Skip to content

Commit

Permalink
Add radio LED methods to shim
Browse files Browse the repository at this point in the history
  • Loading branch information
jwbonner committed Jan 6, 2024
1 parent db6772d commit c00488a
Showing 1 changed file with 61 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.littletonrobotics.junction.inputs.LoggedSystemStats;

import edu.wpi.first.hal.HALUtil;
import edu.wpi.first.hal.LEDJNI;
import edu.wpi.first.hal.PowerJNI;
import edu.wpi.first.hal.can.CANStatus;

Expand Down Expand Up @@ -346,6 +347,66 @@ public static double getCPUTemp() {
return LoggedSystemStats.getInputs().cpuTemp;
}

/** State for the radio led. */
public enum RadioLEDState {
/** Off. */
kOff(LEDJNI.RADIO_LED_STATE_OFF),
/** Green. */
kGreen(LEDJNI.RADIO_LED_STATE_GREEN),
/** Red. */
kRed(LEDJNI.RADIO_LED_STATE_RED),
/** Orange. */
kOrange(LEDJNI.RADIO_LED_STATE_ORANGE);

/** The native value for this state. */
public final int value;

RadioLEDState(int value) {
this.value = value;
}

/**
* Gets a state from an int value.
*
* @param value int value
* @return state
*/
public static RadioLEDState fromValue(int value) {
switch (value) {
case LEDJNI.RADIO_LED_STATE_OFF:
return RadioLEDState.kOff;
case LEDJNI.RADIO_LED_STATE_GREEN:
return RadioLEDState.kGreen;
case LEDJNI.RADIO_LED_STATE_RED:
return RadioLEDState.kRed;
case LEDJNI.RADIO_LED_STATE_ORANGE:
return RadioLEDState.kOrange;
default:
return RadioLEDState.kOff;
}
}
}

/**
* Set the state of the "Radio" LED. On the RoboRIO, this writes to sysfs, so this function should
* not be called multiple times per loop cycle to avoid overruns.
*
* @param state The state to set the LED to.
*/
public static void setRadioLEDState(RadioLEDState state) {
LEDJNI.setRadioLEDState(state.value);
}

/**
* Get the state of the "Radio" LED. On the RoboRIO, this reads from sysfs, so this function
* should not be called multiple times per loop cycle to avoid overruns.
*
* @return The state of the LED.
*/
public static RadioLEDState getRadioLEDState() {
return RadioLEDState.fromValue(LEDJNI.getRadioLEDState());
}

/**
* Get the current status of the CAN bus.
*
Expand Down

0 comments on commit c00488a

Please sign in to comment.