Handle bool defaults on emulated eeprom platform platforms (fixes #5)
This commit is contained in:
parent
13e9a2c598
commit
51b5b670e6
6 changed files with 24 additions and 5 deletions
|
|
@ -11,6 +11,7 @@
|
||||||
#define MAX_ARGUMENT_LENGTH 20 //used in argument parsing, takes up ram
|
#define MAX_ARGUMENT_LENGTH 20 //used in argument parsing, takes up ram
|
||||||
#define VERSION_STRING "Sangaboard Firmware v1.0.0-beta"
|
#define VERSION_STRING "Sangaboard Firmware v1.0.0-beta"
|
||||||
#define DEBUG_ON
|
#define DEBUG_ON
|
||||||
|
#define EMULATED_EEPROM_SIZE 512
|
||||||
|
|
||||||
//module choice
|
//module choice
|
||||||
#define HELP
|
#define HELP
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
|
#ifndef dummyEEPROM_h
|
||||||
|
#define dummyEEPROM_h
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
struct EEPROMClass
|
struct EEPROMClass
|
||||||
|
|
@ -22,3 +23,4 @@ struct EEPROMClass
|
||||||
};
|
};
|
||||||
|
|
||||||
static EEPROMClass EEPROM;
|
static EEPROMClass EEPROM;
|
||||||
|
#endif
|
||||||
|
|
@ -178,7 +178,7 @@ void setup()
|
||||||
// On the Pico, EEPROM is emulated.
|
// On the Pico, EEPROM is emulated.
|
||||||
// This means we need to explicitly enable it, and also
|
// This means we need to explicitly enable it, and also
|
||||||
// call EEPROM.commit() periodically to persist it to flash.
|
// call EEPROM.commit() periodically to persist it to flash.
|
||||||
EEPROM.begin(256);
|
EEPROM.begin(EMULATED_EEPROM_SIZE);
|
||||||
eeprom_last_commit = millis();
|
eeprom_last_commit = millis();
|
||||||
#endif
|
#endif
|
||||||
// initialise serial port
|
// initialise serial port
|
||||||
|
|
|
||||||
15
src/main.h
15
src/main.h
|
|
@ -2,6 +2,11 @@
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <ComPort.h>
|
#include <ComPort.h>
|
||||||
|
#ifdef SUPPORT_EEPROM
|
||||||
|
#include <EEPROM.h>
|
||||||
|
#else
|
||||||
|
#include "dummyEEPROM.h"
|
||||||
|
#endif
|
||||||
#ifdef DEBUG_ON
|
#ifdef DEBUG_ON
|
||||||
#define D(x) comPort->println(x)
|
#define D(x) comPort->println(x)
|
||||||
#else
|
#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 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;
|
const Command end_command = END_COMMAND;
|
||||||
uint8_t parse_arguments(char ** arguments, String, uint8_t);
|
uint8_t parse_arguments(char ** arguments, String, uint8_t);
|
||||||
|
|
|
||||||
|
|
@ -140,6 +140,7 @@ void illumination_setup()
|
||||||
for(int i = 0; i < PWM_NUM; i++)
|
for(int i = 0; i < PWM_NUM; i++)
|
||||||
{
|
{
|
||||||
EEPROM.get(pwm_values_eeprom+i*sizeof(uint16_t), pwm_values[i]);
|
EEPROM.get(pwm_values_eeprom+i*sizeof(uint16_t), pwm_values[i]);
|
||||||
|
if (pwm_values[i] > 0)
|
||||||
analogWrite(pwm_led_pins[i], pwm_values[i]);
|
analogWrite(pwm_led_pins[i], pwm_values[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ void stage_setup()
|
||||||
}
|
}
|
||||||
|
|
||||||
//using non-blocking moves here to have blocking moves by default
|
//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);
|
register_module(stage_commands, stage_loop);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue