Browse Source

Added EEPROM management commands to terminal interface

fastled
Xose Pérez 8 years ago
parent
commit
8a21133ecf
4 changed files with 56 additions and 11 deletions
  1. +1
    -1
      code/src/main.ino
  2. +3
    -3
      code/src/pow.ino
  3. +49
    -4
      code/src/settings.ino
  4. +3
    -3
      code/src/web.ino

+ 1
- 1
code/src/main.ino View File

@ -111,7 +111,7 @@ void setup() {
settingsSetup();
if (getSetting("hostname").length() == 0) {
setSetting("hostname", String() + getIdentifier());
setSetting("hostname", getIdentifier());
saveSettings();
}


+ 3
- 3
code/src/pow.ino View File

@ -41,9 +41,9 @@ void powDettachInterrupts() {
}
void powSaveCalibration() {
setSetting("powPowerMult", String() + hlw8012.getPowerMultiplier());
setSetting("powCurrentMult", String() + hlw8012.getCurrentMultiplier());
setSetting("powVoltageMult", String() + hlw8012.getVoltageMultiplier());
setSetting("powPowerMult", hlw8012.getPowerMultiplier());
setSetting("powCurrentMult", hlw8012.getCurrentMultiplier());
setSetting("powVoltageMult", hlw8012.getVoltageMultiplier());
}
void powRetrieveCalibration() {


+ 49
- 4
code/src/settings.ino View File

@ -20,6 +20,21 @@ Embedis embedis(Serial);
// Settings
// -----------------------------------------------------------------------------
unsigned long settingsSize() {
bool zero = false;
unsigned long size = 0;
for (unsigned int i = SPI_FLASH_SEC_SIZE; i>0; i--) {
size++;
if (EEPROM.read(i) == 0) {
if (zero) break;
zero = true;
} else {
zero = false;
}
}
return size-2;
}
void settingsSetup() {
EEPROM.begin(SPI_FLASH_SEC_SIZE);
@ -35,24 +50,46 @@ void settingsSetup() {
#endif
);
Embedis::hardware( F("wifi"), [](Embedis* e) {
Embedis::hardware( F("WIFI"), [](Embedis* e) {
StreamString s;
WiFi.printDiag(s);
e->response(s);
}, 0);
Embedis::command( F("reconnect"), [](Embedis* e) {
Embedis::command( F("RECONNECT"), [](Embedis* e) {
wifiConfigure();
wifiDisconnect();
e->response(Embedis::OK);
});
Embedis::command( F("reset"), [](Embedis* e) {
Embedis::command( F("RESET"), [](Embedis* e) {
e->response(Embedis::OK);
ESP.reset();
});
DEBUG_MSG("[SETTINGS] Initialized\n");
Embedis::command( F("EEPROM.DUMP"), [](Embedis* e) {
for (unsigned int i = 0; i < SPI_FLASH_SEC_SIZE; i++) {
if (i % 16 == 0) Serial.printf("\n[%04X] ", i);
Serial.printf("%02X ", EEPROM.read(i));
}
Serial.printf("\n");
e->response(Embedis::OK);
});
Embedis::command( F("EEPROM.ERASE"), [](Embedis* e) {
for (unsigned int i = 0; i < SPI_FLASH_SEC_SIZE; i++) {
EEPROM.write(i, 0xFF);
}
EEPROM.commit();
e->response(Embedis::OK);
});
Embedis::command( F("SETTINGS.SIZE"), [](Embedis* e) {
e->response(String(settingsSize()));
});
DEBUG_MSG("[SETTINGS] EEPROM size: %d bytes\n", SPI_FLASH_SEC_SIZE);
DEBUG_MSG("[SETTINGS] Settings size: %d bytes\n", settingsSize());
}
@ -70,6 +107,14 @@ bool setSetting(const String& key, String& value) {
return Embedis::set(key, value);
}
bool setSetting(const String& key, char * value) {
return Embedis::set(key, String(value));
}
bool setSetting(const String& key, bool value) {
return Embedis::set(key, value ? String("0") : String("1"));
}
bool delSetting(const String& key) {
return Embedis::del(key);
}


+ 3
- 3
code/src/web.ino View File

@ -155,12 +155,12 @@ void _wsParse(uint32_t client_id, uint8_t * payload, size_t length) {
// Checkboxes
if (apiEnabled != (getSetting("apiEnabled").toInt() == 1)) {
setSetting("apiEnabled", String() + (apiEnabled ? 1 : 0));
setSetting("apiEnabled", apiEnabled);
dirty = true;
}
#if ENABLE_FAUXMO
if (fauxmoEnabled != (getSetting("fauxmoEnabled").toInt() == 1)) {
setSetting("fauxmoEnabled", String() + (fauxmoEnabled ? 1 : 0));
setSetting("fauxmoEnabled", fauxmoEnabled);
dirty = true;
}
#endif
@ -502,7 +502,7 @@ void webSetup() {
char lastModified[50];
sprintf(lastModified, "%s %s GMT", __DATE__, __TIME__);
server.serveStatic("/", SPIFFS, "/").setLastModified(lastModified);
// 404
server.onNotFound([](AsyncWebServerRequest *request){
request->send(404);


Loading…
Cancel
Save