Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
viggy96 committed Jan 23, 2025
1 parent 7383de3 commit 0c14446
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 24 deletions.
5 changes: 4 additions & 1 deletion src/main/java/org/lasarobotics/led/LEDStrip.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ public static Hardware initializeHardware(ID id) {
return ledStripHardware;
}

/**
* Run animation on LED strip
*/
void runAnimation() {
m_sectionLEDPatterns.entrySet().stream().forEach(entry -> {
for (var section : entry.getKey()) entry.getValue().applyTo(SECTION_MAP.get(section));
Expand Down Expand Up @@ -210,7 +213,7 @@ void off() {
* Get latest LED buffer
* @return Addressable LED buffer
*/
public AddressableLEDBuffer getBuffer() {
AddressableLEDBuffer getBuffer() {
return m_ledBuffer;
}

Expand Down
41 changes: 18 additions & 23 deletions src/test/java/org/lasarobotics/led/LEDSubsystemTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public class LEDSubsystemTest {
private final int LENGTH = 31;
private final int MIDDLE_START = 11;
private final int MIDDLE_END = 21;
private LEDSubsystem m_ledSubsystem;

private LEDStrip m_ledStrip1;

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

// Create LEDSubsystem object
m_ledSubsystem = LEDSubsystem.getInstance();

// Set LED strip for subsystem
m_ledSubsystem.setLEDStrip(m_ledStrip1);
LEDSubsystem.getInstance().setLEDStrip(m_ledStrip1);
}

@AfterEach
public void close() {
m_ledSubsystem.close();
m_ledSubsystem = null;
LEDSubsystem.getInstance().close();
}

@Test
@Order(1)
@DisplayName("Test if robot can set LED strip to single static solid color")
public void solidFull() {
// Set LED pattern
m_ledSubsystem.set(LEDPattern.solid(LEDStrip.TEAM_COLOR), LEDStrip.Section.FULL);
LEDSubsystem.getInstance().set(LEDPattern.solid(LEDStrip.TEAM_COLOR), LEDStrip.Section.FULL);

// Run LED subsystem loop
m_ledSubsystem.getDefaultCommand().execute();
LEDSubsystem.getInstance().getDefaultCommand().execute();

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

// Run LED subsystem loop
m_ledSubsystem.getDefaultCommand().execute();
LEDSubsystem.getInstance().getDefaultCommand().execute();

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

// Run LED subsystem loop
m_ledSubsystem.getDefaultCommand().execute();
LEDSubsystem.getInstance().getDefaultCommand().execute();

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

// Run LED subsystem loop
m_ledSubsystem.getDefaultCommand().execute();
LEDSubsystem.getInstance().getDefaultCommand().execute();

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

// Request LED override
m_ledSubsystem.startOverride(LEDPattern.solid(LEDStrip.TEAM_COLOR));
LEDSubsystem.getInstance().startOverride(LEDPattern.solid(LEDStrip.TEAM_COLOR));

// Run LED subsystem loop
m_ledSubsystem.getDefaultCommand().execute();
LEDSubsystem.getInstance().getDefaultCommand().execute();

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

// End LED override
m_ledSubsystem.endOverride();
LEDSubsystem.getInstance().endOverride();

// Run LED subsystem loop
m_ledSubsystem.getDefaultCommand().execute();
LEDSubsystem.getInstance().getDefaultCommand().execute();

// Verify LED pattern
for (int i = 0; i < LENGTH; i++)
Expand Down

0 comments on commit 0c14446

Please sign in to comment.