mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-21 01:01:43 +00:00
[hal,wpilib] Add function to control "Radio" LED (#6073)
This commit is contained in:
51
hal/src/main/native/cpp/jni/LEDJNI.cpp
Normal file
51
hal/src/main/native/cpp/jni/LEDJNI.cpp
Normal file
@@ -0,0 +1,51 @@
|
||||
// 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 <fmt/core.h>
|
||||
|
||||
#include "HALUtil.h"
|
||||
#include "edu_wpi_first_hal_LEDJNI.h"
|
||||
#include "hal/LEDs.h"
|
||||
|
||||
static_assert(edu_wpi_first_hal_LEDJNI_RADIO_LED_STATE_OFF ==
|
||||
HAL_RadioLEDState::HAL_RadioLED_kOff);
|
||||
static_assert(edu_wpi_first_hal_LEDJNI_RADIO_LED_STATE_GREEN ==
|
||||
HAL_RadioLEDState::HAL_RadioLED_kGreen);
|
||||
static_assert(edu_wpi_first_hal_LEDJNI_RADIO_LED_STATE_RED ==
|
||||
HAL_RadioLEDState::HAL_RadioLED_kRed);
|
||||
static_assert(edu_wpi_first_hal_LEDJNI_RADIO_LED_STATE_ORANGE ==
|
||||
HAL_RadioLEDState::HAL_RadioLED_kOrange);
|
||||
|
||||
using namespace hal;
|
||||
|
||||
extern "C" {
|
||||
/*
|
||||
* 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(static_cast<HAL_RadioLEDState>(state), &status);
|
||||
CheckStatus(env, status);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_LEDJNI
|
||||
* Method: getRadioLEDState
|
||||
* Signature: ()I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_edu_wpi_first_hal_LEDJNI_getRadioLEDState
|
||||
(JNIEnv* env, jclass)
|
||||
{
|
||||
int32_t status = 0;
|
||||
auto retVal = HAL_GetRadioLEDState(&status);
|
||||
CheckStatus(env, status);
|
||||
return retVal;
|
||||
}
|
||||
} // extern "C"
|
||||
@@ -983,6 +983,57 @@ Java_edu_wpi_first_hal_simulation_RoboRioDataJNI_setComments
|
||||
HALSIM_SetRoboRioComments(commentsJString.c_str(), commentsJString.size());
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_simulation_RoboRioDataJNI
|
||||
* Method: registerRadioLEDStateCallback
|
||||
* Signature: (Ljava/lang/Object;Z)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_edu_wpi_first_hal_simulation_RoboRioDataJNI_registerRadioLEDStateCallback
|
||||
(JNIEnv* env, jclass, jobject callback, jboolean initialNotify)
|
||||
{
|
||||
return sim::AllocateCallbackNoIndex(
|
||||
env, callback, initialNotify,
|
||||
&HALSIM_RegisterRoboRioRadioLEDStateCallback);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_simulation_RoboRioDataJNI
|
||||
* Method: cancelRadioLEDStateCallback
|
||||
* Signature: (I)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_simulation_RoboRioDataJNI_cancelRadioLEDStateCallback
|
||||
(JNIEnv* env, jclass, jint handle)
|
||||
{
|
||||
return sim::FreeCallbackNoIndex(env, handle,
|
||||
&HALSIM_CancelRoboRioRadioLEDStateCallback);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_simulation_RoboRioDataJNI
|
||||
* Method: getRadioLEDState
|
||||
* Signature: ()I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_edu_wpi_first_hal_simulation_RoboRioDataJNI_getRadioLEDState
|
||||
(JNIEnv*, jclass)
|
||||
{
|
||||
return HALSIM_GetRoboRioRadioLEDState();
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_simulation_RoboRioDataJNI
|
||||
* Method: setRadioLEDState
|
||||
* Signature: (I)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_simulation_RoboRioDataJNI_setRadioLEDState
|
||||
(JNIEnv*, jclass, jint value)
|
||||
{
|
||||
HALSIM_SetRoboRioRadioLEDState(static_cast<HAL_RadioLEDState>(value));
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_simulation_RoboRioDataJNI
|
||||
* Method: resetData
|
||||
|
||||
Reference in New Issue
Block a user