Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

send deviceID instead of name from input device #219

Open
wants to merge 51 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
3743062
send deviceID instead of name from input device
elral Nov 9, 2022
800a382
add InputMultiplexer w/ deviceID instead of name
elral Nov 10, 2022
fe43697
change name into deviceID for the handler defin.
elral Nov 10, 2022
02a5808
delete double define of Mux handler
elral Nov 11, 2022
53ac8e8
deactivate config if reading from EEPROM fails
elral Dec 6, 2022
80b3273
correct comment for variable copy_success
elral Dec 6, 2022
3b19a95
Merge branch 'wo_NameBuffer' of https://github.com/elral/MobiFlight-F…
elral Dec 6, 2022
adb6875
Merge branch 'MobiFlight:main' into wo_NameBuffer
elral Dec 8, 2022
145e4b8
Merge branch 'main' into wo_NameBuffer
DocMoebiuz Dec 8, 2022
9895bd1
Merge branch 'main' into wo_NameBuffer
elral Dec 9, 2022
fab649d
new handler ID's for inputs to differ from old way
elral Dec 12, 2022
eb11e8b
double definition for input shifter change deleted
elral Dec 12, 2022
e5faee9
deleted unused variable
elral Dec 14, 2022
00790f5
Merge branch 'main' into wo_NameBuffer
elral Jan 6, 2023
318852a
Merge branch 'MobiFlight:main' into wo_NameBuffer
elral Jan 6, 2023
a0a0b8a
Merge branch 'main' into wo_NameBuffer
elral Jan 16, 2023
b6d1f3e
Merge branch 'MobiFlight:main' into wo_NameBuffer
elral Mar 19, 2023
9251715
delete array for namebuffer, cleanup of EEPROM defines
elral May 24, 2023
e7c8046
#define not required
elral May 31, 2023
34269aa
Merge branch 'main' into wo_NameBuffer
elral Jun 19, 2023
cb20906
Merge branch 'main' into wo_NameBuffer
elral Sep 8, 2023
62b309c
merge main
elral Sep 8, 2023
d59e252
Merge branch 'MobiFlight:main' into wo_NameBuffer
elral Oct 11, 2023
5fbe6c8
Merge branch 'main' into wo_NameBuffer
elral Oct 23, 2023
3ab728a
Merge branch 'main' into wo_NameBuffer
elral Oct 23, 2023
37b7522
merge branch main
elral Oct 23, 2023
89e5a33
merge main
elral Oct 23, 2023
b8e6294
merge error
elral Oct 25, 2023
794b390
Merge branch 'main' into wo_NameBuffer
elral Nov 4, 2023
b86325d
Merge branch 'MobiFlight:main' into wo_NameBuffer
elral Nov 7, 2023
2e2d971
Merge branch 'MobiFlight:main' into wo_NameBuffer
elral Nov 9, 2023
049e0eb
Merge branch 'MobiFlight:main' into wo_NameBuffer
elral Nov 13, 2023
af0201b
Merge branch 'main' into wo_NameBuffer
elral Nov 18, 2023
1e1e4ae
Merge branch 'main' into wo_NameBuffer
elral Nov 24, 2023
ebe8c06
Merge branch 'MobiFlight:main' into wo_NameBuffer
elral Nov 30, 2023
32c2ca2
Merge branch 'MobiFlight:main' into wo_NameBuffer
elral Dec 15, 2023
a5dc49a
Merge branch 'MobiFlight:main' into wo_NameBuffer
elral Dec 17, 2023
0f0e977
Merge branch 'main' into wo_NameBuffer
elral Jan 5, 2024
ec9c371
Merge branch 'MobiFlight:main' into wo_NameBuffer
elral Jan 8, 2024
8dc8a3a
Merge branch 'MobiFlight:main' into wo_NameBuffer
elral Jan 10, 2024
2ae2c7f
Merge branch 'MobiFlight:main' into wo_NameBuffer
elral Jan 10, 2024
67fda32
Merge branch 'MobiFlight:main' into wo_NameBuffer
elral May 5, 2024
2dccc8a
Merge main
elral May 6, 2024
b84f846
Merge branch 'wo_NameBuffer' of https://github.com/elral/MobiFlight-F…
elral May 6, 2024
5dd1791
Merge branch 'MobiFlight:main' into wo_NameBuffer
elral May 24, 2024
a18e839
Merge branch 'main' into wo_NameBuffer
elral May 28, 2024
c3f9d38
Merge branch 'main' into wo_NameBuffer
elral Sep 5, 2024
7ee0e51
Merge branch 'MobiFlight:main' into wo_NameBuffer
elral Sep 17, 2024
5c87b39
Merge branch 'MobiFlight:main' into wo_NameBuffer
elral Oct 1, 2024
fed89d1
Merge branch 'MobiFlight:main' into wo_NameBuffer
elral Oct 22, 2024
89b9b25
Merge branch 'main' into wo_NameBuffer
elral Oct 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 21 additions & 23 deletions src/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,15 @@ bool configStoredInEEPROM()
// reads the EEPROM until NUL terminator and returns the number of characters incl. terminator, starting from given address
bool readconfigLengthEEPROM()
{
uint16_t addreeprom = MEM_OFFSET_CONFIG;
uint16_t addrMem = MEM_OFFSET_CONFIG;
uint16_t length = MFeeprom.get_length();
configLengthEEPROM = 0;

if (MFeeprom.read_byte(MEM_OFFSET_CONFIG) == 0xFF)
return false;
while (MFeeprom.read_byte(addreeprom++) != 0x00) {
while (MFeeprom.read_byte(addrMem++) != 0x00) {
configLengthEEPROM++;
if (addreeprom > length) {
if (addrMem > length) {
cmdMessenger.sendCmd(kStatus, F("Loading config failed")); // text or "-1" like config upload?
return false;
}
Expand Down Expand Up @@ -414,15 +414,15 @@ void readConfigFromMemory(bool configFromFlash)
do {
switch (command) {
case kTypeButton:
params[0] = readUint(&addrMem, configFromFlash); // Pin number
Button::Add(params[0], &nameBuffer[pNameBuffer]); // MUST be before readName because readName returns the pointer for the NEXT Name
copy_success = readName(&addrMem, nameBuffer, &pNameBuffer, configFromFlash); // copy the NULL terminated name to nameBuffer and set to next free memory location
params[0] = readUint(&addrMem, configFromFlash); // Pin number
Button::Add(params[0]);
copy_success = readEndCommand(&addrMem, ':', configFromFlash);
break;

case kTypeOutput:
params[0] = readUint(&addrMem, configFromFlash); // Pin number
Output::Add(params[0]);
copy_success = readEndCommand(&addrMem, ':', configFromFlash); // check EEPROM until end of name
copy_success = readEndCommand(&addrMem, ':', configFromFlash);
break;

#if MF_SEGMENT_SUPPORT == 1
Expand Down Expand Up @@ -493,8 +493,8 @@ void readConfigFromMemory(bool configFromFlash)
if (command == kTypeEncoder)
params[2] = readUint(&addrMem, configFromFlash); // type

Encoder::Add(params[0], params[1], params[2], &nameBuffer[pNameBuffer]); // MUST be before readName because readName returns the pointer for the NEXT Name
copy_success = readName(&addrMem, nameBuffer, &pNameBuffer, configFromFlash); // copy the NULL terminated name to nameBuffer and set to next free memory location
Encoder::Add(params[0], params[1], params[2]);
copy_success = readEndCommand(&addrMem, ':', configFromFlash);
break;

#if MF_LCD_SUPPORT == 1
Expand All @@ -503,17 +503,16 @@ void readConfigFromMemory(bool configFromFlash)
params[1] = readUint(&addrMem, configFromFlash); // columns
params[2] = readUint(&addrMem, configFromFlash); // lines
LCDDisplay::Add(params[0], params[1], params[2]);
copy_success = readEndCommand(&addrMem, ':', configFromFlash); // check EEPROM until end of name
copy_success = readEndCommand(&addrMem, ':', configFromFlash);
break;
#endif

#if MF_ANALOG_SUPPORT == 1
case kTypeAnalogInput:
params[0] = readUint(&addrMem, configFromFlash); // pin number
params[1] = readUint(&addrMem, configFromFlash); // sensitivity
Analog::Add(params[0], &nameBuffer[pNameBuffer], params[1]); // MUST be before readName because readName returns the pointer for the NEXT Name
copy_success = readName(&addrMem, nameBuffer, &pNameBuffer, configFromFlash); // copy the NULL terminated name to to nameBuffer and set to next free memory location
// copy_success = readEndCommand(&addrMem, ':'); // once the nameBuffer is not required anymore uncomment this line and delete the line before
params[0] = readUint(&addrMem, configFromFlash); // pin number
params[1] = readUint(&addrMem, configFromFlash); // sensitivity
Analog::Add(params[0], params[1]);
copy_success = readEndCommand(&addrMem, ':', configFromFlash);
break;
#endif

Expand All @@ -524,7 +523,7 @@ void readConfigFromMemory(bool configFromFlash)
params[2] = readUint(&addrMem, configFromFlash); // data Pin
params[3] = readUint(&addrMem, configFromFlash); // number of daisy chained modules
OutputShifter::Add(params[0], params[1], params[2], params[3]);
copy_success = readEndCommand(&addrMem, ':', configFromFlash); // check EEPROM until end of name
copy_success = readEndCommand(&addrMem, ':', configFromFlash);
break;
#endif

Expand All @@ -534,9 +533,8 @@ void readConfigFromMemory(bool configFromFlash)
params[1] = readUint(&addrMem, configFromFlash); // clock Pin
params[2] = readUint(&addrMem, configFromFlash); // data Pin
params[3] = readUint(&addrMem, configFromFlash); // number of daisy chained modules
InputShifter::Add(params[0], params[1], params[2], params[3], &nameBuffer[pNameBuffer]);
copy_success = readName(&addrMem, nameBuffer, &pNameBuffer, configFromFlash); // copy the NULL terminated name to to nameBuffer and set to next free memory location
// copy_success = readEndCommand(&addrMem, ':'); // once the nameBuffer is not required anymore uncomment this line and delete the line before
InputShifter::Add(params[0], params[1], params[2], params[3]);
copy_success = readEndCommand(&addrMem, ':', configFromFlash);
break;
#endif

Expand All @@ -552,8 +550,8 @@ void readConfigFromMemory(bool configFromFlash)
params[4] = readUint(&addrMem, configFromFlash); // Sel3 pin
MUX.attach(params[1], params[2], params[3], params[4]);
params[5] = readUint(&addrMem, configFromFlash); // 8-bit registers (1-2)
DigInMux::Add(params[0], params[5], &nameBuffer[pNameBuffer]);
copy_success = readName(&addrMem, nameBuffer, &pNameBuffer, configFromFlash);
DigInMux::Add(params[0], params[5]);
copy_success = readEndCommand(&addrMem, ':', configFromFlash);
break;
#endif

Expand Down Expand Up @@ -584,8 +582,8 @@ void readConfigFromMemory(bool configFromFlash)
}
command = readUint(&addrMem, configFromFlash);
} while (command && copy_success);
if (!copy_success) { // too much/long names for input devices
nameBuffer[MEMLEN_NAMES_BUFFER - 1] = 0x00; // terminate the last copied (part of) string with 0x00
if (!copy_success) { // EEPROM size exceeded while reading the config, might happen if EEPROM is corrupted
configActivated = false;
cmdMessenger.sendCmd(kStatus, F("Failure on reading config"));
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/MF_Analog/Analog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ namespace Analog
uint8_t analogRegistered = 0;
uint8_t maxAnalogIn = 0;

void handlerOnAnalogChange(int value, const char *name)
void handlerOnAnalogChange(int value, uint8_t deviceID)
{
cmdMessenger.sendCmdStart(kAnalogChange);
cmdMessenger.sendCmdArg(name);
cmdMessenger.sendCmdArg(deviceID);
cmdMessenger.sendCmdArg(value);
cmdMessenger.sendCmdEnd();
};
Expand All @@ -27,18 +27,18 @@ namespace Analog
{
if (!FitInMemory(sizeof(MFAnalog) * count))
return false;
analog = new (allocateMemory(sizeof(MFAnalog) * count)) MFAnalog;
analog = new (allocateMemory(sizeof(MFAnalog) * count)) MFAnalog();
maxAnalogIn = count;
return true;
}

void Add(uint8_t pin, char const *name, uint8_t sensitivity)
void Add(uint8_t pin, uint8_t sensitivity)
{
if (analogRegistered == maxAnalogIn)
return;

analog[analogRegistered] = MFAnalog();
analog[analogRegistered].attach(pin, name, sensitivity);
analog[analogRegistered].attach(pin, analogRegistered, sensitivity);
MFAnalog::attachHandler(handlerOnAnalogChange);
analogRegistered++;
#ifdef DEBUG2CMDMESSENGER
Expand Down
2 changes: 1 addition & 1 deletion src/MF_Analog/Analog.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
namespace Analog
{
bool setupArray(uint16_t count);
void Add(uint8_t pin, char const *name = "AnalogInput", uint8_t sensitivity = 3);
void Add(uint8_t pin, uint8_t sensitivity = 3);
void Clear();
void read();
void readAverage();
Expand Down
6 changes: 3 additions & 3 deletions src/MF_Analog/MFAnalog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ MFAnalog::MFAnalog()
_initialized = false;
}

void MFAnalog::attach(uint8_t pin, const char *name, uint8_t sensitivity)
void MFAnalog::attach(uint8_t pin, uint8_t deviceID, uint8_t sensitivity)
{
_sensitivity = sensitivity;
_pin = pin;
_name = name;
_deviceID = deviceID;
#if defined(ARDUINO_AVR_PROMICRO16)
// ProMicro has a special pin assignment for analog pins
// therefore reading from A6 and A7 does not work
Expand Down Expand Up @@ -52,7 +52,7 @@ void MFAnalog::readChannel(uint8_t alwaysTrigger)
if (alwaysTrigger || valueHasChanged(newValue)) {
_lastValue = newValue;
if (_handler != NULL) {
(*_handler)(_lastValue, _name);
(*_handler)(_lastValue, _deviceID);
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/MF_Analog/MFAnalog.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

extern "C" {
// callback functions
typedef void (*analogEvent)(int, const char *);
typedef void (*analogEvent)(int, uint8_t);
};

/////////////////////////////////////////////////////////////////////
Expand All @@ -26,7 +26,7 @@ class MFAnalog
public:
MFAnalog();
static void attachHandler(analogEvent handler);
void attach(uint8_t pin, const char *name, uint8_t sensitivity);
void attach(uint8_t pin, uint8_t deviceID, uint8_t sensitivity);
void update();
void retrigger();
void readBuffer();
Expand All @@ -35,8 +35,9 @@ class MFAnalog

private:
static analogEvent _handler;
int _lastValue;
int16_t _lastValue;
uint8_t _sensitivity;
uint8_t _deviceID;

uint16_t ADC_Buffer[ADC_MAX_AVERAGE] = {0}; // Buffer for all values from each channel
uint16_t ADC_Average_Total = 0; // sum of sampled values, must be divided by ADC_MAX_AVERAGE to get actual value
Expand Down
8 changes: 4 additions & 4 deletions src/MF_Button/Button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ namespace Button
uint8_t buttonsRegistered = 0;
uint8_t maxButtons = 0;

void handlerButtonOnChange(uint8_t eventId, const char *name)
void handlerButtonOnChange(uint8_t eventId, uint8_t deviceID)
{
cmdMessenger.sendCmdStart(kButtonChange);
cmdMessenger.sendCmdArg(name);
cmdMessenger.sendCmdArg(deviceID);
cmdMessenger.sendCmdArg(eventId);
cmdMessenger.sendCmdEnd();
};
Expand All @@ -31,12 +31,12 @@ namespace Button
return true;
}

void Add(uint8_t pin, char const *name)
void Add(uint8_t pin)
{
if (buttonsRegistered == maxButtons)
return;
buttons[buttonsRegistered] = MFButton();
buttons[buttonsRegistered].attach(pin, name);
buttons[buttonsRegistered].attach(pin, buttonsRegistered);
MFButton::attachHandler(handlerButtonOnChange);
buttonsRegistered++;
#ifdef DEBUG2CMDMESSENGER
Expand Down
2 changes: 1 addition & 1 deletion src/MF_Button/Button.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
namespace Button
{
bool setupArray(uint16_t count);
void Add(uint8_t pin, char const *name = "Button");
void Add(uint8_t pin);
void Clear();
void read();
void OnTrigger();
Expand Down
8 changes: 4 additions & 4 deletions src/MF_Button/MFButton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ MFButton::MFButton()
_initialized = false;
}

void MFButton::attach(uint8_t pin, const char *name)
void MFButton::attach(uint8_t pin, uint8_t deviceID)
{
_pin = pin;
_name = name;
_deviceID = deviceID;
pinMode(_pin, INPUT_PULLUP); // set pin to input
_state = digitalRead(_pin); // initialize on actual status
_initialized = true;
Expand Down Expand Up @@ -47,7 +47,7 @@ void MFButton::triggerOnPress()
if (!_initialized)
return;
if (_inputHandler && _state == LOW) {
(*_inputHandler)(btnOnPress, _name);
(*_inputHandler)(btnOnPress, _deviceID);
}
}

Expand All @@ -56,7 +56,7 @@ void MFButton::triggerOnRelease()
if (!_initialized)
return;
if (_inputHandler && _state == HIGH) {
(*_inputHandler)(btnOnRelease, _name);
(*_inputHandler)(btnOnRelease, _deviceID);
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/MF_Button/MFButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

extern "C" {
// callback functions always follow the signature: void cmd(void);
typedef void (*buttonEvent)(uint8_t, const char *);
typedef void (*buttonEvent)(uint8_t, uint8_t);
};

enum {
Expand All @@ -25,15 +25,15 @@ class MFButton
public:
MFButton();
static void attachHandler(buttonEvent newHandler);
void attach(uint8_t pin, const char *name);
void attach(uint8_t pin, uint8_t deviceID);
void detach();
void update();
void trigger(uint8_t state);
void triggerOnPress();
void triggerOnRelease();

private:
const char *_name;
uint8_t _deviceID;
uint8_t _pin;
bool _initialized;
bool _state;
Expand Down
10 changes: 5 additions & 5 deletions src/MF_DigInMux/DigInMux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ namespace DigInMux
uint8_t digInMuxRegistered = 0;
uint8_t maxDigInMux = 0;

void handlerOnDigInMux(uint8_t eventId, uint8_t channel, const char *name)
void handlerOnDigInMux(uint8_t eventId, uint8_t channel, uint8_t deviceID)
{
cmdMessenger.sendCmdStart(kDigInMuxChange);
cmdMessenger.sendCmdArg(name);
cmdMessenger.sendCmdArg(deviceID);
cmdMessenger.sendCmdArg(channel);
cmdMessenger.sendCmdArg(eventId);
cmdMessenger.sendCmdEnd();
Expand All @@ -34,12 +34,12 @@ namespace DigInMux
return true;
}

void Add(uint8_t dataPin, uint8_t nRegs, char const *name)
void Add(uint8_t dataPin, uint8_t nRegs)
{
if (digInMuxRegistered == maxDigInMux)
return;
digInMux[digInMuxRegistered] = MFDigInMux(&MUX, name);
digInMux[digInMuxRegistered].attach(dataPin, (nRegs == 1), name);
digInMux[digInMuxRegistered] = MFDigInMux(&MUX);
digInMux[digInMuxRegistered].attach(dataPin, (nRegs == 1), digInMuxRegistered);
MFDigInMux::attachHandler(handlerOnDigInMux);
digInMuxRegistered++;

Expand Down
2 changes: 1 addition & 1 deletion src/MF_DigInMux/DigInMux.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
namespace DigInMux
{
bool setupArray(uint16_t count);
void Add(uint8_t dataPin, uint8_t nRegs, char const *name = "DigInMux");
void Add(uint8_t dataPin, uint8_t nRegs);
void Clear();
void read();
void OnTrigger();
Expand Down
14 changes: 6 additions & 8 deletions src/MF_DigInMux/MFDigInMux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@ MuxDigInEvent MFDigInMux::_inputHandler = NULL;
MFDigInMux::MFDigInMux(void)
{
_MUX = NULL;
_name = "MUXDigIn";
_flags = 0x00;
clear();
}

MFDigInMux::MFDigInMux(MFMuxDriver *MUX, const char *name)
: _name(name)
MFDigInMux::MFDigInMux(MFMuxDriver *MUX)
{
if (MUX) _MUX = MUX;
_flags = 0x00;
Expand All @@ -34,12 +32,12 @@ void MFDigInMux::setMux(MFMuxDriver *MUX)
}

// Registers a new MUX input block and configures the driver pins
void MFDigInMux::attach(uint8_t dataPin, bool halfSize, char const *name)
void MFDigInMux::attach(uint8_t dataPin, bool halfSize, uint8_t deviceID)
{
// if(!_MUX) return; // no need to check, the object can be set up in advance before the MUX is configured
_dataPin = dataPin;
_name = name;
_flags = 0x00;
_dataPin = dataPin;
_deviceID = deviceID;
_flags = 0x00;
if (halfSize) bitSet(_flags, MUX_HALFSIZE);
pinMode(_dataPin, INPUT_PULLUP);
bitSet(_flags, MUX_INITED);
Expand Down Expand Up @@ -140,7 +138,7 @@ void MFDigInMux::trigger(uint8_t channel, bool state)
{
if (!_MUX) return;
if (!_inputHandler) return;
(*_inputHandler)((state ? MuxDigInOnRelease : MuxDigInOnPress), channel, _name);
(*_inputHandler)((state ? MuxDigInOnRelease : MuxDigInOnPress), channel, _deviceID);
}

// Attaches a new event handler for the specified event.
Expand Down
Loading
Loading