Skip to content

Add set_mode to GPIO and fix checkFirmware error#147

Merged
beniroquai merged 1 commit into
masterfrom
mergemaster
Jul 2, 2026
Merged

Add set_mode to GPIO and fix checkFirmware error#147
beniroquai merged 1 commit into
masterfrom
mergemaster

Conversation

@beniroquai

Copy link
Copy Markdown
Contributor

Add set_mode() to GPIO for switching between auto/manual collision detection modes (persisted in NVS). Also wrap the firmware check loop body in a try/except to prevent crashes on decode errors.

Add `set_mode()` to GPIO for switching between auto/manual collision detection modes (persisted in NVS). Also wrap the firmware check loop body in a try/except to prevent crashes on decode errors.
Copilot AI review requested due to automatic review settings July 2, 2026 20:09
@beniroquai beniroquai merged commit 473fad0 into master Jul 2, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR extends the GPIO collision-detection client API with a set_mode() helper (persisted on the slave in NVS) and hardens the serial firmware-check loop to avoid crashing on decode errors during connection.

Changes:

  • Add GPIO.set_mode() to switch between auto/manual collision detection modes (mapped to 0/1).
  • Clarify GPIO.calibrate() docstring to indicate it applies to manual mode semantics.
  • Wrap the checkFirmware() loop body with exception handling to prevent decode-related crashes.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
uc2rest/mserial.py Adds error handling in checkFirmware() to avoid crashes when reading/decoding serial output.
uc2rest/gpio.py Adds set_mode() API and updates calibration documentation to reflect manual/auto behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread uc2rest/mserial.py
Comment on lines +367 to +374
try:
if self.DEBUG and mReadline != "" and mReadline != "\n" and mReadline != b'' and mReadline != b'\n':
self._logger.debug("[checkFirmware]: "+str(mReadline))
if mReadline.decode('utf-8').strip() == "++" or mReadline.decode('utf-8').strip().find("++")>=0:
self._freeSerialBuffer(ser)
return True
except Exception as e:
self._logger.error("Error in checkFirmware: "+str(e))
Comment thread uc2rest/gpio.py
Comment on lines +167 to +171
if isinstance(mode, str):
mval = 1 if mode.lower() == "manual" else 0
else:
mval = 1 if int(mode) else 0
return self._act(node=node, timeout=timeout, mode=mval)
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