mirror of
https://github.com/polhenarejos/pico-keys-sdk
synced 2026-06-02 19:33:01 +02:00
Add cancel button event.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
14
src/button.c
14
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
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 };
|
||||
|
||||
|
||||
Reference in New Issue
Block a user