C++ DevKit
C++ set of OOP library
Loading...
Searching...
No Matches
SwitchButton Class Reference

SwitchButton status is sampled periodically by software. More...

#include <switch_button.h>

Inheritance diagram for SwitchButton:
Inheritance graph
Collaboration diagram for SwitchButton:
Collaboration graph

Public Member Functions

 SwitchButton (uint gpio, struct_ConfigSwitchButton conf={})
 Construct a new SwitchButton object.
 
 ~SwitchButton ()
 Destroy the SwitchButton object.
 
UIControlEvent process_sample_event ()
 the periodic routine that process deboucing, push and release of the switch.
 
ButtonState get_button_status ()
 Get the button status object.
 

Protected Member Functions

bool is_switch_pushed ()
 return the status of the switch.
 

Protected Attributes

uint debounce_delay_us
 The time during which all changes in the switch state is ignored.
 
uint long_push_delay_us
 when a button is pushed more than long_push_delay_us (in microseconds) a UIControlEvent::LONG_PUSH is returned.
 
uint long_release_delay_us
 if the button is released after long_release_delay_us (in microseconds) a UIControlEvent::RELEASED_AFTER_LONG_TIME is returned, else a UIControlEvent::RELEASED_AFTER_SHORT_TIME is released.
 
uint time_out_delay_us
 if the button is released after time_out_delay_us (in microseconds) a UIControlEvent::TIME_OUT is returned,
 
uint gpio
 the GPIO that reads the logical state of the switch (pushed or released)
 
bool active_lo
 his indicates that when the switch is pushed, a logical LO (0) signal is read.
 
uint previous_change_time_us
 the system time stored on the previous switch state change.
 
bool previous_switch_pushed_state
 The previous state read during the previous period.
 
ButtonState button_status {ButtonState::IDLE}
 the logical button status, required to manage the event returned when the switch is pushed or released.
 

Detailed Description

SwitchButton status is sampled periodically by software.

  • Switch status is the status of the physical (i.e. mechanical) switch device.
  • Button status is the logical status of the button (regardless if the switch is wired active Lo or HI).

During each period, the status of the button is compared to the previous status and the function member process_sample_event() return an event accordingly.

SwitchButton can be associated with UIController if button belongs to a GUI. In such case a new class must be created that inherits from SwitchButton and UIController.

SwitchButton times references for short release
SwitchButton times references for long release

Constructor & Destructor Documentation

◆ SwitchButton()

SwitchButton::SwitchButton ( uint gpio,
struct_ConfigSwitchButton conf = {} )

Construct a new SwitchButton object.

Parameters
gpiothe microcontroller GPIO that read the switch status
confthe configuration data according struct_ConfigSwitchButton
Here is the call graph for this function:
Here is the caller graph for this function:

Member Function Documentation

◆ get_button_status()

ButtonState SwitchButton::get_button_status ( )

Get the button status object.

Returns
ButtonState

◆ is_switch_pushed()

bool SwitchButton::is_switch_pushed ( )
protected

return the status of the switch.

Returns
true if switch status is read LO (resp. HI) if active_lo is true (resp. false)
false if switch status is read HI (resp. LO) if active_lo is true (resp. false)
Here is the caller graph for this function:

◆ process_sample_event()

UIControlEvent SwitchButton::process_sample_event ( )

the periodic routine that process deboucing, push and release of the switch.

Returns
UIControlEvent
Here is the call graph for this function:

The documentation for this class was generated from the following files: