mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
[wpilib, hal] High Level REV PH changes (#3792)
More functionality was implemented at the HAL level, so expose that to the wpilib level. This also does units changes for all the PH related functionality.
This commit is contained in:
@@ -53,6 +53,7 @@ static JClass accumulatorResultCls;
|
||||
static JClass canDataCls;
|
||||
static JClass halValueCls;
|
||||
static JClass baseStoreCls;
|
||||
static JClass revPHVersionCls;
|
||||
|
||||
static const JClassInit classes[] = {
|
||||
{"edu/wpi/first/hal/PWMConfigDataResult", &pwmConfigDataResultCls},
|
||||
@@ -61,7 +62,8 @@ static const JClassInit classes[] = {
|
||||
{"edu/wpi/first/hal/AccumulatorResult", &accumulatorResultCls},
|
||||
{"edu/wpi/first/hal/CANData", &canDataCls},
|
||||
{"edu/wpi/first/hal/HALValue", &halValueCls},
|
||||
{"edu/wpi/first/hal/DMAJNISample$BaseStore", &baseStoreCls}};
|
||||
{"edu/wpi/first/hal/DMAJNISample$BaseStore", &baseStoreCls},
|
||||
{"edu/wpi/first/hal/REVPHVersion", &revPHVersionCls}};
|
||||
|
||||
static const JExceptionInit exceptions[] = {
|
||||
{"java/lang/IllegalArgumentException", &illegalArgExCls},
|
||||
@@ -238,6 +240,19 @@ jobject CreatePWMConfigDataResult(JNIEnv* env, int32_t maxPwm,
|
||||
static_cast<jint>(deadbandMinPwm), static_cast<jint>(minPwm));
|
||||
}
|
||||
|
||||
jobject CreateREVPHVersion(JNIEnv* env, uint32_t firmwareMajor,
|
||||
uint32_t firmwareMinor, uint32_t firmwareFix,
|
||||
uint32_t hardwareMinor, uint32_t hardwareMajor,
|
||||
uint32_t uniqueId) {
|
||||
static jmethodID constructor =
|
||||
env->GetMethodID(revPHVersionCls, "<init>", "(IIIIII)V");
|
||||
return env->NewObject(
|
||||
revPHVersionCls, constructor, static_cast<jint>(firmwareMajor),
|
||||
static_cast<jint>(firmwareMinor), static_cast<jint>(firmwareFix),
|
||||
static_cast<jint>(hardwareMinor), static_cast<jint>(hardwareMajor),
|
||||
static_cast<jint>(uniqueId));
|
||||
}
|
||||
|
||||
void SetCanStatusObject(JNIEnv* env, jobject canStatus,
|
||||
float percentBusUtilization, uint32_t busOffCount,
|
||||
uint32_t txFullCount, uint32_t receiveErrorCount,
|
||||
|
||||
@@ -59,6 +59,11 @@ jobject CreatePWMConfigDataResult(JNIEnv* env, int32_t maxPwm,
|
||||
int32_t deadbandMaxPwm, int32_t centerPwm,
|
||||
int32_t deadbandMinPwm, int32_t minPwm);
|
||||
|
||||
jobject CreateREVPHVersion(JNIEnv* env, uint32_t firmwareMajor,
|
||||
uint32_t firmwareMinor, uint32_t firmwareFix,
|
||||
uint32_t hardwareMinor, uint32_t hardwareMajor,
|
||||
uint32_t uniqueId);
|
||||
|
||||
void SetCanStatusObject(JNIEnv* env, jobject canStatus,
|
||||
float percentBusUtilization, uint32_t busOffCount,
|
||||
uint32_t txFullCount, uint32_t receiveErrorCount,
|
||||
|
||||
@@ -196,15 +196,15 @@ Java_edu_wpi_first_hal_REVPHJNI_getPressureSwitch
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_REVPHJNI
|
||||
* Method: getAnalogPressure
|
||||
* Method: getAnalogVoltage
|
||||
* Signature: (II)D
|
||||
*/
|
||||
JNIEXPORT jdouble JNICALL
|
||||
Java_edu_wpi_first_hal_REVPHJNI_getAnalogPressure
|
||||
Java_edu_wpi_first_hal_REVPHJNI_getAnalogVoltage
|
||||
(JNIEnv* env, jclass, jint handle, jint channel)
|
||||
{
|
||||
int32_t status = 0;
|
||||
auto result = HAL_GetREVPHAnalogPressure(handle, channel, &status);
|
||||
auto result = HAL_GetREVPHAnalogVoltage(handle, channel, &status);
|
||||
CheckStatus(env, status, false);
|
||||
return result;
|
||||
}
|
||||
@@ -267,4 +267,137 @@ Java_edu_wpi_first_hal_REVPHJNI_fireOneShot
|
||||
CheckStatus(env, status, false);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_REVPHJNI
|
||||
* Method: clearStickyFaults
|
||||
* Signature: (I)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_REVPHJNI_clearStickyFaults
|
||||
(JNIEnv* env, jclass, jint handle)
|
||||
{
|
||||
int32_t status = 0;
|
||||
HAL_ClearREVPHStickyFaults(handle, &status);
|
||||
CheckStatus(env, status, false);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_REVPHJNI
|
||||
* Method: getInputVoltage
|
||||
* Signature: (I)D
|
||||
*/
|
||||
JNIEXPORT jdouble JNICALL
|
||||
Java_edu_wpi_first_hal_REVPHJNI_getInputVoltage
|
||||
(JNIEnv* env, jclass, jint handle)
|
||||
{
|
||||
int32_t status = 0;
|
||||
auto voltage = HAL_GetREVPHVoltage(handle, &status);
|
||||
CheckStatus(env, status, false);
|
||||
return voltage;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_REVPHJNI
|
||||
* Method: get5VVoltage
|
||||
* Signature: (I)D
|
||||
*/
|
||||
JNIEXPORT jdouble JNICALL
|
||||
Java_edu_wpi_first_hal_REVPHJNI_get5VVoltage
|
||||
(JNIEnv* env, jclass, jint handle)
|
||||
{
|
||||
int32_t status = 0;
|
||||
auto voltage = HAL_GetREVPH5VVoltage(handle, &status);
|
||||
CheckStatus(env, status, false);
|
||||
return voltage;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_REVPHJNI
|
||||
* Method: getSolenoidCurrent
|
||||
* Signature: (I)D
|
||||
*/
|
||||
JNIEXPORT jdouble JNICALL
|
||||
Java_edu_wpi_first_hal_REVPHJNI_getSolenoidCurrent
|
||||
(JNIEnv* env, jclass, jint handle)
|
||||
{
|
||||
int32_t status = 0;
|
||||
auto voltage = HAL_GetREVPHSolenoidCurrent(handle, &status);
|
||||
CheckStatus(env, status, false);
|
||||
return voltage;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_REVPHJNI
|
||||
* Method: getSolenoidVoltage
|
||||
* Signature: (I)D
|
||||
*/
|
||||
JNIEXPORT jdouble JNICALL
|
||||
Java_edu_wpi_first_hal_REVPHJNI_getSolenoidVoltage
|
||||
(JNIEnv* env, jclass, jint handle)
|
||||
{
|
||||
int32_t status = 0;
|
||||
auto voltage = HAL_GetREVPHSolenoidVoltage(handle, &status);
|
||||
CheckStatus(env, status, false);
|
||||
return voltage;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_REVPHJNI
|
||||
* Method: getStickyFaultsNative
|
||||
* Signature: (I)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_edu_wpi_first_hal_REVPHJNI_getStickyFaultsNative
|
||||
(JNIEnv* env, jclass, jint handle)
|
||||
{
|
||||
int32_t status = 0;
|
||||
HAL_REVPHStickyFaults halFaults;
|
||||
std::memset(&halFaults, 0, sizeof(halFaults));
|
||||
HAL_GetREVPHStickyFaults(handle, &halFaults, &status);
|
||||
CheckStatus(env, status, false);
|
||||
jint faults;
|
||||
static_assert(sizeof(faults) == sizeof(halFaults));
|
||||
std::memcpy(&faults, &halFaults, sizeof(faults));
|
||||
return faults;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_REVPHJNI
|
||||
* Method: getFaultsNative
|
||||
* Signature: (I)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_edu_wpi_first_hal_REVPHJNI_getFaultsNative
|
||||
(JNIEnv* env, jclass, jint handle)
|
||||
{
|
||||
int32_t status = 0;
|
||||
HAL_REVPHFaults halFaults;
|
||||
std::memset(&halFaults, 0, sizeof(halFaults));
|
||||
HAL_GetREVPHFaults(handle, &halFaults, &status);
|
||||
CheckStatus(env, status, false);
|
||||
jint faults;
|
||||
static_assert(sizeof(faults) == sizeof(halFaults));
|
||||
std::memcpy(&faults, &halFaults, sizeof(faults));
|
||||
return faults;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_REVPHJNI
|
||||
* Method: getVersion
|
||||
* Signature: (I)Ljava/lang/Object;
|
||||
*/
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_edu_wpi_first_hal_REVPHJNI_getVersion
|
||||
(JNIEnv* env, jclass, jint handle)
|
||||
{
|
||||
int32_t status = 0;
|
||||
HAL_REVPHVersion version;
|
||||
std::memset(&version, 0, sizeof(version));
|
||||
HAL_GetREVPHVersion(handle, &version, &status);
|
||||
CheckStatus(env, status, false);
|
||||
return CreateREVPHVersion(env, version.firmwareMajor, version.firmwareMinor,
|
||||
version.firmwareFix, version.hardwareMinor,
|
||||
version.hardwareMajor, version.uniqueId);
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
|
||||
Reference in New Issue
Block a user