Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
PolledProducer.hxx
Go to the documentation of this file.
1
35#ifndef _OPENLCB_POLLEDPRODUCER_HXX_
36#define _OPENLCB_POLLEDPRODUCER_HXX_
37
40
41namespace openlcb {
42
47template <class Debouncer, class BaseBit>
48class PolledProducer : public BaseBit, public Polling
49{
50public:
51 template <typename... Fields>
52 PolledProducer(const typename Debouncer::Options &debounce_args,
53 Fields... bit_args)
54 : BaseBit(bit_args...)
55 , debouncer_(debounce_args)
56 , producer_(this)
57 {
58 debouncer_.initialize(BaseBit::get_current_state() == EventState::VALID);
59 }
60
61 EventState get_current_state() OVERRIDE
62 {
63 return debouncer_.current_state() ? EventState::VALID : EventState::INVALID;
64 }
65
66 void set_state(bool new_value) OVERRIDE
67 {
68 debouncer_.override(new_value);
69 }
70
72 {
73 if (debouncer_.update_state(BaseBit::get_current_state() == EventState::VALID))
74 {
75 producer_.SendEventReport(helper, done);
76 }
77 else
78 {
79 done->notify();
80 }
81 }
82
83private:
84 Debouncer debouncer_;
85 BitEventProducer producer_;
86};
87
88} // namespace openlcb
89
90#endif // _OPENLCB_POLLEDPRODUCER_HXX_
An object that can schedule itself on an executor to run.
void SendEventReport(WriteHelper *writer, Notifiable *done)
Requests the event associated with the current value of the bit to be produced (unconditionally): sen...
Event handler for a single-bit producer, e.g.
Producer class for GPIO bits.
void poll_33hz(WriteHelper *helper, Notifiable *done) OVERRIDE
This function will be called approximately 33 times per second by the refresh loop.
Abstract base class for components that need repeated execution (with a specified frequency,...
A statically allocated buffer for sending one message to the OpenLCB bus.
#define OVERRIDE
Function attribute for virtual functions declaring that this funciton is overriding a funciton that s...
Definition macros.h:180
EventState
Allowed states of producers and consumers.