From 02dfa1385e25875659eec20313b8914ccbf60954 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Gassmann?= Date: Fri, 11 Oct 2024 02:18:54 +0200 Subject: [+] Button module with long / short press and release detection --- components/button/button_handler.h | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 components/button/button_handler.h (limited to 'components/button/button_handler.h') diff --git a/components/button/button_handler.h b/components/button/button_handler.h new file mode 100644 index 0000000..a980d5b --- /dev/null +++ b/components/button/button_handler.h @@ -0,0 +1,33 @@ +#ifndef BUTTON_HANDLER_H +#define BUTTON_HANDLER_H + +#include +#include +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "driver/gpio.h" +#include "esp_timer.h" + +#define LONG_PRESS 500 +#define BUTTON_PIN CONFIG_BUTTON_PIN +#define ESP_INTR_FLAG_DEFAULT 0 + +struct Button { + uint8_t pin; + int64_t time; + int64_t p_time; + uint16_t dt; +}; +static QueueHandle_t uinput_evt_queue = NULL; + +void setup_button(struct Button* b); +void button_task(void* arg); +bool is_pressed(struct Button* b); +bool was_pressed(struct Button* b, int64_t since); +bool was_pressed_and_released(struct Button* b, int64_t since); +bool was_short_pressed(struct Button* b, int64_t since); +bool was_long_pressed(struct Button* b, int64_t since); +bool was_short_pressed_and_released(struct Button* b, int64_t since); +bool was_long_pressed_and_released(struct Button* b, int64_t since); + +#endif // BUTTON_HANDLER_H \ No newline at end of file -- cgit v1.2.3