-
Notifications
You must be signed in to change notification settings - Fork 264
Use diozero for GPIO #2171
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Use diozero for GPIO #2171
Conversation
|
Looks like tests need to be fixed. |
|
Also seems like you grabbed some commits off a different branch when you created this one. You can fix that using interactive rebase. |
Gold856
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks pretty good at first glance. The big question I have is boards that support setting LEDs via a command of some sort, but not via diozero. If we do want to support LEDs on that kind of board, we still need CustomGPIO (I think). If not, we should clean up our config to not have those command fields.
|
I am currently planning to leave custom GPIO commands unimplemented, since The commit history and unit tests will be fixed before the draft status of this PR is removed. |
d46aad5 to
2c18a10
Compare
photon-core/src/main/java/org/photonvision/common/hardware/VisionLED.java
Outdated
Show resolved
Hide resolved
photon-core/src/main/java/org/photonvision/common/hardware/VisionLED.java
Outdated
Show resolved
Hide resolved
photon-core/src/main/java/org/photonvision/common/hardware/VisionLED.java
Outdated
Show resolved
Hide resolved
photon-core/src/main/java/org/photonvision/common/util/math/MathUtils.java
Outdated
Show resolved
Hide resolved
|
I am revisiting custom GPIO before unmarking this as a draft. I have some new ideas on how to make that happen. |
|
Can we make a PR to https://github.com/PhotonVision/photon-image-modifier as well to remove the installation of pigpio which is no longer needed? |
This was on my plans. |
275fd35 to
1915638
Compare
|
I elected to break compatibility with the older GPIO commands due to differences in behavior for the new GPIO commands. Specifically, the presence of new GPIO command dictates if they are enabled, instead of the platform. Also, |
photon-core/src/main/java/org/photonvision/common/configuration/HardwareConfig.java
Show resolved
Hide resolved
photon-core/src/main/java/org/photonvision/common/hardware/HardwareManager.java
Outdated
Show resolved
Hide resolved
photon-core/src/main/java/org/photonvision/common/hardware/VisionLED.java
Outdated
Show resolved
Hide resolved
photon-core/src/main/java/org/photonvision/common/hardware/VisionLED.java
Outdated
Show resolved
Hide resolved
| } | ||
|
|
||
| private int doProcess(boolean wait, Process process) { | ||
| private synchronized int doProcess(boolean wait, Process process) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this necessary? If so, why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without this, I would occasionally get an IllegalThreadStateException from the gobblers since they were overwritten by another thread and were already started. I know the default implementation of blink in diozero uses threads, and I believe threads are also used in the default shutdown process. An alternative to synchronizing this method would to be to remove all of its dependencies on class variables, which would break some of the other methods here.
| @Override | ||
| public void setMode(DeviceMode mode) { | ||
| if (mode == DeviceMode.DIGITAL_INPUT) { | ||
| getValue(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does getting the value do here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assumed the getGPIO and setGPIO to also set the data direction of the request pin to input or output, respectively. This is also why I cache the output value instead of getting it.
Description
The old GPIO abstraction was replaced with
diozero, which supports most hardware running Linux due to its use of GPIO character devices provided by the Linux kernel.diozeroalso supports alternate providers if for some reason the character device API is insufficient. Certain capabilities outside of the character device API is also implemented for common hardware.Custom GPIO commands are implemented via a custom
diozeroprovider. The configuration for custom GPIO will need manually updated according to the Hardware Config documentation page.This was tested on a RPi 5 with LL3 illumination LEDs and an RGB status led attached. All capabilities worked as expected. All 8 status LED colors were tested and functional via modifying the code. Basic functionality of custom GPIO was tested with dummy commands.
closes #2062
Meta
Merge checklist: