Plaquette
 
Loading...
Searching...
No Matches
pq::DigitalIn Class Reference

A generic class representing a simple digital input. More...

#include <PqInputs.h>

Inheritance diagram for pq::DigitalIn:
Collaboration diagram for pq::DigitalIn:

Public Member Functions

 DigitalIn (uint8_t pin, Engine &engine=Engine::primary())
 Constructor.
 
 DigitalIn (uint8_t pin, uint8_t mode, Engine &engine=Engine::primary())
 
virtual void mode (uint8_t mode)
 Changes the mode of the component.
 
float read () const
 Directly reads value from the pin as 1 or 0 (bypasses mode, debounce, and engine).
 
int rawRead () const
 Directly reads raw value from the pin as HIGH or LOW (bypasses mode, debounce, and engine).
 
virtual bool isOn ()
 Returns true iff the input is "on".
 
virtual bool putOn (bool value)
 Pushes value into the unit.
 
virtual bool rose ()
 Returns true if the value rose.
 
virtual bool fell ()
 Returns true if the value fell.
 
virtual bool changed ()
 Returns true if the value changed.
 
virtual bool toggle ()
 Switches between on and off.
 
virtual int8_t changeState ()
 Difference between current and previous value of the unit.
 
virtual void onRise (EventCallback callback)
 Registers event callback on rise event.
 
virtual void onFall (EventCallback callback)
 Registers event callback on fall event.
 
virtual void onChange (EventCallback callback)
 Registers event callback on change event.
 
virtual bool isOff ()
 Returns true iff the input is "off".
 
virtual int getInt ()
 Returns value as integer (0 or 1).
 
virtual float get ()
 Returns value as float (either 0.0 or 1.0).
 
virtual bool on ()
 Sets output to "on" (ie. true, 1).
 
virtual bool off ()
 Sets output to "off" (ie. false, 0).
 
virtual float put (float value)
 Pushes value into the unit.
 
virtual float mapTo (float toLow, float toHigh)
 Maps value to new range.
 
 operator bool ()
 Operator that allows usage in conditional expressions.
 
 operator float ()
 
virtual void clearEvents ()
 
float seconds () const
 Returns engine time in seconds.
 
uint32_t milliSeconds () const
 Returns engine time in milliseconds.
 
uint64_t microSeconds () const
 Returns engine time in microseconds.
 
unsigned long nSteps () const
 Returns number of engine steps.
 
float sampleRate () const
 Returns engine sample rate.
 
float samplePeriod () const
 Returns enginesample period.
 
uint8_t pin () const
 Returns the pin this component is attached to.
 
uint8_t mode () const
 Returns the mode of the component.
 
virtual void debounce (float debounceTime=PLAQUETTE_DEFAULT_DEBOUNCE_WINDOW)
 Apply smoothing to object.
 
virtual void noDebounce ()
 Remove smoothing.
 
virtual void smooth (float smoothTime=PLAQUETTE_DEFAULT_DEBOUNCE_WINDOW)
 Deprecated. Left for backwards compatibility.
 
virtual void noSmooth ()
 Remove smoothing.
 
virtual void timeWindow (float seconds)
 Changes the debouncing window (expressed in seconds).
 
float timeWindow () const
 Returns the debouncing window (expressed in seconds).
 
uint8_t debounceMode () const
 Returns the debounce mode.
 
void debounceMode (uint8_t mode)
 Sets debounce mode.
 

Static Public Member Functions

static bool analogToDigital (float f)
 Converts analog (float) value to digital (bool) value.
 
static float digitalToAnalog (bool b)
 Converts digital (bool) value to analog (float) value.
 

Protected Member Functions

virtual bool _isOn ()
 
virtual float _time () const
 
virtual void _init ()
 
virtual void begin ()
 
virtual void step ()
 
void _updateChangeState ()
 
virtual bool eventTriggered (EventType eventType)
 Returns true iff an event of a certain type has been triggered.
 
virtual void onEvent (EventCallback callback, EventType eventType)
 Registers event callback.
 
Engineengine () const
 Returns the engine that owns this unit.
 
virtual void _begin ()
 
virtual void _step ()
 
virtual bool _debounced ()
 
void _changeState ()
 
void _setStateFlag (const uint8_t flag)
 
void _unsetStateFlag (const uint8_t flag)
 
void _toggleStateFlag (const uint8_t flag)
 
bool _getStateFlag (const uint8_t flag)
 

Protected Attributes

bool _onValue: 1
 
bool _prevOnValue: 1
 
int8_t _changeState: 2
 
uint8_t _data: 4
 
uint8_t _pin
 
uint8_t _mode
 
float _interval
 
float _startTime
 
uint8_t _state
 
uint8_t _debounceMode
 

Detailed Description

A generic class representing a simple digital input.

Constructor & Destructor Documentation

◆ DigitalIn()

pq::DigitalIn::DigitalIn ( uint8_t  pin,
Engine engine = Engine::primary() 
)

Constructor.

Parameters
pinthe pin number
modethe mode (DIRECT, INVERTED, or INTERNAL_PULLUP)

Member Function Documentation

◆ _isOn()

bool pq::DigitalIn::_isOn ( )
protectedvirtual

Implements pq::Debounceable.

◆ _time()

virtual float pq::DigitalIn::_time ( ) const
inlineprotectedvirtual

Implements pq::Debounceable.

◆ begin()

void pq::DigitalIn::begin ( )
protectedvirtual

Reimplemented from pq::Unit.

◆ debounceMode()

void pq::Debounceable::debounceMode ( uint8_t  mode)
inlineinherited

Sets debounce mode.

Parameters
modethe debounce mode (DEBOUNCE_DEFAULT, DEBOUNCE_LOCK_OUT or DEBOUNCE_PROMPT_DETECT)

◆ eventTriggered()

virtual bool pq::DigitalSource::eventTriggered ( EventType  eventType)
inlineprotectedvirtualinherited

Returns true iff an event of a certain type has been triggered.

Reimplemented from pq::Unit.

Reimplemented in pq::Alarm.

◆ get()

virtual float pq::DigitalUnit::get ( )
inlinevirtualinherited

Returns value as float (either 0.0 or 1.0).

Reimplemented from pq::Chainable.

◆ isOn()

virtual bool pq::DigitalSource::isOn ( )
inlinevirtualinherited

Returns true iff the input is "on".

Reimplemented from pq::DigitalUnit.

◆ mapTo()

virtual float pq::DigitalUnit::mapTo ( float  toLow,
float  toHigh 
)
inlinevirtualinherited

Maps value to new range.

Reimplemented from pq::Chainable.

◆ mode()

void pq::DigitalIn::mode ( uint8_t  mode)
virtual

Changes the mode of the component.

Reimplemented from pq::PinConfig.

◆ put()

virtual float pq::DigitalUnit::put ( float  value)
inlinevirtualinherited

Pushes value into the unit.

Parameters
valuethe value sent to the unit
Returns
the new value of the unit

Reimplemented from pq::Chainable.

Reimplemented in pq::PeakDetector.

◆ putOn()

virtual bool pq::DigitalSource::putOn ( bool  value)
inlinevirtualinherited

Pushes value into the unit.

Parameters
valuethe value sent to the unit
Returns
the new value of the unit

Reimplemented from pq::DigitalUnit.

◆ step()

void pq::DigitalIn::step ( )
protectedvirtual

Reimplemented from pq::Unit.


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