|
LCC Fusion Project 1.0
LCC Automation
|
Version of the SensorConfiguredProducer that can handle many GPIO sensor pins with two events each. More...
#include <SensorConfiguredProducer.h>


Public Types | |
| typedef ButtonCardConfig | ButtonCardConfig_type |
| typedef SensorCardConfig | SensorCardConfig_type |
| typedef BodCardConfig | BodCardConfig_type |
| typedef PodCardConfig | PodCardConfig_type |
Public Member Functions | |
| template<unsigned NUM_CARDS> | |
| SensorConfiguredProducer (openlcb::Node *pNode, const openlcb::RepeatedGroup< ButtonCardConfig_type, NUM_CARDS > &configOffset, uint8_t numDevicesPerCard, EventDeviceTypes eventDeviceType, const char *cardDescription) __attribute__((noinline)) | |
| constructor More... | |
| bool | processPinState (int cardIndex, int pinIndex) |
| Polls the state of pins on sensor cards and triggers events on state changes. More... | |
| void | factory_reset (int fd) OVERRIDE |
| bool | ensureUniqueI2cOffset (uint8_t cardIndex, uint8_t bus, uint8_t offset) |
Public Attributes | |
| union I2cCardHelper::EventUserArgsUnion | userArgs |
Protected Member Functions | |
| void | _do_unregister () |
| Unregisters this event handler from the global registry. | |
| void | handle_identify_consumer (const openlcb::EventRegistryEntry ®istry_entry, openlcb::EventReport *event, BarrierNotifiable *done) OVERRIDE |
| Process request to identify produced events. | |
| void | handle_identify_producer (const openlcb::EventRegistryEntry ®istry_entry, openlcb::EventReport *event, BarrierNotifiable *done) OVERRIDE |
| Process request to identify produced events. | |
| virtual void | SendEventIdentified (const openlcb::EventRegistryEntry ®istry_entry, openlcb::EventReport *event, BarrierNotifiable *done) |
Sends Producer- or Consumer-Identified for registry_entry. More... | |
| void | applyI2cInfo (int fd, uint8_t cardIndex, i2cInfoConfig_type cfgI2cInfoRef) |
| sets up the MCP card's I2C connection using the user provided (CDI) configuration information (bus and address offset) More... | |
| void | resetCardInfo (int fd, cardInfoConfig_type cfgI2cInfoRef) |
| resets the card configuration information (description field). More... | |
| void | resetI2cInfo (int fd, i2cInfoConfig_type cfgI2cInfoRef) |
| resets the card's I2C configuration information (bus and address fields). More... | |
| virtual void | drive_pin (uint8_t card, uint8_t pin, bool set) |
| virtual void | drive_pin_ext (uint8_t card, uint8_t pin, bool set, uint8_t intArg) |
| EventUserArgsUnion | unpack_user_args (const openlcb::EventRegistryEntry &re) const |
| Small helper to unpack our 4-byte user_arg payload from the registry entry. | |
| void | handle_event_report (const openlcb::EventRegistryEntry ®istry_entry, openlcb::EventReport *event, BarrierNotifiable *done) OVERRIDE |
Private Member Functions | |
| template<typename GroupType > | |
| void | _processApplyCards (GroupType &grpCardsRef, int fd) |
| Applies the current CDI configuration for all cards and lines in a group. More... | |
| void | _checkPins (uint8_t cardIndex, uint8_t firstPin, uint8_t lastPin) |
| Sanity-checks a contiguous range of MCP23017 GPIO pins on one card and logs the results. More... | |
| template<typename GroupType > | |
| void | _processResetCards (GroupType &grpCardsRef, int fd) |
| Factory-resets CDI configuration for all sensors on all configured cards in a group. More... | |
| void | _setPowerOnState (uint8_t cardNum, uint8_t pinNum, DefaultDeviceSettings::DeviceStates state, uint8_t debounceCount) |
| Sets the power-on state for a specific pin on a specific card. More... | |
| void | _initI2cCards (bool isProducer) |
| Initializes the array of I2C card objects using the configured card type. More... | |
Private Attributes | |
| DefaultDeviceSettings | defaultDeviceSettings_ |
| Shadow copy of the event IDs produced by each of the UOD cards. | |
Version of the SensorConfiguredProducer that can handle many GPIO sensor pins with two events each.
Definition at line 112 of file SensorConfiguredProducer.h.
| typedef BodCardConfig SensorConfiguredProducer::BodCardConfig_type |
Type for the sensor card CDI configuration entry
Definition at line 117 of file SensorConfiguredProducer.h.
| typedef ButtonCardConfig SensorConfiguredProducer::ButtonCardConfig_type |
Type for the sensor card CDI configuration entry
Definition at line 115 of file SensorConfiguredProducer.h.
| typedef PodCardConfig SensorConfiguredProducer::PodCardConfig_type |
Type for the sensor card CDI configuration entry
Definition at line 118 of file SensorConfiguredProducer.h.
| typedef SensorCardConfig SensorConfiguredProducer::SensorCardConfig_type |
Type for the sensor card CDI configuration entry
Definition at line 116 of file SensorConfiguredProducer.h.
|
inline |
constructor
| pNode | OpenLCB node object from the stack |
| configOffset | repeated group object from the configuration space that represents all the events for each sensor card |
| numDevicesPerCard | number of sensors configured for each sensor card. |
| eventDeviceType | EventDeviceTypes value identify the type of device, used when setting default event ID |
| cardDescription | human-friendly card description for log messages and debug output ( e .g. "Input Card"). |
Definition at line 133 of file SensorConfiguredProducer.h.
|
inlineprivate |
Sanity-checks a contiguous range of MCP23017 GPIO pins on one card and logs the results.
Iterates pins firstPin through lastPin (inclusive) on the specified card and probes each pin's digital state via the MCP23017. For each pin, a short, human-readable status string is emitted to the Serial Monitor (e.g., "OK", "GND (Error or triggered)"), using the project’s SENSOR_TESTING_SELECTOR_INFO message key.
This helper is meant for assembly/bring-up testing when g_isTesting is enabled.
| cardIndex | Zero-based card index into I2cCardHelper::i2cCards. |
| firstPin | First MCP23017 pin to check (0–15). |
| lastPin | Last MCP23017 pin to check (0–15), inclusive. |
initI2cCardPins()). g_pSerialMonitor is non-null if log output is desired.firstPin <= lastPin. Definition at line 553 of file SensorConfiguredProducer.h.


|
inlineprivateinherited |
Initializes the array of I2C card objects using the configured card type.
Allocates and initializes each I2C card in the array to the type specified by the cardType_ member. If isProducer is true, registers each card's polling callback.
| isProducer | True if the card is used as a producer and requires polling. |
Definition at line 460 of file I2cCardHelper.h.


|
inlineprivate |
Applies the current CDI configuration for all cards and lines in a group.
Invoked on first CDI load (after reboot) and whenever CDI is updated. This routine walks each configured card in the supplied repeated group and performs the following per-card steps:
I2cCardHelper::applyI2cInfo(...) to validate offsets, check for duplicates, and (re)open the device connection.initI2cCardPins(...).defaultDeviceSettings_ with retrievePinStates(...) so subsequent logic has an accurate baseline.initialSensorState, eventOn, eventOff, and debounceCount from CDI._setPowerOnState(...) without emitting an event.producerEventIds_ for later use by notify().If testing mode (g_isTesting) is enabled, the function also probes specific MCP pins and prints human-readable diagnostics to the serial monitor to assist bring-up.
| GroupType | A CDI repeated-group type providing:
|
| grpCardsRef | Reference to the repeated group of card configurations (e.g., openlcb::RepeatedGroup<ButtonCardConfig_type, ...>). |
| fd | File descriptor used by the OpenMRN configuration backend for CDI reads/writes. |
numCards_ and numDevicesPerCard_ reflect the active CDI layout.grpCardsRef references a valid CDI segment; card indices in [0, numCards_) are present.eventOn/eventOff producer events found in CDI.initI2cCardPins() must respect the helper’s inclusive/exclusive contract.Definition at line 451 of file SensorConfiguredProducer.h.

|
inlineprivate |
Factory-resets CDI configuration for all sensors on all configured cards in a group.
Walks every card (0..numCards_-1) in grpCardsRef and:
I2cCardHelper::resetCardInfo().I2cCardHelper::resetI2cInfo().numDevicesPerCard_-1) and:CDI_FACTORY_RESET to initialSensorState and debounceCount.description() to the empty string.eventOn() / eventOff() IDs using NEXT_EVENT(nodeId, eventDeviceType_, cardIndex, I2cCardHelper::nextDefaultEvent).No events are emitted; this only updates CDI storage through fd.
| GroupType | A CDI repeated-group type providing:
|
| grpCardsRef | Reference to the card repeated group to reset (e.g., RepeatedGroup<ButtonCardConfig_type, ...> or RepeatedGroup<SensorCardConfig_type, ...>). |
| fd | File descriptor used by the OpenMRN configuration backend for reads/writes. |
pNode_ is valid; numCards_ and numDevicesPerCard_ reflect the CDI layout. GroupType instance refers to the correct CDI segment (offset is valid).I2cCardHelper::nextDefaultEvent is advanced internally by NEXT_EVENT is implementation-specific. If not, ensure that it is post-incremented at the call sites (e.g., pass I2cCardHelper::nextDefaultEvent++ as the macro argument).fd. Ensure the configuration space is mounted/available and not concurrently modified.Definition at line 614 of file SensorConfiguredProducer.h.


|
inlineprivate |
Sets the power-on state for a specific pin on a specific card.
Seed debouncer/state at power-up from CDI initial setting (no event emission here).
| cardNum | The card number on which the pin resides. This is used to index into the I2cCardHelper::i2cCards array of I2C card helpers. |
| pinNum | The pin number to set the state for. This should be within the valid range for the card. |
| state | The desired initial state of the pin specified by the DefaultDeviceSettings::DeviceStates enum. |
| debounceCount | The debounce count configured by user |
Definition at line 646 of file SensorConfiguredProducer.h.

|
inlineprotectedinherited |
sets up the MCP card's I2C connection using the user provided (CDI) configuration information (bus and address offset)
| fd | file handle to access the CDI configuration information (provided by openmrn) |
| cardIndex | specifies which card the configuration is for. Used to update the i2cCards[] array and initialize the connection |
| cfgI2cInfoRef | offset into the intenal configuration space for the CDI configuration for the MCP card |
Definition at line 295 of file I2cCardHelper.h.


|
inlineprotectedvirtualinherited |
Hook for consumers: drive one output pin (simple case). Default does nothing; simple consumers override this.
| card | card index (as stored in user_arg) |
| pin | pin index (as stored in user_arg) |
| set | desired logical state from the event semantics (SET/ON = true, CLR/OFF = false) |
Reimplemented in IoConfiguredPC, OutputConfiguredConsumer, ServoConfiguredConsumer, TurnoutConfiguredPC, and NeoPixelConfiguredConsumer.
Definition at line 392 of file I2cCardHelper.h.

|
inlineprotectedvirtualinherited |
Extended hook for consumers that also need the CDI intArg (e.g., audio message index). Default forwards to drive_pin(...) so existing consumers remain unchanged.
Reimplemented in AudioConfiguredConsumer.
Definition at line 402 of file I2cCardHelper.h.


|
inlineinherited |
Check for duplicate offsets on the same I2C bus. Automatically resets the tracker on the first call per config pass.
| cardIndex | Index of the card in the config loop. |
| bus | I2C bus number (0 or 1). |
| offset | I2C offset (0–7). |
Definition at line 183 of file I2cCardHelper.h.

|
inline |
Reset CDI configuration entries to their initial (default) values
| fd | used to access the CDI information in the file system |
Definition at line 311 of file SensorConfiguredProducer.h.

|
inlineprotectedinherited |
Default consumer handler: maps an incoming Event Report to (card,pin,set,intArg) and calls drive_pin_ext(...). Producers are ignored.
Definition at line 418 of file I2cCardHelper.h.

|
inline |
Polls the state of pins on sensor cards and triggers events on state changes.
Asynchronous callback when the previous polling message has left via the bus. Used as a poor man's iterative state machine.
Iteratively checks each pin of every connected sensor card for state changes. When a change in state is detected, it triggers a corresponding event. This function maintains state across calls, allowing it to resume polling where it left off in the previous call. Only one state change is handled per call to ensure load distribution over time.
Definition at line 241 of file SensorConfiguredProducer.h.

|
inlineprotectedinherited |
resets the card configuration information (description field).
| fd | file handle to access the CDI configuration information (provided by openmrn) |
| cfgI2cInfoRef | offset into the intenal configuration space for the CDI configuration block for the card's info (description, etc) |
Definition at line 309 of file I2cCardHelper.h.

|
inlineprotectedinherited |
resets the card's I2C configuration information (bus and address fields).
| fd | file handle to access the CDI configuration information (provided by openmrn) |
| cfgI2cInfoRef | offset into the intenal configuration space for the CDI configuration for card's I2C info (bus/offset) |
Definition at line 321 of file I2cCardHelper.h.

|
inlineprotectedvirtualinherited |
Sends Producer- or Consumer-Identified for registry_entry.
Identification type is inferred from the registry entry’s packed user args (see
Reimplemented in TurnoutConfiguredPC.
Definition at line 273 of file I2cCardHelper.h.


|
inherited |
event arguments