From 3dc86ac6d472f73b3e8ee01b3cd3dbfdba45bf44 Mon Sep 17 00:00:00 2001 From: openshwprojects Date: Sun, 24 Jul 2022 09:09:14 +0200 Subject: [PATCH] instant press aka SetOption13 --- src/httpserver/http_fns.c | 2 +- src/new_pins.c | 30 ++++++++++++++++++++++++------ src/new_pins.h | 3 ++- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/httpserver/http_fns.c b/src/httpserver/http_fns.c index a8e3ae124..2930211a9 100644 --- a/src/httpserver/http_fns.c +++ b/src/httpserver/http_fns.c @@ -1536,7 +1536,7 @@ const char *g_obk_flagNames[] = { "[LED][Debug] Show raw PWM controller on WWW index instead of new LED RGB/CW/etc picker", "[LED] Force show RGBCW controller (for example, for SM2135 LEDs, or for DGR sender)", "[CMD] Enable TCP console command server (for Putty, etc)", - "error", + "[BTN] Instant touch reaction instead of waiting for release (aka SetOption 13)", "error", "error", "error", diff --git a/src/new_pins.c b/src/new_pins.c index 71e50cac8..320213936 100644 --- a/src/new_pins.c +++ b/src/new_pins.c @@ -128,18 +128,35 @@ void RAW_SetPinValue(int index, int iVal){ HAL_PIN_SetOutputValue(index, iVal); } } +void Button_OnInitialPressDown(int index) +{ + //addLogAdv(LOG_INFO, LOG_FEATURE_GENERAL,"%i Button_OnInitialPressDown\r\n", index); + + // so-called SetOption13 - instant reaction to touch instead of waiting for release + if(CFG_HasFlag(OBK_FLAG_BTN_INSTANTTOUCH)) { + if(g_cfg.pins.roles[index] == IOR_Button_ToggleAll || g_cfg.pins.roles[index] == IOR_Button_ToggleAll_n) + { + CHANNEL_DoSpecialToggleAll(); + return; + } + CHANNEL_Toggle(g_cfg.pins.channels[index]); + } +} void Button_OnShortClick(int index) { addLogAdv(LOG_INFO, LOG_FEATURE_GENERAL,"%i key_short_press\r\n", index); - if(g_cfg.pins.roles[index] == IOR_Button_ToggleAll || g_cfg.pins.roles[index] == IOR_Button_ToggleAll_n) - { - CHANNEL_DoSpecialToggleAll(); - return; - } // fire event - button on pin was clicked EventHandlers_FireEvent(CMD_EVENT_PIN_ONCLICK,index); + // so-called SetOption13 - instant reaction to touch instead of waiting for release // first click toggles FIRST CHANNEL linked to this button - CHANNEL_Toggle(g_cfg.pins.channels[index]); + if(CFG_HasFlag(OBK_FLAG_BTN_INSTANTTOUCH)==false) { + if(g_cfg.pins.roles[index] == IOR_Button_ToggleAll || g_cfg.pins.roles[index] == IOR_Button_ToggleAll_n) + { + CHANNEL_DoSpecialToggleAll(); + return; + } + CHANNEL_Toggle(g_cfg.pins.channels[index]); + } } void Button_OnDoubleClick(int index) { @@ -731,6 +748,7 @@ void PIN_Input_Handler(int pinIndex) if(handle->button_level == handle->active_level) { //start press down handle->event = (uint8_t)BTN_PRESS_DOWN; EVENT_CB(BTN_PRESS_DOWN); + Button_OnInitialPressDown(pinIndex); handle->ticks = 0; handle->repeat = 1; handle->state = 1; diff --git a/src/new_pins.h b/src/new_pins.h index 397d8db3b..de351a9b4 100644 --- a/src/new_pins.h +++ b/src/new_pins.h @@ -96,8 +96,9 @@ typedef struct pinsState_s { #define OBK_FLAG_LED_RAWCHANNELSMODE 3 #define OBK_FLAG_LED_FORCESHOWRGBCWCONTROLLER 4 #define OBK_FLAG_CMD_ENABLETCPRAWPUTTYSERVER 5 +#define OBK_FLAG_BTN_INSTANTTOUCH 6 -#define OBK_TOTAL_FLAGS 6 +#define OBK_TOTAL_FLAGS 7 // // Main config structure (less than 2KB)