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

Emits a "bang" signal when another signal peaks. More...

#include <PeakDetector.h>

Inheritance diagram for pq::PeakDetector:
Collaboration diagram for pq::PeakDetector:

Public Member Functions

 PeakDetector (float triggerThreshold, Engine &engine=Engine::primary())
 Constructor with default mode (PEAK_MAX).
 
 PeakDetector (float triggerThreshold, uint8_t mode, Engine &engine=Engine::primary())
 Constructor.
 
void triggerThreshold (float triggerThreshold)
 Sets triggerThreshold.
 
float triggerThreshold () const
 Returns triggerThreshold.
 
void reloadThreshold (float reloadThreshold)
 Sets minimal threshold that "resets" peak detection in crossing (rising/falling) and peak (min/max) modes.
 
float reloadThreshold () const
 Returns minimal value "drop" for reset.
 
void fallbackTolerance (float fallbackTolerance)
 Sets minimal relative "drop" after peak to trigger detection in peak (min/max) modes, expressed as proportion (%) of peak minus triggerThreshold.
 
float fallbackTolerance () const
 Returns minimal relative "drop" after peak to trigger detection in peak modes.
 
bool modeInverted () const
 Returns true if mode is PEAK_FALLING or PEAK_MIN.
 
bool modeCrossing () const
 Returns true if mode is PEAK_RISING or PEAK_FALLING.
 
bool modeApex () const
 Returns true if mode is PEAK_MAX or PEAK_MIN.
 
void mode (uint8_t mode)
 Sets mode.
 
uint8_t mode () const
 Returns mode.
 
virtual float put (float value)
 Pushes value into the unit.
 
virtual bool isOn ()
 Returns true iff the triggerThreshold is crossed.
 
virtual void onBang (EventCallback callback)
 Registers event callback on peak detection.
 
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 bool putOn (bool 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.
 

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

void _reset ()
 
virtual bool eventTriggered (EventType eventType)
 Returns true iff an event of a certain type has been triggered.
 
virtual void begin ()
 
virtual void step ()
 
virtual void onEvent (EventCallback callback, EventType eventType)
 Registers event callback.
 
Engineengine () const
 Returns the engine that owns this unit.
 

Protected Attributes

float _triggerThreshold
 
float _reloadThreshold
 
float _fallbackTolerance
 
float _peakValue
 
bool _onValue: 1
 
uint8_t _mode: 2
 
bool _isHigh: 1
 
bool _wasLow: 1
 
bool _crossed: 1
 
bool _firstRun: 1
 
uint8_t _data: 1
 

Detailed Description

Emits a "bang" signal when another signal peaks.

Constructor & Destructor Documentation

◆ PeakDetector() [1/2]

pq::PeakDetector::PeakDetector ( float  triggerThreshold,
Engine engine = Engine::primary() 
)

Constructor with default mode (PEAK_MAX).

Parameters
triggerThresholdvalue that triggers peak detection
enginethe engine running this unit

◆ PeakDetector() [2/2]

pq::PeakDetector::PeakDetector ( float  triggerThreshold,
uint8_t  mode,
Engine engine = Engine::primary() 
)

Constructor.

Possible modes are:

  • PEAK_RISING : peak detected when value becomes >= triggerThreshold, then wait until it becomes < reloadThreshold (*)
  • PEAK_FALLING : peak detected when value becomes <= triggerThreshold, then wait until it becomes > reloadThreshold (*)
  • PEAK_MAX : peak detected after value becomes >= triggerThreshold and then falls back after peaking; then waits until it becomes < reloadThreshold (*)
  • PEAK_MIN : peak detected after value becomes <= triggerThreshold and then rises back after peaking; then waits until it becomes > reloadThreshold (*)
    Parameters
    triggerThresholdvalue that triggers peak detection
    modepeak detection mode
    enginethe engine running this unit

Member Function Documentation

◆ eventTriggered()

bool pq::PeakDetector::eventTriggered ( EventType  eventType)
protectedvirtual

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

Reimplemented from pq::Unit.

◆ 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::PeakDetector::isOn ( )
inlinevirtual

Returns true iff the triggerThreshold is crossed.

Reimplemented from pq::DigitalUnit.

◆ mapTo()

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

Maps value to new range.

Reimplemented from pq::Chainable.

◆ put()

float pq::PeakDetector::put ( float  value)
virtual

Pushes value into the unit.

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

Reimplemented from pq::DigitalUnit.

◆ putOn()

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

Pushes value into the unit.

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

Reimplemented in pq::DigitalSource.


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