From 53842637d9cb4e4aa9464c543023ad9832496f50 Mon Sep 17 00:00:00 2001 From: elral <3263285+elral@users.noreply.github.com> Date: Thu, 8 Dec 2022 19:39:40 +0100 Subject: [PATCH 1/2] MF type to flash, simplier check for serial avail. (#217) * MF type to flash, simplier check for serial avail. * write a const instead of a defined 1byte array * change command defintion from char to uint8_t --- src/Config.cpp | 46 +++++++++++++++++++++------------------------- 1 file changed, 21 insertions(+), 25 deletions(-) diff --git a/src/Config.cpp b/src/Config.cpp index e5cdb053..4d61c9e5 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -55,13 +55,12 @@ 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; -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; +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; void resetConfig(); void readConfig(); @@ -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() @@ -237,7 +236,7 @@ void readConfig() 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 + 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 // not required anymore when pins instead of names are transferred to the UI @@ -422,7 +421,7 @@ void OnGetInfo() { setLastCommandMillis(); cmdMessenger.sendCmdStart(kInfo); - cmdMessenger.sendCmdArg(type); + cmdMessenger.sendCmdArg(F(MOBIFLIGHT_TYPE)); cmdMessenger.sendCmdArg(name); cmdMessenger.sendCmdArg(serial); cmdMessenger.sendCmdArg(VERSION); @@ -462,16 +461,13 @@ void OnGenNewSerial() // ************************************************************ void storeName() { - char prefix[] = "#"; - MFeeprom.write_block(MEM_OFFSET_NAME, prefix, 1); + MFeeprom.write_byte(MEM_OFFSET_NAME, '#'); MFeeprom.write_block(MEM_OFFSET_NAME + 1, name, MEM_LEN_NAME - 1); } void restoreName() { - char testHasName[1] = ""; - MFeeprom.read_block(MEM_OFFSET_NAME, testHasName, 1); - if (testHasName[0] != '#') + if (MFeeprom.read_char(MEM_OFFSET_NAME) != '#') return; MFeeprom.read_block(MEM_OFFSET_NAME + 1, name, MEM_LEN_NAME - 1); From d265384e5af1a9e2b340bd8a2636f54046f4ca3e Mon Sep 17 00:00:00 2001 From: GioCC <25667790+GioCC@users.noreply.github.com> Date: Thu, 8 Dec 2022 19:40:49 +0100 Subject: [PATCH 2/2] Change constant for averaging buffer size of analog inputs (#211) (#218) --- src/MF_Analog/MFAnalog.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/MF_Analog/MFAnalog.h b/src/MF_Analog/MFAnalog.h index b6256e5c..aa29ed42 100644 --- a/src/MF_Analog/MFAnalog.h +++ b/src/MF_Analog/MFAnalog.h @@ -8,8 +8,11 @@ #include -#define ADC_MAX_AVERAGE 8 // must be 2^n -#define ADC_MAX_AVERAGE_LOG2 3 // please calculate LOG2(ADC_MAX_AVERAGE) +// Following value defines the buffer size for samples; the larger the buffer, +// the smoother the response (and the larger the delay). +// Buffer size is 2^ADC_MAX_AVERAGE_LOG2: 3 -> 8 samples, 4 -> 16 samples etc. +#define ADC_MAX_AVERAGE_LOG2 3 +#define ADC_MAX_AVERAGE (1 << ADC_MAX_AVERAGE_LOG2) extern "C" { // callback functions