From 51b5b670e6c6d2dcf277501db9bebb0362388f0f Mon Sep 17 00:00:00 2001 From: Filip Ayazi Date: Wed, 8 Mar 2023 23:51:22 +0000 Subject: [PATCH] Handle bool defaults on emulated eeprom platform platforms (fixes #5) --- src/config.h | 1 + src/dummyEEPROM.h | 6 ++++-- src/main.cpp | 2 +- src/main.h | 15 +++++++++++++++ src/modules/illumination/illumination.cpp | 3 ++- src/modules/stage/stage.cpp | 2 +- 6 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/config.h b/src/config.h index aefd73c..36c15a6 100644 --- a/src/config.h +++ b/src/config.h @@ -11,6 +11,7 @@ #define MAX_ARGUMENT_LENGTH 20 //used in argument parsing, takes up ram #define VERSION_STRING "Sangaboard Firmware v1.0.0-beta" #define DEBUG_ON + #define EMULATED_EEPROM_SIZE 512 //module choice #define HELP diff --git a/src/dummyEEPROM.h b/src/dummyEEPROM.h index 442a610..1802f23 100644 --- a/src/dummyEEPROM.h +++ b/src/dummyEEPROM.h @@ -1,4 +1,5 @@ - +#ifndef dummyEEPROM_h +#define dummyEEPROM_h #include struct EEPROMClass @@ -21,4 +22,5 @@ struct EEPROMClass } }; -static EEPROMClass EEPROM; \ No newline at end of file +static EEPROMClass EEPROM; +#endif \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 95c1c53..ba48ed3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -178,7 +178,7 @@ void setup() // On the Pico, EEPROM is emulated. // This means we need to explicitly enable it, and also // call EEPROM.commit() periodically to persist it to flash. - EEPROM.begin(256); + EEPROM.begin(EMULATED_EEPROM_SIZE); eeprom_last_commit = millis(); #endif // initialise serial port diff --git a/src/main.h b/src/main.h index 2b74b83..140c14a 100644 --- a/src/main.h +++ b/src/main.h @@ -2,6 +2,11 @@ #include "config.h" #include #include +#ifdef SUPPORT_EEPROM +#include +#else +#include "dummyEEPROM.h" +#endif #ifdef DEBUG_ON #define D(x) comPort->println(x) #else @@ -22,6 +27,16 @@ struct Command inline bool check_end_command(Command c) { return strlen(c.command) > 0; } inline bool check_end_command(Command * c) {return strlen(c->command) > 0; } +inline bool read_eeprom_bool(uint16_t address, bool default_value) +{ + int8_t temp_value; + EEPROM.get(address, temp_value); + if (temp_value < 0) + return default_value; + + return temp_value != 0; +} + const Command end_command = END_COMMAND; uint8_t parse_arguments(char ** arguments, String, uint8_t); diff --git a/src/modules/illumination/illumination.cpp b/src/modules/illumination/illumination.cpp index e35c1bc..86ee9ab 100644 --- a/src/modules/illumination/illumination.cpp +++ b/src/modules/illumination/illumination.cpp @@ -140,7 +140,8 @@ void illumination_setup() for(int i = 0; i < PWM_NUM; i++) { EEPROM.get(pwm_values_eeprom+i*sizeof(uint16_t), pwm_values[i]); - analogWrite(pwm_led_pins[i], pwm_values[i]); + if (pwm_values[i] > 0) + analogWrite(pwm_led_pins[i], pwm_values[i]); } register_module(illumination_commands, NULL); diff --git a/src/modules/stage/stage.cpp b/src/modules/stage/stage.cpp index 0ee6324..ead2f53 100644 --- a/src/modules/stage/stage.cpp +++ b/src/modules/stage/stage.cpp @@ -55,7 +55,7 @@ void stage_setup() } //using non-blocking moves here to have blocking moves by default - EEPROM.get(non_blocking_moves_eeprom, non_blocking_moves); + non_blocking_moves = read_eeprom_bool(non_blocking_moves_eeprom, false); register_module(stage_commands, stage_loop); }