JM9 XRCU Board 0.1.3a
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 isPressed;
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
121 bool isButtonPressed();
122
126 void scheduledCallback();
127
132 bool anyOtherButtonsPressed();
133
138 void setAntiMisclickActive(const bool active);
139
143 void stateChangedCallback();
144
148 struct Node {
152 Button *const button;
153
157 Node *volatile next;
158
162 Node(Button *const button, Node *const next);
163 };
164
168 static Node *volatile activeButtonsListHead;
169
173 void registerButtonToActiveList();
174
178 void unregisterButtonFromActiveList();
179
183 static const TransitionEdge DEFAULT_SINGLE_CLICK_TRANSITION_EDGE;
184
188 static const unsigned long DEFAULT_PULSE_DELAY_START_MILLIS;
189
193 static const unsigned long DEFAULT_PULSE_CLICKS_MINIMUM_INTERVAL_MILLIS;
194
195 public:
200 Button(const uint32_t pin);
201
205 ~Button();
206
211 void begin();
212
217 void end();
218
223 bool isClicked();
224
231
238 void setPulseClickEnabled(const bool enabled);
239
245 void setPulseDelayStartPeriod(const unsigned long period);
246
253 void setPulseClicksMinimumInterval(const unsigned long minInterval);
254
262 void setSecureModeEnabled(const bool enabled);
263
271 void attachInterrupt(void (*callback)(void));
272
277 void detachInterrupt();
278
283 static void scheduledAllButtonsCallback();
284};
285
291extern Button buttons [4];
292
298extern Button &button1;
299
305extern Button &button2;
306
312extern Button &button3;
313
319extern Button &button4;
320
329bool is_button_clicked(const uint32_t button_no);
330
338void set_buttons_mode(const uint8_t mode);
339
345enum {
346
353
359
366
374
380
387
395};
396
404void button_attach_interrupt(const uint32_t button_no, void (*user_func)(void));
405
412void button_detach_interrupt(const uint32_t button_no);
413
414
415#endif
bool is_button_clicked(const uint32_t button_no)
Checks whether a button is clicked.
Definition Buttons.cpp:296
void set_buttons_mode(const uint8_t mode)
Sets the buttons mode.
Definition Buttons.cpp:301
void button_detach_interrupt(const uint32_t button_no)
Detaches the interrupt on a button from the button.
Definition Buttons.cpp:351
@ button_rise_pulse_mode
Clicks on every rising edge and during long pulses.
Definition Buttons.h:386
@ button_fall_mode
Clicks on every falling edge.
Definition Buttons.h:358
@ button_raw_mode
Clicks whenever button is down.
Definition Buttons.h:352
@ button_rise_mode
Clicks on every rising edge.
Definition Buttons.h:379
@ button_rise_pulse_secured_mode
Clicks on every rising edge and during long pulses with anti-misclick.
Definition Buttons.h:394
@ button_fall_pulse_mode
Clicks on every falling edge and during long pulses.
Definition Buttons.h:365
@ button_fall_pulse_secured_mode
Clicks on every falling edge and during long pulses with anti-misclick.
Definition Buttons.h:373
void button_attach_interrupt(const uint32_t button_no, void(*user_func)(void))
Attaches an interrupt to a button.
Definition Buttons.cpp:346
Button Driver for XRCU.
Definition Buttons.h:18
void setSingleClickTransitionEdge(TransitionEdge edge)
Sets the edge of voltage level transition where a button should be deemed single clicked.
Definition Buttons.cpp:112
void setPulseDelayStartPeriod(const unsigned long period)
Sets the time delay between the button being "pressed and held" and the pulse click starts.
Definition Buttons.cpp:129
~Button()
Destroys this button and release the resources it occupied.
Definition Buttons.cpp:55
void detachInterrupt()
Detaches the interrupt function from this button as set in attachInterrupt(...).
Definition Buttons.cpp:154
void setSecureModeEnabled(const bool enabled)
Sets whether secure mode is enabled.
Definition Buttons.cpp:137
void begin()
Activates this button.
Definition Buttons.cpp:68
void setPulseClicksMinimumInterval(const unsigned long minInterval)
Sets the minimum time separation between 2 consecutive pulse clicks.
Definition Buttons.cpp:133
void attachInterrupt(void(*callback)(void))
Attaches an interrupt function to the button whenever its status is possibly changed.
Definition Buttons.cpp:150
void setPulseClickEnabled(const bool enabled)
Sets whether pulse click is enabled.
Definition Buttons.cpp:121
static void scheduledAllButtonsCallback()
The interrupt service routine to be run by JM9 XRCU System Callback at fixed intervals only.
Definition Buttons.cpp:173
void end()
Deactivates this button.
Definition Buttons.cpp:82
bool isClicked()
Checks whether this button is clicked.
Definition Buttons.cpp:94
Button(const uint32_t pin)
Creates a new button at a certain pin.
Definition Buttons.cpp:36
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