Switches compressor to handles (#125)

This commit is contained in:
Thad House
2016-07-02 08:22:44 -07:00
committed by Peter Johnson
parent 0f105a26f7
commit 62c217cd01
9 changed files with 253 additions and 114 deletions

View File

@@ -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);
}

View File

@@ -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 {
* <p>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

View File

@@ -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);
}