/** * TODO file description */ #include #include #include "app_config.h" #include "ee.h" #define APPCONFIG_EE_BASE_ADDR 0 // TODO sensible defaults, loading and saving to/from EE struct AppConfig app_config; static const struct AppConfig DEFAULTS = { .circuit_base_time_s = 300, // for a test .circuit_time_percent = {100, 100, 100, 100}, // for a test .scheduler_enable = true, .schedules = { {true, 7, 0}, {true, 14, 0}, {true, 20, 0}, {false, 0, 0} }, .moisture_enable = false, .moisture_dry = 2800, .moisture_wet = 1600, .moisture_threshold_percent = 70, }; static void load_fallback_config() { // Read failed, load defaults memcpy(&app_config, &DEFAULTS, sizeof(struct AppConfig)); } void appconfig_load() { uint8_t magic = 0; if (0 > ee_read(APPCONFIG_EE_BASE_ADDR, &magic, 1) || magic != APPCONFIG_VERSION) { printf("Couldn't read EE to check magic!\r\n"); load_fallback_config(); return; } if (0 > ee_read(APPCONFIG_EE_BASE_ADDR, (uint8_t *) &app_config, APPCONFIG_SIZE)) { printf("Couldn't read EE to load config!\r\n"); load_fallback_config(); } } void appconfig_save() { // printf("PERSISTENCE DISABLED - NOT SAVING\r\n"); // return; // FIXME - when all GUIs are finished, add persistence // whatever, just write everything app_config.magic_version = APPCONFIG_VERSION; if (0 > ee_write(APPCONFIG_EE_BASE_ADDR, (const uint8_t *) &app_config, APPCONFIG_SIZE)) { printf("Couldn't write EE!"); } }