|
RSeries astromech firmware
|
|
Go to the documentation of this file. 1 #ifndef AnoRotaryEncoder_h
2 #define AnoRotaryEncoder_h
19 bool useInterrupt =
true) :
21 fPinManager(pinManager)
23 fButtonPin[0] = buttonUp;
24 fButtonPin[1] = buttonLeft;
25 fButtonPin[2] = buttonDown;
26 fButtonPin[3] = buttonRight;
27 fButtonPin[4] = buttonIn;
28 memset(&fButtonState,
'\0',
sizeof(fButtonState));
29 memset(&fButtonOldState,
'\0',
sizeof(fButtonOldState));
30 for (
unsigned i = 0; i <
sizeof(fButtonPin); i++)
31 fPinManager.
pinMode(fButtonPin[i], INPUT_PULLUP);
36 for (
unsigned i = 0; i <
sizeof(fButtonPin); i++)
38 if (fButtonPin[i] == pin)
40 fButtonNotify[i] = notify;
47 return fButtonStateChanged;
53 for (
unsigned i = 0; i <
sizeof(fButtonPin); i++)
63 for (
unsigned i = 0; i <
sizeof(fButtonPin); i++)
65 if (fButtonPin[i] == pin)
66 return fButtonState[i];
73 for (
unsigned i = 0; i <
sizeof(fButtonPin); i++)
75 if (fButtonPin[i] == pin)
77 return fButtonOldState[i] && !fButtonState[i];
85 fButtonStateChanged =
false;
87 for (
unsigned i = 0; i <
sizeof(fButtonPin); i++)
89 bool newState = !fPinManager.
digitalRead(fButtonPin[i]);
90 fButtonOldState[i] = fButtonState[i];
91 if (newState != fButtonState[i])
93 fButtonState[i] = newState;
94 fButtonStateChanged =
true;
95 if (fButtonNotify[i] !=
nullptr)
97 fButtonNotify[i](newState);
104 typedef void (*ButtonNotifyProc)(
bool pressed);
106 bool fButtonState[
sizeof(fButtonPin)];
107 bool fButtonOldState[
sizeof(fButtonPin)];
108 ButtonNotifyProc fButtonNotify[
sizeof(fButtonPin)];
109 bool fButtonStateChanged =
false;
LatchMode
Definition: RotaryEncoder.h:29
virtual void pinMode(uint8_t pin, uint8_t mode)
Definition: PinManager.h:20
virtual void animate() override
Subclasses must implement this function to run through a single frame of animation/activity.
Definition: AnoRotaryEncoder.h:83
uint8_t getButtonPressedMask() const
Definition: AnoRotaryEncoder.h:50
Definition: AnoRotaryEncoder.h:7
bool isButtonReleased(byte pin) const
Definition: AnoRotaryEncoder.h:71
void setButtonNotify(byte pin, void(*notify)(bool))
Definition: AnoRotaryEncoder.h:34
virtual void animate() override
Subclasses must implement this function to run through a single frame of animation/activity.
Definition: RotaryEncoder.h:62
AnoRotaryEncoder(PinManager &pinManager, byte encoderA, byte encoderB, byte buttonUp, byte buttonLeft, byte buttonDown, byte buttonRight, byte buttonIn, bool useInterrupt=true)
Definition: AnoRotaryEncoder.h:10
Definition: PinManager.h:6
bool isButtonPressed(byte pin) const
Definition: AnoRotaryEncoder.h:61
virtual bool digitalRead(uint8_t pin)
Definition: PinManager.h:12
Decodes the signals from a rotary encoder (quadrature pulses) and translates them into a counter posi...
Definition: RotaryEncoder.h:19
bool hasButtonStateChanged() const
Definition: AnoRotaryEncoder.h:45