Make sensor polarity per-sensor, ready for the active-high detector (#9) - #23
Merged
Merged
Conversation
Polarity belongs to the device on the far end of the wire, not to the node, and the bazauto/block-detection board is the first device that disagrees with the rest: push-pull, 3.3 V when occupied. One global ACTIVE_LOW could not express a node carrying both. Every SENSORS entry now carries active_low, set from a per-device constant (LM_ID_ACTIVE_LOW, WAVESHARE_IR_ACTIVE_LOW, BAZAUTO_BD_ACTIVE_LOW). There is no default: select_installed refuses an entry without one, or with anything other than a real bool, since "False" is truthy and a guessed polarity publishes clear for every occupied block. No behaviour change on the layout: every entry, including the installed Goods Shed pair, is still active low. Swapping a cs--- entry to the new board is a one-line change, made after its wire-pull bench check. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Makes sensor polarity a per-sensor field instead of one global
ACTIVE_LOW, so the node can carry thebazauto/block-detectionboard alongside the existing devices.Why
Polarity belongs to the device on the far end of the wire, not to the node. Until now every fitted device happened to be active low: the LM-iD.1 on board 1 and the Waveshare IR modules on board 2. The new block-detection board is the first one that isn't. It drives its output push-pull, 3.3 V when occupied, so a broken signal wire into the expander's pull-up reads occupied. That is the point of it (#9). One global flag couldn't describe a node carrying both kinds.
What changed
SENSORSentry inconfig.pynow has anactive_lowfield, set from a per-device constant:LM_ID_ACTIVE_LOW = True,WAVESHARE_IR_ACTIVE_LOW = True,BAZAUTO_BD_ACTIVE_LOW = False.select_installedrefuses an entry with no polarity, or with anything other than a realTrueorFalse. There is no default. A guessed polarity publishesclearfor every occupied block, and"False"is truthy.main.pybuilds each sensor as(sensor_id, pin, active_low)and reads each one with its own polarity. The pull-up stays on for every sensor. For an active-high device, the pull-up is what makes a broken wire read occupied.The layout's behaviour doesn't change. Every entry, including the installed Goods Shed pair, is still active low. Moving a
cs---entry to the new board is a one-line change, made after that channel's wire-pull check on the bench. That check belongs to the current-sensing validation, and it can't be done on the host.Tests
python -m pytest: 185 passed. New tests cover:1,0,"False",None) is refused;main.pyimportsmachineand isn't host-tested. Its change only passes the value through, and deploying and reading Goods Shed on the bench covers it.MQTT contract check: topics, payloads, QoS, retention and the 30 s re-assert are unchanged.
tick()re-asserts the cached reading, which is now computed with each sensor's own polarity.Docs
CLAUDE.md,docs/pin-allocation.md(the polarity section is rewritten with a per-device table), anddocs/block-detector-wiring.md(records that the new board replaces the "power Input A plus inverter" plan for board 1).Refs #9. This doesn't close it: the IR half is still open, and the new board hasn't been fitted or wire-pull tested yet.
🤖 Generated with Claude Code