Skip to content

Commit

Permalink
add extern C
Browse files Browse the repository at this point in the history
  • Loading branch information
rzblue committed Dec 22, 2023
1 parent f0db2f3 commit 0203c83
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions hal/src/main/native/athena/LEDs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ static const fs::path radioLEDRedFilePath =
static const char* onStr = "1";
static const char* offStr = "0";

extern "C" {
void HAL_SetRadioLEDState(HAL_RadioLEDState state, int32_t* status) {
std::error_code ec;
fs::file_t greenFile = fs::OpenFileForWrite(radioLEDGreenFilePath, ec,
Expand All @@ -49,3 +50,5 @@ void HAL_SetRadioLEDState(HAL_RadioLEDState state, int32_t* status) {
fs::CloseFile(greenFile);
fs::CloseFile(redFile);
}

} // extern "C"
3 changes: 3 additions & 0 deletions hal/src/main/native/cpp/jni/LEDJNI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ 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
Expand All @@ -31,3 +33,4 @@ Java_edu_wpi_first_hal_LEDJNI_setRadioLEDState
HAL_SetRadioLEDState(static_cast<HAL_RadioLEDState>(state), &status);
CheckStatus(env, status);
}
} // extern "C"
7 changes: 7 additions & 0 deletions hal/src/main/native/include/hal/LEDs.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,16 @@
HAL_ENUM(HAL_RadioLEDState){HAL_RadioLED_kOff = 0, HAL_RadioLED_kGreen = 1,
HAL_RadioLED_kRed = 2, HAL_RadioLED_kOrange = 3};

#ifdef __cplusplus
extern "C" {
#endif
/**
* Set the state of the "Radio" LED.
* @param state The state to set the LED to.
* @param[out] status the error code, or 0 for success
*/
void HAL_SetRadioLEDState(HAL_RadioLEDState state, int32_t* status);

#ifdef __cplusplus
} // extern "C"
#endif
4 changes: 4 additions & 0 deletions hal/src/main/native/sim/LEDs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ namespace hal::init {
void InitializeLEDs() {}
} // namespace hal::init

extern "C" {

void HAL_SetRadioLEDState(HAL_RadioLEDState state, int32_t* status) {
HALSIM_SetRoboRioRadioLEDState(state);
}

} // extern "C"

0 comments on commit 0203c83

Please sign in to comment.