2025-08-26 16:35:25 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
2025-09-14 20:17:24 +02:00
|
|
|
// This is a version of RotaryEncoder which is based on a debounce inherent FSM table (see RotaryEncoder library)
|
2025-08-26 16:35:25 +02:00
|
|
|
|
|
|
|
|
#include "InputBroker.h"
|
|
|
|
|
#include "concurrency/OSThread.h"
|
|
|
|
|
#include "mesh/NodeDB.h"
|
|
|
|
|
|
|
|
|
|
class RotaryEncoder;
|
|
|
|
|
|
2025-12-12 04:04:15 +03:00
|
|
|
class RotaryEncoderImpl final : public InputPollable
|
2025-08-26 16:35:25 +02:00
|
|
|
{
|
|
|
|
|
public:
|
2025-09-21 03:23:16 +02:00
|
|
|
RotaryEncoderImpl();
|
2025-12-12 04:04:15 +03:00
|
|
|
~RotaryEncoderImpl() override;
|
|
|
|
|
bool init();
|
2025-09-19 22:05:18 +02:00
|
|
|
virtual void pollOnce() override;
|
2025-12-12 04:04:15 +03:00
|
|
|
// Disconnect and reconnect interrupts for light sleep
|
|
|
|
|
#ifdef ARCH_ESP32
|
|
|
|
|
int beforeLightSleep(void *unused);
|
|
|
|
|
int afterLightSleep(esp_sleep_wakeup_cause_t cause);
|
|
|
|
|
#endif
|
2025-08-26 16:35:25 +02:00
|
|
|
|
|
|
|
|
protected:
|
2025-09-21 03:23:16 +02:00
|
|
|
static RotaryEncoderImpl *interruptInstance;
|
2025-09-12 05:53:35 +02:00
|
|
|
|
2025-08-26 16:35:25 +02:00
|
|
|
input_broker_event eventCw = INPUT_BROKER_NONE;
|
|
|
|
|
input_broker_event eventCcw = INPUT_BROKER_NONE;
|
|
|
|
|
input_broker_event eventPressed = INPUT_BROKER_NONE;
|
|
|
|
|
|
|
|
|
|
RotaryEncoder *rotary;
|
2025-12-12 04:04:15 +03:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
#ifdef ARCH_ESP32
|
|
|
|
|
bool isFirstInit;
|
|
|
|
|
#endif
|
|
|
|
|
void detachRotaryEncoderInterrupts();
|
|
|
|
|
void attachRotaryEncoderInterrupts();
|
|
|
|
|
|
|
|
|
|
#ifdef ARCH_ESP32
|
|
|
|
|
// Get notified when lightsleep begins and ends
|
|
|
|
|
CallbackObserver<RotaryEncoderImpl, void *> lsObserver =
|
|
|
|
|
CallbackObserver<RotaryEncoderImpl, void *>(this, &RotaryEncoderImpl::beforeLightSleep);
|
|
|
|
|
CallbackObserver<RotaryEncoderImpl, esp_sleep_wakeup_cause_t> lsEndObserver =
|
|
|
|
|
CallbackObserver<RotaryEncoderImpl, esp_sleep_wakeup_cause_t>(this, &RotaryEncoderImpl::afterLightSleep);
|
|
|
|
|
#endif
|
2025-08-26 16:35:25 +02:00
|
|
|
};
|
|
|
|
|
|
2025-09-21 03:23:16 +02:00
|
|
|
extern RotaryEncoderImpl *rotaryEncoderImpl;
|