Skip to content

Commit f826e09

Browse files
authored
Merge pull request midilab#7 from midilab/develop
Preparing release v1.2
2 parents f2a1573 + cc53d57 commit f826e09

File tree

27 files changed

+645
-537
lines changed

27 files changed

+645
-537
lines changed

module/ain/ain.cpp

Lines changed: 44 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,16 @@ Ain::Ain()
3535
rtCallback = nullptr;
3636
}
3737

38+
// we never reach here because its a lifetime object
3839
Ain::~Ain()
3940
{
40-
41+
delete[] _analog_input_last_state;
42+
delete[] _analog_input_state;
43+
delete[] _analog_input_lock_control;
44+
#ifdef AUTOLOCK
45+
delete[] _analog_input_check_state;
46+
#endif
47+
free(_port);
4148
}
4249

4350
uint8_t Ain::sizeOf()
@@ -87,8 +94,15 @@ void Ain::setMuxPins(int8_t pin1, int8_t pin2, int8_t pin3, int8_t pin4)
8794
// call first all plug() for pin register, then plugMux()
8895
void Ain::plug(uint8_t setup)
8996
{
90-
if (_host_analog_port >= USE_AIN_MAX_PORTS)
91-
return;
97+
//if (_host_analog_port >= USE_AIN_MAX_PORTS)
98+
// return;
99+
100+
// alloc once and forever policy!
101+
if (_port == nullptr) {
102+
_port = (int8_t*) malloc( sizeof(int8_t) );
103+
} else {
104+
_port = (int8_t*) realloc( _port, sizeof(int8_t) * (_host_analog_port+1) );
105+
}
92106

93107
_port[_host_analog_port] = setup;
94108
pinMode(setup, INPUT);
@@ -101,8 +115,15 @@ void Ain::plug(uint8_t setup)
101115

102116
void Ain::plugMux(uint8_t setup)
103117
{
104-
if (_host_analog_port >= USE_AIN_MAX_PORTS)
105-
return;
118+
//if (_host_analog_port >= USE_AIN_MAX_PORTS)
119+
// return;
120+
121+
// alloc once and forever policy!
122+
if (_port == nullptr) {
123+
_port = (int8_t*) malloc( sizeof(int8_t) );
124+
} else {
125+
_port = (int8_t*) realloc( _port, sizeof(int8_t) * (_host_analog_port+1) );
126+
}
106127

107128
_port[_host_analog_port] = setup;
108129
pinMode(setup, INPUT);
@@ -119,18 +140,23 @@ void Ain::init()
119140
// Allocate memory
120141
// alloc rules: alloc once and forever! no memory free call at runtime
121142
if ( _remote_analog_port > 0 ) {
122-
_analog_input_last_state = (uint16_t*) malloc( sizeof(uint16_t) * _remote_analog_port );
143+
//_analog_input_last_state = (uint16_t*) malloc( sizeof(uint16_t) * _remote_analog_port );
144+
_analog_input_last_state = new uint16_t[_remote_analog_port];
123145
#ifdef ANALOG_AVG_READS
124-
_analog_input_state = (AVG_READS*) malloc( sizeof(AVG_READS) * _remote_analog_port );
146+
//_analog_input_state = (AVG_READS*) malloc( sizeof(AVG_READS) * _remote_analog_port );
147+
_analog_input_state = new AVG_READS[_remote_analog_port];
125148
#else
126-
_analog_input_state = (uint16_t*) malloc( sizeof(uint16_t*) * _remote_analog_port );
149+
//_analog_input_state = (uint16_t*) malloc( sizeof(uint16_t*) * _remote_analog_port );
150+
_analog_input_state = new uint16_t[_remote_analog_port];
127151
#endif
128-
_analog_input_lock_control = (int8_t*) malloc( sizeof(int8_t) * _remote_analog_port );
152+
//_analog_input_lock_control = (int8_t*) malloc( sizeof(int8_t) * _remote_analog_port );
153+
_analog_input_lock_control = new int8_t[_remote_analog_port];
129154
#ifdef AUTOLOCK
130-
_analog_input_check_state = (uint16_t*) malloc( sizeof(uint16_t) * _remote_analog_port );
131-
#endif
155+
//_analog_input_check_state = (uint16_t*) malloc( sizeof(uint16_t) * _remote_analog_port );
156+
_analog_input_check_state = new uint16_t[_remote_analog_port];
157+
#endif
132158
}
133-
159+
134160
// initing memory and first mux scan
135161
for (uint8_t remote_port=0; remote_port < _remote_analog_port; remote_port++) {
136162

@@ -253,15 +279,15 @@ int16_t Ain::getData(uint8_t remote_port, uint16_t min, uint16_t max)
253279
// otherwise its a mux read request
254280
} else {
255281
//#if defined(USE_AIN_4051_DRIVER) || defined(USE_AIN_4067_DRIVER)
256-
if (_use_mux_driver == MUX_DRIVER_4051 || _use_mux_driver == MUX_DRIVER_4067) {
282+
//if (_use_mux_driver == MUX_DRIVER_4051 || _use_mux_driver == MUX_DRIVER_4067) {
257283
uint8_t mux_host_port = remote_port - _direct_pin_size;
258284
// find our indexes
259285
host_analog_port = (uint8_t)(mux_host_port/_mux_size) + _direct_pin_size;
260286
// get data
261287
input_data = readPort(remote_port, host_analog_port);
262288
// select next mux port while processing this one
263289
selectMuxPort(mux_host_port+1);
264-
}
290+
//}
265291
//#endif
266292
}
267293

@@ -275,7 +301,9 @@ int16_t Ain::getData(uint8_t remote_port, uint16_t min, uint16_t max)
275301
}
276302

277303
// value remap?
278-
max = _user_adc_max_resolution != _adc_max_resolution ? _user_adc_max_resolution-1 : _adc_max_resolution;
304+
if (max == 0)
305+
max = _user_adc_max_resolution != _adc_max_resolution ? _user_adc_max_resolution-1 : _adc_max_resolution;
306+
279307
if ( min == 0 && max == _adc_max_resolution ) {
280308
value = input_data;
281309
last_value = _analog_input_last_state[remote_port];
@@ -319,6 +347,4 @@ int16_t Ain::getData(uint8_t remote_port, uint16_t min, uint16_t max)
319347

320348
}
321349

322-
} }
323-
324-
uctrl::module::Ain ain_module;
350+
} }

module/ain/ain.hpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ namespace uctrl { namespace module {
3636
#define AUTOLOCK
3737
#define ANALOG_AVG_READS
3838

39-
#if !defined(USE_AIN_MAX_PORTS)
40-
#define USE_AIN_MAX_PORTS 8
41-
#endif
39+
//#if !defined(USE_AIN_MAX_PORTS)
40+
//#define USE_AIN_MAX_PORTS 8
41+
//#endif
4242

4343
#define AIN_4051_MUX_SIZE 8
4444
#define AIN_4067_MUX_SIZE 16
@@ -106,7 +106,8 @@ class Ain
106106
int8_t _use_mux_driver = -1; // 0=4051, 1=4067
107107
uint8_t _mux_size = 0;
108108

109-
int8_t _port[USE_AIN_MAX_PORTS] = {-1};
109+
//int8_t _port[USE_AIN_MAX_PORTS] = {-1};
110+
int8_t * _port = nullptr;
110111

111112
uint8_t _host_analog_port = 0; // uint8_t hard_port[16];
112113
uint8_t _remote_analog_port = 0; // uint8_t soft_port[16];
@@ -138,7 +139,5 @@ class Ain
138139
};
139140

140141
} }
141-
142-
extern uctrl::module::Ain ain_module;
143142

144143
#endif

module/device/device.cpp

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#ifdef USE_DEVICE
2-
31
#include "../../uCtrl.h"
42
#include "device.hpp"
53

@@ -163,7 +161,7 @@ bool Device::handleAnalogEvent(uint8_t port, uint16_t value, uint8_t interrupted
163161
{
164162
//static uint16_t address;
165163

166-
--port;
164+
//--port;
167165
if ( _remote.adc_port[port].event_address != 1023 ) { //>= 0 ) {
168166
// Handler dispatcher
169167
_ctrl.port = port+1;
@@ -184,8 +182,7 @@ bool Device::handleAnalogEvent(uint8_t port, uint16_t value, uint8_t interrupted
184182

185183
bool Device::handleDigitalEvent(uint8_t port, uint16_t value, uint8_t interrupted)
186184
{
187-
--port;
188-
185+
//--port;
189186
if ( _remote.din_port[port].event_address != 1023 ) { //!= -1 ) {
190187
//_ctrl.port = port+1;
191188
#if defined(USE_DEVICE_LABELS)
@@ -231,7 +228,7 @@ bool Device::handleDigitalEvent(uint8_t port, uint16_t value, uint8_t interrupte
231228
void Device::setupCtrl(uint8_t port, uint16_t value)
232229
{
233230
uint8_t size_of_ports;
234-
--port;
231+
//--port;
235232

236233
// 1023 default value we got no _remote.adc_port[port].device_id
237234
if ( _remote.adc_port[port].event_address == 1023 ) {
@@ -286,7 +283,7 @@ void Device::clearMap(uint8_t device_id)
286283
#endif
287284
}
288285

289-
void Device::eventMap(uint8_t device_id, CONTROL_DATA * event, uint8_t * eventName = NULL, int16_t label_offset = 0)
286+
void Device::eventMap(uint8_t device_id, CONTROL_DATA * event, uint8_t * eventName, int16_t label_offset)
290287
{
291288
uint16_t memory_address;
292289

@@ -421,7 +418,7 @@ void Device::getDeviceMapEventData(uint8_t device_id, uint16_t event_address, CO
421418
uint8_t * Device::getDeviceName(uint8_t device_id)
422419
{
423420
if ( device_id > _device_number ) {
424-
return;
421+
return nullptr;
425422
}
426423
if ( device_id == 0 ) {
427424
device_id = _selected_device;
@@ -544,7 +541,7 @@ void Device::editCtrlsetDevice(int8_t inc, uint8_t port)
544541
if ( event.data_label != 65535 ) {
545542
memcpy (_ctrl.data_label, getDataLabel(_remote.adc_port[port].device_id, event.data_label, _edit_ctrl_last_value), 16);
546543
} else {
547-
sprintf (_ctrl.data_label, "%-8d", event.label_offset + _edit_ctrl_last_value);
544+
sprintf ((char*)_ctrl.data_label, "%-8d", event.label_offset + _edit_ctrl_last_value);
548545
//sprintf (_ctrl.data_label, "%d", event.label_offset + _edit_ctrl_last_value);
549546
}
550547
/*
@@ -605,7 +602,7 @@ void Device::editCtrlsetCtrl(int8_t inc, uint8_t port)
605602
if ( event.data_label != 65535 ) {
606603
memcpy (_ctrl.data_label, getDataLabel(_remote.adc_port[port].device_id, event.data_label, _edit_ctrl_last_value), 16);
607604
} else {
608-
sprintf (_ctrl.data_label, "%-8d", event.label_offset + _edit_ctrl_last_value);
605+
sprintf ((char*)_ctrl.data_label, "%-8d", event.label_offset + _edit_ctrl_last_value);
609606
//sprintf (_ctrl.data_label, "%d", event.label_offset + _edit_ctrl_last_value);
610607
}
611608
/*
@@ -827,19 +824,17 @@ void Device::remoteEventHandler(CONTROL_DATA * event, uint8_t device_id, uint16_
827824

828825
switch (event->type) {
829826

830-
#ifdef USE_MIDI
831827
case uctrl::MIDI_ANALOG:
832828
case uctrl::MIDI_TRIGGER:
833829
case uctrl::MIDI_BUTTON:
834830
if ( interrupted == 1 ) {
835831
if ( uCtrl.midi != nullptr && _ctrl_mode != 1 ) {
836-
uCtrl.midi->sendMessage(eventToMidiMsg(event, value, _device[device_id].chn), _device[device_id].port+1, 0, event->config);
832+
uCtrl.midi->sendMessage(eventToMidiMsg(event, value, _device[device_id].chn), _device[device_id].port+1, interrupted, event->config);
837833
}
838834
return;
839835
} else {
840836
break;
841837
}
842-
#endif
843838

844839
// this is non realtime action, so always return if its interrupted
845840
case uctrl::APP_CTRL:
@@ -860,6 +855,9 @@ void Device::remoteEventHandler(CONTROL_DATA * event, uint8_t device_id, uint16_
860855
// the comming piece of code should only be processed if interrupted == 0, or face the consequences...
861856

862857
#ifdef USE_DEVICE_LABELS
858+
if ( uCtrl.oled == nullptr )
859+
return;
860+
863861
// TODO: dont use oled object here... go for callback solution!
864862
// if event name has a # on it means do not show feedback, do it silent
865863
if ( event->name[0] != '#' ) {
@@ -870,7 +868,7 @@ void Device::remoteEventHandler(CONTROL_DATA * event, uint8_t device_id, uint16_
870868
if ( event->data_label != 65535 ) {
871869
memcpy (_ctrl.data_label, getDataLabel(device_id, event->data_label, value), 16);
872870
} else {
873-
sprintf (_ctrl.data_label, "%-8d", event->label_offset + value);
871+
sprintf ((char*)_ctrl.data_label, "%-8d", event->label_offset + value);
874872
//sprintf (_ctrl.data_label, "%d", event->label_offset + value);
875873
}
876874
if ( _data_feedback_show == false ) {
@@ -972,13 +970,13 @@ void Device::sendEvent(uint16_t eventAddress, uint8_t device_id, uint16_t value)
972970
*/
973971
void Device::lockControl(uint8_t remote_port)
974972
{
975-
#ifdef USE_AIN
976-
if ( remote_port == 0 ) {
977-
uCtrl.ain->lockAllControls();
978-
} else {
979-
uCtrl.ain->lockControl(remote_port-1);
973+
if ( uCtrl.ain != nullptr) {
974+
if ( remote_port == 0 ) {
975+
uCtrl.ain->lockAllControls();
976+
} else {
977+
uCtrl.ain->lockControl(remote_port-1);
978+
}
980979
}
981-
#endif
982980
}
983981
/*
984982
// Special shift button with n taps support
@@ -1077,10 +1075,8 @@ bool Device::isPressed(uint8_t port)
10771075
#endif
10781076
*/
10791077

1080-
#ifdef USE_DIN
1081-
return uCtrl.din->getDataRaw(port);
1082-
#endif
1083-
1078+
if ( uCtrl.din != nullptr )
1079+
return uCtrl.din->getDataRaw(port);
10841080
}
10851081

10861082
void Device::ctrlMap(uint8_t device_id, uint16_t control_id, uint16_t range_min, uint16_t range_max, int16_t label_offset, uint8_t * name)
@@ -1355,5 +1351,4 @@ const uint8_t * Device::getDataLabel(uint8_t device_id, uint16_t address, uint16
13551351

13561352
} }
13571353

1358-
uctrl::module::Device device_module;
1359-
#endif
1354+
//uctrl::module::Device device_module;

module/device/device.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ namespace uctrl {
88
#define DEVICE_LABEL_SIZE 16
99
#define SYSEX_TEMPLATE_SIZE 16
1010

11+
// find a place for user to setup it
12+
#define USE_DEVICE_LABELS
13+
#define USE_EXT_RAM
14+
1115
// Sysex template system datatypes
1216
typedef enum {
1317
SYSEX_TEMPLATE_STATIC,

module/device/device.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ class Device
1212
Device();
1313
~Device();
1414

15-
//void init(uctrl::uCtrlClass * uCtrl, uint8_t device_number, uint16_t event_buffer_size, uint8_t device_buffer_size, uint16_t device_label_buffer_size = 0);
1615
void init(uint8_t device_number, uint16_t event_buffer_size, uint8_t sysex_buffer_size = 0, uint16_t device_label_buffer_size = 0);
1716

1817
bool isPressed(uint8_t port);
@@ -177,6 +176,6 @@ class Device
177176

178177
} }
179178

180-
extern uctrl::module::Device device_module;
179+
//extern uctrl::module::Device device_module;
181180

182181
#endif

0 commit comments

Comments
 (0)