mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-04-19 12:57:19 +00:00
Create default files after factory reset
This commit is contained in:
parent
39e807ace6
commit
bbe2c373bf
@ -615,7 +615,7 @@ void dispatch_parse_jsonl(std::istream& stream)
|
||||
{
|
||||
uint8_t savedPage = haspPages.get();
|
||||
uint16_t line = 1;
|
||||
DynamicJsonDocument jsonl(MQTT_MAX_PACKET_SIZE / 2 + 128); // max ~256 characters per line
|
||||
DynamicJsonDocument jsonl(MQTT_MAX_PACKET_SIZE / 2 + 128);
|
||||
DeserializationError jsonError = deserializeJson(jsonl, stream);
|
||||
|
||||
#ifdef ARDUINO
|
||||
@ -1147,7 +1147,7 @@ bool dispatch_factory_reset()
|
||||
#endif
|
||||
|
||||
#if HASP_USE_EEPROM > 0
|
||||
erased = false;
|
||||
erased = configClearEeprom();
|
||||
#endif
|
||||
|
||||
return formated && erased;
|
||||
|
@ -63,6 +63,7 @@ void dispatch_page_next(lv_scr_load_anim_t effectid);
|
||||
void dispatch_page_prev(lv_scr_load_anim_t effectid);
|
||||
void dispatch_page_back(lv_scr_load_anim_t effectid);
|
||||
|
||||
bool dispatch_factory_reset();
|
||||
void dispatch_reboot(bool saveConfig);
|
||||
void dispatch_current_state(uint8_t source);
|
||||
void dispatch_current_page();
|
||||
|
@ -518,10 +518,8 @@ bool configClearEeprom()
|
||||
LOG_ERROR(TAG_CONF, F("Failed to clear to EEPROM"));
|
||||
return false;
|
||||
}
|
||||
#elif HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0
|
||||
return HASP_FS.format();
|
||||
#else
|
||||
return false;
|
||||
return true; // nothing to clear
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -15,8 +15,7 @@
|
||||
#endif
|
||||
|
||||
#ifndef HASP_PAGES_JSONL
|
||||
#define HASP_PAGES_JSONL \
|
||||
"{\"page\":1,\"id\":10,\"w\":240,\"obj\":\"label\",\"txt\":\"%hostname%\"}"
|
||||
#define HASP_PAGES_JSONL "{\"page\":1,\"id\":10,\"w\":240,\"obj\":\"label\",\"txt\":\"%hostname%\"}"
|
||||
#endif
|
||||
|
||||
#include <Arduino.h>
|
||||
@ -186,20 +185,27 @@ void filesystemList()
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline void filesystemCreateFile(const char* filename, const char* data)
|
||||
static void filesystem_write_file(const char* filename, const char* data)
|
||||
{
|
||||
if(HASP_FS.exists(filename)) return;
|
||||
|
||||
LOG_TRACE(TAG_CONF, F(D_FILE_SAVING), filename);
|
||||
File file = HASP_FS.open(filename, "w");
|
||||
if(!file) return;
|
||||
file.print(data);
|
||||
file.close();
|
||||
|
||||
if(file) {
|
||||
file.print(data);
|
||||
file.close();
|
||||
LOG_INFO(TAG_CONF, F(D_FILE_SAVED), filename);
|
||||
} else {
|
||||
LOG_ERROR(TAG_FILE, D_FILE_SAVE_FAILED, filename);
|
||||
}
|
||||
}
|
||||
|
||||
void filesystemSetupFiles()
|
||||
{
|
||||
filesystemCreateFile("/pages.jsonl", HASP_PAGES_JSONL);
|
||||
filesystemCreateFile("/online.cmd", HASP_ONLINE_CMD);
|
||||
filesystemCreateFile("/offline.cmd", HASP_OFFLINE_CMD);
|
||||
filesystem_write_file("/pages.jsonl", HASP_PAGES_JSONL);
|
||||
filesystem_write_file("/online.cmd", HASP_ONLINE_CMD);
|
||||
filesystem_write_file("/offline.cmd", HASP_OFFLINE_CMD);
|
||||
}
|
||||
|
||||
bool filesystemSetup(void)
|
||||
|
@ -2241,7 +2241,7 @@ void httpHandleResetConfig()
|
||||
httpMessage += F("</h1><hr>");
|
||||
|
||||
if(resetConfirmed) { // User has confirmed, so reset everything
|
||||
bool formatted = configClearEeprom();
|
||||
bool formatted = dispatch_factory_reset(); // configClearEeprom();
|
||||
if(formatted) {
|
||||
httpMessage += F("<b>Resetting all saved settings and restarting device</b>");
|
||||
} else {
|
||||
|
@ -2146,7 +2146,7 @@ void httpHandleResetConfig(AsyncWebServerRequest* request)
|
||||
httpMessage += F("</h1><hr>");
|
||||
|
||||
if(resetConfirmed) { // User has confirmed, so reset everything
|
||||
bool formatted = configClearEeprom();
|
||||
bool formatted = dispatch_factory_reset(); // configClearEeprom();
|
||||
if(formatted) {
|
||||
httpMessage += F("<b>Resetting all saved settings and restarting device</b>");
|
||||
} else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user