36#ifndef _OPENLCB_CONFIGUREDCONSUMER_HXX_
37#define _OPENLCB_CONFIGUREDCONSUMER_HXX_
52 Name(
"Description"), Description(
"User name of this output."));
57 Description(
"Receiving this event ID will turn the output on."));
62 Description(
"Receiving this event ID will turn the output off."));
69 Name(
"Description"), Description(
"User name of this output."));
75 "Receiving this event ID will generate a pulse on the output."));
79 Name(
"Pulse duration"),
80 Description(
"Length of the pulse to output (unit of 30 msec)."));
93 : impl_(node, 0, 0, gpio)
101 ConfiguredConsumer(
Node *node,
const ConsumerConfig &cfg,
const HW &,
const Gpio* g = HW::instance(),
decltype(HW::instance)* = 0)
102 : impl_(node, 0, 0, g)
113 EventId cfg_event_on = cfg_.event_on().read(fd);
114 EventId cfg_event_off = cfg_.event_off().read(fd);
115 if (cfg_event_off != impl_.
event_off() ||
118 auto saved_gpio = impl_.gpio_;
119 auto saved_node = impl_.
node();
122 consumer_.~BitEventConsumer();
125 Impl(saved_node, cfg_event_on, cfg_event_off, saved_gpio);
134 cfg_.description().write(fd,
"");
140 const ConsumerConfig cfg_;
154 const HW &,
const Gpio* g = HW::instance())
181 EventId cfg_event_on = cfg_.event().read(fd);
182 pulseLength_ = cfg_.duration().read(fd);
183 if (cfg_event_on == event_)
189 event_ = cfg_event_on;
196 cfg_.description().write(fd,
"");
221 if (event->dst_node && event->dst_node != node_)
223 return done->notify();
225 SendConsumerIdentified(event, done);
231 if (!pulseRemaining_)
235 event->event_write_helper<3>()->WriteAsync(
242 if (event->
event != event_)
246 SendConsumerIdentified(event, done);
252 if (event->
event == event_)
254 pulseRemaining_ = pulseLength_;
262 if (pulseRemaining_ > 0)
277 const PulseConsumerConfig cfg_;
278 uint8_t pulseLength_{1};
279 uint8_t pulseRemaining_{0};
#define CDI_GROUP(GroupName, ARGS...)
Starts a CDI group.
#define CDI_GROUP_ENTRY(NAME, TYPE, ARGS...)
Adds an entry to a CDI group.
#define CDI_FACTORY_RESET(PATH)
Performs factory reset on a CDI variable.
This class sends a notification in its destructor.
A BarrierNotifiable allows to create a number of child Notifiable and wait for all of them to finish.
void notify() override
Implementation of the barrier semantics.
Abstract class for components that need to receive configuration from EEPROM.
UpdateAction
Specifies what additional steps are needed to apply the new configuration.
@ REINIT_NEEDED
Need to perform application-level reinitialization.
@ UPDATED
No additional step is necessary.
virtual void register_update_listener(ConfigUpdateListener *listener)=0
Adds a config update listener to be called upon configuration updates.
virtual void unregister_update_listener(ConfigUpdateListener *listener)=0
Removes a config update listener.
OS-independent abstraction for GPIO.
virtual void clr() const =0
Clears the GPIO output pin to low.
virtual void set() const =0
Sets the GPIO output pin to high.
An object that can schedule itself on an executor to run.
static ConfigUpdateService * instance()
Event handler for a single-bit consumer, e.g.
uint64_t event_on()
returns the event ID for representing the state transition OFF->ON.
uint64_t event_off()
returns the event ID for representing the state transition ON->OFF.
Implementation class for event ID configuration entries.
Structure used in registering event handlers.
Simple implementation of the BitEventInterface for going through GPIO ports.
Node * node() OVERRIDE
returns the OpenLCB virtual node from which to send the respective events when the bit changes.
Base class for NMRAnet nodes conforming to the asynchronous interface.
Implementation class for numeric configuration entries, templated by the integer type.
Abstract base class for components that need repeated execution (with a specified frequency,...
SimpleEventHandler ignores all non-essential callbacks.
Implementation class for string configuration entries.
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...
CDI_GROUP_END()
Signals termination of the group.
Payload eventid_to_buffer(uint64_t eventid)
Converts an Event ID to a Payload suitable to be sent as an event report.
MTI
Known Message type indicators.
@ MTI_CONSUMER_IDENTIFIED_VALID
consumer broadcast, valid state
Shared notification structure that is assembled for each incoming event-related message,...
EventId event
The event ID from the incoming message.