From 9ab7f8591cff83ebee1760b68314e8004bf05d74 Mon Sep 17 00:00:00 2001 From: Kevin Cooney Date: Sat, 8 Mar 2025 21:21:16 -0800 Subject: [PATCH 1/7] Lightshow cleanups - Make fields final that can be final - Set an initial value for defaultState. --- .../com/team2813/lib2813/subsystems/lightshow/Lightshow.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/src/main/java/com/team2813/lib2813/subsystems/lightshow/Lightshow.java b/lib/src/main/java/com/team2813/lib2813/subsystems/lightshow/Lightshow.java index 87d63c24..01b5f969 100644 --- a/lib/src/main/java/com/team2813/lib2813/subsystems/lightshow/Lightshow.java +++ b/lib/src/main/java/com/team2813/lib2813/subsystems/lightshow/Lightshow.java @@ -37,8 +37,8 @@ public boolean apply() { } }; - protected Set states = new HashSet<>(); - protected Optional defaultState; + protected final Set states = new HashSet<>(); + protected Optional defaultState = Optional.empty(); /** * Creates a new Lightshow subsystem using an enum. Uses the given {@code enumClass} to get a list From d43cf04da74487e94303a7b0bd8b6ba86c03b22b Mon Sep 17 00:00:00 2001 From: Kevin Cooney Date: Sat, 17 Jan 2026 11:16:04 -0800 Subject: [PATCH 2/7] Improve JavaDoc --- .../lib2813/subsystems/lightshow/Lightshow.java | 10 +++++++++- .../lib2813/subsystems/lightshow/QueueLightshow.java | 6 +++++- .../team2813/lib2813/subsystems/lightshow/State.java | 2 +- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/src/main/java/com/team2813/lib2813/subsystems/lightshow/Lightshow.java b/lib/src/main/java/com/team2813/lib2813/subsystems/lightshow/Lightshow.java index 01b5f969..1d5775b0 100644 --- a/lib/src/main/java/com/team2813/lib2813/subsystems/lightshow/Lightshow.java +++ b/lib/src/main/java/com/team2813/lib2813/subsystems/lightshow/Lightshow.java @@ -60,7 +60,15 @@ protected Lightshow(Set states) { addStates(states); } - protected abstract void useColor(Color c); + /** + * Sets the lights to the provided color. + * + *

Subclasses should override this to display the provided color. For example, the value could + * be passed to {@link com.ctre.phoenix.CANifier#setLEDOutput(double, LEDChannel)}. + * + * @param color Color to display + */ + protected abstract void useColor(Color color); public final & State> void addStates(Class enumClass) { T[] constants = enumClass.getEnumConstants(); diff --git a/lib/src/main/java/com/team2813/lib2813/subsystems/lightshow/QueueLightshow.java b/lib/src/main/java/com/team2813/lib2813/subsystems/lightshow/QueueLightshow.java index 19ac3607..5e3ce5c2 100644 --- a/lib/src/main/java/com/team2813/lib2813/subsystems/lightshow/QueueLightshow.java +++ b/lib/src/main/java/com/team2813/lib2813/subsystems/lightshow/QueueLightshow.java @@ -25,10 +25,14 @@ * A lightshow that keeps track of the states that have been applied, and uses the last state. To be * more specific, all states that return {@code true} on a call to {@link State#apply()} are added * to the list. States are only removed from the list if they are at the front and {@link - * State#apply()} returns {@code false}, when a state is removed, the next one will be activated if + * State#apply()} returns {@code false}. When a state is removed, the next one will be activated if * {@link State#apply()} returns {@code true}, until either a state returns {@code true} upon a call * to {@link State#apply()}, in which the color will be used, or there are no states where {@link * State#apply()} return {@code true}, then the default color is used. + * + *

For example usage, see FRC Team 2813's 2024 robot code. */ public abstract class QueueLightshow extends Lightshow { private final Deque activatedStates = new ArrayDeque<>(); diff --git a/lib/src/main/java/com/team2813/lib2813/subsystems/lightshow/State.java b/lib/src/main/java/com/team2813/lib2813/subsystems/lightshow/State.java index 22b19ad2..97e4aa60 100644 --- a/lib/src/main/java/com/team2813/lib2813/subsystems/lightshow/State.java +++ b/lib/src/main/java/com/team2813/lib2813/subsystems/lightshow/State.java @@ -19,7 +19,7 @@ public interface State { /** - * gets the color of this State. + * Gets the color of this State. * * @return the color of this State */ From ee63506ac716ab766d93919b6ad597a7951a1f3d Mon Sep 17 00:00:00 2001 From: Kevin Cooney Date: Sat, 17 Jan 2026 11:34:38 -0800 Subject: [PATCH 3/7] Rename State.apply() to isActive() --- .../lib2813/subsystems/lightshow/Lightshow.java | 2 +- .../subsystems/lightshow/QueueLightshow.java | 16 ++++++++-------- .../lib2813/subsystems/lightshow/State.java | 6 +++--- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/src/main/java/com/team2813/lib2813/subsystems/lightshow/Lightshow.java b/lib/src/main/java/com/team2813/lib2813/subsystems/lightshow/Lightshow.java index 1d5775b0..bd0cb947 100644 --- a/lib/src/main/java/com/team2813/lib2813/subsystems/lightshow/Lightshow.java +++ b/lib/src/main/java/com/team2813/lib2813/subsystems/lightshow/Lightshow.java @@ -32,7 +32,7 @@ public Color color() { return new Color(0, 0, 0); } - public boolean apply() { + public boolean isActive() { return true; } }; diff --git a/lib/src/main/java/com/team2813/lib2813/subsystems/lightshow/QueueLightshow.java b/lib/src/main/java/com/team2813/lib2813/subsystems/lightshow/QueueLightshow.java index 5e3ce5c2..99a450ee 100644 --- a/lib/src/main/java/com/team2813/lib2813/subsystems/lightshow/QueueLightshow.java +++ b/lib/src/main/java/com/team2813/lib2813/subsystems/lightshow/QueueLightshow.java @@ -23,12 +23,12 @@ /** * A lightshow that keeps track of the states that have been applied, and uses the last state. To be - * more specific, all states that return {@code true} on a call to {@link State#apply()} are added - * to the list. States are only removed from the list if they are at the front and {@link - * State#apply()} returns {@code false}. When a state is removed, the next one will be activated if - * {@link State#apply()} returns {@code true}, until either a state returns {@code true} upon a call - * to {@link State#apply()}, in which the color will be used, or there are no states where {@link - * State#apply()} return {@code true}, then the default color is used. + * more specific, all states that return {@code true} on a call to {@link State#isActive()} are + * added to the list. States are only removed from the list if they are at the front and {@link + * State#isActive()} returns {@code false}. When a state is removed, the next one will be activated + * if {@link State#isActive()} returns {@code true}, until either a state returns {@code true} upon + * a call to {@link State#isActive()}, in which the color will be used, or there are no states where + * {@link State#isActive()} return {@code true}, then the default color is used. * *

For example usage, see FRC Team 2813's states) { @Override protected Optional update() { for (State s : states) { - if (!activatedStates.contains(s) && s.apply()) { + if (!activatedStates.contains(s) && s.isActive()) { activatedStates.addFirst(s); } } while (!activatedStates.isEmpty()) { State s = activatedStates.poll(); - if (s.apply()) { + if (s.isActive()) { activatedStates.addFirst(s); return Optional.of(s.color()); } diff --git a/lib/src/main/java/com/team2813/lib2813/subsystems/lightshow/State.java b/lib/src/main/java/com/team2813/lib2813/subsystems/lightshow/State.java index 97e4aa60..be9a0672 100644 --- a/lib/src/main/java/com/team2813/lib2813/subsystems/lightshow/State.java +++ b/lib/src/main/java/com/team2813/lib2813/subsystems/lightshow/State.java @@ -26,9 +26,9 @@ public interface State { Color color(); /** - * Checks if the current state should be applied + * Checks if the current state is active. * - * @return {@code true} if the state should be applied + * @return {@code true} if the state is active */ - boolean apply(); + boolean isActive(); } From bf70daf3888287f8ffa5a2f1c285d6182bbdae22 Mon Sep 17 00:00:00 2001 From: Kevin Cooney Date: Sat, 17 Jan 2026 12:01:59 -0800 Subject: [PATCH 4/7] Add comments; replace call to poll() to removeFirst() for clarity --- .../lib2813/subsystems/lightshow/QueueLightshow.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/src/main/java/com/team2813/lib2813/subsystems/lightshow/QueueLightshow.java b/lib/src/main/java/com/team2813/lib2813/subsystems/lightshow/QueueLightshow.java index 99a450ee..78856d03 100644 --- a/lib/src/main/java/com/team2813/lib2813/subsystems/lightshow/QueueLightshow.java +++ b/lib/src/main/java/com/team2813/lib2813/subsystems/lightshow/QueueLightshow.java @@ -51,13 +51,13 @@ public QueueLightshow(Set states) { protected Optional update() { for (State s : states) { if (!activatedStates.contains(s) && s.isActive()) { - activatedStates.addFirst(s); + activatedStates.addFirst(s); // Push } } while (!activatedStates.isEmpty()) { - State s = activatedStates.poll(); + State s = activatedStates.removeFirst(); // Pop if (s.isActive()) { - activatedStates.addFirst(s); + activatedStates.addFirst(s); // Push return Optional.of(s.color()); } } From d8ef3dbf38a982344d197b14860936d68c0965af Mon Sep 17 00:00:00 2001 From: Kevin Cooney Date: Sat, 31 Jan 2026 19:28:53 -0800 Subject: [PATCH 5/7] Add comments and minor cleanup in QueueLightshow.update() --- .../subsystems/lightshow/QueueLightshow.java | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/lib/src/main/java/com/team2813/lib2813/subsystems/lightshow/QueueLightshow.java b/lib/src/main/java/com/team2813/lib2813/subsystems/lightshow/QueueLightshow.java index 78856d03..0f080a40 100644 --- a/lib/src/main/java/com/team2813/lib2813/subsystems/lightshow/QueueLightshow.java +++ b/lib/src/main/java/com/team2813/lib2813/subsystems/lightshow/QueueLightshow.java @@ -49,18 +49,28 @@ public QueueLightshow(Set states) { @Override protected Optional update() { + // NOTE: Even though this class is called QueueLightshow, we are treating activatedStates as a + // stack, not a queue. + + // If new States become active, push them, so we change the color. for (State s : states) { if (!activatedStates.contains(s) && s.isActive()) { activatedStates.addFirst(s); // Push } } - while (!activatedStates.isEmpty()) { - State s = activatedStates.removeFirst(); // Pop + + // Pick the color to display. We start with the State that was most recently pushed, so the + // color returned changes when a either a State transitions to active or when the State + // associated with the previous color transitioned to inactive. + do { + State s = activatedStates.peekFirst(); + if (s == null) { + return Optional.empty(); // No states active. The lightshow is over. 😿 + } if (s.isActive()) { - activatedStates.addFirst(s); // Push return Optional.of(s.color()); } - } - return Optional.empty(); + activatedStates.removeFirst(); // Pop + } while (true); } } From 6f68c60ab314f88ea7022d8cd79fee939262c394 Mon Sep 17 00:00:00 2001 From: Kevin Cooney Date: Sat, 31 Jan 2026 19:39:25 -0800 Subject: [PATCH 6/7] Run ./gradlew spotlessApply --- .../com/team2813/lib2813/subsystems/lightshow/Lightshow.java | 2 +- .../team2813/lib2813/subsystems/lightshow/QueueLightshow.java | 2 +- .../java/com/team2813/lib2813/subsystems/lightshow/State.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/src/main/java/com/team2813/lib2813/subsystems/lightshow/Lightshow.java b/lib/src/main/java/com/team2813/lib2813/subsystems/lightshow/Lightshow.java index bd0cb947..8c5c7ec7 100644 --- a/lib/src/main/java/com/team2813/lib2813/subsystems/lightshow/Lightshow.java +++ b/lib/src/main/java/com/team2813/lib2813/subsystems/lightshow/Lightshow.java @@ -1,5 +1,5 @@ /* -Copyright 2024-2025 Prospect Robotics SWENext Club +Copyright 2024-2026 Prospect Robotics SWENext Club Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/lib/src/main/java/com/team2813/lib2813/subsystems/lightshow/QueueLightshow.java b/lib/src/main/java/com/team2813/lib2813/subsystems/lightshow/QueueLightshow.java index 0f080a40..83b7ac77 100644 --- a/lib/src/main/java/com/team2813/lib2813/subsystems/lightshow/QueueLightshow.java +++ b/lib/src/main/java/com/team2813/lib2813/subsystems/lightshow/QueueLightshow.java @@ -1,5 +1,5 @@ /* -Copyright 2024-2025 Prospect Robotics SWENext Club +Copyright 2024-2026 Prospect Robotics SWENext Club Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/lib/src/main/java/com/team2813/lib2813/subsystems/lightshow/State.java b/lib/src/main/java/com/team2813/lib2813/subsystems/lightshow/State.java index be9a0672..27045293 100644 --- a/lib/src/main/java/com/team2813/lib2813/subsystems/lightshow/State.java +++ b/lib/src/main/java/com/team2813/lib2813/subsystems/lightshow/State.java @@ -1,5 +1,5 @@ /* -Copyright 2024-2025 Prospect Robotics SWENext Club +Copyright 2024-2026 Prospect Robotics SWENext Club Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. From 0aa59dae3319479a23a5e779865b918b0f18028e Mon Sep 17 00:00:00 2001 From: Kevin Cooney Date: Sat, 31 Jan 2026 19:49:02 -0800 Subject: [PATCH 7/7] Improve class Javadoc for QueueLightshow --- .../lib2813/subsystems/lightshow/QueueLightshow.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/src/main/java/com/team2813/lib2813/subsystems/lightshow/QueueLightshow.java b/lib/src/main/java/com/team2813/lib2813/subsystems/lightshow/QueueLightshow.java index 83b7ac77..6ad33607 100644 --- a/lib/src/main/java/com/team2813/lib2813/subsystems/lightshow/QueueLightshow.java +++ b/lib/src/main/java/com/team2813/lib2813/subsystems/lightshow/QueueLightshow.java @@ -22,9 +22,10 @@ import java.util.Set; /** - * A lightshow that keeps track of the states that have been applied, and uses the last state. To be - * more specific, all states that return {@code true} on a call to {@link State#isActive()} are - * added to the list. States are only removed from the list if they are at the front and {@link + * A lightshow that changes color when a State transitions from inactive to active. + * + *

All states that return {@code true} on a call to {@link State#isActive()} are pushed to a + * deque. States are only removed from the deque if they are at the front and {@link * State#isActive()} returns {@code false}. When a state is removed, the next one will be activated * if {@link State#isActive()} returns {@code true}, until either a state returns {@code true} upon * a call to {@link State#isActive()}, in which the color will be used, or there are no states where