Fix endian order of buffers in AnalogTrigger.java

Change-Id: Ica262494c4b8169d812295006e24f9cb440de078
This commit is contained in:
Kevin O'Connor
2015-02-13 11:16:55 -05:00
parent 215002e487
commit 605bb45e0c

View File

@@ -15,6 +15,7 @@ import edu.wpi.first.wpilibj.hal.HALUtil;
import edu.wpi.first.wpilibj.util.BoundaryException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.IntBuffer;
//import com.sun.jna.Pointer;
@@ -57,12 +58,14 @@ public class AnalogTrigger {
*/
protected void initTrigger(final int channel) {
ByteBuffer port_pointer = AnalogJNI.getPort((byte) channel);
IntBuffer index = ByteBuffer.allocateDirect(4).asIntBuffer();
IntBuffer status = ByteBuffer.allocateDirect(4).asIntBuffer();
ByteBuffer index = ByteBuffer.allocateDirect(4);
ByteBuffer status = ByteBuffer.allocateDirect(4);
index.order(ByteOrder.LITTLE_ENDIAN);
status.order(ByteOrder.LITTLE_ENDIAN);
m_port = AnalogJNI.initializeAnalogTrigger(port_pointer, index, status);
HALUtil.checkStatus(status);
m_index = index.get(0);
m_port = AnalogJNI.initializeAnalogTrigger(port_pointer, index.asIntBuffer(), status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
m_index = index.asIntBuffer().get(0);
UsageReporting.report(tResourceType.kResourceType_AnalogTrigger, channel);
}
@@ -96,9 +99,10 @@ public class AnalogTrigger {
* Release the resources used by this object
*/
public void free() {
IntBuffer status = ByteBuffer.allocateDirect(4).asIntBuffer();
AnalogJNI.cleanAnalogTrigger(m_port, status);
HALUtil.checkStatus(status);
ByteBuffer status = ByteBuffer.allocateDirect(4);
status.order(ByteOrder.LITTLE_ENDIAN);
AnalogJNI.cleanAnalogTrigger(m_port, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
m_port = null;
}
@@ -116,9 +120,10 @@ public class AnalogTrigger {
if (lower > upper) {
throw new BoundaryException("Lower bound is greater than upper");
}
IntBuffer status = ByteBuffer.allocateDirect(4).asIntBuffer();
AnalogJNI.setAnalogTriggerLimitsRaw(m_port, lower, upper, status);
HALUtil.checkStatus(status);
ByteBuffer status = ByteBuffer.allocateDirect(4);
status.order(ByteOrder.LITTLE_ENDIAN);
AnalogJNI.setAnalogTriggerLimitsRaw(m_port, lower, upper, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
}
/**
@@ -135,10 +140,11 @@ public class AnalogTrigger {
throw new BoundaryException(
"Lower bound is greater than upper bound");
}
IntBuffer status = ByteBuffer.allocateDirect(4).asIntBuffer();
ByteBuffer status = ByteBuffer.allocateDirect(4);
status.order(ByteOrder.LITTLE_ENDIAN);
AnalogJNI.setAnalogTriggerLimitsVoltage(m_port, (float) lower,
(float) upper, status);
HALUtil.checkStatus(status);
(float) upper, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
}
/**
@@ -150,10 +156,11 @@ public class AnalogTrigger {
* true to use an averaged value, false otherwise
*/
public void setAveraged(boolean useAveragedValue) {
IntBuffer status = ByteBuffer.allocateDirect(4).asIntBuffer();
ByteBuffer status = ByteBuffer.allocateDirect(4);
status.order(ByteOrder.LITTLE_ENDIAN);
AnalogJNI.setAnalogTriggerAveraged(m_port,
(byte) (useAveragedValue ? 1 : 0), status);
HALUtil.checkStatus(status);
(byte) (useAveragedValue ? 1 : 0), status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
}
/**
@@ -166,10 +173,11 @@ public class AnalogTrigger {
* true to use a filterd value, false otherwise
*/
public void setFiltered(boolean useFilteredValue) {
IntBuffer status = ByteBuffer.allocateDirect(4).asIntBuffer();
ByteBuffer status = ByteBuffer.allocateDirect(4);
status.order(ByteOrder.LITTLE_ENDIAN);
AnalogJNI.setAnalogTriggerFiltered(m_port,
(byte) (useFilteredValue ? 1 : 0), status);
HALUtil.checkStatus(status);
(byte) (useFilteredValue ? 1 : 0), status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
}
/**
@@ -189,9 +197,10 @@ public class AnalogTrigger {
* @return The InWindow output of the analog trigger.
*/
public boolean getInWindow() {
IntBuffer status = ByteBuffer.allocateDirect(4).asIntBuffer();
byte value = AnalogJNI.getAnalogTriggerInWindow(m_port, status);
HALUtil.checkStatus(status);
ByteBuffer status = ByteBuffer.allocateDirect(4);
status.order(ByteOrder.LITTLE_ENDIAN);
byte value = AnalogJNI.getAnalogTriggerInWindow(m_port, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
return value != 0;
}
@@ -203,9 +212,10 @@ public class AnalogTrigger {
* @return The TriggerState output of the analog trigger.
*/
public boolean getTriggerState() {
IntBuffer status = ByteBuffer.allocateDirect(4).asIntBuffer();
byte value = AnalogJNI.getAnalogTriggerTriggerState(m_port, status);
HALUtil.checkStatus(status);
ByteBuffer status = ByteBuffer.allocateDirect(4);
status.order(ByteOrder.LITTLE_ENDIAN);
byte value = AnalogJNI.getAnalogTriggerTriggerState(m_port, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
return value != 0;
}