mirror of https://github.com/arendst/Tasmota.git
dd Toggle functionality to button double press when more devices are detected
dd Toggle functionality to button double press when more devices are detected
This commit is contained in:
parent
164b3aaf11
commit
345a514f7b
|
@ -1,8 +1,10 @@
|
|||
/* 6.5.0.14 20190602
|
||||
/*
|
||||
* 6.5.0.14 20190602
|
||||
* Change webserver HTML input, button, textarea, and select name based on id
|
||||
* Fix webserver multiple Javascript window.onload functionality
|
||||
* Fix PZem startup issue (#5875)
|
||||
* Add command SetOption39 1..255 to control CSE7766 (Pow R2) or HLW8032 (Blitzwolf SHP5) handling of power loads below 6W. Default setting is 128 (#5756)
|
||||
* Add Toggle functionality to button double press when more devices are detected
|
||||
*
|
||||
* 6.5.0.13 20190527
|
||||
* Add command SetOption38 6..255 to set IRReceive protocol detection sensitivity mimizing UNKNOWN protocols (#5853)
|
||||
|
|
|
@ -90,16 +90,22 @@ uint8_t ButtonSerial(uint8_t serial_in_byte)
|
|||
|
||||
/*********************************************************************************************\
|
||||
* Button handler with single press only or multi-press and hold on all buttons
|
||||
*
|
||||
* ButtonDebounce (50) - Debounce time in mSec
|
||||
* SetOption1 (0) - If set do not execute config commands
|
||||
* SetOption11 (0) - If set perform single press action on double press and reverse
|
||||
* SetOption13 (0) - If set act on single press only
|
||||
* SetOption32 (40) - Max button hold time in Seconds
|
||||
\*********************************************************************************************/
|
||||
|
||||
void ButtonHandler(void)
|
||||
{
|
||||
if (uptime < 4) { return; } // Block GPIO for 4 seconds after poweron to workaround Wemos D1 / Obi RTS circuit
|
||||
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
|
||||
uint16_t loops_per_second = 1000 / Settings.button_debounce;
|
||||
uint8_t hold_time_extent = IMMINENT_RESET_FACTOR; // Extent hold time factor in case of iminnent Reset command
|
||||
uint16_t loops_per_second = 1000 / Settings.button_debounce; // ButtonDebounce (50)
|
||||
char scmnd[20];
|
||||
|
||||
// uint8_t maxdev = (devices_present > MAX_KEYS) ? MAX_KEYS : devices_present;
|
||||
|
@ -114,7 +120,7 @@ void ButtonHandler(void)
|
|||
AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_APPLICATION D_BUTTON " " D_CODE " %04X"), dual_button_code);
|
||||
button = PRESSED;
|
||||
if (0xF500 == dual_button_code) { // Button hold
|
||||
holdbutton[button_index] = (loops_per_second * Settings.param[P_HOLD_TIME] / 10) -1;
|
||||
holdbutton[button_index] = (loops_per_second * Settings.param[P_HOLD_TIME] / 10) -1; // SetOption32 (40)
|
||||
hold_time_extent = 1;
|
||||
}
|
||||
dual_button_code = 0;
|
||||
|
@ -163,7 +169,7 @@ void ButtonHandler(void)
|
|||
}
|
||||
else {
|
||||
if ((PRESSED == button) && (NOT_PRESSED == lastbutton[button_index])) {
|
||||
if (Settings.flag.button_single) { // Allow only single button press for immediate action
|
||||
if (Settings.flag.button_single) { // SetOption13 (0) - Allow only single button press for immediate action
|
||||
AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_APPLICATION D_BUTTON "%d " D_IMMEDIATE), button_index +1);
|
||||
if (!SendKey(0, button_index +1, POWER_TOGGLE)) { // Execute Toggle command via MQTT if ButtonTopic is set
|
||||
ExecuteCommandPower(button_index +1, POWER_TOGGLE, SRC_BUTTON); // Execute Toggle command internally
|
||||
|
@ -180,20 +186,20 @@ void ButtonHandler(void)
|
|||
holdbutton[button_index] = 0;
|
||||
} else {
|
||||
holdbutton[button_index]++;
|
||||
if (Settings.flag.button_single) { // Allow only single button press for immediate action
|
||||
if (holdbutton[button_index] == loops_per_second * hold_time_extent * Settings.param[P_HOLD_TIME] / 10) { // Button held for factor times longer
|
||||
if (Settings.flag.button_single) { // SetOption13 (0) - Allow only single button press for immediate action
|
||||
if (holdbutton[button_index] == loops_per_second * hold_time_extent * Settings.param[P_HOLD_TIME] / 10) { // SetOption32 (40) - Button held for factor times longer
|
||||
// Settings.flag.button_single = 0;
|
||||
snprintf_P(scmnd, sizeof(scmnd), PSTR(D_CMND_SETOPTION "13 0")); // Disable single press only
|
||||
ExecuteCommand(scmnd, SRC_BUTTON);
|
||||
}
|
||||
} else {
|
||||
if (Settings.flag.button_restrict) { // Button restriction
|
||||
if (holdbutton[button_index] == loops_per_second * Settings.param[P_HOLD_TIME] / 10) { // Button hold
|
||||
if (Settings.flag.button_restrict) { // SetOption1 (0) - Button restriction
|
||||
if (holdbutton[button_index] == loops_per_second * Settings.param[P_HOLD_TIME] / 10) { // SetOption32 (40) - Button hold
|
||||
multipress[button_index] = 0;
|
||||
SendKey(0, button_index +1, 3); // Execute Hold command via MQTT if ButtonTopic is set
|
||||
}
|
||||
} else {
|
||||
if (holdbutton[button_index] == loops_per_second * hold_time_extent * Settings.param[P_HOLD_TIME] / 10) { // Button held for factor times longer
|
||||
if (holdbutton[button_index] == loops_per_second * hold_time_extent * Settings.param[P_HOLD_TIME] / 10) { // SetOption32 (40) - Button held for factor times longer
|
||||
multipress[button_index] = 0;
|
||||
snprintf_P(scmnd, sizeof(scmnd), PSTR(D_CMND_RESET " 1"));
|
||||
ExecuteCommand(scmnd, SRC_BUTTON);
|
||||
|
@ -202,7 +208,7 @@ void ButtonHandler(void)
|
|||
}
|
||||
}
|
||||
|
||||
if (!Settings.flag.button_single) { // Allow multi-press
|
||||
if (!Settings.flag.button_single) { // SetOption13 (0) - Allow multi-press
|
||||
if (multiwindow[button_index]) {
|
||||
multiwindow[button_index]--;
|
||||
} else {
|
||||
|
@ -212,8 +218,10 @@ void ButtonHandler(void)
|
|||
if ((SONOFF_DUAL_R2 == my_module_type) || (SONOFF_DUAL == my_module_type) || (CH4 == my_module_type)) {
|
||||
single_press = true;
|
||||
} else {
|
||||
single_press = (Settings.flag.button_swap +1 == multipress[button_index]);
|
||||
multipress[button_index] = 1;
|
||||
single_press = (Settings.flag.button_swap +1 == multipress[button_index]); // SetOption11 (0)
|
||||
if (Settings.flag.button_swap) { // SetOption11 (0)
|
||||
multipress[button_index] = (single_press) ? 1 : 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ((MI_DESK_LAMP == my_module_type) && (button_index == 0) && (rotary_changed) && (light_power)) {
|
||||
|
@ -229,7 +237,7 @@ void ButtonHandler(void)
|
|||
ExecuteCommandPower(button_index + multipress[button_index], POWER_TOGGLE, SRC_BUTTON); // Execute Toggle command internally
|
||||
}
|
||||
} else { // 3 - 7 press
|
||||
if (!Settings.flag.button_restrict) {
|
||||
if (!Settings.flag.button_restrict) { // SetOption1 (0)
|
||||
snprintf_P(scmnd, sizeof(scmnd), kCommands[multipress[button_index] -3]);
|
||||
ExecuteCommand(scmnd, SRC_BUTTON);
|
||||
}
|
||||
|
@ -250,7 +258,7 @@ void ButtonLoop(void)
|
|||
{
|
||||
if (buttons_found) {
|
||||
if (TimeReached(button_debounce)) {
|
||||
SetNextTimeInterval(button_debounce, Settings.button_debounce);
|
||||
SetNextTimeInterval(button_debounce, Settings.button_debounce); // ButtonDebounce (50)
|
||||
ButtonHandler();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue