Changes HAL Port from a pointer to a handle (#93)

HAL Port is using a special handle, where the module and pin are bit
shifted straight into the handle. This is one of the few special cases
we have, but for the way port is used it is much cleaner and uses much
less memory.  Plus it is generic and not specific to one type.
This commit is contained in:
Thad House
2016-06-05 15:23:58 -07:00
committed by Peter Johnson
parent 5a82f73d9b
commit fc515f4572
44 changed files with 288 additions and 233 deletions

View File

@@ -59,8 +59,8 @@ public class AnalogInput extends SensorBase implements PIDSource, LiveWindowSend
throw new AllocationException("Analog input channel " + m_channel + " is already allocated");
}
final long portPointer = AnalogJNI.getPort((byte) channel);
m_port = AnalogJNI.initializeAnalogInputPort(portPointer);
final int portHandle = AnalogJNI.getPort((byte) channel);
m_port = AnalogJNI.initializeAnalogInputPort(portHandle);
LiveWindow.addSensor("AnalogInput", channel, this);
UsageReporting.report(tResourceType.kResourceType_AnalogChannel, channel);

View File

@@ -42,8 +42,8 @@ public class AnalogOutput extends SensorBase implements LiveWindowSendable {
throw new AllocationException("Analog output channel " + m_channel + " is already allocated");
}
final long portPointer = AnalogJNI.getPort((byte) channel);
m_port = AnalogJNI.initializeAnalogOutputPort(portPointer);
final int portHandle = AnalogJNI.getPort((byte) channel);
m_port = AnalogJNI.initializeAnalogOutputPort(portHandle);
LiveWindow.addSensor("AnalogOutput", channel, this);
UsageReporting.report(tResourceType.kResourceType_AnalogOutput, channel);

View File

@@ -51,12 +51,12 @@ public class AnalogTrigger {
* @param channel the port to use for the analog trigger
*/
public AnalogTrigger(final int channel) {
final long portPointer = AnalogJNI.getPort((byte) channel);
final int portHandle = AnalogJNI.getPort((byte) channel);
ByteBuffer index = ByteBuffer.allocateDirect(4);
index.order(ByteOrder.LITTLE_ENDIAN);
m_port =
AnalogJNI.initializeAnalogTrigger(portPointer, index.asIntBuffer());
AnalogJNI.initializeAnalogTrigger(portHandle, index.asIntBuffer());
m_index = index.asIntBuffer().get(0);
UsageReporting.report(tResourceType.kResourceType_AnalogTrigger, channel);

View File

@@ -35,8 +35,8 @@ public abstract class DigitalSource extends InterruptableSensorBase {
throw new AllocationException("Digital input " + m_channel + " is already allocated");
}
long portPointer = DIOJNI.getPort((byte) channel);
m_port = DIOJNI.initializeDigitalPort(portPointer);
int portHandle = DIOJNI.getPort((byte) channel);
m_port = DIOJNI.initializeDigitalPort(portHandle);
DIOJNI.allocateDIO(m_port, input);
}

View File

@@ -57,8 +57,8 @@ public class Solenoid extends SolenoidBase implements LiveWindowSendable {
+ m_moduleNumber + " is already allocated");
}
long port = SolenoidJNI.getPortWithModule((byte) m_moduleNumber, (byte) m_channel);
m_solenoidPort = SolenoidJNI.initializeSolenoidPort(port);
int portHandle = SolenoidJNI.getPortWithModule((byte) m_moduleNumber, (byte) m_channel);
m_solenoidPort = SolenoidJNI.initializeSolenoidPort(portHandle);
LiveWindow.addActuator("Solenoid", m_moduleNumber, m_channel, this);
UsageReporting.report(tResourceType.kResourceType_Solenoid, m_channel, m_moduleNumber);

View File

@@ -28,8 +28,8 @@ public abstract class SolenoidBase extends SensorBase {
m_moduleNumber = moduleNumber;
m_ports = new long[SensorBase.kSolenoidChannels];
for (int i = 0; i < SensorBase.kSolenoidChannels; i++) {
long port = SolenoidJNI.getPortWithModule((byte) moduleNumber, (byte) i);
m_ports[i] = SolenoidJNI.initializeSolenoidPort(port);
int portHandle = SolenoidJNI.getPortWithModule((byte) moduleNumber, (byte) i);
m_ports[i] = SolenoidJNI.initializeSolenoidPort(portHandle);
}
}

View File

@@ -33,11 +33,11 @@ public class AnalogJNI extends JNIWrapper {
int kFallingPulse = 3;
}
public static native long initializeAnalogInputPort(long portPointer);
public static native long initializeAnalogInputPort(int halPortHandle);
public static native void freeAnalogInputPort(long portPointer);
public static native long initializeAnalogOutputPort(long portPointer);
public static native long initializeAnalogOutputPort(int halPortHandle);
public static native void freeAnalogOutputPort(long portPointer);
@@ -94,7 +94,7 @@ public class AnalogJNI extends JNIWrapper {
public static native void getAccumulatorOutput(long analogPortPointer, LongBuffer value,
IntBuffer count);
public static native long initializeAnalogTrigger(long portPointer, IntBuffer index);
public static native long initializeAnalogTrigger(int halPortHandle, IntBuffer index);
public static native void cleanAnalogTrigger(long analogTriggerPointer);

View File

@@ -9,7 +9,7 @@ package edu.wpi.first.wpilibj.hal;
@SuppressWarnings("AbbreviationAsWordInName")
public class DIOJNI extends JNIWrapper {
public static native long initializeDigitalPort(long portPointer);
public static native long initializeDigitalPort(int halPortHandle);
public static native void freeDigitalPort(long portPointer);

View File

@@ -59,9 +59,9 @@ public class JNIWrapper {
}
}
public static native long getPortWithModule(byte module, byte pin);
public static native int getPortWithModule(byte module, byte pin);
public static native long getPort(byte pin);
public static native int getPort(byte pin);
public static native void freePort(long portPointer);
public static native void freePort(int halPortHandle);
}

View File

@@ -8,12 +8,10 @@
package edu.wpi.first.wpilibj.hal;
public class SolenoidJNI extends JNIWrapper {
public static native long initializeSolenoidPort(long portPointer);
public static native long initializeSolenoidPort(int halPortHandle);
public static native void freeSolenoidPort(long portPointer);
public static native long getPortWithModule(byte module, byte channel);
public static native void setSolenoid(long port, boolean on);
public static native boolean getSolenoid(long port);