diff --git a/hal/src/main/java/edu/wpi/first/hal/LEDJNI.java b/hal/src/main/java/edu/wpi/first/hal/LEDJNI.java new file mode 100644 index 00000000000..592de5a74f1 --- /dev/null +++ b/hal/src/main/java/edu/wpi/first/hal/LEDJNI.java @@ -0,0 +1,22 @@ +// Copyright (c) FIRST and other WPILib contributors. +// Open Source Software; you can modify and/or share it under the terms of +// the WPILib BSD license file in the root directory of this project. + +package edu.wpi.first.hal; + +public class LEDJNI extends JNIWrapper { + public enum RadioLEDState { + kOff(0), + kGreen(1), + kRed(2), + kOrange(3); + + final int m_value; + + RadioLEDState(int value) { + m_value = value; + } + } + + public static native void setRadioLEDState(int state); +} diff --git a/hal/src/main/native/athena/LEDs.cpp b/hal/src/main/native/athena/LEDs.cpp new file mode 100644 index 00000000000..8e82159a3e1 --- /dev/null +++ b/hal/src/main/native/athena/LEDs.cpp @@ -0,0 +1,42 @@ +// Copyright (c) FIRST and other WPILib contributors. +// Open Source Software; you can modify and/or share it under the terms of +// the WPILib BSD license file in the root directory of this project. + +#include + +#include + +#include + +#include "hal/Errors.h" +#include "hal/HALBase.h" + +static const fs::path radioLEDGreenFilePath = + "/sys/class/leds/nilrt:wifi:primary/brightness"; +static const fs::path radioLEDRedFilePath = + "/sys/class/leds/nilrt:wifi:secondary/brightness"; + +static const char* onStr = "1"; +static const char* offStr = "0"; + +void HAL_SetRadioLEDState(HAL_RadioLEDState state, int32_t* status) { + std::error_code ec; + fs::file_t greenFile = fs::OpenFileForWrite(radioLEDGreenFilePath, ec, + fs::CD_OpenExisting, fs::OF_Text); + if (ec) { + *status = INCOMPATIBLE_STATE; + return; + } + fs::file_t redFile = fs::OpenFileForWrite(radioLEDRedFilePath, ec, + fs::CD_OpenExisting, fs::OF_Text); + if (ec) { + *status = INCOMPATIBLE_STATE; + return; + } + + write(greenFile, state & HAL_RadioLED_kGreen ? onStr : offStr, 1); + write(redFile, state & HAL_RadioLED_kRed ? onStr : offStr, 1); + + fs::CloseFile(greenFile); + fs::CloseFile(redFile); +} diff --git a/hal/src/main/native/cpp/jni/LEDJNI.cpp b/hal/src/main/native/cpp/jni/LEDJNI.cpp new file mode 100644 index 00000000000..7aad13827cf --- /dev/null +++ b/hal/src/main/native/cpp/jni/LEDJNI.cpp @@ -0,0 +1,24 @@ +// Copyright (c) FIRST and other WPILib contributors. +// Open Source Software; you can modify and/or share it under the terms of +// the WPILib BSD license file in the root directory of this project. + +#include + +#include "HALUtil.h" +#include "edu_wpi_first_hal_LEDJNI.h" +#include "hal/HALBase.h" + +using namespace hal; +/* + * Class: edu_wpi_first_hal_LEDJNI + * Method: setRadioLEDState + * Signature: (I)V + */ +JNIEXPORT void JNICALL +Java_edu_wpi_first_hal_LEDJNI_setRadioLEDState + (JNIEnv* env, jclass, jint state) +{ + int32_t status = 0; + HAL_SetRadioLEDState((HAL_RadioLEDState)state, &status); + CheckStatus(env, status); +} diff --git a/hal/src/main/native/include/hal/HALBase.h b/hal/src/main/native/include/hal/HALBase.h index fe8d1bf190e..4c0eec1b534 100644 --- a/hal/src/main/native/include/hal/HALBase.h +++ b/hal/src/main/native/include/hal/HALBase.h @@ -240,6 +240,11 @@ void HAL_SimPeriodicBefore(void); */ void HAL_SimPeriodicAfter(void); +HAL_ENUM(HAL_RadioLEDState){HAL_RadioLED_kOFF = 0, HAL_RadioLED_kGreen = 1, + HAL_RadioLED_kRed = 2, HAL_RadioLED_kOrange = 3}; + +void HAL_SetRadioLEDState(HAL_RadioLEDState state, int32_t* status); + #ifdef __cplusplus } // extern "C" #endif diff --git a/hal/src/main/native/sim/LEDs.cpp b/hal/src/main/native/sim/LEDs.cpp new file mode 100644 index 00000000000..60eab2c5662 --- /dev/null +++ b/hal/src/main/native/sim/LEDs.cpp @@ -0,0 +1,7 @@ +// Copyright (c) FIRST and other WPILib contributors. +// Open Source Software; you can modify and/or share it under the terms of +// the WPILib BSD license file in the root directory of this project. + +#include "hal/HALBase.h" + +void HAL_SetRadioLEDState(HAL_RadioLEDState state, int32_t* status) {}