Skip to content

Commit 0c14446

Browse files
committed
Code cleanup
1 parent 7383de3 commit 0c14446

File tree

2 files changed

+22
-24
lines changed

2 files changed

+22
-24
lines changed

src/main/java/org/lasarobotics/led/LEDStrip.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ public static Hardware initializeHardware(ID id) {
140140
return ledStripHardware;
141141
}
142142

143+
/**
144+
* Run animation on LED strip
145+
*/
143146
void runAnimation() {
144147
m_sectionLEDPatterns.entrySet().stream().forEach(entry -> {
145148
for (var section : entry.getKey()) entry.getValue().applyTo(SECTION_MAP.get(section));
@@ -210,7 +213,7 @@ void off() {
210213
* Get latest LED buffer
211214
* @return Addressable LED buffer
212215
*/
213-
public AddressableLEDBuffer getBuffer() {
216+
AddressableLEDBuffer getBuffer() {
214217
return m_ledBuffer;
215218
}
216219

src/test/java/org/lasarobotics/led/LEDSubsystemTest.java

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ public class LEDSubsystemTest {
2727
private final int LENGTH = 31;
2828
private final int MIDDLE_START = 11;
2929
private final int MIDDLE_END = 21;
30-
private LEDSubsystem m_ledSubsystem;
3130

3231
private LEDStrip m_ledStrip1;
3332

@@ -46,28 +45,24 @@ public void setup() {
4645
// Create LED strip objects
4746
m_ledStrip1 = new LEDStrip(new LEDStrip.Hardware(m_leds1));
4847

49-
// Create LEDSubsystem object
50-
m_ledSubsystem = LEDSubsystem.getInstance();
51-
5248
// Set LED strip for subsystem
53-
m_ledSubsystem.setLEDStrip(m_ledStrip1);
49+
LEDSubsystem.getInstance().setLEDStrip(m_ledStrip1);
5450
}
5551

5652
@AfterEach
5753
public void close() {
58-
m_ledSubsystem.close();
59-
m_ledSubsystem = null;
54+
LEDSubsystem.getInstance().close();
6055
}
6156

6257
@Test
6358
@Order(1)
6459
@DisplayName("Test if robot can set LED strip to single static solid color")
6560
public void solidFull() {
6661
// Set LED pattern
67-
m_ledSubsystem.set(LEDPattern.solid(LEDStrip.TEAM_COLOR), LEDStrip.Section.FULL);
62+
LEDSubsystem.getInstance().set(LEDPattern.solid(LEDStrip.TEAM_COLOR), LEDStrip.Section.FULL);
6863

6964
// Run LED subsystem loop
70-
m_ledSubsystem.getDefaultCommand().execute();
65+
LEDSubsystem.getInstance().getDefaultCommand().execute();
7166

7267
Color ledBuffer[] = new Color[LENGTH];
7368
for (int i = 0; i < ledBuffer.length; i++) ledBuffer[i] = m_ledStrip1.getBuffer().getLED(i);
@@ -82,11 +77,11 @@ public void solidFull() {
8277
@DisplayName("Test if robot can set LED strip start section independently")
8378
public void startSection() {
8479
// Set LED pattern
85-
m_ledSubsystem.set(LEDPattern.solid(Color.kRed), Section.START);
86-
m_ledSubsystem.set(LEDPattern.solid(LEDStrip.TEAM_COLOR), Section.MIDDLE, Section.END);
80+
LEDSubsystem.getInstance().set(LEDPattern.solid(Color.kRed), Section.START);
81+
LEDSubsystem.getInstance().set(LEDPattern.solid(LEDStrip.TEAM_COLOR), Section.MIDDLE, Section.END);
8782

8883
// Run LED subsystem loop
89-
m_ledSubsystem.getDefaultCommand().execute();
84+
LEDSubsystem.getInstance().getDefaultCommand().execute();
9085

9186
// Verify LED pattern
9287
for (int i = 0; i < MIDDLE_START; i++)
@@ -100,11 +95,11 @@ public void startSection() {
10095
@DisplayName("Test if robot can set LED strip middle section independently")
10196
public void middleSection() {
10297
// Set LED pattern
103-
m_ledSubsystem.set(LEDPattern.solid(Color.kRed), Section.MIDDLE);
104-
m_ledSubsystem.set(LEDPattern.solid(LEDStrip.TEAM_COLOR), Section.START, Section.END);
98+
LEDSubsystem.getInstance().set(LEDPattern.solid(Color.kRed), Section.MIDDLE);
99+
LEDSubsystem.getInstance().set(LEDPattern.solid(LEDStrip.TEAM_COLOR), Section.START, Section.END);
105100

106101
// Run LED subsystem loop
107-
m_ledSubsystem.getDefaultCommand().execute();
102+
LEDSubsystem.getInstance().getDefaultCommand().execute();
108103

109104
Color ledBuffer[] = new Color[LENGTH];
110105
for (int i = 0; i < ledBuffer.length; i++) ledBuffer[i] = m_ledStrip1.getBuffer().getLED(i);
@@ -123,11 +118,11 @@ public void middleSection() {
123118
@DisplayName("Test if robot can set LED strip end section independently")
124119
public void endSection() {
125120
// Set LED pattern
126-
m_ledSubsystem.set(LEDPattern.solid(Color.kRed), Section.END);
127-
m_ledSubsystem.set(LEDPattern.solid(LEDStrip.TEAM_COLOR), Section.START, Section.MIDDLE);
121+
LEDSubsystem.getInstance().set(LEDPattern.solid(Color.kRed), Section.END);
122+
LEDSubsystem.getInstance().set(LEDPattern.solid(LEDStrip.TEAM_COLOR), Section.START, Section.MIDDLE);
128123

129124
// Run LED subsystem loop
130-
m_ledSubsystem.getDefaultCommand().execute();
125+
LEDSubsystem.getInstance().getDefaultCommand().execute();
131126

132127
// Verify LED pattern
133128
for (int i = 0; i < MIDDLE_END; i++)
@@ -141,13 +136,13 @@ public void endSection() {
141136
@DisplayName("Test if robot can override subsystem LED control")
142137
public void ledOverride() {
143138
// Set LED pattern
144-
m_ledSubsystem.set(LEDPattern.solid(Color.kBlue), Section.FULL);
139+
LEDSubsystem.getInstance().set(LEDPattern.solid(Color.kBlue), Section.FULL);
145140

146141
// Request LED override
147-
m_ledSubsystem.startOverride(LEDPattern.solid(LEDStrip.TEAM_COLOR));
142+
LEDSubsystem.getInstance().startOverride(LEDPattern.solid(LEDStrip.TEAM_COLOR));
148143

149144
// Run LED subsystem loop
150-
m_ledSubsystem.getDefaultCommand().execute();
145+
LEDSubsystem.getInstance().getDefaultCommand().execute();
151146

152147
// Verify LED pattern
153148
for (int i = 0; i < LENGTH; i++)
@@ -156,10 +151,10 @@ public void ledOverride() {
156151
assertEquals(LEDStrip.TEAM_COLOR, m_ledStrip1.getBuffer().getLED(i));
157152

158153
// End LED override
159-
m_ledSubsystem.endOverride();
154+
LEDSubsystem.getInstance().endOverride();
160155

161156
// Run LED subsystem loop
162-
m_ledSubsystem.getDefaultCommand().execute();
157+
LEDSubsystem.getInstance().getDefaultCommand().execute();
163158

164159
// Verify LED pattern
165160
for (int i = 0; i < LENGTH; i++)

0 commit comments

Comments
 (0)