Refactor: remove Euclidean steps into its own firmware

This commit is contained in:
2026-02-21 09:39:57 -08:00
parent dd7217d04e
commit 6d38c6b36b
12 changed files with 2510 additions and 1061 deletions

View File

@ -19,79 +19,76 @@
struct AppState;
/**
* @brief Manages saving and loading of the application state to and from EEPROM.
* The number of user slots is defined by MAX_SAVE_SLOTS, and one additional slot
* is reseved for transient state to persist state between power cycles before
* state is explicitly saved to a user slot. Metadata is stored in the beginning
* of the memory space which stores firmware version information to validate that
* the data can be loaded into the current version of AppState.
* @brief Manages saving and loading of the application state to and from
* EEPROM. The number of user slots is defined by MAX_SAVE_SLOTS, and one
* additional slot is reseved for transient state to persist state between power
* cycles before state is explicitly saved to a user slot. Metadata is stored in
* the beginning of the memory space which stores firmware version information
* to validate that the data can be loaded into the current version of AppState.
*/
class StateManager {
public:
static const char SKETCH_NAME[];
static const char SEMANTIC_VERSION[];
static const byte MAX_SAVE_SLOTS;
static const byte TRANSIENT_SLOT;
public:
static const char SKETCH_NAME[];
static const char SEMANTIC_VERSION[];
static const byte MAX_SAVE_SLOTS;
static const byte TRANSIENT_SLOT;
StateManager();
StateManager();
// Populate the AppState instance with values from EEPROM if they exist.
bool initialize(AppState& app);
// Load data from specified slot.
bool loadData(AppState& app, byte slot_index);
// Save data to specified slot.
void saveData(const AppState& app);
// Reset AppState instance back to default values.
void reset(AppState& app);
// Call from main loop, check if state has changed and needs to be saved.
void update(const AppState& app);
// Indicate that state has changed and we should save.
void markDirty();
// Erase all data stored in the EEPROM.
void factoryReset(AppState& app);
// Populate the AppState instance with values from EEPROM if they exist.
bool initialize(AppState &app);
// Load data from specified slot.
bool loadData(AppState &app, byte slot_index);
// Save data to specified slot.
void saveData(const AppState &app);
// Reset AppState instance back to default values.
void reset(AppState &app);
// Call from main loop, check if state has changed and needs to be saved.
void update(const AppState &app);
// Indicate that state has changed and we should save.
void markDirty();
// Erase all data stored in the EEPROM.
void factoryReset(AppState &app);
// This struct holds the data that identifies the firmware version.
struct Metadata {
char sketch_name[16];
char version[16];
// Additional global/hardware settings
byte selected_save_slot;
bool encoder_reversed;
};
struct ChannelState {
byte base_clock_mod_index;
byte base_probability;
byte base_duty_cycle;
byte base_offset;
byte base_swing;
byte base_euc_steps;
byte base_euc_hits;
byte cv1_dest; // Cast the CvDestination enum as a byte for storage
byte cv2_dest; // Cast the CvDestination enum as a byte for storage
};
// This struct holds all the parameters we want to save.
struct EepromData {
int tempo;
byte selected_param;
byte selected_channel;
byte selected_source;
byte selected_pulse;
ChannelState channel_data[Gravity::OUTPUT_COUNT];
};
// This struct holds the data that identifies the firmware version.
struct Metadata {
char sketch_name[16];
char version[16];
// Additional global/hardware settings
byte selected_save_slot;
bool encoder_reversed;
};
struct ChannelState {
byte base_clock_mod_index;
byte base_probability;
byte base_duty_cycle;
byte base_offset;
byte cv1_dest; // Cast the CvDestination enum as a byte for storage
byte cv2_dest; // Cast the CvDestination enum as a byte for storage
};
// This struct holds all the parameters we want to save.
struct EepromData {
int tempo;
byte selected_param;
byte selected_channel;
byte selected_source;
byte selected_pulse;
ChannelState channel_data[Gravity::OUTPUT_COUNT];
};
private:
bool _isDataValid();
void _saveMetadata(const AppState& app);
void _loadMetadata(AppState& app);
void _saveState(const AppState& app, byte slot_index);
void _loadState(AppState& app, byte slot_index);
private:
bool _isDataValid();
void _saveMetadata(const AppState &app);
void _loadMetadata(AppState &app);
void _saveState(const AppState &app, byte slot_index);
void _loadState(AppState &app, byte slot_index);
static const unsigned long SAVE_DELAY_MS;
static const int METADATA_START_ADDR;
static const int EEPROM_DATA_START_ADDR;
static const unsigned long SAVE_DELAY_MS;
static const int METADATA_START_ADDR;
static const int EEPROM_DATA_START_ADDR;
bool _isDirty;
unsigned long _lastChangeTime;
bool _isDirty;
unsigned long _lastChangeTime;
};
#endif // SAVE_STATE_H
#endif // SAVE_STATE_H