Skip to content

v2.1: seed digitalio input change-detection from a last-known-state initial write in pinAdd #955

Description

@tyeth-ai-assisted

Context

Deferred from the #943 review (thread, deferral) as a nice-to-have for v2.1.

DigitalIOHardware::CheckEvent() (src/components/digitalIO/hardware.cpp) currently treats the first read after a pinAdd specially: _prv_value starts as a guess, so the first read seeds the baseline from hardware and is always published as the pin's initial state (fixed in dcb1f04 — previously the guess could suppress or fabricate a transition).

Feature

For input pins, IO should supply the last known state in the pinAdd's optional initial write (the field already exists in ws_digitalio_Add and is currently only meaningful for outputs). The firmware would use that as the starting previous value for the on-change trigger:

  • current reading == last known state → no redundant initial event; the broker already has this value
  • current reading != last known state → a genuine transition event fires, so a state change that happened while the device was offline / rebooting / sleeping is detected and published as a change rather than a fresh baseline

Notes

  • Needs IO/broker cooperation: the pinAdd for an input must carry the last value the broker saw (companion change in adafruit/Wippersnapper_Protobuf semantics/docs if the existing write field is reused).
  • Interaction with is_inverted and expander-backed pins (EXP_0xNN_P) should follow the logical-value convention used by ReadValue().
  • Sleep/wake replay makes this more valuable: every deep-sleep wake re-runs componentAdds (see v2: refcounted shared power-rail/pin ownership + sleep-mode rail handling #952), so today each wake re-publishes baselines for every input.

Refs: #943, #952.

🤖 Generated with Claude Code

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions