Skip to content

Commit

Permalink
Add JNI/Java functions for power rail disable
Browse files Browse the repository at this point in the history
  • Loading branch information
rzblue committed Jul 28, 2023
1 parent e718187 commit bcf4338
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 9 deletions.
21 changes: 21 additions & 0 deletions hal/src/main/java/edu/wpi/first/hal/PowerJNI.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ public class PowerJNI extends JNIWrapper {
*/
public static native double getUserCurrent6V();

/**
* Enables or disables the 6V rail.
*
* @param enabled whether the rail should be enabled
*/
public static native void setUserEnabled6V(boolean enabled);

/**
* Gets the active state of the 6V rail.
*
Expand Down Expand Up @@ -74,6 +81,13 @@ public class PowerJNI extends JNIWrapper {
*/
public static native double getUserCurrent5V();

/**
* Enables or disables the 5V rail.
*
* @param enabled whether the rail should be enabled
*/
public static native void setUserEnabled5V(boolean enabled);

/**
* Gets the active state of the 5V rail.
*
Expand Down Expand Up @@ -106,6 +120,13 @@ public class PowerJNI extends JNIWrapper {
*/
public static native double getUserCurrent3V3();

/**
* Enables or disables the 3V3 rail.
*
* @param enabled whether the rail should be enabled
*/
public static native void setUserEnabled3V3(boolean enabled);

/**
* Gets the active state of the 3V3 rail.
*
Expand Down
21 changes: 21 additions & 0 deletions hal/src/main/native/cpp/jni/PowerJNI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ Java_edu_wpi_first_hal_PowerJNI_getUserCurrent6V
return val;
}

JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_PowerJNI_setUserEnabled6V(JNIEnv* env, jclass, jboolean enabled) {
int32_t status = 0;
HAL_SetUserRailEnabled6V(enabled, &status);
CheckStatus(env, status);
}

/*
* Class: edu_wpi_first_hal_PowerJNI
* Method: getUserActive6V
Expand Down Expand Up @@ -132,6 +139,13 @@ Java_edu_wpi_first_hal_PowerJNI_getUserCurrent5V
return val;
}

JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_PowerJNI_setUserEnabled5V(JNIEnv* env, jclass, jboolean enabled) {
int32_t status = 0;
HAL_SetUserRailEnabled5V(enabled, &status);
CheckStatus(env, status);
}

/*
* Class: edu_wpi_first_hal_PowerJNI
* Method: getUserActive5V
Expand Down Expand Up @@ -192,6 +206,13 @@ Java_edu_wpi_first_hal_PowerJNI_getUserCurrent3V3
return val;
}

JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_PowerJNI_setUserEnabled3V3(JNIEnv* env, jclass, jboolean enabled) {
int32_t status = 0;
HAL_SetUserRailEnabled3V3(enabled, &status);
CheckStatus(env, status);
}

/*
* Class: edu_wpi_first_hal_PowerJNI
* Method: getUserActive3V3
Expand Down
18 changes: 18 additions & 0 deletions wpilibc/src/main/native/cpp/RobotController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ double RobotController::GetCurrent3V3() {
return retVal;
}

void RobotController::SetEnabled3V3(bool enabled) {
int32_t status = 0;
HAL_SetUserRailEnabled3V3(enabled, &status);
FRC_CheckErrorStatus(status, "SetEnabled3V3");
}

bool RobotController::GetEnabled3V3() {
int32_t status = 0;
bool retVal = HAL_GetUserActive3V3(&status);
Expand Down Expand Up @@ -139,6 +145,12 @@ double RobotController::GetCurrent5V() {
return retVal;
}

void RobotController::SetEnabled5V(bool enabled) {
int32_t status = 0;
HAL_SetUserRailEnabled5V(enabled, &status);
FRC_CheckErrorStatus(status, "SetEnabled5V");
}

bool RobotController::GetEnabled5V() {
int32_t status = 0;
bool retVal = HAL_GetUserActive5V(&status);
Expand Down Expand Up @@ -167,6 +179,12 @@ double RobotController::GetCurrent6V() {
return retVal;
}

void RobotController::SetEnabled6V(bool enabled) {
int32_t status = 0;
HAL_SetUserRailEnabled6V(enabled, &status);
FRC_CheckErrorStatus(status, "SetEnabled6V");
}

bool RobotController::GetEnabled6V() {
int32_t status = 0;
bool retVal = HAL_GetUserActive6V(&status);
Expand Down
39 changes: 30 additions & 9 deletions wpilibc/src/main/native/include/frc/RobotController.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,16 @@ class RobotController {
static double GetCurrent3V3();

/**
* Get the enabled state of the 3.3V rail. The rail may be disabled due to a
* controller brownout, a short circuit on the rail, or controller
* over-voltage.
* Enables or disables the 3.3V rail.
*
* @param enabled whether to enable the 3.3V rail.
*/
static void SetEnabled3V3(bool enabled);

/**
* Get the enabled state of the 3.3V rail. The rail may be disabled due to
* calling SetEnabled3V3(), a controller brownout, a short circuit on the
* rail, or controller over-voltage.
*
* @return The controller 3.3V rail enabled value. True for enabled.
*/
Expand Down Expand Up @@ -167,9 +174,16 @@ class RobotController {
static double GetCurrent5V();

/**
* Get the enabled state of the 5V rail. The rail may be disabled due to a
* controller brownout, a short circuit on the rail, or controller
* over-voltage.
* Enables or disables the 5V rail.
*
* @param enabled whether to enable the 5V rail.
*/
static void SetEnabled5V(bool enabled);

/**
* Get the enabled state of the 5V rail. The rail may be disabled due to
* calling SetEnabled5V(), a controller brownout, a short circuit on the rail,
* or controller over-voltage.
*
* @return The controller 5V rail enabled value. True for enabled.
*/
Expand Down Expand Up @@ -198,9 +212,16 @@ class RobotController {
static double GetCurrent6V();

/**
* Get the enabled state of the 6V rail. The rail may be disabled due to a
* controller brownout, a short circuit on the rail, or controller
* over-voltage.
* Enables or disables the 6V rail.
*
* @param enabled whether to enable the 6V rail.
*/
static void SetEnabled6V(bool enabled);

/**
* Get the enabled state of the 6V rail. The rail may be disabled due to
* calling SetEnabled6V(), a controller brownout, a short circuit on the rail,
* or controller over-voltage.
*
* @return The controller 6V rail enabled value. True for enabled.
*/
Expand Down
27 changes: 27 additions & 0 deletions wpilibj/src/main/java/edu/wpi/first/wpilibj/RobotController.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,15 @@ public static double getCurrent3V3() {
return PowerJNI.getUserCurrent3V3();
}

/**
* Enables or disables the 3.3V rail.
*
* @param enabled whether to enable the 3.3V rail.
*/
public static void setEnabled3V3(boolean enabled) {
PowerJNI.setUserEnabled3V3(enabled);
}

/**
* Get the enabled state of the 3.3V rail. The rail may be disabled due to a controller brownout,
* a short circuit on the rail, or controller over-voltage.
Expand Down Expand Up @@ -185,6 +194,15 @@ public static double getCurrent5V() {
return PowerJNI.getUserCurrent5V();
}

/**
* Enables or disables the 5V rail.
*
* @param enabled whether to enable the 5V rail.
*/
public static void setEnabled5V(boolean enabled) {
PowerJNI.setUserEnabled5V(enabled);
}

/**
* Get the enabled state of the 5V rail. The rail may be disabled due to a controller brownout, a
* short circuit on the rail, or controller over-voltage.
Expand Down Expand Up @@ -222,6 +240,15 @@ public static double getCurrent6V() {
return PowerJNI.getUserCurrent6V();
}

/**
* Enables or disables the 6V rail.
*
* @param enabled whether to enable the 6V rail.
*/
public static void setEnabled6V(boolean enabled) {
PowerJNI.setUserEnabled6V(enabled);
}

/**
* Get the enabled state of the 6V rail. The rail may be disabled due to a controller brownout, a
* short circuit on the rail, or controller over-voltage.
Expand Down

0 comments on commit bcf4338

Please sign in to comment.