You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
1.6 KiB
59 lines
1.6 KiB
/**
|
|
* TODO file description
|
|
*/
|
|
|
|
#include <string.h>
|
|
#include <stdio.h>
|
|
#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 = 10, // for a test
|
|
.circuit_time_percent = {30, 60, 90, 100}, // for a test
|
|
.schedules = {
|
|
{true, 6, 45},
|
|
{false, 255, 0},
|
|
{false, 255, 0},
|
|
{false, 255, 0}
|
|
},
|
|
.moisture_enable = true,
|
|
.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
|
|
if (0 != ee_write(APPCONFIG_EE_BASE_ADDR, (const uint8_t *) &app_config, APPCONFIG_SIZE)) {
|
|
printf("Couldn't write EE!");
|
|
}
|
|
}
|
|
|