works so far
This commit is contained in:
@ -3,7 +3,9 @@
|
||||
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <ESP8266WebServer.h>
|
||||
#include <EEPROM.h>
|
||||
|
||||
#include "defines.h"
|
||||
#include "configuration.h"
|
||||
#end raw
|
||||
|
||||
@ -12,10 +14,22 @@ tConfigBlock configBlock;
|
||||
const uint32_t MAGIC = 0xC0DE0001;
|
||||
extern ESP8266WebServer webServer;
|
||||
|
||||
|
||||
void configServeIndex() {
|
||||
webServer.send(200, "text/html",
|
||||
""
|
||||
bool configValid = (configBlock.magic == MAGIC);
|
||||
|
||||
if (! configValid) {
|
||||
#for $configItem in $configItems
|
||||
#if $configItem.label != "_"
|
||||
#if $configItem.type == "C"
|
||||
strcpy(configBlock.$configItem.key, "$configItem.default");
|
||||
#else if $configItem.type == "I"
|
||||
configBlock.$configItem.key = $configItem.default;
|
||||
#end if
|
||||
#end if
|
||||
#end for
|
||||
}
|
||||
|
||||
String buffer =
|
||||
"<!doctype html"
|
||||
"<html lang=\"en\">"
|
||||
" <head>"
|
||||
@ -31,7 +45,20 @@ void configServeIndex() {
|
||||
" <td>"
|
||||
" <label for\"$configItem.key\">$configItem.label</label>"
|
||||
" </td><td>"
|
||||
" <input type=\"text\" name=\"$configItem.key\" id=\"$configItem.key\""
|
||||
" <input type=\"text\" name=\"$configItem.key\" id=\"$configItem.key\" ";
|
||||
|
||||
#if $configItem.type == "C"
|
||||
buffer += " size=\"$configItem.length\" ";
|
||||
buffer += " value=\"";
|
||||
buffer += configBlock.$configItem.key;
|
||||
buffer += "\"";
|
||||
#else if $configItem.type == "I"
|
||||
buffer += " value=\"";
|
||||
buffer += configBlock.$configItem.key;
|
||||
buffer += "\"";
|
||||
#end if
|
||||
|
||||
buffer +=
|
||||
" />"
|
||||
" </td>"
|
||||
" </tr>"
|
||||
@ -45,8 +72,9 @@ void configServeIndex() {
|
||||
" </table>"
|
||||
" </form>"
|
||||
" </body>"
|
||||
"</html>"
|
||||
);
|
||||
"</html>";
|
||||
|
||||
webServer.send(200, "text/html", buffer);
|
||||
|
||||
|
||||
#ifdef DEBUG
|
||||
@ -62,9 +90,31 @@ void configServeGetConfiguration() {
|
||||
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"
|
||||
configBlock.$configItem.key = atoi(arg.c_str());
|
||||
#end if
|
||||
#end if
|
||||
#end for
|
||||
|
||||
configBlock.magic = MAGIC;
|
||||
|
||||
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.commit();
|
||||
|
||||
Serial.println("EEPROM saved");
|
||||
|
||||
webServer.send(200, "text/html", "configuration saved");
|
||||
}
|
||||
|
||||
@ -72,11 +122,9 @@ void showConfiguration() {
|
||||
Serial.println("Configuration is");
|
||||
|
||||
#for $configItem in $configItems
|
||||
#if $configItem.label != "_"
|
||||
Serial.print("$configItem.key = ");
|
||||
Serial.println(configBlock.$configItem.key);
|
||||
|
||||
#end if
|
||||
#end for
|
||||
|
||||
Serial.println("---");
|
||||
|
Reference in New Issue
Block a user