-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move setting storage related settings from Software.ino to nvme folder
- Loading branch information
Showing
3 changed files
with
105 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
#include "comm_nvm.h" | ||
#include "../../include.h" | ||
|
||
// Parameters | ||
Preferences settings; // Store user settings | ||
|
||
// Initialization functions | ||
|
||
void init_stored_settings() { | ||
static uint32_t temp = 0; | ||
settings.begin("batterySettings", false); | ||
|
||
// Always get the equipment stop status | ||
datalayer.system.settings.equipment_stop_active = settings.getBool("EQUIPMENT_STOP", false); | ||
if (datalayer.system.settings.equipment_stop_active) { | ||
set_event(EVENT_EQUIPMENT_STOP, 1); | ||
} | ||
|
||
#ifndef LOAD_SAVED_SETTINGS_ON_BOOT | ||
settings.clear(); // If this clear function is executed, no settings will be read from storage | ||
|
||
//always save the equipment stop status | ||
settings.putBool("EQUIPMENT_STOP", datalayer.system.settings.equipment_stop_active); | ||
#endif // LOAD_SAVED_SETTINGS_ON_BOOT | ||
|
||
#ifdef WIFI | ||
char tempSSIDstring[63]; // Allocate buffer with sufficient size | ||
size_t lengthSSID = settings.getString("SSID", tempSSIDstring, sizeof(tempSSIDstring)); | ||
if (lengthSSID > 0) { // Successfully read the string from memory. Set it to SSID! | ||
ssid = tempSSIDstring; | ||
} else { // Reading from settings failed. Do nothing with SSID. Raise event? | ||
} | ||
char tempPasswordString[63]; // Allocate buffer with sufficient size | ||
size_t lengthPassword = settings.getString("PASSWORD", tempPasswordString, sizeof(tempPasswordString)); | ||
if (lengthPassword > 7) { // Successfully read the string from memory. Set it to password! | ||
password = tempPasswordString; | ||
} else { // Reading from settings failed. Do nothing with SSID. Raise event? | ||
} | ||
#endif // WIFI | ||
|
||
temp = settings.getUInt("BATTERY_WH_MAX", false); | ||
if (temp != 0) { | ||
datalayer.battery.info.total_capacity_Wh = temp; | ||
} | ||
temp = settings.getUInt("MAXPERCENTAGE", false); | ||
if (temp != 0) { | ||
datalayer.battery.settings.max_percentage = temp * 10; // Multiply by 10 for backwards compatibility | ||
} | ||
temp = settings.getUInt("MINPERCENTAGE", false); | ||
if (temp != 0) { | ||
datalayer.battery.settings.min_percentage = temp * 10; // Multiply by 10 for backwards compatibility | ||
} | ||
temp = settings.getUInt("MAXCHARGEAMP", false); | ||
if (temp != 0) { | ||
datalayer.battery.settings.max_user_set_charge_dA = temp; | ||
} | ||
temp = settings.getUInt("MAXDISCHARGEAMP", false); | ||
if (temp != 0) { | ||
datalayer.battery.settings.max_user_set_discharge_dA = temp; | ||
temp = settings.getBool("USE_SCALED_SOC", false); | ||
datalayer.battery.settings.soc_scaling_active = temp; //This bool needs to be checked inside the temp!= block | ||
} // No way to know if it wasnt reset otherwise | ||
|
||
settings.end(); | ||
} | ||
|
||
void store_settings_equipment_stop() { | ||
settings.begin("batterySettings", false); | ||
settings.putBool("EQUIPMENT_STOP", datalayer.system.settings.equipment_stop_active); | ||
settings.end(); | ||
} | ||
|
||
void storeSettings() { | ||
settings.begin("batterySettings", false); | ||
#ifdef WIFI | ||
settings.putString("SSID", String(ssid.c_str())); | ||
settings.putString("PASSWORD", String(password.c_str())); | ||
#endif | ||
settings.putUInt("BATTERY_WH_MAX", datalayer.battery.info.total_capacity_Wh); | ||
settings.putUInt("MAXPERCENTAGE", | ||
datalayer.battery.settings.max_percentage / 10); // Divide by 10 for backwards compatibility | ||
settings.putUInt("MINPERCENTAGE", | ||
datalayer.battery.settings.min_percentage / 10); // Divide by 10 for backwards compatibility | ||
settings.putUInt("MAXCHARGEAMP", datalayer.battery.settings.max_user_set_charge_dA); | ||
settings.putUInt("MAXDISCHARGEAMP", datalayer.battery.settings.max_user_set_discharge_dA); | ||
settings.putBool("USE_SCALED_SOC", datalayer.battery.settings.soc_scaling_active); | ||
settings.end(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#ifndef _COMM_NVM_H_ | ||
#define _COMM_NVM_H_ | ||
|
||
#include "../../include.h" | ||
|
||
#include "../../datalayer/datalayer.h" | ||
#include "../../devboard/utils/events.h" | ||
#include "../../devboard/wifi/wifi.h" | ||
|
||
void init_stored_settings(); | ||
|
||
void store_settings_equipment_stop(); | ||
|
||
void storeSettings(); | ||
|
||
#endif |