Fix initial reset RTC memory based variables

Fix initial reset RTC memory based variables like EnergyToday and EnergyTotal
This commit is contained in:
Theo Arends 2021-10-21 16:24:41 +02:00
parent 11371e3da1
commit 071971edaa
3 changed files with 29 additions and 22 deletions

View File

@ -10,6 +10,9 @@ All notable changes to this project will be documented in this file.
### Changed ### Changed
- File editor no-wrap (#13427) - File editor no-wrap (#13427)
### Fixed
- Initial reset RTC memory based variables like EnergyToday and EnergyTotal
## [Released] ## [Released]
## [10.0.0] 20211019 ## [10.0.0] 20211019

View File

@ -108,3 +108,4 @@ The latter links can be used for OTA upgrades too like ``OtaUrl http://ota.tasmo
- File editor no-wrap [#13427](https://github.com/arendst/Tasmota/issues/13427) - File editor no-wrap [#13427](https://github.com/arendst/Tasmota/issues/13427)
### Fixed ### Fixed
- Initial reset RTC memory based variables like EnergyToday and EnergyTotal

View File

@ -38,28 +38,8 @@ uint32_t GetRtcSettingsCrc(void) {
void RtcSettingsSave(void) { void RtcSettingsSave(void) {
RtcSettings.baudrate = Settings->baudrate * 300; RtcSettings.baudrate = Settings->baudrate * 300;
if (GetRtcSettingsCrc() != rtc_settings_crc) { if (GetRtcSettingsCrc() != rtc_settings_crc) {
RtcSettings.valid = RTC_MEM_VALID;
#ifdef ESP8266
ESP.rtcUserMemoryWrite(100, (uint32_t*)&RtcSettings, sizeof(RtcSettings));
#endif // ESP8266
#ifdef ESP32
RtcDataSettings = RtcSettings;
#endif // ESP32
rtc_settings_crc = GetRtcSettingsCrc();
}
}
bool RtcSettingsLoad(uint32_t update) { if (RTC_MEM_VALID != RtcSettings.valid) {
#ifdef ESP8266
ESP.rtcUserMemoryRead(100, (uint32_t*)&RtcSettings, sizeof(RtcSettings)); // 0x290
#endif // ESP8266
#ifdef ESP32
RtcSettings = RtcDataSettings;
#endif // ESP32
bool read_valid = (RTC_MEM_VALID == RtcSettings.valid);
if (update) {
if (!read_valid) {
memset(&RtcSettings, 0, sizeof(RtcSettings)); memset(&RtcSettings, 0, sizeof(RtcSettings));
RtcSettings.valid = RTC_MEM_VALID; RtcSettings.valid = RTC_MEM_VALID;
RtcSettings.energy_kWhtoday = Settings->energy_kWhtoday; RtcSettings.energy_kWhtoday = Settings->energy_kWhtoday;
@ -75,9 +55,32 @@ bool RtcSettingsLoad(uint32_t update) {
RtcSettings.power = Settings->power; RtcSettings.power = Settings->power;
// RtcSettings.baudrate = Settings->baudrate * 300; // RtcSettings.baudrate = Settings->baudrate * 300;
RtcSettings.baudrate = APP_BAUDRATE; RtcSettings.baudrate = APP_BAUDRATE;
}
#ifdef ESP8266
ESP.rtcUserMemoryWrite(100, (uint32_t*)&RtcSettings, sizeof(RtcSettings));
#endif // ESP8266
#ifdef ESP32
RtcDataSettings = RtcSettings;
#endif // ESP32
rtc_settings_crc = GetRtcSettingsCrc();
}
}
bool RtcSettingsLoad(uint32_t update) {
#ifdef ESP8266
ESP.rtcUserMemoryRead(100, (uint32_t*)&RtcSettings, sizeof(RtcSettings)); // 0x290
#endif // ESP8266
#ifdef ESP32
RtcSettings = RtcDataSettings;
#endif // ESP32
bool read_valid = (RTC_MEM_VALID == RtcSettings.valid);
if (update) {
if (!read_valid) {
RtcSettingsSave(); RtcSettingsSave();
} }
rtc_settings_crc = GetRtcSettingsCrc();
} }
return read_valid; return read_valid;
} }