From 49edef1d3f222ab93535a5c29095d96f1e6b0e35 Mon Sep 17 00:00:00 2001 From: Pol Henarejos Date: Mon, 1 Jun 2026 01:40:31 +0200 Subject: [PATCH] Add cancel button event. Signed-off-by: Pol Henarejos --- src/button.c | 14 +++++++------- src/button.h | 4 +++- src/usb/usb.c | 9 ++++++++- src/usb/usb.h | 1 + 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/button.c b/src/button.c index 96ff136..9fc9570 100644 --- a/src/button.c +++ b/src/button.c @@ -40,6 +40,7 @@ bool is_req_button_pending(void) { } bool cancel_button = false; +bool touch_accept_button = false; #if !defined(ENABLE_EMULATION) #ifdef ESP_PLATFORM @@ -94,7 +95,7 @@ static bool button_pressed_state = false; static uint32_t button_pressed_time = 0; static uint8_t button_press = 0; -bool button_wait(void) { +int button_wait(void) { /* Disabled by default. As LED may not be properly configured, it will not be possible to indicate button press unless it is commissioned. */ @@ -103,7 +104,7 @@ bool button_wait(void) { button_timeout = phy_data.up_btn * 1000; } if (button_timeout == 0) { - return false; + return 0; } signal_user_presence_request_data_t data = { .timeout = button_timeout / 1000, @@ -137,14 +138,14 @@ bool button_wait(void) { req_button_pending = false; if (timeout) { signal_emit(SIGNAL_USER_PRESENCE_TIMEOUT); + return 1; } else if (cancel_button) { signal_emit(SIGNAL_USER_PRESENCE_CANCELLED); + return 2; } - else { - signal_emit(SIGNAL_USER_PRESENCE_COMPLETED); - } - return timeout || cancel_button; + signal_emit(SIGNAL_USER_PRESENCE_COMPLETED); + return 0; } #endif @@ -170,4 +171,3 @@ void button_task(void) { } #endif } - diff --git a/src/button.h b/src/button.h index a0633bb..bf9bea1 100644 --- a/src/button.h +++ b/src/button.h @@ -25,7 +25,9 @@ #define BOOT_PIN GPIO_NUM_0 #endif -extern bool button_wait(void); +extern int button_wait(void); extern void button_task(void); +extern bool cancel_button; +extern bool touch_accept_button; #endif // BUTTON_H diff --git a/src/usb/usb.c b/src/usb/usb.c index 7dab2b2..a4d21d3 100644 --- a/src/usb/usb.c +++ b/src/usb/usb.c @@ -347,7 +347,14 @@ int card_status(uint8_t itf) { } #ifndef ENABLE_EMULATION else if (m == EV_PRESS_BUTTON) { - uint32_t flag = button_wait() ? EV_BUTTON_TIMEOUT : EV_BUTTON_PRESSED; + int ret = button_wait(); + uint32_t flag = EV_BUTTON_PRESSED; + if (ret == 1) { //timeout + flag = EV_BUTTON_TIMEOUT; + } + else if (ret == 2) { //cancelled + flag = EV_BUTTON_CANCELLED; + } queue_try_add(&usb_to_card_q, &flag); } #endif diff --git a/src/usb/usb.h b/src/usb/usb.h index 79acfcc..f296370 100644 --- a/src/usb/usb.h +++ b/src/usb/usb.h @@ -49,6 +49,7 @@ #define EV_EXIT 8 #define EV_BUTTON_TIMEOUT 16 #define EV_BUTTON_PRESSED 32 +#define EV_BUTTON_CANCELLED 64 enum { ITF_INVALID = 0xFF };