From 6753eaeea694441392ef391bada7d7bdb332872a Mon Sep 17 00:00:00 2001 From: Mick Vleeshouwer Date: Wed, 28 Oct 2026 00:32:04 +0000 Subject: [PATCH] Fix key release on 5-byte keypad frames and map M4 in pass-through --- .../loctekmotion_desk_command/desk_command_sensor.cpp | 4 +++- packages/office-desk-esp32-passthrough.yaml | 6 +++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/components/loctekmotion_desk_command/desk_command_sensor.cpp b/components/loctekmotion_desk_command/desk_command_sensor.cpp index 5e94353..a020228 100644 --- a/components/loctekmotion_desk_command/desk_command_sensor.cpp +++ b/components/loctekmotion_desk_command/desk_command_sensor.cpp @@ -34,12 +34,14 @@ void DeskCommandSensor::loop() { // Decide command on byte 5: history[0] is byte 4 (bits 0..6 — Up, Down, // M1..M3, M-memory, Alarm), incomingByte is byte 5 (bits 8.. — M4 and // any future high-byte buttons). Both zero == release. + // 5-byte frames (e.g. HS01B-1) have a single payload byte, so byte 5 is + // the checksum there and must not be decoded as a button. if (this->history[3] == 0x9b) { if (this->msg_type == 0x02 && ((this->msg_len == 6) || (this->msg_len == 5))) { if (this->history[0] != 0) { this->value = log2(this->history[0] * 2); // 1..7 - } else if (incomingByte != 0) { + } else if (this->msg_len == 6 && incomingByte != 0) { this->value = 8 + log2(incomingByte * 2); // 9 for M4, 10 for M5, ... } else { diff --git a/packages/office-desk-esp32-passthrough.yaml b/packages/office-desk-esp32-passthrough.yaml index 2c2ad76..e180f31 100644 --- a/packages/office-desk-esp32-passthrough.yaml +++ b/packages/office-desk-esp32-passthrough.yaml @@ -116,7 +116,7 @@ sensor: id: "desk_command" name: Desk command uart_id: keypad_uart - on_value_range: # The sensor outputs values 1 to 8 depending on the button pressed. + on_value_range: # The sensor outputs values 1 to 9 depending on the button pressed. - above: 1 below: 1 then: @@ -151,6 +151,10 @@ sensor: - switch.turn_off: switch_up - switch.turn_off: switch_down - button.press: button_wake_screen + - above: 9 + below: 9 + then: + - button.press: button_sit switch: - platform: gpio