29 uint32_t detectionThreshold,
34 callbacks.insert({pin, PinEntry{
38 .threshold = detectionThreshold,
48 .lastState = pin.value() != reverted,
58 scheduler.
addTask([
this, pin] { periodicPinValueCheck(pin); },
73 auto pinEntry = callbacks.find(pin);
74 if (pinEntry == callbacks.end())
77 return pinEntry->second.data;
82 auto pinEntry = callbacks.find(pin);
83 if (pinEntry == callbacks.end())
86 pinEntry->second.data.changesCount = 0;
89void PinObserver::periodicPinValueCheck(miosix::GpioPin pin)
91 auto pinEntry = callbacks.find(pin);
94 if (pinEntry == callbacks.end())
98 auto& pinConfig = pinEntry->second.config;
99 auto& pinData = pinEntry->second.data;
100 auto& count = pinData.periodCount;
103 const bool newState = pin.value() != pinConfig.reverted;
106 if (pinData.lastState != newState)
113 if (count >= pinConfig.threshold)
116 pinData.changesCount++;
119 pinData.lastStateChangeTs = Clock::now();
120 pinData.lastState = newState;
133 pinData.lastTransitionTs = Clock::now();
std::function< void(PinTransition transition, const PinData &data)> PinCallback
Callback function type for pin transitions.
Clock::time_point TimePoint
void resetPinChangesCount(miosix::GpioPin pin)
Resets the changes counter for the specified pin.
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.
@ RECOVER
Prioritize the number of executions over the period.
size_t addTask(function_t function, uint32_t periodMs, Policy policy=Policy::RECOVER, int64_t startTick=Kernel::getOldTick())
Add a millisecond-period task function to the scheduler with an auto generated ID.
Driver for the VN100S IMU.
PinTransition
Pin transition.
@ FALLING_EDGE
The pin goes from high to low.
@ RISING_EDGE
The pin goes from low to high.
PinObserver::PinCallback callback
The callback function.