Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion api_drivers/common_api_drivers/indev/cst816s.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
_ChipID = const(0xA7)
_ChipIDValue = const(0xB5)
_ChipIDValue2 = const(0xB6)
_ChipIDValue3 = const(0xB4)

_ProjID = const(0xA8)
_FwVersion = const(0xA9)
Expand Down Expand Up @@ -206,7 +207,7 @@ def __init__(
self._read_reg(_FwVersion)
print('FW Version:', hex(self._rx_buf[0]))

if chip_id not in (_ChipIDValue, _ChipIDValue2):
if chip_id not in (_ChipIDValue, _ChipIDValue2, _ChipIDValue3):
raise RuntimeError(f'Incorrect chip id ({hex(_ChipIDValue)})')
Comment on lines +210 to 211
Copy link

Copilot AI Mar 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The RuntimeError message still hard-codes the expected chip ID as _ChipIDValue (0xB5), but the allowlist now includes 0xB4/0xB5/0xB6. This will mislead users debugging mismatches. Consider including the actual chip_id read and the full set of allowed IDs in the error message (e.g., “expected one of …, got …”).

Suggested change
if chip_id not in (_ChipIDValue, _ChipIDValue2, _ChipIDValue3):
raise RuntimeError(f'Incorrect chip id ({hex(_ChipIDValue)})')
allowed_ids = (_ChipIDValue, _ChipIDValue2, _ChipIDValue3)
if chip_id not in allowed_ids:
allowed_hex = ", ".join(hex(i) for i in allowed_ids)
raise RuntimeError(
f"Incorrect chip id: expected one of {allowed_hex}, got {hex(chip_id)}"
)

Copilot uses AI. Check for mistakes.

self._write_reg(_IrqCtl, _EnTouch | _EnChange)
Expand Down
Loading