-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LED Light thing, not tested yet. Also RunForTask
- Loading branch information
1 parent
5d0981a
commit 00315e3
Showing
2 changed files
with
84 additions
and
2 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
src/main/java/org/murraybridgebunyips/bunyipslib/subsystems/BlinkinLights.java
This file contains 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,61 @@ | ||
package org.murraybridgebunyips.bunyipslib.subsystems; | ||
|
||
import com.qualcomm.hardware.rev.RevBlinkinLedDriver; | ||
|
||
import org.murraybridgebunyips.bunyipslib.BunyipsSubsystem; | ||
import org.murraybridgebunyips.bunyipslib.external.units.Measure; | ||
import org.murraybridgebunyips.bunyipslib.external.units.Time; | ||
import org.murraybridgebunyips.bunyipslib.tasks.RunForTask; | ||
import org.murraybridgebunyips.bunyipslib.tasks.bases.Task; | ||
|
||
public class BlinkinLights extends BunyipsSubsystem { | ||
This comment has been minimized.
Sorry, something went wrong. |
||
private final RevBlinkinLedDriver lights; | ||
private final RevBlinkinLedDriver.BlinkinPattern defaultPattern; | ||
private RevBlinkinLedDriver.BlinkinPattern currentPattern; | ||
|
||
public BlinkinLights(RevBlinkinLedDriver light, RevBlinkinLedDriver.BlinkinPattern defaultBlinkPattern) { | ||
lights = light; | ||
defaultPattern = defaultBlinkPattern; | ||
currentPattern = defaultBlinkPattern; | ||
|
||
lights.setPattern(defaultPattern); | ||
} | ||
|
||
public void setPattern(RevBlinkinLedDriver.BlinkinPattern pattern) { | ||
currentPattern = pattern; | ||
} | ||
|
||
public Task setPatternForTask(Measure<Time> duration, RevBlinkinLedDriver.BlinkinPattern pattern) { | ||
return new RunForTask(duration, () -> currentPattern = pattern, this::resetPattern) | ||
.onSubsystem(this, true) | ||
.withName("Lights:" + pattern.name()); | ||
} | ||
|
||
public RevBlinkinLedDriver.BlinkinPattern getPattern() { | ||
return currentPattern; | ||
} | ||
|
||
public void resetPattern() { | ||
currentPattern = defaultPattern; | ||
} | ||
|
||
public void turnOff() { | ||
currentPattern = RevBlinkinLedDriver.BlinkinPattern.BLACK; | ||
} | ||
|
||
@Override | ||
protected void onDisable() { | ||
turnOff(); | ||
} | ||
|
||
@Override | ||
protected void onEnable() { | ||
currentPattern = defaultPattern; | ||
} | ||
|
||
@Override | ||
protected void periodic() { | ||
opMode.telemetry.add("Current Pattern:" + currentPattern.name()); | ||
lights.setPattern(currentPattern); | ||
} | ||
} |
This file contains 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
add docs