Skip to content

Add adc_ladder() factory for ADC resistor-ladder binary inputs#78

Merged
g4bri3lDev merged 2 commits into
OpenDisplay:mainfrom
teancom:feat/adc-ladder
Jul 3, 2026
Merged

Add adc_ladder() factory for ADC resistor-ladder binary inputs#78
g4bri3lDev merged 2 commits into
OpenDisplay:mainfrom
teancom:feat/adc-ladder

Conversation

@teancom

@teancom teancom commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Matching PR to OpenDisplay/Firmware#35, this adds support for configs of analog buttons. Tested live on an XTEINK X4, and I tried to make it as generic as possible. As always, let me know if something doesn't look right / should be architected differently, I'm still learning (obvs!) so any/all feedback is very welcome.

Robot's commit message:

ADC resistor-ladder buttons (input_type=2) share one ADC pin and are distinguished by voltage. adc_ladder() packs (N, id_base) + (N+1) strictly-descending LE uint16 thresholds into BinaryInputs.reserved[14], matching the firmware's registerAdcLadder decode byte-for-byte.

Validation mirrors the firmware contract so this helper can't build a config the device would silently drop:

  • 2..6 thresholds (N = 1..5; reserved[14] holds at most N+1=6)
  • thresholds strictly descending, each a uint16
  • button_data_byte_index 0..10 (index into the 11-byte MSD block)
  • id_base >= 0 and last id <= 7 (button id is a 3-bit report field)

Adds BinaryInputType enum and tests pinning the wire contract plus every rejection branch.

@teancom teancom requested a review from g4bri3lDev as a code owner June 2, 2026 18:18
@codecov

codecov Bot commented Jun 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

teancom and others added 2 commits June 25, 2026 11:57
ADC resistor-ladder buttons (input_type=2) share one ADC pin and are
distinguished by voltage. adc_ladder() packs (N, id_base) + (N+1)
strictly-descending LE uint16 thresholds into BinaryInputs.reserved[14],
matching the firmware's registerAdcLadder decode byte-for-byte.

Validation mirrors the firmware contract so this helper can't build a
config the device would silently drop:
  - 2..6 thresholds (N = 1..5; reserved[14] holds at most N+1=6)
  - thresholds strictly descending, each a uint16
  - button_data_byte_index 0..10 (index into the 11-byte MSD block)
  - id_base >= 0 and last id <= 7 (button id is a 3-bit report field)

Adds BinaryInputType enum and tests pinning the wire contract plus every
rejection branch.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Matches firmware OpenDisplay#35 review: input_type == 2 is reserved for the
host-side switch feature. Add SWITCH = 2 to model the reservation and
renumber ADC_LADDER to 3. Wire layout is otherwise unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@g4bri3lDev g4bri3lDev merged commit dab93b1 into OpenDisplay:main Jul 3, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants