Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
ActivityLed.hxx
Go to the documentation of this file.
1
35#ifndef _UTILS_ACTIVITYLED_HXX_
36#define _UTILS_ACTIVITYLED_HXX_
37
39#include "os/Gpio.hxx"
40
45class ActivityLed : private ::Timer
46{
47public:
54 Service *service, const Gpio *pin, long long period = MSEC_TO_NSEC(33))
55 : ::Timer(service->executor()->active_timers())
56 , gpio_(pin)
57 {
58 start(period);
59 }
60
62 void activity()
63 {
65 }
66
67private:
68 long long timeout() override
69 {
70 if (triggerCount_)
71 {
72 gpio_->write(true);
73 triggerCount_ = 0;
74 }
75 else
76 {
77 gpio_->write(false);
78 }
79 return RESTART;
80 }
81
83 const Gpio *gpio_;
85 unsigned triggerCount_ {0};
86};
87
88#endif // _UTILS_ACTIVITYLED_HXX_
Operates an LED to visually display some activity.
const Gpio * gpio_
Output pin to blink for activity.
ActivityLed(Service *service, const Gpio *pin, long long period=MSEC_TO_NSEC(33))
Constructor.
long long timeout() override
Clients of timer should override this function.
void activity()
Call this function when activity happens.
unsigned triggerCount_
How many triggers happened since the last run of the timer.
OS-independent abstraction for GPIO.
Definition Gpio.hxx:43
virtual void write(Value new_state) const =0
Writes a GPIO output pin (set or clear to a specific state).
Collection of related state machines that pend on incoming messages.
A timer that can schedule itself to run on an executor at specified times in the future.
Definition Timer.hxx:134
@ RESTART
Restart the timer with existing period.
Definition Timer.hxx:162
void start(long long period=-1)
Starts a timer.
Definition Timer.hxx:185
#define MSEC_TO_NSEC(_msec)
Convert a millisecond value to a nanosecond value.
Definition os.h:268