2022-04-10 16:57:24 +02:00
|
|
|
#include "Configuration.h"
|
2022-04-10 17:37:54 +02:00
|
|
|
#include "defaults.h"
|
2022-04-13 23:05:32 +02:00
|
|
|
#include <LITTLEFS.h>
|
2022-04-10 16:57:24 +02:00
|
|
|
|
|
|
|
|
CONFIG_T config;
|
|
|
|
|
|
|
|
|
|
void ConfigurationClass::init()
|
|
|
|
|
{
|
|
|
|
|
memset(&config, 0x0, sizeof(config));
|
|
|
|
|
config.Cfg_SaveCount = 0;
|
|
|
|
|
config.Cfg_Version = CONFIG_VERSION;
|
2022-04-10 17:37:54 +02:00
|
|
|
|
|
|
|
|
// WiFi Settings
|
|
|
|
|
strlcpy(config.WiFi_Ssid, WIFI_SSID, sizeof(config.WiFi_Ssid));
|
|
|
|
|
strlcpy(config.WiFi_Password, WIFI_PASSWORD, sizeof(config.WiFi_Password));
|
|
|
|
|
config.WiFi_Dhcp = WIFI_DHCP;
|
|
|
|
|
strlcpy(config.WiFi_Hostname, APP_HOSTNAME, sizeof(config.WiFi_Hostname));
|
2022-04-10 16:57:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ConfigurationClass::write()
|
|
|
|
|
{
|
|
|
|
|
File f = LITTLEFS.open(CONFIG_FILENAME, "w");
|
|
|
|
|
if (!f) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
config.Cfg_SaveCount++;
|
|
|
|
|
uint8_t* bytes = (uint8_t*)&config;
|
|
|
|
|
for (unsigned int i = 0; i < sizeof(CONFIG_T); i++) {
|
|
|
|
|
f.write(bytes[i]);
|
|
|
|
|
}
|
|
|
|
|
f.close();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ConfigurationClass::read()
|
|
|
|
|
{
|
|
|
|
|
File f = LITTLEFS.open(CONFIG_FILENAME, "r");
|
|
|
|
|
if (!f) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
uint8_t* bytes = (uint8_t*)&config;
|
|
|
|
|
for (unsigned int i = 0; i < sizeof(CONFIG_T); i++) {
|
|
|
|
|
bytes[i] = f.read();
|
|
|
|
|
}
|
|
|
|
|
f.close();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ConfigurationClass::migrate()
|
|
|
|
|
{
|
|
|
|
|
config.Cfg_Version = CONFIG_VERSION;
|
|
|
|
|
write();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CONFIG_T& ConfigurationClass::get()
|
|
|
|
|
{
|
|
|
|
|
return config;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ConfigurationClass Configuration;
|