-
Notifications
You must be signed in to change notification settings - Fork 688
Allow passing DS Instance to Robot and OpModes #8626
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
ThadHouse
wants to merge
12
commits into
wpilibsuite:2027
Choose a base branch
from
ThadHouse:dsinstance
base: 2027
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.
+316
−25
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
6d5d3a9
Allow passing DS Instance to Robot and OpModes
ThadHouse c0141a4
Fix templates
ThadHouse 24fa744
Add gamepads to default
ThadHouse c3c0b7d
Add to backend
ThadHouse a3457a1
Better name
ThadHouse 21963cb
More formatting
ThadHouse 2491b4a
Docs
ThadHouse 4054cf9
Another format
ThadHouse 0e99e34
Merge remote-tracking branch 'wpilibsuite/2027' into dsinstance
ThadHouse f4f71c9
Formatting changes
ThadHouse 7bccc72
Fix timed
ThadHouse af43afa
Lint
ThadHouse 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
33 changes: 33 additions & 0 deletions
33
wpilibj/src/main/java/org/wpilib/driverstation/DefaultUserControls.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,33 @@ | ||
| // Copyright (c) FIRST and other WPILib contributors. | ||
| // Open Source Software; you can modify and/or share it under the terms of | ||
| // the WPILib BSD license file in the root directory of this project. | ||
|
|
||
| package org.wpilib.driverstation; | ||
|
|
||
| /** | ||
| * A default implementation of UserControls that provides Gamepad instances for | ||
| * each of the 6 joystick ports provided by the DS. | ||
| */ | ||
| public class DefaultUserControls implements UserControls { | ||
| private final Gamepad[] m_gamepads; | ||
|
|
||
| /** | ||
| * Constructs a DefaultUserControls instance with Gamepads for each port. | ||
| */ | ||
| public DefaultUserControls() { | ||
| m_gamepads = new Gamepad[DriverStation.kJoystickPorts]; | ||
| for (int i = 0; i < m_gamepads.length; i++) { | ||
| m_gamepads[i] = new Gamepad(i); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Returns the Gamepad instance for the specified port. | ||
| * | ||
| * @param port The joystick port number. | ||
| * @return The Gamepad instance for the given port. | ||
| */ | ||
| public Gamepad getGamepad(int port) { | ||
| return m_gamepads[port]; | ||
| } | ||
| } |
15 changes: 15 additions & 0 deletions
15
wpilibj/src/main/java/org/wpilib/driverstation/UserControls.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,15 @@ | ||
| // Copyright (c) FIRST and other WPILib contributors. | ||
| // Open Source Software; you can modify and/or share it under the terms of | ||
| // the WPILib BSD license file in the root directory of this project. | ||
|
|
||
| package org.wpilib.driverstation; | ||
|
|
||
| /** | ||
| * An interface representing user controls such as gamepads or joysticks. | ||
| * If your main robot class has a UserControlsInstance attribute with a | ||
| * class implementing this interface, the constructor is able to receive | ||
| * an instance of that class. Additionally, any OpModes can also receive | ||
| * that same instance. | ||
| */ | ||
| public interface UserControls { | ||
| } | ||
26 changes: 26 additions & 0 deletions
26
wpilibj/src/main/java/org/wpilib/driverstation/UserControlsInstance.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,26 @@ | ||
| // Copyright (c) FIRST and other WPILib contributors. | ||
| // Open Source Software; you can modify and/or share it under the terms of | ||
| // the WPILib BSD license file in the root directory of this project. | ||
|
|
||
| package org.wpilib.driverstation; | ||
|
|
||
| import java.lang.annotation.ElementType; | ||
| import java.lang.annotation.Retention; | ||
| import java.lang.annotation.RetentionPolicy; | ||
| import java.lang.annotation.Target; | ||
|
|
||
| /** | ||
| * An annotation to specify the UserControls implementation class to be used | ||
| * for a robot. Apply this annotation to your main robot class, providing | ||
| * a class that implements the UserControls interface. | ||
| */ | ||
| @Target(ElementType.TYPE) | ||
| @Retention(RetentionPolicy.RUNTIME) | ||
| public @interface UserControlsInstance { | ||
| /** | ||
| * The UserControls implementation class to be used. | ||
| * | ||
| * @return The class that implements UserControls. | ||
| */ | ||
| Class<? extends UserControls> value(); | ||
| } |
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
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.
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.
We should document (either here or in
@UserControlsInterface, or both) that the class must have a default constructor.