1#ifndef _OPENLCB_SERVOCONSUMER_HXX_
2#define _OPENLCB_SERVOCONSUMER_HXX_
4#if defined(ARDUINO) || defined(ESP_PLATFORM)
5#include "freertos_drivers/arduino/DummyGPIO.hxx"
6#include "freertos_drivers/arduino/PWM.hxx"
11#include "openlcb/ServoConsumerConfig.hxx"
25 const uint32_t pwmCountPerMs,
PWM *pwm)
41 const EventId cfg_event_min =
cfg_.event_rotate_min().read(fd);
42 const EventId cfg_event_max =
cfg_.event_rotate_max().read(fd);
43 const int16_t cfg_servo_min_pct =
cfg_.servo_min_percent().read(fd);
44 const int16_t cfg_servo_max_pct =
cfg_.servo_max_percent().read(fd);
52 const uint32_t cfg_srv_ticks_min =
53 ((100 - cfg_servo_min_pct) * servo_ticks_0 +
54 cfg_servo_min_pct * servo_ticks_180) /
56 const uint32_t cfg_srv_ticks_max =
57 ((100 - cfg_servo_max_pct) * servo_ticks_0 +
58 cfg_servo_max_pct * servo_ticks_180) /
66 cfg_event_max != gpioImpl_.
event_on() ||
67 cfg_srv_ticks_min !=
pwmGpo_->get_off_counts() ||
68 cfg_srv_ticks_max !=
pwmGpo_->get_on_counts())
70 auto saved_node = gpioImpl_.
node();
78 pwmGpo_->write(was_set ? Gpio::SET : Gpio::CLR);
81 saved_node, cfg_event_min, cfg_event_max,
pwmGpo_.get());
92 cfg_.description().write(fd,
"");
110 const ServoConsumerConfig
cfg_;
#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.
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.
Implementation of ConfigUpdateListener that registers itself in the constructor and unregisters itsel...
General Purpose Output specialization of a PWM Bit.
Abstract interface for a PWM driver.
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.
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.
Basically a specialized ConfiguredConsumer.
const uint32_t pwmCountPerMs_
Used to compute PWM ticks for max/min servo rotation.
std::unique_ptr< PWMGPO > pwmGpo_
all the rest are owned and must be reset on config change.
PWM * pwm_
timer channel. not owned; lives forever
void factory_reset(int fd) OVERRIDE
Clears configuration file and resets the configuration settings to factory value.
BitEventConsumer consumer_
has on/off events, Node*, and Gpio*
UpdateAction apply_configuration(int fd, bool initial_load, BarrierNotifiable *done) OVERRIDE
Notifies the component that there is new configuration available for loading.
const ServoConsumerConfig cfg_
has GPIOBit*
#define OVERRIDE
Function attribute for virtual functions declaring that this funciton is overriding a funciton that s...
GPIO Pin definition structure with no actual pin behind it.