This commit is contained in:
Michael Mikovsky
2026-01-29 18:02:04 -07:00
parent fe412d0981
commit 0cc2d423fe
6 changed files with 128 additions and 94 deletions
@@ -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());