Add command `SetOption73 1` for button decoupling

Add command ``SetOption73 1`` for button decoupling and send multi-press and hold MQTT messages by Federico Leoni (#8235)
This commit is contained in:
Theo Arends 2020-04-20 17:47:40 +02:00
parent 780b250d9d
commit 0b08c72247
4 changed files with 22 additions and 15 deletions

View File

@ -71,6 +71,7 @@ The following binary downloads have been compiled with ESP8266/Arduino library c
- Add commands ``NrfPage``, ``NrfIgnore``, ``NrfScan`` and ``NrfBeacon`` to NRF24 Bluetooth driver (#8075)
- Add commands ``GlobalTemp`` and ``GlobalHum`` to init sensor data (#8152)
- Add command ``SetOption41 <x>`` to force sending gratuitous ARP every <x> seconds
- Add command ``SetOption73 1`` for button decoupling and send multi-press and hold MQTT messages by Federico Leoni (#8235)
- Add command ``SetOption90 1`` to disable non-json MQTT messages (#8044)
- Add command ``SetOption91 1`` to enable fading at startup / power on
- Add command ``Sensor10 0/1/2`` to control BH1750 resolution - 0 = High (default), 1 = High2, 2 = Low (#8016)

View File

@ -2,8 +2,9 @@
### 8.2.0.4 20200417
- Add config version tag
- Fix Zigbee DimmerUp/DimmerDown malformed
- Add config version tag
- Add command ``SetOption73 1`` for button decoupling and send multi-press and hold MQTT messages by Federico Leoni (#8235)
### 8.2.0.3 20200329

View File

@ -17,7 +17,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define BUTTON_V1
//#define BUTTON_V1
#ifdef BUTTON_V1
/*********************************************************************************************\
* Button support

View File

@ -17,7 +17,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
//#define BUTTON_V2
#define BUTTON_V2
#ifdef BUTTON_V2
/*********************************************************************************************\
* Button support
@ -99,7 +99,8 @@ 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
* SetOption11 (0) - If set perform single press action on double press and reverse
* SetOption1 (0) - If set do not execute commands WifiConfig and Reset
* SetOption11 (0) - If set perform single press action on double press and reverse (on two relay devices only)
* SetOption13 (0) - If set act on single press only
* SetOption73 (0) - Decouple button from relay and send just mqtt topic
\*********************************************************************************************/
@ -171,10 +172,10 @@ void ButtonHandler(void)
if (!Settings.flag3.mqtt_buttons) {
if (!SendKey(KEY_BUTTON, 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
}
}
} else {
MqttButtonTopic(button_index +1, 1, 0); // SetOption73 (0) - Decouple button from relay and send just mqtt topic
}
}
}
}
#endif // ESP8266
@ -196,7 +197,7 @@ void ButtonHandler(void)
Button.window_timer[button_index] = loops_per_second / 2; // 0.5 second multi press window
}
blinks = 201;
}
}
if (NOT_PRESSED == button) {
Button.hold_timer[button_index] = 0;
@ -214,13 +215,15 @@ void ButtonHandler(void)
MqttButtonTopic(button_index +1, 3, 1);
} else {
SendKey(KEY_BUTTON, button_index +1, POWER_HOLD); // Execute Hold command via MQTT if ButtonTopic is set
}
}
} else {
if ((Button.hold_timer[button_index] == loops_per_second * hold_time_extent * Settings.param[P_HOLD_TIME] / 10)) { // SetOption32 (40) - Button held for factor times longer
Button.press_counter[button_index] = 0;
snprintf_P(scmnd, sizeof(scmnd), PSTR(D_CMND_RESET " 1"));
ExecuteCommand(scmnd, SRC_BUTTON);
}
if (!Settings.flag.button_restrict) {
if ((Button.hold_timer[button_index] == loops_per_second * hold_time_extent * Settings.param[P_HOLD_TIME] / 10)) { // SetOption32 (40) - Button held for factor times longer
Button.press_counter[button_index] = 0;
snprintf_P(scmnd, sizeof(scmnd), PSTR(D_CMND_RESET " 1"));
ExecuteCommand(scmnd, SRC_BUTTON);
}
}
}
}
}
@ -272,8 +275,10 @@ void ButtonHandler(void)
}
} else { // 6 press start wificonfig 2
if (!Settings.flag.button_restrict) {
snprintf_P(scmnd, sizeof(scmnd), PSTR(D_CMND_WIFICONFIG " 2"));
ExecuteCommand(scmnd, SRC_BUTTON);
}
}
if (Settings.flag3.mqtt_buttons) { // SetOption73 (0) - Decouple button from relay and send just mqtt topic
if (Button.press_counter[button_index] >= 1 && Button.press_counter[button_index] <= 5) {
@ -288,7 +293,7 @@ void ButtonHandler(void)
}
}
}
}
}
Button.last_state[button_index] = button;
@ -301,7 +306,7 @@ void MqttButtonTopic(uint8_t button_id, uint8_t action, uint8_t hold)
char stopic[TOPSZ];
char mqttstate[7];
GetTextIndexed(mqttstate, sizeof(mqttstate), action, kMultiPress);
GetTextIndexed(mqttstate, sizeof(mqttstate), action, kMultiPress);
SendKey(KEY_BUTTON, button_id, (hold) ? 3 : action +9);
snprintf_P(scommand, sizeof(scommand), PSTR("BUTTON%d"), button_id);