Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
CountingDebouncer Class Reference

This debouncer will count the ON values and if the number of ON values in a given window exceeds a threshold, then triggers. More...

#include <Debouncer.hxx>

Classes

struct  Options
 Static parameters for the CountingDebouncer. More...
 

Public Member Functions

 CountingDebouncer (const Options &opts)
 Constructor.
 
void reset_options (const Options &opts)
 Re-creates the debouncer with new options.
 
const Optionsoptions ()
 Retrieves the currently set options.
 
void initialize (bool state)
 Initilalize the debouncer.
 
void override (bool new_state)
 Overrides the debounced state to a given value, irrespective of what is on the input pin.
 
bool current_state ()
 
bool update_state (bool state)
 Callback from the polling loop checking the input state.
 

Private Member Functions

void trim_options ()
 

Private Attributes

uint32_t window_ {0}
 bit-map of last observations. bit 0 is latest.
 
Options opts_
 options
 
unsigned lastCount_: 6
 how many 1 bits we have in the window
 
unsigned currentState_: 1
 last known state
 

Detailed Description

This debouncer will count the ON values and if the number of ON values in a given window exceeds a threshold, then triggers.

Todo:
: there should really be a hysteresis.

Definition at line 142 of file Debouncer.hxx.

Constructor & Destructor Documentation

◆ CountingDebouncer()

CountingDebouncer::CountingDebouncer ( const Options opts)
inline

Constructor.

Parameters
optsspecified the debouncing options.

Definition at line 157 of file Debouncer.hxx.

Member Function Documentation

◆ current_state()

bool CountingDebouncer::current_state ( )
inline
Returns
the current debounced state.

Definition at line 204 of file Debouncer.hxx.

◆ initialize()

void CountingDebouncer::initialize ( bool  state)
inline

Initilalize the debouncer.

Parameters
stateis the current input state at initialization time, which will be taken over as is (without debouncing because we don't have any information based on which to debounce).

Definition at line 183 of file Debouncer.hxx.

◆ options()

const Options & CountingDebouncer::options ( )
inline

Retrieves the currently set options.

Definition at line 175 of file Debouncer.hxx.

◆ override()

void CountingDebouncer::override ( bool  new_state)
inline

Overrides the debounced state to a given value, irrespective of what is on the input pin.

Parameters
new_stateis the desired state.

Definition at line 198 of file Debouncer.hxx.

◆ reset_options()

void CountingDebouncer::reset_options ( const Options opts)
inline

Re-creates the debouncer with new options.

Parameters
optsnew options.

Definition at line 167 of file Debouncer.hxx.

◆ trim_options()

void CountingDebouncer::trim_options ( )
inlineprivate

Definition at line 234 of file Debouncer.hxx.

◆ update_state()

bool CountingDebouncer::update_state ( bool  state)
inline

Callback from the polling loop checking the input state.

Parameters
stateis the currently observed input state.
Returns
true if the debounced state has just transitioned to matching the inbound parameter, false if the debounced state has not changed (i.e. not yet matching the current observed state or already previously matching the observed state).

Definition at line 214 of file Debouncer.hxx.

Member Data Documentation

◆ currentState_

unsigned CountingDebouncer::currentState_
private

last known state

Definition at line 257 of file Debouncer.hxx.

◆ lastCount_

unsigned CountingDebouncer::lastCount_
private

how many 1 bits we have in the window

Definition at line 256 of file Debouncer.hxx.

◆ opts_

Options CountingDebouncer::opts_
private

options

Definition at line 255 of file Debouncer.hxx.

◆ window_

uint32_t CountingDebouncer::window_ {0}
private

bit-map of last observations. bit 0 is latest.

Definition at line 254 of file Debouncer.hxx.


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