diff --git a/Software/Software.ino b/Software/Software.ino index 3b0cb5db..664f9852 100644 --- a/Software/Software.ino +++ b/Software/Software.ino @@ -19,7 +19,7 @@ #include "src/devboard/webserver/webserver.h" #endif -Preferences preferences; // Parameter storage +Preferences settings; // Store user settings // Interval settings int intervalUpdateValues = 4800; // Interval at which to update inverter values / Modbus registers @@ -105,7 +105,7 @@ bool inverterAllowsContactorClosing = true; void setup() { init_serial(); - init_storage(); + init_stored_settings(); #ifdef WEBSERVER init_webserver(); @@ -174,35 +174,35 @@ void init_serial() { Serial.println("__ OK __"); } -void init_storage() { - preferences.begin("batterySettings", false); +void init_stored_settings() { + settings.begin("batterySettings", false); -#ifdef CLEAR_SAVED_SETTINGS - preferences.clear(); // If this clear function is executed, no parameters will be read from storage +#ifndef LOAD_SAVED_SETTINGS_ON_BOOT + settings.clear(); // If this clear function is executed, no settings will be read from storage #endif static uint16_t temp = 0; - temp = preferences.getUInt("BATTERY_WH_MAX", false); + temp = settings.getUInt("BATTERY_WH_MAX", false); if (temp != 0) { BATTERY_WH_MAX = temp; } - temp = preferences.getUInt("MAXPERCENTAGE", false); + temp = settings.getUInt("MAXPERCENTAGE", false); if (temp != 0) { MAXPERCENTAGE = temp; } - temp = preferences.getUInt("MINPERCENTAGE", false); + temp = settings.getUInt("MINPERCENTAGE", false); if (temp != 0) { MINPERCENTAGE = temp; } - temp = preferences.getUInt("MAXCHARGEAMP", false); + temp = settings.getUInt("MAXCHARGEAMP", false); if (temp != 0) { MAXCHARGEAMP = temp; } - temp = preferences.getUInt("MAXDISCHARGEAMP", false); + temp = settings.getUInt("MAXDISCHARGEAMP", false); if (temp != 0) { MAXDISCHARGEAMP = temp; } - preferences.end(); + settings.end(); } void init_CAN() { @@ -706,12 +706,12 @@ void init_serialDataLink() { #endif } -void storeParameters() { - preferences.begin("batterySettings", false); - preferences.putUInt("BATTERY_WH_MAX", BATTERY_WH_MAX); - preferences.putUInt("MAXPERCENTAGE", MAXPERCENTAGE); - preferences.putUInt("MINPERCENTAGE", MINPERCENTAGE); - preferences.putUInt("MAXCHARGEAMP", MAXCHARGEAMP); - preferences.putUInt("MAXDISCHARGEAMP", MAXDISCHARGEAMP); - preferences.end(); +void storeSettings() { + settings.begin("batterySettings", false); + settings.putUInt("BATTERY_WH_MAX", BATTERY_WH_MAX); + settings.putUInt("MAXPERCENTAGE", MAXPERCENTAGE); + settings.putUInt("MINPERCENTAGE", MINPERCENTAGE); + settings.putUInt("MAXCHARGEAMP", MAXCHARGEAMP); + settings.putUInt("MAXDISCHARGEAMP", MAXDISCHARGEAMP); + settings.end(); } diff --git a/Software/USER_SETTINGS.h b/Software/USER_SETTINGS.h index 28e32e86..009033c1 100644 --- a/Software/USER_SETTINGS.h +++ b/Software/USER_SETTINGS.h @@ -17,7 +17,7 @@ //#define RENAULT_ZOE_BATTERY //#define SANTA_FE_PHEV_BATTERY //#define TESLA_MODEL_3_BATTERY -#define TEST_FAKE_BATTERY +//#define TEST_FAKE_BATTERY /* Select inverter communication protocol. See Wiki for which to use with your inverter: https://github.com/dalathegreat/BYD-Battery-Emulator-For-Gen24/wiki */ //#define BYD_CAN //Enable this line to emulate a "BYD Battery-Box Premium HVS" over CAN Bus @@ -37,7 +37,7 @@ //#define SERIAL_LINK_RECEIVER //Enable this line to receive battery data over RS485 pins from another Lilygo (This LilyGo interfaces with inverter) //#define SERIAL_LINK_TRANSMITTER //Enable this line to send battery data over RS485 pins to another Lilygo (This LilyGo interfaces with battery) #define WEBSERVER //Enable this line to enable WiFi, and to run the webserver. See USER_SETTINGS.cpp for the Wifi settings. -//#define CLEAR_SAVED_SETTINGS //Enable this line to clear all data that has been saved via the webserver page +#define LOAD_SAVED_SETTINGS_ON_BOOT //Enable this line to read settings stored via the webserver on boot /* Battery limits: These are set in the USER_SETTINGS.cpp file, or later on via the Webserver */ extern volatile uint16_t BATTERY_WH_MAX; diff --git a/Software/src/devboard/webserver/webserver.cpp b/Software/src/devboard/webserver/webserver.cpp index 1ff67d6d..d19cea82 100644 --- a/Software/src/devboard/webserver/webserver.cpp +++ b/Software/src/devboard/webserver/webserver.cpp @@ -68,7 +68,7 @@ void init_webserver() { if (request->hasParam("value")) { String value = request->getParam("value")->value(); BATTERY_WH_MAX = value.toInt(); - storeParameters(); + storeSettings(); request->send(200, "text/plain", "Updated successfully"); } else { request->send(400, "text/plain", "Bad Request"); @@ -80,7 +80,7 @@ void init_webserver() { if (request->hasParam("value")) { String value = request->getParam("value")->value(); MAXPERCENTAGE = value.toInt() * 10; - storeParameters(); + storeSettings(); request->send(200, "text/plain", "Updated successfully"); } else { request->send(400, "text/plain", "Bad Request"); @@ -92,7 +92,7 @@ void init_webserver() { if (request->hasParam("value")) { String value = request->getParam("value")->value(); MINPERCENTAGE = value.toInt() * 10; - storeParameters(); + storeSettings(); request->send(200, "text/plain", "Updated successfully"); } else { request->send(400, "text/plain", "Bad Request"); @@ -104,7 +104,7 @@ void init_webserver() { if (request->hasParam("value")) { String value = request->getParam("value")->value(); MAXCHARGEAMP = value.toInt() * 10; - storeParameters(); + storeSettings(); request->send(200, "text/plain", "Updated successfully"); } else { request->send(400, "text/plain", "Bad Request"); @@ -116,7 +116,7 @@ void init_webserver() { if (request->hasParam("value")) { String value = request->getParam("value")->value(); MAXDISCHARGEAMP = value.toInt() * 10; - storeParameters(); + storeSettings(); request->send(200, "text/plain", "Updated successfully"); } else { request->send(400, "text/plain", "Bad Request"); diff --git a/Software/src/devboard/webserver/webserver.h b/Software/src/devboard/webserver/webserver.h index 30a14d2c..3d3a8ee2 100644 --- a/Software/src/devboard/webserver/webserver.h +++ b/Software/src/devboard/webserver/webserver.h @@ -128,7 +128,7 @@ void onOTAEnd(bool success); template String formatPowerValue(String label, T value, String unit, int precision); -extern void storeParameters(); -extern void restoreParameters(); +extern void storeSettings(); +extern void restoreSettings(); #endif