RobotCore
1.0
WPILib port to raspberry Pi
Toggle main menu visibility
Loading...
Searching...
No Matches
BindingScope.java
1
// Copyright (c) FIRST and other WPILib contributors.
2
// Open Source Software; you can modify and/or share it under the terms of
3
// the WPILib BSD license file in the root directory of this project.
4
5
package
org.wpilib.command3;
6
7
import
org.wpilib.hardware.hal.RobotMode;
8
13
@SuppressWarnings(
"PMD.ImplicitFunctionalInterface"
)
14
interface
BindingScope
{
20
boolean
active
();
21
29
static
BindingScope
createNarrowestScope
(
Scheduler
scheduler) {
30
Command
currentCommand = scheduler.
currentCommand
();
31
RobotStateFetcher fetcher = RobotStateFetcher.getFetcher();
32
long
currentOpMode = fetcher.getOpModeId();
33
RobotMode
currentRobotMode = fetcher.getRobotMode();
34
35
if
(currentCommand !=
null
) {
36
// Commands are the narrowest scope, so prioritize them first.
37
return
new
ForCommand
(scheduler, currentCommand);
38
}
else
if
(currentOpMode != 0) {
39
// Opmodes are more specific than general robot mode bindings.
40
return
new
ForOpmode
(currentOpMode);
41
}
else
{
42
// Not in a command and not in an opmode. Use a robot mode scope, if applicable,
43
// or fall back to the global scope if the robot is disabled or in an unrecognized mode.
44
// The switch statement deliberately does not have a default case. We want the compiler to
45
// tell us to update the switch statement if the enum changes.
46
return
switch
(currentRobotMode) {
47
case
AUTONOMOUS ->
AutonomousMode
.INSTANCE;
48
case
TELEOPERATED ->
TeleopMode
.INSTANCE;
49
case
UTILITY ->
UtilityMode
.INSTANCE;
50
case
UNKNOWN ->
Global
.INSTANCE;
51
};
52
}
53
}
54
56
final
class
Global
implements
BindingScope
{
57
// No reason not to be a singleton.
58
public
static
final
Global
INSTANCE =
new
Global
();
59
60
@Override
61
public
boolean
active
() {
62
return
true
;
63
}
64
}
65
73
record
ForCommand
(
Scheduler
scheduler,
Command
command) implements
BindingScope
{
74
@Override
75
public
boolean
active
() {
76
return
scheduler.isRunning(command);
77
}
78
}
79
85
record
ForOpmode
(
long
opmodeId) implements
BindingScope
{
86
@Override
87
public
boolean
active
() {
88
return
RobotStateFetcher.getFetcher().getOpModeId() == opmodeId;
89
}
90
}
91
92
interface
RobotModeScope
extends
BindingScope
{}
93
98
final
class
AutonomousMode
implements
RobotModeScope
{
99
public
static
final
AutonomousMode
INSTANCE =
new
AutonomousMode
();
100
101
@Override
102
public
boolean
active
() {
103
return
RobotStateFetcher.getFetcher().getRobotMode() ==
RobotMode
.
AUTONOMOUS
;
104
}
105
}
106
111
final
class
TeleopMode
implements
RobotModeScope
{
112
public
static
final
TeleopMode
INSTANCE =
new
TeleopMode
();
113
114
@Override
115
public
boolean
active
() {
116
return
RobotStateFetcher.getFetcher().getRobotMode() ==
RobotMode
.
TELEOPERATED
;
117
}
118
}
119
124
final
class
UtilityMode
implements
RobotModeScope
{
125
public
static
final
UtilityMode
INSTANCE =
new
UtilityMode
();
126
127
@Override
128
public
boolean
active
() {
129
return
RobotStateFetcher.getFetcher().getRobotMode() ==
RobotMode
.
UTILITY
;
130
}
131
}
132
133
// There is no scope for the "disabled" mode, since it would interfere with the global scope
134
}
org.wpilib.command3.BindingScope.AutonomousMode
Definition
BindingScope.java:98
org.wpilib.command3.BindingScope.AutonomousMode.active
boolean active()
Definition
BindingScope.java:102
org.wpilib.command3.BindingScope.Global
Definition
BindingScope.java:56
org.wpilib.command3.BindingScope.Global.active
boolean active()
Definition
BindingScope.java:61
org.wpilib.command3.BindingScope.TeleopMode
Definition
BindingScope.java:111
org.wpilib.command3.BindingScope.TeleopMode.active
boolean active()
Definition
BindingScope.java:115
org.wpilib.command3.BindingScope.UtilityMode
Definition
BindingScope.java:124
org.wpilib.command3.BindingScope.UtilityMode.active
boolean active()
Definition
BindingScope.java:128
org.wpilib.command3.Scheduler
Definition
Scheduler.java:106
org.wpilib.command3.Scheduler.currentCommand
Command currentCommand()
Definition
Scheduler.java:1151
org.wpilib.hardware.hal.RobotMode
Definition
RobotMode.java:8
org.wpilib.hardware.hal.RobotMode.AUTONOMOUS
AUTONOMOUS
Definition
RobotMode.java:12
org.wpilib.hardware.hal.RobotMode.TELEOPERATED
TELEOPERATED
Definition
RobotMode.java:14
org.wpilib.hardware.hal.RobotMode.UTILITY
UTILITY
Definition
RobotMode.java:16
org.wpilib.command3.BindingScope.RobotModeScope
Definition
BindingScope.java:92
org.wpilib.command3.BindingScope
Definition
BindingScope.java:14
org.wpilib.command3.BindingScope.active
boolean active()
org.wpilib.command3.BindingScope.ForOpmode
record ForOpmode(long opmodeId) implements BindingScope
Definition
BindingScope.java:85
org.wpilib.command3.BindingScope.createNarrowestScope
static BindingScope createNarrowestScope(Scheduler scheduler)
Definition
BindingScope.java:29
org.wpilib.command3.BindingScope.ForCommand
record ForCommand(Scheduler scheduler, Command command) implements BindingScope
Definition
BindingScope.java:73
org.wpilib.command3.Command
Definition
Command.java:98
org
wpilib
command3
BindingScope.java
Generated by
1.18.0