-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinput.h
More file actions
103 lines (83 loc) · 2.62 KB
/
input.h
File metadata and controls
103 lines (83 loc) · 2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
* TT Control, advanced sinusoidal control of multi-phase turntable motors
* Created by Ashley Cox at The Blind Man’s Workshop
* https://theblindmansworkshop.com
* No part of this code may be used or reproduced for commercial purposes without written permission and contractual agreement
* All external libraries and frameworks are the property of their respective authors and governed by their respective licenses
*/
#ifndef INPUT_H
#define INPUT_H
#include <Arduino.h>
#include "config.h"
// Abstracted Input Events
enum InputEvent {
EVT_NONE,
EVT_NAV_UP, // Encoder Right (Clockwise)
EVT_NAV_DOWN, // Encoder Left (Counter-Clockwise)
EVT_SELECT, // Short Press
EVT_BACK, // Long Press
EVT_EXIT, // Very Long Press
EVT_DOUBLE_CLICK // Double Click
};
/**
* @brief Manages physical input devices (Encoder, Buttons).
*
* Handles:
* - Quadrature decoding
* - Acceleration (faster rotation = larger delta)
* - Button debouncing
* - Click detection (Single, Double, Long, Very Long)
*/
class InputManager {
public:
InputManager();
void begin();
void update();
// Check for pending high-level events (consumes the event)
InputEvent getEvent();
// Get raw encoder delta for value editing (consumes the delta)
int getEncoderDelta();
// Get pitch encoder delta (consumes the delta)
int getPitchDelta();
// Check if main button is currently held down
bool isButtonDown() { return _btnPressed; }
// Injection for Serial/Testing
void injectDelta(int delta);
void injectButton(bool pressed);
// Global Button Accessors (Debounced)
bool isSpeedButtonPressed();
bool isStartStopPressed();
bool isStandbyPressed();
private:
// Encoder State
volatile long _encoderPosition;
long _lastEncoderPosition;
int _encDelta; // Accumulated delta since last read
uint32_t _lastEncTime;
int _encAccel;
// Pitch Encoder State
int _pitchLastClk;
int _pitchDelta;
uint32_t _lastPitchTime;
int _pitchAccel;
// Button State
bool _btnPressed;
uint32_t _btnPressTime;
bool _waitingForDoubleClick;
uint32_t _doubleClickTimer;
int _clickCount;
// Global Button State
bool _speedBtnState;
uint32_t _speedBtnTime;
bool _startStopBtnState;
uint32_t _startStopBtnTime;
bool _standbyBtnState;
uint32_t _standbyBtnTime;
static void isrEncoder();
// Event Queue (Single item buffer)
InputEvent _pendingEvent;
// Injection State
int _injectedDelta;
int readPitchEncoder();
};
#endif // INPUT_H