Change Reset on Button Hold time to 40 seconds

5.12.0i
 * Change default Reset configuration time from 4 seconds to 40
seconds on Button hold (#2268)
This commit is contained in:
Theo Arends 2018-03-29 17:21:03 +02:00
parent c85edf15ac
commit 9f0fdd597c
3 changed files with 19 additions and 9 deletions

View File

@ -5,6 +5,7 @@
* Change MQTT response topic for Energy changes from ENERGY to SENSOR (#2229, #2251) * Change MQTT response topic for Energy changes from ENERGY to SENSOR (#2229, #2251)
* Add Home Assistant MQTT Discovery for Buttons and change SetOption19 response (#2277) * Add Home Assistant MQTT Discovery for Buttons and change SetOption19 response (#2277)
* Change webpage parameter communication * Change webpage parameter communication
* Change default Reset configuration time from 4 seconds to 40 seconds on Button hold (#2268)
* *
* 5.12.0h * 5.12.0h
* Add optional Arduino OTA support to be enabled in user_config.h (#1998) * Add optional Arduino OTA support to be enabled in user_config.h (#1998)

View File

@ -80,6 +80,7 @@ typedef unsigned long power_t; // Power (Relay) type
#define MAX_POWER_RETRY 5 // Retry count allowing agreed power limit overflow #define MAX_POWER_RETRY 5 // Retry count allowing agreed power limit overflow
#define STATES 20 // State loops per second #define STATES 20 // State loops per second
#define IMMINENT_RESET_FACTOR 10 // Factor to extent button hold time for imminent Reset to default 40 seconds using KEY_HOLD_TIME of 40
#define SYSLOG_TIMER 600 // Seconds to restore syslog_level #define SYSLOG_TIMER 600 // Seconds to restore syslog_level
#define SERIALLOG_TIMER 600 // Seconds to disable SerialLog #define SERIALLOG_TIMER 600 // Seconds to disable SerialLog
#define OTA_ATTEMPTS 5 // Number of times to try fetching the new firmware #define OTA_ATTEMPTS 5 // Number of times to try fetching the new firmware

View File

@ -31,7 +31,11 @@
#include <core_version.h> // Arduino_Esp8266 version information (ARDUINO_ESP8266_RELEASE and ARDUINO_ESP8266_RELEASE_2_3_0) #include <core_version.h> // Arduino_Esp8266 version information (ARDUINO_ESP8266_RELEASE and ARDUINO_ESP8266_RELEASE_2_3_0)
#include "sonoff.h" // Enumeration used in user_config.h #include "sonoff.h" // Enumeration used in user_config.h
#include "user_config.h" // Fixed user configurable options #include "user_config.h" // Fixed user configurable options
#include "user_config_override.h" // Configuration overrides for user_config.h
//#ifdef USE_CONFIG_OVERRIDE
#include "user_config_override.h" // Configuration overrides for user_config.h
//#endif
#include "i18n.h" // Language support configured by user_config.h #include "i18n.h" // Language support configured by user_config.h
#include "sonoff_template.h" // Hardware configuration #include "sonoff_template.h" // Hardware configuration
#include "sonoff_post.h" // Configuration overrides for all previous includes #include "sonoff_post.h" // Configuration overrides for all previous includes
@ -572,7 +576,6 @@ void MqttDataHandler(char* topic, byte* data, unsigned int data_len)
switch (index) { switch (index) {
case 3: // mqtt case 3: // mqtt
case 15: // pwm_control case 15: // pwm_control
// case 19: // hass_discovery
restart_flag = 2; restart_flag = 2;
case 0: // save_state case 0: // save_state
case 1: // button_restrict case 1: // button_restrict
@ -1478,6 +1481,7 @@ void ButtonHandler()
{ {
uint8_t button = NOT_PRESSED; uint8_t button = NOT_PRESSED;
uint8_t button_present = 0; uint8_t button_present = 0;
uint8_t hold_time_extent = IMMINENT_RESET_FACTOR; // Extent hold time factor in case of iminnent Reset command
char scmnd[20]; char scmnd[20];
uint8_t maxdev = (devices_present > MAX_KEYS) ? MAX_KEYS : devices_present; uint8_t maxdev = (devices_present > MAX_KEYS) ? MAX_KEYS : devices_present;
@ -1493,6 +1497,7 @@ void ButtonHandler()
button = PRESSED; button = PRESSED;
if (0xF500 == dual_button_code) { // Button hold if (0xF500 == dual_button_code) { // Button hold
holdbutton[button_index] = (Settings.param[P_HOLD_TIME] * (STATES / 10)) -1; holdbutton[button_index] = (Settings.param[P_HOLD_TIME] * (STATES / 10)) -1;
hold_time_extent = 0;
} }
dual_button_code = 0; dual_button_code = 0;
} }
@ -1545,20 +1550,23 @@ void ButtonHandler()
holdbutton[button_index] = 0; holdbutton[button_index] = 0;
} else { } else {
holdbutton[button_index]++; holdbutton[button_index]++;
if (Settings.flag.button_single) { // Allow only single button press for immediate action if (Settings.flag.button_single) { // Allow only single button press for immediate action
if (holdbutton[button_index] == Settings.param[P_HOLD_TIME] * (STATES / 10) * 4) { // Button hold for four times longer if (holdbutton[button_index] == Settings.param[P_HOLD_TIME] * (STATES / 10) * hold_time_extent) { // Button held for factor times longer
// Settings.flag.button_single = 0; // Settings.flag.button_single = 0;
snprintf_P(scmnd, sizeof(scmnd), PSTR(D_CMND_SETOPTION "13 0")); // Disable single press only snprintf_P(scmnd, sizeof(scmnd), PSTR(D_CMND_SETOPTION "13 0")); // Disable single press only
ExecuteCommand(scmnd); ExecuteCommand(scmnd);
} }
} else { } else {
if (holdbutton[button_index] == Settings.param[P_HOLD_TIME] * (STATES / 10)) { // Button hold if (Settings.flag.button_restrict) { // Button restriction
multipress[button_index] = 0; if (holdbutton[button_index] == Settings.param[P_HOLD_TIME] * (STATES / 10)) { // Button hold
if (!Settings.flag.button_restrict) { // No button restriction multipress[button_index] = 0;
send_button_power(0, button_index +1, 3); // Execute Hold command via MQTT if ButtonTopic is set
}
} else {
if (holdbutton[button_index] == (Settings.param[P_HOLD_TIME] * (STATES / 10)) * hold_time_extent) { // Button held for factor times longer
multipress[button_index] = 0;
snprintf_P(scmnd, sizeof(scmnd), PSTR(D_CMND_RESET " 1")); snprintf_P(scmnd, sizeof(scmnd), PSTR(D_CMND_RESET " 1"));
ExecuteCommand(scmnd); ExecuteCommand(scmnd);
} else {
send_button_power(0, button_index +1, 3); // Execute Hold command via MQTT if ButtonTopic is set
} }
} }
} }