forked from Team254/FRC-2019-Public
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TimedLEDState.java
61 lines (49 loc) · 2.61 KB
/
TimedLEDState.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package com.team254.frc2019.states;
public interface TimedLEDState {
void getCurrentLEDState(LEDState desiredState, double timestamp);
class BlinkingLEDState implements TimedLEDState {
public static BlinkingLEDState kZeroingFault = new BlinkingLEDState(
LEDState.kOff, LEDState.kFault, 1.0);
public static BlinkingLEDState kJustZeroed = new BlinkingLEDState(
LEDState.kOff, LEDState.kRobotZeroed, 0.250);
public static BlinkingLEDState kBlinkingIntakeCargo = new BlinkingLEDState(
LEDState.kOff, LEDState.kIntakeIntakingCargo, 0.1);
public static BlinkingLEDState kBlinkingIntakingDisk = new BlinkingLEDState(
LEDState.kOff, LEDState.kIntakeIntakingDisk, 0.1);
public static BlinkingLEDState kHangNoPressure = new BlinkingLEDState(
LEDState.kOff, LEDState.kHanging, 0.5);
LEDState mStateOne = new LEDState(0.0, 0.0, 0.0);
LEDState mStateTwo = new LEDState(0.0, 0.0, 0.0);
double mDuration;
public BlinkingLEDState(LEDState stateOne, LEDState stateTwo, double duration) {
mStateOne.copyFrom(stateOne);
mStateTwo.copyFrom(stateTwo);
mDuration = duration;
}
@Override
public void getCurrentLEDState(LEDState desiredState, double timestamp) {
if ((int) (timestamp / mDuration) % 2 == 0) {
desiredState.copyFrom(mStateOne);
} else {
desiredState.copyFrom(mStateTwo);
}
}
}
class StaticLEDState implements TimedLEDState {
public static StaticLEDState kStaticOff = new StaticLEDState(LEDState.kOff);
public static StaticLEDState kIntakingDisk = new StaticLEDState(LEDState.kIntakeIntakingDisk);
public static StaticLEDState kIntakingCargo = new StaticLEDState(LEDState.kIntakeIntakingCargo);
public static StaticLEDState kExhausting = new StaticLEDState(LEDState.kIntakeExhuasting);
public static StaticLEDState kRobotZeroed = new StaticLEDState(LEDState.kRobotZeroed);
public static StaticLEDState kHangMinimalPressure = new StaticLEDState(LEDState.kMinimalPressure);
public static StaticLEDState kHangOptimalPressure = new StaticLEDState(LEDState.kOptimalPressure);
LEDState mStaticState = new LEDState(0.0, 0.0, 0.0);
public StaticLEDState(LEDState staticState) {
mStaticState.copyFrom(staticState);
}
@Override
public void getCurrentLEDState(LEDState desiredState, double timestamp) {
desiredState.copyFrom(mStaticState);
}
}
}