C++ DevKit
C++ set of OOP library
Loading...
Searching...
No Matches
switch_button.h
Go to the documentation of this file.
1
11#pragma once
12
13#include "pico/stdio.h"
14#include "pico/stdlib.h"
15#include <stdio.h>
17
19#define GPIO_HI true
20
22#define GPIO_LO false
23
43
45#define DEBOUNCE_us 10000 // default to 10ms
47#define LONG_RELEASE_DELAY_us 1000000 // default to 1s
49#define LONG_PUSH_DELAY_us 1000000 // default to 1s
51#define TIME_OUT_DELAY_us 5000000 // default top 5s
52
90
106{
107private:
108protected:
109 /*time related members*/
112
115
121
127
128 /*mechanical switch related members*/
130 uint gpio;
131
134
137
144 bool is_switch_pushed();
145
148
149 /*logical button related members*/
152
153public:
161
162 SwitchButton();
168
175
182};
183
197{
198private:
202 uint32_t irq_event_mask_config;
210 bool is_switch_pushed(uint32_t current_event_mask);
211
212protected:
213public:
219 void irq_enabled(bool enabled);
228 SwitchButtonWithIRQ(uint gpio, gpio_irq_callback_t call_back, struct_ConfigSwitchButton conf = {},
229 uint32_t event_mask_config = GPIO_IRQ_EDGE_FALL | GPIO_IRQ_EDGE_RISE);
242 UIControlEvent process_IRQ_event(uint32_t current_event_mask);
243};
SwitchButton status is sampled periodically by software.
Definition switch_button.h:106
bool previous_switch_pushed_state
The previous state read during the previous period.
Definition switch_button.h:147
bool is_switch_pushed()
return the status of the switch.
Definition switch_button.cpp:91
uint time_out_delay_us
if the button is released after time_out_delay_us (in microseconds) a UIControlEvent::TIME_OUT is ret...
Definition switch_button.h:126
~SwitchButton()
Destroy the SwitchButton object.
Definition switch_button.cpp:28
ButtonState button_status
the logical button status, required to manage the event returned when the switch is pushed or release...
Definition switch_button.h:151
uint long_release_delay_us
if the button is released after long_release_delay_us (in microseconds) a UIControlEvent::RELEASED_AF...
Definition switch_button.h:120
uint gpio
the GPIO that reads the logical state of the switch (pushed or released)
Definition switch_button.h:130
ButtonState get_button_status()
Get the button status object.
Definition switch_button.cpp:86
SwitchButton(uint gpio, struct_ConfigSwitchButton conf={})
Construct a new SwitchButton object.
Definition switch_button.cpp:5
UIControlEvent process_sample_event()
the periodic routine that process deboucing, push and release of the switch.
Definition switch_button.cpp:32
uint debounce_delay_us
The time during which all changes in the switch state is ignored.
Definition switch_button.h:111
uint long_push_delay_us
when a button is pushed more than long_push_delay_us (in microseconds) a UIControlEvent::LONG_PUSH is...
Definition switch_button.h:114
bool active_lo
his indicates that when the switch is pushed, a logical LO (0) signal is read.
Definition switch_button.h:133
uint previous_change_time_us
the system time stored on the previous switch state change.
Definition switch_button.h:136
void irq_enabled(bool enabled)
"AND" function used to enable/disable interrupt during Interrupt Service Routine (ISR)
Definition switch_button.cpp:140
~SwitchButtonWithIRQ()
Destroy the SwitchButtonWithIRQ object.
Definition switch_button.cpp:108
UIControlEvent process_IRQ_event(uint32_t current_event_mask)
Process IRQ event and return the resulting event.
Definition switch_button.cpp:112
SwitchButtonWithIRQ(uint gpio, gpio_irq_callback_t call_back, struct_ConfigSwitchButton conf={}, uint32_t event_mask_config=GPIO_IRQ_EDGE_FALL|GPIO_IRQ_EDGE_RISE)
Construct a new SwitchButtonWithIRQ object.
Definition switch_button.cpp:97
These are the values used to configure a switch button (0) debounce_delay_us (1) long_release_delay_u...
Definition switch_button.h:63
bool active_lo
if true, this indicates that when the switch is pushed, a logical LO (0) signal is read on GPIO pin.
Definition switch_button.h:88
uint long_push_delay_us
when a switch is pushed more than long_push_delay_us (in microseconds) a UIControlEvent::LONG_PUSH is...
Definition switch_button.h:77
uint long_release_delay_us
if the switch is released after long_release_delay_us (in microseconds) a UIControlEvent::RELEASED_AF...
Definition switch_button.h:73
uint time_out_delay_us
when a switch is released and not pushed again for time_out_delay_us (in microseconds) a UIControlEve...
Definition switch_button.h:83
uint debounce_delay_us
The time during which all changes in the switch state is ignored.
Definition switch_button.h:68
#define DEBOUNCE_us
the default value for debounce_delay_us
Definition switch_button.h:45
#define LONG_PUSH_DELAY_us
the default value for LONG_PUSH_DELAY_us
Definition switch_button.h:49
#define LONG_RELEASE_DELAY_us
the default value for LONG_RELEASE_DELAY_us
Definition switch_button.h:47
#define TIME_OUT_DELAY_us
the default value for TIME_OUT_DELAY_us
Definition switch_button.h:51
ButtonState
The logical state of the switch (0) IDLE (1) ACTIVE (2) RELEASE_PENDING (3) TIME_OUT_PENDING.
Definition switch_button.h:33
@ ACTIVE
the switch has been pushed, the button is active
Definition switch_button.h:37
@ TIME_OUT_PENDING
the switch has beeb released, the button wait for next action. If nothing occurs, a time_out event is...
Definition switch_button.h:41
@ IDLE
The button is inactive.
Definition switch_button.h:35
@ RELEASE_PENDING
A long push has been detected, the switch wait to be released.
Definition switch_button.h:39
UIControlEvent
The list of predefined events that a button, or more generally an User Interface Controller,...
Definition ui_control_event.h:18