mirror of
https://github.com/Team4388/2026KPopRobotHunters.git
synced 2026-06-09 00:38:03 -06:00
LEDs
This commit is contained in:
@@ -10,6 +10,7 @@ package frc4388.robot.subsystems;
|
||||
import org.littletonrobotics.junction.AutoLogOutput;
|
||||
|
||||
import edu.wpi.first.wpilibj.DriverStation;
|
||||
import edu.wpi.first.wpilibj.PWM;
|
||||
import edu.wpi.first.wpilibj.motorcontrol.Spark;
|
||||
import edu.wpi.first.wpilibj2.command.SubsystemBase;
|
||||
import frc4388.robot.constants.Constants.LEDConstants;
|
||||
@@ -24,11 +25,19 @@ import frc4388.utility.structs.LEDPatterns;
|
||||
* Driver
|
||||
*/
|
||||
public class LED extends SubsystemBase implements Queryable {
|
||||
public LED() {
|
||||
private PWM m_pwm;
|
||||
|
||||
public LED(int PWMport) {
|
||||
FaultReporter.register(this);
|
||||
m_pwm = new PWM(PWMport);
|
||||
|
||||
m_pwm.setBoundsMicroseconds(2003, 1550, 1500, 1460, 999);
|
||||
m_pwm.setPeriodMultiplier(PWM.PeriodMultiplier.k1X);
|
||||
m_pwm.setSpeed(0.0);
|
||||
m_pwm.setZeroLatch();
|
||||
|
||||
}
|
||||
|
||||
private static Spark LEDController = new Spark(LEDConstants.LED_SPARK_ID);
|
||||
private LEDPatterns mode = LEDConstants.DEFAULT_PATTERN;
|
||||
|
||||
public void setMode(LEDPatterns pattern){
|
||||
@@ -41,14 +50,27 @@ public class LED extends SubsystemBase implements Queryable {
|
||||
}
|
||||
|
||||
public void update() {
|
||||
if(!LEDController.isAlive() || LEDController.isSafetyEnabled()) return;
|
||||
|
||||
if(DriverStation.isDisabled()){
|
||||
LEDController.set(LEDConstants.DEFAULT_PATTERN.getValue());
|
||||
m_pwm.setSpeed(LEDConstants.DEFAULT_PATTERN.getValue());
|
||||
}else
|
||||
LEDController.set(mode.getValue());
|
||||
m_pwm.setSpeed(mode.getValue());
|
||||
}
|
||||
|
||||
// I freaking hate unmaintained code so much
|
||||
// https://github.com/REVrobotics/Blinkin-Firmware/pull/12
|
||||
// Turns out the REV Blinkin firmware has an undocumented 'feature'
|
||||
// that means that whenever a specific pulse length is randomly generated,
|
||||
// the pulse has a chance of changing the selected strip of the Blinkin
|
||||
// 2125 μs for 5v, 2145 μs for 12v
|
||||
// Also check out: https://www.chiefdelphi.com/t/rev-blinkin-resetting-strip-mode-randomly/432510/12
|
||||
public void setTo5V() {
|
||||
try {
|
||||
m_pwm.setPulseTimeMicroseconds(2125);
|
||||
Thread.sleep(10);
|
||||
update();
|
||||
} catch (InterruptedException e) {}
|
||||
}
|
||||
|
||||
@AutoLogOutput
|
||||
public String state() {
|
||||
return mode.getClass().toString();
|
||||
@@ -63,8 +85,8 @@ public class LED extends SubsystemBase implements Queryable {
|
||||
public Status diagnosticStatus() {
|
||||
Status status = new Status();
|
||||
|
||||
if(!LEDController.isAlive())
|
||||
status.addReport(ReportLevel.ERROR, "LED is DISCONNECTED");
|
||||
// if(!LEDController.isAlive())
|
||||
// status.addReport(ReportLevel.ERROR, "LED is DISCONNECTED");
|
||||
|
||||
status.addReport(ReportLevel.INFO, "LED Mode: " + mode.name());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user