2024-02-12 22:44:21 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "OneButton.h"
|
2022-05-07 10:31:21 +00:00
|
|
|
#include "concurrency/OSThread.h"
|
|
|
|
#include "configuration.h"
|
2022-02-28 21:19:38 +00:00
|
|
|
|
2023-01-19 03:13:31 +00:00
|
|
|
class ButtonThread : public concurrency::OSThread
|
|
|
|
{
|
2024-02-12 22:44:21 +00:00
|
|
|
public:
|
|
|
|
static const uint32_t c_longPressTime = 5000; // shutdown after 5s
|
|
|
|
static const uint32_t c_holdOffTime = 30000; // hold off 30s after boot
|
|
|
|
|
|
|
|
enum ButtonEventType {
|
|
|
|
BUTTON_EVENT_NONE,
|
|
|
|
BUTTON_EVENT_PRESSED,
|
|
|
|
BUTTON_EVENT_DOUBLE_PRESSED,
|
|
|
|
BUTTON_EVENT_MULTI_PRESSED,
|
|
|
|
BUTTON_EVENT_LONG_PRESSED,
|
|
|
|
BUTTON_EVENT_LONG_RELEASED,
|
|
|
|
BUTTON_EVENT_TOUCH_PRESSED
|
|
|
|
};
|
|
|
|
|
|
|
|
ButtonThread();
|
|
|
|
int32_t runOnce() override;
|
|
|
|
|
|
|
|
private:
|
2022-02-28 21:19:38 +00:00
|
|
|
#ifdef BUTTON_PIN
|
2023-01-19 03:13:31 +00:00
|
|
|
OneButton userButton;
|
2022-02-28 21:19:38 +00:00
|
|
|
#endif
|
|
|
|
#ifdef BUTTON_PIN_ALT
|
2023-01-19 03:13:31 +00:00
|
|
|
OneButton userButtonAlt;
|
2022-02-28 21:19:38 +00:00
|
|
|
#endif
|
|
|
|
#ifdef BUTTON_PIN_TOUCH
|
2023-01-19 03:13:31 +00:00
|
|
|
OneButton userButtonTouch;
|
2023-11-26 21:08:20 +00:00
|
|
|
#endif
|
2024-01-12 08:00:31 +00:00
|
|
|
#if defined(ARCH_PORTDUINO)
|
2023-11-26 21:08:20 +00:00
|
|
|
OneButton userButton;
|
2022-02-28 21:19:38 +00:00
|
|
|
#endif
|
|
|
|
|
2024-02-12 22:44:21 +00:00
|
|
|
// set during IRQ
|
|
|
|
static volatile ButtonEventType btnEvent;
|
2022-02-28 21:19:38 +00:00
|
|
|
|
2024-02-12 22:44:21 +00:00
|
|
|
static void wakeOnIrq(int irq, int mode);
|
2022-02-28 21:19:38 +00:00
|
|
|
|
2024-02-12 22:44:21 +00:00
|
|
|
// IRQ callbacks
|
|
|
|
static void touchPressed() { btnEvent = BUTTON_EVENT_TOUCH_PRESSED; }
|
|
|
|
static void userButtonPressed() { btnEvent = BUTTON_EVENT_PRESSED; }
|
|
|
|
static void userButtonDoublePressed() { btnEvent = BUTTON_EVENT_DOUBLE_PRESSED; }
|
|
|
|
static void userButtonMultiPressed() { btnEvent = BUTTON_EVENT_MULTI_PRESSED; }
|
|
|
|
static void userButtonPressedLongStart();
|
|
|
|
static void userButtonPressedLongStop();
|
2023-01-19 03:13:31 +00:00
|
|
|
};
|