From 37430628dc60fe87691f2c36eaf2e1c53bc504c8 Mon Sep 17 00:00:00 2001 From: elral <3263285+elral@users.noreply.github.com> Date: Wed, 9 Nov 2022 07:58:14 +0100 Subject: [PATCH 01/15] send deviceID instead of name from input device --- _Boards/Atmel/Board_Mega/MFBoards.h | 13 ++- _Boards/Atmel/Board_ProMicro/MFBoards.h | 13 ++- _Boards/Atmel/Board_Uno/MFBoards.h | 13 ++- src/Config.cpp | 103 +++++++++--------------- src/MF_Analog/Analog.cpp | 8 +- src/MF_Analog/Analog.h | 2 +- src/MF_Analog/MFAnalog.cpp | 6 +- src/MF_Analog/MFAnalog.h | 7 +- src/MF_Button/Button.cpp | 8 +- src/MF_Button/Button.h | 2 +- src/MF_Button/MFButton.cpp | 14 ++-- src/MF_Button/MFButton.h | 6 +- src/MF_Encoder/Encoder.cpp | 8 +- src/MF_Encoder/Encoder.h | 2 +- src/MF_Encoder/MFEncoder.cpp | 14 ++-- src/MF_Encoder/MFEncoder.h | 14 ++-- src/MF_InputShifter/InputShifter.cpp | 8 +- src/MF_InputShifter/InputShifter.h | 2 +- src/MF_InputShifter/MFInputShifter.cpp | 9 +-- src/MF_InputShifter/MFInputShifter.h | 20 ++--- 20 files changed, 122 insertions(+), 150 deletions(-) diff --git a/_Boards/Atmel/Board_Mega/MFBoards.h b/_Boards/Atmel/Board_Mega/MFBoards.h index c1da424c..a9026309 100644 --- a/_Boards/Atmel/Board_Mega/MFBoards.h +++ b/_Boards/Atmel/Board_Mega/MFBoards.h @@ -52,13 +52,12 @@ #define STEPPER_SPEED 400 // 300 already worked, 467, too? #define STEPPER_ACCEL 800 -#define MOBIFLIGHT_TYPE "MobiFlight Mega" -#define MOBIFLIGHT_SERIAL "1234567890" -#define MOBIFLIGHT_NAME "MobiFlight Mega" -#define EEPROM_SIZE 4096 // EEPROMSizeMega -#define MEMLEN_CONFIG 1496 // max. size for config which wil be stored in EEPROM -#define MEMLEN_NAMES_BUFFER 1000 // max. size for configBuffer, contains only names from inputs -#define MF_MAX_DEVICEMEM 1500 // max. memory size for devices +#define MOBIFLIGHT_TYPE "MobiFlight Mega" +#define MOBIFLIGHT_SERIAL "1234567890" +#define MOBIFLIGHT_NAME "MobiFlight Mega" +#define EEPROM_SIZE 4096 // EEPROMSizeMega +#define MEMLEN_CONFIG 1496 // max. size for config which wil be stored in EEPROM +#define MF_MAX_DEVICEMEM 1500 // max. memory size for devices #define RANDOM_SEED_INPUT A0 diff --git a/_Boards/Atmel/Board_ProMicro/MFBoards.h b/_Boards/Atmel/Board_ProMicro/MFBoards.h index ba483229..7f304ac4 100644 --- a/_Boards/Atmel/Board_ProMicro/MFBoards.h +++ b/_Boards/Atmel/Board_ProMicro/MFBoards.h @@ -52,13 +52,12 @@ #define STEPPER_SPEED 400 // 300 already worked, 467, too? #define STEPPER_ACCEL 800 -#define MOBIFLIGHT_TYPE "MobiFlight Micro" -#define MOBIFLIGHT_SERIAL "0987654321" -#define MOBIFLIGHT_NAME "MobiFlight Micro" -#define EEPROM_SIZE 1024 // EEPROMSizeMicro -#define MEMLEN_CONFIG 440 // max. size for config which wil be stored in EEPROM -#define MEMLEN_NAMES_BUFFER 350 // max. size for configBuffer, contains only names from inputs -#define MF_MAX_DEVICEMEM 400 // max. memory size for devices +#define MOBIFLIGHT_TYPE "MobiFlight Micro" +#define MOBIFLIGHT_SERIAL "0987654321" +#define MOBIFLIGHT_NAME "MobiFlight Micro" +#define EEPROM_SIZE 1024 // EEPROMSizeMicro +#define MEMLEN_CONFIG 440 // max. size for config which wil be stored in EEPROM +#define MF_MAX_DEVICEMEM 400 // max. memory size for devices #define RANDOM_SEED_INPUT A0 diff --git a/_Boards/Atmel/Board_Uno/MFBoards.h b/_Boards/Atmel/Board_Uno/MFBoards.h index 709ff6bf..ce9195df 100644 --- a/_Boards/Atmel/Board_Uno/MFBoards.h +++ b/_Boards/Atmel/Board_Uno/MFBoards.h @@ -52,13 +52,12 @@ #define STEPPER_SPEED 400 // 300 already worked, 467, too? #define STEPPER_ACCEL 800 -#define MOBIFLIGHT_TYPE "MobiFlight Uno" -#define MOBIFLIGHT_SERIAL "0987654321" -#define MOBIFLIGHT_NAME "MobiFlight Uno" -#define EEPROM_SIZE 1024 // EEPROMSizeUno -#define MEMLEN_CONFIG 286 // max. size for config which wil be stored in EEPROM -#define MEMLEN_NAMES_BUFFER 220 // max. size for configBuffer, contains only names from inputs -#define MF_MAX_DEVICEMEM 300 // max. memory size for devices +#define MOBIFLIGHT_TYPE "MobiFlight Uno" +#define MOBIFLIGHT_SERIAL "0987654321" +#define MOBIFLIGHT_NAME "MobiFlight Uno" +#define EEPROM_SIZE 1024 // EEPROMSizeUno +#define MEMLEN_CONFIG 286 // max. size for config which wil be stored in EEPROM +#define MF_MAX_DEVICEMEM 300 // max. memory size for devices #define RANDOM_SEED_INPUT A0 diff --git a/src/Config.cpp b/src/Config.cpp index e5cdb053..77064642 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -59,7 +59,6 @@ const char type[sizeof(MOBIFLIGHT_TYPE)] = MOBIFLIGHT_TYPE; char serial[MEM_LEN_SERIAL] = MOBIFLIGHT_SERIAL; char name[MEM_LEN_NAME] = MOBIFLIGHT_NAME; const int MEM_LEN_CONFIG = MEMLEN_CONFIG; -char nameBuffer[MEM_LEN_CONFIG] = ""; uint16_t configLength = 0; boolean configActivated = false; @@ -164,17 +163,17 @@ void OnResetConfig() void OnSaveConfig() { cmdMessenger.sendCmd(kConfigSaved, F("OK")); -// Uncomment the if{} part to reset and load the config via serial terminal for testing w/o the GUI -// 1: Type "13" to reset the config -// 2: Type "14" to get the config length -// 3: Type "16" to load the config -/* - if (readConfigLength()) - { - readConfig(); - _activateConfig(); - } -*/ + // Uncomment the if{} part to reset and load the config via serial terminal for testing w/o the GUI + // 1: Type "13" to reset the config + // 2: Type "14" to get the config length + // 3: Type "16" to load the config + /* + if (readConfigLength()) + { + readConfig(); + _activateConfig(); + } + */ } void OnActivateConfig() @@ -201,22 +200,6 @@ uint8_t readUintFromEEPROM(volatile uint16_t *addreeprom) return atoi(params); } -// reads a string from EEPROM at given address which is ':' terminated and saves it in the nameBuffer -// once the nameBuffer is not needed anymore, just read until the ":" termination -> see function below -bool readNameFromEEPROM(uint16_t *addreeprom, char *buffer, uint16_t *addrbuffer) -{ - char temp = 0; - do { - temp = MFeeprom.read_char((*addreeprom)++); // read the first character - buffer[(*addrbuffer)++] = temp; // save character and locate next buffer position - if (*addrbuffer >= MEMLEN_NAMES_BUFFER) { // nameBuffer will be exceeded - return false; // abort copying from EEPROM to nameBuffer - } - } while (temp != ':'); // reads until limiter ':' and locates the next free buffer position - buffer[(*addrbuffer) - 1] = 0x00; // replace ':' by NULL, terminates the string - return true; -} - // reads the EEPRROM until end of command which ':' terminated bool readEndCommandFromEEPROM(uint16_t *addreeprom) { @@ -235,7 +218,6 @@ void readConfig() if (configLength == 0) // do nothing if no config is available return; uint16_t addreeprom = MEM_OFFSET_CONFIG; // define first memory location where config is saved in EEPROM - uint16_t addrbuffer = 0; // and start with first memory location from nameBuffer char params[6] = ""; char command = readUintFromEEPROM(&addreeprom); // read the first value from EEPROM, it's a device definition bool copy_success = true; // will be set to false if copying input names to nameBuffer exceeds array dimensions @@ -248,15 +230,15 @@ void readConfig() { switch (command) { case kTypeButton: - params[0] = readUintFromEEPROM(&addreeprom); // Pin number - Button::Add(params[0], &nameBuffer[addrbuffer]); // MUST be before readNameFromEEPROM because readNameFromEEPROM returns the pointer for the NEXT Name - copy_success = readNameFromEEPROM(&addreeprom, nameBuffer, &addrbuffer); // copy the NULL terminated name to nameBuffer and set to next free memory location + params[0] = readUintFromEEPROM(&addreeprom); // Pin number + Button::Add(params[0]); + copy_success = readEndCommandFromEEPROM(&addreeprom); break; case kTypeOutput: params[0] = readUintFromEEPROM(&addreeprom); // Pin number Output::Add(params[0]); - copy_success = readEndCommandFromEEPROM(&addreeprom); // check EEPROM until end of name + copy_success = readEndCommandFromEEPROM(&addreeprom); break; #if MF_SEGMENT_SUPPORT == 1 @@ -267,7 +249,7 @@ void readConfig() params[3] = readUintFromEEPROM(&addreeprom); // brightness params[4] = readUintFromEEPROM(&addreeprom); // number of modules LedSegment::Add(params[0], params[1], params[2], params[4], params[3]); - copy_success = readEndCommandFromEEPROM(&addreeprom); // check EEPROM until end of name + copy_success = readEndCommandFromEEPROM(&addreeprom); break; #endif @@ -280,7 +262,7 @@ void readConfig() params[3] = readUintFromEEPROM(&addreeprom); // Pin4 number params[4] = readUintFromEEPROM(&addreeprom); // Button number Stepper::Add(params[0], params[1], params[2], params[3], 0); - copy_success = readEndCommandFromEEPROM(&addreeprom); // check EEPROM until end of name + copy_success = readEndCommandFromEEPROM(&addreeprom); break; #endif @@ -292,7 +274,7 @@ void readConfig() params[3] = readUintFromEEPROM(&addreeprom); // Pin4 number params[4] = readUintFromEEPROM(&addreeprom); // Button number Stepper::Add(params[0], params[1], params[2], params[3], params[4]); - copy_success = readEndCommandFromEEPROM(&addreeprom); // check EEPROM until end of name + copy_success = readEndCommandFromEEPROM(&addreeprom); break; #endif @@ -300,25 +282,23 @@ void readConfig() case kTypeServo: params[0] = readUintFromEEPROM(&addreeprom); // Pin number Servos::Add(params[0]); - copy_success = readEndCommandFromEEPROM(&addreeprom); // check EEPROM until end of name + copy_success = readEndCommandFromEEPROM(&addreeprom); break; #endif case kTypeEncoderSingleDetent: - params[0] = readUintFromEEPROM(&addreeprom); // Pin1 number - params[1] = readUintFromEEPROM(&addreeprom); // Pin2 number - Encoder::Add(params[0], params[1], 0, &nameBuffer[addrbuffer]); // MUST be before readNameFromEEPROM because readNameFromEEPROM returns the pointer for the NEXT Name - copy_success = readNameFromEEPROM(&addreeprom, nameBuffer, &addrbuffer); // copy the NULL terminated name to nameBuffer and set to next free memory location - // copy_success = readEndCommandFromEEPROM(&addreeprom); // once the nameBuffer is not required anymore uncomment this line and delete the line before + params[0] = readUintFromEEPROM(&addreeprom); // Pin1 number + params[1] = readUintFromEEPROM(&addreeprom); // Pin2 number + Encoder::Add(params[0], params[1], 0); + copy_success = readEndCommandFromEEPROM(&addreeprom); break; case kTypeEncoder: - params[0] = readUintFromEEPROM(&addreeprom); // Pin1 number - params[1] = readUintFromEEPROM(&addreeprom); // Pin2 number - params[2] = readUintFromEEPROM(&addreeprom); // type - Encoder::Add(params[0], params[1], params[2], &nameBuffer[addrbuffer]); // MUST be before readNameFromEEPROM because readNameFromEEPROM returns the pointer for the NEXT Name - copy_success = readNameFromEEPROM(&addreeprom, nameBuffer, &addrbuffer); // copy the NULL terminated name to to nameBuffer and set to next free memory location - // copy_success = readEndCommandFromEEPROM(&addreeprom); // once the nameBuffer is not required anymore uncomment this line and delete the line before + params[0] = readUintFromEEPROM(&addreeprom); // Pin1 number + params[1] = readUintFromEEPROM(&addreeprom); // Pin2 number + params[2] = readUintFromEEPROM(&addreeprom); // type + Encoder::Add(params[0], params[1], params[2]); + copy_success = readEndCommandFromEEPROM(&addreeprom); break; #if MF_LCD_SUPPORT == 1 @@ -327,17 +307,16 @@ void readConfig() params[1] = readUintFromEEPROM(&addreeprom); // columns params[2] = readUintFromEEPROM(&addreeprom); // lines LCDDisplay::Add(params[0], params[1], params[2]); - copy_success = readEndCommandFromEEPROM(&addreeprom); // check EEPROM until end of name + copy_success = readEndCommandFromEEPROM(&addreeprom); break; #endif #if MF_ANALOG_SUPPORT == 1 case kTypeAnalogInput: - params[0] = readUintFromEEPROM(&addreeprom); // pin number - params[1] = readUintFromEEPROM(&addreeprom); // sensitivity - Analog::Add(params[0], &nameBuffer[addrbuffer], params[1]); // MUST be before readNameFromEEPROM because readNameFromEEPROM returns the pointer for the NEXT Name - copy_success = readNameFromEEPROM(&addreeprom, nameBuffer, &addrbuffer); // copy the NULL terminated name to to nameBuffer and set to next free memory location - // copy_success = readEndCommandFromEEPROM(&addreeprom); // once the nameBuffer is not required anymore uncomment this line and delete the line before + params[0] = readUintFromEEPROM(&addreeprom); // pin number + params[1] = readUintFromEEPROM(&addreeprom); // sensitivity + Analog::Add(params[0], params[1]); + copy_success = readEndCommandFromEEPROM(&addreeprom); break; #endif @@ -348,7 +327,7 @@ void readConfig() params[2] = readUintFromEEPROM(&addreeprom); // data Pin params[3] = readUintFromEEPROM(&addreeprom); // number of daisy chained modules OutputShifter::Add(params[0], params[1], params[2], params[3]); - copy_success = readEndCommandFromEEPROM(&addreeprom); // check EEPROM until end of name + copy_success = readEndCommandFromEEPROM(&addreeprom); break; #endif @@ -358,9 +337,8 @@ void readConfig() params[1] = readUintFromEEPROM(&addreeprom); // clock Pin params[2] = readUintFromEEPROM(&addreeprom); // data Pin params[3] = readUintFromEEPROM(&addreeprom); // number of daisy chained modules - InputShifter::Add(params[0], params[1], params[2], params[3], &nameBuffer[addrbuffer]); - copy_success = readNameFromEEPROM(&addreeprom, nameBuffer, &addrbuffer); // copy the NULL terminated name to to nameBuffer and set to next free memory location - // copy_success = readEndCommandFromEEPROM(&addreeprom); // 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 = readEndCommandFromEEPROM(&addreeprom); break; #endif @@ -387,10 +365,8 @@ void readConfig() params[4] = readUintFromEEPROM(&addreeprom); // Sel3 pin MUX.attach(params[1], params[2], params[3], params[4]); params[5] = readUintFromEEPROM(&addreeprom); // 8-bit registers (1-2) - DigInMux::Add(params[0], params[5], &nameBuffer[addrbuffer]); - copy_success = readNameFromEEPROM(&addreeprom, nameBuffer, &addrbuffer); - - // cmdMessenger.sendCmd(kDebug, F("Mux loaded")); + DigInMux::Add(params[0], params[5]); + copy_success = readEndCommandFromEEPROM(&addreeprom); break; #endif @@ -399,8 +375,7 @@ void readConfig() } command = readUintFromEEPROM(&addreeprom); } 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) { // too much/long names for input devices cmdMessenger.sendCmd(kStatus, F("Failure on reading config")); } } diff --git a/src/MF_Analog/Analog.cpp b/src/MF_Analog/Analog.cpp index 70a186cb..a3a44228 100644 --- a/src/MF_Analog/Analog.cpp +++ b/src/MF_Analog/Analog.cpp @@ -14,15 +14,15 @@ namespace Analog MFAnalog *analog[MAX_ANALOG_INPUTS]; uint8_t analogRegistered = 0; - void handlerOnAnalogChange(int value, uint8_t pin, const char *name) + void handlerOnAnalogChange(int16_t value, uint8_t deviceID) { cmdMessenger.sendCmdStart(kAnalogChange); - cmdMessenger.sendCmdArg(name); + cmdMessenger.sendCmdArg(deviceID); cmdMessenger.sendCmdArg(value); cmdMessenger.sendCmdEnd(); }; - void Add(uint8_t pin, char const *name, uint8_t sensitivity) + void Add(uint8_t pin, uint8_t sensitivity) { if (analogRegistered == MAX_ANALOG_INPUTS) return; @@ -32,7 +32,7 @@ namespace Analog cmdMessenger.sendCmd(kStatus, F("AnalogIn does not fit in Memory")); return; } - analog[analogRegistered] = new (allocateMemory(sizeof(MFAnalog))) MFAnalog(pin, name, sensitivity); + analog[analogRegistered] = new (allocateMemory(sizeof(MFAnalog))) MFAnalog(pin, analogRegistered, sensitivity); MFAnalog::attachHandler(handlerOnAnalogChange); analogRegistered++; #ifdef DEBUG2CMDMESSENGER diff --git a/src/MF_Analog/Analog.h b/src/MF_Analog/Analog.h index 61fb0f5f..33790d37 100644 --- a/src/MF_Analog/Analog.h +++ b/src/MF_Analog/Analog.h @@ -9,7 +9,7 @@ #include namespace Analog { - void Add(uint8_t pin, char const *name = "AnalogInput", uint8_t sensitivity = 3); + void Add(uint8_t pin, uint8_t sensitivity); void Clear(); void read(); void readAverage(); diff --git a/src/MF_Analog/MFAnalog.cpp b/src/MF_Analog/MFAnalog.cpp index 473c6700..68faeb10 100644 --- a/src/MF_Analog/MFAnalog.cpp +++ b/src/MF_Analog/MFAnalog.cpp @@ -8,11 +8,11 @@ analogEvent MFAnalog::_handler = NULL; -MFAnalog::MFAnalog(uint8_t pin, const char *name, uint8_t sensitivity) +MFAnalog::MFAnalog(uint8_t pin, uint8_t deviceID, uint8_t sensitivity) { _sensitivity = sensitivity; _pin = pin; - _name = name; + _deviceID = deviceID; pinMode(_pin, INPUT_PULLUP); // set pin to input. Could use OUTPUT for analog, but shows the intention :-) // Fill averaging buffers with initial reading for (uint8_t i = 0; i < ADC_MAX_AVERAGE; i++) { @@ -33,7 +33,7 @@ void MFAnalog::readChannel(uint8_t alwaysTrigger) if (alwaysTrigger || valueHasChanged(newValue)) { _lastValue = newValue; if (_handler != NULL) { - (*_handler)(_lastValue, _pin, _name); + (*_handler)(_lastValue, _deviceID); } } } diff --git a/src/MF_Analog/MFAnalog.h b/src/MF_Analog/MFAnalog.h index b6256e5c..78e02954 100644 --- a/src/MF_Analog/MFAnalog.h +++ b/src/MF_Analog/MFAnalog.h @@ -13,7 +13,7 @@ extern "C" { // callback functions -typedef void (*analogEvent)(int, uint8_t, const char *); +typedef void (*analogEvent)(int, uint8_t); }; ///////////////////////////////////////////////////////////////////// @@ -21,7 +21,7 @@ typedef void (*analogEvent)(int, uint8_t, const char *); class MFAnalog { public: - MFAnalog(uint8_t pin = 1, const char *name = "Analog Input", uint8_t sensitivity = 2); + MFAnalog(uint8_t pin, uint8_t deviceID, uint8_t sensitivity); static void attachHandler(analogEvent handler); void update(); void retrigger(); @@ -31,8 +31,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 diff --git a/src/MF_Button/Button.cpp b/src/MF_Button/Button.cpp index 8c767882..13eecb35 100644 --- a/src/MF_Button/Button.cpp +++ b/src/MF_Button/Button.cpp @@ -13,15 +13,15 @@ namespace Button MFButton *buttons[MAX_BUTTONS]; uint8_t buttonsRegistered = 0; - void handlerOnButton(uint8_t eventId, uint8_t pin, const char *name) + void handlerOnButton(uint8_t eventId, uint8_t deviceID) { cmdMessenger.sendCmdStart(kButtonChange); - cmdMessenger.sendCmdArg(name); + cmdMessenger.sendCmdArg(deviceID); cmdMessenger.sendCmdArg(eventId); cmdMessenger.sendCmdEnd(); }; - void Add(uint8_t pin, char const *name) + void Add(uint8_t pin) { if (buttonsRegistered == MAX_BUTTONS) return; @@ -31,7 +31,7 @@ namespace Button cmdMessenger.sendCmd(kStatus, F("Button does not fit in Memory")); return; } - buttons[buttonsRegistered] = new (allocateMemory(sizeof(MFButton))) MFButton(pin, name); + buttons[buttonsRegistered] = new (allocateMemory(sizeof(MFButton))) MFButton(pin, buttonsRegistered); MFButton::attachHandler(handlerOnButton); buttonsRegistered++; #ifdef DEBUG2CMDMESSENGER diff --git a/src/MF_Button/Button.h b/src/MF_Button/Button.h index 1d52fb6a..c5d43af3 100644 --- a/src/MF_Button/Button.h +++ b/src/MF_Button/Button.h @@ -10,7 +10,7 @@ namespace Button { - void Add(uint8_t pin, char const *name = "Button"); + void Add(uint8_t pin); void Clear(); void read(); void OnTrigger(); diff --git a/src/MF_Button/MFButton.cpp b/src/MF_Button/MFButton.cpp index 1a80e17e..37f4768a 100644 --- a/src/MF_Button/MFButton.cpp +++ b/src/MF_Button/MFButton.cpp @@ -8,12 +8,12 @@ buttonEvent MFButton::_handler = NULL; -MFButton::MFButton(uint8_t pin, const char *name) +MFButton::MFButton(uint8_t pin, uint8_t deviceID) { - _pin = pin; - _name = name; - pinMode(_pin, INPUT_PULLUP); // set pin to input - _state = digitalRead(_pin); // initialize on actual status + _pin = pin; + _deviceID = deviceID; + pinMode(_pin, INPUT_PULLUP); // set pin to input + _state = digitalRead(_pin); // initialize on actual status } void MFButton::update() @@ -33,14 +33,14 @@ void MFButton::trigger(uint8_t state) void MFButton::triggerOnPress() { if (_handler && _state == LOW) { - (*_handler)(btnOnPress, _pin, _name); + (*_handler)(btnOnPress, _deviceID); } } void MFButton::triggerOnRelease() { if (_handler && _state == HIGH) { - (*_handler)(btnOnRelease, _pin, _name); + (*_handler)(btnOnRelease, _deviceID); } } diff --git a/src/MF_Button/MFButton.h b/src/MF_Button/MFButton.h index 87386e20..55805e71 100644 --- a/src/MF_Button/MFButton.h +++ b/src/MF_Button/MFButton.h @@ -10,7 +10,7 @@ extern "C" { // callback functions always follow the signature: void cmd(void); -typedef void (*buttonEvent)(byte, uint8_t, const char *); +typedef void (*buttonEvent)(uint8_t, uint8_t); }; enum { @@ -23,13 +23,13 @@ enum { class MFButton { public: - MFButton(uint8_t pin = 1, const char *name = "Button"); + MFButton(uint8_t pin, uint8_t deviceID); static void attachHandler(buttonEvent newHandler); void update(); void trigger(uint8_t state); void triggerOnPress(); void triggerOnRelease(); - const char *_name; + uint8_t _deviceID; uint8_t _pin; private: diff --git a/src/MF_Encoder/Encoder.cpp b/src/MF_Encoder/Encoder.cpp index 46edd649..fafd2575 100644 --- a/src/MF_Encoder/Encoder.cpp +++ b/src/MF_Encoder/Encoder.cpp @@ -13,15 +13,15 @@ namespace Encoder MFEncoder *encoders[MAX_ENCODERS]; uint8_t encodersRegistered = 0; - void handlerOnEncoder(uint8_t eventId, uint8_t pin, const char *name) + void handlerOnEncoder(uint8_t eventId, uint8_t deviceID) { cmdMessenger.sendCmdStart(kEncoderChange); - cmdMessenger.sendCmdArg(name); + cmdMessenger.sendCmdArg(deviceID); cmdMessenger.sendCmdArg(eventId); cmdMessenger.sendCmdEnd(); }; - void Add(uint8_t pin1, uint8_t pin2, uint8_t encoder_type, char const *name) + void Add(uint8_t pin1, uint8_t pin2, uint8_t encoder_type) { if (encodersRegistered == MAX_ENCODERS) return; @@ -32,7 +32,7 @@ namespace Encoder return; } encoders[encodersRegistered] = new (allocateMemory(sizeof(MFEncoder))) MFEncoder; - encoders[encodersRegistered]->attach(pin1, pin2, encoder_type, name); + encoders[encodersRegistered]->attach(pin1, pin2, encoder_type, encodersRegistered); MFEncoder::attachHandler(handlerOnEncoder); encodersRegistered++; #ifdef DEBUG2CMDMESSENGER diff --git a/src/MF_Encoder/Encoder.h b/src/MF_Encoder/Encoder.h index 20290802..0fa28267 100644 --- a/src/MF_Encoder/Encoder.h +++ b/src/MF_Encoder/Encoder.h @@ -9,7 +9,7 @@ namespace Encoder { - void Add(uint8_t pin1 = 1, uint8_t pin2 = 2, uint8_t encoder_type = 0, char const *name = "Encoder"); + void Add(uint8_t pin1 = 1, uint8_t pin2 = 2, uint8_t encoder_type = 0); void Clear(); void read(); } diff --git a/src/MF_Encoder/MFEncoder.cpp b/src/MF_Encoder/MFEncoder.cpp index 590d220f..62b9df93 100644 --- a/src/MF_Encoder/MFEncoder.cpp +++ b/src/MF_Encoder/MFEncoder.cpp @@ -60,10 +60,10 @@ MFEncoder::MFEncoder() _initialized = false; } -void MFEncoder::attach(uint8_t pin1, uint8_t pin2, uint8_t TypeEncoder, const char *name) +void MFEncoder::attach(uint8_t pin1, uint8_t pin2, uint8_t TypeEncoder, uint8_t deviceID) { _pos = 0; - _name = name; + _deviceID = deviceID; _pin1 = pin1; _pin2 = pin2; _encoderType = encoderTypes[TypeEncoder]; @@ -103,16 +103,16 @@ void MFEncoder::update() if (abs(delta) < (MF_ENC_FAST_LIMIT)) { // slow turn detected if (dir) { - (*_handler)(encLeft, _pin1, _name); + (*_handler)(encLeft, _deviceID); } else { - (*_handler)(encRight, _pin2, _name); + (*_handler)(encRight, _deviceID); } } else { // fast turn detected if (dir) { - (*_handler)(encLeftFast, _pin1, _name); + (*_handler)(encLeftFast, _deviceID); } else { - (*_handler)(encRightFast, _pin2, _name); + (*_handler)(encRightFast, _deviceID); } } } @@ -132,7 +132,7 @@ void MFEncoder::tick(void) int _speed = 0; uint32_t currentMs = millis(); - int8_t thisState = sig1 | (sig2 << 1); + int8_t thisState = sig1 | (sig2 << 1); if (currentMs - _lastFastDec > 100 && _detentCounter > 1) { _lastFastDec = currentMs; diff --git a/src/MF_Encoder/MFEncoder.h b/src/MF_Encoder/MFEncoder.h index 0cb0db39..90991883 100644 --- a/src/MF_Encoder/MFEncoder.h +++ b/src/MF_Encoder/MFEncoder.h @@ -20,7 +20,7 @@ #include extern "C" { -typedef void (*encoderEvent)(uint8_t, uint8_t, const char *); +typedef void (*encoderEvent)(uint8_t, uint8_t); }; // this prevents the internal position overflow. @@ -38,7 +38,7 @@ enum { typedef struct { // Detent positions in the quadrature (by value, not position) - bool detents[4]; + bool detents[4]; // Bit shift to apply given the detent resolution of this encoder. // @@ -53,21 +53,21 @@ class MFEncoder public: MFEncoder(); static void attachHandler(encoderEvent newHandler); - void attach(uint8_t pin1, uint8_t pin2, uint8_t TypeEncoder, const char *name = "Encoder"); + void attach(uint8_t pin1, uint8_t pin2, uint8_t TypeEncoder, uint8_t deviceID); void update(); // call this function every some milliseconds or by using an interrupt for handling state changes of the rotary encoder. - void tick(void); + void tick(void); // retrieve the current position - int16_t getPosition(); + int16_t getPosition(); // adjust the current position - void setPosition(int16_t newPosition); + void setPosition(int16_t newPosition); private: static encoderEvent _handler; uint8_t _pin1; uint8_t _pin2; bool _initialized; - const char *_name; + uint8_t _deviceID; int16_t _pos; uint8_t _TypeEncoder; uint8_t _detentCounter; diff --git a/src/MF_InputShifter/InputShifter.cpp b/src/MF_InputShifter/InputShifter.cpp index cedf9429..4334d4f6 100644 --- a/src/MF_InputShifter/InputShifter.cpp +++ b/src/MF_InputShifter/InputShifter.cpp @@ -13,16 +13,16 @@ namespace InputShifter MFInputShifter *inputShifters[MAX_INPUT_SHIFTERS]; uint8_t inputShiftersRegistered = 0; - void handlerInputShifterOnChange(uint8_t eventId, uint8_t pin, const char *name) + void handlerInputShifterOnChange(uint8_t eventId, uint8_t pin, uint8_t deviceID) { cmdMessenger.sendCmdStart(kInputShifterChange); - cmdMessenger.sendCmdArg(name); + cmdMessenger.sendCmdArg(deviceID); cmdMessenger.sendCmdArg(pin); cmdMessenger.sendCmdArg(eventId); cmdMessenger.sendCmdEnd(); }; - void Add(uint8_t latchPin, uint8_t clockPin, uint8_t dataPin, uint8_t modules, char const *name) + void Add(uint8_t latchPin, uint8_t clockPin, uint8_t dataPin, uint8_t modules) { if (inputShiftersRegistered == MAX_INPUT_SHIFTERS) return; @@ -32,7 +32,7 @@ namespace InputShifter return; } inputShifters[inputShiftersRegistered] = new (allocateMemory(sizeof(MFInputShifter))) MFInputShifter; - inputShifters[inputShiftersRegistered]->attach(latchPin, clockPin, dataPin, modules, name); + inputShifters[inputShiftersRegistered]->attach(latchPin, clockPin, dataPin, modules, inputShiftersRegistered); MFInputShifter::attachHandler(handlerInputShifterOnChange); inputShiftersRegistered++; #ifdef DEBUG2CMDMESSENGER diff --git a/src/MF_InputShifter/InputShifter.h b/src/MF_InputShifter/InputShifter.h index b28a4e9c..f4773400 100644 --- a/src/MF_InputShifter/InputShifter.h +++ b/src/MF_InputShifter/InputShifter.h @@ -9,7 +9,7 @@ namespace InputShifter { - void Add(uint8_t latchPin, uint8_t clockPin, uint8_t dataPin, uint8_t modules, char const *name = "InputShifter"); + void Add(uint8_t latchPin, uint8_t clockPin, uint8_t dataPin, uint8_t modules); void Clear(); // void OnInit(); // this is defined but not used!? void read(); diff --git a/src/MF_InputShifter/MFInputShifter.cpp b/src/MF_InputShifter/MFInputShifter.cpp index 0cdb994c..25fc8141 100644 --- a/src/MF_InputShifter/MFInputShifter.cpp +++ b/src/MF_InputShifter/MFInputShifter.cpp @@ -8,20 +8,19 @@ inputShifterEvent MFInputShifter::_inputHandler = NULL; -MFInputShifter::MFInputShifter(const char *name) +MFInputShifter::MFInputShifter() { _initialized = false; - _name = name; } // Registers a new input shifter and configures the clock, data and latch pins as well // as the number of modules to read from. -void MFInputShifter::attach(uint8_t latchPin, uint8_t clockPin, uint8_t dataPin, uint8_t moduleCount, const char *name) +void MFInputShifter::attach(uint8_t latchPin, uint8_t clockPin, uint8_t dataPin, uint8_t moduleCount, uint8_t deviceID) { _latchPin = latchPin; _clockPin = clockPin; _dataPin = dataPin; - _name = name; + _deviceID = deviceID; _moduleCount = moduleCount; pinMode(_latchPin, OUTPUT); @@ -123,7 +122,7 @@ void MFInputShifter::retrigger() void MFInputShifter::trigger(uint8_t pin, bool state) { if (!_inputHandler) return; - (*_inputHandler)((state == LOW ? inputShifterOnPress : inputShifterOnRelease), pin, _name); + (*_inputHandler)((state == LOW ? inputShifterOnPress : inputShifterOnRelease), pin, _deviceID); } // Attaches a new event handler for the specified event. diff --git a/src/MF_InputShifter/MFInputShifter.h b/src/MF_InputShifter/MFInputShifter.h index c2b5cbcc..a8f0a8d3 100644 --- a/src/MF_InputShifter/MFInputShifter.h +++ b/src/MF_InputShifter/MFInputShifter.h @@ -14,7 +14,7 @@ #define MAX_CHAINED_INPUT_SHIFTERS 4 extern "C" { -typedef void (*inputShifterEvent)(byte, uint8_t, const char *); +typedef void (*inputShifterEvent)(byte, uint8_t, uint8_t); }; enum { @@ -25,8 +25,8 @@ enum { class MFInputShifter { public: - MFInputShifter(const char *name = "InputShifter"); - void attach(uint8_t latchPin, uint8_t clockPin, uint8_t dataPin, uint8_t moduleCount, const char *name); + MFInputShifter(); + void attach(uint8_t latchPin, uint8_t clockPin, uint8_t dataPin, uint8_t moduleCount, uint8_t deviceID); static void attachHandler(inputShifterEvent newHandler); void clear(); void detach(); @@ -37,13 +37,13 @@ class MFInputShifter enum { DONT_TRIGGER = 0, DO_TRIGGER = 1 }; - const char *_name; - uint8_t _latchPin; // SH/~LD (latch) pin - uint8_t _clockPin; // CLK (clock) pin - uint8_t _dataPin; // SDO (data) pin - uint8_t _moduleCount; // Number of 8 bit modules in series. - bool _initialized = false; - uint8_t _lastState[MAX_CHAINED_INPUT_SHIFTERS] = {0}; + uint8_t _deviceID; + uint8_t _latchPin; // SH/~LD (latch) pin + uint8_t _clockPin; // CLK (clock) pin + uint8_t _dataPin; // SDO (data) pin + uint8_t _moduleCount; // Number of 8 bit modules in series. + bool _initialized = false; + uint8_t _lastState[MAX_CHAINED_INPUT_SHIFTERS] = {0}; void poll(uint8_t doTrigger); void detectChanges(uint8_t lastState, uint8_t currentState, uint8_t module); From 800a3823ba7837f294a44dbc76b268d07d7bd94e Mon Sep 17 00:00:00 2001 From: elral <3263285+elral@users.noreply.github.com> Date: Thu, 10 Nov 2022 11:56:35 +0100 Subject: [PATCH 02/15] add InputMultiplexer w/ deviceID instead of name --- src/MF_DigInMux/DigInMux.cpp | 10 +++++----- src/MF_DigInMux/DigInMux.h | 2 +- src/MF_DigInMux/MFDigInMux.cpp | 14 ++++++-------- src/MF_DigInMux/MFDigInMux.h | 14 +++++++------- 4 files changed, 19 insertions(+), 21 deletions(-) diff --git a/src/MF_DigInMux/DigInMux.cpp b/src/MF_DigInMux/DigInMux.cpp index 1f6d2af9..271327aa 100644 --- a/src/MF_DigInMux/DigInMux.cpp +++ b/src/MF_DigInMux/DigInMux.cpp @@ -15,23 +15,23 @@ namespace DigInMux MFDigInMux *digInMux[MAX_DIGIN_MUX]; uint8_t digInMuxRegistered = 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(); }; - void Add(uint8_t dataPin, uint8_t nRegs, char const *name) + void Add(uint8_t dataPin, uint8_t nRegs) { if (digInMuxRegistered == MAX_DIGIN_MUX) return; MFDigInMux *dip; - dip = new (allocateMemory(sizeof(MFDigInMux))) MFDigInMux(&MUX, name); + dip = new (allocateMemory(sizeof(MFDigInMux))) MFDigInMux(&MUX); digInMux[digInMuxRegistered] = dip; - dip->attach(dataPin, (nRegs == 1), name); + dip->attach(dataPin, (nRegs == 1), digInMuxRegistered); dip->clear(); // MFDigInMux::setMux(&MUX); MFDigInMux::attachHandler(handlerOnDigInMux); diff --git a/src/MF_DigInMux/DigInMux.h b/src/MF_DigInMux/DigInMux.h index 7a6624bd..0e1894e2 100644 --- a/src/MF_DigInMux/DigInMux.h +++ b/src/MF_DigInMux/DigInMux.h @@ -10,7 +10,7 @@ namespace DigInMux { - 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(); diff --git a/src/MF_DigInMux/MFDigInMux.cpp b/src/MF_DigInMux/MFDigInMux.cpp index c82f0883..0d44d03f 100644 --- a/src/MF_DigInMux/MFDigInMux.cpp +++ b/src/MF_DigInMux/MFDigInMux.cpp @@ -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; @@ -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); @@ -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. diff --git a/src/MF_DigInMux/MFDigInMux.h b/src/MF_DigInMux/MFDigInMux.h index 19896674..168af3ed 100644 --- a/src/MF_DigInMux/MFDigInMux.h +++ b/src/MF_DigInMux/MFDigInMux.h @@ -10,7 +10,7 @@ #include "MFMuxDriver.h" extern "C" { -typedef void (*MuxDigInEvent)(byte, uint8_t, const char *); +typedef void (*MuxDigInEvent)(byte, uint8_t, uint8_t); }; enum { @@ -22,11 +22,11 @@ class MFDigInMux { public: MFDigInMux(void); - MFDigInMux(MFMuxDriver *MUX, const char *name); + MFDigInMux(MFMuxDriver *MUX); static void setMux(MFMuxDriver *MUX); static void attachHandler(MuxDigInEvent newHandler); - void attach(uint8_t dataPin, bool halfSize, char const *name); + void attach(uint8_t dataPin, bool halfSize, uint8_t deviceID); void detach(); void clear(); void retrigger(); @@ -44,10 +44,10 @@ class MFDigInMux static MFMuxDriver *_MUX; static MuxDigInEvent _inputHandler; - const char *_name; - uint8_t _dataPin; // Data pin - MUX common, input to AVR - uint8_t _flags; - uint16_t _lastState; + uint8_t _deviceID; + uint8_t _dataPin; // Data pin - MUX common, input to AVR + uint8_t _flags; + uint16_t _lastState; void poll(bool detect); void detectChanges(uint16_t lastState, uint16_t currentState); From fe43697f8530c74e5bf1719757d11e99eb7dd52a Mon Sep 17 00:00:00 2001 From: elral <3263285+elral@users.noreply.github.com> Date: Thu, 10 Nov 2022 12:08:35 +0100 Subject: [PATCH 03/15] change name into deviceID for the handler defin. --- src/MF_Modules/MFMuxDriver.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MF_Modules/MFMuxDriver.h b/src/MF_Modules/MFMuxDriver.h index 4cd39971..d948e0e8 100644 --- a/src/MF_Modules/MFMuxDriver.h +++ b/src/MF_Modules/MFMuxDriver.h @@ -9,7 +9,7 @@ #include extern "C" { -typedef void (*MuxDigInEvent)(byte, uint8_t, const char *); +typedef void (*MuxDigInEvent)(byte, uint8_t, uint8_t); }; class MFMuxDriver From 02a5808d1ecc8b0b5ac19a918c7b14073d673884 Mon Sep 17 00:00:00 2001 From: elral <3263285+elral@users.noreply.github.com> Date: Fri, 11 Nov 2022 13:46:19 +0100 Subject: [PATCH 04/15] delete double define of Mux handler --- src/MF_Modules/MFMuxDriver.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/MF_Modules/MFMuxDriver.h b/src/MF_Modules/MFMuxDriver.h index d948e0e8..cb3bee72 100644 --- a/src/MF_Modules/MFMuxDriver.h +++ b/src/MF_Modules/MFMuxDriver.h @@ -8,10 +8,6 @@ #include -extern "C" { -typedef void (*MuxDigInEvent)(byte, uint8_t, uint8_t); -}; - class MFMuxDriver { public: From 53ac8e89170c5e9d33633fc62f71bbf082814184 Mon Sep 17 00:00:00 2001 From: elral <3263285+elral@users.noreply.github.com> Date: Tue, 6 Dec 2022 07:20:12 +0100 Subject: [PATCH 05/15] deactivate config if reading from EEPROM fails --- src/Config.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Config.cpp b/src/Config.cpp index 77064642..989d1dda 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -375,7 +375,8 @@ void readConfig() } command = readUintFromEEPROM(&addreeprom); } while (command && copy_success); - if (!copy_success) { // too much/long names for input devices + 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")); } } From 80b3273168767f87466bc4635c1cf8b575f0a5e8 Mon Sep 17 00:00:00 2001 From: elral <3263285+elral@users.noreply.github.com> Date: Tue, 6 Dec 2022 08:03:08 +0100 Subject: [PATCH 06/15] correct comment for variable copy_success --- src/Config.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Config.cpp b/src/Config.cpp index 77064642..49f08457 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -220,8 +220,7 @@ void readConfig() uint16_t addreeprom = MEM_OFFSET_CONFIG; // define first memory location where config is saved in EEPROM char params[6] = ""; char command = readUintFromEEPROM(&addreeprom); // read the first value from EEPROM, it's a device definition - bool copy_success = true; // will be set to false if copying input names to nameBuffer exceeds array dimensions - // not required anymore when pins instead of names are transferred to the UI + bool copy_success = true; // will be set to false if reading from eeprom exceeds size if (command == 0) // just to be sure, configLength should also be 0 return; From fab649d3d748ea524c81b64083581bde684ec420 Mon Sep 17 00:00:00 2001 From: elral <3263285+elral@users.noreply.github.com> Date: Mon, 12 Dec 2022 10:04:17 +0100 Subject: [PATCH 07/15] new handler ID's for inputs to differ from old way --- src/commandmessenger.h | 83 ++++++++++++++++++++++++------------------ 1 file changed, 48 insertions(+), 35 deletions(-) diff --git a/src/commandmessenger.h b/src/commandmessenger.h index 855286a4..4aa4be50 100644 --- a/src/commandmessenger.h +++ b/src/commandmessenger.h @@ -12,42 +12,55 @@ // In order to receive, attach a callback function to these events enum { - kInitModule, // 0 - kSetModule, // 1 - kSetPin, // 2 - kSetStepper, // 3 - kSetServo, // 4 - kStatus, // 5, Command to report status - kEncoderChange, // 6 - kButtonChange, // 7 - kStepperChange, // 8 - kGetInfo, // 9 - kInfo, // 10 - kSetConfig, // 11 - kGetConfig, // 12 - kResetConfig, // 13 - kSaveConfig, // 14 - kConfigSaved, // 15 - kActivateConfig, // 16 - kConfigActivated, // 17 - kSetPowerSavingMode, // 18 - kSetName, // 19 - kGenNewSerial, // 20 - kResetStepper, // 21 - kSetZeroStepper, // 22 - kTrigger, // 23 - kResetBoard, // 24 - kSetLcdDisplayI2C, // 25 - kSetModuleBrightness, // 26 - kSetShiftRegisterPins, // 27 - kAnalogChange, // 28 - kInputShifterChange, // 29 - kDigInMuxChange, // 30 - kDebug = 0xFF // 255 + kInitModule, // 0 + kSetModule, // 1 + kSetPin, // 2 + kSetStepper, // 3 + kSetServo, // 4 + kStatus, // 5, Command to report status + kEncoderChangeDeprecated, // 6 + kButtonChangeDeprecated, // 7 + kStepperChange, // 8 + kGetInfo, // 9 + kInfo, // 10 + kSetConfig, // 11 + kGetConfig, // 12 + kResetConfig, // 13 + kSaveConfig, // 14 + kConfigSaved, // 15 + kActivateConfig, // 16 + kConfigActivated, // 17 + kSetPowerSavingMode, // 18 + kSetName, // 19 + kGenNewSerial, // 20 + kResetStepper, // 21 + kSetZeroStepper, // 22 + kTrigger, // 23 + kResetBoard, // 24 + kSetLcdDisplayI2C, // 25 + kSetModuleBrightness, // 26 + kSetShiftRegisterPins, // 27 + kAnalogChangeDeprecated, // 28 + kInputShifterChangeDeprecated, // 29 + kDigInMuxChangeDeprecated, // 30 + + // functions which get be called from the UI via the command messenger + // must be added before. The command messenger has a fix buffer size + // for the functions which defined by MAXCALLBACKS=30. + // ------------------------------------------------------------------- + // new handler ID's for input devices must be added here + // This will save size of the Callback buffer + kButtonChange = 100, // 100 + kEncoderChange, // 101 + kAnalogChange, // 102 + kInputShifterChange, // 103 + kInputShifterChange, // 104 + kDigInMuxChange, // 105 + kDebug = 0xFF // 255 }; -void attachCommandCallbacks(); -uint32_t getLastCommandMillis(); -void setLastCommandMillis(); +void attachCommandCallbacks(); +uint32_t getLastCommandMillis(); +void setLastCommandMillis(); extern CmdMessenger cmdMessenger; \ No newline at end of file From eb11e8b23bfa2a3d38db7ad42dc72d34b637d25f Mon Sep 17 00:00:00 2001 From: elral <3263285+elral@users.noreply.github.com> Date: Mon, 12 Dec 2022 15:32:04 +0100 Subject: [PATCH 08/15] double definition for input shifter change deleted --- src/commandmessenger.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/commandmessenger.h b/src/commandmessenger.h index 4aa4be50..84cbc816 100644 --- a/src/commandmessenger.h +++ b/src/commandmessenger.h @@ -54,8 +54,7 @@ enum { kEncoderChange, // 101 kAnalogChange, // 102 kInputShifterChange, // 103 - kInputShifterChange, // 104 - kDigInMuxChange, // 105 + kDigInMuxChange, // 104 kDebug = 0xFF // 255 }; From e5faee94d683af6a2088b3ec37a02512ad9b7ffa Mon Sep 17 00:00:00 2001 From: elral <3263285+elral@users.noreply.github.com> Date: Wed, 14 Dec 2022 09:08:31 +0100 Subject: [PATCH 09/15] deleted unused variable --- src/Config.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Config.cpp b/src/Config.cpp index a96e6ca6..734d3283 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -72,7 +72,6 @@ void _activateConfig(); // reads the EEPROM until NUL terminator and returns the number of characters incl. terminator, starting from given address bool readConfigLength() { - char temp = 0; uint16_t addreeprom = MEM_OFFSET_CONFIG; uint16_t length = MFeeprom.get_length(); configLength = 0; From 925171515a6234663a0f820853a5ced3e053722b Mon Sep 17 00:00:00 2001 From: elral <3263285+elral@users.noreply.github.com> Date: Wed, 24 May 2023 08:50:21 +0200 Subject: [PATCH 10/15] delete array for namebuffer, cleanup of EEPROM defines --- _Boards/Atmel/Board_Mega/MFBoards.h | 3 +- _Boards/Atmel/Board_Nano/MFBoards.h | 3 +- _Boards/Atmel/Board_ProMicro/MFBoards.h | 3 +- _Boards/Atmel/Board_Uno/MFBoards.h | 3 +- _Boards/RaspberryPi/Pico/MFBoards.h | 2 +- src/Config.cpp | 38 +++++++++++++------------ 6 files changed, 25 insertions(+), 27 deletions(-) diff --git a/_Boards/Atmel/Board_Mega/MFBoards.h b/_Boards/Atmel/Board_Mega/MFBoards.h index d97fd4b3..5aead797 100644 --- a/_Boards/Atmel/Board_Mega/MFBoards.h +++ b/_Boards/Atmel/Board_Mega/MFBoards.h @@ -52,8 +52,7 @@ #define MOBIFLIGHT_SERIAL "1234567890" #define MOBIFLIGHT_NAME "MobiFlight Mega" #define EEPROM_SIZE 4096 // EEPROMSizeMega -#define MEMLEN_CONFIG 1496 // max. size for config which wil be stored in EEPROM -#define MEMLEN_NAMES_BUFFER 1000 // max. size for configBuffer, contains only names from inputs +#define MEM_LEN_CONFIG 1496 // max. size for config which wil be stored in EEPROM, must be less than (EEPROM_SIZE - (MEM_OFFSET_NAME + MEM_LEN_NAME + MEM_LEN_SERIAL)) #define MF_MAX_DEVICEMEM 1500 // max. memory size for devices diff --git a/_Boards/Atmel/Board_Nano/MFBoards.h b/_Boards/Atmel/Board_Nano/MFBoards.h index 0137e75d..fa65995d 100644 --- a/_Boards/Atmel/Board_Nano/MFBoards.h +++ b/_Boards/Atmel/Board_Nano/MFBoards.h @@ -56,8 +56,7 @@ #define MOBIFLIGHT_SERIAL "0987654321" #define MOBIFLIGHT_NAME "MobiFlight Nano" #define EEPROM_SIZE 1024 // EEPROMSizeUno -#define MEMLEN_CONFIG 286 // max. size for config which wil be stored in EEPROM -#define MEMLEN_NAMES_BUFFER 220 // max. size for configBuffer, contains only names from inputs +#define MEM_LEN_CONFIG 286 // max. size for config which wil be stored in EEPROM, must be less than (EEPROM_SIZE - (MEM_OFFSET_NAME + MEM_LEN_NAME + MEM_LEN_SERIAL)) #define MF_MAX_DEVICEMEM 300 // max. memory size for devices diff --git a/_Boards/Atmel/Board_ProMicro/MFBoards.h b/_Boards/Atmel/Board_ProMicro/MFBoards.h index ab843239..23f3c98f 100644 --- a/_Boards/Atmel/Board_ProMicro/MFBoards.h +++ b/_Boards/Atmel/Board_ProMicro/MFBoards.h @@ -52,8 +52,7 @@ #define MOBIFLIGHT_SERIAL "0987654321" #define MOBIFLIGHT_NAME "MobiFlight Micro" #define EEPROM_SIZE 1024 // EEPROMSizeMicro -#define MEMLEN_CONFIG 440 // max. size for config which wil be stored in EEPROM -#define MEMLEN_NAMES_BUFFER 350 // max. size for configBuffer, contains only names from inputs +#define MEM_LEN_CONFIG 440 // max. size for config which wil be stored in EEPROM, must be less than (EEPROM_SIZE - (MEM_OFFSET_NAME + MEM_LEN_NAME + MEM_LEN_SERIAL)) #define MF_MAX_DEVICEMEM 400 // max. memory size for devices diff --git a/_Boards/Atmel/Board_Uno/MFBoards.h b/_Boards/Atmel/Board_Uno/MFBoards.h index f8b050cb..f5a6bff3 100644 --- a/_Boards/Atmel/Board_Uno/MFBoards.h +++ b/_Boards/Atmel/Board_Uno/MFBoards.h @@ -52,8 +52,7 @@ #define MOBIFLIGHT_SERIAL "0987654321" #define MOBIFLIGHT_NAME "MobiFlight Uno" #define EEPROM_SIZE 1024 // EEPROMSizeUno -#define MEMLEN_CONFIG 286 // max. size for config which wil be stored in EEPROM -#define MEMLEN_NAMES_BUFFER 220 // max. size for configBuffer, contains only names from inputs +#define MEM_LEN_CONFIG 286 // max. size for config which wil be stored in EEPROM, must be less than (MEM_OFFSET_NAME + EEPROM_SIZE - (MEM_LEN_NAME + MEM_LEN_SERIAL)) #define MF_MAX_DEVICEMEM 300 // max. memory size for devices diff --git a/_Boards/RaspberryPi/Pico/MFBoards.h b/_Boards/RaspberryPi/Pico/MFBoards.h index 211cb266..05f1266d 100644 --- a/_Boards/RaspberryPi/Pico/MFBoards.h +++ b/_Boards/RaspberryPi/Pico/MFBoards.h @@ -50,7 +50,7 @@ #define MOBIFLIGHT_SERIAL "0987654321" #define MOBIFLIGHT_NAME "MobiFlight RaspiPico" #define EEPROM_SIZE 4096 // EEPROMSizeRaspberryPico -#define MEMLEN_CONFIG 1496 // MUST be less than EEPROM_SIZE!! MEM_OFFSET_CONFIG + MEM_LEN_CONFIG <= EEPROM_SIZE, see: eeprom_write_block (MEM_OFFSET_CONFIG, configBuffer, MEM_LEN_CONFIG); +#define MEM_LEN_CONFIG 1496 // max. size for config which wil be stored in EEPROM, must be less than (EEPROM_SIZE - (MEM_OFFSET_NAME + MEM_LEN_NAME + MEM_LEN_SERIAL)) #define MEMLEN_NAMES_BUFFER 1000 // max. size for configBuffer, contains only names from inputs #define MF_MAX_DEVICEMEM 2000 // max. memory size for devices diff --git a/src/Config.cpp b/src/Config.cpp index 1064a194..8544ef30 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -49,18 +49,20 @@ MFEEPROM MFeeprom; extern MFMuxDriver MUX; #endif -const uint8_t MEM_OFFSET_NAME = 0; -const uint8_t MEM_LEN_NAME = 48; -const uint8_t MEM_OFFSET_SERIAL = MEM_OFFSET_NAME + MEM_LEN_NAME; -const uint8_t MEM_LEN_SERIAL = 11; -const uint8_t MEM_OFFSET_CONFIG = MEM_OFFSET_NAME + MEM_LEN_NAME + MEM_LEN_SERIAL; - -char serial[3 + UniqueIDsize * 2 + 1] = MOBIFLIGHT_SERIAL; // 3 characters for "SN-", UniqueID as HEX String, terminating NULL -char name[MEM_LEN_NAME] = MOBIFLIGHT_NAME; -const int MEM_LEN_CONFIG = MEMLEN_CONFIG; -char nameBuffer[MEM_LEN_CONFIG] = ""; -uint16_t configLength = 0; -boolean configActivated = false; +#define MEM_OFFSET_NAME 0 +#define MEM_LEN_NAME 48 +#define MEM_OFFSET_SERIAL (MEM_OFFSET_NAME + MEM_LEN_NAME) +#define MEM_LEN_SERIAL 11 +#define MEM_OFFSET_CONFIG (MEM_OFFSET_NAME + MEM_LEN_NAME + MEM_LEN_SERIAL) + +#if ((MEM_OFFSET_NAME + MEM_LEN_NAME + MEM_LEN_SERIAL + MEM_LEN_CONFIG)) >= EEPROM_SIZE +#error EEPROM size is exceeded +#endif + +char serial[3 + UniqueIDsize * 2 + 1] = MOBIFLIGHT_SERIAL; // 3 characters for "SN-", UniqueID as HEX String, terminating NULL +char name[MEM_LEN_NAME] = MOBIFLIGHT_NAME; +uint16_t configLength = 0; +boolean configActivated = false; void resetConfig(); void readConfig(); @@ -78,7 +80,7 @@ bool readConfigLength() while (MFeeprom.read_byte(addreeprom++) != 0x00) { configLength++; - if (addreeprom > length) // abort if EEPROM size will be exceeded + if (addreeprom > length) // abort if EEPROM size will be exceeded { cmdMessenger.sendCmd(kStatus, F("Loading config failed")); // text or "-1" like config upload? return false; @@ -207,21 +209,21 @@ bool readEndCommandFromEEPROM(uint16_t *addreeprom) temp = MFeeprom.read_byte((*addreeprom)++); if (*addreeprom > length) // abort if EEPROM size will be exceeded return false; - } while (temp != ':'); // reads until limiter ':' + } while (temp != ':'); // reads until limiter ':' return true; } void readConfig() { - if (configLength == 0) // do nothing if no config is available + if (configLength == 0) // do nothing if no config is available return; - uint16_t addreeprom = MEM_OFFSET_CONFIG; // define first memory location where config is saved in EEPROM + uint16_t addreeprom = MEM_OFFSET_CONFIG; // define first memory location where config is saved in EEPROM char params[8] = ""; uint8_t command = readUintFromEEPROM(&addreeprom); // read the first value from EEPROM, it's a device definition - bool copy_success = true; // will be set to false if copying input names to nameBuffer exceeds array dimensions + bool copy_success = true; // will be set to false if EEPROM size gets exceeded // not required anymore when pins instead of names are transferred to the UI - if (command == 0) // just to be sure, configLength should also be 0 + if (command == 0) // just to be sure, configLength should also be 0 return; do // go through the EEPROM until it is NULL terminated From e7c80467b8cdc53dceea02f9502d223ace1b7e58 Mon Sep 17 00:00:00 2001 From: elral <3263285+elral@users.noreply.github.com> Date: Wed, 31 May 2023 06:36:59 +0200 Subject: [PATCH 11/15] #define not required --- _Boards/RaspberryPi/Pico/MFBoards.h | 1 - 1 file changed, 1 deletion(-) diff --git a/_Boards/RaspberryPi/Pico/MFBoards.h b/_Boards/RaspberryPi/Pico/MFBoards.h index 05f1266d..b3de9d70 100644 --- a/_Boards/RaspberryPi/Pico/MFBoards.h +++ b/_Boards/RaspberryPi/Pico/MFBoards.h @@ -51,7 +51,6 @@ #define MOBIFLIGHT_NAME "MobiFlight RaspiPico" #define EEPROM_SIZE 4096 // EEPROMSizeRaspberryPico #define MEM_LEN_CONFIG 1496 // max. size for config which wil be stored in EEPROM, must be less than (EEPROM_SIZE - (MEM_OFFSET_NAME + MEM_LEN_NAME + MEM_LEN_SERIAL)) -#define MEMLEN_NAMES_BUFFER 1000 // max. size for configBuffer, contains only names from inputs #define MF_MAX_DEVICEMEM 2000 // max. memory size for devices #endif From 62b309c5d3756628ee06974133152230a636743c Mon Sep 17 00:00:00 2001 From: elral <3263285+elral@users.noreply.github.com> Date: Fri, 8 Sep 2023 17:35:38 +0200 Subject: [PATCH 12/15] merge main --- src/Config.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Config.cpp b/src/Config.cpp index 5d10c8e2..a56c2c7f 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -108,7 +108,7 @@ void OnSetConfig() char *cfg = cmdMessenger.readStringArg(); uint8_t cfgLen = strlen(cfg); - if (configLength + cfgLen + 1 < MEM_LEN_CONFIG) { + if (configLength + cfgLen + 1 < MEMLEN_CONFIG) { MFeeprom.write_block(MEM_OFFSET_CONFIG + configLength, cfg, cfgLen + 1); // save the received config string including the terminatung NULL (+1) to EEPROM configLength += cfgLen; cmdMessenger.sendCmd(kStatus, configLength); From 37b7522951c23f196ca659658e978cfd085c6377 Mon Sep 17 00:00:00 2001 From: elral <3263285+elral@users.noreply.github.com> Date: Mon, 23 Oct 2023 20:49:32 +0200 Subject: [PATCH 13/15] merge branch main --- src/Config.cpp | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/Config.cpp b/src/Config.cpp index d1f9b1a5..d904dcc6 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -228,11 +228,10 @@ void readConfig() { if (configLength == 0) // do nothing if no config is available return; - uint16_t addreeprom = MEM_OFFSET_CONFIG; // define first memory location where config is saved in EEPROM + uint16_t addreeprom = MEM_OFFSET_CONFIG; // define first memory location where config is saved in EEPROM char params[8] = ""; uint8_t command = readUintFromEEPROM(&addreeprom); // read the first value from EEPROM, it's a device definition bool copy_success = true; // will be set to false if EEPROM size gets exceeded - // not required anymore when pins instead of names are transferred to the UI if (command == 0) // just to be sure, configLength should also be 0 return; @@ -336,9 +335,9 @@ void readConfig() #if MF_ANALOG_SUPPORT == 1 case kTypeAnalogInput: - params[0] = readUintFromEEPROM(&addreeprom); // pin number - params[1] = readUintFromEEPROM(&addreeprom); // sensitivity - Analog::Add(params[0], &nameBuffer[addrbuffer], params[1]); // MUST be before readNameFromEEPROM because readNameFromEEPROM returns the pointer for the NEXT Name + params[0] = readUintFromEEPROM(&addreeprom); // pin number + params[1] = readUintFromEEPROM(&addreeprom); // sensitivity + Analog::Add(params[0], params[1]); copy_success = readEndCommandFromEEPROM(&addreeprom, ':'); break; #endif @@ -395,18 +394,18 @@ void readConfig() #if MF_CUSTOMDEVICE_SUPPORT == 1 case kTypeCustomDevice: { - uint16_t adrType = addreeprom; // first location of custom Type in EEPROM - copy_success = readEndCommandFromEEPROM(&addreeprom, '.'); + uint16_t adrType = addreeprom; // first location of custom Type in EEPROM + copy_success = readEndCommandFromEEPROM(&addreeprom, '.'); if (!copy_success) break; - uint16_t adrPin = addreeprom; // first location of custom pins in EEPROM - copy_success = readEndCommandFromEEPROM(&addreeprom, '.'); + uint16_t adrPin = addreeprom; // first location of custom pins in EEPROM + copy_success = readEndCommandFromEEPROM(&addreeprom, '.'); if (!copy_success) break; - uint16_t adrConfig = addreeprom; // first location of custom config in EEPROM - copy_success = readEndCommandFromEEPROM(&addreeprom, '.'); + uint16_t adrConfig = addreeprom; // first location of custom config in EEPROM + copy_success = readEndCommandFromEEPROM(&addreeprom, '.'); if (copy_success) { CustomDevice::Add(adrPin, adrType, adrConfig); copy_success = readEndCommandFromEEPROM(&addreeprom, ':'); // check EEPROM until end of command From b8e62947b7c3b762707f7f931000338b94c06bd2 Mon Sep 17 00:00:00 2001 From: elral <3263285+elral@users.noreply.github.com> Date: Wed, 25 Oct 2023 14:33:26 +0200 Subject: [PATCH 14/15] merge error --- src/MF_Analog/Analog.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MF_Analog/Analog.cpp b/src/MF_Analog/Analog.cpp index a3a44228..576ec48b 100644 --- a/src/MF_Analog/Analog.cpp +++ b/src/MF_Analog/Analog.cpp @@ -14,7 +14,7 @@ namespace Analog MFAnalog *analog[MAX_ANALOG_INPUTS]; uint8_t analogRegistered = 0; - void handlerOnAnalogChange(int16_t value, uint8_t deviceID) + void handlerOnAnalogChange(int value, uint8_t deviceID) { cmdMessenger.sendCmdStart(kAnalogChange); cmdMessenger.sendCmdArg(deviceID); From 2dccc8a17b6325e9196ab83d7b67e19403e52d07 Mon Sep 17 00:00:00 2001 From: elral <3263285+elral@users.noreply.github.com> Date: Mon, 6 May 2024 09:04:08 +0200 Subject: [PATCH 15/15] Merge main --- .github/workflows/ci.yml | 6 ------ .github/workflows/release.yml | 6 ------ CustomDevices | 2 +- get_CustomDevices.py | 13 ------------- platformio.ini | 11 +---------- src/Config.cpp | 18 +++++++++++++----- 6 files changed, 15 insertions(+), 41 deletions(-) delete mode 100644 get_CustomDevices.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 80211a3d..7a31313b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -39,12 +39,6 @@ jobs: python -m pip install --upgrade pip pip install --upgrade platformio - - name: Checkout custom devices - uses: actions/checkout@v3 - with: - repository: MobiFlight/MobiFlight-CustomDevices - path: CustomDevices - - name: Run PlatformIO env: VERSION: "0.0.${{ github.event.number }}" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ec8a0677..78507eee 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -38,12 +38,6 @@ jobs: python -m pip install --upgrade pip pip install --upgrade platformio - - name: Checkout custom devices - uses: actions/checkout@v3 - with: - repository: MobiFlight/MobiFlight-CustomDevices - path: CustomDevices - - name: Extract build version id: get_version uses: battila7/get-version-action@v2 diff --git a/CustomDevices b/CustomDevices index 8d63b403..cea02ee7 160000 --- a/CustomDevices +++ b/CustomDevices @@ -1 +1 @@ -Subproject commit 8d63b403cc4a4cc8915ca6b65e0af8239b8cd4a1 +Subproject commit cea02ee70bd0a0d39210cf7d372b53169c32d141 diff --git a/get_CustomDevices.py b/get_CustomDevices.py deleted file mode 100644 index 4dab8572..00000000 --- a/get_CustomDevices.py +++ /dev/null @@ -1,13 +0,0 @@ -import os - -Import("env") - -CUSTOMDEVICES_DIR = env.subst("$PROJECT_DIR/CustomDevices") -CUSTOMDEVICES_TAG = "0.2.0" - -if not os.path.exists(CUSTOMDEVICES_DIR): - print ("Cloning Mobiflight-CustomDevices repo ... ") - env.Execute(f"git clone --depth 100 --branch {CUSTOMDEVICES_TAG} https://github.com/MobiFlight/MobiFlight-CustomDevices $PROJECT_DIR/CustomDevices") -else: - print ("Checking for Mobiflight-CustomDevices repo updates ... ") - env.Execute(f"git --work-tree=$PROJECT_DIR/CustomDevices --git-dir=$PROJECT_DIR/CustomDevices/.git pull origin {CUSTOMDEVICES_TAG} --depth 100") diff --git a/platformio.ini b/platformio.ini index 5366ac0a..15a29891 100644 --- a/platformio.ini +++ b/platformio.ini @@ -14,15 +14,7 @@ ; If you want to only build a single platform locally during ; development use VSCode to change the target to a non-default ; by clicking on the target name in the bottom status bar. -[platformio] -; include custom environments to be build -extra_configs = - ./CustomDevices/KAV_Simulation/displays_platformio.ini - ./CustomDevices/Mobiflight/GNC255/GNC255_platformio.ini - ./CustomDevices/Mobiflight/TM1637/TM1637_platformio.ini - ./CustomDevices/Mobiflight/GenericI2C/GenericI2C_platformio.ini - ./CustomDevices/_all_CustomDevices/all_devices_platformio.ini - + ; Common build settings across all devices [env] @@ -61,7 +53,6 @@ build_src_filter = -<./MF_CustomDevice> extra_scripts = pre:get_version.py - pre:get_CustomDevices.py ; Build settings for the Arduino Mega [env:mobiflight_mega] diff --git a/src/Config.cpp b/src/Config.cpp index f36aab8f..fb44e7c9 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -87,6 +87,8 @@ bool readConfigLength() uint16_t length = MFeeprom.get_length(); configLength = 0; + if (MFeeprom.read_byte(MEM_OFFSET_CONFIG) == 0xFF) + return false; while (MFeeprom.read_byte(addreeprom++) != 0x00) { configLength++; if (addreeprom > length) { @@ -566,6 +568,7 @@ void generateRandomSerial() randomSerial >>= 4; } MFeeprom.write_block(MEM_OFFSET_SERIAL, serial, MEM_LEN_SERIAL); + cmdMessenger.sendCmd(kDebug, F("Serial number generated")); } #if defined(ARDUINO_ARCH_RP2040) @@ -597,13 +600,17 @@ void generateSerial(bool force) MFeeprom.read_block(MEM_OFFSET_SERIAL, serial, MEM_LEN_SERIAL); return; } -#if defined(ARDUINO_ARCH_RP2040) + // A uniqueID is already generated and saved to the eeprom if (MFeeprom.read_byte(MEM_OFFSET_SERIAL) == 'I' && MFeeprom.read_byte(MEM_OFFSET_SERIAL + 1) == 'D') { +#if defined(ARDUINO_ARCH_AVR) + generateRandomSerial(); +#elif defined(ARDUINO_ARCH_RP2040) readUniqueSerial(); +#endif return; } -#endif + // Coming here no UniqueID and no serial number is available, so it's the first start up of a board #if defined(ARDUINO_ARCH_AVR) @@ -611,6 +618,7 @@ void generateSerial(bool force) // To have not always the same starting point for the random generator, millis() are // used as starting point. It is very unlikely that the time between flashing the firmware // and getting the command to send the info's to the connector is always the same. + // additional double check if it's really a new board, should reduce Jaimes problem generateRandomSerial(); #elif defined(ARDUINO_ARCH_RP2040) // Read the uniqueID for Pico's and use it as serial number @@ -618,9 +626,9 @@ void generateSerial(bool force) // mark this in the eeprom that a UniqueID is used on first start up for Pico's MFeeprom.write_block(MEM_OFFSET_SERIAL, "ID", 2); #endif - // Set first byte of config to 0x00 to ensure empty config on 1st start up - // Otherwise the complete length of the config will be send with 0xFF (empty EEPROM) - MFeeprom.write_byte(MEM_OFFSET_CONFIG, 0x00); + if (MFeeprom.read_byte(MEM_OFFSET_CONFIG) == 0xFF) { + MFeeprom.write_block(MEM_OFFSET_CONFIG, 0x00); + } } void OnGenNewSerial()