Add set_mode to GPIO and fix checkFirmware error#147
Merged
Conversation
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.
Contributor
There was a problem hiding this comment.
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 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 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) |
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.
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.