feat: button handler with press detection and combo support
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
38
src/button_handler.h
Normal file
38
src/button_handler.h
Normal file
@@ -0,0 +1,38 @@
|
||||
#pragma once
|
||||
|
||||
#include <Arduino.h>
|
||||
#include "config.h"
|
||||
|
||||
class PowerManager;
|
||||
class SettingsManager;
|
||||
|
||||
enum class ButtonEvent : uint8_t {
|
||||
None,
|
||||
NextPhoto,
|
||||
RandomPhoto,
|
||||
PlayPause,
|
||||
DeepSleep,
|
||||
FactoryReset
|
||||
};
|
||||
|
||||
class ButtonHandler {
|
||||
public:
|
||||
void begin(PowerManager& power, SettingsManager& settings);
|
||||
ButtonEvent poll();
|
||||
|
||||
private:
|
||||
PowerManager* _power = nullptr;
|
||||
SettingsManager* _settings = nullptr;
|
||||
|
||||
unsigned long _btnTopPressTime = 0;
|
||||
unsigned long _btnUpPressTime = 0;
|
||||
unsigned long _btnDownPressTime = 0;
|
||||
|
||||
bool _btnTopPressed = false;
|
||||
bool _btnUpPressed = false;
|
||||
bool _btnDownPressed = false;
|
||||
|
||||
unsigned long _lastDebounce = 0;
|
||||
|
||||
bool debounced(unsigned long now);
|
||||
};
|
||||
Reference in New Issue
Block a user