Skip to content

fix(hidpp): tolerate unrecognised BacklightStatus codes from getBacklightInfo - #687

Open
charliecai01 wants to merge 1 commit into
AprilNEA:masterfrom
charliecai01:fix/backlight-k98m-unknown-status
Open

fix(hidpp): tolerate unrecognised BacklightStatus codes from getBacklightInfo#687
charliecai01 wants to merge 1 commit into
AprilNEA:masterfrom
charliecai01:fix/backlight-k98m-unknown-status

Conversation

@charliecai01

Copy link
Copy Markdown
Contributor

The keyboard backlight can't be read at all on an Alto Keys K98M — openlogi backlight status (and the equivalent GUI panel) fails outright.

Root cause

The K98M runs Backlight / 0x1982 at version 4. Its getBacklightInfo response reports status byte 6, which none of the six named BacklightStatus variants (0–5) cover. The strict TryFromPrimitive decode fails on that byte and the whole read errors out — status, level, and effect all lost over one unrecognised code:

Error: read backlight state

Caused by:
    HID++ unsupported response during ReadBacklight for feature 0x1982

The interesting part: hid/src/write/backlight.rs::status_from_firmware already has a catch-all mapping any "unmodelled future variant" back to AlsAutomatic, with a doc comment saying exactly that's the intent. That fallback was dead code — unreachable because the decoder aborted before it could ever run.

Fix

Add BacklightStatus::Unknown(u8) and switch the decode from try_from (fails closed) to a total From<u8> conversion (falls back open), so an unrecognised status code is preserved instead of failing the read. This lets the existing status_from_firmware fallback do the job it was already written for. No public spec documents what 6 means on this firmware, so I didn't invent a name for it — it's just carried through as Unknown(6).

Testing

  • Verified against a physical Alto Keys K98M paired over a Logi Bolt receiver. Before: HID++ unsupported response during ReadBacklight for feature 0x1982. After:
    current: enabled=true mode=none status=on (following ambient light) level=2/8
    
  • Added keeps_unmodelled_status_codes covering the exact byte pattern the K98M returns.
  • cargo test -p openlogi-hidpp — 202 passed, 0 failed.
  • cargo fmt --check and cargo clippy --release -p openlogi-hidpp — clean.

…ightInfo

An Alto Keys K98M on 0x1982 (Backlight2) v4 answers getBacklightInfo
with status byte 6, which none of the six named BacklightStatus
variants cover. The strict TryFromPrimitive decode failed on that byte
and errored the entire backlight read — status, level, and effect all
lost to one unmodelled code.

The consumer at hid/src/write/backlight.rs already has a catch-all
mapping any "unmodelled future variant" back to AlsAutomatic, per its
own doc comment — that branch was unreachable because the decoder
failed first. Add BacklightStatus::Unknown(u8) so an unfamiliar status
code is preserved instead of aborting the read, and let the existing
fallback do what it was written to do.

Verified against a physical Alto Keys K98M over a Logi Bolt receiver:
`openlogi backlight status` previously errored with "HID++ unsupported
response during ReadBacklight for feature 0x1982"; now reads
`enabled=true mode=none status=on (following ambient light) level=2/8`.
@charliecai01
charliecai01 requested a review from AprilNEA as a code owner August 19, 2026 18:31
@greptile-apps

greptile-apps Bot commented Aug 19, 2026

Copy link
Copy Markdown

Greptile Summary

This PR makes HID++ backlight-status decoding forward-compatible so unknown firmware status bytes no longer fail the entire backlight read.

  • Adds BacklightStatus::Unknown(u8) and lossless numeric conversions.
  • Uses total status decoding for queried backlight information and update events.
  • Adds coverage for the status code reported by the Alto Keys K98M.

Confidence Score: 5/5

The PR appears safe to merge because unknown status values are preserved during protocol decoding and handled by the existing application-level fallback.

The changed query and event decoders accept all status bytes, known values retain their prior mappings, unknown values round-trip losslessly, and the sole current application consumer already handles unmodeled variants.

Important Files Changed

Filename Overview
crates/openlogi-hidpp/src/feature/backlight.rs Adds lossless handling of unrecognized backlight-status bytes across both response parsers, with focused round-trip coverage and no actionable defect found.

Reviews (1): Last reviewed commit: "fix(hidpp): tolerate unrecognised Backli..." | Re-trigger Greptile

@davidbudnick davidbudnick added type: bug Something is broken or behaves incorrectly platform: all Cross-platform issue labels Aug 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

platform: all Cross-platform issue type: bug Something is broken or behaves incorrectly

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants