-
Notifications
You must be signed in to change notification settings - Fork 263
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
Open
thatcomputerguy0101
wants to merge
17
commits into
PhotonVision:main
Choose a base branch
from
thatcomputerguy0101:diozero-gpio
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+814
−1,429
Open
Use diozero for GPIO #2171
Changes from 11 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
99edd82
Migrate GPIO control to diozero
thatcomputerguy0101 9866272
Update documentation to reflect the use of diozero
thatcomputerguy0101 62ce302
Remove custom gpio commands
thatcomputerguy0101 c358ebf
Update tests for diozero
thatcomputerguy0101 c1b04bf
Calculate brightness percentage as a floating point number
thatcomputerguy0101 3534b9c
Make for loops consistent in VisionLED
thatcomputerguy0101 112915f
Deduplicate code in VisionLED.setINternal
thatcomputerguy0101 0177318
Calculate brightness as a double
thatcomputerguy0101 14d0596
Add custom GPIO diozero provider
thatcomputerguy0101 1915638
Synchronize ShellExec `doProcess` to prevent race condition on gobblers
thatcomputerguy0101 ea4c6c5
Add license header to new files
thatcomputerguy0101 19505f9
Add missing fields to HardwareConfig string
thatcomputerguy0101 c40eddb
Fix usage of default device factory in native gpio test
thatcomputerguy0101 570b914
Replace Arrays.asList with List.of
thatcomputerguy0101 911fb1b
Replace Closable with AutoClosable
thatcomputerguy0101 008b0bc
Use coercion instead of casting
thatcomputerguy0101 fc8dc11
Remove unused device name from Custom GPIO adapter
thatcomputerguy0101 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
80 changes: 80 additions & 0 deletions
80
photon-core/src/main/java/org/photonvision/common/hardware/GPIO/CustomAdapter.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| /* | ||
| * Copyright (C) Photon Vision. | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU General Public License as published by | ||
| * the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU General Public License | ||
| * along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| package org.photonvision.common.hardware.GPIO; | ||
|
|
||
| import java.util.Arrays; | ||
| import org.photonvision.common.logging.LogGroup; | ||
| import org.photonvision.common.logging.Logger; | ||
| import org.photonvision.common.util.ShellExec; | ||
|
|
||
| public class CustomAdapter { | ||
| private static final Logger logger = new Logger(CustomAdapter.class, LogGroup.General); | ||
| private static final ShellExec runCommand = new ShellExec(true, true); | ||
|
|
||
| public final String deviceName; | ||
| protected final String getGPIOCommand; | ||
| protected final String setGPIOCommand; | ||
| protected final String setPWMCommand; | ||
| protected final String releaseGPIOCommand; | ||
|
|
||
| public CustomAdapter( | ||
| String deviceName, | ||
| String getGPIOCommand, | ||
| String setGPIOCommand, | ||
| String setPWMCommand, | ||
| String releaseGPIOCommand) { | ||
| this.deviceName = deviceName; | ||
| this.getGPIOCommand = getGPIOCommand; | ||
| this.setGPIOCommand = setGPIOCommand; | ||
| this.setPWMCommand = setPWMCommand; | ||
| this.releaseGPIOCommand = releaseGPIOCommand; | ||
| } | ||
|
|
||
| protected static String execute(String command) { | ||
| try { | ||
| runCommand.executeBashCommand(command); | ||
| } catch (Exception e) { | ||
| logger.error(Arrays.toString(e.getStackTrace())); | ||
| return ""; | ||
| } | ||
| return runCommand.getOutput(); | ||
| } | ||
|
|
||
| public boolean getGPIO(int gpio) { | ||
| return Boolean.parseBoolean( | ||
| execute(getGPIOCommand.replace("{p}", Integer.toString(gpio))).trim()); | ||
| } | ||
|
|
||
| public void setGPIO(int gpio, boolean state) { | ||
| execute( | ||
| setGPIOCommand | ||
| .replace("{p}", Integer.toString(gpio)) | ||
| .replace("{s}", Boolean.toString(state))); | ||
| } | ||
|
|
||
| public void setPWM(int gpio, double value) { | ||
| execute( | ||
| setPWMCommand | ||
| .replace("{p}", Integer.toString(gpio)) | ||
| .replace("{v}", Double.toString(value))); | ||
| } | ||
|
|
||
| public void releaseGPIO(int gpio) { | ||
| execute(releaseGPIOCommand.replace("{p}", Integer.toString(gpio))); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.