Add GPIO collision detector client#146
Merged
Merged
Conversation
Adds a new `GPIO` helper for the CAN GPIO slave, including status polling, configuration commands, and async event callbacks. Wire it into `UC2Client` so the GPIO interface is initialized alongside the other device modules.
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a new GPIO/collision-detector client module and wires it into UC2Client so consumers can poll status, configure thresholds/sensitivity/reference, and receive async collision/E-stop events via callbacks.
Changes:
- Added
uc2rest/gpio.pyimplementing GPIO status polling (/gpio_get), configuration (/gpio_act), and async event callbacks. - Initialized the new
GPIOhelper inUC2Clientalongside other device modules. - Added an inline JSON example comment in
motor.set_joystick_direction().
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| uc2rest/UC2Client.py | Imports and initializes the new GPIO helper during client construction. |
| uc2rest/motor.py | Adds an inline payload example comment for joystick direction configuration. |
| uc2rest/gpio.py | New GPIO/collision-detector client with polling, configuration helpers, and serial callback plumbing. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+54
to
+66
| gpio = data.get("gpio", None) | ||
| if not isinstance(gpio, dict): | ||
| return | ||
| self.status.update(gpio) | ||
|
|
||
| for cb in self._status_callbacks: | ||
| try: | ||
| cb(dict(self.status)) | ||
| except Exception as e: | ||
| print(f"Error in gpio status callback: {e}") | ||
|
|
||
| if gpio.get("event", 0): | ||
| for cb in self._collision_callbacks: |
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.
Adds a new
GPIOhelper for the CAN GPIO slave, including status polling, configuration commands, and async event callbacks. Wire it intoUC2Clientso the GPIO interface is initialized alongside the other device modules.