simplify eeprom handling
This commit is contained in:
@ -14,6 +14,8 @@ tConfigBlock configBlock;
|
||||
const uint32_t MAGIC = 0xC0DE0001;
|
||||
extern ESP8266WebServer webServer;
|
||||
|
||||
bool configSaved = false;
|
||||
|
||||
void configServeIndex() {
|
||||
bool configValid = (configBlock.magic == MAGIC);
|
||||
|
||||
@ -36,7 +38,14 @@ void configServeIndex() {
|
||||
" <title>ESP8266 Thermometer Configuration Page</title>"
|
||||
" </head>"
|
||||
" <body>"
|
||||
" <h1>ESP8266 Configuration Page</h1>"
|
||||
" <h1>ESP8266 Configuration Page</h1>";
|
||||
|
||||
if (configSaved) {
|
||||
configSaved = false;
|
||||
buffer += "<h2>Configuration saved</h2>";
|
||||
}
|
||||
|
||||
buffer +=
|
||||
" <form action=\"/config\" method=\"GET\">"
|
||||
" <table>"
|
||||
#for $configItem in $configItems
|
||||
@ -88,8 +97,6 @@ void configServeGetConfiguration() {
|
||||
#for $configItem in $configItems
|
||||
#if $configItem.label != "_"
|
||||
arg = webServer.arg("$configItem.key");
|
||||
Serial.print("$configItem.key");
|
||||
Serial.println(arg);
|
||||
#if $configItem.type == "C"
|
||||
strcpy(configBlock.$configItem.key, arg.c_str());
|
||||
#else if $configItem.type == "I"
|
||||
@ -103,19 +110,15 @@ void configServeGetConfiguration() {
|
||||
showConfiguration();
|
||||
|
||||
EEPROM.begin(512);
|
||||
for (uint16_t i = 0; i < sizeof(configBlock); i++) {
|
||||
char c = *(((char*)(&configBlock))+i);
|
||||
Serial.print("write to eeprom: ");
|
||||
Serial.print(i);
|
||||
Serial.print(" ");
|
||||
Serial.println(c);
|
||||
EEPROM.write(EEPROM_ADDR + i, c);
|
||||
}
|
||||
EEPROM.put(EEPROM_ADDR, configBlock);
|
||||
EEPROM.commit();
|
||||
|
||||
Serial.println("EEPROM saved");
|
||||
|
||||
webServer.send(200, "text/html", "configuration saved");
|
||||
|
||||
configSaved = true;
|
||||
webServer.sendHeader("Location", String("/"), true);
|
||||
webServer.send(302, "text/plain", "");
|
||||
//webServer.send(200, "text/html", "configuration saved");
|
||||
}
|
||||
|
||||
void showConfiguration() {
|
||||
|
Reference in New Issue
Block a user