Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
CpuDisplay.hxx
Go to the documentation of this file.
1
34#ifndef _UTILS_CPUDISPLAY_HXX_
35#define _UTILS_CPUDISPLAY_HXX_
36
39
46{
47public:
53 CpuDisplay(Service *s, const Gpio *red, const Gpio *green)
54 : StateFlowBase(s)
55 , timer_(this)
56 , red_(red)
57 , green_(green)
58 {
60 }
61
67
70 {
71 uint8_t load = CpuLoad::instance()->get_load();
72 if (load < 20)
73 {
74 green_->set();
75 red_->clr();
76 }
77 else if (load < 75)
78 {
79 green_->set();
80 red_->set();
81 }
82 else
83 {
84 green_->clr();
85 red_->set();
86 }
88 }
89
90private:
94 const Gpio *red_;
96 const Gpio *green_;
97};
98
99#endif // _UTILS_CPUDISPLAY_HXX_
#define STATE(_fn)
Turns a function name into an argument to be supplied to functions expecting a state.
Definition StateFlow.hxx:61
Displays the current CPU load on a bicolor LED (red + green) by showing green when CPU load is light,...
Action update_display()
Update the display.
StateFlowTimer timer_
Helper struct for timer state.
const Gpio * green_
Green LED for display.
const Gpio * red_
Red LED for display.
CpuDisplay(Service *s, const Gpio *red, const Gpio *green)
Constructor.
Action delay()
Wait for updating the display.
OS-independent abstraction for GPIO.
Definition Gpio.hxx:43
virtual void clr() const =0
Clears the GPIO output pin to low.
virtual void set() const =0
Sets the GPIO output pin to high.
Collection of related state machines that pend on incoming messages.
Return type for a state flow callback.
Use this timer class to deliver the timeout notification to a stateflow.
Base class for state machines.
void start_flow(Callback c)
Resets the flow to the specified state and starts it.
Action call_immediately(Callback c)
Imediately call the next state upon return.
Action sleep_and_call(::Timer *timer, long long timeout_nsec, Callback c)
Suspends execution of this control flow for a specified time.
#define MSEC_TO_NSEC(_msec)
Convert a millisecond value to a nanosecond value.
Definition os.h:268