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

Get rid of fixed device numbers #253

Merged
merged 34 commits into from
Nov 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
03c36c8
dynamical button numbers
elral Aug 19, 2023
45edfaf
set up array function
elral Aug 19, 2023
ce9d55c
better comments
elral Aug 19, 2023
701dcc1
all devices with dymically defined array
elral Aug 20, 2023
088167d
changes for MUX
elral Aug 20, 2023
c080f58
missing defines added
elral Aug 21, 2023
34e83fc
missing return statement
elral Aug 21, 2023
1762966
back to original device memory space
elral Aug 21, 2023
03ec932
debug print out added
elral Aug 21, 2023
97ed2d6
extended information of memory usage to serial, deactivated
elral Aug 21, 2023
838888e
clean up, delete max. number of devices from board file
elral Aug 21, 2023
f77ebe8
get servos to run
elral Aug 21, 2023
dcbb30a
add comment for array size
elral Aug 23, 2023
cb038b2
get array size via an array
elral Aug 23, 2023
f2b0955
error handling added
elral Aug 23, 2023
666fec8
better definition of array size
elral Aug 23, 2023
ea09be0
intended size for nameBuffer[]
elral Sep 6, 2023
e3fe451
increased deviceBuffer for AVR's, decreased for Pico
elral Sep 6, 2023
6230b32
Merge branch 'main' into no_fixed_device_numbers
elral Sep 8, 2023
8584aaa
Merge branch 'MobiFlight:main' into no_fixed_device_numbers
elral Oct 11, 2023
517385b
max. numbers of devices not required anymore
elral Oct 13, 2023
63f9c36
one common function for sending failure message
elral Oct 15, 2023
8dd5291
failure message directly from flash
elral Oct 15, 2023
096be82
better naming
elral Oct 15, 2023
27abcd9
delete not required parameter in handler functions
elral Oct 15, 2023
0db4409
Revert "delete not required parameter in handler functions"
elral Oct 17, 2023
50a7526
Merge branch 'main' into no_fixed_device_numbers
elral Oct 21, 2023
018b451
merge branch main
elral Oct 21, 2023
4e8eba1
delete not required folder
elral Oct 23, 2023
8cb5d3b
Merge branch 'main' into no_fixed_device_numbers
elral Oct 23, 2023
d2a42d5
Merge branch 'main' into no_fixed_device_numbers
elral Oct 23, 2023
daac96f
merge branch main
elral Oct 23, 2023
64403aa
also custom devices w/o device limit
elral Oct 25, 2023
910f7b2
setup array for custom device was missing
elral Oct 30, 2023
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
39 changes: 1 addition & 38 deletions _Boards/Atmel/Board_Mega/MFBoards.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,43 +39,6 @@
#define MF_CUSTOMDEVICE_SUPPORT 1
#endif

#ifndef MAX_OUTPUTS
#define MAX_OUTPUTS 40
#endif
#ifndef MAX_BUTTONS
#define MAX_BUTTONS 68
#endif
#ifndef MAX_LEDSEGMENTS
#define MAX_LEDSEGMENTS 4
#endif
#ifndef MAX_ENCODERS
#define MAX_ENCODERS 20
#endif
#ifndef MAX_STEPPERS
#define MAX_STEPPERS 10
#endif
#ifndef MAX_MFSERVOS
#define MAX_MFSERVOS 10
#endif
#ifndef MAX_MFLCD_I2C
#define MAX_MFLCD_I2C 2
#endif
#ifndef MAX_ANALOG_INPUTS
#define MAX_ANALOG_INPUTS 16
#endif
#ifndef MAX_OUTPUT_SHIFTERS
#define MAX_OUTPUT_SHIFTERS 4
#endif
#ifndef MAX_INPUT_SHIFTERS
#define MAX_INPUT_SHIFTERS 4
#endif
#ifndef MAX_DIGIN_MUX
#define MAX_DIGIN_MUX 4
#endif
#ifndef MAX_CUSTOM_DEVICES
#define MAX_CUSTOM_DEVICES 5
#endif

#ifndef MOBIFLIGHT_TYPE
#define MOBIFLIGHT_TYPE "MobiFlight Mega"
#endif
Expand All @@ -95,7 +58,7 @@
#define MEMLEN_NAMES_BUFFER 1000 // max. size for configBuffer, contains only names from inputs
#endif
#ifndef MF_MAX_DEVICEMEM
#define MF_MAX_DEVICEMEM 1500 // max. memory size for devices
#define MF_MAX_DEVICEMEM 1600 // max. memory size for devices
#endif

#endif
Expand Down
39 changes: 1 addition & 38 deletions _Boards/Atmel/Board_Nano/MFBoards.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,43 +39,6 @@
#define MF_CUSTOMDEVICE_SUPPORT 2
#endif

#ifndef MAX_OUTPUTS
#define MAX_OUTPUTS 18
#endif
#ifndef MAX_BUTTONS
#define MAX_BUTTONS 18
#endif
#ifndef MAX_LEDSEGMENTS
#define MAX_LEDSEGMENTS 4
#endif
#ifndef MAX_ENCODERS
#define MAX_ENCODERS 9
#endif
#ifndef MAX_STEPPERS
#define MAX_STEPPERS 2
#endif
#ifndef MAX_MFSERVOS
#define MAX_MFSERVOS 2
#endif
#ifndef MAX_MFLCD_I2C
#define MAX_MFLCD_I2C 2
#endif
#ifndef MAX_ANALOG_INPUTS
#define MAX_ANALOG_INPUTS 8
#endif
#ifndef MAX_OUTPUT_SHIFTERS
#define MAX_OUTPUT_SHIFTERS 2
#endif
#ifndef MAX_INPUT_SHIFTERS
#define MAX_INPUT_SHIFTERS 2
#endif
#ifndef MAX_DIGIN_MUX
#define MAX_DIGIN_MUX 3
#endif
#ifndef MAX_CUSTOM_DEVICES
#define MAX_CUSTOM_DEVICES 2
#endif

#ifndef MOBIFLIGHT_TYPE
#define MOBIFLIGHT_TYPE "MobiFlight Nano"
#endif
Expand All @@ -95,7 +58,7 @@
#define MEMLEN_NAMES_BUFFER 220 // max. size for configBuffer, contains only names from inputs
#endif
#ifndef MF_MAX_DEVICEMEM
#define MF_MAX_DEVICEMEM 300 // max. memory size for devices
#define MF_MAX_DEVICEMEM 420 // max. memory size for devices
#endif
#endif

Expand Down
39 changes: 1 addition & 38 deletions _Boards/Atmel/Board_ProMicro/MFBoards.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,43 +39,6 @@
#define MF_CUSTOMDEVICE_SUPPORT 2
#endif

#ifndef MAX_OUTPUTS
#define MAX_OUTPUTS 18
#endif
#ifndef MAX_BUTTONS
#define MAX_BUTTONS 18
#endif
#ifndef MAX_LEDSEGMENTS
#define MAX_LEDSEGMENTS 4
#endif
#ifndef MAX_ENCODERS
#define MAX_ENCODERS 9
#endif
#ifndef MAX_STEPPERS
#define MAX_STEPPERS 3
#endif
#ifndef MAX_MFSERVOS
#define MAX_MFSERVOS 3
#endif
#ifndef MAX_MFLCD_I2C
#define MAX_MFLCD_I2C 2
#endif
#ifndef MAX_ANALOG_INPUTS
#define MAX_ANALOG_INPUTS 9
#endif
#ifndef MAX_OUTPUT_SHIFTERS
#define MAX_OUTPUT_SHIFTERS 2
#endif
#ifndef MAX_INPUT_SHIFTERS
#define MAX_INPUT_SHIFTERS 2
#endif
#ifndef MAX_DIGIN_MUX
#define MAX_DIGIN_MUX 3
#endif
#ifndef MAX_CUSTOM_DEVICES
#define MAX_CUSTOM_DEVICES 2
#endif

#ifndef MOBIFLIGHT_TYPE
#define MOBIFLIGHT_TYPE "MobiFlight Micro"
#endif
Expand All @@ -95,7 +58,7 @@
#define MEMLEN_NAMES_BUFFER 350 // max. size for configBuffer, contains only names from inputs
#endif
#ifndef MF_MAX_DEVICEMEM
#define MF_MAX_DEVICEMEM 400 // max. memory size for devices
#define MF_MAX_DEVICEMEM 470 // max. memory size for devices
#endif

#endif
Expand Down
39 changes: 1 addition & 38 deletions _Boards/Atmel/Board_Uno/MFBoards.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,43 +39,6 @@
#define MF_CUSTOMDEVICE_SUPPORT 2
#endif

#ifndef MAX_OUTPUTS
#define MAX_OUTPUTS 18
#endif
#ifndef MAX_BUTTONS
#define MAX_BUTTONS 18
#endif
#ifndef MAX_LEDSEGMENTS
#define MAX_LEDSEGMENTS 4
#endif
#ifndef MAX_ENCODERS
#define MAX_ENCODERS 9
#endif
#ifndef MAX_STEPPERS
#define MAX_STEPPERS 2
#endif
#ifndef MAX_MFSERVOS
#define MAX_MFSERVOS 2
#endif
#ifndef MAX_MFLCD_I2C
#define MAX_MFLCD_I2C 2
#endif
#ifndef MAX_ANALOG_INPUTS
#define MAX_ANALOG_INPUTS 6
#endif
#ifndef MAX_OUTPUT_SHIFTERS
#define MAX_OUTPUT_SHIFTERS 2
#endif
#ifndef MAX_INPUT_SHIFTERS
#define MAX_INPUT_SHIFTERS 2
#endif
#ifndef MAX_DIGIN_MUX
#define MAX_DIGIN_MUX 3
#endif
#ifndef MAX_CUSTOM_DEVICES
#define MAX_CUSTOM_DEVICES 2
#endif

#ifndef MOBIFLIGHT_TYPE
#define MOBIFLIGHT_TYPE "MobiFlight Uno"
#endif
Expand All @@ -95,7 +58,7 @@
#define MEMLEN_NAMES_BUFFER 220 // max. size for configBuffer, contains only names from inputs
#endif
#ifndef MF_MAX_DEVICEMEM
#define MF_MAX_DEVICEMEM 300 // max. memory size for devices
#define MF_MAX_DEVICEMEM 420 // max. memory size for devices
#endif

#endif
Expand Down
39 changes: 1 addition & 38 deletions _Boards/RaspberryPi/Pico/MFBoards.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,43 +30,6 @@
#define MF_DIGIN_MUX_SUPPORT 1
#endif

#ifndef MAX_OUTPUTS
#define MAX_OUTPUTS 26
#endif
#ifndef MAX_BUTTONS
#define MAX_BUTTONS 26
#endif
#ifndef MAX_LEDSEGMENTS
#define MAX_LEDSEGMENTS 4
#endif
#ifndef MAX_ENCODERS
#define MAX_ENCODERS 8
#endif
#ifndef MAX_STEPPERS
#define MAX_STEPPERS 6
#endif
#ifndef MAX_MFSERVOS
#define MAX_MFSERVOS 8
#endif
#ifndef MAX_MFLCD_I2C
#define MAX_MFLCD_I2C 2
#endif
#ifndef MAX_ANALOG_INPUTS
#define MAX_ANALOG_INPUTS 3
#endif
#ifndef MAX_OUTPUT_SHIFTERS
#define MAX_OUTPUT_SHIFTERS 4
#endif
#ifndef MAX_INPUT_SHIFTERS
#define MAX_INPUT_SHIFTERS 4
#endif
#ifndef MAX_DIGIN_MUX
#define MAX_DIGIN_MUX 4
#endif
#ifndef MAX_CUSTOM_DEVICES
#define MAX_CUSTOM_DEVICES 5
#endif

#ifndef MOBIFLIGHT_TYPE
#define MOBIFLIGHT_TYPE "MobiFlight RaspiPico"
#endif
Expand All @@ -86,7 +49,7 @@
#define MEMLEN_NAMES_BUFFER 1000 // max. size for configBuffer, contains only names from inputs
#endif
#ifndef MF_MAX_DEVICEMEM
#define MF_MAX_DEVICEMEM 2000 // max. memory size for devices
#define MF_MAX_DEVICEMEM 1000 // max. memory size for devices
#endif

#endif
83 changes: 82 additions & 1 deletion src/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,20 +242,101 @@ bool readEndCommandFromEEPROM(uint16_t *addreeprom, uint8_t delimiter)
return true;
}

void sendFailureMessage(const char *deviceName)
{
cmdMessenger.sendCmdStart(kStatus);
cmdMessenger.sendCmdArg(deviceName);
cmdMessenger.sendCmdArg(F("does not fit in Memory"));
cmdMessenger.sendCmdEnd();
}

bool getArraysizes()
{
if (configLength == 0) // do nothing if no config is available
return true;
uint16_t addreeprom = MEM_OFFSET_CONFIG; // define first memory location where config is saved in EEPROM
uint8_t device = 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
uint8_t numberDevices[kTypeMax] = {0};

if (device == 0) // just to be sure, configLength should also be 0
return true;

// step through the EEPROM and calculate the number of devices for each type
do // step through the EEPROM until it is NULL terminated
{
numberDevices[device]++;
copy_success = readEndCommandFromEEPROM(&addreeprom, ':'); // check EEPROM until end of name
device = readUintFromEEPROM(&addreeprom);
} while (device && copy_success);

if (!copy_success) { // too much/long names for input devices -> tbd how to handle this!!
cmdMessenger.sendCmd(kStatus, F("Failure, EEPROM size exceeded "));
return false;
}

// then call the function to allocate required memory for the arrays of each type
if (!Button::setupArray(numberDevices[kTypeButton]))
sendFailureMessage("Button");
if (!Output::setupArray(numberDevices[kTypeOutput]))
sendFailureMessage("Output");
#if MF_SEGMENT_SUPPORT == 1
if (!LedSegment::setupArray(numberDevices[kTypeLedSegmentDeprecated]) + numberDevices[kTypeLedSegmentMulti])
sendFailureMessage("7Segment");
#endif
#if MF_STEPPER_SUPPORT == 1
if (!Stepper::setupArray(numberDevices[kTypeStepper] + numberDevices[kTypeStepperDeprecated1] + numberDevices[kTypeStepperDeprecated2]))
sendFailureMessage("Stepper");
#endif
#if MF_SERVO_SUPPORT == 1
if (!Servos::setupArray(numberDevices[kTypeServo]))
sendFailureMessage("Servo");
#endif
if (!Encoder::setupArray(numberDevices[kTypeEncoder] + numberDevices[kTypeEncoderSingleDetent]))
sendFailureMessage("Encoders");
#if MF_LCD_SUPPORT == 1
if (!LCDDisplay::setupArray(numberDevices[kTypeLcdDisplayI2C]))
sendFailureMessage("LCD");
#endif
#if MF_ANALOG_SUPPORT == 1
if (!Analog::setupArray(numberDevices[kTypeAnalogInput]))
sendFailureMessage("AnalogIn");
#endif
#if MF_OUTPUT_SHIFTER_SUPPORT == 1
if (!OutputShifter::setupArray(numberDevices[kTypeOutputShifter]))
sendFailureMessage("OutputShifter");
#endif
#if MF_INPUT_SHIFTER_SUPPORT == 1
if (!InputShifter::setupArray(numberDevices[kTypeInputShifter]))
sendFailureMessage("InputShifter");
#endif
#if MF_DIGIN_MUX_SUPPORT == 1
if (!DigInMux::setupArray(numberDevices[kTypeDigInMux]))
sendFailureMessage("DigInMux");
#endif
#if MF_CUSTOMDEVICE_SUPPORT == 1
if (!CustomDevice::setupArray(numberDevices[kTypeCustomDevice]))
sendFailureMessage("CustomDevice");
#endif
return true;
}

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[8] = ""; // buffer for reading parameters from EEPROM and sending to ::Add() function of device
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

if (command == 0) // just to be sure, configLength should also be 0
return;

getArraysizes();

do // go through the EEPROM until it is NULL terminated
{
switch (command) {
Expand Down
Loading
Loading