From 3d31dd1457ce18d463456eeb346ba888ef109e47 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Mon, 7 Jan 2019 10:15:00 +0100 Subject: [PATCH] Disable Button/Switch 4 seconds Disable both Buttons and Switches 4 seconds after power on to workaround Wemos and Obi startup issues. --- sonoff/sonoff.ino | 9 ++++---- sonoff/support_switch.ino | 44 +++++++++++++++++++-------------------- 2 files changed, 26 insertions(+), 27 deletions(-) diff --git a/sonoff/sonoff.ino b/sonoff/sonoff.ino index 16205b458..af7a0c6e6 100755 --- a/sonoff/sonoff.ino +++ b/sonoff/sonoff.ino @@ -1750,6 +1750,8 @@ void PerformEverySecond(void) void ButtonHandler(void) { + if (uptime < 4) { return; } // Block GPIO for 4 seconds after poweron to workaround Wemos D1 / Obi RTS circuit + uint8_t button = NOT_PRESSED; uint8_t button_present = 0; uint8_t hold_time_extent = IMMINENT_RESET_FACTOR; // Extent hold time factor in case of iminnent Reset command @@ -1775,11 +1777,8 @@ void ButtonHandler(void) } } else { if (pin[GPIO_KEY1 +button_index] < 99) { -// if (!((uptime < 4) && (0 == pin[GPIO_KEY1 +button_index]))) { // Block GPIO0 for 4 seconds after poweron to workaround Wemos D1 RTS circuit - if (uptime > 3) { // Block GPIO for 4 seconds after poweron to workaround Wemos D1 / Obi RTS circuit - button_present = 1; - button = digitalRead(pin[GPIO_KEY1 +button_index]); - } + button_present = 1; + button = digitalRead(pin[GPIO_KEY1 +button_index]); } } diff --git a/sonoff/support_switch.ino b/sonoff/support_switch.ino index cc32eb0bb..5f3685a7a 100644 --- a/sonoff/support_switch.ino +++ b/sonoff/support_switch.ino @@ -65,41 +65,41 @@ uint8_t SwitchGetVirtual(uint8_t index) void SwitchProbe(void) { + if (uptime < 4) { return; } // Block GPIO for 4 seconds after poweron to workaround Wemos D1 / Obi RTS circuit + uint8_t state_filter = Settings.switch_debounce / SWITCH_PROBE_INTERVAL; // 5, 10, 15 uint8_t force_high = (Settings.switch_debounce % 50) &1; // 51, 101, 151 etc uint8_t force_low = (Settings.switch_debounce % 50) &2; // 52, 102, 152 etc for (byte i = 0; i < MAX_SWITCHES; i++) { if (pin[GPIO_SWT1 +i] < 99) { - if (!((uptime < 4) && (0 == pin[GPIO_SWT1 +i]))) { // Block GPIO0 for 4 seconds after poweron to workaround Wemos D1 RTS circuit - // Olimex user_switch2.c code to fix 50Hz induced pulses - if (1 == digitalRead(pin[GPIO_SWT1 +i])) { + // Olimex user_switch2.c code to fix 50Hz induced pulses + if (1 == digitalRead(pin[GPIO_SWT1 +i])) { - if (force_high) { // Enabled with SwitchDebounce x1 - if (1 == switch_virtual[i]) { - switch_state_buf[i] = state_filter; // With noisy input keep current state 1 unless constant 0 - } + if (force_high) { // Enabled with SwitchDebounce x1 + if (1 == switch_virtual[i]) { + switch_state_buf[i] = state_filter; // With noisy input keep current state 1 unless constant 0 } + } - if (switch_state_buf[i] < state_filter) { - switch_state_buf[i]++; - if (state_filter == switch_state_buf[i]) { - switch_virtual[i] = 1; - } + if (switch_state_buf[i] < state_filter) { + switch_state_buf[i]++; + if (state_filter == switch_state_buf[i]) { + switch_virtual[i] = 1; } - } else { + } + } else { - if (force_low) { // Enabled with SwitchDebounce x2 - if (0 == switch_virtual[i]) { - switch_state_buf[i] = 0; // With noisy input keep current state 0 unless constant 1 - } + if (force_low) { // Enabled with SwitchDebounce x2 + if (0 == switch_virtual[i]) { + switch_state_buf[i] = 0; // With noisy input keep current state 0 unless constant 1 } + } - if (switch_state_buf[i] > 0) { - switch_state_buf[i]--; - if (0 == switch_state_buf[i]) { - switch_virtual[i] = 0; - } + if (switch_state_buf[i] > 0) { + switch_state_buf[i]--; + if (0 == switch_state_buf[i]) { + switch_virtual[i] = 0; } } }