mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-27 02:01:42 +00:00
AnalogInput: Remove byte buffer usage.
This commit is contained in:
@@ -7,9 +7,6 @@
|
||||
|
||||
package edu.wpi.first.wpilibj;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
import edu.wpi.first.networktables.NetworkTable;
|
||||
import edu.wpi.first.networktables.NetworkTableEntry;
|
||||
import edu.wpi.first.wpilibj.hal.AnalogJNI;
|
||||
@@ -289,15 +286,8 @@ public class AnalogInput extends SensorBase implements PIDSource, LiveWindowSend
|
||||
throw new IllegalArgumentException(
|
||||
"Channel " + m_channel + " is not an accumulator channel.");
|
||||
}
|
||||
ByteBuffer value = ByteBuffer.allocateDirect(8);
|
||||
// set the byte order
|
||||
value.order(ByteOrder.LITTLE_ENDIAN);
|
||||
ByteBuffer count = ByteBuffer.allocateDirect(8);
|
||||
// set the byte order
|
||||
count.order(ByteOrder.LITTLE_ENDIAN);
|
||||
AnalogJNI.getAccumulatorOutput(m_port, value.asLongBuffer(), count.asLongBuffer());
|
||||
result.value = value.asLongBuffer().get(0) + m_accumulatorOffset;
|
||||
result.count = count.asLongBuffer().get(0);
|
||||
AnalogJNI.getAccumulatorOutput(m_port, result);
|
||||
result.value += m_accumulatorOffset;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
|
||||
package edu.wpi.first.wpilibj.hal;
|
||||
|
||||
import edu.wpi.first.wpilibj.AccumulatorResult;
|
||||
import java.nio.IntBuffer;
|
||||
import java.nio.LongBuffer;
|
||||
|
||||
public class AnalogJNI extends JNIWrapper {
|
||||
/**
|
||||
@@ -91,8 +91,7 @@ public class AnalogJNI extends JNIWrapper {
|
||||
|
||||
public static native int getAccumulatorCount(int analogPortHandle);
|
||||
|
||||
public static native void getAccumulatorOutput(int analogPortHandle, LongBuffer value,
|
||||
LongBuffer count);
|
||||
public static native void getAccumulatorOutput(int analogPortHandle, AccumulatorResult result);
|
||||
|
||||
public static native int initializeAnalogTrigger(int analogInputHandle, IntBuffer index);
|
||||
|
||||
|
||||
@@ -500,22 +500,19 @@ Java_edu_wpi_first_wpilibj_hal_AnalogJNI_getAccumulatorCount(
|
||||
/*
|
||||
* Class: edu_wpi_first_wpilibj_hal_AnalogJNI
|
||||
* Method: getAccumulatorOutput
|
||||
* Signature: (ILjava/nio/LongBuffer;Ljava/nio/LongBuffer;)V
|
||||
* Signature: (ILedu/wpi/first/wpilibj/AccumulatorResult;)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_wpilibj_hal_AnalogJNI_getAccumulatorOutput(
|
||||
JNIEnv *env, jclass, jint id, jobject value, jobject count) {
|
||||
JNIEnv *env, jclass, jint id, jobject accumulatorResult) {
|
||||
ANALOGJNI_LOG(logDEBUG) << "Analog Handle = " << (HAL_AnalogInputHandle)id;
|
||||
int32_t status = 0;
|
||||
jlong *valuePtr = (jlong *)env->GetDirectBufferAddress(value);
|
||||
jlong *countPtr = (jlong *)env->GetDirectBufferAddress(count);
|
||||
int64_t valueInt64;
|
||||
int64_t countInt64;
|
||||
HAL_GetAccumulatorOutput((HAL_AnalogInputHandle)id, &valueInt64, &countInt64, &status);
|
||||
*valuePtr = valueInt64;
|
||||
*countPtr = countInt64;
|
||||
ANALOGJNI_LOG(logDEBUG) << "Value = " << *valuePtr;
|
||||
ANALOGJNI_LOG(logDEBUG) << "Count = " << *countPtr;
|
||||
int64_t value = 0;
|
||||
int64_t count = 0;
|
||||
HAL_GetAccumulatorOutput((HAL_AnalogInputHandle)id, &value, &count, &status);
|
||||
SetAccumulatorResultObject(env, accumulatorResult, value, count);
|
||||
ANALOGJNI_LOG(logDEBUG) << "Value = " << value;
|
||||
ANALOGJNI_LOG(logDEBUG) << "Count = " << count;
|
||||
ANALOGJNI_LOG(logDEBUG) << "Status = " << status;
|
||||
CheckStatus(env, status);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user