From 62c217cd01d8fc143cee01deafc513a12bbc1d0a Mon Sep 17 00:00:00 2001 From: Thad House Date: Sat, 2 Jul 2016 08:22:44 -0700 Subject: [PATCH] Switches compressor to handles (#125) --- hal/include/HAL/Compressor.h | 42 +++-- hal/include/HAL/Handles.h | 2 + hal/lib/athena/Compressor.cpp | 148 ++++++++++++++---- hal/lib/athena/handles/HandlesInternal.h | 3 +- wpilibc/athena/include/Compressor.h | 3 +- wpilibc/athena/src/Compressor.cpp | 53 +++++-- wpilibj/src/athena/cpp/lib/CompressorJNI.cpp | 62 ++++---- .../edu/wpi/first/wpilibj/Compressor.java | 28 ++-- .../wpi/first/wpilibj/hal/CompressorJNI.java | 26 +-- 9 files changed, 253 insertions(+), 114 deletions(-) diff --git a/hal/include/HAL/Compressor.h b/hal/include/HAL/Compressor.h index 2f8f53cdc1..697b59f5f5 100644 --- a/hal/include/HAL/Compressor.h +++ b/hal/include/HAL/Compressor.h @@ -5,27 +5,39 @@ /* the project. */ /*----------------------------------------------------------------------------*/ -#include - #pragma once +#include + +#include "HAL/Handles.h" + extern "C" { -void* initializeCompressor(uint8_t module); +HalCompressorHandle initializeCompressor(uint8_t module, int32_t* status); bool checkCompressorModule(uint8_t module); -bool getCompressor(void* pcm_pointer, int32_t* status); +bool getCompressor(HalCompressorHandle compressor_handle, int32_t* status); -void setClosedLoopControl(void* pcm_pointer, bool value, int32_t* status); -bool getClosedLoopControl(void* pcm_pointer, int32_t* status); +void setClosedLoopControl(HalCompressorHandle compressor_handle, bool value, + int32_t* status); +bool getClosedLoopControl(HalCompressorHandle compressor_handle, + int32_t* status); -bool getPressureSwitch(void* pcm_pointer, int32_t* status); -float getCompressorCurrent(void* pcm_pointer, int32_t* status); +bool getPressureSwitch(HalCompressorHandle compressor_handle, int32_t* status); +float getCompressorCurrent(HalCompressorHandle compressor_handle, + int32_t* status); -bool getCompressorCurrentTooHighFault(void* pcm_pointer, int32_t* status); -bool getCompressorCurrentTooHighStickyFault(void* pcm_pointer, int32_t* status); -bool getCompressorShortedStickyFault(void* pcm_pointer, int32_t* status); -bool getCompressorShortedFault(void* pcm_pointer, int32_t* status); -bool getCompressorNotConnectedStickyFault(void* pcm_pointer, int32_t* status); -bool getCompressorNotConnectedFault(void* pcm_pointer, int32_t* status); -void clearAllPCMStickyFaults(void* pcm_pointer, int32_t* status); +bool getCompressorCurrentTooHighFault(HalCompressorHandle compressor_handle, + int32_t* status); +bool getCompressorCurrentTooHighStickyFault( + HalCompressorHandle compressor_handle, int32_t* status); +bool getCompressorShortedStickyFault(HalCompressorHandle compressor_handle, + int32_t* status); +bool getCompressorShortedFault(HalCompressorHandle compressor_handle, + int32_t* status); +bool getCompressorNotConnectedStickyFault(HalCompressorHandle compressor_handle, + int32_t* status); +bool getCompressorNotConnectedFault(HalCompressorHandle compressor_handle, + int32_t* status); +void clearAllPCMStickyFaults(HalCompressorHandle compressor_handle, + int32_t* status); } diff --git a/hal/include/HAL/Handles.h b/hal/include/HAL/Handles.h index 59b51a8337..6451ec0d0d 100644 --- a/hal/include/HAL/Handles.h +++ b/hal/include/HAL/Handles.h @@ -32,3 +32,5 @@ typedef HalHandle HalDigitalHandle; typedef HalHandle HalDigitalPWMHandle; typedef HalHandle HalCounterHandle; + +typedef HalHandle HalCompressorHandle; diff --git a/hal/lib/athena/Compressor.cpp b/hal/lib/athena/Compressor.cpp index e4c1b1ef66..b1407c6962 100644 --- a/hal/lib/athena/Compressor.cpp +++ b/hal/lib/athena/Compressor.cpp @@ -7,26 +7,45 @@ #include "HAL/Compressor.h" +#include "HAL/Errors.h" #include "ctre/PCM.h" +#include "handles/HandlesInternal.h" static const int NUM_MODULE_NUMBERS = 63; extern PCM* PCM_modules[NUM_MODULE_NUMBERS]; extern void initializePCM(int module); +using namespace hal; + extern "C" { -void* initializeCompressor(uint8_t module) { +HalCompressorHandle initializeCompressor(uint8_t module, int32_t* status) { + // fail on invalid index; + if (!checkCompressorModule(module)) { + *status = PARAMETER_OUT_OF_RANGE; + return HAL_INVALID_HANDLE; + } + initializePCM(module); - return PCM_modules[module]; + // As compressors can have unlimited objects, just create a + // handle with the module number as the index. + + return (HalCompressorHandle)createHandle(module, HalHandleEnum::Compressor); } bool checkCompressorModule(uint8_t module) { return module < NUM_MODULE_NUMBERS; } -bool getCompressor(void* pcm_pointer, int32_t* status) { - PCM* module = (PCM*)pcm_pointer; +bool getCompressor(HalCompressorHandle compressor_handle, int32_t* status) { + int16_t index = + getHandleTypedIndex(compressor_handle, HalHandleEnum::Compressor); + if (index == InvalidHandleIndex) { + *status = PARAMETER_OUT_OF_RANGE; + return false; + } + PCM* module = PCM_modules[index]; bool value; *status = module->GetCompressor(value); @@ -34,14 +53,28 @@ bool getCompressor(void* pcm_pointer, int32_t* status) { return value; } -void setClosedLoopControl(void* pcm_pointer, bool value, int32_t* status) { - PCM* module = (PCM*)pcm_pointer; +void setClosedLoopControl(HalCompressorHandle compressor_handle, bool value, + int32_t* status) { + int16_t index = + getHandleTypedIndex(compressor_handle, HalHandleEnum::Compressor); + if (index == InvalidHandleIndex) { + *status = PARAMETER_OUT_OF_RANGE; + return; + } + PCM* module = PCM_modules[index]; *status = module->SetClosedLoopControl(value); } -bool getClosedLoopControl(void* pcm_pointer, int32_t* status) { - PCM* module = (PCM*)pcm_pointer; +bool getClosedLoopControl(HalCompressorHandle compressor_handle, + int32_t* status) { + int16_t index = + getHandleTypedIndex(compressor_handle, HalHandleEnum::Compressor); + if (index == InvalidHandleIndex) { + *status = PARAMETER_OUT_OF_RANGE; + return false; + } + PCM* module = PCM_modules[index]; bool value; *status = module->GetClosedLoopControl(value); @@ -49,8 +82,14 @@ bool getClosedLoopControl(void* pcm_pointer, int32_t* status) { return value; } -bool getPressureSwitch(void* pcm_pointer, int32_t* status) { - PCM* module = (PCM*)pcm_pointer; +bool getPressureSwitch(HalCompressorHandle compressor_handle, int32_t* status) { + int16_t index = + getHandleTypedIndex(compressor_handle, HalHandleEnum::Compressor); + if (index == InvalidHandleIndex) { + *status = PARAMETER_OUT_OF_RANGE; + return false; + } + PCM* module = PCM_modules[index]; bool value; *status = module->GetPressure(value); @@ -58,65 +97,120 @@ bool getPressureSwitch(void* pcm_pointer, int32_t* status) { return value; } -float getCompressorCurrent(void* pcm_pointer, int32_t* status) { - PCM* module = (PCM*)pcm_pointer; +float getCompressorCurrent(HalCompressorHandle compressor_handle, + int32_t* status) { + int16_t index = + getHandleTypedIndex(compressor_handle, HalHandleEnum::Compressor); + if (index == InvalidHandleIndex) { + *status = PARAMETER_OUT_OF_RANGE; + return 0; + } + PCM* module = PCM_modules[index]; float value; *status = module->GetCompressorCurrent(value); return value; } -bool getCompressorCurrentTooHighFault(void* pcm_pointer, int32_t* status) { - PCM* module = (PCM*)pcm_pointer; +bool getCompressorCurrentTooHighFault(HalCompressorHandle compressor_handle, + int32_t* status) { + int16_t index = + getHandleTypedIndex(compressor_handle, HalHandleEnum::Compressor); + if (index == InvalidHandleIndex) { + *status = PARAMETER_OUT_OF_RANGE; + return false; + } + PCM* module = PCM_modules[index]; bool value; *status = module->GetCompressorCurrentTooHighFault(value); return value; } -bool getCompressorCurrentTooHighStickyFault(void* pcm_pointer, - int32_t* status) { - PCM* module = (PCM*)pcm_pointer; +bool getCompressorCurrentTooHighStickyFault( + HalCompressorHandle compressor_handle, int32_t* status) { + int16_t index = + getHandleTypedIndex(compressor_handle, HalHandleEnum::Compressor); + if (index == InvalidHandleIndex) { + *status = PARAMETER_OUT_OF_RANGE; + return false; + } + PCM* module = PCM_modules[index]; bool value; *status = module->GetCompressorCurrentTooHighStickyFault(value); return value; } -bool getCompressorShortedStickyFault(void* pcm_pointer, int32_t* status) { - PCM* module = (PCM*)pcm_pointer; +bool getCompressorShortedStickyFault(HalCompressorHandle compressor_handle, + int32_t* status) { + int16_t index = + getHandleTypedIndex(compressor_handle, HalHandleEnum::Compressor); + if (index == InvalidHandleIndex) { + *status = PARAMETER_OUT_OF_RANGE; + return false; + } + PCM* module = PCM_modules[index]; bool value; *status = module->GetCompressorShortedStickyFault(value); return value; } -bool getCompressorShortedFault(void* pcm_pointer, int32_t* status) { - PCM* module = (PCM*)pcm_pointer; +bool getCompressorShortedFault(HalCompressorHandle compressor_handle, + int32_t* status) { + int16_t index = + getHandleTypedIndex(compressor_handle, HalHandleEnum::Compressor); + if (index == InvalidHandleIndex) { + *status = PARAMETER_OUT_OF_RANGE; + return false; + } + PCM* module = PCM_modules[index]; bool value; *status = module->GetCompressorShortedFault(value); return value; } -bool getCompressorNotConnectedStickyFault(void* pcm_pointer, int32_t* status) { - PCM* module = (PCM*)pcm_pointer; +bool getCompressorNotConnectedStickyFault(HalCompressorHandle compressor_handle, + int32_t* status) { + int16_t index = + getHandleTypedIndex(compressor_handle, HalHandleEnum::Compressor); + if (index == InvalidHandleIndex) { + *status = PARAMETER_OUT_OF_RANGE; + return false; + } + PCM* module = PCM_modules[index]; bool value; *status = module->GetCompressorNotConnectedStickyFault(value); return value; } -bool getCompressorNotConnectedFault(void* pcm_pointer, int32_t* status) { - PCM* module = (PCM*)pcm_pointer; +bool getCompressorNotConnectedFault(HalCompressorHandle compressor_handle, + int32_t* status) { + int16_t index = + getHandleTypedIndex(compressor_handle, HalHandleEnum::Compressor); + if (index == InvalidHandleIndex) { + *status = PARAMETER_OUT_OF_RANGE; + return false; + } + PCM* module = PCM_modules[index]; bool value; *status = module->GetCompressorNotConnectedFault(value); return value; } -void clearAllPCMStickyFaults(void* pcm_pointer, int32_t* status) { - PCM* module = (PCM*)pcm_pointer; +void clearAllPCMStickyFaults(HalCompressorHandle compressor_handle, + int32_t* status) { + int16_t index = + getHandleTypedIndex(compressor_handle, HalHandleEnum::Compressor); + if (index == InvalidHandleIndex) { + *status = PARAMETER_OUT_OF_RANGE; + return; + } + PCM* module = PCM_modules[index]; *status = module->ClearStickyFaults(); } diff --git a/hal/lib/athena/handles/HandlesInternal.h b/hal/lib/athena/handles/HandlesInternal.h index 3bcf41f89f..6e9510a18e 100644 --- a/hal/lib/athena/handles/HandlesInternal.h +++ b/hal/lib/athena/handles/HandlesInternal.h @@ -37,7 +37,8 @@ enum class HalHandleEnum { Relay = 8, PWM = 9, DigitalPWM = 10, - Counter = 11 + Counter = 11, + Compressor = 14 }; static inline int16_t getHandleIndex(HalHandle handle) { diff --git a/wpilibc/athena/include/Compressor.h b/wpilibc/athena/include/Compressor.h index 2960058212..287339fb2f 100644 --- a/wpilibc/athena/include/Compressor.h +++ b/wpilibc/athena/include/Compressor.h @@ -9,6 +9,7 @@ #include +#include "HAL/Handles.h" #include "LiveWindow/LiveWindowSendable.h" #include "SensorBase.h" #include "tables/ITableListener.h" @@ -53,7 +54,7 @@ class Compressor : public SensorBase, std::shared_ptr value, bool isNew) override; protected: - void* m_pcm_pointer; + HalCompressorHandle m_compressorHandle; private: void SetCompressor(bool on); diff --git a/wpilibc/athena/src/Compressor.cpp b/wpilibc/athena/src/Compressor.cpp index 0ee8841bca..0c11e7103f 100644 --- a/wpilibc/athena/src/Compressor.cpp +++ b/wpilibc/athena/src/Compressor.cpp @@ -13,7 +13,12 @@ * @param module The PCM ID to use (0-62) */ Compressor::Compressor(uint8_t pcmID) { - m_pcm_pointer = initializeCompressor(pcmID); + int32_t status = 0; + m_compressorHandle = initializeCompressor(pcmID, &status); + if (status != 0) { + wpi_setErrorWithContext(status, getHALErrorMessage(status)); + return; + } SetClosedLoopControl(true); } @@ -21,13 +26,19 @@ Compressor::Compressor(uint8_t pcmID) { * Starts closed-loop control. Note that closed loop control is enabled by * default. */ -void Compressor::Start() { SetClosedLoopControl(true); } +void Compressor::Start() { + if (StatusIsFatal()) return; + SetClosedLoopControl(true); +} /** * Stops closed-loop control. Note that closed loop control is enabled by * default. */ -void Compressor::Stop() { SetClosedLoopControl(false); } +void Compressor::Stop() { + if (StatusIsFatal()) return; + SetClosedLoopControl(false); +} /** * Check if compressor output is active. @@ -35,10 +46,11 @@ void Compressor::Stop() { SetClosedLoopControl(false); } * @return true if the compressor is on */ bool Compressor::Enabled() const { + if (StatusIsFatal()) return false; int32_t status = 0; bool value; - value = getCompressor(m_pcm_pointer, &status); + value = getCompressor(m_compressorHandle, &status); if (status) { wpi_setWPIError(Timeout); @@ -53,10 +65,11 @@ bool Compressor::Enabled() const { * @return true if pressure is low */ bool Compressor::GetPressureSwitchValue() const { + if (StatusIsFatal()) return false; int32_t status = 0; bool value; - value = getPressureSwitch(m_pcm_pointer, &status); + value = getPressureSwitch(m_compressorHandle, &status); if (status) { wpi_setWPIError(Timeout); @@ -71,10 +84,11 @@ bool Compressor::GetPressureSwitchValue() const { * @return The current through the compressor, in amps */ float Compressor::GetCompressorCurrent() const { + if (StatusIsFatal()) return 0; int32_t status = 0; float value; - value = getCompressorCurrent(m_pcm_pointer, &status); + value = getCompressorCurrent(m_compressorHandle, &status); if (status) { wpi_setWPIError(Timeout); @@ -91,9 +105,10 @@ float Compressor::GetCompressorCurrent() const { * to disable. */ void Compressor::SetClosedLoopControl(bool on) { + if (StatusIsFatal()) return; int32_t status = 0; - setClosedLoopControl(m_pcm_pointer, on, &status); + setClosedLoopControl(m_compressorHandle, on, &status); if (status) { wpi_setWPIError(Timeout); @@ -108,10 +123,11 @@ void Compressor::SetClosedLoopControl(bool on) { * disabled. */ bool Compressor::GetClosedLoopControl() const { + if (StatusIsFatal()) return false; int32_t status = 0; bool value; - value = getClosedLoopControl(m_pcm_pointer, &status); + value = getClosedLoopControl(m_compressorHandle, &status); if (status) { wpi_setWPIError(Timeout); @@ -127,10 +143,11 @@ bool Compressor::GetClosedLoopControl() const { * disabled due to compressor current being too high. */ bool Compressor::GetCompressorCurrentTooHighFault() const { + if (StatusIsFatal()) return false; int32_t status = 0; bool value; - value = getCompressorCurrentTooHighFault(m_pcm_pointer, &status); + value = getCompressorCurrentTooHighFault(m_compressorHandle, &status); if (status) { wpi_setWPIError(Timeout); @@ -150,10 +167,11 @@ bool Compressor::GetCompressorCurrentTooHighFault() const { * disabled due to compressor current being too high. */ bool Compressor::GetCompressorCurrentTooHighStickyFault() const { + if (StatusIsFatal()) return false; int32_t status = 0; bool value; - value = getCompressorCurrentTooHighStickyFault(m_pcm_pointer, &status); + value = getCompressorCurrentTooHighStickyFault(m_compressorHandle, &status); if (status) { wpi_setWPIError(Timeout); @@ -173,10 +191,11 @@ bool Compressor::GetCompressorCurrentTooHighStickyFault() const { * appears to be shorted. */ bool Compressor::GetCompressorShortedStickyFault() const { + if (StatusIsFatal()) return false; int32_t status = 0; bool value; - value = getCompressorShortedStickyFault(m_pcm_pointer, &status); + value = getCompressorShortedStickyFault(m_compressorHandle, &status); if (status) { wpi_setWPIError(Timeout); @@ -192,10 +211,11 @@ bool Compressor::GetCompressorShortedStickyFault() const { * appears to be shorted. */ bool Compressor::GetCompressorShortedFault() const { + if (StatusIsFatal()) return false; int32_t status = 0; bool value; - value = getCompressorShortedFault(m_pcm_pointer, &status); + value = getCompressorShortedFault(m_compressorHandle, &status); if (status) { wpi_setWPIError(Timeout); @@ -214,10 +234,11 @@ bool Compressor::GetCompressorShortedFault() const { * appear to be wired, i.e. compressor is not drawing enough current. */ bool Compressor::GetCompressorNotConnectedStickyFault() const { + if (StatusIsFatal()) return false; int32_t status = 0; bool value; - value = getCompressorNotConnectedStickyFault(m_pcm_pointer, &status); + value = getCompressorNotConnectedStickyFault(m_compressorHandle, &status); if (status) { wpi_setWPIError(Timeout); @@ -233,10 +254,11 @@ bool Compressor::GetCompressorNotConnectedStickyFault() const { * appear to be wired, i.e. compressor is not drawing enough current. */ bool Compressor::GetCompressorNotConnectedFault() const { + if (StatusIsFatal()) return false; int32_t status = 0; bool value; - value = getCompressorNotConnectedFault(m_pcm_pointer, &status); + value = getCompressorNotConnectedFault(m_compressorHandle, &status); if (status) { wpi_setWPIError(Timeout); @@ -256,9 +278,10 @@ bool Compressor::GetCompressorNotConnectedFault() const { * If no sticky faults are set then this call will have no effect. */ void Compressor::ClearAllPCMStickyFaults() { + if (StatusIsFatal()) return; int32_t status = 0; - clearAllPCMStickyFaults(m_pcm_pointer, &status); + clearAllPCMStickyFaults(m_compressorHandle, &status); if (status) { wpi_setWPIError(Timeout); diff --git a/wpilibj/src/athena/cpp/lib/CompressorJNI.cpp b/wpilibj/src/athena/cpp/lib/CompressorJNI.cpp index fe7f45b26a..31ebfe102c 100644 --- a/wpilibj/src/athena/cpp/lib/CompressorJNI.cpp +++ b/wpilibj/src/athena/cpp/lib/CompressorJNI.cpp @@ -15,13 +15,19 @@ extern "C" { /* * Class: edu_wpi_first_wpilibj_hal_CompressorJNI * Method: initializeCompressor - * Signature: (B)J + * Signature: (B)I */ -JNIEXPORT jlong JNICALL +JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_CompressorJNI_initializeCompressor( JNIEnv *env, jclass, jbyte module) { - void *pcm = initializeCompressor(module); - return (jlong)pcm; + int32_t status = 0; + auto handle = initializeCompressor(module, &status); + if (status == PARAMETER_OUT_OF_RANGE) { + //TODO: Move 63 to a constant (Thad will do) + ThrowBoundaryException(env, module, 0, 63); + } + + return (jint)handle; } /* @@ -42,9 +48,9 @@ Java_edu_wpi_first_wpilibj_hal_CompressorJNI_checkCompressorModule( */ JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_CompressorJNI_getCompressor( - JNIEnv *env, jclass, jlong pcm_pointer) { + JNIEnv *env, jclass, jint compressor_handle) { int32_t status = 0; - bool val = getCompressor((void *)pcm_pointer, &status); + bool val = getCompressor((HalCompressorHandle)compressor_handle, &status); CheckStatus(env, status); return val; } @@ -56,9 +62,9 @@ Java_edu_wpi_first_wpilibj_hal_CompressorJNI_getCompressor( */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_CompressorJNI_setClosedLoopControl( - JNIEnv *env, jclass, jlong pcm_pointer, jboolean value) { + JNIEnv *env, jclass, jint compressor_handle, jboolean value) { int32_t status = 0; - setClosedLoopControl((void *)pcm_pointer, value, &status); + setClosedLoopControl((HalCompressorHandle)compressor_handle, value, &status); CheckStatus(env, status); } @@ -69,9 +75,9 @@ Java_edu_wpi_first_wpilibj_hal_CompressorJNI_setClosedLoopControl( */ JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_CompressorJNI_getClosedLoopControl( - JNIEnv *env, jclass, jlong pcm_pointer) { + JNIEnv *env, jclass, jint compressor_handle) { int32_t status = 0; - bool val = getClosedLoopControl((void *)pcm_pointer, &status); + bool val = getClosedLoopControl((HalCompressorHandle)compressor_handle, &status); CheckStatus(env, status); return val; } @@ -83,9 +89,9 @@ Java_edu_wpi_first_wpilibj_hal_CompressorJNI_getClosedLoopControl( */ JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_CompressorJNI_getPressureSwitch( - JNIEnv *env, jclass, jlong pcm_pointer) { + JNIEnv *env, jclass, jint compressor_handle) { int32_t status = 0; - bool val = getPressureSwitch((void *)pcm_pointer, &status); + bool val = getPressureSwitch((HalCompressorHandle)compressor_handle, &status); CheckStatus(env, status); return val; } @@ -97,9 +103,9 @@ Java_edu_wpi_first_wpilibj_hal_CompressorJNI_getPressureSwitch( */ JNIEXPORT jfloat JNICALL Java_edu_wpi_first_wpilibj_hal_CompressorJNI_getCompressorCurrent( - JNIEnv *env, jclass, jlong pcm_pointer) { + JNIEnv *env, jclass, jint compressor_handle) { int32_t status = 0; - float val = getCompressorCurrent((void *)pcm_pointer, &status); + float val = getCompressorCurrent((HalCompressorHandle)compressor_handle, &status); CheckStatus(env, status); return val; } @@ -111,9 +117,9 @@ Java_edu_wpi_first_wpilibj_hal_CompressorJNI_getCompressorCurrent( */ JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_CompressorJNI_getCompressorCurrentTooHighFault( - JNIEnv *env, jclass, jlong pcm_pointer) { + JNIEnv *env, jclass, jint compressor_handle) { int32_t status = 0; - bool val = getCompressorCurrentTooHighFault((void *)pcm_pointer, &status); + bool val = getCompressorCurrentTooHighFault((HalCompressorHandle)compressor_handle, &status); CheckStatus(env, status); return val; } @@ -125,10 +131,10 @@ Java_edu_wpi_first_wpilibj_hal_CompressorJNI_getCompressorCurrentTooHighFault( */ JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_CompressorJNI_getCompressorCurrentTooHighStickyFault( - JNIEnv *env, jclass, jlong pcm_pointer) { + JNIEnv *env, jclass, jint compressor_handle) { int32_t status = 0; bool val = - getCompressorCurrentTooHighStickyFault((void *)pcm_pointer, &status); + getCompressorCurrentTooHighStickyFault((HalCompressorHandle)compressor_handle, &status); CheckStatus(env, status); return val; } @@ -140,9 +146,9 @@ Java_edu_wpi_first_wpilibj_hal_CompressorJNI_getCompressorCurrentTooHighStickyFa */ JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_CompressorJNI_getCompressorShortedStickyFault( - JNIEnv *env, jclass, jlong pcm_pointer) { + JNIEnv *env, jclass, jint compressor_handle) { int32_t status = 0; - bool val = getCompressorShortedStickyFault((void *)pcm_pointer, &status); + bool val = getCompressorShortedStickyFault((HalCompressorHandle)compressor_handle, &status); CheckStatus(env, status); return val; } @@ -154,9 +160,9 @@ Java_edu_wpi_first_wpilibj_hal_CompressorJNI_getCompressorShortedStickyFault( */ JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_CompressorJNI_getCompressorShortedFault( - JNIEnv *env, jclass, jlong pcm_pointer) { + JNIEnv *env, jclass, jint compressor_handle) { int32_t status = 0; - bool val = getCompressorShortedFault((void *)pcm_pointer, &status); + bool val = getCompressorShortedFault((HalCompressorHandle)compressor_handle, &status); CheckStatus(env, status); return val; } @@ -168,9 +174,9 @@ Java_edu_wpi_first_wpilibj_hal_CompressorJNI_getCompressorShortedFault( */ JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_CompressorJNI_getCompressorNotConnectedStickyFault( - JNIEnv *env, jclass, jlong pcm_pointer) { + JNIEnv *env, jclass, jint compressor_handle) { int32_t status = 0; - bool val = getCompressorNotConnectedStickyFault((void *)pcm_pointer, &status); + bool val = getCompressorNotConnectedStickyFault((HalCompressorHandle)compressor_handle, &status); CheckStatus(env, status); return val; } @@ -182,9 +188,9 @@ Java_edu_wpi_first_wpilibj_hal_CompressorJNI_getCompressorNotConnectedStickyFaul */ JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_CompressorJNI_getCompressorNotConnectedFault( - JNIEnv *env, jclass, jlong pcm_pointer) { + JNIEnv *env, jclass, jint compressor_handle) { int32_t status = 0; - bool val = getCompressorNotConnectedFault((void *)pcm_pointer, &status); + bool val = getCompressorNotConnectedFault((HalCompressorHandle)compressor_handle, &status); CheckStatus(env, status); return val; } @@ -195,9 +201,9 @@ Java_edu_wpi_first_wpilibj_hal_CompressorJNI_getCompressorNotConnectedFault( */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_CompressorJNI_clearAllPCMStickyFaults( - JNIEnv *env, jclass, jlong pcm_pointer) { + JNIEnv *env, jclass, jint compressor_handle) { int32_t status = 0; - clearAllPCMStickyFaults((void *)pcm_pointer, &status); + clearAllPCMStickyFaults((HalCompressorHandle)compressor_handle, &status); CheckStatus(env, status); } diff --git a/wpilibj/src/athena/java/edu/wpi/first/wpilibj/Compressor.java b/wpilibj/src/athena/java/edu/wpi/first/wpilibj/Compressor.java index 1c1c966144..b9c391d53c 100644 --- a/wpilibj/src/athena/java/edu/wpi/first/wpilibj/Compressor.java +++ b/wpilibj/src/athena/java/edu/wpi/first/wpilibj/Compressor.java @@ -21,7 +21,7 @@ import edu.wpi.first.wpilibj.tables.ITable; * thereby stopping the compressor from operating. */ public class Compressor extends SensorBase implements LiveWindowSendable { - private long m_pcm; + private int m_compressorHandle; /** * Constructor. @@ -34,7 +34,7 @@ public class Compressor extends SensorBase implements LiveWindowSendable { public Compressor(int module) { m_table = null; - m_pcm = CompressorJNI.initializeCompressor((byte) module); + m_compressorHandle = CompressorJNI.initializeCompressor((byte) module); } /** @@ -70,7 +70,7 @@ public class Compressor extends SensorBase implements LiveWindowSendable { * @return true if the compressor is on */ public boolean enabled() { - return CompressorJNI.getCompressor(m_pcm); + return CompressorJNI.getCompressor(m_compressorHandle); } /** @@ -79,7 +79,7 @@ public class Compressor extends SensorBase implements LiveWindowSendable { * @return true if the pressure is low by reading the pressure switch that is plugged into the PCM */ public boolean getPressureSwitchValue() { - return CompressorJNI.getPressureSwitch(m_pcm); + return CompressorJNI.getPressureSwitch(m_compressorHandle); } /** @@ -88,7 +88,7 @@ public class Compressor extends SensorBase implements LiveWindowSendable { * @return current consumed in amps for the compressor motor */ public float getCompressorCurrent() { - return CompressorJNI.getCompressorCurrent(m_pcm); + return CompressorJNI.getCompressorCurrent(m_compressorHandle); } /** @@ -98,7 +98,7 @@ public class Compressor extends SensorBase implements LiveWindowSendable { * operation of the compressor is disabled. */ public void setClosedLoopControl(boolean on) { - CompressorJNI.setClosedLoopControl(m_pcm, on); + CompressorJNI.setClosedLoopControl(m_compressorHandle, on); } /** @@ -107,7 +107,7 @@ public class Compressor extends SensorBase implements LiveWindowSendable { * @return true if compressor is operating on closed-loop mode, otherwise return false. */ public boolean getClosedLoopControl() { - return CompressorJNI.getClosedLoopControl(m_pcm); + return CompressorJNI.getClosedLoopControl(m_compressorHandle); } /** @@ -117,7 +117,7 @@ public class Compressor extends SensorBase implements LiveWindowSendable { * @return true if PCM is in fault state. */ public boolean getCompressorCurrentTooHighFault() { - return CompressorJNI.getCompressorCurrentTooHighFault(m_pcm); + return CompressorJNI.getCompressorCurrentTooHighFault(m_compressorHandle); } /** @@ -127,21 +127,21 @@ public class Compressor extends SensorBase implements LiveWindowSendable { * @return true if PCM sticky fault is set. */ public boolean getCompressorCurrentTooHighStickyFault() { - return CompressorJNI.getCompressorCurrentTooHighStickyFault(m_pcm); + return CompressorJNI.getCompressorCurrentTooHighStickyFault(m_compressorHandle); } /** * @return true if PCM sticky fault is set : Compressor output appears to be shorted. */ public boolean getCompressorShortedStickyFault() { - return CompressorJNI.getCompressorShortedStickyFault(m_pcm); + return CompressorJNI.getCompressorShortedStickyFault(m_compressorHandle); } /** * @return true if PCM is in fault state : Compressor output appears to be shorted. */ public boolean getCompressorShortedFault() { - return CompressorJNI.getCompressorShortedFault(m_pcm); + return CompressorJNI.getCompressorShortedFault(m_compressorHandle); } /** @@ -151,7 +151,7 @@ public class Compressor extends SensorBase implements LiveWindowSendable { * @return true if PCM sticky fault is set. */ public boolean getCompressorNotConnectedStickyFault() { - return CompressorJNI.getCompressorNotConnectedStickyFault(m_pcm); + return CompressorJNI.getCompressorNotConnectedStickyFault(m_compressorHandle); } /** @@ -161,7 +161,7 @@ public class Compressor extends SensorBase implements LiveWindowSendable { * @return true if PCM is in fault state. */ public boolean getCompressorNotConnectedFault() { - return CompressorJNI.getCompressorNotConnectedFault(m_pcm); + return CompressorJNI.getCompressorNotConnectedFault(m_compressorHandle); } /** @@ -174,7 +174,7 @@ public class Compressor extends SensorBase implements LiveWindowSendable { *

If no sticky faults are set then this call will have no effect. */ public void clearAllPCMStickyFaults() { - CompressorJNI.clearAllPCMStickyFaults(m_pcm); + CompressorJNI.clearAllPCMStickyFaults(m_compressorHandle); } @Override diff --git a/wpilibj/src/athena/java/edu/wpi/first/wpilibj/hal/CompressorJNI.java b/wpilibj/src/athena/java/edu/wpi/first/wpilibj/hal/CompressorJNI.java index 36498dc2e5..ead9118f7e 100644 --- a/wpilibj/src/athena/java/edu/wpi/first/wpilibj/hal/CompressorJNI.java +++ b/wpilibj/src/athena/java/edu/wpi/first/wpilibj/hal/CompressorJNI.java @@ -8,31 +8,31 @@ package edu.wpi.first.wpilibj.hal; public class CompressorJNI extends JNIWrapper { - public static native long initializeCompressor(byte module); + public static native int initializeCompressor(byte module); public static native boolean checkCompressorModule(byte module); - public static native boolean getCompressor(long pcmPointer); + public static native boolean getCompressor(int compressorHandle); - public static native void setClosedLoopControl(long pcmPointer, boolean value); + public static native void setClosedLoopControl(int compressorHandle, boolean value); - public static native boolean getClosedLoopControl(long pcmPointer); + public static native boolean getClosedLoopControl(int compressorHandle); - public static native boolean getPressureSwitch(long pcmPointer); + public static native boolean getPressureSwitch(int compressorHandle); - public static native float getCompressorCurrent(long pcmPointer); + public static native float getCompressorCurrent(int compressorHandle); - public static native boolean getCompressorCurrentTooHighFault(long pcmPointer); + public static native boolean getCompressorCurrentTooHighFault(int compressorHandle); - public static native boolean getCompressorCurrentTooHighStickyFault(long pcmPointer); + public static native boolean getCompressorCurrentTooHighStickyFault(int compressorHandle); - public static native boolean getCompressorShortedStickyFault(long pcmPointer); + public static native boolean getCompressorShortedStickyFault(int compressorHandle); - public static native boolean getCompressorShortedFault(long pcmPointer); + public static native boolean getCompressorShortedFault(int compressorHandle); - public static native boolean getCompressorNotConnectedStickyFault(long pcmPointer); + public static native boolean getCompressorNotConnectedStickyFault(int compressorHandle); - public static native boolean getCompressorNotConnectedFault(long pcmPointer); + public static native boolean getCompressorNotConnectedFault(int compressorHandle); - public static native void clearAllPCMStickyFaults(long pcmPointer); + public static native void clearAllPCMStickyFaults(int compressorHandle); }