C++ DevKit
C++ set of OOP library
Loading...
Searching...
No Matches
rtos_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 "hardware/timer.h"
16#include <stdio.h>
18#include "FreeRTOS.h"
19#include "queue.h"
20#include "task.h"
21
23#define GPIO_HI true
24
26#define GPIO_LO false
27
47
51struct struct_IRQData
52{
54 uint32_t current_time_us;
56 uint32_t event_mask;
57};
58
70
72#define DEBOUNCE_us 10000 // default to 10ms
74#define LONG_RELEASE_DELAY_us 1000000 // default to 1s
76#define LONG_PUSH_DELAY_ms 1000 // default to 1s
78#define TIME_OUT_DELAY_ms 5000 // default 5s/
79
118
137
139{
140private:
144 uint32_t irq_event_mask_config;
145
146protected:
154 bool is_switch_pushed(uint32_t current_event_mask);
155
156 /*time related members*/
159
162
168
174
175 /*mechanical switch related members*/
177 uint gpio;
178
181
184
187
188 /*logical button related members*/
191
193 QueueHandle_t switch_button_queue;
195 QueueHandle_t control_event_queue;
196
197public:
208 rtosSwitchButton(uint gpio, gpio_irq_callback_t call_back, QueueHandle_t in_switch_button_queue, QueueHandle_t out_control_event_queue,
209 struct_rtosConfigSwitchButton conf = {}, uint32_t event_mask_config = GPIO_IRQ_EDGE_FALL | GPIO_IRQ_EDGE_RISE);
210
216
221 virtual void rtos_process_IRQ_event() ;
222};
QueueHandle_t control_event_queue
the queue to which the resulting control event is sent
Definition rtos_switch_button.h:195
~rtosSwitchButton()
Destroy the SwitchButton object.
Definition rtos_switch_button.cpp:30
QueueHandle_t switch_button_queue
the queue from which IRQ data are received
Definition rtos_switch_button.h:193
ButtonState button_status
the logical button status, required to manage the event returned when the switch is pushed or release...
Definition rtos_switch_button.h:190
uint long_release_delay_us
if the button is released after long_release_delay_us (in microseconds) a UIControlEvent::RELEASED_AF...
Definition rtos_switch_button.h:167
rtosSwitchButton(uint gpio, gpio_irq_callback_t call_back, QueueHandle_t in_switch_button_queue, QueueHandle_t out_control_event_queue, struct_rtosConfigSwitchButton conf={}, uint32_t event_mask_config=GPIO_IRQ_EDGE_FALL|GPIO_IRQ_EDGE_RISE)
Construct a new rtos Switch Button object.
Definition rtos_switch_button.cpp:5
uint previous_change_time_us
the system time stored on the previous switch state change.
Definition rtos_switch_button.h:183
bool active_lo
his indicates that when the switch is pushed, a logical LO (0) signal is read.
Definition rtos_switch_button.h:180
uint debounce_delay_us
The time during which all changes in the switch state is ignored.
Definition rtos_switch_button.h:158
uint gpio
the GPIO that reads the logical state of the switch (pushed or released)
Definition rtos_switch_button.h:177
uint time_out_delay_ms
if the button is released after time_out_delay_ms (in milliseconds) a UIControlEvent::TIME_OUT is ret...
Definition rtos_switch_button.h:173
virtual void rtos_process_IRQ_event()
Process IRQ event and sent the resulting event to the event queue.
Definition rtos_switch_button.cpp:34
uint long_push_delay_ms
when a button is pushed more than long_push_delay_ms (in milliseconds) a UIControlEvent::LONG_PUSH is...
Definition rtos_switch_button.h:161
bool is_switch_pushed(uint32_t current_event_mask)
return the logical status of the switch. It process rising and falling edges of the interrupt,...
Definition rtos_switch_button.cpp:96
bool previous_switch_pushed_state
The previous state read during the previous period.
Definition rtos_switch_button.h:186
#define DEBOUNCE_us
the default value for debounce_delay_us
Definition rtos_switch_button.h:72
#define LONG_PUSH_DELAY_ms
the default value for LONG_PUSH_DELAY_us
Definition rtos_switch_button.h:76
#define LONG_RELEASE_DELAY_us
the default value for LONG_RELEASE_DELAY_us
Definition rtos_switch_button.h:74
#define TIME_OUT_DELAY_ms
the default value for TIME_OUT_DELAY_us
Definition rtos_switch_button.h:78
ButtonState
The logical state of the switch (0) IDLE (1) ACTIVE (2) RELEASE_PENDING (3) TIME_OUT_PENDING.
Definition rtos_switch_button.h:37
@ ACTIVE
the switch has been pushed, the button is active
Definition rtos_switch_button.h:41
@ TIME_OUT_PENDING
the switch has beeb released, the button wait for next action. If nothing occurs, a time_out event is...
Definition rtos_switch_button.h:45
@ IDLE
The button is inactive.
Definition rtos_switch_button.h:39
@ RELEASE_PENDING
A long push has been detected, the switch wait to be released.
Definition rtos_switch_button.h:43
this is the structure used to transmit control event through the queue
Definition rtos_switch_button.h:64
int gpio_number
the gpio that receive the IRQ
Definition rtos_switch_button.h:66
UIControlEvent event
the control event computed by the IRQ processing task
Definition rtos_switch_button.h:68
data structure used by ISR to capture, mask, time.
Definition rtos_hc_sr04.h:20
uint32_t current_time_us
the current time at wich the IRQ occurred
Definition rtos_hc_sr04.h:22
uint32_t event_mask
the IRQ mask given by the IRQ harware
Definition rtos_hc_sr04.h:24
These are the values used to configure a switch button delays related to action of the button (and ge...
Definition rtos_switch_button.h:91
uint time_out_delay_ms
when a switch is released and not pushed again for time_out_delay_ms (in milliseconds) a UIControlEve...
Definition rtos_switch_button.h:111
uint long_release_delay_us
if the switch is released after long_release_delay_us (in microseconds) a UIControlEvent::RELEASED_AF...
Definition rtos_switch_button.h:101
uint long_push_delay_ms
when a switch is maintained pushed more than long_push_delay_ms (in milliseconds) a UIControlEvent::L...
Definition rtos_switch_button.h:105
uint debounce_delay_us
The time during which all changes in the switch state is ignored.
Definition rtos_switch_button.h:96
bool active_lo
if true, this indicates that when the switch is pushed, a logical LO (0) signal is read on GPIO pin.
Definition rtos_switch_button.h:116
UIControlEvent
The list of predefined events that a button, or more generally an User Interface Controller,...
Definition ui_control_event.h:18