Remove obsolete Tuya code

Remove obsolete Tuya code
This commit is contained in:
Theo Arends 2019-09-05 16:56:02 +02:00
parent db51e516b6
commit a01de9a9b2
3 changed files with 33 additions and 42 deletions

View File

@ -78,7 +78,7 @@ typedef union { // Restricted by MISRA-C Rule 18.4 bu
uint32_t no_hold_retain : 1; // bit 12 (v6.4.1.19) - SetOption62 - Don't use retain flag on HOLD messages
uint32_t no_power_feedback : 1; // bit 13 (v6.5.0.9) - SetOption63 - Don't scan relay power state at restart
uint32_t use_underscore : 1; // bit 14 (v6.5.0.12) - SetOption64 - Enable "_" instead of "-" as sensor index separator
uint32_t tuya_disable_dimmer : 1; // bit 15 (v6.5.0.15) - SetOption65 - Enable or Disable Tuya Serial Dimmer control
uint32_t ex_tuya_disable_dimmer : 1; // bit 15 (v6.5.0.15) - SetOption65 - (Enable or Disable Tuya Serial Dimmer control) - free since 6.6.0.10
uint32_t tuya_dimmer_range_255 : 1; // bit 16 (v6.6.0.1) - SetOption66 - Enable or Disable Dimmer range 255 slider control
uint32_t buzzer_enable : 1; // bit 17 (v6.6.0.1) - SetOption67 - Enable buzzer when available
uint32_t pwm_multi_channels : 1; // bit 18 (v6.6.0.3) - SetOption68 - Enable multi-channels PWM instead of Color PWM
@ -377,7 +377,7 @@ struct SYSCFG {
uint8_t free_e20[472]; // E20
uint32_t cfg_timestamp; // FF8
uint32_t cfg_crc4; // FFC
uint32_t cfg_crc32; // FFC
} Settings;
struct RTCRBT {

View File

@ -273,8 +273,9 @@ const uint32_t SETTINGS_LOCATION = SPIFFS_END; // No need for SPIFFS as it uses
// Version 5.2 allow for more flash space
const uint8_t CFG_ROTATES = 8; // Number of flash sectors used (handles uploads)
uint16_t settings_crc = 0;
uint32_t settings_location = SETTINGS_LOCATION;
//uint32_t settings_crc32 = 0;
uint16_t settings_crc = 0;
uint8_t *settings_buffer = nullptr;
/********************************************************************************************/
@ -331,6 +332,22 @@ uint16_t GetSettingsCrc(void)
return crc;
}
uint32_t GetSettingsCrc32(void)
{
// https://create.stephan-brumme.com/crc32/#bitwise
uint32_t crc = 0;
uint8_t *bytes = (uint8_t*)&Settings;
uint32_t length = sizeof(SYSCFG) -4; // Skip crc
while (length--) {
crc ^= *bytes++;
for (uint32_t j = 0; j < 8; j++) {
crc = (crc >> 1) ^ (-int(crc & 1) & 0xEDB88320);
}
}
return ~crc;
}
void SettingsSaveAll(void)
{
if (Settings.flag.save_state) {
@ -340,9 +357,6 @@ void SettingsSaveAll(void)
}
XsnsCall(FUNC_SAVE_BEFORE_RESTART);
XdrvCall(FUNC_SAVE_BEFORE_RESTART);
#ifdef USE_EEPROM
EepromCommit();
#endif
SettingsSave(0);
}
@ -382,31 +396,17 @@ void SettingsSave(uint8_t rotate)
}
}
Settings.save_flag++;
if (UtcTime() > START_VALID_TIME) {
Settings.cfg_timestamp = UtcTime();
} else {
Settings.cfg_timestamp++;
}
Settings.cfg_size = sizeof(SYSCFG);
// Settings.cfg_crc32 = GetSettingsCrc32();
Settings.cfg_crc = GetSettingsCrc();
#ifdef USE_EEPROM
if (SPIFFS_END == settings_location) {
uint8_t* flash_buffer;
flash_buffer = new uint8_t[SPI_FLASH_SEC_SIZE];
if (eeprom_data && eeprom_size) {
size_t flash_offset = SPI_FLASH_SEC_SIZE - eeprom_size;
memcpy(flash_buffer + flash_offset, eeprom_data, eeprom_size); // Write dirty EEPROM data
} else {
ESP.flashRead(settings_location * SPI_FLASH_SEC_SIZE, (uint32*)flash_buffer, SPI_FLASH_SEC_SIZE); // Read EEPROM area
}
memcpy(flash_buffer, &Settings, sizeof(Settings));
ESP.flashEraseSector(settings_location);
ESP.flashWrite(settings_location * SPI_FLASH_SEC_SIZE, (uint32*)flash_buffer, SPI_FLASH_SEC_SIZE);
delete[] flash_buffer;
} else {
ESP.flashEraseSector(settings_location);
ESP.flashWrite(settings_location * SPI_FLASH_SEC_SIZE, (uint32*)&Settings, sizeof(SYSCFG));
}
#else
ESP.flashEraseSector(settings_location);
ESP.flashWrite(settings_location * SPI_FLASH_SEC_SIZE, (uint32*)&Settings, sizeof(SYSCFG));
#endif // USE_EEPROM
if (!stop_flash_rotate && rotate) {
for (uint32_t i = 1; i < CFG_ROTATES; i++) {
@ -418,6 +418,7 @@ void SettingsSave(uint8_t rotate)
AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_CONFIG D_SAVED_TO_FLASH_AT " %X, " D_COUNT " %d, " D_BYTES " %d"), settings_location, Settings.save_flag, sizeof(SYSCFG));
settings_crc = Settings.cfg_crc;
// settings_crc32 = Settings.cfg_crc32;
}
#endif // FIRMWARE_MINIMAL
RtcSettingsSave();
@ -1102,7 +1103,7 @@ void SettingsDelta(void)
Settings.tuya_fnid_map[tuyaindex].fnid = 21; // TUYA_MCU_FUNC_DIMMER - Move Tuya Dimmer Id to Map
Settings.tuya_fnid_map[tuyaindex].dpid = Settings.param[P_ex_TUYA_DIMMER_ID];
tuyaindex++;
} else if (Settings.flag3.tuya_disable_dimmer == 1) { // ex SetOption65
} else if (Settings.flag3.ex_tuya_disable_dimmer == 1) { // ex SetOption65
Settings.tuya_fnid_map[tuyaindex].fnid = 11; // TUYA_MCU_FUNC_REL1 - Create FnID for Switches
Settings.tuya_fnid_map[tuyaindex].dpid = 1;
tuyaindex++;

View File

@ -616,26 +616,23 @@ void CmndSetoption(void)
#endif // USE_HOME_ASSISTANT
}
}
else if (1 == ptype) { // SetOption50 .. 81
else if (1 == ptype) { // SetOption50 .. 81
if (XdrvMailbox.payload <= 1) {
bitWrite(Settings.flag3.data, pindex, XdrvMailbox.payload);
if (5 == pindex) { // SetOption55
if (5 == pindex) { // SetOption55
if (0 == XdrvMailbox.payload) {
restart_flag = 2; // Disable mDNS needs restart
}
}
if (10 == pindex) { // SetOption60 enable or disable traditional sleep
if (10 == pindex) { // SetOption60 enable or disable traditional sleep
WiFiSetSleepMode(); // Update WiFi sleep mode accordingly
}
if (18 == pindex) { // SetOption68 for multi-channel PWM, requires a reboot
restart_flag = 2;
}
if (15 == pindex) { // SetOption65 for tuya_disable_dimmer requires a reboot
if (18 == pindex) { // SetOption68 for multi-channel PWM, requires a reboot
restart_flag = 2;
}
}
}
else { // SetOption32 .. 49
else { // SetOption32 .. 49
uint32_t param_low = 0;
uint32_t param_high = 255;
switch (pindex) {
@ -644,9 +641,6 @@ void CmndSetoption(void)
param_low = 1;
param_high = 250;
break;
case P_ex_TUYA_RELAYS:
param_high = 8;
break;
}
if ((XdrvMailbox.payload >= param_low) && (XdrvMailbox.payload <= param_high)) {
Settings.param[pindex] = XdrvMailbox.payload;
@ -662,10 +656,6 @@ void CmndSetoption(void)
break;
#endif
#ifdef USE_TUYA_MCU
// case P_ex_TUYA_RELAYS:
// case P_ex_TUYA_POWER_ID:
// case P_ex_TUYA_CURRENT_ID:
// case P_ex_TUYA_VOLTAGE_ID:
case P_TUYA_DIMMER_MAX:
restart_flag = 2; // Need a restart to update GUI
break;