|
LCC Fusion Project 1.0
LCC Automation
|
#include <IoConfiguredPC.h>


Public Types | |
| typedef IoCardConfig | CardConfig_type |
| typedef IoConfig | LineConfig_type |
Public Member Functions | |
| template<unsigned N> | |
| IoConfiguredPC (openlcb::Node *pNode, const openlcb::RepeatedGroup< CardConfig_type, N > &configOffset, uint8_t numDevicesPerCard, EventDeviceTypes eventDeviceType, const char *cardDescription) __attribute__((noinline)) | |
| Helper that wires a bank of MCP23017-based I/O cards into the OpenLCB / LCC event system. More... | |
| UpdateAction | apply_configuration (int fd, bool initial_load, BarrierNotifiable *done) OVERRIDE |
| Read CDI, initialize hardware, and (re)register events for every IO card and line. More... | |
| void | factory_reset (int fd) OVERRIDE |
| Reset this node's IO card CDI segment to factory defaults. More... | |
| bool | ensureUniqueI2cOffset (uint8_t cardIndex, uint8_t bus, uint8_t offset) |
Public Attributes | |
| union I2cCardHelper::EventUserArgsUnion | userArgs |
Protected Member Functions | |
| void | drive_pin (uint8_t card, uint8_t pin, bool set) override |
| Consumer hook: parent decodes EventReport and calls this with (card,pin,set). | |
| 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_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 | |
| bool | _processPinState (int cardIndex, int pinIndex) |
| Shadow copy of the event IDs produced by each of the UOD cards. More... | |
| void | _initI2cCards (bool isProducer) |
| Initializes the array of I2C card objects using the configured card type. More... | |
(card,pin,set,intArg) and calls drive_pin(...) here. This class writes the MCP pin and, if desired, persists the new state via DefaultDeviceSettings.WriteAsync (one‑event‑per‑slice).action per pin: LINPUT (producer) or LOUTPUT (consumer)debounceCount: applied immediately to debouncer at config timeonEvent/offEvent: ON/OFF Event IDs for each pini2cInfoConfigStartup & config:
user_arg and registers ON/OFF events for each pinRuntime:
_processPinState() → emit ON/OFF → engine resumes on notify()drive_pin(card,pin,set) → MCP writeread_card() returns false and the engine skips it this slice. Definition at line 113 of file IoConfiguredPC.h.
| typedef IoCardConfig IoConfiguredPC::CardConfig_type |
Type for Input/Output card configuration entry
Definition at line 117 of file IoConfiguredPC.h.
| typedef IoConfig IoConfiguredPC::LineConfig_type |
Type for Input/Output configuration entry
Definition at line 118 of file IoConfiguredPC.h.
|
inline |
Helper that wires a bank of MCP23017-based I/O cards into the OpenLCB / LCC event system.
Constructs an IoConfiguredPC instance that:
Typically created once in the sketch (or node wrapper) during startup, then used to apply CDI configuration and register consumer/producer events.
| N | Number of I/O cards in the CDI repeated group. |
| pNode | OpenLCB node object from the stack. |
| configOffset | CDI configuration offset for the repeated group of I/O cards. |
| numDevicesPerCard | Number of I/O lines (pins) per card (for example, 16 for a full MCP23017 port). |
| eventDeviceType | Logical type of event device (used for logging, diagnostics, and naming). |
| cardDescription | Human-friendly card description for log messages and debug output (e.g. "IO Card"). |
Definition at line 163 of file IoConfiguredPC.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 |
Shadow copy of the event IDs produced by each of the UOD cards.
Process one I/O line on a card (debounce + maybe emit one event).
This is called by the polling engine provided by I2cPollingHelper via process_line(cardIndex, lineIndex).
Behavior:
poll_.helper->WriteAsync(...),true so the engine stops this slice (one-event-per-slice rule).false and the engine advances to the next line (and eventually the next card).Notes:
notify() after the write completes.read_card(cardIndex) should return false so this function is not called for that card during the current slice. Definition at line 401 of file IoConfiguredPC.h.

|
inline |
Read CDI, initialize hardware, and (re)register events for every IO card and line.
When it runs:
initial_load == true.initial_load == false.High-level flow: 1) Unregister old events (only on live updates): If !initial_load, call _do_unregister() so we don’t leak duplicate registry entries.
2) Per-card hardware init (I²C): For each card i, call applyI2cInfo(fd, i, cfgCardsRef.i2cInfoConfig()) to:
i2cCards[i] with the correct bus/address,3) Per-line configuration and event registration: For each line j on card i:
action (input vs output), debounceCount, onEvent, offEvent, and optional description.user_arg for the registry entry using the helper’s standard layout: (card=i, pin=j, intArg=0 unless specified elsewhere, isSetEvent bit implied by event, isProducer = (action == input)).user_arg.producerEventIds_ so the producer path can emit later.(i, j) from the current raw pin value and the configured debounceCount. This is seed only (no Event Report yet); the first debounced change at runtime will produce a single ON/OFF event.handle_event_report → drive_pin(...) hook).4) Tell the stack to (re)announce: Return REINIT_NEEDED so OpenMRN will run Identify; this lets peers rediscover the updated set of events after a boot or CDI change.
Notes & guarantees:
apply_configuration(...). Producers only emit later, during polling, when the debounced state actually changes. Consumers only act in response to incoming Event Reports.| fd | File descriptor used to read CDI entries. |
| initial_load | true on cold boot, false during a live reconfiguration. |
| done | Completion notifier (handled via AutoNotify at entry). |
REINIT_NEEDED to trigger Identify after registration. Definition at line 237 of file IoConfiguredPC.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 |
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 this node's IO card CDI segment to factory defaults.
What this does (by design, CDI only):
resetCardInfo(fd, ...) to reset card-level metadata (e.g., enable/name).resetI2cInfo(fd, ...) to reset the I²C bus and address-offset entries.action (input/output role) and debounceCount to their default values.description string.onEvent / offEvent IDs using NEXT_DEFAULT_EVENT(...) so each line has a valid, discoverable pair of event IDs after a reset.What this does not do:
Why this matters:
apply_configuration(...) run will re-initialize cards from the clean CDI image and (re)register events in a known-good state.| fd | File descriptor used to write the CDI entries. |
Definition at line 320 of file IoConfiguredPC.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.

|
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