mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-23 18:56:38 +00:00
Enable multipress events on buttons (#19465)
This commit is contained in:
parent
3cd7950d3b
commit
3cb63bcb67
@ -181,6 +181,7 @@ struct SHUTTER {
|
||||
uint16_t min_TiltChange = 0; // minimum change of the tilt before the shutter operates. different for PWM and time based operations
|
||||
uint16_t last_reported_time = 0; // get information on skipped 50ms loop() slots
|
||||
uint32_t last_stop_time = 0; // record the last time the relay was switched off
|
||||
uint8_t button_simu_pressed = 0; // record if both button where pressed simultanously
|
||||
} Shutter[MAX_SHUTTERS_ESP32];
|
||||
|
||||
struct SHUTTERGLOBAL {
|
||||
@ -205,7 +206,7 @@ struct SHUTTERGLOBAL {
|
||||
void ShutterSettingsDefault(void) {
|
||||
// Init default values in case file is not found
|
||||
|
||||
AddLog(LOG_LEVEL_INFO, PSTR("Shutter: " D_USE_DEFAULTS));
|
||||
AddLog(LOG_LEVEL_INFO, PSTR("SHT: " D_USE_DEFAULTS));
|
||||
|
||||
memset(&ShutterSettings, 0x00, sizeof(ShutterSettings));
|
||||
ShutterSettings.version = SHUTTER_VERSION;
|
||||
@ -1170,15 +1171,16 @@ bool ShutterButtonHandlerMulti(void)
|
||||
uint8_t button = XdrvMailbox.payload;
|
||||
uint32_t button_index = XdrvMailbox.index;
|
||||
uint8_t shutter_index = ShutterSettings.shutter_button[button_index].shutter_number;
|
||||
uint8_t button_press_counter = Button.press_counter[button_index] ;
|
||||
uint8_t button_press_counter = Button.press_counter[button_index];
|
||||
|
||||
AddLog(LOG_LEVEL_DEBUG_MORE, PSTR("MULTI: SHT: Shtr%d, Button %d, hold %d, dir %d, index %d, payload %d, last state %d, press counter %d, window %d"),
|
||||
AddLog(LOG_LEVEL_DEBUG_MORE, PSTR("MULTI: SHT: Shtr%d, Btn %d, hold %d, dir %d, idx %d, payload %d, last state %d, press cnt %d, window %d, simu_press %d"),
|
||||
shutter_index+1, button_index+1, Button.hold_timer[button_index],Shutter[shutter_index].direction,XdrvMailbox.index,XdrvMailbox.payload,
|
||||
Button.last_state[button_index], Button.press_counter[button_index], Button.window_timer[button_index]);
|
||||
Button.last_state[button_index], Button.press_counter[button_index], Button.window_timer[button_index], Shutter[shutter_index].button_simu_pressed);
|
||||
|
||||
// multipress event handle back to main procedure
|
||||
if (Button.press_counter[button_index]>4) return false;
|
||||
|
||||
if (!Shutter[shutter_index].button_simu_pressed) {
|
||||
uint8_t pos_press_index = Button.press_counter[button_index]-1;
|
||||
|
||||
AddLog(LOG_LEVEL_DEBUG_MORE, PSTR("SHT: Shtr%d, Button %d = %d (single=1, double=2, tripple=3, hold=4)"), shutter_index+1, button_index+1, pos_press_index+1);
|
||||
@ -1240,11 +1242,19 @@ bool ShutterButtonHandlerMulti(void)
|
||||
} // for (uint32_t)
|
||||
} // ShutterSettings.shutter_button[button_index].positionmatrix & ((0x01<<26)<<pos_press_index
|
||||
// reset counter is served by shutter driver
|
||||
}
|
||||
|
||||
Response_P(PSTR("{"));
|
||||
ResponseAppend_P(JSON_SHUTTER_BUTTON, shutter_index+1, button_index+1 , button_press_counter);
|
||||
ResponseAppend_P(JSON_SHUTTER_BUTTON, shutter_index+1, Shutter[shutter_index].button_simu_pressed ? 0 : button_index+1, button_press_counter);
|
||||
ResponseJsonEnd();
|
||||
MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_STAT, PSTR(D_PRFX_SHUTTER));
|
||||
Shutter[shutter_index].button_simu_pressed = 0;
|
||||
// reset all buttons on this shutter to prevent further actions with the second button comming in
|
||||
for (uint32_t i = 0; i < MAX_SHUTTERS_ESP32*2 ; i++) {
|
||||
if ((ShutterSettings.shutter_button[i].enabled) && (ShutterSettings.shutter_button[i].shutter_number == shutter_index) ) {
|
||||
Button.press_counter[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -1260,6 +1270,7 @@ bool ShutterButtonHandler(void)
|
||||
shutter_index+1, button_index+1, Button.hold_timer[button_index],Shutter[shutter_index].direction,XdrvMailbox.index,XdrvMailbox.payload,
|
||||
Button.last_state[button_index], Button.press_counter[button_index], Button.window_timer[button_index]);
|
||||
|
||||
Shutter[shutter_index].button_simu_pressed |= ShutterButtonIsSimultaneousHold( button_index, shutter_index);
|
||||
if (Button.hold_timer[button_index] > 100 ) {
|
||||
Button.hold_timer[button_index] = 1; // Reset button hold counter to stay below hold trigger
|
||||
}
|
||||
@ -1280,6 +1291,22 @@ bool ShutterButtonHandler(void)
|
||||
return true;
|
||||
}
|
||||
|
||||
// simulatanous press. Stop
|
||||
if (PRESSED == button
|
||||
&& Shutter[shutter_index].button_simu_pressed
|
||||
&& Button.window_timer[button_index] == 0
|
||||
&& Button.press_counter[button_index] > 0
|
||||
)
|
||||
{
|
||||
AddLog(LOG_LEVEL_DEBUG_MORE, PSTR("Simu Hold detected"));
|
||||
Button.press_counter[button_index] = 0;
|
||||
|
||||
if ( button_index % 2 ) {
|
||||
ShutterButtonHandlerMulti();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
//long press detected. Start moving shutter into direction
|
||||
if (PRESSED == button
|
||||
&& Shutter[shutter_index].direction == 0 //shutter in STOP Position
|
||||
|
Loading…
x
Reference in New Issue
Block a user