Handle bool defaults on emulated eeprom platform platforms (fixes #5)

This commit is contained in:
Filip Ayazi 2023-03-08 23:51:22 +00:00
parent 13e9a2c598
commit 51b5b670e6
6 changed files with 24 additions and 5 deletions

View file

@ -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

View file

@ -1,4 +1,5 @@
#ifndef dummyEEPROM_h
#define dummyEEPROM_h
#include <stdint.h>
struct EEPROMClass
@ -22,3 +23,4 @@ struct EEPROMClass
};
static EEPROMClass EEPROM;
#endif

View file

@ -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

View file

@ -2,6 +2,11 @@
#include "config.h"
#include <Arduino.h>
#include <ComPort.h>
#ifdef SUPPORT_EEPROM
#include <EEPROM.h>
#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);

View file

@ -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);

View file

@ -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);
}