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
58
60#define DEBOUNCE_us 10000 // default to 10ms
62#define LONG_RELEASE_DELAY_us 1000000 // default to 1s
64#define LONG_PUSH_DELAY_ms 1000 // default to 1s
66#define TIME_OUT_DELAY_ms 5000 // default 5s/
67
106
125
127{
128private:
133
134protected:
142 bool is_switch_pushed(uint32_t current_event_mask);
143
144 /*time related members*/
147
150
156
162
163 /*mechanical switch related members*/
165 uint gpio;
166
169
172
175
176 /*logical button related members*/
179
181 QueueHandle_t control_event_queue;
182
183public:
185 QueueHandle_t IRQdata_input_queue;
186
196 rtos_SwitchButton(uint gpio, gpio_irq_callback_t call_back, QueueHandle_t control_event_destination_queue,
197 struct_rtosConfigSwitchButton conf = {}, uint32_t event_mask_config = GPIO_IRQ_EDGE_FALL | GPIO_IRQ_EDGE_RISE);
198
204
209 virtual void rtos_process_IRQ_event();
210};
bool active_lo
his indicates that when the switch is pushed, a logical LO (0) signal is read.
Definition rtos_switch_button.h:168
uint gpio
the GPIO that reads the logical state of the switch (pushed or released)
Definition rtos_switch_button.h:165
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:149
QueueHandle_t IRQdata_input_queue
the queue from which IRQ data are received
Definition rtos_switch_button.h:185
uint32_t irq_event_mask_config
A memory slot reserved to store the irq_event_mask.
Definition rtos_switch_button.h:132
uint debounce_delay_us
The time during which all changes in the switch state is ignored.
Definition rtos_switch_button.h:146
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: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:98
virtual void rtos_process_IRQ_event()
Process IRQ event and sent the resulting event to the event queue.
Definition rtos_switch_button.cpp:36
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:178
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:155
~rtos_SwitchButton()
Destroy the SwitchButton object.
Definition rtos_switch_button.cpp:32
QueueHandle_t control_event_queue
the queue to which the resulting control event is sent
Definition rtos_switch_button.h:181
rtos_SwitchButton(uint gpio, gpio_irq_callback_t call_back, QueueHandle_t control_event_destination_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:171
bool previous_switch_pushed_state
The previous state read during the previous period.
Definition rtos_switch_button.h:174
#define DEBOUNCE_us
the default value for debounce_delay_us
Definition rtos_switch_button.h:60
#define LONG_PUSH_DELAY_ms
the default value for LONG_PUSH_DELAY_us
Definition rtos_switch_button.h:64
#define LONG_RELEASE_DELAY_us
the default value for LONG_RELEASE_DELAY_us
Definition rtos_switch_button.h:62
#define TIME_OUT_DELAY_ms
the default value for TIME_OUT_DELAY_us
Definition rtos_switch_button.h:66
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 send irq data though the queue
Definition rtos_switch_button.h:52
uint32_t current_time_us
the current time at wich the IRQ occurred
Definition rtos_switch_button.h:54
uint32_t event_mask
the IRQ mask given by the IRQ harware
Definition rtos_switch_button.h:56
These are the values used to configure a switch button delays related to action of the button (and ge...
Definition rtos_switch_button.h:79
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:99
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:89
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:93
uint debounce_delay_us
The time during which all changes in the switch state is ignored.
Definition rtos_switch_button.h:84
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:104