mirror of https://github.com/arendst/Tasmota.git
Fix driver config restore
This commit is contained in:
parent
8c31acd376
commit
889e6ea54d
|
@ -428,7 +428,7 @@ enum LightTypes { LT_BASIC, LT_PWM1, LT_PWM2, LT_PWM3, LT_PWM4, LT
|
|||
|
||||
enum XsnsFunctions { FUNC_SETTINGS_OVERRIDE, FUNC_SETUP_RING1, FUNC_SETUP_RING2, FUNC_PRE_INIT, FUNC_INIT,
|
||||
FUNC_LOOP, FUNC_SLEEP_LOOP, FUNC_EVERY_50_MSECOND, FUNC_EVERY_100_MSECOND, FUNC_EVERY_200_MSECOND, FUNC_EVERY_250_MSECOND, FUNC_EVERY_SECOND,
|
||||
FUNC_RESET_SETTINGS, FUNC_SAVE_SETTINGS, FUNC_SAVE_AT_MIDNIGHT, FUNC_SAVE_BEFORE_RESTART, FUNC_INTERRUPT_STOP, FUNC_INTERRUPT_START,
|
||||
FUNC_RESET_SETTINGS, FUNC_RESTORE_SETTINGS, FUNC_SAVE_SETTINGS, FUNC_SAVE_AT_MIDNIGHT, FUNC_SAVE_BEFORE_RESTART, FUNC_INTERRUPT_STOP, FUNC_INTERRUPT_START,
|
||||
FUNC_AFTER_TELEPERIOD, FUNC_JSON_APPEND, FUNC_WEB_SENSOR, FUNC_WEB_COL_SENSOR,
|
||||
FUNC_MQTT_SUBSCRIBE, FUNC_MQTT_INIT,
|
||||
FUNC_SET_POWER, FUNC_SHOW_SENSOR, FUNC_ANY_KEY, FUNC_LED_LINK,
|
||||
|
|
|
@ -544,14 +544,22 @@ bool SettingsConfigRestore(void) {
|
|||
if (settings_size > sizeof(TSettings)) {
|
||||
uint8_t *filebuf_ptr = settings_buffer + sizeof(TSettings);
|
||||
while ((filebuf_ptr - settings_buffer) < settings_size) {
|
||||
filebuf_ptr += 14;
|
||||
uint32_t fsize = *filebuf_ptr;
|
||||
filebuf_ptr++;
|
||||
fsize += *filebuf_ptr << 8;
|
||||
filebuf_ptr++;
|
||||
AddLog(LOG_LEVEL_DEBUG, PSTR("CFG: Restore file %s (%d)"), (char*)filebuf_ptr -16, fsize);
|
||||
TfsSaveFile((const char*)filebuf_ptr -16, (uint8_t*)filebuf_ptr, fsize);
|
||||
filebuf_ptr += ((fsize / 16) * 16) + 16;
|
||||
uint32_t driver = atoi((const char*)filebuf_ptr +8); // /.drvset012 = 12
|
||||
uint32_t fsize = filebuf_ptr[15] << 8 | filebuf_ptr[14]; // Tar header settings size
|
||||
filebuf_ptr += 16; // Start of file settings
|
||||
uint32_t buffer_crc32 = filebuf_ptr[3] << 24 | filebuf_ptr[2] << 16 | filebuf_ptr[1] << 8 | filebuf_ptr[0];
|
||||
bool valid_buffer = (GetCfgCrc32(filebuf_ptr +4, fsize -4) == buffer_crc32);
|
||||
if (valid_buffer) {
|
||||
XdrvMailbox.data = (char*)filebuf_ptr;
|
||||
XdrvMailbox.index = fsize;
|
||||
if (XdrvCallDriver(driver, FUNC_RESTORE_SETTINGS)) {
|
||||
AddLog(LOG_LEVEL_DEBUG, PSTR("CFG: Restore driver %d"), driver);
|
||||
} else {
|
||||
AddLog(LOG_LEVEL_DEBUG, PSTR("CFG: Restore file %s (%d)"), (char*)filebuf_ptr -16, fsize);
|
||||
TfsSaveFile((const char*)filebuf_ptr -16, (uint8_t*)filebuf_ptr, fsize);
|
||||
}
|
||||
}
|
||||
filebuf_ptr += ((fsize / 16) * 16) + 16; // Next tar header or eof
|
||||
}
|
||||
}
|
||||
#endif // USE_UFILESYS
|
||||
|
|
|
@ -372,6 +372,14 @@ void EnergySettingsSave(void) {
|
|||
#endif // USE_UFILESYS
|
||||
}
|
||||
|
||||
bool EnergySettingsRestore(void) {
|
||||
#ifdef USE_UFILESYS
|
||||
uint32_t max_size = (XdrvMailbox.index > sizeof(tEnergySettings)) ? sizeof(tEnergySettings) : XdrvMailbox.index;
|
||||
memcpy((uint8_t*)&Energy->Settings, (uint8_t*)XdrvMailbox.data, max_size); // Restore version and auto upgrade after restart
|
||||
return true;
|
||||
#endif // USE_UFILESYS
|
||||
}
|
||||
|
||||
/********************************************************************************************/
|
||||
|
||||
const uint16_t GUISZ = 600; // Max number of characters in WebEnergyFmt string
|
||||
|
@ -1764,6 +1772,9 @@ bool Xdrv03(uint32_t function)
|
|||
case FUNC_RESET_SETTINGS:
|
||||
EnergySettingsLoad(1);
|
||||
break;
|
||||
case FUNC_RESTORE_SETTINGS:
|
||||
result = EnergySettingsRestore();
|
||||
break;
|
||||
case FUNC_SAVE_SETTINGS:
|
||||
EnergySettingsSave();
|
||||
EnergyRtcSettingsSave();
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
|
||||
#define DRV_DEMO_MAX_DRV_TEXT 16
|
||||
|
||||
const uint32_t DRV_DEMO_VERSION = 0x01010101; // Latest driver version (See settings deltas below)
|
||||
const uint32_t DRV_DEMO_VERSION = 0x0101; // Latest driver version (See settings deltas below)
|
||||
|
||||
// Demo command line commands
|
||||
const char kDrvDemoCommands[] PROGMEM = "Drv|" // Prefix
|
||||
|
@ -46,7 +46,8 @@ void (* const DrvDemoCommand[])(void) PROGMEM = {
|
|||
// Global structure containing driver saved variables
|
||||
struct {
|
||||
uint32_t crc32; // To detect file changes
|
||||
uint32_t version; // To detect driver function changes
|
||||
uint16_t version; // To detect driver function changes
|
||||
uint16_t spare;
|
||||
char drv_text[DRV_DEMO_MAX_DRV_TEXT -1][10];
|
||||
} DrvDemoSettings;
|
||||
|
||||
|
@ -155,6 +156,14 @@ void DrvDemoSettingsSave(void) {
|
|||
#endif // USE_UFILESYS
|
||||
}
|
||||
|
||||
bool DrvDemoSettingsRestore(void) {
|
||||
#ifdef USE_UFILESYS
|
||||
uint32_t max_size = (XdrvMailbox.index > sizeof(DrvDemoSettings)) ? sizeof(DrvDemoSettings) : XdrvMailbox.index;
|
||||
memcpy((uint8_t*)&DrvDemoSettings, (uint8_t*)XdrvMailbox.data, max_size); // Restore version and auto upgrade after restart
|
||||
return true;
|
||||
#endif // USE_UFILESYS
|
||||
}
|
||||
|
||||
/*********************************************************************************************\
|
||||
* Interface
|
||||
\*********************************************************************************************/
|
||||
|
@ -166,6 +175,9 @@ bool Xdrv122(uint32_t function) {
|
|||
case FUNC_RESET_SETTINGS:
|
||||
DrvDemoSettingsLoad(1);
|
||||
break;
|
||||
case FUNC_RESTORE_SETTINGS:
|
||||
result = DrvDemoSettingsRestore();
|
||||
break;
|
||||
case FUNC_SAVE_SETTINGS:
|
||||
DrvDemoSettingsSave();
|
||||
break;
|
||||
|
|
|
@ -53,7 +53,7 @@ const char HTTP_MSG_SLIDER_SHUTTER[] PROGMEM =
|
|||
"<div><span class='p'>%s</span><span class='q'>%s</span></div>"
|
||||
"<div><input type='range' min='0' max='100' value='%d' onchange='lc(\"u\",%d,value)'></div>";
|
||||
|
||||
const uint32_t SHUTTER_VERSION = 0x01010100; // Latest driver version (See settings deltas below)
|
||||
const uint32_t SHUTTER_VERSION = 0x0100; // Latest driver version (See settings deltas below)
|
||||
|
||||
typedef struct { // depreciated 2023-04-28
|
||||
int8_t pos;
|
||||
|
@ -86,7 +86,8 @@ typedef struct {
|
|||
// Global structure containing shutter saved variables
|
||||
struct SHUTTERSETTINGS {
|
||||
uint32_t crc32; // To detect file changes
|
||||
uint32_t version; // To detect driver function changes
|
||||
uint16_t version; // To detect driver function changes
|
||||
uint16_t spare;
|
||||
uint8_t shutter_accuracy;
|
||||
uint8_t shutter_mode;
|
||||
uint16_t shutter_motorstop;
|
||||
|
@ -340,6 +341,14 @@ void ShutterSettingsSave(void) {
|
|||
}
|
||||
}
|
||||
|
||||
bool ShutterSettingsRestore(void) {
|
||||
#ifdef USE_UFILESYS
|
||||
uint32_t max_size = (XdrvMailbox.index > sizeof(ShutterSettings)) ? sizeof(ShutterSettings) : XdrvMailbox.index;
|
||||
memcpy((uint8_t*)&ShutterSettings, (uint8_t*)XdrvMailbox.data, max_size); // Restore version and auto upgrade after restart
|
||||
return true;
|
||||
#endif // USE_UFILESYS
|
||||
}
|
||||
|
||||
uint8_t ShutterGetRelayNoFromBitfield(power_t number) {
|
||||
int position = 0;
|
||||
while (number != 0) {
|
||||
|
@ -2258,9 +2267,12 @@ bool Xdrv27(uint32_t function)
|
|||
char stemp1[10];
|
||||
power_t save_powermatrix;
|
||||
switch (function) {
|
||||
case FUNC_RESTORE_SETTINGS:
|
||||
result = ShutterSettingsRestore();
|
||||
break;
|
||||
case FUNC_SAVE_SETTINGS:
|
||||
ShutterSettingsSave();
|
||||
break;
|
||||
break;
|
||||
case FUNC_PRE_INIT:
|
||||
ShutterSettingsLoad(0);
|
||||
ShutterInit();
|
||||
|
|
|
@ -373,6 +373,14 @@ void Xdrv86SettingsSave(void) {
|
|||
#endif // USE_UFILESYS
|
||||
}
|
||||
|
||||
bool Xdrv86SettingsRestore(void) {
|
||||
#ifdef USE_UFILESYS
|
||||
uint32_t max_size = (XdrvMailbox.index > sizeof(tSspmSettings)) ? sizeof(tSspmSettings) : XdrvMailbox.index;
|
||||
memcpy((uint8_t*)&Sspm->Settings, (uint8_t*)XdrvMailbox.data, max_size); // Restore version and auto upgrade after restart
|
||||
return true;
|
||||
#endif // USE_UFILESYS
|
||||
}
|
||||
|
||||
/*********************************************************************************************/
|
||||
|
||||
uint32_t SSMPGetModuleId(uint32_t module) {
|
||||
|
@ -2650,6 +2658,9 @@ bool Xdrv86(uint32_t function) {
|
|||
case FUNC_RESET_SETTINGS:
|
||||
Xdrv86SettingsLoad(1);
|
||||
break;
|
||||
case FUNC_RESTORE_SETTINGS:
|
||||
result = Xdrv86SettingsRestore();
|
||||
break;
|
||||
case FUNC_SAVE_SETTINGS:
|
||||
Xdrv86SettingsSave();
|
||||
break;
|
||||
|
|
|
@ -162,6 +162,14 @@ void Xdrv87SettingsSave(void) {
|
|||
#endif // USE_UFILESYS
|
||||
}
|
||||
|
||||
bool Xdrv87SettingsRestore(void) {
|
||||
#ifdef USE_UFILESYS
|
||||
uint32_t max_size = (XdrvMailbox.index > sizeof(tXdrv87Settings)) ? sizeof(tXdrv87Settings) : XdrvMailbox.index;
|
||||
memcpy((uint8_t*)&Xdrv87Settings, (uint8_t*)XdrvMailbox.data, max_size); // Restore version and auto upgrade after restart
|
||||
return true;
|
||||
#endif // USE_UFILESYS
|
||||
}
|
||||
|
||||
/*********************************************************************************************/
|
||||
|
||||
void TM1621StopSequence(void) {
|
||||
|
@ -585,6 +593,9 @@ bool Xdrv87(uint32_t function) {
|
|||
case FUNC_RESET_SETTINGS:
|
||||
Xdrv87SettingsLoad(1);
|
||||
break;
|
||||
case FUNC_RESTORE_SETTINGS:
|
||||
result = Xdrv87SettingsRestore();
|
||||
break;
|
||||
case FUNC_SAVE_SETTINGS:
|
||||
Xdrv87SettingsSave();
|
||||
break;
|
||||
|
|
Loading…
Reference in New Issue