Tolerate sensors that do not ACK every command - #72
Open
nikicat wants to merge 1 commit into
Open
Conversation
Every Device method assumes the sensor sends an ACK frame before the reply:
if isinstance(self.protocol, protocol.USBProtocol):
check_ack(
check_message_protocol(
check_message_pack(self.protocol.read()), COMMAND_ACK),
COMMAND_FIRMWARE_VERSION)
That assumption does not hold for every device. 27c6:533c (GF5288_GM168SEC,
Dell XPS 13 9310) ACKs reset and read_sensor_register but answers
firmware_version and enable_chip with the reply alone. The unconditional read
then consumes that reply, fails to parse it as an ACK, and the command errors
out on a perfectly healthy sensor:
firmware_version() -> ValueError: Invalid message protocol
enable_chip(True) -> USBTimeoutError: [Errno 110] Operation timed out
Add Device._expect_ack(), which reads one frame and puts it back via
Device.read() when it turns out not to be an ACK, so the caller reads it as
the reply. Sensors that do ACK are unaffected -- the ACK is consumed and
verified exactly as before.
This is strictly more permissive, so nothing that worked before changes. It
also collapses 31 five-line blocks into one-liners, for a net -88 lines.
Verified on 27c6:533c, all six commands now succeeding where two used to fail:
nop OK
enable_chip OK (was: USBTimeoutError)
firmware_version OK GF5288_GM168SEC_APP_13016 (was: ValueError)
reset OK (True, 1024)
read_sensor_register OK 0c a1 00 22
read_otp OK 68 e6 86 4a 54 ec 15 04 ...
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This was referenced Aug 6, 2026
This was referenced Aug 22, 2026
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.
Every
Devicemethod assumes the sensor sends an ACK frame before the reply:That assumption does not hold for every device. 27c6:533c (
GF5288_GM168SEC, tested on a Dell XPS 13 9310; the same USB ID is also reported for the XPS 13 9300 and XPS 15 9500) ACKsresetandread_sensor_registerbut answersfirmware_versionandenable_chipwith the reply alone. The unconditional read then consumes that reply, fails to parse it as an ACK, and the command errors out on a perfectly healthy sensor:The change
Device._expect_ack()reads one frame and, if it turns out not to be an ACK, puts it back viaself._pendingsoDevice.read()hands it to the caller as the reply. The 25self.protocol.read()call sites becameself.read()so they see the pushback.Sensors that do ACK are unaffected — the ACK is consumed and verified exactly as before. The change is strictly more permissive, so nothing that works today should change.
It also collapses 31 five-line blocks into one-liners: net −88 lines.
Verification
On 27c6:533c, all six commands now succeed where two used to fail:
nopenable_chipfirmware_versionGF5288_GM168SEC_APP_13016reset(True, 1024)read_sensor_register0c a1 00 22read_otp68 e6 86 4a 54 ec 15 04 ...I only have a 533c to test against, so a sanity check on a device that does ACK everything would be welcome.
Unrelated bug spotted
goodix.py:341inwrite_sensor_registerhasfor i in lengthwherelengthis anint— presumablyrange(length). Left alone here to keep this PR to one concern.