Refactor module change detection

This commit is contained in:
Theo Arends 2020-11-01 12:12:27 +01:00
parent 0057a1dd34
commit 8338a9cc80
5 changed files with 8 additions and 11 deletions

View File

@ -791,10 +791,6 @@ void PerformEverySecond(void)
{ {
TasmotaGlobal.uptime++; TasmotaGlobal.uptime++;
if (LAST_MODULE_SET_TIME == TasmotaGlobal.uptime) {
Settings.last_module = Settings.module; // Needs to be done after AriluxRfInit() and PWMModulePreInit()
}
if (POWER_CYCLE_TIME == TasmotaGlobal.uptime) { if (POWER_CYCLE_TIME == TasmotaGlobal.uptime) {
UpdateQuickPowerCycle(false); UpdateQuickPowerCycle(false);
} }
@ -802,6 +798,8 @@ void PerformEverySecond(void)
if (BOOT_LOOP_TIME == TasmotaGlobal.uptime) { if (BOOT_LOOP_TIME == TasmotaGlobal.uptime) {
RtcRebootReset(); RtcRebootReset();
Settings.last_module = Settings.module;
#ifdef USE_DEEPSLEEP #ifdef USE_DEEPSLEEP
if (!(DeepSleepEnabled() && !Settings.flag3.bootcount_update)) { if (!(DeepSleepEnabled() && !Settings.flag3.bootcount_update)) {
#endif #endif
@ -1490,7 +1488,8 @@ void GpioInit(void)
} }
SetModuleType(); SetModuleType();
if (Settings.module != Settings.last_module) { TasmotaGlobal.module_changed = (Settings.module != Settings.last_module);
if (TasmotaGlobal.module_changed) {
Settings.baudrate = APP_BAUDRATE / 300; Settings.baudrate = APP_BAUDRATE / 300;
Settings.serial_config = TS_SERIAL_8N1; Settings.serial_config = TS_SERIAL_8N1;
SetSerialBegin(); SetSerialBegin();

View File

@ -124,7 +124,6 @@ const uint8_t MAX_POWER_RETRY = 5; // Retry count allowing agreed power
const uint8_t STATES = 20; // Number of states per second using 50 mSec interval const uint8_t STATES = 20; // Number of states per second using 50 mSec interval
const uint8_t IMMINENT_RESET_FACTOR = 10; // Factor to extent button hold time for imminent Reset to default 40 seconds using KEY_HOLD_TIME of 40 const uint8_t IMMINENT_RESET_FACTOR = 10; // Factor to extent button hold time for imminent Reset to default 40 seconds using KEY_HOLD_TIME of 40
const uint32_t LAST_MODULE_SET_TIME = 12; // Number of seconds to set last module to current module
const uint32_t BOOT_LOOP_TIME = 10; // Number of seconds to stop detecting boot loops const uint32_t BOOT_LOOP_TIME = 10; // Number of seconds to stop detecting boot loops
const uint32_t POWER_CYCLE_TIME = 8; // Number of seconds to reset power cycle boot loops const uint32_t POWER_CYCLE_TIME = 8; // Number of seconds to reset power cycle boot loops
const uint16_t SYSLOG_TIMER = 600; // Seconds to restore syslog_level const uint16_t SYSLOG_TIMER = 600; // Seconds to restore syslog_level

View File

@ -122,6 +122,7 @@ struct {
bool is_8285; // Hardware device ESP8266EX (0) or ESP8285 (1) bool is_8285; // Hardware device ESP8266EX (0) or ESP8285 (1)
bool skip_light_fade; // Temporarily skip light fading bool skip_light_fade; // Temporarily skip light fading
bool restart_halt; // Do not restart but stay in wait loop bool restart_halt; // Do not restart but stay in wait loop
bool module_changed; // Indicate module changed since last restart
StateBitfield global_state; // Global states (currently Wifi and Mqtt) (8 bits) StateBitfield global_state; // Global states (currently Wifi and Mqtt) (8 bits)
uint8_t blinks; // Number of LED blinks uint8_t blinks; // Number of LED blinks

View File

@ -146,10 +146,9 @@ void AriluxRfHandler(void)
void AriluxRfInit(void) void AriluxRfInit(void)
{ {
if (PinUsed(GPIO_ARIRFRCV) && PinUsed(GPIO_ARIRFSEL)) { if (PinUsed(GPIO_ARIRFRCV) && PinUsed(GPIO_ARIRFSEL)) {
if (Settings.last_module != Settings.module) { if (TasmotaGlobal.module_changed) {
Settings.rf_code[1][6] = 0; Settings.rf_code[1][6] = 0;
Settings.rf_code[1][7] = 0; Settings.rf_code[1][7] = 0;
// Settings.last_module = Settings.module; // Will be done at LAST_MODULE_SET_TIME after restart as other drivers also test for module change
} }
Arilux.rf_received_value = 0; Arilux.rf_received_value = 0;
@ -179,7 +178,7 @@ bool Xdrv26(uint8_t function)
if (PinUsed(GPIO_ARIRFRCV)) { AriluxRfHandler(); } if (PinUsed(GPIO_ARIRFRCV)) { AriluxRfHandler(); }
break; break;
case FUNC_EVERY_SECOND: case FUNC_EVERY_SECOND:
if (LAST_MODULE_SET_TIME -2 == TasmotaGlobal.uptime) { AriluxRfInit(); } // Needs rest before enabling RF interrupts if (10 == TasmotaGlobal.uptime) { AriluxRfInit(); } // Needs rest before enabling RF interrupts
break; break;
} }
return result; return result;

View File

@ -88,10 +88,9 @@ void PWMModulePreInit(void)
Settings.ledstate = 0; // Disable LED usage Settings.ledstate = 0; // Disable LED usage
// If the module was just changed to PWM Dimmer, set the defaults. // If the module was just changed to PWM Dimmer, set the defaults.
if (Settings.last_module != Settings.module) { if (TasmotaGlobal.module_changed) {
Settings.flag.pwm_control = true; // SetOption15 - Switch between commands PWM or COLOR/DIMMER/CT/CHANNEL Settings.flag.pwm_control = true; // SetOption15 - Switch between commands PWM or COLOR/DIMMER/CT/CHANNEL
Settings.bri_power_on = Settings.bri_preset_low = Settings.bri_preset_high = 0; Settings.bri_power_on = Settings.bri_preset_low = Settings.bri_preset_high = 0;
// Settings.last_module = Settings.module; // Will be done at LAST_MODULE_SET_TIME after restart as other drivers also test for module change
// Previous versions of PWM Dimmer used SetOption32 - Button held for factor times longer as the // Previous versions of PWM Dimmer used SetOption32 - Button held for factor times longer as the
// hold time. The hold time is now fixed and SetOption32 is used as normal including to // hold time. The hold time is now fixed and SetOption32 is used as normal including to