mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-03 03:01:44 +00:00
Move Analog Outputs to Handles (#112)
This commit is contained in:
committed by
Peter Johnson
parent
95d40ed01f
commit
e1d4845ccd
@@ -60,16 +60,16 @@ Java_edu_wpi_first_wpilibj_hal_AnalogJNI_freeAnalogInputPort(
|
||||
/*
|
||||
* Class: edu_wpi_first_wpilibj_hal_AnalogJNI
|
||||
* Method: initializeAnalogOutputPort
|
||||
* Signature: (I)J
|
||||
* Signature: (I)I
|
||||
*/
|
||||
JNIEXPORT jlong JNICALL
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_edu_wpi_first_wpilibj_hal_AnalogJNI_initializeAnalogOutputPort(
|
||||
JNIEnv *env, jclass, jint id) {
|
||||
ANALOGJNI_LOG(logDEBUG) << "Port Handle = " << (HalPortHandle)id;
|
||||
int32_t status = 0;
|
||||
void *analog = initializeAnalogOutputPort((HalPortHandle)id, &status);
|
||||
HalAnalogOutputHandle analog = initializeAnalogOutputPort((HalPortHandle)id, &status);
|
||||
ANALOGJNI_LOG(logDEBUG) << "Status = " << status;
|
||||
ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << analog;
|
||||
ANALOGJNI_LOG(logDEBUG) << "Analog Handle = " << analog;
|
||||
CheckStatus(env, status);
|
||||
return (jlong)analog;
|
||||
}
|
||||
@@ -77,13 +77,13 @@ Java_edu_wpi_first_wpilibj_hal_AnalogJNI_initializeAnalogOutputPort(
|
||||
/*
|
||||
* Class: edu_wpi_first_wpilibj_hal_AnalogJNI
|
||||
* Method: freeAnalogOutputPort
|
||||
* Signature: (J)V
|
||||
* Signature: (I)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_wpilibj_hal_AnalogJNI_freeAnalogOutputPort(
|
||||
JNIEnv *env, jclass, jlong id) {
|
||||
ANALOGJNI_LOG(logDEBUG) << "Port Ptr = " << (void *)id;
|
||||
freeAnalogOutputPort((void *)id);
|
||||
JNIEnv *env, jclass, jint id) {
|
||||
ANALOGJNI_LOG(logDEBUG) << "Port Handle = " << id;
|
||||
freeAnalogOutputPort((HalAnalogOutputHandle)id);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -134,28 +134,28 @@ Java_edu_wpi_first_wpilibj_hal_AnalogJNI_checkAnalogOutputChannel(
|
||||
/*
|
||||
* Class: edu_wpi_first_wpilibj_hal_AnalogJNI
|
||||
* Method: setAnalogOutput
|
||||
* Signature: (JD)V
|
||||
* Signature: (ID)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_setAnalogOutput(
|
||||
JNIEnv *env, jclass, jlong id, jdouble voltage) {
|
||||
JNIEnv *env, jclass, jint id, jdouble voltage) {
|
||||
ANALOGJNI_LOG(logDEBUG) << "Calling setAnalogOutput";
|
||||
ANALOGJNI_LOG(logDEBUG) << "Voltage = " << voltage;
|
||||
ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << (void *)id;
|
||||
ANALOGJNI_LOG(logDEBUG) << "Analog Handle = " << id;
|
||||
int32_t status = 0;
|
||||
setAnalogOutput((void *)id, voltage, &status);
|
||||
setAnalogOutput((HalAnalogOutputHandle)id, voltage, &status);
|
||||
CheckStatus(env, status);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_wpilibj_hal_AnalogJNI
|
||||
* Method: getAnalogOutput
|
||||
* Signature: (J)D
|
||||
* Signature: (I)D
|
||||
*/
|
||||
JNIEXPORT jdouble JNICALL
|
||||
Java_edu_wpi_first_wpilibj_hal_AnalogJNI_getAnalogOutput(
|
||||
JNIEnv *env, jclass, jlong id) {
|
||||
JNIEnv *env, jclass, jint id) {
|
||||
int32_t status = 0;
|
||||
double val = getAnalogOutput((void *)id, &status);
|
||||
double val = getAnalogOutput((HalAnalogOutputHandle)id, &status);
|
||||
CheckStatus(env, status);
|
||||
return val;
|
||||
}
|
||||
|
||||
@@ -14,14 +14,12 @@ import edu.wpi.first.wpilibj.livewindow.LiveWindow;
|
||||
import edu.wpi.first.wpilibj.livewindow.LiveWindowSendable;
|
||||
import edu.wpi.first.wpilibj.tables.ITable;
|
||||
import edu.wpi.first.wpilibj.util.AllocationException;
|
||||
import edu.wpi.first.wpilibj.util.CheckedAllocationException;
|
||||
|
||||
/**
|
||||
* Analog output class.
|
||||
*/
|
||||
public class AnalogOutput extends SensorBase implements LiveWindowSendable {
|
||||
private static Resource channels = new Resource(kAnalogOutputChannels);
|
||||
private long m_port;
|
||||
private int m_port;
|
||||
private int m_channel;
|
||||
|
||||
/**
|
||||
@@ -36,14 +34,10 @@ public class AnalogOutput extends SensorBase implements LiveWindowSendable {
|
||||
throw new AllocationException("Analog output channel " + m_channel
|
||||
+ " cannot be allocated. Channel is not present.");
|
||||
}
|
||||
try {
|
||||
channels.allocate(channel);
|
||||
} catch (CheckedAllocationException ex) {
|
||||
throw new AllocationException("Analog output channel " + m_channel + " is already allocated");
|
||||
}
|
||||
|
||||
final int portHandle = AnalogJNI.getPort((byte) channel);
|
||||
m_port = AnalogJNI.initializeAnalogOutputPort(portHandle);
|
||||
AnalogJNI.freePort(portHandle);
|
||||
|
||||
LiveWindow.addSensor("AnalogOutput", channel, this);
|
||||
UsageReporting.report(tResourceType.kResourceType_AnalogOutput, channel);
|
||||
@@ -55,7 +49,6 @@ public class AnalogOutput extends SensorBase implements LiveWindowSendable {
|
||||
public void free() {
|
||||
AnalogJNI.freeAnalogOutputPort(m_port);
|
||||
m_port = 0;
|
||||
channels.free(m_channel);
|
||||
m_channel = 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -37,9 +37,9 @@ public class AnalogJNI extends JNIWrapper {
|
||||
|
||||
public static native void freeAnalogInputPort(long portPointer);
|
||||
|
||||
public static native long initializeAnalogOutputPort(int halPortHandle);
|
||||
public static native int initializeAnalogOutputPort(int halPortHandle);
|
||||
|
||||
public static native void freeAnalogOutputPort(long portPointer);
|
||||
public static native void freeAnalogOutputPort(int portHandle);
|
||||
|
||||
public static native boolean checkAnalogModule(byte module);
|
||||
|
||||
@@ -47,9 +47,9 @@ public class AnalogJNI extends JNIWrapper {
|
||||
|
||||
public static native boolean checkAnalogOutputChannel(int pin);
|
||||
|
||||
public static native void setAnalogOutput(long portPointer, double voltage);
|
||||
public static native void setAnalogOutput(int portHandle, double voltage);
|
||||
|
||||
public static native double getAnalogOutput(long portPointer);
|
||||
public static native double getAnalogOutput(int portHandle);
|
||||
|
||||
public static native void setAnalogSampleRate(double samplesPerSecond);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user