Skip to content

Commit

Permalink
Merge branch 'main' into wo_NameBuffer
Browse files Browse the repository at this point in the history
  • Loading branch information
DocMoebiuz authored Dec 8, 2022
2 parents adb6875 + d265384 commit 145e4b8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
26 changes: 12 additions & 14 deletions src/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +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;
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();
Expand Down Expand Up @@ -219,8 +219,9 @@ void readConfig()
return;
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 reading from eeprom exceeds size
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

if (command == 0) // just to be sure, configLength should also be 0
return;
Expand Down Expand Up @@ -397,7 +398,7 @@ void OnGetInfo()
{
setLastCommandMillis();
cmdMessenger.sendCmdStart(kInfo);
cmdMessenger.sendCmdArg(type);
cmdMessenger.sendCmdArg(F(MOBIFLIGHT_TYPE));
cmdMessenger.sendCmdArg(name);
cmdMessenger.sendCmdArg(serial);
cmdMessenger.sendCmdArg(VERSION);
Expand Down Expand Up @@ -437,16 +438,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);
Expand Down
7 changes: 5 additions & 2 deletions src/MF_Analog/MFAnalog.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@

#include <Arduino.h>

#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
Expand Down

0 comments on commit 145e4b8

Please sign in to comment.