-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLEDManager.java
More file actions
97 lines (83 loc) · 3.33 KB
/
LEDManager.java
File metadata and controls
97 lines (83 loc) · 3.33 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package frc.robot.subsystems;
import java.util.ArrayList;
import edu.wpi.first.wpilibj.AddressableLED;
import edu.wpi.first.wpilibj.AddressableLEDBuffer;
import edu.wpi.first.wpilibj.AddressableLEDBufferView;
import frc.robot.util.LEDs.LEDConfiguration;
/**
* <h2> LEDManager </h2>
* The LEDManager class is a class that allows for LEDs to be easily controlled and configured to
* several preset configurations. This simplifies communicating information to the driver, as
* complex actions can be communicated through unique LED Patterns. Below is a breakdown of all
* these patterns:
* <ul>
* <li> <strong> Purple Pulsing: </strong> Manual drive active </li>
* <li> <strong> Solid Red: </strong> Program stopped </li>
* <li> <strong> Rainbow Blinking: </strong> Victory dance </li>
* <li> <strong> Orange-Blue-Magenta Gradient: </strong> Autonomously scoring coral </li>
* <li> <strong> Light-Dark Green Gradient: </strong> Autonomously scoring algae </li>
* <li> <strong> Dark Red Blinking: </strong> Autoscoring failure </li>
* <li> <strong> Light Pink Breathing: </strong> Autonomously grabbing coral </li>
* </ul>
* <hr>
* @author Kinjal Bhardwa
* @author Cameron Myhre
* @since v1.2.0
*/
public class LEDManager {
private static LEDManager instance;
// Hardware
private AddressableLED ledStrip;
private AddressableLEDBuffer ledBuffer;
/**
* returns the singleton object of the LED Manager
* @return the singleton object
*/
public static LEDManager getInstance() {
if (instance == null) {
throw new IllegalStateException("LEDManager has not been initialized. Call initialize() first.");
}
return instance;
}
/**
* initialized the LEDManager object using the provided PWM port number and length.
*
* @param port The port number the LED strip is plugged into on the PWM.
* @param length The number of LEDs in the strip
*/
public static void initialize(int port, int length) {
if (instance != null) {
throw new IllegalStateException("LEDManager has already been initialized.");
}
instance = new LEDManager(port, length);
}
/**
* Creates a new LEDManager object using the provided PWM port number and length.
*
* @param port The port number the LED strip is plugged into on the PWM.
* @param length The number of LEDs in the strip
*/
private LEDManager(int port, int length) {
// Create new AddressableLED and AddressableLEDBuffer objects.
this.ledStrip = new AddressableLED(port);
this.ledBuffer = new AddressableLEDBuffer(length);
// Setup the LED strip hardware
this.ledStrip.setLength(this.ledBuffer.getLength());
this.ledStrip.setData(ledBuffer);
this.ledStrip.start();
}
/**
* creates a view to control a segment of the led strip
* @param ledSegment the segment to create the view out of
* @return the view to control the segment
*/
public static AddressableLEDBufferView getViewForSegment(LEDSegment ledSegment) {
return instance.ledBuffer.createView(ledSegment.getStartingIndex(),ledSegment.getEndingIndex());
}
/**
* updates the LED strip.
*/
public static void update() {
instance.ledStrip.setData(instance.ledBuffer);
}
}