mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-29 02:21:44 +00:00
[hal] Expose power rail disable and cpu temp functionality (#5477)
This commit is contained in:
@@ -61,6 +61,11 @@ int32_t HAL_GetUserCurrentFaults6V(int32_t* status) {
|
||||
power->readFaultCounts_OverCurrentFaultCount6V(status));
|
||||
}
|
||||
|
||||
void HAL_SetUserRailEnabled6V(HAL_Bool enabled, int32_t* status) {
|
||||
initializePower(status);
|
||||
power->writeDisable_User6V(!enabled, status);
|
||||
}
|
||||
|
||||
double HAL_GetUserVoltage5V(int32_t* status) {
|
||||
initializePower(status);
|
||||
return power->readUserVoltage5V(status) / 4.096 * 0.005962 - 0.013;
|
||||
@@ -82,6 +87,11 @@ int32_t HAL_GetUserCurrentFaults5V(int32_t* status) {
|
||||
power->readFaultCounts_OverCurrentFaultCount5V(status));
|
||||
}
|
||||
|
||||
void HAL_SetUserRailEnabled5V(HAL_Bool enabled, int32_t* status) {
|
||||
initializePower(status);
|
||||
power->writeDisable_User5V(!enabled, status);
|
||||
}
|
||||
|
||||
double HAL_GetUserVoltage3V3(int32_t* status) {
|
||||
initializePower(status);
|
||||
return power->readUserVoltage3V3(status) / 4.096 * 0.004902 - 0.01;
|
||||
@@ -103,6 +113,11 @@ int32_t HAL_GetUserCurrentFaults3V3(int32_t* status) {
|
||||
power->readFaultCounts_OverCurrentFaultCount3V3(status));
|
||||
}
|
||||
|
||||
void HAL_SetUserRailEnabled3V3(HAL_Bool enabled, int32_t* status) {
|
||||
initializePower(status);
|
||||
power->writeDisable_User3V3(!enabled, status);
|
||||
}
|
||||
|
||||
void HAL_SetBrownoutVoltage(double voltage, int32_t* status) {
|
||||
initializePower(status);
|
||||
if (voltage < 0) {
|
||||
@@ -121,4 +136,9 @@ double HAL_GetBrownoutVoltage(int32_t* status) {
|
||||
return brownout / 4.0;
|
||||
}
|
||||
|
||||
double HAL_GetCPUTemp(int32_t* status) {
|
||||
initializePower(status);
|
||||
return power->readOnChipTemperature(status) / 4096.0 * 503.975 - 273.15;
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
|
||||
@@ -28,6 +28,7 @@ DEFINE_CAPI(int32_t, UserFaults6V, 0)
|
||||
DEFINE_CAPI(int32_t, UserFaults5V, 0)
|
||||
DEFINE_CAPI(int32_t, UserFaults3V3, 0)
|
||||
DEFINE_CAPI(double, BrownoutVoltage, 6.75)
|
||||
DEFINE_CAPI(int32_t, CPUTemp, 16)
|
||||
|
||||
int32_t HALSIM_RegisterRoboRioSerialNumberCallback(
|
||||
HAL_RoboRioStringCallback callback, void* param, HAL_Bool initialNotify) {
|
||||
|
||||
@@ -72,6 +72,20 @@ Java_edu_wpi_first_hal_PowerJNI_getUserCurrent6V
|
||||
return val;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_PowerJNI
|
||||
* Method: setUserEnabled6V
|
||||
* Signature: (Z)V
|
||||
*/
|
||||
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
|
||||
@@ -132,6 +146,20 @@ Java_edu_wpi_first_hal_PowerJNI_getUserCurrent5V
|
||||
return val;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_PowerJNI
|
||||
* Method: setUserEnabled5V
|
||||
* Signature: (Z)V
|
||||
*/
|
||||
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
|
||||
@@ -192,6 +220,20 @@ Java_edu_wpi_first_hal_PowerJNI_getUserCurrent3V3
|
||||
return val;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_PowerJNI
|
||||
* Method: setUserEnabled3V3
|
||||
* Signature: (Z)V
|
||||
*/
|
||||
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
|
||||
@@ -251,4 +293,19 @@ Java_edu_wpi_first_hal_PowerJNI_getBrownoutVoltage
|
||||
return val;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_PowerJNI
|
||||
* Method: getCPUTemp
|
||||
* Signature: ()D
|
||||
*/
|
||||
JNIEXPORT jdouble JNICALL
|
||||
Java_edu_wpi_first_hal_PowerJNI_getCPUTemp
|
||||
(JNIEnv* env, jclass)
|
||||
{
|
||||
int32_t status = 0;
|
||||
double val = HAL_GetCPUTemp(&status);
|
||||
CheckStatus(env, status);
|
||||
return val;
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
|
||||
@@ -66,6 +66,14 @@ HAL_Bool HAL_GetUserActive6V(int32_t* status);
|
||||
*/
|
||||
int32_t HAL_GetUserCurrentFaults6V(int32_t* status);
|
||||
|
||||
/**
|
||||
* Enables or disables the 6V rail.
|
||||
*
|
||||
* @param enabled whether the rail should be enabled
|
||||
* @param[out] status the error code, or 0 for success
|
||||
*/
|
||||
void HAL_SetUserRailEnabled6V(HAL_Bool enabled, int32_t* status);
|
||||
|
||||
/**
|
||||
* Gets the 5V rail voltage.
|
||||
*
|
||||
@@ -98,6 +106,14 @@ HAL_Bool HAL_GetUserActive5V(int32_t* status);
|
||||
*/
|
||||
int32_t HAL_GetUserCurrentFaults5V(int32_t* status);
|
||||
|
||||
/**
|
||||
* Enables or disables the 5V rail.
|
||||
*
|
||||
* @param enabled whether the rail should be enabled
|
||||
* @param[out] status the error code, or 0 for success
|
||||
*/
|
||||
void HAL_SetUserRailEnabled5V(HAL_Bool enabled, int32_t* status);
|
||||
|
||||
/**
|
||||
* Gets the 3V3 rail voltage.
|
||||
*
|
||||
@@ -130,6 +146,14 @@ HAL_Bool HAL_GetUserActive3V3(int32_t* status);
|
||||
*/
|
||||
int32_t HAL_GetUserCurrentFaults3V3(int32_t* status);
|
||||
|
||||
/**
|
||||
* Enables or disables the 3V3 rail.
|
||||
*
|
||||
* @param enabled whether the rail should be enabled
|
||||
* @param[out] status the error code, or 0 for success
|
||||
*/
|
||||
void HAL_SetUserRailEnabled3V3(HAL_Bool enabled, int32_t* status);
|
||||
|
||||
/**
|
||||
* Get the current brownout voltage setting.
|
||||
*
|
||||
@@ -149,6 +173,14 @@ double HAL_GetBrownoutVoltage(int32_t* status);
|
||||
*/
|
||||
void HAL_SetBrownoutVoltage(double voltage, int32_t* status);
|
||||
|
||||
/**
|
||||
* Get the current CPU temperature in degrees Celsius
|
||||
*
|
||||
* @param[out] status the error code, or 0 for success
|
||||
* @return current CPU temperature in degrees Celsius
|
||||
*/
|
||||
double HAL_GetCPUTemp(int32_t* status);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
@@ -141,6 +141,13 @@ void HALSIM_SetRoboRioComments(const char* comments, size_t size);
|
||||
void HALSIM_RegisterRoboRioAllCallbacks(HAL_NotifyCallback callback,
|
||||
void* param, HAL_Bool initialNotify);
|
||||
|
||||
int32_t HALSIM_RegisterRoboRioCPUTempCallback(HAL_NotifyCallback callback,
|
||||
void* param,
|
||||
HAL_Bool initialNotify);
|
||||
void HALSIM_CancelRoboRioCPUTempCallback(int32_t uid);
|
||||
HAL_Bool HALSIM_GetRoboRioCPUTemp(void);
|
||||
void HALSIM_SetRoboRioUserCPUTemp(HAL_Bool userActive3V3);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
@@ -32,6 +32,7 @@ HAL_Bool HAL_GetUserActive6V(int32_t* status) {
|
||||
int32_t HAL_GetUserCurrentFaults6V(int32_t* status) {
|
||||
return SimRoboRioData->userFaults6V;
|
||||
}
|
||||
void HAL_SetUserRailEnabled6V(HAL_Bool enabled, int32_t* status) {}
|
||||
double HAL_GetUserVoltage5V(int32_t* status) {
|
||||
return SimRoboRioData->userVoltage5V;
|
||||
}
|
||||
@@ -44,6 +45,7 @@ HAL_Bool HAL_GetUserActive5V(int32_t* status) {
|
||||
int32_t HAL_GetUserCurrentFaults5V(int32_t* status) {
|
||||
return SimRoboRioData->userFaults5V;
|
||||
}
|
||||
void HAL_SetUserRailEnabled5V(HAL_Bool enabled, int32_t* status) {}
|
||||
double HAL_GetUserVoltage3V3(int32_t* status) {
|
||||
return SimRoboRioData->userVoltage3V3;
|
||||
}
|
||||
@@ -56,10 +58,14 @@ HAL_Bool HAL_GetUserActive3V3(int32_t* status) {
|
||||
int32_t HAL_GetUserCurrentFaults3V3(int32_t* status) {
|
||||
return SimRoboRioData->userFaults3V3;
|
||||
}
|
||||
void HAL_SetUserRailEnabled3V3(HAL_Bool enabled, int32_t* status) {}
|
||||
void HAL_SetBrownoutVoltage(double voltage, int32_t* status) {
|
||||
SimRoboRioData->brownoutVoltage = voltage;
|
||||
}
|
||||
double HAL_GetBrownoutVoltage(int32_t* status) {
|
||||
return SimRoboRioData->brownoutVoltage;
|
||||
}
|
||||
double HAL_GetCPUTemp(int32_t* status) {
|
||||
return SimRoboRioData->cpuTemp;
|
||||
}
|
||||
} // extern "C"
|
||||
|
||||
@@ -32,6 +32,7 @@ void RoboRioData::ResetData() {
|
||||
userFaults5V.Reset(0);
|
||||
userFaults3V3.Reset(0);
|
||||
brownoutVoltage.Reset(6.75);
|
||||
cpuTemp.Reset(100);
|
||||
m_serialNumber = "";
|
||||
m_comments = "";
|
||||
}
|
||||
@@ -132,6 +133,7 @@ DEFINE_CAPI(int32_t, UserFaults6V, userFaults6V)
|
||||
DEFINE_CAPI(int32_t, UserFaults5V, userFaults5V)
|
||||
DEFINE_CAPI(int32_t, UserFaults3V3, userFaults3V3)
|
||||
DEFINE_CAPI(double, BrownoutVoltage, brownoutVoltage)
|
||||
DEFINE_CAPI(int32_t, CPUTemp, cpuTemp)
|
||||
|
||||
int32_t HALSIM_RegisterRoboRioSerialNumberCallback(
|
||||
HAL_RoboRioStringCallback callback, void* param, HAL_Bool initialNotify) {
|
||||
@@ -187,5 +189,6 @@ void HALSIM_RegisterRoboRioAllCallbacks(HAL_NotifyCallback callback,
|
||||
REGISTER(userFaults5V);
|
||||
REGISTER(userFaults3V3);
|
||||
REGISTER(brownoutVoltage);
|
||||
REGISTER(cpuTemp);
|
||||
}
|
||||
} // extern "C"
|
||||
|
||||
@@ -30,6 +30,7 @@ class RoboRioData {
|
||||
HAL_SIMDATAVALUE_DEFINE_NAME(UserFaults5V)
|
||||
HAL_SIMDATAVALUE_DEFINE_NAME(UserFaults3V3)
|
||||
HAL_SIMDATAVALUE_DEFINE_NAME(BrownoutVoltage)
|
||||
HAL_SIMDATAVALUE_DEFINE_NAME(CPUTemp)
|
||||
|
||||
HAL_SIMCALLBACKREGISTRY_DEFINE_NAME(SerialNumber)
|
||||
HAL_SIMCALLBACKREGISTRY_DEFINE_NAME(Comments);
|
||||
@@ -57,6 +58,7 @@ class RoboRioData {
|
||||
SimDataValue<int32_t, HAL_MakeInt, GetUserFaults3V3Name> userFaults3V3{0};
|
||||
SimDataValue<double, HAL_MakeDouble, GetBrownoutVoltageName> brownoutVoltage{
|
||||
6.75};
|
||||
SimDataValue<double, HAL_MakeDouble, GetCPUTempName> cpuTemp{100};
|
||||
|
||||
int32_t RegisterSerialNumberCallback(HAL_RoboRioStringCallback callback,
|
||||
void* param, HAL_Bool initialNotify);
|
||||
|
||||
Reference in New Issue
Block a user