JM9 XRCU Board 0.1.4
Libraries API Reference
Loading...
Searching...
No Matches
Buttons.h
Go to the documentation of this file.
1
8
9#ifndef BUTTONS_H
10#define BUTTONS_H
11
12#include <Arduino.h>
13
18class Button {
19 private:
23 const uint32_t pin;
24
28 bool activated;
29
30 public:
44
45 private:
49 volatile TransitionEdge singleClickTransitionEdge;
50
54 volatile bool pulseClickEnabled;
55
60 volatile bool secureModeEnabled;
61
66 volatile bool isPressedCache;
67
72 volatile bool singleClicked;
73
78 volatile bool pulseClicked;
79
84 volatile unsigned long buttonFallTimeMillis;
85
89 unsigned long pulseDelayStartMillis;
90
94 unsigned long pulseClicksMinimumIntervalMillis;
95
99 unsigned long prevPulseClickResponseTimeMillis;
100
105 volatile bool antiMisclickActivated;
106
110 void (*volatile callback)(void);
111
115 void resetFields();
116
120 void scheduledCallback();
121
126 bool anyOtherButtonsPressed();
127
132 void setAntiMisclickActive(const bool active);
133
138 void stateChangedCallback(const bool isPressed);
139
143 struct Node {
147 Button *const button;
148
152 Node *volatile next;
153
157 Node(Button *const button, Node *const next);
158 };
159
163 static Node *volatile activeButtonsListHead;
164
168 void registerButtonToActiveList();
169
173 void unregisterButtonFromActiveList();
174
178 static const TransitionEdge DEFAULT_SINGLE_CLICK_TRANSITION_EDGE;
179
183 static const unsigned long DEFAULT_PULSE_DELAY_START_MILLIS;
184
188 static const unsigned long DEFAULT_PULSE_CLICKS_MINIMUM_INTERVAL_MILLIS;
189
190 public:
195 Button(const uint32_t pin);
196
201
206 void begin();
207
212 void end();
213
219 bool isPressed();
220
225 bool isClicked();
226
233
240 void setPulseClickEnabled(const bool enabled);
241
247 void setPulseDelayStartPeriod(const unsigned long period);
248
255 void setPulseClicksMinimumInterval(const unsigned long minInterval);
256
264 void setSecureModeEnabled(const bool enabled);
265
273 void attachInterrupt(void (*callback)(void));
274
280
286};
287
293extern Button buttons [4];
294
300extern Button &button1;
301
307extern Button &button2;
308
314extern Button &button3;
315
321extern Button &button4;
322
331bool is_button_clicked(const uint32_t button_no);
332
340void set_buttons_mode(const uint8_t mode);
341
347enum {
348
355
361
368
376
382
389
397};
398
406void button_attach_interrupt(const uint32_t button_no, void (*user_func)(void));
407
414void button_detach_interrupt(const uint32_t button_no);
415
416
417#endif
Button buttons[4]
The buttons.
bool is_button_clicked(const uint32_t button_no)
Checks whether a button is clicked.
Button & button1
The leftmost button.
Button & button4
The rightmost button.
void set_buttons_mode(const uint8_t mode)
Sets the buttons mode.
void button_detach_interrupt(const uint32_t button_no)
Detaches the interrupt on a button from the button.
@ button_rise_pulse_mode
Clicks on every rising edge and during long pulses.
Definition Buttons.h:388
@ button_fall_mode
Clicks on every falling edge.
Definition Buttons.h:360
@ button_raw_mode
Clicks whenever button is down.
Definition Buttons.h:354
@ button_rise_mode
Clicks on every rising edge.
Definition Buttons.h:381
@ button_rise_pulse_secured_mode
Clicks on every rising edge and during long pulses with anti-misclick.
Definition Buttons.h:396
@ button_fall_pulse_mode
Clicks on every falling edge and during long pulses.
Definition Buttons.h:367
@ button_fall_pulse_secured_mode
Clicks on every falling edge and during long pulses with anti-misclick.
Definition Buttons.h:375
Button & button3
The 3rd leftmost button.
void button_attach_interrupt(const uint32_t button_no, void(*user_func)(void))
Attaches an interrupt to a button.
Button & button2
The 2nd leftmost button.
Button Driver for XRCU.
Definition Buttons.h:18
bool isPressed()
Checks whether the button is physically pressed.
void setSingleClickTransitionEdge(TransitionEdge edge)
Sets the edge of voltage level transition where a button should be deemed single clicked.
void setPulseDelayStartPeriod(const unsigned long period)
Sets the time delay between the button being "pressed and held" and the pulse click starts.
~Button()
Destroys this button and release the resources it occupied.
void detachInterrupt()
Detaches the interrupt function from this button as set in attachInterrupt(...).
void setSecureModeEnabled(const bool enabled)
Sets whether secure mode is enabled.
static void scheduledAllButtonsCallback()
The interrupt service routine to be run by JM9 XRCU System Callback at fixed intervals only.
void begin()
Activates this button.
void setPulseClicksMinimumInterval(const unsigned long minInterval)
Sets the minimum time separation between 2 consecutive pulse clicks.
void attachInterrupt(void(*callback)(void))
Attaches an interrupt function to the button whenever its status is possibly changed.
void setPulseClickEnabled(const bool enabled)
Sets whether pulse click is enabled.
void end()
Deactivates this button.
bool isClicked()
Checks whether this button is clicked.
Button(const uint32_t pin)
Creates a new button at a certain pin.
TransitionEdge
The edge of voltage level transition where a button should be deemed single clicked.
Definition Buttons.h:34
@ PRESSING
The button is deemed single clicked when the button is pressed.
Definition Buttons.h:38
@ RELEASING
The button is deemed single clicked when the button is released after pressed.
Definition Buttons.h:42