mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-26 01:51:41 +00:00
Simplify JNI interfaces.
These changes both simplify the Java code and improve performance across the JNI boundary. This also fixes the AnalogCrossConnectTest by adding delays to setInterruptHigh() and setInterruptLow() to ensure the change in voltage has time to propagate and extends the timeouts in AbstractInterruptTest. Detailed changes: Hoisted status checks to C. This avoids the need to create direct byte buffers (expensive) and significantly simplifies the Java code. The C code now directly generates the exception or reports the error to the DS. The JVM pointer is now a global across the JNI, initialized by the OnLoad function, avoiding the need for some of the class-specific initializers to get this pointer for callbacks. Opaque pointers (such as ports) are now passed as long values rather than with a ByteBuffer wrapper. Added extern "C" to source files. This allows earlier detection of JNI definition mismatches to the Java source headers. Changed JNI signatures to more closely match HAL signatures (in particular, boolean is now universally used instead of byte for HAL bool, which cleans up mapping back and forth to 1/0 from true/false). Change-Id: I4ea0032cabb0871cd74106a3a70d947258c29d2d
This commit is contained in:
committed by
Brad Miller (WPI)
parent
927400a43c
commit
7023013c4b
@@ -16,7 +16,6 @@ import java.nio.ByteBuffer;
|
||||
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType;
|
||||
import edu.wpi.first.wpilibj.communication.UsageReporting;
|
||||
import edu.wpi.first.wpilibj.hal.AnalogJNI;
|
||||
import edu.wpi.first.wpilibj.hal.HALUtil;
|
||||
import edu.wpi.first.wpilibj.livewindow.LiveWindow;
|
||||
import edu.wpi.first.wpilibj.livewindow.LiveWindowSendable;
|
||||
import edu.wpi.first.wpilibj.tables.ITable;
|
||||
@@ -42,7 +41,7 @@ public class AnalogInput extends SensorBase implements PIDSource, LiveWindowSend
|
||||
|
||||
private static final int kAccumulatorSlot = 1;
|
||||
private static Resource channels = new Resource(kAnalogInputChannels);
|
||||
private ByteBuffer m_port;
|
||||
private long m_port;
|
||||
private int m_channel;
|
||||
private static final int[] kAccumulatorChannels = {0, 1};
|
||||
private long m_accumulatorOffset;
|
||||
@@ -57,7 +56,7 @@ public class AnalogInput extends SensorBase implements PIDSource, LiveWindowSend
|
||||
public AnalogInput(final int channel) {
|
||||
m_channel = channel;
|
||||
|
||||
if (AnalogJNI.checkAnalogInputChannel(channel) == 0) {
|
||||
if (!AnalogJNI.checkAnalogInputChannel(channel)) {
|
||||
throw new AllocationException("Analog input channel " + m_channel
|
||||
+ " cannot be allocated. Channel is not present.");
|
||||
}
|
||||
@@ -67,12 +66,8 @@ public class AnalogInput extends SensorBase implements PIDSource, LiveWindowSend
|
||||
throw new AllocationException("Analog input channel " + m_channel + " is already allocated");
|
||||
}
|
||||
|
||||
ByteBuffer port_pointer = AnalogJNI.getPort((byte) channel);
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
m_port = AnalogJNI.initializeAnalogInputPort(port_pointer, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
long port_pointer = AnalogJNI.getPort((byte) channel);
|
||||
m_port = AnalogJNI.initializeAnalogInputPort(port_pointer);
|
||||
|
||||
LiveWindow.addSensor("AnalogInput", channel, this);
|
||||
UsageReporting.report(tResourceType.kResourceType_AnalogChannel, channel);
|
||||
@@ -96,12 +91,7 @@ public class AnalogInput extends SensorBase implements PIDSource, LiveWindowSend
|
||||
* @return A sample straight from this channel.
|
||||
*/
|
||||
public int getValue() {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
int value = AnalogJNI.getAnalogValue(m_port, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
return value;
|
||||
return AnalogJNI.getAnalogValue(m_port);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -116,12 +106,7 @@ public class AnalogInput extends SensorBase implements PIDSource, LiveWindowSend
|
||||
* @return A sample from the oversample and average engine for this channel.
|
||||
*/
|
||||
public int getAverageValue() {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
int value = AnalogJNI.getAnalogAverageValue(m_port, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
return value;
|
||||
return AnalogJNI.getAnalogAverageValue(m_port);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -132,12 +117,7 @@ public class AnalogInput extends SensorBase implements PIDSource, LiveWindowSend
|
||||
* @return A scaled sample straight from this channel.
|
||||
*/
|
||||
public double getVoltage() {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
double value = AnalogJNI.getAnalogVoltage(m_port, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
return value;
|
||||
return AnalogJNI.getAnalogVoltage(m_port);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -152,12 +132,7 @@ public class AnalogInput extends SensorBase implements PIDSource, LiveWindowSend
|
||||
* engine for this channel.
|
||||
*/
|
||||
public double getAverageVoltage() {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
double value = AnalogJNI.getAnalogAverageVoltage(m_port, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
return value;
|
||||
return AnalogJNI.getAnalogAverageVoltage(m_port);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -170,12 +145,7 @@ public class AnalogInput extends SensorBase implements PIDSource, LiveWindowSend
|
||||
* @return Least significant bit weight.
|
||||
*/
|
||||
public long getLSBWeight() {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
long value = AnalogJNI.getAnalogLSBWeight(m_port, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
return value;
|
||||
return AnalogJNI.getAnalogLSBWeight(m_port);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -187,12 +157,7 @@ public class AnalogInput extends SensorBase implements PIDSource, LiveWindowSend
|
||||
* @return Offset constant.
|
||||
*/
|
||||
public int getOffset() {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
int value = AnalogJNI.getAnalogOffset(m_port, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
return value;
|
||||
return AnalogJNI.getAnalogOffset(m_port);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -212,11 +177,7 @@ public class AnalogInput extends SensorBase implements PIDSource, LiveWindowSend
|
||||
* @param bits The number of averaging bits.
|
||||
*/
|
||||
public void setAverageBits(final int bits) {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
AnalogJNI.setAnalogAverageBits(m_port, bits, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
AnalogJNI.setAnalogAverageBits(m_port, bits);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -227,12 +188,7 @@ public class AnalogInput extends SensorBase implements PIDSource, LiveWindowSend
|
||||
* @return The number of averaging bits.
|
||||
*/
|
||||
public int getAverageBits() {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
int value = AnalogJNI.getAnalogAverageBits(m_port, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
return value;
|
||||
return AnalogJNI.getAnalogAverageBits(m_port);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -243,11 +199,7 @@ public class AnalogInput extends SensorBase implements PIDSource, LiveWindowSend
|
||||
* @param bits The number of oversample bits.
|
||||
*/
|
||||
public void setOversampleBits(final int bits) {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
AnalogJNI.setAnalogOversampleBits(m_port, bits, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
AnalogJNI.setAnalogOversampleBits(m_port, bits);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -258,12 +210,7 @@ public class AnalogInput extends SensorBase implements PIDSource, LiveWindowSend
|
||||
* @return The number of oversample bits.
|
||||
*/
|
||||
public int getOversampleBits() {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
int value = AnalogJNI.getAnalogOversampleBits(m_port, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
return value;
|
||||
return AnalogJNI.getAnalogOversampleBits(m_port);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -275,11 +222,7 @@ public class AnalogInput extends SensorBase implements PIDSource, LiveWindowSend
|
||||
+ " on channels " + kAccumulatorChannels[0] + "," + kAccumulatorChannels[1]);
|
||||
}
|
||||
m_accumulatorOffset = 0;
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
AnalogJNI.initAccumulator(m_port, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
AnalogJNI.initAccumulator(m_port);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -298,11 +241,7 @@ public class AnalogInput extends SensorBase implements PIDSource, LiveWindowSend
|
||||
* Resets the accumulator to the initial value.
|
||||
*/
|
||||
public void resetAccumulator() {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
AnalogJNI.resetAccumulator(m_port, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
AnalogJNI.resetAccumulator(m_port);
|
||||
|
||||
// Wait until the next sample, so the next call to getAccumulator*()
|
||||
// won't have old values.
|
||||
@@ -325,11 +264,7 @@ public class AnalogInput extends SensorBase implements PIDSource, LiveWindowSend
|
||||
* bits will affect the size of the value for this field.
|
||||
*/
|
||||
public void setAccumulatorCenter(int center) {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
AnalogJNI.setAccumulatorCenter(m_port, center, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
AnalogJNI.setAccumulatorCenter(m_port, center);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -338,11 +273,7 @@ public class AnalogInput extends SensorBase implements PIDSource, LiveWindowSend
|
||||
* @param deadband The deadband size in ADC codes (12-bit value)
|
||||
*/
|
||||
public void setAccumulatorDeadband(int deadband) {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
AnalogJNI.setAccumulatorDeadband(m_port, deadband, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
AnalogJNI.setAccumulatorDeadband(m_port, deadband);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -354,12 +285,7 @@ public class AnalogInput extends SensorBase implements PIDSource, LiveWindowSend
|
||||
* @return The 64-bit value accumulated since the last Reset().
|
||||
*/
|
||||
public long getAccumulatorValue() {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
long value = AnalogJNI.getAccumulatorValue(m_port, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
return value + m_accumulatorOffset;
|
||||
return AnalogJNI.getAccumulatorValue(m_port) + m_accumulatorOffset;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -371,12 +297,7 @@ public class AnalogInput extends SensorBase implements PIDSource, LiveWindowSend
|
||||
* @return The number of times samples from the channel were accumulated.
|
||||
*/
|
||||
public long getAccumulatorCount() {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
long value = AnalogJNI.getAccumulatorCount(m_port, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
return value;
|
||||
return AnalogJNI.getAccumulatorCount(m_port);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -400,14 +321,9 @@ public class AnalogInput extends SensorBase implements PIDSource, LiveWindowSend
|
||||
ByteBuffer count = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
count.order(ByteOrder.LITTLE_ENDIAN);
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
AnalogJNI.getAccumulatorOutput(m_port, value.asLongBuffer(), count.asIntBuffer(),
|
||||
status.asIntBuffer());
|
||||
AnalogJNI.getAccumulatorOutput(m_port, value.asLongBuffer(), count.asIntBuffer());
|
||||
result.value = value.asLongBuffer().get(0) + m_accumulatorOffset;
|
||||
result.count = count.asIntBuffer().get(0);
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -434,12 +350,7 @@ public class AnalogInput extends SensorBase implements PIDSource, LiveWindowSend
|
||||
* @param samplesPerSecond The number of samples per second.
|
||||
*/
|
||||
public static void setGlobalSampleRate(final double samplesPerSecond) {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
AnalogJNI.setAnalogSampleRate((float) samplesPerSecond, status.asIntBuffer());
|
||||
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
AnalogJNI.setAnalogSampleRate((float) samplesPerSecond);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -451,14 +362,7 @@ public class AnalogInput extends SensorBase implements PIDSource, LiveWindowSend
|
||||
* @return Sample rate.
|
||||
*/
|
||||
public static double getGlobalSampleRate() {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
double value = AnalogJNI.getAnalogSampleRate(status.asIntBuffer());
|
||||
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
|
||||
return value;
|
||||
return AnalogJNI.getAnalogSampleRate();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -6,17 +6,9 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
package edu.wpi.first.wpilibj;
|
||||
|
||||
import java.nio.ByteOrder;
|
||||
import java.nio.IntBuffer;
|
||||
import java.nio.LongBuffer;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
// import com.sun.jna.Pointer;
|
||||
|
||||
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType;
|
||||
import edu.wpi.first.wpilibj.communication.UsageReporting;
|
||||
import edu.wpi.first.wpilibj.hal.AnalogJNI;
|
||||
import edu.wpi.first.wpilibj.hal.HALUtil;
|
||||
import edu.wpi.first.wpilibj.livewindow.LiveWindow;
|
||||
import edu.wpi.first.wpilibj.livewindow.LiveWindowSendable;
|
||||
import edu.wpi.first.wpilibj.tables.ITable;
|
||||
@@ -28,7 +20,7 @@ import edu.wpi.first.wpilibj.util.CheckedAllocationException;
|
||||
*/
|
||||
public class AnalogOutput extends SensorBase implements LiveWindowSendable {
|
||||
private static Resource channels = new Resource(kAnalogOutputChannels);
|
||||
private ByteBuffer m_port;
|
||||
private long m_port;
|
||||
private int m_channel;
|
||||
|
||||
/**
|
||||
@@ -39,7 +31,7 @@ public class AnalogOutput extends SensorBase implements LiveWindowSendable {
|
||||
public AnalogOutput(final int channel) {
|
||||
m_channel = channel;
|
||||
|
||||
if (AnalogJNI.checkAnalogOutputChannel(channel) == 0) {
|
||||
if (!AnalogJNI.checkAnalogOutputChannel(channel)) {
|
||||
throw new AllocationException("Analog output channel " + m_channel
|
||||
+ " cannot be allocated. Channel is not present.");
|
||||
}
|
||||
@@ -49,12 +41,8 @@ public class AnalogOutput extends SensorBase implements LiveWindowSendable {
|
||||
throw new AllocationException("Analog output channel " + m_channel + " is already allocated");
|
||||
}
|
||||
|
||||
ByteBuffer port_pointer = AnalogJNI.getPort((byte) channel);
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
m_port = AnalogJNI.initializeAnalogOutputPort(port_pointer, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
long port_pointer = AnalogJNI.getPort((byte) channel);
|
||||
m_port = AnalogJNI.initializeAnalogOutputPort(port_pointer);
|
||||
|
||||
LiveWindow.addSensor("AnalogOutput", channel, this);
|
||||
UsageReporting.report(tResourceType.kResourceType_AnalogOutput, channel);
|
||||
@@ -69,23 +57,11 @@ public class AnalogOutput extends SensorBase implements LiveWindowSendable {
|
||||
}
|
||||
|
||||
public void setVoltage(double voltage) {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
AnalogJNI.setAnalogOutput(m_port, voltage, status.asIntBuffer());
|
||||
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
AnalogJNI.setAnalogOutput(m_port, voltage);
|
||||
}
|
||||
|
||||
public double getVoltage() {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
double voltage = AnalogJNI.getAnalogOutput(m_port, status.asIntBuffer());
|
||||
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
|
||||
return voltage;
|
||||
return AnalogJNI.getAnalogOutput(m_port);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -11,7 +11,6 @@ import edu.wpi.first.wpilibj.AnalogTriggerOutput.AnalogTriggerType;
|
||||
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType;
|
||||
import edu.wpi.first.wpilibj.communication.UsageReporting;
|
||||
import edu.wpi.first.wpilibj.hal.AnalogJNI;
|
||||
import edu.wpi.first.wpilibj.hal.HALUtil;
|
||||
import edu.wpi.first.wpilibj.util.BoundaryException;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
@@ -46,7 +45,7 @@ public class AnalogTrigger {
|
||||
/**
|
||||
* Where the analog trigger is attached
|
||||
*/
|
||||
protected ByteBuffer m_port;
|
||||
protected long m_port;
|
||||
protected int m_index;
|
||||
|
||||
/**
|
||||
@@ -55,15 +54,12 @@ public class AnalogTrigger {
|
||||
* @param channel the port to use for the analog trigger
|
||||
*/
|
||||
protected void initTrigger(final int channel) {
|
||||
ByteBuffer port_pointer = AnalogJNI.getPort((byte) channel);
|
||||
long port_pointer = AnalogJNI.getPort((byte) channel);
|
||||
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.asIntBuffer(), status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
AnalogJNI.initializeAnalogTrigger(port_pointer, index.asIntBuffer());
|
||||
m_index = index.asIntBuffer().get(0);
|
||||
|
||||
UsageReporting.report(tResourceType.kResourceType_AnalogTrigger, channel);
|
||||
@@ -97,11 +93,8 @@ public class AnalogTrigger {
|
||||
* Release the resources used by this object
|
||||
*/
|
||||
public void free() {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
AnalogJNI.cleanAnalogTrigger(m_port, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
m_port = null;
|
||||
AnalogJNI.cleanAnalogTrigger(m_port);
|
||||
m_port = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -116,10 +109,7 @@ public class AnalogTrigger {
|
||||
if (lower > upper) {
|
||||
throw new BoundaryException("Lower bound is greater than upper");
|
||||
}
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
AnalogJNI.setAnalogTriggerLimitsRaw(m_port, lower, upper, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
AnalogJNI.setAnalogTriggerLimitsRaw(m_port, lower, upper);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -133,11 +123,7 @@ public class AnalogTrigger {
|
||||
if (lower > upper) {
|
||||
throw new BoundaryException("Lower bound is greater than upper bound");
|
||||
}
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
AnalogJNI.setAnalogTriggerLimitsVoltage(m_port, (float) lower, (float) upper,
|
||||
status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
AnalogJNI.setAnalogTriggerLimitsVoltage(m_port, lower, upper);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -148,11 +134,7 @@ public class AnalogTrigger {
|
||||
* @param useAveragedValue true to use an averaged value, false otherwise
|
||||
*/
|
||||
public void setAveraged(boolean useAveragedValue) {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
AnalogJNI.setAnalogTriggerAveraged(m_port, (byte) (useAveragedValue ? 1 : 0),
|
||||
status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
AnalogJNI.setAnalogTriggerAveraged(m_port, useAveragedValue);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -164,11 +146,7 @@ public class AnalogTrigger {
|
||||
* @param useFilteredValue true to use a filterd value, false otherwise
|
||||
*/
|
||||
public void setFiltered(boolean useFilteredValue) {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
AnalogJNI.setAnalogTriggerFiltered(m_port, (byte) (useFilteredValue ? 1 : 0),
|
||||
status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
AnalogJNI.setAnalogTriggerFiltered(m_port, useFilteredValue);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -188,11 +166,7 @@ public class AnalogTrigger {
|
||||
* @return The InWindow output of the analog trigger.
|
||||
*/
|
||||
public boolean getInWindow() {
|
||||
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;
|
||||
return AnalogJNI.getAnalogTriggerInWindow(m_port);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -203,11 +177,7 @@ public class AnalogTrigger {
|
||||
* @return The TriggerState output of the analog trigger.
|
||||
*/
|
||||
public boolean getTriggerState() {
|
||||
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;
|
||||
return AnalogJNI.getAnalogTriggerTriggerState(m_port);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -10,7 +10,6 @@ package edu.wpi.first.wpilibj;
|
||||
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType;
|
||||
import edu.wpi.first.wpilibj.communication.UsageReporting;
|
||||
import edu.wpi.first.wpilibj.hal.AnalogJNI;
|
||||
import edu.wpi.first.wpilibj.hal.HALUtil;
|
||||
|
||||
import java.nio.IntBuffer;
|
||||
|
||||
@@ -99,10 +98,7 @@ public class AnalogTriggerOutput extends DigitalSource {
|
||||
* @return The state of the analog trigger output.
|
||||
*/
|
||||
public boolean get() {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
byte value = AnalogJNI.getAnalogTriggerOutput(m_trigger.m_port, m_outputType.value, status);
|
||||
HALUtil.checkStatus(status);
|
||||
return value != 0;
|
||||
return AnalogJNI.getAnalogTriggerOutput(m_trigger.m_port, m_outputType.value);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -10,7 +10,6 @@ package edu.wpi.first.wpilibj;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
import edu.wpi.first.wpilibj.can.CANExceptionFactory;
|
||||
import edu.wpi.first.wpilibj.can.CANJNI;
|
||||
import edu.wpi.first.wpilibj.can.CANMessageNotFoundException;
|
||||
import edu.wpi.first.wpilibj.tables.ITable;
|
||||
@@ -275,10 +274,6 @@ public class CANJaguar implements MotorSafety, PIDOutput, CANSpeedController {
|
||||
allocated.free(m_deviceNumber - 1);
|
||||
m_safetyHelper = null;
|
||||
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
status.asIntBuffer().put(0, 0);
|
||||
|
||||
int messageID;
|
||||
|
||||
// Disable periodic setpoints
|
||||
@@ -308,7 +303,7 @@ public class CANJaguar implements MotorSafety, PIDOutput, CANSpeedController {
|
||||
}
|
||||
|
||||
CANJNI.FRCNetworkCommunicationCANSessionMuxSendMessage(messageID, null,
|
||||
CANJNI.CAN_SEND_PERIOD_STOP_REPEATING, status.asIntBuffer());
|
||||
CANJNI.CAN_SEND_PERIOD_STOP_REPEATING);
|
||||
|
||||
configMaxOutputVoltage(kApproxBusVoltage);
|
||||
}
|
||||
@@ -1904,10 +1899,6 @@ public class CANJaguar implements MotorSafety, PIDOutput, CANSpeedController {
|
||||
CANJNI.LM_API_POS_T_EN, CANJNI.LM_API_POS_T_SET, CANJNI.LM_API_ICTRL_T_EN,
|
||||
CANJNI.LM_API_ICTRL_T_SET};
|
||||
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
status.asIntBuffer().put(0, 0);
|
||||
|
||||
for (byte i = 0; i < kTrustedMessages.length; i++) {
|
||||
if ((kFullMessageIDMask & messageID) == kTrustedMessages[i]) {
|
||||
// Make sure the data will still fit after adjusting for the token.
|
||||
@@ -1923,12 +1914,7 @@ public class CANJaguar implements MotorSafety, PIDOutput, CANSpeedController {
|
||||
trustedBuffer.put(j + 2, data[j]);
|
||||
}
|
||||
|
||||
CANJNI.FRCNetworkCommunicationCANSessionMuxSendMessage(messageID, trustedBuffer, period,
|
||||
status.asIntBuffer());
|
||||
int statusCode = status.asIntBuffer().get(0);
|
||||
if (statusCode < 0) {
|
||||
CANExceptionFactory.checkStatus(statusCode, messageID);
|
||||
}
|
||||
CANJNI.FRCNetworkCommunicationCANSessionMuxSendMessage(messageID, trustedBuffer, period);
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -1945,13 +1931,7 @@ public class CANJaguar implements MotorSafety, PIDOutput, CANSpeedController {
|
||||
buffer = null;
|
||||
}
|
||||
|
||||
CANJNI.FRCNetworkCommunicationCANSessionMuxSendMessage(messageID, buffer, period,
|
||||
status.asIntBuffer());
|
||||
|
||||
int statusCode = status.asIntBuffer().get(0);
|
||||
if (statusCode < 0) {
|
||||
CANExceptionFactory.checkStatus(statusCode, messageID);
|
||||
}
|
||||
CANJNI.FRCNetworkCommunicationCANSessionMuxSendMessage(messageID, buffer, period);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2022,25 +2002,16 @@ public class CANJaguar implements MotorSafety, PIDOutput, CANSpeedController {
|
||||
|
||||
ByteBuffer timeStamp = ByteBuffer.allocateDirect(4);
|
||||
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
status.asIntBuffer().put(0, 0);
|
||||
|
||||
// Get the data.
|
||||
ByteBuffer dataBuffer =
|
||||
CANJNI.FRCNetworkCommunicationCANSessionMuxReceiveMessage(targetedMessageID.asIntBuffer(),
|
||||
messageMask, timeStamp, status.asIntBuffer());
|
||||
messageMask, timeStamp);
|
||||
|
||||
if (data != null) {
|
||||
for (int i = 0; i < dataBuffer.capacity(); i++) {
|
||||
data[i] = dataBuffer.get(i);
|
||||
}
|
||||
}
|
||||
|
||||
int statusCode = status.asIntBuffer().get(0);
|
||||
if (statusCode < 0) {
|
||||
CANExceptionFactory.checkStatus(statusCode, messageID);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,11 +1,7 @@
|
||||
package edu.wpi.first.wpilibj;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
import edu.wpi.first.wpilibj.SensorBase;
|
||||
import edu.wpi.first.wpilibj.hal.CompressorJNI;
|
||||
import edu.wpi.first.wpilibj.hal.HALUtil;
|
||||
import edu.wpi.first.wpilibj.livewindow.LiveWindowSendable;
|
||||
import edu.wpi.first.wpilibj.tables.ITable;
|
||||
|
||||
@@ -22,7 +18,7 @@ import edu.wpi.first.wpilibj.tables.ITable;
|
||||
* closed loop control, thereby stopping the compressor from operating.
|
||||
*/
|
||||
public class Compressor extends SensorBase implements LiveWindowSendable {
|
||||
private ByteBuffer m_pcm;
|
||||
private long m_pcm;
|
||||
|
||||
/**
|
||||
* Create an instance of the Compressor
|
||||
@@ -76,13 +72,7 @@ public class Compressor extends SensorBase implements LiveWindowSendable {
|
||||
* @return true if the compressor is on
|
||||
*/
|
||||
public boolean enabled() {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
boolean on = CompressorJNI.getCompressor(m_pcm, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
|
||||
return on;
|
||||
return CompressorJNI.getCompressor(m_pcm);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -92,13 +82,7 @@ public class Compressor extends SensorBase implements LiveWindowSendable {
|
||||
* plugged into the PCM
|
||||
*/
|
||||
public boolean getPressureSwitchValue() {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
boolean on = CompressorJNI.getPressureSwitch(m_pcm, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
|
||||
return on;
|
||||
return CompressorJNI.getPressureSwitch(m_pcm);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -107,13 +91,7 @@ public class Compressor extends SensorBase implements LiveWindowSendable {
|
||||
* @return current consumed in amps for the compressor motor
|
||||
*/
|
||||
public float getCompressorCurrent() {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
float current = CompressorJNI.getCompressorCurrent(m_pcm, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
|
||||
return current;
|
||||
return CompressorJNI.getCompressorCurrent(m_pcm);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -123,11 +101,7 @@ public class Compressor extends SensorBase implements LiveWindowSendable {
|
||||
* otherwise normal operation of the compressor is disabled.
|
||||
*/
|
||||
public void setClosedLoopControl(boolean on) {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
CompressorJNI.setClosedLoopControl(m_pcm, on, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
CompressorJNI.setClosedLoopControl(m_pcm, on);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -137,13 +111,7 @@ public class Compressor extends SensorBase implements LiveWindowSendable {
|
||||
* return false.
|
||||
*/
|
||||
public boolean getClosedLoopControl() {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
boolean on = CompressorJNI.getClosedLoopControl(m_pcm, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
|
||||
return on;
|
||||
return CompressorJNI.getClosedLoopControl(m_pcm);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -151,13 +119,7 @@ public class Compressor extends SensorBase implements LiveWindowSendable {
|
||||
* compressor current being too high.
|
||||
*/
|
||||
public boolean getCompressorCurrentTooHighFault() {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
boolean retval = CompressorJNI.getCompressorCurrentTooHighFault(m_pcm, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
|
||||
return retval;
|
||||
return CompressorJNI.getCompressorCurrentTooHighFault(m_pcm);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -165,14 +127,7 @@ public class Compressor extends SensorBase implements LiveWindowSendable {
|
||||
* to compressor current being too high.
|
||||
*/
|
||||
public boolean getCompressorCurrentTooHighStickyFault() {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
boolean retval =
|
||||
CompressorJNI.getCompressorCurrentTooHighStickyFault(m_pcm, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
|
||||
return retval;
|
||||
return CompressorJNI.getCompressorCurrentTooHighStickyFault(m_pcm);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -180,13 +135,7 @@ public class Compressor extends SensorBase implements LiveWindowSendable {
|
||||
* shorted.
|
||||
*/
|
||||
public boolean getCompressorShortedStickyFault() {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
boolean retval = CompressorJNI.getCompressorShortedStickyFault(m_pcm, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
|
||||
return retval;
|
||||
return CompressorJNI.getCompressorShortedStickyFault(m_pcm);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -194,13 +143,7 @@ public class Compressor extends SensorBase implements LiveWindowSendable {
|
||||
* shorted.
|
||||
*/
|
||||
public boolean getCompressorShortedFault() {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
boolean retval = CompressorJNI.getCompressorShortedFault(m_pcm, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
|
||||
return retval;
|
||||
return CompressorJNI.getCompressorShortedFault(m_pcm);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -208,14 +151,7 @@ public class Compressor extends SensorBase implements LiveWindowSendable {
|
||||
* wired, i.e. compressor is not drawing enough current.
|
||||
*/
|
||||
public boolean getCompressorNotConnectedStickyFault() {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
boolean retval =
|
||||
CompressorJNI.getCompressorNotConnectedStickyFault(m_pcm, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
|
||||
return retval;
|
||||
return CompressorJNI.getCompressorNotConnectedStickyFault(m_pcm);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -223,13 +159,7 @@ public class Compressor extends SensorBase implements LiveWindowSendable {
|
||||
* wired, i.e. compressor is not drawing enough current.
|
||||
*/
|
||||
public boolean getCompressorNotConnectedFault() {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
boolean retval = CompressorJNI.getCompressorNotConnectedFault(m_pcm, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
|
||||
return retval;
|
||||
return CompressorJNI.getCompressorNotConnectedFault(m_pcm);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -243,11 +173,7 @@ public class Compressor extends SensorBase implements LiveWindowSendable {
|
||||
* If no sticky faults are set then this call will have no effect.
|
||||
*/
|
||||
public void clearAllPCMStickyFaults() {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
CompressorJNI.clearAllPCMStickyFaults(m_pcm, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
CompressorJNI.clearAllPCMStickyFaults(m_pcm);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -7,11 +7,6 @@
|
||||
|
||||
package edu.wpi.first.wpilibj;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.nio.IntBuffer;
|
||||
|
||||
import edu.wpi.first.wpilibj.hal.HALUtil;
|
||||
import edu.wpi.first.wpilibj.hal.PowerJNI;
|
||||
|
||||
public class ControllerPower {
|
||||
@@ -21,11 +16,7 @@ public class ControllerPower {
|
||||
* @return The controller input voltage value in Volts
|
||||
*/
|
||||
public static double getInputVoltage() {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
double retVal = PowerJNI.getVinVoltage(status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
return retVal;
|
||||
return PowerJNI.getVinVoltage();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -34,11 +25,7 @@ public class ControllerPower {
|
||||
* @return The controller input current value in Amps
|
||||
*/
|
||||
public static double getInputCurrent() {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
double retVal = PowerJNI.getVinCurrent(status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
return retVal;
|
||||
return PowerJNI.getVinCurrent();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -47,11 +34,7 @@ public class ControllerPower {
|
||||
* @return The controller 3.3V rail voltage value in Volts
|
||||
*/
|
||||
public static double getVoltage3V3() {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
double retVal = PowerJNI.getUserVoltage3V3(status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
return retVal;
|
||||
return PowerJNI.getUserVoltage3V3();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -60,11 +43,7 @@ public class ControllerPower {
|
||||
* @return The controller 3.3V rail output current value in Volts
|
||||
*/
|
||||
public static double getCurrent3V3() {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
double retVal = PowerJNI.getUserCurrent3V3(status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
return retVal;
|
||||
return PowerJNI.getUserCurrent3V3();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -75,11 +54,7 @@ public class ControllerPower {
|
||||
* @return The controller 3.3V rail enabled value
|
||||
*/
|
||||
public static boolean getEnabled3V3() {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
boolean retVal = PowerJNI.getUserActive3V3(status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
return retVal;
|
||||
return PowerJNI.getUserActive3V3();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -89,11 +64,7 @@ public class ControllerPower {
|
||||
* @return The number of faults
|
||||
*/
|
||||
public static int getFaultCount3V3() {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
int retVal = PowerJNI.getUserCurrentFaults3V3(status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
return retVal;
|
||||
return PowerJNI.getUserCurrentFaults3V3();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -102,11 +73,7 @@ public class ControllerPower {
|
||||
* @return The controller 5V rail voltage value in Volts
|
||||
*/
|
||||
public static double getVoltage5V() {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
double retVal = PowerJNI.getUserVoltage5V(status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
return retVal;
|
||||
return PowerJNI.getUserVoltage5V();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -115,11 +82,7 @@ public class ControllerPower {
|
||||
* @return The controller 5V rail output current value in Amps
|
||||
*/
|
||||
public static double getCurrent5V() {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
double retVal = PowerJNI.getUserCurrent5V(status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
return retVal;
|
||||
return PowerJNI.getUserCurrent5V();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -130,11 +93,7 @@ public class ControllerPower {
|
||||
* @return The controller 5V rail enabled value
|
||||
*/
|
||||
public static boolean getEnabled5V() {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
boolean retVal = PowerJNI.getUserActive5V(status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
return retVal;
|
||||
return PowerJNI.getUserActive5V();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -144,11 +103,7 @@ public class ControllerPower {
|
||||
* @return The number of faults
|
||||
*/
|
||||
public static int getFaultCount5V() {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
int retVal = PowerJNI.getUserCurrentFaults5V(status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
return retVal;
|
||||
return PowerJNI.getUserCurrentFaults5V();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -157,11 +112,7 @@ public class ControllerPower {
|
||||
* @return The controller 6V rail voltage value in Volts
|
||||
*/
|
||||
public static double getVoltage6V() {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
double retVal = PowerJNI.getUserVoltage6V(status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
return retVal;
|
||||
return PowerJNI.getUserVoltage6V();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -170,11 +121,7 @@ public class ControllerPower {
|
||||
* @return The controller 6V rail output current value in Amps
|
||||
*/
|
||||
public static double getCurrent6V() {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
double retVal = PowerJNI.getUserCurrent6V(status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
return retVal;
|
||||
return PowerJNI.getUserCurrent6V();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -185,11 +132,7 @@ public class ControllerPower {
|
||||
* @return The controller 6V rail enabled value
|
||||
*/
|
||||
public static boolean getEnabled6V() {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
boolean retVal = PowerJNI.getUserActive6V(status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
return retVal;
|
||||
return PowerJNI.getUserActive6V();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -199,10 +142,6 @@ public class ControllerPower {
|
||||
* @return The number of faults
|
||||
*/
|
||||
public static int getFaultCount6V() {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
int retVal = PowerJNI.getUserCurrentFaults6V(status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
return retVal;
|
||||
return PowerJNI.getUserCurrentFaults6V();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@ import edu.wpi.first.wpilibj.AnalogTriggerOutput.AnalogTriggerType;
|
||||
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType;
|
||||
import edu.wpi.first.wpilibj.communication.UsageReporting;
|
||||
import edu.wpi.first.wpilibj.hal.CounterJNI;
|
||||
import edu.wpi.first.wpilibj.hal.HALUtil;
|
||||
import edu.wpi.first.wpilibj.livewindow.LiveWindowSendable;
|
||||
import edu.wpi.first.wpilibj.tables.ITable;
|
||||
import edu.wpi.first.wpilibj.util.BoundaryException;
|
||||
@@ -65,20 +64,16 @@ public class Counter extends SensorBase implements CounterBase, LiveWindowSendab
|
||||
private DigitalSource m_downSource; // /< What makes the counter count down.
|
||||
private boolean m_allocatedUpSource;
|
||||
private boolean m_allocatedDownSource;
|
||||
private ByteBuffer m_counter; // /< The FPGA counter object.
|
||||
private long m_counter; // /< The FPGA counter object.
|
||||
private int m_index; // /< The index of this counter.
|
||||
private PIDSourceType m_pidSource;
|
||||
private double m_distancePerPulse; // distance of travel for each tick
|
||||
|
||||
private void initCounter(final Mode mode) {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
ByteBuffer index = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
index.order(ByteOrder.LITTLE_ENDIAN);
|
||||
m_counter = CounterJNI.initializeCounter(mode.value, index.asIntBuffer(), status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
m_counter = CounterJNI.initializeCounter(mode.value, index.asIntBuffer());
|
||||
m_index = index.asIntBuffer().get(0);
|
||||
|
||||
m_allocatedUpSource = false;
|
||||
@@ -161,16 +156,14 @@ public class Counter extends SensorBase implements CounterBase, LiveWindowSendab
|
||||
if (encodingType == null)
|
||||
throw new NullPointerException("Encoding type given was null");
|
||||
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
if (encodingType == EncodingType.k1X) {
|
||||
setUpSourceEdge(true, false);
|
||||
CounterJNI.setCounterAverageSize(m_counter, 1, status.asIntBuffer());
|
||||
CounterJNI.setCounterAverageSize(m_counter, 1);
|
||||
} else {
|
||||
setUpSourceEdge(true, true);
|
||||
CounterJNI.setCounterAverageSize(m_counter, 2, status.asIntBuffer());
|
||||
CounterJNI.setCounterAverageSize(m_counter, 2);
|
||||
}
|
||||
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
setDownSourceEdge(inverted, true);
|
||||
}
|
||||
|
||||
@@ -198,14 +191,11 @@ public class Counter extends SensorBase implements CounterBase, LiveWindowSendab
|
||||
clearUpSource();
|
||||
clearDownSource();
|
||||
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
CounterJNI.freeCounter(m_counter, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
CounterJNI.freeCounter(m_counter);
|
||||
|
||||
m_upSource = null;
|
||||
m_downSource = null;
|
||||
m_counter = null;
|
||||
m_counter = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -238,11 +228,8 @@ public class Counter extends SensorBase implements CounterBase, LiveWindowSendab
|
||||
m_allocatedUpSource = false;
|
||||
}
|
||||
m_upSource = source;
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
CounterJNI.setCounterUpSource(m_counter, source.getChannelForRouting(),
|
||||
(byte) (source.getAnalogTriggerForRouting() ? 1 : 0), status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
source.getAnalogTriggerForRouting());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -273,11 +260,7 @@ public class Counter extends SensorBase implements CounterBase, LiveWindowSendab
|
||||
public void setUpSourceEdge(boolean risingEdge, boolean fallingEdge) {
|
||||
if (m_upSource == null)
|
||||
throw new RuntimeException("Up Source must be set before setting the edge!");
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
CounterJNI.setCounterUpSourceEdge(m_counter, (byte) (risingEdge ? 1 : 0),
|
||||
(byte) (fallingEdge ? 1 : 0), status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
CounterJNI.setCounterUpSourceEdge(m_counter, risingEdge, fallingEdge);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -290,10 +273,7 @@ public class Counter extends SensorBase implements CounterBase, LiveWindowSendab
|
||||
}
|
||||
m_upSource = null;
|
||||
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
CounterJNI.clearCounterUpSource(m_counter, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
CounterJNI.clearCounterUpSource(m_counter);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -322,15 +302,8 @@ public class Counter extends SensorBase implements CounterBase, LiveWindowSendab
|
||||
m_downSource.free();
|
||||
m_allocatedDownSource = false;
|
||||
}
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
CounterJNI.setCounterDownSource(m_counter, source.getChannelForRouting(),
|
||||
(byte) (source.getAnalogTriggerForRouting() ? 1 : 0), status.asIntBuffer());
|
||||
if (status.asIntBuffer().get(0) == HALUtil.PARAMETER_OUT_OF_RANGE) {
|
||||
throw new IllegalArgumentException(
|
||||
"Counter only supports DownSource in TwoPulse and ExternalDirection modes.");
|
||||
}
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
source.getAnalogTriggerForRouting());
|
||||
m_downSource = source;
|
||||
}
|
||||
|
||||
@@ -363,11 +336,7 @@ public class Counter extends SensorBase implements CounterBase, LiveWindowSendab
|
||||
public void setDownSourceEdge(boolean risingEdge, boolean fallingEdge) {
|
||||
if (m_downSource == null)
|
||||
throw new RuntimeException(" Down Source must be set before setting the edge!");
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
CounterJNI.setCounterDownSourceEdge(m_counter, (byte) (risingEdge ? 1 : 0),
|
||||
(byte) (fallingEdge ? 1 : 0), status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
CounterJNI.setCounterDownSourceEdge(m_counter, risingEdge, fallingEdge);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -380,10 +349,7 @@ public class Counter extends SensorBase implements CounterBase, LiveWindowSendab
|
||||
}
|
||||
m_downSource = null;
|
||||
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
CounterJNI.clearCounterDownSource(m_counter, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
CounterJNI.clearCounterDownSource(m_counter);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -391,10 +357,7 @@ public class Counter extends SensorBase implements CounterBase, LiveWindowSendab
|
||||
* are sourced independently from two inputs.
|
||||
*/
|
||||
public void setUpDownCounterMode() {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
CounterJNI.setCounterUpDownMode(m_counter, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
CounterJNI.setCounterUpDownMode(m_counter);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -402,10 +365,7 @@ public class Counter extends SensorBase implements CounterBase, LiveWindowSendab
|
||||
* counter input. The Down counter input represents the direction to count.
|
||||
*/
|
||||
public void setExternalDirectionMode() {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
CounterJNI.setCounterExternalDirectionMode(m_counter, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
CounterJNI.setCounterExternalDirectionMode(m_counter);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -415,11 +375,7 @@ public class Counter extends SensorBase implements CounterBase, LiveWindowSendab
|
||||
* @param highSemiPeriod true to count up on both rising and falling
|
||||
*/
|
||||
public void setSemiPeriodMode(boolean highSemiPeriod) {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
CounterJNI.setCounterSemiPeriodMode(m_counter, (byte) (highSemiPeriod ? 1 : 0),
|
||||
status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
CounterJNI.setCounterSemiPeriodMode(m_counter, highSemiPeriod);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -431,10 +387,7 @@ public class Counter extends SensorBase implements CounterBase, LiveWindowSendab
|
||||
* opposite direction. Units are seconds.
|
||||
*/
|
||||
public void setPulseLengthMode(double threshold) {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
CounterJNI.setCounterPulseLengthMode(m_counter, threshold, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
CounterJNI.setCounterPulseLengthMode(m_counter, threshold);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -444,11 +397,7 @@ public class Counter extends SensorBase implements CounterBase, LiveWindowSendab
|
||||
*/
|
||||
@Override
|
||||
public int get() {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
int value = CounterJNI.getCounter(m_counter, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
return value;
|
||||
return CounterJNI.getCounter(m_counter);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -468,10 +417,7 @@ public class Counter extends SensorBase implements CounterBase, LiveWindowSendab
|
||||
*/
|
||||
@Override
|
||||
public void reset() {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
CounterJNI.resetCounter(m_counter, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
CounterJNI.resetCounter(m_counter);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -485,10 +431,7 @@ public class Counter extends SensorBase implements CounterBase, LiveWindowSendab
|
||||
*/
|
||||
@Override
|
||||
public void setMaxPeriod(double maxPeriod) {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
CounterJNI.setCounterMaxPeriod(m_counter, maxPeriod, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
CounterJNI.setCounterMaxPeriod(m_counter, maxPeriod);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -508,10 +451,7 @@ public class Counter extends SensorBase implements CounterBase, LiveWindowSendab
|
||||
* @param enabled true to continue updating
|
||||
*/
|
||||
public void setUpdateWhenEmpty(boolean enabled) {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
CounterJNI.setCounterUpdateWhenEmpty(m_counter, (byte) (enabled ? 1 : 0), status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
CounterJNI.setCounterUpdateWhenEmpty(m_counter, enabled);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -525,11 +465,7 @@ public class Counter extends SensorBase implements CounterBase, LiveWindowSendab
|
||||
*/
|
||||
@Override
|
||||
public boolean getStopped() {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
boolean value = CounterJNI.getCounterStopped(m_counter, status.asIntBuffer()) != 0;
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
return value;
|
||||
return CounterJNI.getCounterStopped(m_counter);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -539,11 +475,7 @@ public class Counter extends SensorBase implements CounterBase, LiveWindowSendab
|
||||
*/
|
||||
@Override
|
||||
public boolean getDirection() {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
boolean value = CounterJNI.getCounterDirection(m_counter, status.asIntBuffer()) != 0;
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
return value;
|
||||
return CounterJNI.getCounterDirection(m_counter);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -554,11 +486,7 @@ public class Counter extends SensorBase implements CounterBase, LiveWindowSendab
|
||||
* @param reverseDirection true if the value counted should be negated.
|
||||
*/
|
||||
public void setReverseDirection(boolean reverseDirection) {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
CounterJNI.setCounterReverseDirection(m_counter, (byte) (reverseDirection ? 1 : 0),
|
||||
status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
CounterJNI.setCounterReverseDirection(m_counter, reverseDirection);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -570,11 +498,7 @@ public class Counter extends SensorBase implements CounterBase, LiveWindowSendab
|
||||
*/
|
||||
@Override
|
||||
public double getPeriod() {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
double value = CounterJNI.getCounterPeriod(m_counter, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
return value;
|
||||
return CounterJNI.getCounterPeriod(m_counter);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -596,13 +520,7 @@ public class Counter extends SensorBase implements CounterBase, LiveWindowSendab
|
||||
* @param samplesToAverage The number of samples to average from 1 to 127.
|
||||
*/
|
||||
public void setSamplesToAverage(int samplesToAverage) {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
CounterJNI.setCounterSamplesToAverage(m_counter, samplesToAverage, status.asIntBuffer());
|
||||
if (status.asIntBuffer().get(0) == HALUtil.PARAMETER_OUT_OF_RANGE) {
|
||||
throw new BoundaryException(BoundaryException.getMessage(samplesToAverage, 1, 127));
|
||||
}
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
CounterJNI.setCounterSamplesToAverage(m_counter, samplesToAverage);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -614,11 +532,7 @@ public class Counter extends SensorBase implements CounterBase, LiveWindowSendab
|
||||
* 127)
|
||||
*/
|
||||
public int getSamplesToAverage() {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
int value = CounterJNI.getCounterSamplesToAverage(m_counter, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
return value;
|
||||
return CounterJNI.getCounterSamplesToAverage(m_counter);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -7,13 +7,9 @@
|
||||
|
||||
package edu.wpi.first.wpilibj;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType;
|
||||
import edu.wpi.first.wpilibj.communication.UsageReporting;
|
||||
import edu.wpi.first.wpilibj.hal.DIOJNI;
|
||||
import edu.wpi.first.wpilibj.hal.HALUtil;
|
||||
import edu.wpi.first.wpilibj.livewindow.LiveWindow;
|
||||
import edu.wpi.first.wpilibj.livewindow.LiveWindowSendable;
|
||||
import edu.wpi.first.wpilibj.tables.ITable;
|
||||
@@ -48,12 +44,7 @@ public class DigitalInput extends DigitalSource implements LiveWindowSendable {
|
||||
* @return the status of the digital input
|
||||
*/
|
||||
public boolean get() {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
boolean value = DIOJNI.getDIO(m_port, status.asIntBuffer()) != 0;
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
return value;
|
||||
return DIOJNI.getDIO(m_port);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -7,17 +7,12 @@
|
||||
|
||||
package edu.wpi.first.wpilibj;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
import edu.wpi.first.wpilibj.communication.UsageReporting;
|
||||
import edu.wpi.first.wpilibj.hal.DIOJNI;
|
||||
import edu.wpi.first.wpilibj.hal.HALUtil;
|
||||
import edu.wpi.first.wpilibj.hal.PWMJNI;
|
||||
import edu.wpi.first.wpilibj.livewindow.LiveWindowSendable;
|
||||
import edu.wpi.first.wpilibj.tables.ITable;
|
||||
import edu.wpi.first.wpilibj.tables.ITableListener;
|
||||
// import com.sun.jna.Pointer;
|
||||
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType;
|
||||
|
||||
/**
|
||||
@@ -27,7 +22,7 @@ import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tReso
|
||||
*/
|
||||
public class DigitalOutput extends DigitalSource implements LiveWindowSendable {
|
||||
|
||||
private ByteBuffer m_pwmGenerator;
|
||||
private long m_pwmGenerator;
|
||||
|
||||
/**
|
||||
* Create an instance of a digital output. Create an instance of a digital
|
||||
@@ -48,7 +43,7 @@ public class DigitalOutput extends DigitalSource implements LiveWindowSendable {
|
||||
@Override
|
||||
public void free() {
|
||||
// disable the pwm only if we have allocated it
|
||||
if (m_pwmGenerator != null) {
|
||||
if (m_pwmGenerator != 0) {
|
||||
disablePWM();
|
||||
}
|
||||
super.free();
|
||||
@@ -60,11 +55,7 @@ public class DigitalOutput extends DigitalSource implements LiveWindowSendable {
|
||||
* @param value true is on, off is false
|
||||
*/
|
||||
public void set(boolean value) {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
DIOJNI.setDIO(m_port, (short) (value ? 1 : 0), status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
DIOJNI.setDIO(m_port, (short) (value ? 1 : 0));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -82,11 +73,7 @@ public class DigitalOutput extends DigitalSource implements LiveWindowSendable {
|
||||
* @param pulseLength The length of the pulse.
|
||||
*/
|
||||
public void pulse(final int channel, final float pulseLength) {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
DIOJNI.pulse(m_port, pulseLength, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
DIOJNI.pulse(m_port, pulseLength);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -99,15 +86,11 @@ public class DigitalOutput extends DigitalSource implements LiveWindowSendable {
|
||||
*/
|
||||
@Deprecated
|
||||
public void pulse(final int channel, final int pulseLength) {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
float convertedPulse =
|
||||
(float) (pulseLength / 1.0e9 * (DIOJNI.getLoopTiming(status.asIntBuffer()) * 25));
|
||||
(float) (pulseLength / 1.0e9 * (DIOJNI.getLoopTiming() * 25));
|
||||
System.err
|
||||
.println("You should use the float version of pulse for portability. This is deprecated");
|
||||
DIOJNI.pulse(m_port, convertedPulse, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
DIOJNI.pulse(m_port, convertedPulse);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -117,12 +100,7 @@ public class DigitalOutput extends DigitalSource implements LiveWindowSendable {
|
||||
* @return true if pulsing
|
||||
*/
|
||||
public boolean isPulsing() {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
boolean value = DIOJNI.isPulsing(m_port, status.asIntBuffer()) != 0;
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
return value;
|
||||
return DIOJNI.isPulsing(m_port);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -136,11 +114,7 @@ public class DigitalOutput extends DigitalSource implements LiveWindowSendable {
|
||||
* @param rate The frequency to output all digital output PWM signals.
|
||||
*/
|
||||
public void setPWMRate(double rate) {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
PWMJNI.setPWMRate(rate, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
PWMJNI.setPWMRate(rate);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -157,16 +131,11 @@ public class DigitalOutput extends DigitalSource implements LiveWindowSendable {
|
||||
* @param initialDutyCycle The duty-cycle to start generating. [0..1]
|
||||
*/
|
||||
public void enablePWM(double initialDutyCycle) {
|
||||
if (m_pwmGenerator != null)
|
||||
if (m_pwmGenerator != 0)
|
||||
return;
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
m_pwmGenerator = PWMJNI.allocatePWM(status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
PWMJNI.setPWMDutyCycle(m_pwmGenerator, initialDutyCycle, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
PWMJNI.setPWMOutputChannel(m_pwmGenerator, m_channel, status.asIntBuffer());
|
||||
m_pwmGenerator = PWMJNI.allocatePWM();
|
||||
PWMJNI.setPWMDutyCycle(m_pwmGenerator, initialDutyCycle);
|
||||
PWMJNI.setPWMOutputChannel(m_pwmGenerator, m_channel);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -175,16 +144,12 @@ public class DigitalOutput extends DigitalSource implements LiveWindowSendable {
|
||||
* Free up one of the 6 DO PWM generator resources that were in use.
|
||||
*/
|
||||
public void disablePWM() {
|
||||
if (m_pwmGenerator == null)
|
||||
if (m_pwmGenerator == 0)
|
||||
return;
|
||||
// Disable the output by routing to a dead bit.
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
PWMJNI.setPWMOutputChannel(m_pwmGenerator, kDigitalChannels, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
PWMJNI.freePWM(m_pwmGenerator, status.asIntBuffer());
|
||||
m_pwmGenerator = null;
|
||||
PWMJNI.setPWMOutputChannel(m_pwmGenerator, kDigitalChannels);
|
||||
PWMJNI.freePWM(m_pwmGenerator);
|
||||
m_pwmGenerator = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -196,13 +161,9 @@ public class DigitalOutput extends DigitalSource implements LiveWindowSendable {
|
||||
* @param dutyCycle The duty-cycle to change to. [0..1]
|
||||
*/
|
||||
public void updateDutyCycle(double dutyCycle) {
|
||||
if (m_pwmGenerator == null)
|
||||
if (m_pwmGenerator == 0)
|
||||
return;
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
PWMJNI.setPWMDutyCycle(m_pwmGenerator, dutyCycle, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
PWMJNI.setPWMDutyCycle(m_pwmGenerator, dutyCycle);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -7,11 +7,7 @@
|
||||
|
||||
package edu.wpi.first.wpilibj;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
import edu.wpi.first.wpilibj.hal.DIOJNI;
|
||||
import edu.wpi.first.wpilibj.hal.HALUtil;
|
||||
import edu.wpi.first.wpilibj.util.AllocationException;
|
||||
import edu.wpi.first.wpilibj.util.CheckedAllocationException;
|
||||
|
||||
@@ -25,7 +21,7 @@ import edu.wpi.first.wpilibj.util.CheckedAllocationException;
|
||||
public abstract class DigitalSource extends InterruptableSensorBase {
|
||||
|
||||
protected static Resource channels = new Resource(kDigitalChannels);
|
||||
protected ByteBuffer m_port;
|
||||
protected long m_port;
|
||||
protected int m_channel;
|
||||
|
||||
protected void initDigitalPort(int channel, boolean input) {
|
||||
@@ -42,24 +38,15 @@ public abstract class DigitalSource extends InterruptableSensorBase {
|
||||
throw new AllocationException("Digital input " + m_channel + " is already allocated");
|
||||
}
|
||||
|
||||
ByteBuffer port_pointer = DIOJNI.getPort((byte) channel);
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
m_port = DIOJNI.initializeDigitalPort(port_pointer, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
DIOJNI.allocateDIO(m_port, (byte) (input ? 1 : 0), status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
long port_pointer = DIOJNI.getPort((byte) channel);
|
||||
m_port = DIOJNI.initializeDigitalPort(port_pointer);
|
||||
DIOJNI.allocateDIO(m_port, input);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void free() {
|
||||
channels.free(m_channel);
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
DIOJNI.freeDIO(m_port, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
DIOJNI.freeDIO(m_port);
|
||||
m_channel = 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,9 +6,7 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
package edu.wpi.first.wpilibj;
|
||||
|
||||
import java.nio.IntBuffer;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary;
|
||||
import edu.wpi.first.wpilibj.communication.HALControlWord;
|
||||
@@ -76,8 +74,8 @@ public class DriverStation implements RobotState.Interface {
|
||||
private boolean m_userInTeleop = false;
|
||||
private boolean m_userInTest = false;
|
||||
private boolean m_newControlData;
|
||||
private final ByteBuffer m_packetDataAvailableMutex;
|
||||
private final ByteBuffer m_packetDataAvailableSem;
|
||||
private final long m_packetDataAvailableMutex;
|
||||
private final long m_packetDataAvailableSem;
|
||||
|
||||
/**
|
||||
* Gets an instance of the DriverStation
|
||||
@@ -197,11 +195,7 @@ public class DriverStation implements RobotState.Interface {
|
||||
* @return The battery voltage in Volts.
|
||||
*/
|
||||
public double getBatteryVoltage() {
|
||||
IntBuffer status = ByteBuffer.allocateDirect(4).asIntBuffer();
|
||||
float voltage = PowerJNI.getVinVoltage(status);
|
||||
HALUtil.checkStatus(status);
|
||||
|
||||
return voltage;
|
||||
return PowerJNI.getVinVoltage();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -485,11 +479,7 @@ public class DriverStation implements RobotState.Interface {
|
||||
* @return True if the FPGA outputs are enabled.
|
||||
*/
|
||||
public boolean isSysActive() {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
boolean retVal = FRCNetworkCommunicationsLibrary.HALGetSystemActive(status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
return retVal;
|
||||
return FRCNetworkCommunicationsLibrary.HALGetSystemActive();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -498,11 +488,7 @@ public class DriverStation implements RobotState.Interface {
|
||||
* @return True if the system is browned out
|
||||
*/
|
||||
public boolean isBrownedOut() {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
boolean retVal = FRCNetworkCommunicationsLibrary.HALGetBrownedOut(status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
return retVal;
|
||||
return FRCNetworkCommunicationsLibrary.HALGetBrownedOut();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -13,7 +13,6 @@ import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tInst
|
||||
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType;
|
||||
import edu.wpi.first.wpilibj.communication.UsageReporting;
|
||||
import edu.wpi.first.wpilibj.hal.EncoderJNI;
|
||||
import edu.wpi.first.wpilibj.hal.HALUtil;
|
||||
import edu.wpi.first.wpilibj.livewindow.LiveWindow;
|
||||
import edu.wpi.first.wpilibj.livewindow.LiveWindowSendable;
|
||||
import edu.wpi.first.wpilibj.tables.ITable;
|
||||
@@ -49,7 +48,7 @@ public class Encoder extends SensorBase implements CounterBase, PIDSource, LiveW
|
||||
* The index source
|
||||
*/
|
||||
protected DigitalSource m_indexSource = null; // Index on some encoders
|
||||
private ByteBuffer m_encoder;
|
||||
private long m_encoder;
|
||||
private int m_index;
|
||||
private double m_distancePerPulse; // distance of travel for each encoder
|
||||
// tick
|
||||
@@ -80,19 +79,15 @@ public class Encoder extends SensorBase implements CounterBase, PIDSource, LiveW
|
||||
switch (m_encodingType) {
|
||||
case k4X:
|
||||
m_encodingScale = 4;
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
ByteBuffer index = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
index.order(ByteOrder.LITTLE_ENDIAN);
|
||||
m_encoder =
|
||||
EncoderJNI.initializeEncoder((byte) m_aSource.getModuleForRouting(), m_aSource
|
||||
.getChannelForRouting(), (byte) (m_aSource.getAnalogTriggerForRouting() ? 1 : 0),
|
||||
.getChannelForRouting(), m_aSource.getAnalogTriggerForRouting(),
|
||||
(byte) m_bSource.getModuleForRouting(), m_bSource.getChannelForRouting(),
|
||||
(byte) (m_bSource.getAnalogTriggerForRouting() ? 1 : 0),
|
||||
(byte) (reverseDirection ? 1 : 0), index.asIntBuffer(), status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
m_bSource.getAnalogTriggerForRouting(),
|
||||
reverseDirection, index.asIntBuffer());
|
||||
m_index = index.asIntBuffer().get(0);
|
||||
m_counter = null;
|
||||
setMaxPeriod(.5);
|
||||
@@ -378,11 +373,7 @@ public class Encoder extends SensorBase implements CounterBase, PIDSource, LiveW
|
||||
m_counter.free();
|
||||
m_counter = null;
|
||||
} else {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
EncoderJNI.freeEncoder(m_encoder, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
EncoderJNI.freeEncoder(m_encoder);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -397,11 +388,7 @@ public class Encoder extends SensorBase implements CounterBase, PIDSource, LiveW
|
||||
if (m_counter != null) {
|
||||
value = m_counter.get();
|
||||
} else {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
value = EncoderJNI.getEncoder(m_encoder, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
value = EncoderJNI.getEncoder(m_encoder);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
@@ -425,11 +412,7 @@ public class Encoder extends SensorBase implements CounterBase, PIDSource, LiveW
|
||||
if (m_counter != null) {
|
||||
m_counter.reset();
|
||||
} else {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
EncoderJNI.resetEncoder(m_encoder, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
EncoderJNI.resetEncoder(m_encoder);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -449,11 +432,7 @@ public class Encoder extends SensorBase implements CounterBase, PIDSource, LiveW
|
||||
if (m_counter != null) {
|
||||
measuredPeriod = m_counter.getPeriod() / decodingScaleFactor();
|
||||
} else {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
measuredPeriod = EncoderJNI.getEncoderPeriod(m_encoder, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
measuredPeriod = EncoderJNI.getEncoderPeriod(m_encoder);
|
||||
}
|
||||
return measuredPeriod;
|
||||
}
|
||||
@@ -474,11 +453,7 @@ public class Encoder extends SensorBase implements CounterBase, PIDSource, LiveW
|
||||
if (m_counter != null) {
|
||||
m_counter.setMaxPeriod(maxPeriod * decodingScaleFactor());
|
||||
} else {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
EncoderJNI.setEncoderMaxPeriod(m_encoder, maxPeriod, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
EncoderJNI.setEncoderMaxPeriod(m_encoder, maxPeriod);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -494,12 +469,7 @@ public class Encoder extends SensorBase implements CounterBase, PIDSource, LiveW
|
||||
if (m_counter != null) {
|
||||
return m_counter.getStopped();
|
||||
} else {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
boolean value = EncoderJNI.getEncoderStopped(m_encoder, status.asIntBuffer()) != 0;
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
return value;
|
||||
return EncoderJNI.getEncoderStopped(m_encoder);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -512,12 +482,7 @@ public class Encoder extends SensorBase implements CounterBase, PIDSource, LiveW
|
||||
if (m_counter != null) {
|
||||
return m_counter.getDirection();
|
||||
} else {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
boolean value = EncoderJNI.getEncoderDirection(m_encoder, status.asIntBuffer()) != 0;
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
return value;
|
||||
return EncoderJNI.getEncoderDirection(m_encoder);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -613,18 +578,12 @@ public class Encoder extends SensorBase implements CounterBase, PIDSource, LiveW
|
||||
public void setSamplesToAverage(int samplesToAverage) {
|
||||
switch (m_encodingType) {
|
||||
case k4X:
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
EncoderJNI.setEncoderSamplesToAverage(m_encoder, samplesToAverage, status.asIntBuffer());
|
||||
if (status.duplicate().get() == HALUtil.PARAMETER_OUT_OF_RANGE) {
|
||||
throw new BoundaryException(BoundaryException.getMessage(samplesToAverage, 1, 127));
|
||||
}
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
EncoderJNI.setEncoderSamplesToAverage(m_encoder, samplesToAverage);
|
||||
break;
|
||||
case k1X:
|
||||
case k2X:
|
||||
m_counter.setSamplesToAverage(samplesToAverage);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -639,12 +598,7 @@ public class Encoder extends SensorBase implements CounterBase, PIDSource, LiveW
|
||||
public int getSamplesToAverage() {
|
||||
switch (m_encodingType) {
|
||||
case k4X:
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
int value = EncoderJNI.getEncoderSamplesToAverage(m_encoder, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
return value;
|
||||
return EncoderJNI.getEncoderSamplesToAverage(m_encoder);
|
||||
case k1X:
|
||||
case k2X:
|
||||
return m_counter.getSamplesToAverage();
|
||||
@@ -693,17 +647,12 @@ public class Encoder extends SensorBase implements CounterBase, PIDSource, LiveW
|
||||
* @param type The state that will cause the encoder to reset
|
||||
*/
|
||||
public void setIndexSource(int channel, IndexingType type) {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
boolean activeHigh =
|
||||
(type == IndexingType.kResetWhileHigh) || (type == IndexingType.kResetOnRisingEdge);
|
||||
boolean edgeSensitive =
|
||||
(type == IndexingType.kResetOnFallingEdge) || (type == IndexingType.kResetOnRisingEdge);
|
||||
|
||||
EncoderJNI.setEncoderIndexSource(m_encoder, channel, false, activeHigh, edgeSensitive,
|
||||
status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
EncoderJNI.setEncoderIndexSource(m_encoder, channel, false, activeHigh, edgeSensitive);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -724,17 +673,13 @@ public class Encoder extends SensorBase implements CounterBase, PIDSource, LiveW
|
||||
* @param type The state that will cause the encoder to reset
|
||||
*/
|
||||
public void setIndexSource(DigitalSource source, IndexingType type) {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
boolean activeHigh =
|
||||
(type == IndexingType.kResetWhileHigh) || (type == IndexingType.kResetOnRisingEdge);
|
||||
boolean edgeSensitive =
|
||||
(type == IndexingType.kResetOnFallingEdge) || (type == IndexingType.kResetOnRisingEdge);
|
||||
|
||||
EncoderJNI.setEncoderIndexSource(m_encoder, source.getChannelForRouting(),
|
||||
source.getAnalogTriggerForRouting(), activeHigh, edgeSensitive, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
source.getAnalogTriggerForRouting(), activeHigh, edgeSensitive);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -7,13 +7,11 @@
|
||||
package edu.wpi.first.wpilibj;
|
||||
|
||||
import java.nio.ByteOrder;
|
||||
import java.nio.IntBuffer;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType;
|
||||
import edu.wpi.first.wpilibj.communication.UsageReporting;
|
||||
import edu.wpi.first.wpilibj.hal.HALLibrary;
|
||||
import edu.wpi.first.wpilibj.hal.HALUtil;
|
||||
import edu.wpi.first.wpilibj.hal.I2CJNI;
|
||||
import edu.wpi.first.wpilibj.util.BoundaryException;
|
||||
|
||||
@@ -48,14 +46,10 @@ public class I2C extends SensorBase {
|
||||
* @param deviceAddress The address of the device on the I2C bus.
|
||||
*/
|
||||
public I2C(Port port, int deviceAddress) {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
m_port = port;
|
||||
m_deviceAddress = deviceAddress;
|
||||
|
||||
I2CJNI.i2CInitialize((byte) m_port.getValue(), status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
I2CJNI.i2CInitialize((byte) m_port.getValue());
|
||||
|
||||
UsageReporting.report(tResourceType.kResourceType_I2C, deviceAddress);
|
||||
}
|
||||
|
||||
@@ -7,10 +7,6 @@
|
||||
|
||||
package edu.wpi.first.wpilibj;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
import edu.wpi.first.wpilibj.hal.HALUtil;
|
||||
import edu.wpi.first.wpilibj.hal.InterruptJNI;
|
||||
import edu.wpi.first.wpilibj.util.AllocationException;
|
||||
import edu.wpi.first.wpilibj.util.CheckedAllocationException;
|
||||
@@ -19,22 +15,10 @@ import edu.wpi.first.wpilibj.util.CheckedAllocationException;
|
||||
* Base for sensors to be used with interrupts
|
||||
*/
|
||||
public abstract class InterruptableSensorBase extends SensorBase {
|
||||
/**
|
||||
* This is done to store the JVM variable in the InterruptJNI This is done
|
||||
* because the HAL must have access to the JVM variable in order to attach the
|
||||
* newly spawned thread when an interrupt is fired.
|
||||
*/
|
||||
static {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
InterruptJNI.initializeInterruptJVM(status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
}
|
||||
|
||||
/**
|
||||
* The interrupt resource
|
||||
*/
|
||||
protected ByteBuffer m_interrupt = null;
|
||||
protected long m_interrupt = 0;
|
||||
|
||||
/**
|
||||
* Flags if the interrupt being allocated is synchronous
|
||||
@@ -54,7 +38,7 @@ public abstract class InterruptableSensorBase extends SensorBase {
|
||||
* Create a new InterrupatableSensorBase
|
||||
*/
|
||||
public InterruptableSensorBase() {
|
||||
m_interrupt = null;
|
||||
m_interrupt = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -83,24 +67,19 @@ public abstract class InterruptableSensorBase extends SensorBase {
|
||||
* default is interrupt on rising edges only.
|
||||
*/
|
||||
public void requestInterrupts(InterruptHandlerFunction<?> handler) {
|
||||
if (m_interrupt != null) {
|
||||
if (m_interrupt != 0) {
|
||||
throw new AllocationException("The interrupt has already been allocated");
|
||||
}
|
||||
|
||||
allocateInterrupts(false);
|
||||
|
||||
assert (m_interrupt != null);
|
||||
assert (m_interrupt != 0);
|
||||
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
InterruptJNI.requestInterrupts(m_interrupt, getModuleForRouting(), getChannelForRouting(),
|
||||
(byte) (getAnalogTriggerForRouting() ? 1 : 0), status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
getAnalogTriggerForRouting());
|
||||
setUpSourceEdge(true, false);
|
||||
InterruptJNI.attachInterruptHandler(m_interrupt, handler.function,
|
||||
handler.overridableParameter(), status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
handler.overridableParameter());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -110,20 +89,16 @@ public abstract class InterruptableSensorBase extends SensorBase {
|
||||
* The default is interrupt on rising edges only.
|
||||
*/
|
||||
public void requestInterrupts() {
|
||||
if (m_interrupt != null) {
|
||||
if (m_interrupt != 0) {
|
||||
throw new AllocationException("The interrupt has already been allocated");
|
||||
}
|
||||
|
||||
allocateInterrupts(true);
|
||||
|
||||
assert (m_interrupt != null);
|
||||
assert (m_interrupt != 0);
|
||||
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
InterruptJNI.requestInterrupts(m_interrupt, getModuleForRouting(), getChannelForRouting(),
|
||||
(byte) (getAnalogTriggerForRouting() ? 1 : 0), status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
getAnalogTriggerForRouting());
|
||||
setUpSourceEdge(true, false);
|
||||
|
||||
}
|
||||
@@ -143,12 +118,8 @@ public abstract class InterruptableSensorBase extends SensorBase {
|
||||
}
|
||||
m_isSynchronousInterrupt = watcher;
|
||||
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
m_interrupt =
|
||||
InterruptJNI.initializeInterrupts(m_interruptIndex, (byte) (watcher ? 1 : 0),
|
||||
status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
InterruptJNI.initializeInterrupts(m_interruptIndex, watcher);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -156,14 +127,11 @@ public abstract class InterruptableSensorBase extends SensorBase {
|
||||
* structures and disables any interrupts.
|
||||
*/
|
||||
public void cancelInterrupts() {
|
||||
if (m_interrupt == null) {
|
||||
if (m_interrupt == 0) {
|
||||
throw new IllegalStateException("The interrupt is not allocated.");
|
||||
}
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
InterruptJNI.cleanInterrupts(m_interrupt, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
m_interrupt = null;
|
||||
InterruptJNI.cleanInterrupts(m_interrupt);
|
||||
m_interrupt = 0;
|
||||
interrupts.free(m_interruptIndex);
|
||||
}
|
||||
|
||||
@@ -175,14 +143,10 @@ public abstract class InterruptableSensorBase extends SensorBase {
|
||||
* waitForInterrupt was called.
|
||||
*/
|
||||
public void waitForInterrupt(double timeout, boolean ignorePrevious) {
|
||||
if (m_interrupt == null) {
|
||||
if (m_interrupt == 0) {
|
||||
throw new IllegalStateException("The interrupt is not allocated.");
|
||||
}
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
InterruptJNI.waitForInterrupt(m_interrupt, (float) timeout, ignorePrevious,
|
||||
status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
InterruptJNI.waitForInterrupt(m_interrupt, timeout, ignorePrevious);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -200,32 +164,26 @@ public abstract class InterruptableSensorBase extends SensorBase {
|
||||
* options before starting to field interrupts.
|
||||
*/
|
||||
public void enableInterrupts() {
|
||||
if (m_interrupt == null) {
|
||||
if (m_interrupt == 0) {
|
||||
throw new IllegalStateException("The interrupt is not allocated.");
|
||||
}
|
||||
if (m_isSynchronousInterrupt) {
|
||||
throw new IllegalStateException("You do not need to enable synchronous interrupts");
|
||||
}
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
InterruptJNI.enableInterrupts(m_interrupt, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
InterruptJNI.enableInterrupts(m_interrupt);
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable Interrupts without without deallocating structures.
|
||||
*/
|
||||
public void disableInterrupts() {
|
||||
if (m_interrupt == null) {
|
||||
if (m_interrupt == 0) {
|
||||
throw new IllegalStateException("The interrupt is not allocated.");
|
||||
}
|
||||
if (m_isSynchronousInterrupt) {
|
||||
throw new IllegalStateException("You can not disable synchronous interrupts");
|
||||
}
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
InterruptJNI.disableInterrupts(m_interrupt, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
InterruptJNI.disableInterrupts(m_interrupt);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -236,14 +194,10 @@ public abstract class InterruptableSensorBase extends SensorBase {
|
||||
* @return Timestamp in seconds since boot.
|
||||
*/
|
||||
public double readRisingTimestamp() {
|
||||
if (m_interrupt == null) {
|
||||
if (m_interrupt == 0) {
|
||||
throw new IllegalStateException("The interrupt is not allocated.");
|
||||
}
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
double timestamp = InterruptJNI.readRisingTimestamp(m_interrupt, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
return timestamp;
|
||||
return InterruptJNI.readRisingTimestamp(m_interrupt);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -254,14 +208,10 @@ public abstract class InterruptableSensorBase extends SensorBase {
|
||||
* @return Timestamp in seconds since boot.
|
||||
*/
|
||||
public double readFallingTimestamp() {
|
||||
if (m_interrupt == null) {
|
||||
if (m_interrupt == 0) {
|
||||
throw new IllegalStateException("The interrupt is not allocated.");
|
||||
}
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
double timestamp = InterruptJNI.readFallingTimestamp(m_interrupt, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
return timestamp;
|
||||
return InterruptJNI.readFallingTimestamp(m_interrupt);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -271,13 +221,9 @@ public abstract class InterruptableSensorBase extends SensorBase {
|
||||
* @param fallingEdge true to interrupt on falling edge
|
||||
*/
|
||||
public void setUpSourceEdge(boolean risingEdge, boolean fallingEdge) {
|
||||
if (m_interrupt != null) {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
InterruptJNI.setInterruptUpSourceEdge(m_interrupt, (byte) (risingEdge ? 1 : 0),
|
||||
(byte) (fallingEdge ? 1 : 0), status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
if (m_interrupt != 0) {
|
||||
InterruptJNI.setInterruptUpSourceEdge(m_interrupt, risingEdge,
|
||||
fallingEdge);
|
||||
} else {
|
||||
throw new IllegalArgumentException("You must call RequestInterrupts before setUpSourceEdge");
|
||||
}
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
package edu.wpi.first.wpilibj;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import java.lang.Runtime;
|
||||
|
||||
import edu.wpi.first.wpilibj.hal.HALUtil;
|
||||
import edu.wpi.first.wpilibj.hal.NotifierJNI;
|
||||
import edu.wpi.first.wpilibj.Utility;
|
||||
|
||||
@@ -58,7 +55,7 @@ public class Notifier {
|
||||
static private Notifier timerQueueHead = null;
|
||||
// The C pointer to the notifier object. We don't use it directly, it is just
|
||||
// passed to the JNI bindings.
|
||||
private static ByteBuffer m_notifier;
|
||||
private static long m_notifier;
|
||||
// The lock for the queue information (namely, timerQueueHead and the
|
||||
// m_nextEvent members).
|
||||
private static ReentrantLock queueLock = new ReentrantLock();
|
||||
@@ -88,17 +85,6 @@ public class Notifier {
|
||||
// destructed.
|
||||
private ReentrantLock m_handlerLock = new ReentrantLock();
|
||||
|
||||
/**
|
||||
* This is done to store the JVM variable in the InterruptJNI This is done
|
||||
* because the HAL must have access to the JVM variable in order to attach the
|
||||
* newly spawned thread when an interrupt is fired.
|
||||
*/
|
||||
static {
|
||||
ByteBuffer status = pointer();
|
||||
NotifierJNI.initializeNotifierJVM(status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a Notifier for timer event notification.
|
||||
*$
|
||||
@@ -120,9 +106,7 @@ public class Notifier {
|
||||
|
||||
// If this was the last instance of a Notifier, clean up after ourselves.
|
||||
if ((--refcount) == 0) {
|
||||
ByteBuffer status = pointer();
|
||||
NotifierJNI.cleanNotifier(m_notifier, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
NotifierJNI.cleanNotifier(m_notifier);
|
||||
}
|
||||
|
||||
queueLock.unlock();
|
||||
@@ -140,10 +124,7 @@ public class Notifier {
|
||||
*/
|
||||
static protected void updateAlarm() {
|
||||
if (timerQueueHead != null) {
|
||||
ByteBuffer status = pointer();
|
||||
NotifierJNI.updateNotifierAlarm(m_notifier, (int) (timerQueueHead.m_expirationTime * 1e6),
|
||||
status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
NotifierJNI.updateNotifierAlarm(m_notifier, (int) (timerQueueHead.m_expirationTime * 1e6));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -271,17 +252,7 @@ public class Notifier {
|
||||
|
||||
// First time init.
|
||||
protected static void init() {
|
||||
ByteBuffer status = pointer();
|
||||
m_processQueue = new ProcessQueue();
|
||||
m_notifier = NotifierJNI.initializeNotifier(m_processQueue, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
}
|
||||
|
||||
// Returns a ByteBuffer with the appropriate length and endianness to pass to
|
||||
// the JNI bindings.
|
||||
protected static ByteBuffer pointer() {
|
||||
ByteBuffer buf = ByteBuffer.allocateDirect(HALUtil.pointerSize());
|
||||
buf.order(ByteOrder.LITTLE_ENDIAN);
|
||||
return buf;
|
||||
m_notifier = NotifierJNI.initializeNotifier(m_processQueue);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,9 +7,6 @@
|
||||
|
||||
package edu.wpi.first.wpilibj;
|
||||
|
||||
import java.nio.ByteOrder;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType;
|
||||
import edu.wpi.first.wpilibj.communication.UsageReporting;
|
||||
import edu.wpi.first.wpilibj.hal.PWMJNI;
|
||||
@@ -19,7 +16,6 @@ import edu.wpi.first.wpilibj.tables.ITable;
|
||||
import edu.wpi.first.wpilibj.tables.ITableListener;
|
||||
import edu.wpi.first.wpilibj.util.AllocationException;
|
||||
import edu.wpi.first.wpilibj.util.CheckedAllocationException;
|
||||
import edu.wpi.first.wpilibj.hal.HALUtil;
|
||||
|
||||
/**
|
||||
* Class implements the PWM generation in the FPGA.
|
||||
@@ -67,7 +63,7 @@ public class PWM extends SensorBase implements LiveWindowSendable {
|
||||
}
|
||||
|
||||
private int m_channel;
|
||||
private ByteBuffer m_port;
|
||||
private long m_port;
|
||||
/**
|
||||
* kDefaultPwmPeriod is in ms
|
||||
*
|
||||
@@ -116,19 +112,13 @@ public class PWM extends SensorBase implements LiveWindowSendable {
|
||||
checkPWMChannel(channel);
|
||||
m_channel = channel;
|
||||
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
m_port = DIOJNI.initializeDigitalPort(DIOJNI.getPort((byte) m_channel));
|
||||
|
||||
m_port = DIOJNI.initializeDigitalPort(DIOJNI.getPort((byte) m_channel), status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
|
||||
if (!PWMJNI.allocatePWMChannel(m_port, status.asIntBuffer())) {
|
||||
if (!PWMJNI.allocatePWMChannel(m_port)) {
|
||||
throw new AllocationException("PWM channel " + channel + " is already allocated");
|
||||
}
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
|
||||
PWMJNI.setPWM(m_port, (short) 0, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
PWMJNI.setPWM(m_port, (short) 0);
|
||||
|
||||
m_eliminateDeadband = false;
|
||||
|
||||
@@ -150,17 +140,9 @@ public class PWM extends SensorBase implements LiveWindowSendable {
|
||||
* Free the resource associated with the PWM channel and set the value to 0.
|
||||
*/
|
||||
public void free() {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
PWMJNI.setPWM(m_port, (short) 0, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
|
||||
PWMJNI.freePWMChannel(m_port, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
|
||||
PWMJNI.freeDIO(m_port, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
PWMJNI.setPWM(m_port, (short) 0);
|
||||
PWMJNI.freePWMChannel(m_port);
|
||||
PWMJNI.freeDIO(m_port);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -209,11 +191,8 @@ public class PWM extends SensorBase implements LiveWindowSendable {
|
||||
*/
|
||||
protected void setBounds(double max, double deadbandMax, double center, double deadbandMin,
|
||||
double min) {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
double loopTime =
|
||||
DIOJNI.getLoopTiming(status.asIntBuffer()) / (kSystemClockTicksPerMicrosecond * 1e3);
|
||||
DIOJNI.getLoopTiming() / (kSystemClockTicksPerMicrosecond * 1e3);
|
||||
|
||||
m_maxPwm = (int) ((max - kDefaultPwmCenter) / loopTime + kDefaultPwmStepsDown - 1);
|
||||
m_deadbandMaxPwm =
|
||||
@@ -352,11 +331,7 @@ public class PWM extends SensorBase implements LiveWindowSendable {
|
||||
* @param value Raw PWM value. Range 0 - 255.
|
||||
*/
|
||||
public void setRaw(int value) {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
PWMJNI.setPWM(m_port, (short) value, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
PWMJNI.setPWM(m_port, (short) value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -367,13 +342,7 @@ public class PWM extends SensorBase implements LiveWindowSendable {
|
||||
* @return Raw PWM control value. Range: 0 - 255.
|
||||
*/
|
||||
public int getRaw() {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
int value = PWMJNI.getPWM(m_port, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
|
||||
return value;
|
||||
return PWMJNI.getPWM(m_port);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -382,36 +351,26 @@ public class PWM extends SensorBase implements LiveWindowSendable {
|
||||
* @param mult The period multiplier to apply to this channel
|
||||
*/
|
||||
public void setPeriodMultiplier(PeriodMultiplier mult) {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
switch (mult.value) {
|
||||
case PeriodMultiplier.k4X_val:
|
||||
// Squelch 3 out of 4 outputs
|
||||
PWMJNI.setPWMPeriodScale(m_port, 3, status.asIntBuffer());
|
||||
PWMJNI.setPWMPeriodScale(m_port, 3);
|
||||
break;
|
||||
case PeriodMultiplier.k2X_val:
|
||||
// Squelch 1 out of 2 outputs
|
||||
PWMJNI.setPWMPeriodScale(m_port, 1, status.asIntBuffer());
|
||||
PWMJNI.setPWMPeriodScale(m_port, 1);
|
||||
break;
|
||||
case PeriodMultiplier.k1X_val:
|
||||
// Don't squelch any outputs
|
||||
PWMJNI.setPWMPeriodScale(m_port, 0, status.asIntBuffer());
|
||||
PWMJNI.setPWMPeriodScale(m_port, 0);
|
||||
break;
|
||||
default:
|
||||
// Cannot hit this, limited by PeriodMultiplier enum
|
||||
}
|
||||
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
}
|
||||
|
||||
protected void setZeroLatch() {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
PWMJNI.latchPWMZero(m_port, status.asIntBuffer());
|
||||
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
PWMJNI.latchPWMZero(m_port);
|
||||
}
|
||||
|
||||
private int getMaxPositivePwm() {
|
||||
|
||||
@@ -7,9 +7,6 @@
|
||||
|
||||
package edu.wpi.first.wpilibj;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
import edu.wpi.first.wpilibj.hal.PDPJNI;
|
||||
import edu.wpi.first.wpilibj.hal.HALUtil;
|
||||
import edu.wpi.first.wpilibj.livewindow.LiveWindow;
|
||||
@@ -43,12 +40,7 @@ public class PowerDistributionPanel extends SensorBase implements LiveWindowSend
|
||||
* @return The voltage of the PDP in volts
|
||||
*/
|
||||
public double getVoltage() {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
double voltage = PDPJNI.getPDPVoltage(status.asIntBuffer(), m_module);
|
||||
|
||||
return voltage;
|
||||
return PDPJNI.getPDPVoltage(m_module);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -57,12 +49,7 @@ public class PowerDistributionPanel extends SensorBase implements LiveWindowSend
|
||||
* @return The temperature of the PDP in degrees Celsius
|
||||
*/
|
||||
public double getTemperature() {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
double temperature = PDPJNI.getPDPTemperature(status.asIntBuffer(), m_module);
|
||||
|
||||
return temperature;
|
||||
return PDPJNI.getPDPTemperature(m_module);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -71,10 +58,7 @@ public class PowerDistributionPanel extends SensorBase implements LiveWindowSend
|
||||
* @return The current of one of the PDP channels (channels 0-15) in Amperes
|
||||
*/
|
||||
public double getCurrent(int channel) {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
double current = PDPJNI.getPDPChannelCurrent((byte) channel, status.asIntBuffer(), m_module);
|
||||
double current = PDPJNI.getPDPChannelCurrent((byte) channel, m_module);
|
||||
|
||||
checkPDPChannel(channel);
|
||||
|
||||
@@ -87,12 +71,7 @@ public class PowerDistributionPanel extends SensorBase implements LiveWindowSend
|
||||
* @return The current of all the channels in Amperes
|
||||
*/
|
||||
public double getTotalCurrent() {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
double current = PDPJNI.getPDPTotalCurrent(status.asIntBuffer(), m_module);
|
||||
|
||||
return current;
|
||||
return PDPJNI.getPDPTotalCurrent(m_module);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -101,13 +80,7 @@ public class PowerDistributionPanel extends SensorBase implements LiveWindowSend
|
||||
* @return the total power in Watts
|
||||
*/
|
||||
public double getTotalPower() {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
double power = PDPJNI.getPDPTotalPower(status.asIntBuffer(), m_module);
|
||||
|
||||
return power;
|
||||
|
||||
return PDPJNI.getPDPTotalPower(m_module);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -116,32 +89,21 @@ public class PowerDistributionPanel extends SensorBase implements LiveWindowSend
|
||||
* @return the total energy in Joules
|
||||
*/
|
||||
public double getTotalEnergy() {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
double energy = PDPJNI.getPDPTotalEnergy(status.asIntBuffer(), m_module);
|
||||
|
||||
return energy;
|
||||
return PDPJNI.getPDPTotalEnergy(m_module);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the total energy to 0
|
||||
*/
|
||||
public void resetTotalEnergy() {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
PDPJNI.resetPDPTotalEnergy(status.asIntBuffer(), m_module);
|
||||
PDPJNI.resetPDPTotalEnergy(m_module);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear all PDP sticky faults
|
||||
*/
|
||||
public void clearStickyFaults() {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
PDPJNI.clearPDPStickyFaults(status.asIntBuffer(), m_module);
|
||||
PDPJNI.clearPDPStickyFaults(m_module);
|
||||
}
|
||||
|
||||
public String getSmartDashboardType() {
|
||||
|
||||
@@ -7,13 +7,9 @@
|
||||
|
||||
package edu.wpi.first.wpilibj;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType;
|
||||
import edu.wpi.first.wpilibj.communication.UsageReporting;
|
||||
import edu.wpi.first.wpilibj.hal.DIOJNI;
|
||||
import edu.wpi.first.wpilibj.hal.HALUtil;
|
||||
import edu.wpi.first.wpilibj.hal.RelayJNI;
|
||||
import edu.wpi.first.wpilibj.livewindow.LiveWindow;
|
||||
import edu.wpi.first.wpilibj.livewindow.LiveWindowSendable;
|
||||
@@ -112,7 +108,7 @@ public class Relay extends SensorBase implements MotorSafety, LiveWindowSendable
|
||||
}
|
||||
|
||||
private final int m_channel;
|
||||
private ByteBuffer m_port;
|
||||
private long m_port;
|
||||
|
||||
private Direction m_direction;
|
||||
private static Resource relayChannels = new Resource(kRelayChannels * 2);
|
||||
@@ -137,11 +133,7 @@ public class Relay extends SensorBase implements MotorSafety, LiveWindowSendable
|
||||
throw new AllocationException("Relay channel " + m_channel + " is already allocated");
|
||||
}
|
||||
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
m_port = DIOJNI.initializeDigitalPort(DIOJNI.getPort((byte) m_channel), status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
m_port = DIOJNI.initializeDigitalPort(DIOJNI.getPort((byte) m_channel));
|
||||
|
||||
m_safetyHelper = new MotorSafetyHelper(this);
|
||||
m_safetyHelper.setSafetyEnabled(false);
|
||||
@@ -182,16 +174,10 @@ public class Relay extends SensorBase implements MotorSafety, LiveWindowSendable
|
||||
relayChannels.free(m_channel * 2 + 1);
|
||||
}
|
||||
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
RelayJNI.setRelayForward(m_port, false);
|
||||
RelayJNI.setRelayReverse(m_port, false);
|
||||
|
||||
RelayJNI.setRelayForward(m_port, (byte) 0, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
RelayJNI.setRelayReverse(m_port, (byte) 0, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
|
||||
DIOJNI.freeDIO(m_port, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
DIOJNI.freeDIO(m_port);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -210,51 +196,46 @@ public class Relay extends SensorBase implements MotorSafety, LiveWindowSendable
|
||||
* @param value The state to set the relay.
|
||||
*/
|
||||
public void set(Value value) {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
switch (value) {
|
||||
case kOff:
|
||||
if (m_direction == Direction.kBoth || m_direction == Direction.kForward) {
|
||||
RelayJNI.setRelayForward(m_port, (byte) 0, status.asIntBuffer());
|
||||
RelayJNI.setRelayForward(m_port, false);
|
||||
}
|
||||
if (m_direction == Direction.kBoth || m_direction == Direction.kReverse) {
|
||||
RelayJNI.setRelayReverse(m_port, (byte) 0, status.asIntBuffer());
|
||||
RelayJNI.setRelayReverse(m_port, false);
|
||||
}
|
||||
break;
|
||||
case kOn:
|
||||
if (m_direction == Direction.kBoth || m_direction == Direction.kForward) {
|
||||
RelayJNI.setRelayForward(m_port, (byte) 1, status.asIntBuffer());
|
||||
RelayJNI.setRelayForward(m_port, true);
|
||||
}
|
||||
if (m_direction == Direction.kBoth || m_direction == Direction.kReverse) {
|
||||
RelayJNI.setRelayReverse(m_port, (byte) 1, status.asIntBuffer());
|
||||
RelayJNI.setRelayReverse(m_port, true);
|
||||
}
|
||||
break;
|
||||
case kForward:
|
||||
if (m_direction == Direction.kReverse)
|
||||
throw new InvalidValueException("A relay configured for reverse cannot be set to forward");
|
||||
if (m_direction == Direction.kBoth || m_direction == Direction.kForward) {
|
||||
RelayJNI.setRelayForward(m_port, (byte) 1, status.asIntBuffer());
|
||||
RelayJNI.setRelayForward(m_port, true);
|
||||
}
|
||||
if (m_direction == Direction.kBoth) {
|
||||
RelayJNI.setRelayReverse(m_port, (byte) 0, status.asIntBuffer());
|
||||
RelayJNI.setRelayReverse(m_port, false);
|
||||
}
|
||||
break;
|
||||
case kReverse:
|
||||
if (m_direction == Direction.kForward)
|
||||
throw new InvalidValueException("A relay configured for forward cannot be set to reverse");
|
||||
if (m_direction == Direction.kBoth) {
|
||||
RelayJNI.setRelayForward(m_port, (byte) 0, status.asIntBuffer());
|
||||
RelayJNI.setRelayForward(m_port, false);
|
||||
}
|
||||
if (m_direction == Direction.kBoth || m_direction == Direction.kReverse) {
|
||||
RelayJNI.setRelayReverse(m_port, (byte) 1, status.asIntBuffer());
|
||||
RelayJNI.setRelayReverse(m_port, true);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
// Cannot hit this, limited by Value enum
|
||||
}
|
||||
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -268,11 +249,8 @@ public class Relay extends SensorBase implements MotorSafety, LiveWindowSendable
|
||||
* @return The current state of the relay as a Relay::Value
|
||||
*/
|
||||
public Value get() {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
if (RelayJNI.getRelayForward(m_port, status.asIntBuffer()) != 0) {
|
||||
if (RelayJNI.getRelayReverse(m_port, status.asIntBuffer()) != 0) {
|
||||
if (RelayJNI.getRelayForward(m_port)) {
|
||||
if (RelayJNI.getRelayReverse(m_port)) {
|
||||
return Value.kOn;
|
||||
} else {
|
||||
if (m_direction == Direction.kForward) {
|
||||
@@ -282,7 +260,7 @@ public class Relay extends SensorBase implements MotorSafety, LiveWindowSendable
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (RelayJNI.getRelayReverse(m_port, status.asIntBuffer()) != 0) {
|
||||
if (RelayJNI.getRelayReverse(m_port)) {
|
||||
if (m_direction == Direction.kReverse) {
|
||||
return Value.kOn;
|
||||
} else {
|
||||
|
||||
@@ -23,6 +23,7 @@ import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tReso
|
||||
import edu.wpi.first.wpilibj.communication.UsageReporting;
|
||||
import edu.wpi.first.wpilibj.internal.HardwareHLUsageReporting;
|
||||
import edu.wpi.first.wpilibj.internal.HardwareTimer;
|
||||
import edu.wpi.first.wpilibj.networktables.NetworkTablesJNI;
|
||||
import edu.wpi.first.wpilibj.networktables.NetworkTable;
|
||||
import edu.wpi.first.wpilibj.Utility;
|
||||
|
||||
@@ -44,6 +45,12 @@ public abstract class RobotBase {
|
||||
|
||||
protected final DriverStation m_ds;
|
||||
|
||||
private static class MyLogger implements NetworkTablesJNI.LoggerFunction {
|
||||
public void apply(int level, String file, int line, String msg) {
|
||||
System.err.println(msg);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for a generic robot program. User code should be placed in the
|
||||
* constructor that runs before the Autonomous or Operator Control period
|
||||
@@ -59,6 +66,7 @@ public abstract class RobotBase {
|
||||
// TODO: See if the next line is necessary
|
||||
// Resource.RestartProgram();
|
||||
|
||||
NetworkTablesJNI.setLogger(new MyLogger(), 0);
|
||||
NetworkTable.setNetworkIdentity("Robot");
|
||||
NetworkTable.setServerMode();// must be before b
|
||||
m_ds = DriverStation.getInstance();
|
||||
@@ -194,21 +202,21 @@ public abstract class RobotBase {
|
||||
|
||||
UsageReporting.report(tResourceType.kResourceType_Language, tInstances.kLanguage_Java);
|
||||
|
||||
String robotName = "";
|
||||
Enumeration<URL> resources = null;
|
||||
try {
|
||||
resources = RobotBase.class.getClassLoader().getResources("META-INF/MANIFEST.MF");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
while (resources != null && resources.hasMoreElements()) {
|
||||
try {
|
||||
Manifest manifest = new Manifest(resources.nextElement().openStream());
|
||||
robotName = manifest.getMainAttributes().getValue("Robot-Class");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
String robotName = "MyRobot";
|
||||
//Enumeration<URL> resources = null;
|
||||
//try {
|
||||
// resources = RobotBase.class.getClassLoader().getResources("META-INF/MANIFEST.MF");
|
||||
//} catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
//}
|
||||
//while (resources != null && resources.hasMoreElements()) {
|
||||
// try {
|
||||
// Manifest manifest = new Manifest(resources.nextElement().openStream());
|
||||
// robotName = manifest.getMainAttributes().getValue("Robot-Class");
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
//}
|
||||
|
||||
RobotBase robot;
|
||||
try {
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
package edu.wpi.first.wpilibj;
|
||||
|
||||
import java.nio.ByteOrder;
|
||||
import java.nio.IntBuffer;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType;
|
||||
import edu.wpi.first.wpilibj.communication.UsageReporting;
|
||||
import edu.wpi.first.wpilibj.hal.HALLibrary;
|
||||
import edu.wpi.first.wpilibj.hal.HALUtil;
|
||||
import edu.wpi.first.wpilibj.hal.SPIJNI;
|
||||
|
||||
/**
|
||||
@@ -45,14 +42,10 @@ public class SPI extends SensorBase {
|
||||
* @param port the physical SPI port
|
||||
*/
|
||||
public SPI(Port port) {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
m_port = (byte) port.getValue();
|
||||
devices++;
|
||||
|
||||
SPIJNI.spiInitialize(m_port, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
SPIJNI.spiInitialize(m_port);
|
||||
|
||||
UsageReporting.report(tResourceType.kResourceType_SPI, devices);
|
||||
}
|
||||
@@ -132,24 +125,14 @@ public class SPI extends SensorBase {
|
||||
* Configure the chip select line to be active high.
|
||||
*/
|
||||
public final void setChipSelectActiveHigh() {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
SPIJNI.spiSetChipSelectActiveHigh(m_port, status.asIntBuffer());
|
||||
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
SPIJNI.spiSetChipSelectActiveHigh(m_port);
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure the chip select line to be active low.
|
||||
*/
|
||||
public final void setChipSelectActiveLow() {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
SPIJNI.spiSetChipSelectActiveLow(m_port, status.asIntBuffer());
|
||||
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
SPIJNI.spiSetChipSelectActiveLow(m_port);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -8,14 +8,11 @@ package edu.wpi.first.wpilibj;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
import java.nio.ByteOrder;
|
||||
import java.nio.IntBuffer;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType;
|
||||
import edu.wpi.first.wpilibj.communication.UsageReporting;
|
||||
import edu.wpi.first.wpilibj.hal.HALLibrary;
|
||||
import edu.wpi.first.wpilibj.hal.HALUtil;
|
||||
import edu.wpi.first.wpilibj.hal.SerialPortJNI;
|
||||
|
||||
/**
|
||||
@@ -191,20 +188,13 @@ public class SerialPort {
|
||||
*/
|
||||
public SerialPort(final int baudRate, Port port, final int dataBits, Parity parity,
|
||||
StopBits stopBits) {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
m_port = (byte) port.getValue();
|
||||
|
||||
SerialPortJNI.serialInitializePort(m_port, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
SerialPortJNI.serialSetBaudRate(m_port, baudRate, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
SerialPortJNI.serialSetDataBits(m_port, (byte) dataBits, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
SerialPortJNI.serialSetParity(m_port, (byte) parity.value, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
SerialPortJNI.serialSetStopBits(m_port, (byte) stopBits.value, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
SerialPortJNI.serialInitializePort(m_port);
|
||||
SerialPortJNI.serialSetBaudRate(m_port, baudRate);
|
||||
SerialPortJNI.serialSetDataBits(m_port, (byte) dataBits);
|
||||
SerialPortJNI.serialSetParity(m_port, (byte) parity.value);
|
||||
SerialPortJNI.serialSetStopBits(m_port, (byte) stopBits.value);
|
||||
|
||||
// Set the default read buffer size to 1 to return bytes immediately
|
||||
setReadBufferSize(1);
|
||||
@@ -258,10 +248,7 @@ public class SerialPort {
|
||||
* Destructor.
|
||||
*/
|
||||
public void free() {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
SerialPortJNI.serialClose(m_port, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
SerialPortJNI.serialClose(m_port);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -272,10 +259,7 @@ public class SerialPort {
|
||||
* @param flowControl the FlowControl value to use
|
||||
*/
|
||||
public void setFlowControl(FlowControl flowControl) {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
SerialPortJNI.serialSetFlowControl(m_port, (byte) flowControl.value, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
SerialPortJNI.serialSetFlowControl(m_port, (byte) flowControl.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -288,10 +272,7 @@ public class SerialPort {
|
||||
* @param terminator The character to use for termination.
|
||||
*/
|
||||
public void enableTermination(char terminator) {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
SerialPortJNI.serialEnableTermination(m_port, terminator, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
SerialPortJNI.serialEnableTermination(m_port, terminator);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -311,10 +292,7 @@ public class SerialPort {
|
||||
* Disable termination behavior.
|
||||
*/
|
||||
public void disableTermination() {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
SerialPortJNI.serialDisableTermination(m_port, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
SerialPortJNI.serialDisableTermination(m_port);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -323,12 +301,7 @@ public class SerialPort {
|
||||
* @return The number of bytes available to read.
|
||||
*/
|
||||
public int getBytesReceived() {
|
||||
int retVal = 0;
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
retVal = SerialPortJNI.serialGetBytesRecieved(m_port, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
return retVal;
|
||||
return SerialPortJNI.serialGetBytesRecieved(m_port);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -363,11 +336,8 @@ public class SerialPort {
|
||||
* @return An array of the read bytes
|
||||
*/
|
||||
public byte[] read(final int count) {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
ByteBuffer dataReceivedBuffer = ByteBuffer.allocateDirect(count);
|
||||
int gotten = SerialPortJNI.serialRead(m_port, dataReceivedBuffer, count, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
int gotten = SerialPortJNI.serialRead(m_port, dataReceivedBuffer, count);
|
||||
byte[] retVal = new byte[gotten];
|
||||
dataReceivedBuffer.get(retVal);
|
||||
return retVal;
|
||||
@@ -381,13 +351,9 @@ public class SerialPort {
|
||||
* @return The number of bytes actually written into the port.
|
||||
*/
|
||||
public int write(byte[] buffer, int count) {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
ByteBuffer dataToSendBuffer = ByteBuffer.allocateDirect(count);
|
||||
dataToSendBuffer.put(buffer, 0, count);
|
||||
int retVal = SerialPortJNI.serialWrite(m_port, dataToSendBuffer, count, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
return retVal;
|
||||
return SerialPortJNI.serialWrite(m_port, dataToSendBuffer, count);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -410,10 +376,7 @@ public class SerialPort {
|
||||
* @param timeout The number of seconds to to wait for I/O.
|
||||
*/
|
||||
public void setTimeout(double timeout) {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
SerialPortJNI.serialSetTimeout(m_port, (float) timeout, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
SerialPortJNI.serialSetTimeout(m_port, (float) timeout);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -429,10 +392,7 @@ public class SerialPort {
|
||||
* @param size The read buffer size.
|
||||
*/
|
||||
public void setReadBufferSize(int size) {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
SerialPortJNI.serialSetReadBufferSize(m_port, size, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
SerialPortJNI.serialSetReadBufferSize(m_port, size);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -444,10 +404,7 @@ public class SerialPort {
|
||||
* @param size The write buffer size.
|
||||
*/
|
||||
public void setWriteBufferSize(int size) {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
SerialPortJNI.serialSetWriteBufferSize(m_port, size, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
SerialPortJNI.serialSetWriteBufferSize(m_port, size);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -462,10 +419,7 @@ public class SerialPort {
|
||||
* @param mode The write buffer mode.
|
||||
*/
|
||||
public void setWriteBufferMode(WriteBufferMode mode) {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
SerialPortJNI.serialSetWriteMode(m_port, (byte) mode.value, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
SerialPortJNI.serialSetWriteMode(m_port, (byte) mode.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -475,10 +429,7 @@ public class SerialPort {
|
||||
* flush before the buffer is full.
|
||||
*/
|
||||
public void flush() {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
SerialPortJNI.serialFlush(m_port, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
SerialPortJNI.serialFlush(m_port);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -487,9 +438,6 @@ public class SerialPort {
|
||||
* Empty the transmit and receive buffers in the device and formatted I/O.
|
||||
*/
|
||||
public void reset() {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
SerialPortJNI.serialClear(m_port, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
SerialPortJNI.serialClear(m_port);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,12 +7,8 @@
|
||||
|
||||
package edu.wpi.first.wpilibj;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType;
|
||||
import edu.wpi.first.wpilibj.communication.UsageReporting;
|
||||
import edu.wpi.first.wpilibj.hal.HALUtil;
|
||||
import edu.wpi.first.wpilibj.hal.SolenoidJNI;
|
||||
import edu.wpi.first.wpilibj.livewindow.LiveWindow;
|
||||
import edu.wpi.first.wpilibj.livewindow.LiveWindowSendable;
|
||||
@@ -30,7 +26,7 @@ import edu.wpi.first.wpilibj.util.CheckedAllocationException;
|
||||
public class Solenoid extends SolenoidBase implements LiveWindowSendable {
|
||||
|
||||
private int m_channel; // /< The channel to control.
|
||||
private ByteBuffer m_solenoid_port;
|
||||
private long m_solenoid_port;
|
||||
|
||||
/**
|
||||
* Common function to implement constructor behavior.
|
||||
@@ -39,12 +35,8 @@ public class Solenoid extends SolenoidBase implements LiveWindowSendable {
|
||||
checkSolenoidModule(m_moduleNumber);
|
||||
checkSolenoidChannel(m_channel);
|
||||
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
ByteBuffer port = SolenoidJNI.getPortWithModule((byte) m_moduleNumber, (byte) m_channel);
|
||||
m_solenoid_port = SolenoidJNI.initializeSolenoidPort(port, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
long port = SolenoidJNI.getPortWithModule((byte) m_moduleNumber, (byte) m_channel);
|
||||
m_solenoid_port = SolenoidJNI.initializeSolenoidPort(port);
|
||||
|
||||
LiveWindow.addActuator("Solenoid", m_moduleNumber, m_channel, this);
|
||||
UsageReporting.report(tResourceType.kResourceType_Solenoid, m_channel, m_moduleNumber);
|
||||
|
||||
@@ -7,10 +7,6 @@
|
||||
|
||||
package edu.wpi.first.wpilibj;
|
||||
|
||||
import java.nio.IntBuffer;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import edu.wpi.first.wpilibj.hal.HALUtil;
|
||||
import edu.wpi.first.wpilibj.hal.SolenoidJNI;
|
||||
|
||||
/**
|
||||
@@ -19,7 +15,7 @@ import edu.wpi.first.wpilibj.hal.SolenoidJNI;
|
||||
*/
|
||||
public abstract class SolenoidBase extends SensorBase {
|
||||
|
||||
private ByteBuffer[] m_ports;
|
||||
private long[] m_ports;
|
||||
protected int m_moduleNumber; // /< The number of the solenoid module being
|
||||
// used.
|
||||
protected Resource m_allocated = new Resource(63 * SensorBase.kSolenoidChannels);
|
||||
@@ -31,12 +27,10 @@ public abstract class SolenoidBase extends SensorBase {
|
||||
*/
|
||||
public SolenoidBase(final int moduleNumber) {
|
||||
m_moduleNumber = moduleNumber;
|
||||
m_ports = new ByteBuffer[SensorBase.kSolenoidChannels];
|
||||
m_ports = new long[SensorBase.kSolenoidChannels];
|
||||
for (int i = 0; i < SensorBase.kSolenoidChannels; i++) {
|
||||
ByteBuffer port = SolenoidJNI.getPortWithModule((byte) moduleNumber, (byte) i);
|
||||
IntBuffer status = ByteBuffer.allocateDirect(4).asIntBuffer();
|
||||
m_ports[i] = SolenoidJNI.initializeSolenoidPort(port, status);
|
||||
HALUtil.checkStatus(status);
|
||||
long port = SolenoidJNI.getPortWithModule((byte) moduleNumber, (byte) i);
|
||||
m_ports[i] = SolenoidJNI.initializeSolenoidPort(port);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,13 +41,11 @@ public abstract class SolenoidBase extends SensorBase {
|
||||
* @param mask The channels you want to be affected.
|
||||
*/
|
||||
protected synchronized void set(int value, int mask) {
|
||||
IntBuffer status = ByteBuffer.allocateDirect(4).asIntBuffer();
|
||||
for (int i = 0; i < SensorBase.kSolenoidChannels; i++) {
|
||||
int local_mask = 1 << i;
|
||||
if ((mask & local_mask) != 0)
|
||||
SolenoidJNI.setSolenoid(m_ports[i], (byte) (value & local_mask), status);
|
||||
SolenoidJNI.setSolenoid(m_ports[i], (value & local_mask) != 0);
|
||||
}
|
||||
HALUtil.checkStatus(status);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -63,11 +55,9 @@ public abstract class SolenoidBase extends SensorBase {
|
||||
*/
|
||||
public byte getAll() {
|
||||
byte value = 0;
|
||||
IntBuffer status = ByteBuffer.allocateDirect(4).asIntBuffer();
|
||||
for (int i = 0; i < SensorBase.kSolenoidChannels; i++) {
|
||||
value |= SolenoidJNI.getSolenoid(m_ports[i], status) << i;
|
||||
value |= (SolenoidJNI.getSolenoid(m_ports[i]) ? 1 : 0) << i;
|
||||
}
|
||||
HALUtil.checkStatus(status);
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -82,12 +72,7 @@ public abstract class SolenoidBase extends SensorBase {
|
||||
* @return The solenoid blacklist of all 8 solenoids on the module.
|
||||
*/
|
||||
public byte getPCMSolenoidBlackList() {
|
||||
IntBuffer status = ByteBuffer.allocateDirect(4).asIntBuffer();
|
||||
|
||||
byte retval = SolenoidJNI.getPCMSolenoidBlackList(m_ports[0], status);
|
||||
HALUtil.checkStatus(status);
|
||||
|
||||
return retval;
|
||||
return (byte)SolenoidJNI.getPCMSolenoidBlackList(m_ports[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -95,12 +80,7 @@ public abstract class SolenoidBase extends SensorBase {
|
||||
* voltage rail is too low, most likely a solenoid channel is shorted.
|
||||
*/
|
||||
public boolean getPCMSolenoidVoltageStickyFault() {
|
||||
IntBuffer status = ByteBuffer.allocateDirect(4).asIntBuffer();
|
||||
|
||||
boolean retval = SolenoidJNI.getPCMSolenoidVoltageStickyFault(m_ports[0], status);
|
||||
HALUtil.checkStatus(status);
|
||||
|
||||
return retval;
|
||||
return SolenoidJNI.getPCMSolenoidVoltageStickyFault(m_ports[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -108,12 +88,7 @@ public abstract class SolenoidBase extends SensorBase {
|
||||
* voltage rail is too low, most likely a solenoid channel is shorted.
|
||||
*/
|
||||
public boolean getPCMSolenoidVoltageFault() {
|
||||
IntBuffer status = ByteBuffer.allocateDirect(4).asIntBuffer();
|
||||
|
||||
boolean retval = SolenoidJNI.getPCMSolenoidVoltageFault(m_ports[0], status);
|
||||
HALUtil.checkStatus(status);
|
||||
|
||||
return retval;
|
||||
return SolenoidJNI.getPCMSolenoidVoltageFault(m_ports[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -127,9 +102,6 @@ public abstract class SolenoidBase extends SensorBase {
|
||||
* If no sticky faults are set then this call will have no effect.
|
||||
*/
|
||||
public void clearAllPCMStickyFaults() {
|
||||
IntBuffer status = ByteBuffer.allocateDirect(4).asIntBuffer();
|
||||
|
||||
SolenoidJNI.clearAllPCMStickyFaults(m_ports[0], status);
|
||||
HALUtil.checkStatus(status);
|
||||
SolenoidJNI.clearAllPCMStickyFaults(m_ports[0]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,14 +7,7 @@
|
||||
|
||||
package edu.wpi.first.wpilibj;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.nio.IntBuffer;
|
||||
import java.lang.StackTraceElement;
|
||||
|
||||
import edu.wpi.first.wpilibj.hal.HALLibrary;
|
||||
import edu.wpi.first.wpilibj.hal.HALUtil;
|
||||
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary;
|
||||
|
||||
/**
|
||||
* Contains global utility functions
|
||||
@@ -29,12 +22,7 @@ public class Utility {
|
||||
* @return FPGA Version number.
|
||||
*/
|
||||
int getFPGAVersion() {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
int value = HALUtil.getFPGAVersion(status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
return value;
|
||||
return HALUtil.getFPGAVersion();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -45,12 +33,7 @@ public class Utility {
|
||||
* @return FPGA Revision number.
|
||||
*/
|
||||
long getFPGARevision() {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
int value = HALUtil.getFPGARevision(status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
return (long) value;
|
||||
return (long) HALUtil.getFPGARevision();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -59,13 +42,7 @@ public class Utility {
|
||||
* @return The current time in microseconds according to the FPGA.
|
||||
*/
|
||||
public static long getFPGATime() {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
long value = HALUtil.getFPGATime(status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
return value;
|
||||
return HALUtil.getFPGATime();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -74,12 +51,6 @@ public class Utility {
|
||||
* @return true if the button is currently pressed down
|
||||
*/
|
||||
public static boolean getUserButton() {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
boolean value = HALUtil.getFPGAButton(status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
return value;
|
||||
return HALUtil.getFPGAButton();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2008-2012. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
package edu.wpi.first.wpilibj.can;
|
||||
|
||||
import edu.wpi.first.wpilibj.communication.NIRioStatus;
|
||||
import edu.wpi.first.wpilibj.util.UncleanStatusException;
|
||||
|
||||
public class CANExceptionFactory {
|
||||
// FRC Error codes
|
||||
static final int ERR_CANSessionMux_InvalidBuffer = -44086;
|
||||
static final int ERR_CANSessionMux_MessageNotFound = -44087;
|
||||
static final int ERR_CANSessionMux_NotAllowed = -44088;
|
||||
static final int ERR_CANSessionMux_NotInitialized = -44089;
|
||||
|
||||
public static void checkStatus(int status, int messageID) throws CANInvalidBufferException,
|
||||
CANMessageNotAllowedException, CANNotInitializedException, UncleanStatusException {
|
||||
switch (status) {
|
||||
case NIRioStatus.kRioStatusSuccess:
|
||||
// Everything is ok... don't throw.
|
||||
return;
|
||||
case ERR_CANSessionMux_InvalidBuffer:
|
||||
case NIRioStatus.kRIOStatusBufferInvalidSize:
|
||||
throw new CANInvalidBufferException();
|
||||
case ERR_CANSessionMux_MessageNotFound:
|
||||
case NIRioStatus.kRIOStatusOperationTimedOut:
|
||||
throw new CANMessageNotFoundException();
|
||||
case ERR_CANSessionMux_NotAllowed:
|
||||
case NIRioStatus.kRIOStatusFeatureNotSupported:
|
||||
throw new CANMessageNotAllowedException("MessageID = " + Integer.toString(messageID));
|
||||
case ERR_CANSessionMux_NotInitialized:
|
||||
case NIRioStatus.kRIOStatusResourceNotInitialized:
|
||||
throw new CANNotInitializedException();
|
||||
default:
|
||||
throw new UncleanStatusException("Fatal status code detected: " + Integer.toString(status));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -497,8 +497,8 @@ public class CANJNI extends JNIWrapper {
|
||||
public static final int CAN_IS_FRAME_11BIT = 0x40000000;
|
||||
|
||||
public static native void FRCNetworkCommunicationCANSessionMuxSendMessage(int messageID,
|
||||
ByteBuffer data, int periodMs, IntBuffer status);
|
||||
ByteBuffer data, int periodMs);
|
||||
|
||||
public static native ByteBuffer FRCNetworkCommunicationCANSessionMuxReceiveMessage(
|
||||
IntBuffer messageID, int messageIDMask, ByteBuffer timeStamp, IntBuffer status);
|
||||
IntBuffer messageID, int messageIDMask, ByteBuffer timeStamp);
|
||||
}
|
||||
|
||||
@@ -855,7 +855,7 @@ public class FRCNetworkCommunicationsLibrary extends JNIWrapper {
|
||||
* <i>native declaration :
|
||||
* src\main\include\NetworkCommunication\FRCComm.h:147</i>
|
||||
*/
|
||||
public static native void setNewDataSem(ByteBuffer mutexId);
|
||||
public static native void setNewDataSem(long mutexId);
|
||||
|
||||
/**
|
||||
* Original signature : <code>void setResyncSem(pthread_mutex_t*)</code><br>
|
||||
@@ -971,9 +971,9 @@ public class FRCNetworkCommunicationsLibrary extends JNIWrapper {
|
||||
|
||||
public static native float HALGetMatchTime();
|
||||
|
||||
public static native boolean HALGetSystemActive(IntBuffer status);
|
||||
public static native boolean HALGetSystemActive();
|
||||
|
||||
public static native boolean HALGetBrownedOut(IntBuffer status);
|
||||
public static native boolean HALGetBrownedOut();
|
||||
|
||||
public static native int HALSetErrorData(String error);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package edu.wpi.first.wpilibj.hal;
|
||||
|
||||
import java.nio.IntBuffer;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.LongBuffer;
|
||||
|
||||
public class AnalogJNI extends JNIWrapper {
|
||||
@@ -33,95 +32,82 @@ public class AnalogJNI extends JNIWrapper {
|
||||
public static final int kFallingPulse = 3;
|
||||
};
|
||||
|
||||
public static native ByteBuffer initializeAnalogInputPort(ByteBuffer port_pointer,
|
||||
IntBuffer status);
|
||||
public static native long initializeAnalogInputPort(long port_pointer);
|
||||
|
||||
public static native ByteBuffer initializeAnalogOutputPort(ByteBuffer port_pointer,
|
||||
IntBuffer status);
|
||||
public static native long initializeAnalogOutputPort(long port_pointer);
|
||||
|
||||
public static native byte checkAnalogModule(byte module);
|
||||
public static native boolean checkAnalogModule(byte module);
|
||||
|
||||
public static native byte checkAnalogInputChannel(int pin);
|
||||
public static native boolean checkAnalogInputChannel(int pin);
|
||||
|
||||
public static native byte checkAnalogOutputChannel(int pin);
|
||||
public static native boolean checkAnalogOutputChannel(int pin);
|
||||
|
||||
public static native void setAnalogOutput(ByteBuffer port_pointer, double voltage,
|
||||
IntBuffer status);
|
||||
public static native void setAnalogOutput(long port_pointer, double voltage);
|
||||
|
||||
public static native double getAnalogOutput(ByteBuffer port_pointer, IntBuffer status);
|
||||
public static native double getAnalogOutput(long port_pointer);
|
||||
|
||||
public static native void setAnalogSampleRate(double samplesPerSecond, IntBuffer status);
|
||||
public static native void setAnalogSampleRate(double samplesPerSecond);
|
||||
|
||||
public static native double getAnalogSampleRate(IntBuffer status);
|
||||
public static native double getAnalogSampleRate();
|
||||
|
||||
public static native void setAnalogAverageBits(ByteBuffer analog_port_pointer, int bits,
|
||||
IntBuffer status);
|
||||
public static native void setAnalogAverageBits(long analog_port_pointer, int bits);
|
||||
|
||||
public static native int getAnalogAverageBits(ByteBuffer analog_port_pointer, IntBuffer status);
|
||||
public static native int getAnalogAverageBits(long analog_port_pointer);
|
||||
|
||||
public static native void setAnalogOversampleBits(ByteBuffer analog_port_pointer, int bits,
|
||||
IntBuffer status);
|
||||
public static native void setAnalogOversampleBits(long analog_port_pointer, int bits);
|
||||
|
||||
public static native int getAnalogOversampleBits(ByteBuffer analog_port_pointer, IntBuffer status);
|
||||
public static native int getAnalogOversampleBits(long analog_port_pointer);
|
||||
|
||||
public static native short getAnalogValue(ByteBuffer analog_port_pointer, IntBuffer status);
|
||||
public static native short getAnalogValue(long analog_port_pointer);
|
||||
|
||||
public static native int getAnalogAverageValue(ByteBuffer analog_port_pointer, IntBuffer status);
|
||||
public static native int getAnalogAverageValue(long analog_port_pointer);
|
||||
|
||||
public static native int getAnalogVoltsToValue(ByteBuffer analog_port_pointer, double voltage,
|
||||
IntBuffer status);
|
||||
public static native int getAnalogVoltsToValue(long analog_port_pointer, double voltage);
|
||||
|
||||
public static native double getAnalogVoltage(ByteBuffer analog_port_pointer, IntBuffer status);
|
||||
public static native double getAnalogVoltage(long analog_port_pointer);
|
||||
|
||||
public static native double getAnalogAverageVoltage(ByteBuffer analog_port_pointer,
|
||||
IntBuffer status);
|
||||
public static native double getAnalogAverageVoltage(long analog_port_pointer);
|
||||
|
||||
public static native int getAnalogLSBWeight(ByteBuffer analog_port_pointer, IntBuffer status);
|
||||
public static native int getAnalogLSBWeight(long analog_port_pointer);
|
||||
|
||||
public static native int getAnalogOffset(ByteBuffer analog_port_pointer, IntBuffer status);
|
||||
public static native int getAnalogOffset(long analog_port_pointer);
|
||||
|
||||
public static native byte isAccumulatorChannel(ByteBuffer analog_port_pointer, IntBuffer status);
|
||||
public static native boolean isAccumulatorChannel(long analog_port_pointer);
|
||||
|
||||
public static native void initAccumulator(ByteBuffer analog_port_pointer, IntBuffer status);
|
||||
public static native void initAccumulator(long analog_port_pointer);
|
||||
|
||||
public static native void resetAccumulator(ByteBuffer analog_port_pointer, IntBuffer status);
|
||||
public static native void resetAccumulator(long analog_port_pointer);
|
||||
|
||||
public static native void setAccumulatorCenter(ByteBuffer analog_port_pointer, int center,
|
||||
IntBuffer status);
|
||||
public static native void setAccumulatorCenter(long analog_port_pointer, int center);
|
||||
|
||||
public static native void setAccumulatorDeadband(ByteBuffer analog_port_pointer, int deadband,
|
||||
IntBuffer status);
|
||||
public static native void setAccumulatorDeadband(long analog_port_pointer, int deadband);
|
||||
|
||||
public static native long getAccumulatorValue(ByteBuffer analog_port_pointer, IntBuffer status);
|
||||
public static native long getAccumulatorValue(long analog_port_pointer);
|
||||
|
||||
public static native int getAccumulatorCount(ByteBuffer analog_port_pointer, IntBuffer status);
|
||||
public static native int getAccumulatorCount(long analog_port_pointer);
|
||||
|
||||
public static native void getAccumulatorOutput(ByteBuffer analog_port_pointer, LongBuffer value,
|
||||
IntBuffer count, IntBuffer status);
|
||||
public static native void getAccumulatorOutput(long analog_port_pointer, LongBuffer value,
|
||||
IntBuffer count);
|
||||
|
||||
public static native ByteBuffer initializeAnalogTrigger(ByteBuffer port_pointer, IntBuffer index,
|
||||
IntBuffer status);
|
||||
public static native long initializeAnalogTrigger(long port_pointer, IntBuffer index);
|
||||
|
||||
public static native void cleanAnalogTrigger(ByteBuffer analog_trigger_pointer, IntBuffer status);
|
||||
public static native void cleanAnalogTrigger(long analog_trigger_pointer);
|
||||
|
||||
public static native void setAnalogTriggerLimitsRaw(ByteBuffer analog_trigger_pointer, int lower,
|
||||
int upper, IntBuffer status);
|
||||
public static native void setAnalogTriggerLimitsRaw(long analog_trigger_pointer, int lower,
|
||||
int upper);
|
||||
|
||||
public static native void setAnalogTriggerLimitsVoltage(ByteBuffer analog_trigger_pointer,
|
||||
double lower, double upper, IntBuffer status);
|
||||
public static native void setAnalogTriggerLimitsVoltage(long analog_trigger_pointer,
|
||||
double lower, double upper);
|
||||
|
||||
public static native void setAnalogTriggerAveraged(ByteBuffer analog_trigger_pointer,
|
||||
byte useAveragedValue, IntBuffer status);
|
||||
public static native void setAnalogTriggerAveraged(long analog_trigger_pointer,
|
||||
boolean useAveragedValue);
|
||||
|
||||
public static native void setAnalogTriggerFiltered(ByteBuffer analog_trigger_pointer,
|
||||
byte useFilteredValue, IntBuffer status);
|
||||
public static native void setAnalogTriggerFiltered(long analog_trigger_pointer,
|
||||
boolean useFilteredValue);
|
||||
|
||||
public static native byte getAnalogTriggerInWindow(ByteBuffer analog_trigger_pointer,
|
||||
IntBuffer status);
|
||||
public static native boolean getAnalogTriggerInWindow(long analog_trigger_pointer);
|
||||
|
||||
public static native byte getAnalogTriggerTriggerState(ByteBuffer analog_trigger_pointer,
|
||||
IntBuffer status);
|
||||
public static native boolean getAnalogTriggerTriggerState(long analog_trigger_pointer);
|
||||
|
||||
public static native byte getAnalogTriggerOutput(ByteBuffer analog_trigger_pointer, int type,
|
||||
IntBuffer status);
|
||||
public static native boolean getAnalogTriggerOutput(long analog_trigger_pointer, int type);
|
||||
}
|
||||
|
||||
@@ -1,40 +1,31 @@
|
||||
package edu.wpi.first.wpilibj.hal;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.IntBuffer;
|
||||
|
||||
public class CompressorJNI extends JNIWrapper {
|
||||
public static native ByteBuffer initializeCompressor(byte module);
|
||||
public static native long initializeCompressor(byte module);
|
||||
|
||||
public static native boolean checkCompressorModule(byte module);
|
||||
|
||||
public static native boolean getCompressor(ByteBuffer pcm_pointer, IntBuffer status);
|
||||
public static native boolean getCompressor(long pcm_pointer);
|
||||
|
||||
public static native void setClosedLoopControl(ByteBuffer pcm_pointer, boolean value,
|
||||
IntBuffer status);
|
||||
public static native void setClosedLoopControl(long pcm_pointer, boolean value);
|
||||
|
||||
public static native boolean getClosedLoopControl(ByteBuffer pcm_pointer, IntBuffer status);
|
||||
public static native boolean getClosedLoopControl(long pcm_pointer);
|
||||
|
||||
public static native boolean getPressureSwitch(ByteBuffer pcm_pointer, IntBuffer status);
|
||||
public static native boolean getPressureSwitch(long pcm_pointer);
|
||||
|
||||
public static native float getCompressorCurrent(ByteBuffer pcm_pointer, IntBuffer status);
|
||||
public static native float getCompressorCurrent(long pcm_pointer);
|
||||
|
||||
public static native boolean getCompressorCurrentTooHighFault(ByteBuffer pcm_pointer,
|
||||
IntBuffer status);
|
||||
public static native boolean getCompressorCurrentTooHighFault(long pcm_pointer);
|
||||
|
||||
public static native boolean getCompressorCurrentTooHighStickyFault(ByteBuffer pcm_pointer,
|
||||
IntBuffer status);
|
||||
public static native boolean getCompressorCurrentTooHighStickyFault(long pcm_pointer);
|
||||
|
||||
public static native boolean getCompressorShortedStickyFault(ByteBuffer pcm_pointer,
|
||||
IntBuffer status);
|
||||
public static native boolean getCompressorShortedStickyFault(long pcm_pointer);
|
||||
|
||||
public static native boolean getCompressorShortedFault(ByteBuffer pcm_pointer, IntBuffer status);
|
||||
public static native boolean getCompressorShortedFault(long pcm_pointer);
|
||||
|
||||
public static native boolean getCompressorNotConnectedStickyFault(ByteBuffer pcm_pointer,
|
||||
IntBuffer status);
|
||||
public static native boolean getCompressorNotConnectedStickyFault(long pcm_pointer);
|
||||
|
||||
public static native boolean getCompressorNotConnectedFault(ByteBuffer pcm_pointer,
|
||||
IntBuffer status);
|
||||
public static native boolean getCompressorNotConnectedFault(long pcm_pointer);
|
||||
|
||||
public static native void clearAllPCMStickyFaults(ByteBuffer pcm_pointer, IntBuffer status);
|
||||
public static native void clearAllPCMStickyFaults(long pcm_pointer);
|
||||
}
|
||||
|
||||
@@ -1,64 +1,58 @@
|
||||
package edu.wpi.first.wpilibj.hal;
|
||||
|
||||
import java.nio.IntBuffer;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public class CounterJNI extends JNIWrapper {
|
||||
public static native ByteBuffer initializeCounter(int mode, IntBuffer index, IntBuffer status);
|
||||
public static native long initializeCounter(int mode, IntBuffer index);
|
||||
|
||||
public static native void freeCounter(ByteBuffer counter_pointer, IntBuffer status);
|
||||
public static native void freeCounter(long counter_pointer);
|
||||
|
||||
public static native void setCounterAverageSize(ByteBuffer counter_pointer, int size,
|
||||
IntBuffer status);
|
||||
public static native void setCounterAverageSize(long counter_pointer, int size);
|
||||
|
||||
public static native void setCounterUpSource(ByteBuffer counter_pointer, int pin,
|
||||
byte analogTrigger, IntBuffer status);
|
||||
public static native void setCounterUpSource(long counter_pointer, int pin,
|
||||
boolean analogTrigger);
|
||||
|
||||
public static native void setCounterUpSourceEdge(ByteBuffer counter_pointer, byte risingEdge,
|
||||
byte fallingEdge, IntBuffer status);
|
||||
public static native void setCounterUpSourceEdge(long counter_pointer, boolean risingEdge,
|
||||
boolean fallingEdge);
|
||||
|
||||
public static native void clearCounterUpSource(ByteBuffer counter_pointer, IntBuffer status);
|
||||
public static native void clearCounterUpSource(long counter_pointer);
|
||||
|
||||
public static native void setCounterDownSource(ByteBuffer counter_pointer, int pin,
|
||||
byte analogTrigger, IntBuffer status);
|
||||
public static native void setCounterDownSource(long counter_pointer, int pin,
|
||||
boolean analogTrigger);
|
||||
|
||||
public static native void setCounterDownSourceEdge(ByteBuffer counter_pointer, byte risingEdge,
|
||||
byte fallingEdge, IntBuffer status);
|
||||
public static native void setCounterDownSourceEdge(long counter_pointer, boolean risingEdge,
|
||||
boolean fallingEdge);
|
||||
|
||||
public static native void clearCounterDownSource(ByteBuffer counter_pointer, IntBuffer status);
|
||||
public static native void clearCounterDownSource(long counter_pointer);
|
||||
|
||||
public static native void setCounterUpDownMode(ByteBuffer counter_pointer, IntBuffer status);
|
||||
public static native void setCounterUpDownMode(long counter_pointer);
|
||||
|
||||
public static native void setCounterExternalDirectionMode(ByteBuffer counter_pointer,
|
||||
IntBuffer status);
|
||||
public static native void setCounterExternalDirectionMode(long counter_pointer);
|
||||
|
||||
public static native void setCounterSemiPeriodMode(ByteBuffer counter_pointer,
|
||||
byte highSemiPeriod, IntBuffer status);
|
||||
public static native void setCounterSemiPeriodMode(long counter_pointer,
|
||||
boolean highSemiPeriod);
|
||||
|
||||
public static native void setCounterPulseLengthMode(ByteBuffer counter_pointer, double threshold,
|
||||
IntBuffer status);
|
||||
public static native void setCounterPulseLengthMode(long counter_pointer, double threshold);
|
||||
|
||||
public static native int getCounterSamplesToAverage(ByteBuffer counter_pointer, IntBuffer status);
|
||||
public static native int getCounterSamplesToAverage(long counter_pointer);
|
||||
|
||||
public static native void setCounterSamplesToAverage(ByteBuffer counter_pointer,
|
||||
int samplesToAverage, IntBuffer status);
|
||||
public static native void setCounterSamplesToAverage(long counter_pointer,
|
||||
int samplesToAverage);
|
||||
|
||||
public static native void resetCounter(ByteBuffer counter_pointer, IntBuffer status);
|
||||
public static native void resetCounter(long counter_pointer);
|
||||
|
||||
public static native int getCounter(ByteBuffer counter_pointer, IntBuffer status);
|
||||
public static native int getCounter(long counter_pointer);
|
||||
|
||||
public static native double getCounterPeriod(ByteBuffer counter_pointer, IntBuffer status);
|
||||
public static native double getCounterPeriod(long counter_pointer);
|
||||
|
||||
public static native void setCounterMaxPeriod(ByteBuffer counter_pointer, double maxPeriod,
|
||||
IntBuffer status);
|
||||
public static native void setCounterMaxPeriod(long counter_pointer, double maxPeriod);
|
||||
|
||||
public static native void setCounterUpdateWhenEmpty(ByteBuffer counter_pointer, byte enabled,
|
||||
IntBuffer status);
|
||||
public static native void setCounterUpdateWhenEmpty(long counter_pointer, boolean enabled);
|
||||
|
||||
public static native byte getCounterStopped(ByteBuffer counter_pointer, IntBuffer status);
|
||||
public static native boolean getCounterStopped(long counter_pointer);
|
||||
|
||||
public static native byte getCounterDirection(ByteBuffer counter_pointer, IntBuffer status);
|
||||
public static native boolean getCounterDirection(long counter_pointer);
|
||||
|
||||
public static native void setCounterReverseDirection(ByteBuffer counter_pointer,
|
||||
byte reverseDirection, IntBuffer status);
|
||||
public static native void setCounterReverseDirection(long counter_pointer,
|
||||
boolean reverseDirection);
|
||||
}
|
||||
|
||||
@@ -1,28 +1,23 @@
|
||||
package edu.wpi.first.wpilibj.hal;
|
||||
|
||||
import java.nio.IntBuffer;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public class DIOJNI extends JNIWrapper {
|
||||
public static native ByteBuffer initializeDigitalPort(ByteBuffer port_pointer, IntBuffer status);
|
||||
public static native long initializeDigitalPort(long port_pointer);
|
||||
|
||||
public static native byte allocateDIO(ByteBuffer digital_port_pointer, byte input,
|
||||
IntBuffer status);
|
||||
public static native boolean allocateDIO(long digital_port_pointer, boolean input);
|
||||
|
||||
public static native void freeDIO(ByteBuffer digital_port_pointer, IntBuffer status);
|
||||
public static native void freeDIO(long digital_port_pointer);
|
||||
|
||||
public static native void setDIO(ByteBuffer digital_port_pointer, short value, IntBuffer status);
|
||||
public static native void setDIO(long digital_port_pointer, short value);
|
||||
|
||||
public static native byte getDIO(ByteBuffer digital_port_pointer, IntBuffer status);
|
||||
public static native boolean getDIO(long digital_port_pointer);
|
||||
|
||||
public static native byte getDIODirection(ByteBuffer digital_port_pointer, IntBuffer status);
|
||||
public static native boolean getDIODirection(long digital_port_pointer);
|
||||
|
||||
public static native void pulse(ByteBuffer digital_port_pointer, double pulseLength,
|
||||
IntBuffer status);
|
||||
public static native void pulse(long digital_port_pointer, double pulseLength);
|
||||
|
||||
public static native byte isPulsing(ByteBuffer digital_port_pointer, IntBuffer status);
|
||||
public static native boolean isPulsing(long digital_port_pointer);
|
||||
|
||||
public static native byte isAnyPulsing(IntBuffer status);
|
||||
public static native boolean isAnyPulsing();
|
||||
|
||||
public static native short getLoopTiming(IntBuffer status);
|
||||
public static native short getLoopTiming();
|
||||
}
|
||||
|
||||
@@ -1,36 +1,34 @@
|
||||
package edu.wpi.first.wpilibj.hal;
|
||||
|
||||
import java.nio.IntBuffer;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public class EncoderJNI extends JNIWrapper {
|
||||
public static native ByteBuffer initializeEncoder(byte port_a_module, int port_a_pin,
|
||||
byte port_a_analog_trigger, byte port_b_module, int port_b_pin, byte port_b_analog_trigger,
|
||||
byte reverseDirection, IntBuffer index, IntBuffer status);
|
||||
public static native long initializeEncoder(byte port_a_module, int port_a_pin,
|
||||
boolean port_a_analog_trigger, byte port_b_module, int port_b_pin, boolean port_b_analog_trigger,
|
||||
boolean reverseDirection, IntBuffer index);
|
||||
|
||||
public static native void freeEncoder(ByteBuffer encoder_pointer, IntBuffer status);
|
||||
public static native void freeEncoder(long encoder_pointer);
|
||||
|
||||
public static native void resetEncoder(ByteBuffer encoder_pointer, IntBuffer status);
|
||||
public static native void resetEncoder(long encoder_pointer);
|
||||
|
||||
public static native int getEncoder(ByteBuffer encoder_pointer, IntBuffer status);
|
||||
public static native int getEncoder(long encoder_pointer);
|
||||
|
||||
public static native double getEncoderPeriod(ByteBuffer encoder_pointer, IntBuffer status);
|
||||
public static native double getEncoderPeriod(long encoder_pointer);
|
||||
|
||||
public static native void setEncoderMaxPeriod(ByteBuffer encoder_pointer, double maxPeriod,
|
||||
IntBuffer status);
|
||||
public static native void setEncoderMaxPeriod(long encoder_pointer, double maxPeriod);
|
||||
|
||||
public static native byte getEncoderStopped(ByteBuffer encoder_pointer, IntBuffer status);
|
||||
public static native boolean getEncoderStopped(long encoder_pointer);
|
||||
|
||||
public static native byte getEncoderDirection(ByteBuffer encoder_pointer, IntBuffer status);
|
||||
public static native boolean getEncoderDirection(long encoder_pointer);
|
||||
|
||||
public static native void setEncoderReverseDirection(ByteBuffer encoder_pointer,
|
||||
byte reverseDirection, IntBuffer status);
|
||||
public static native void setEncoderReverseDirection(long encoder_pointer,
|
||||
boolean reverseDirection);
|
||||
|
||||
public static native void setEncoderSamplesToAverage(ByteBuffer encoder_pointer,
|
||||
int samplesToAverage, IntBuffer status);
|
||||
public static native void setEncoderSamplesToAverage(long encoder_pointer,
|
||||
int samplesToAverage);
|
||||
|
||||
public static native int getEncoderSamplesToAverage(ByteBuffer encoder_pointer, IntBuffer status);
|
||||
public static native int getEncoderSamplesToAverage(long encoder_pointer);
|
||||
|
||||
public static native void setEncoderIndexSource(ByteBuffer digital_port, int pin,
|
||||
boolean analogTrigger, boolean activeHigh, boolean edgeSensitive, IntBuffer status);
|
||||
public static native void setEncoderIndexSource(long digital_port, int pin,
|
||||
boolean analogTrigger, boolean activeHigh, boolean edgeSensitive);
|
||||
}
|
||||
|
||||
@@ -12,8 +12,7 @@ package edu.wpi.first.wpilibj.hal;
|
||||
// import com.sun.jna.PointerType;
|
||||
// import com.sun.jna.ptr.IntByReference;
|
||||
// import com.sun.jna.ptr.LongByReference;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.IntBuffer;
|
||||
// import java.nio.IntBuffer;
|
||||
|
||||
/**
|
||||
* JNA Wrapper for library <b>HAL</b><br>
|
||||
@@ -282,7 +281,7 @@ public class HALLibrary /* implements Library */{
|
||||
* <i>native declaration :
|
||||
* AthenaJava\target\native\include\HAL\Semaphore.h:385</i>
|
||||
*/
|
||||
public static native ByteBuffer initializeMutex(int flags);
|
||||
public static native long initializeMutex(int flags);
|
||||
|
||||
/**
|
||||
* Original signature : <code>void deleteMutex(MUTEX_ID)</code><br>
|
||||
@@ -300,7 +299,7 @@ public class HALLibrary /* implements Library */{
|
||||
* <i>native declaration :
|
||||
* AthenaJava\target\native\include\HAL\Semaphore.h:387</i>
|
||||
*/
|
||||
public static native void deleteMutex(ByteBuffer sem);
|
||||
public static native void deleteMutex(long sem);
|
||||
|
||||
/**
|
||||
* Original signature : <code>int8_t takeMutex(MUTEX_ID, int32_t)</code><br>
|
||||
@@ -318,7 +317,7 @@ public class HALLibrary /* implements Library */{
|
||||
* <i>native declaration :
|
||||
* AthenaJava\target\native\include\HAL\Semaphore.h:389</i>
|
||||
*/
|
||||
public static native byte takeMutex(ByteBuffer sem, int timeout);
|
||||
public static native byte takeMutex(long sem, int timeout);
|
||||
|
||||
/**
|
||||
* Original signature : <code>int8_t giveMutex(MUTEX_ID)</code><br>
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
package edu.wpi.first.wpilibj.hal;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.IntBuffer;
|
||||
import edu.wpi.first.wpilibj.DriverStation;
|
||||
|
||||
public class HALUtil extends JNIWrapper {
|
||||
public static final int NULL_PARAMETER = -1005;
|
||||
public static final int SAMPLE_RATE_TOO_HIGH = 1001;
|
||||
@@ -17,28 +13,28 @@ public class HALUtil extends JNIWrapper {
|
||||
// public static final int SEMAPHORE_WAIT_FOREVER = -1;
|
||||
// public static final int SEMAPHORE_Q_PRIORITY = 0x01;
|
||||
|
||||
public static native ByteBuffer initializeMutexNormal();
|
||||
public static native long initializeMutexNormal();
|
||||
|
||||
public static native void deleteMutex(ByteBuffer sem);
|
||||
public static native void deleteMutex(long sem);
|
||||
|
||||
public static native byte takeMutex(ByteBuffer sem);
|
||||
public static native void takeMutex(long sem);
|
||||
|
||||
// public static native ByteBuffer initializeSemaphore(int initialValue);
|
||||
// public static native void deleteSemaphore(ByteBuffer sem);
|
||||
// public static native byte takeSemaphore(ByteBuffer sem, int timeout);
|
||||
public static native ByteBuffer initializeMultiWait();
|
||||
// public static native long initializeSemaphore(int initialValue);
|
||||
// public static native void deleteSemaphore(long sem);
|
||||
// public static native byte takeSemaphore(long sem, int timeout);
|
||||
public static native long initializeMultiWait();
|
||||
|
||||
public static native void deleteMultiWait(ByteBuffer sem);
|
||||
public static native void deleteMultiWait(long sem);
|
||||
|
||||
public static native byte takeMultiWait(ByteBuffer sem, ByteBuffer m);
|
||||
public static native void takeMultiWait(long sem, long m);
|
||||
|
||||
public static native short getFPGAVersion(IntBuffer status);
|
||||
public static native short getFPGAVersion();
|
||||
|
||||
public static native int getFPGARevision(IntBuffer status);
|
||||
public static native int getFPGARevision();
|
||||
|
||||
public static native long getFPGATime(IntBuffer status);
|
||||
public static native long getFPGATime();
|
||||
|
||||
public static native boolean getFPGAButton(IntBuffer status);
|
||||
public static native boolean getFPGAButton();
|
||||
|
||||
public static native String getHALErrorMessage(int code);
|
||||
|
||||
@@ -49,17 +45,4 @@ public class HALUtil extends JNIWrapper {
|
||||
public static String getHALstrerror() {
|
||||
return getHALstrerror(getHALErrno());
|
||||
}
|
||||
|
||||
public static void checkStatus(IntBuffer status) {
|
||||
int s = status.get(0);
|
||||
if (s < 0) {
|
||||
String message = getHALErrorMessage(s);
|
||||
throw new RuntimeException(" Code: " + s + ". " + message);
|
||||
} else if (s > 0) {
|
||||
String message = getHALErrorMessage(s);
|
||||
DriverStation.reportError(message, true);
|
||||
}
|
||||
}
|
||||
|
||||
public static native int pointerSize();
|
||||
}
|
||||
|
||||
@@ -1,17 +1,16 @@
|
||||
package edu.wpi.first.wpilibj.hal;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.IntBuffer;
|
||||
|
||||
public class I2CJNI extends JNIWrapper {
|
||||
public static native void i2CInitialize(byte port, IntBuffer status);
|
||||
public static native void i2CInitialize(byte port);
|
||||
|
||||
public static native byte i2CTransaction(byte port, byte address, ByteBuffer dataToSend,
|
||||
public static native int i2CTransaction(byte port, byte address, ByteBuffer dataToSend,
|
||||
byte sendSize, ByteBuffer dataReceived, byte receiveSize);
|
||||
|
||||
public static native byte i2CWrite(byte port, byte address, ByteBuffer dataToSend, byte sendSize);
|
||||
public static native int i2CWrite(byte port, byte address, ByteBuffer dataToSend, byte sendSize);
|
||||
|
||||
public static native byte i2CRead(byte port, byte address, ByteBuffer dataRecieved,
|
||||
public static native int i2CRead(byte port, byte address, ByteBuffer dataRecieved,
|
||||
byte receiveSize);
|
||||
|
||||
public static native void i2CClose(byte port);
|
||||
|
||||
@@ -1,37 +1,31 @@
|
||||
package edu.wpi.first.wpilibj.hal;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.IntBuffer;
|
||||
|
||||
public class InterruptJNI extends JNIWrapper {
|
||||
public interface InterruptJNIHandlerFunction {
|
||||
void apply(int interruptAssertedMask, Object param);
|
||||
};
|
||||
|
||||
public static native void initializeInterruptJVM(IntBuffer status);
|
||||
public static native long initializeInterrupts(int interruptIndex, boolean watcher);
|
||||
|
||||
public static native ByteBuffer initializeInterrupts(int interruptIndex, byte watcher,
|
||||
IntBuffer status);
|
||||
public static native void cleanInterrupts(long interrupt_pointer);
|
||||
|
||||
public static native void cleanInterrupts(ByteBuffer interrupt_pointer, IntBuffer status);
|
||||
public static native int waitForInterrupt(long interrupt_pointer, double timeout,
|
||||
boolean ignorePrevious);
|
||||
|
||||
public static native int waitForInterrupt(ByteBuffer interrupt_pointer, double timeout,
|
||||
boolean ignorePrevious, IntBuffer status);
|
||||
public static native void enableInterrupts(long interrupt_pointer);
|
||||
|
||||
public static native void enableInterrupts(ByteBuffer interrupt_pointer, IntBuffer status);
|
||||
public static native void disableInterrupts(long interrupt_pointer);
|
||||
|
||||
public static native void disableInterrupts(ByteBuffer interrupt_pointer, IntBuffer status);
|
||||
public static native double readRisingTimestamp(long interrupt_pointer);
|
||||
|
||||
public static native double readRisingTimestamp(ByteBuffer interrupt_pointer, IntBuffer status);
|
||||
public static native double readFallingTimestamp(long interrupt_pointer);
|
||||
|
||||
public static native double readFallingTimestamp(ByteBuffer interrupt_pointer, IntBuffer status);
|
||||
public static native void requestInterrupts(long interrupt_pointer, byte routing_module,
|
||||
int routing_pin, boolean routing_analog_trigger);
|
||||
|
||||
public static native void requestInterrupts(ByteBuffer interrupt_pointer, byte routing_module,
|
||||
int routing_pin, byte routing_analog_trigger, IntBuffer status);
|
||||
public static native void attachInterruptHandler(long interrupt_pointer,
|
||||
InterruptJNIHandlerFunction handler, Object param);
|
||||
|
||||
public static native void attachInterruptHandler(ByteBuffer interrupt_pointer,
|
||||
InterruptJNIHandlerFunction handler, Object param, IntBuffer status);
|
||||
|
||||
public static native void setInterruptUpSourceEdge(ByteBuffer interrupt_pointer, byte risingEdge,
|
||||
byte fallingEdge, IntBuffer status);
|
||||
public static native void setInterruptUpSourceEdge(long interrupt_pointer, boolean risingEdge,
|
||||
boolean fallingEdge);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
//
|
||||
// base class for all JNI wrappers
|
||||
@@ -49,7 +48,7 @@ public class JNIWrapper {
|
||||
}
|
||||
}
|
||||
|
||||
public static native ByteBuffer getPortWithModule(byte module, byte pin);
|
||||
public static native long getPortWithModule(byte module, byte pin);
|
||||
|
||||
public static native ByteBuffer getPort(byte pin);
|
||||
public static native long getPort(byte pin);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package edu.wpi.first.wpilibj.hal;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.IntBuffer;
|
||||
import java.lang.Runtime;
|
||||
|
||||
/**
|
||||
@@ -17,22 +15,15 @@ public class NotifierJNI extends JNIWrapper {
|
||||
*
|
||||
* Should be called after initializeNotifierJVM().
|
||||
*/
|
||||
public static native ByteBuffer initializeNotifier(Runnable func, IntBuffer status);
|
||||
|
||||
/**
|
||||
* Initializes the JVM for use by the callback. Should be called before
|
||||
* anything else.
|
||||
*/
|
||||
public static native void initializeNotifierJVM(IntBuffer status);
|
||||
public static native long initializeNotifier(Runnable func);
|
||||
|
||||
/**
|
||||
* Deletes the notifier object when we are done with it.
|
||||
*/
|
||||
public static native void cleanNotifier(ByteBuffer notifierPtr, IntBuffer status);
|
||||
public static native void cleanNotifier(long notifierPtr);
|
||||
|
||||
/**
|
||||
* Sets the notifier to call the callback in another triggerTime microseconds.
|
||||
*/
|
||||
public static native void updateNotifierAlarm(ByteBuffer notifierPtr, int triggerTime,
|
||||
IntBuffer status);
|
||||
public static native void updateNotifierAlarm(long notifierPtr, int triggerTime);
|
||||
}
|
||||
|
||||
@@ -1,24 +1,21 @@
|
||||
package edu.wpi.first.wpilibj.hal;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.IntBuffer;
|
||||
|
||||
public class PDPJNI extends JNIWrapper {
|
||||
public static native void initializePDP(int module);
|
||||
|
||||
public static native double getPDPTemperature(IntBuffer status, int module);
|
||||
public static native double getPDPTemperature(int module);
|
||||
|
||||
public static native double getPDPVoltage(IntBuffer status, int module);
|
||||
public static native double getPDPVoltage(int module);
|
||||
|
||||
public static native double getPDPChannelCurrent(byte channel, IntBuffer status, int module);
|
||||
public static native double getPDPChannelCurrent(byte channel, int module);
|
||||
|
||||
public static native double getPDPTotalCurrent(IntBuffer status, int module);
|
||||
public static native double getPDPTotalCurrent(int module);
|
||||
|
||||
public static native double getPDPTotalPower(IntBuffer status, int module);
|
||||
public static native double getPDPTotalPower(int module);
|
||||
|
||||
public static native double getPDPTotalEnergy(IntBuffer status, int module);
|
||||
public static native double getPDPTotalEnergy(int module);
|
||||
|
||||
public static native void resetPDPTotalEnergy(IntBuffer status, int module);
|
||||
public static native void resetPDPTotalEnergy(int module);
|
||||
|
||||
public static native void clearPDPStickyFaults(IntBuffer status, int module);
|
||||
public static native void clearPDPStickyFaults(int module);
|
||||
}
|
||||
|
||||
@@ -1,33 +1,25 @@
|
||||
package edu.wpi.first.wpilibj.hal;
|
||||
|
||||
import java.nio.IntBuffer;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import edu.wpi.first.wpilibj.SensorBase;
|
||||
|
||||
|
||||
public class PWMJNI extends DIOJNI {
|
||||
public static native boolean allocatePWMChannel(ByteBuffer digital_port_pointer, IntBuffer status);
|
||||
public static native boolean allocatePWMChannel(long digital_port_pointer);
|
||||
|
||||
public static native void freePWMChannel(ByteBuffer digital_port_pointer, IntBuffer status);
|
||||
public static native void freePWMChannel(long digital_port_pointer);
|
||||
|
||||
public static native void setPWM(ByteBuffer digital_port_pointer, short value, IntBuffer status);
|
||||
public static native void setPWM(long digital_port_pointer, short value);
|
||||
|
||||
public static native short getPWM(ByteBuffer digital_port_pointer, IntBuffer status);
|
||||
public static native short getPWM(long digital_port_pointer);
|
||||
|
||||
public static native void latchPWMZero(ByteBuffer digital_port_pointer, IntBuffer status);
|
||||
public static native void latchPWMZero(long digital_port_pointer);
|
||||
|
||||
public static native void setPWMPeriodScale(ByteBuffer digital_port_pointer, int squelchMask,
|
||||
IntBuffer status);
|
||||
public static native void setPWMPeriodScale(long digital_port_pointer, int squelchMask);
|
||||
|
||||
public static native ByteBuffer allocatePWM(IntBuffer status);
|
||||
public static native long allocatePWM();
|
||||
|
||||
public static native void freePWM(ByteBuffer pwmGenerator, IntBuffer status);
|
||||
public static native void freePWM(long pwmGenerator);
|
||||
|
||||
public static native void setPWMRate(double rate, IntBuffer status);
|
||||
public static native void setPWMRate(double rate);
|
||||
|
||||
public static native void setPWMDutyCycle(ByteBuffer pwmGenerator, double dutyCycle,
|
||||
IntBuffer status);
|
||||
public static native void setPWMDutyCycle(long pwmGenerator, double dutyCycle);
|
||||
|
||||
public static native void setPWMOutputChannel(ByteBuffer pwmGenerator, int pin, IntBuffer status);
|
||||
public static native void setPWMOutputChannel(long pwmGenerator, int pin);
|
||||
}
|
||||
|
||||
@@ -1,33 +1,31 @@
|
||||
package edu.wpi.first.wpilibj.hal;
|
||||
|
||||
import java.nio.IntBuffer;
|
||||
|
||||
public class PowerJNI extends JNIWrapper {
|
||||
public static native float getVinVoltage(IntBuffer status);
|
||||
public static native float getVinVoltage();
|
||||
|
||||
public static native float getVinCurrent(IntBuffer status);
|
||||
public static native float getVinCurrent();
|
||||
|
||||
public static native float getUserVoltage6V(IntBuffer status);
|
||||
public static native float getUserVoltage6V();
|
||||
|
||||
public static native float getUserCurrent6V(IntBuffer status);
|
||||
public static native float getUserCurrent6V();
|
||||
|
||||
public static native boolean getUserActive6V(IntBuffer status);
|
||||
public static native boolean getUserActive6V();
|
||||
|
||||
public static native int getUserCurrentFaults6V(IntBuffer status);
|
||||
public static native int getUserCurrentFaults6V();
|
||||
|
||||
public static native float getUserVoltage5V(IntBuffer status);
|
||||
public static native float getUserVoltage5V();
|
||||
|
||||
public static native float getUserCurrent5V(IntBuffer status);
|
||||
public static native float getUserCurrent5V();
|
||||
|
||||
public static native boolean getUserActive5V(IntBuffer status);
|
||||
public static native boolean getUserActive5V();
|
||||
|
||||
public static native int getUserCurrentFaults5V(IntBuffer status);
|
||||
public static native int getUserCurrentFaults5V();
|
||||
|
||||
public static native float getUserVoltage3V3(IntBuffer status);
|
||||
public static native float getUserVoltage3V3();
|
||||
|
||||
public static native float getUserCurrent3V3(IntBuffer status);
|
||||
public static native float getUserCurrent3V3();
|
||||
|
||||
public static native boolean getUserActive3V3(IntBuffer status);
|
||||
public static native boolean getUserActive3V3();
|
||||
|
||||
public static native int getUserCurrentFaults3V3(IntBuffer status);
|
||||
public static native int getUserCurrentFaults3V3();
|
||||
}
|
||||
|
||||
@@ -1,16 +1,11 @@
|
||||
package edu.wpi.first.wpilibj.hal;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.IntBuffer;
|
||||
|
||||
public class RelayJNI extends DIOJNI {
|
||||
public static native void setRelayForward(ByteBuffer digital_port_pointer, byte on,
|
||||
IntBuffer status);
|
||||
public static native void setRelayForward(long digital_port_pointer, boolean on);
|
||||
|
||||
public static native void setRelayReverse(ByteBuffer digital_port_pointer, byte on,
|
||||
IntBuffer status);
|
||||
public static native void setRelayReverse(long digital_port_pointer, boolean on);
|
||||
|
||||
public static native byte getRelayForward(ByteBuffer digital_port_pointer, IntBuffer status);
|
||||
public static native boolean getRelayForward(long digital_port_pointer);
|
||||
|
||||
public static native byte getRelayReverse(ByteBuffer digital_port_pointer, IntBuffer status);
|
||||
public static native boolean getRelayReverse(long digital_port_pointer);
|
||||
}
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
package edu.wpi.first.wpilibj.hal;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.IntBuffer;
|
||||
|
||||
public class SPIJNI extends JNIWrapper {
|
||||
public static native void spiInitialize(byte port, IntBuffer status);
|
||||
public static native void spiInitialize(byte port);
|
||||
|
||||
public static native int spiTransaction(byte port, ByteBuffer dataToSend,
|
||||
ByteBuffer dataReceived, byte size);
|
||||
@@ -22,7 +21,7 @@ public class SPIJNI extends JNIWrapper {
|
||||
public static native void spiSetOpts(byte port, int msb_first, int sample_on_trailing,
|
||||
int clk_idle_high);
|
||||
|
||||
public static native void spiSetChipSelectActiveHigh(byte port, IntBuffer status);
|
||||
public static native void spiSetChipSelectActiveHigh(byte port);
|
||||
|
||||
public static native void spiSetChipSelectActiveLow(byte port, IntBuffer status);
|
||||
public static native void spiSetChipSelectActiveLow(byte port);
|
||||
}
|
||||
|
||||
@@ -1,42 +1,41 @@
|
||||
package edu.wpi.first.wpilibj.hal;
|
||||
|
||||
import java.nio.IntBuffer;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public class SerialPortJNI extends JNIWrapper {
|
||||
public static native void serialInitializePort(byte port, IntBuffer status);
|
||||
public static native void serialInitializePort(byte port);
|
||||
|
||||
public static native void serialSetBaudRate(byte port, int baud, IntBuffer status);
|
||||
public static native void serialSetBaudRate(byte port, int baud);
|
||||
|
||||
public static native void serialSetDataBits(byte port, byte bits, IntBuffer status);
|
||||
public static native void serialSetDataBits(byte port, byte bits);
|
||||
|
||||
public static native void serialSetParity(byte port, byte parity, IntBuffer status);
|
||||
public static native void serialSetParity(byte port, byte parity);
|
||||
|
||||
public static native void serialSetStopBits(byte port, byte stopBits, IntBuffer status);
|
||||
public static native void serialSetStopBits(byte port, byte stopBits);
|
||||
|
||||
public static native void serialSetWriteMode(byte port, byte mode, IntBuffer status);
|
||||
public static native void serialSetWriteMode(byte port, byte mode);
|
||||
|
||||
public static native void serialSetFlowControl(byte port, byte flow, IntBuffer status);
|
||||
public static native void serialSetFlowControl(byte port, byte flow);
|
||||
|
||||
public static native void serialSetTimeout(byte port, float timeout, IntBuffer status);
|
||||
public static native void serialSetTimeout(byte port, float timeout);
|
||||
|
||||
public static native void serialEnableTermination(byte port, char terminator, IntBuffer status);
|
||||
public static native void serialEnableTermination(byte port, char terminator);
|
||||
|
||||
public static native void serialDisableTermination(byte port, IntBuffer status);
|
||||
public static native void serialDisableTermination(byte port);
|
||||
|
||||
public static native void serialSetReadBufferSize(byte port, int size, IntBuffer status);
|
||||
public static native void serialSetReadBufferSize(byte port, int size);
|
||||
|
||||
public static native void serialSetWriteBufferSize(byte port, int size, IntBuffer status);
|
||||
public static native void serialSetWriteBufferSize(byte port, int size);
|
||||
|
||||
public static native int serialGetBytesRecieved(byte port, IntBuffer status);
|
||||
public static native int serialGetBytesRecieved(byte port);
|
||||
|
||||
public static native int serialRead(byte port, ByteBuffer buffer, int count, IntBuffer status);
|
||||
public static native int serialRead(byte port, ByteBuffer buffer, int count);
|
||||
|
||||
public static native int serialWrite(byte port, ByteBuffer buffer, int count, IntBuffer status);
|
||||
public static native int serialWrite(byte port, ByteBuffer buffer, int count);
|
||||
|
||||
public static native void serialFlush(byte port, IntBuffer status);
|
||||
public static native void serialFlush(byte port);
|
||||
|
||||
public static native void serialClear(byte port, IntBuffer status);
|
||||
public static native void serialClear(byte port);
|
||||
|
||||
public static native void serialClose(byte port, IntBuffer status);
|
||||
public static native void serialClose(byte port);
|
||||
}
|
||||
|
||||
@@ -1,23 +1,19 @@
|
||||
package edu.wpi.first.wpilibj.hal;
|
||||
|
||||
import java.nio.IntBuffer;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public class SolenoidJNI extends JNIWrapper {
|
||||
public static native ByteBuffer initializeSolenoidPort(ByteBuffer portPointer, IntBuffer status);
|
||||
public static native long initializeSolenoidPort(long portPointer);
|
||||
|
||||
public static native ByteBuffer getPortWithModule(byte module, byte channel);
|
||||
public static native long getPortWithModule(byte module, byte channel);
|
||||
|
||||
public static native void setSolenoid(ByteBuffer port, byte on, IntBuffer status);
|
||||
public static native void setSolenoid(long port, boolean on);
|
||||
|
||||
public static native byte getSolenoid(ByteBuffer port, IntBuffer status);
|
||||
public static native boolean getSolenoid(long port);
|
||||
|
||||
public static native byte getPCMSolenoidBlackList(ByteBuffer pcm_pointer, IntBuffer status);
|
||||
public static native int getPCMSolenoidBlackList(long pcm_pointer);
|
||||
|
||||
public static native boolean getPCMSolenoidVoltageStickyFault(ByteBuffer pcm_pointer,
|
||||
IntBuffer status);
|
||||
public static native boolean getPCMSolenoidVoltageStickyFault(long pcm_pointer);
|
||||
|
||||
public static native boolean getPCMSolenoidVoltageFault(ByteBuffer pcm_pointer, IntBuffer status);
|
||||
public static native boolean getPCMSolenoidVoltageFault(long pcm_pointer);
|
||||
|
||||
public static native void clearAllPCMStickyFaults(ByteBuffer pcm_pointer, IntBuffer status);
|
||||
public static native void clearAllPCMStickyFaults(long pcm_pointer);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user