Skyward boardcore
Loading...
Searching...
No Matches
Boardcore::PinObserver Class Reference

#include <PinObserver.h>

Classes

struct  PinConfig
 Pin configuration. More...
 
struct  PinData
 Pin information. More...
 

Public Types

using Clock = std::chrono::steady_clock
 
using TimePoint = Clock::time_point
 
using PinCallback = std::function< void(PinTransition transition, const PinData &data)>
 Callback function type for pin transitions.
 

Public Member Functions

 PinObserver (TaskScheduler &scheduler, uint32_t pollInterval=20)
 Construct a new PinObserver object.
 
bool registerPinCallback (miosix::GpioPin pin, PinCallback callback, uint32_t detectionThreshold=1, bool reverted=false)
 
PinData getPinData (miosix::GpioPin pin)
 Returns the information for the specified pin.
 
void resetPinChangesCount (miosix::GpioPin pin)
 Resets the changes counter for the specified pin.
 

Detailed Description

Class used to call a callback after a pin performs a specific transition (RISING or FALLING edge) and stays in the new state for a specific amount of time. Useful if you want to monitor pin transitions but you want to avoid spurious state changes.

A callback to monitor each state change no matter the threshold or the transition is also available, in order to be able to observe the current state of the pin.

Definition at line 54 of file PinObserver.h.

Member Typedef Documentation

◆ Clock

using Boardcore::PinObserver::Clock = std::chrono::steady_clock

Definition at line 57 of file PinObserver.h.

◆ PinCallback

using Boardcore::PinObserver::PinCallback = std::function<void(PinTransition transition, const PinData& data)>

Callback function type for pin transitions.

Parameters
transitionThe type of transition that triggered the callback.
dataThe data associated with the pin, updated with the latest transition information.

Definition at line 88 of file PinObserver.h.

◆ TimePoint

using Boardcore::PinObserver::TimePoint = Clock::time_point

Definition at line 58 of file PinObserver.h.

Constructor & Destructor Documentation

◆ PinObserver()

Boardcore::PinObserver::PinObserver ( TaskScheduler scheduler,
uint32_t  pollInterval = 20 
)
inline

Construct a new PinObserver object.

Parameters
schedulerScheduler to be used by this PinObserver.
pollIntervalPin transition polling interval, defaults to 20 [ms].

Definition at line 107 of file PinObserver.h.

Member Function Documentation

◆ getPinData()

PinData Boardcore::PinObserver::getPinData ( miosix::GpioPin  pin)

Returns the information for the specified pin.

Definition at line 71 of file PinObserver.cpp.

◆ registerPinCallback()

bool Boardcore::PinObserver::registerPinCallback ( miosix::GpioPin  pin,
PinCallback  callback,
uint32_t  detectionThreshold = 1,
bool  reverted = false 
)

Observe a pin for a specific transition, and optionally for every single state change. The callback receives the transition and the time point when the transition happened as parameters.

Parameters
pinPin to listen to.
callbackFunction to call on pin events.
detectionThresholdHow many times the pin should be observed in the post-transition state to trigger the actual transition callback, defaults to 1.
Returns
False if another callback was already registered for the pin.

Definition at line 28 of file PinObserver.cpp.

◆ resetPinChangesCount()

void Boardcore::PinObserver::resetPinChangesCount ( miosix::GpioPin  pin)

Resets the changes counter for the specified pin.

Definition at line 80 of file PinObserver.cpp.


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