From 277216429ec7b00d19919906b95c55ab1f93cf06 Mon Sep 17 00:00:00 2001 From: Holger Wirtz Date: Thu, 23 May 2019 14:37:27 +0200 Subject: [PATCH] Storing and loading configs implemented. --- MicroMDAEPiano.ino | 34 ++++++++++++++++++++++++++++++++++ UI.hpp | 2 +- config.h | 2 ++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/MicroMDAEPiano.ino b/MicroMDAEPiano.ino index 0df9993..1e0cf70 100644 --- a/MicroMDAEPiano.ino +++ b/MicroMDAEPiano.ino @@ -218,6 +218,7 @@ void setup() Serial.println(F("")); #if defined (DEBUG) && defined (SHOW_CPU_LOAD_MSEC) + Serial.println(); show_cpu_and_mem_usage(); cpu_mem_millis = 0; #endif @@ -456,6 +457,37 @@ void set_master_volume(uint8_t value) EEPROM HELPER ******************************************************************************/ +void config_from_eeprom(void) +{ + uint32_t checksum; + config_t tmp_conf; + + EEPROM_readAnything(EEPROM_CONFIGURATIONS + sizeof(config_t) * (sound - 1), tmp_conf); + checksum = crc32((byte*)&tmp_conf + 4, sizeof(tmp_conf) - 4); + +#ifdef DEBUG + Serial.print(F("EEPROM checksum: 0x")); + Serial.print(tmp_conf.checksum, HEX); + Serial.print(F(" / 0x")); + Serial.print(checksum, HEX); +#endif + + if (checksum == tmp_conf.checksum) + { + EEPROM_readAnything(EEPROM_CONFIGURATIONS + sizeof(config_t) * (sound - 1), configuration); + Serial.print(F(" - OK, loading config ")); + Serial.print(sound,DEC); + } + else +#ifdef DEBUG + Serial.println(F(" - mismatch (or force) -> nothing done!")); +#endif + +#ifdef DEBUG + Serial.println(); +#endif +} + void initial_values_from_eeprom(void) { uint32_t checksum; @@ -488,6 +520,8 @@ void initial_values_from_eeprom(void) #ifdef DEBUG Serial.print(F(" - Master volume: ")); Serial.println(master_volume, DEC); + Serial.print(F("Max configs in EEPROM: ")); + Serial.println(MAX_SOUNDS); #endif } diff --git a/UI.hpp b/UI.hpp index 94e26b6..82a3883 100644 --- a/UI.hpp +++ b/UI.hpp @@ -705,7 +705,7 @@ void callback_load_sound_function() { menu_system.change_menu(load_sound_menu); menu_position[MAIN] = encoder_value[RIGHT_ENCODER]; encoder_value[RIGHT_ENCODER] = sound; - enc[RIGHT_ENCODER].write(sound, 1, 99); + enc[RIGHT_ENCODER].write(sound, 1, MAX_SOUNDS); menu_system.update(); } diff --git a/config.h b/config.h index 0506438..748bdd5 100644 --- a/config.h +++ b/config.h @@ -135,6 +135,8 @@ //* DO NO CHANGE ANYTHING BEYOND IF YOU DON'T KNOW WHAT YOU ARE DOING !!! //************************************************************************************************* +#define MAX_SOUNDS min(99,int((4096-EEPROM_CONFIGURATIONS)/sizeof(config_t))) + #define CONTROL_RATE_MS 100 #define BACK_TO_MAIN_MS 800 #define STORE_MASTER_VOLUME_MS 5000