mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-23 01:21:42 +00:00
Switch to 0-based for all pins on the RoboRIO [artf2564]
Change-Id: I249965a9d55aec53b7d8a9be3ba5cc43500ddda4
This commit is contained in:
@@ -47,7 +47,7 @@ public class AnalogChannel extends SensorBase implements PIDSource,
|
||||
* kAnalogChannels);
|
||||
private ByteBuffer m_port;
|
||||
private int m_moduleNumber, m_channel;
|
||||
private static final int[] kAccumulatorChannels = { 1, 2 };
|
||||
private static final int[] kAccumulatorChannels = { 0, 1 };
|
||||
private long m_accumulatorOffset;
|
||||
|
||||
/**
|
||||
@@ -82,8 +82,7 @@ public class AnalogChannel extends SensorBase implements PIDSource,
|
||||
+ " cannot be allocated. Channel is not present.");
|
||||
}
|
||||
try {
|
||||
channels.allocate((moduleNumber - 1) * kAnalogChannels + channel
|
||||
- 1);
|
||||
channels.allocate((moduleNumber - 1) * kAnalogChannels + channel);
|
||||
} catch (CheckedAllocationException e) {
|
||||
throw new AllocationException("Analog channel " + m_channel
|
||||
+ " on module " + m_moduleNumber + " is already allocated");
|
||||
@@ -107,7 +106,7 @@ public class AnalogChannel extends SensorBase implements PIDSource,
|
||||
* Channel destructor.
|
||||
*/
|
||||
public void free() {
|
||||
channels.free(((m_moduleNumber - 1) * kAnalogChannels + m_channel - 1));
|
||||
channels.free(((m_moduleNumber - 1) * kAnalogChannels + m_channel));
|
||||
m_channel = 0;
|
||||
m_moduleNumber = 0;
|
||||
m_accumulatorOffset = 0;
|
||||
|
||||
@@ -71,7 +71,7 @@ public class AnalogModule extends Module {
|
||||
|
||||
m_ports = new ByteBuffer[8];
|
||||
for (int i = 0; i < SensorBase.kAnalogChannels; i++) {
|
||||
ByteBuffer port_pointer = AnalogJNI.getPortWithModule((byte) moduleNumber, (byte) (i+1));
|
||||
ByteBuffer port_pointer = AnalogJNI.getPortWithModule((byte) moduleNumber, (byte) i);
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
@@ -65,7 +65,7 @@ public class DigitalModule extends Module {
|
||||
m_digital_ports = new ByteBuffer[SensorBase.kDigitalChannels];
|
||||
for (int i = 0; i < SensorBase.kDigitalChannels; i++) {
|
||||
ByteBuffer port_pointer = DIOJNI.getPortWithModule(
|
||||
(byte) moduleNumber, (byte) (i + 1));
|
||||
(byte) moduleNumber, (byte) i);
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
@@ -77,7 +77,7 @@ public class DigitalModule extends Module {
|
||||
m_relay_ports = new ByteBuffer[SensorBase.kRelayChannels];
|
||||
for (int i = 0; i < SensorBase.kRelayChannels; i++) {
|
||||
ByteBuffer port_pointer = RelayJNI.getPortWithModule(
|
||||
(byte) moduleNumber, (byte) (i + 1));
|
||||
(byte) moduleNumber, (byte) i);
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
@@ -88,7 +88,7 @@ public class DigitalModule extends Module {
|
||||
m_pwm_ports = new ByteBuffer[SensorBase.kPwmChannels];
|
||||
for (int i = 0; i < SensorBase.kPwmChannels; i++) {
|
||||
ByteBuffer port_pointer = PWMJNI.getPortWithModule(
|
||||
(byte) moduleNumber, (byte) (i + 1));
|
||||
(byte) moduleNumber, (byte) i);
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
@@ -112,7 +112,7 @@ public class DigitalModule extends Module {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
PWMJNI.setPWM(m_pwm_ports[channel - 1], (short) value, status.asIntBuffer());
|
||||
PWMJNI.setPWM(m_pwm_ports[channel], (short) value, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ public class DigitalModule extends Module {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
int value = (int) PWMJNI.getPWM(m_pwm_ports[channel - 1], status.asIntBuffer());
|
||||
int value = (int) PWMJNI.getPWM(m_pwm_ports[channel], status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
return value;
|
||||
}
|
||||
@@ -144,7 +144,7 @@ public class DigitalModule extends Module {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
PWMJNI.setPWMPeriodScale(m_pwm_ports[channel - 1], squelchMask,
|
||||
PWMJNI.setPWMPeriodScale(m_pwm_ports[channel], squelchMask,
|
||||
status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
}
|
||||
@@ -162,7 +162,7 @@ public class DigitalModule extends Module {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
RelayJNI.setRelayForward(m_relay_ports[channel - 1], (byte) (on ? 1
|
||||
RelayJNI.setRelayForward(m_relay_ports[channel], (byte) (on ? 1
|
||||
: 0), status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
}
|
||||
@@ -180,7 +180,7 @@ public class DigitalModule extends Module {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
RelayJNI.setRelayReverse(m_relay_ports[channel - 1], (byte) (on ? 1
|
||||
RelayJNI.setRelayReverse(m_relay_ports[channel], (byte) (on ? 1
|
||||
: 0), status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
}
|
||||
@@ -196,7 +196,7 @@ public class DigitalModule extends Module {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
boolean value = RelayJNI.getRelayForward(m_relay_ports[channel - 1],
|
||||
boolean value = RelayJNI.getRelayForward(m_relay_ports[channel],
|
||||
status.asIntBuffer()) != 0;
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
return value;
|
||||
@@ -231,7 +231,7 @@ public class DigitalModule extends Module {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
boolean value = RelayJNI.getRelayReverse(m_relay_ports[channel - 1],
|
||||
boolean value = RelayJNI.getRelayReverse(m_relay_ports[channel],
|
||||
status.asIntBuffer()) != 0;
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
return value;
|
||||
@@ -272,7 +272,7 @@ public class DigitalModule extends Module {
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
boolean allocated = DIOJNI.allocateDIO(
|
||||
m_digital_ports[channel - 1], (byte) (input ? 1 : 0), status.asIntBuffer()) != 0;
|
||||
m_digital_ports[channel], (byte) (input ? 1 : 0), status.asIntBuffer()) != 0;
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
return allocated;
|
||||
}
|
||||
@@ -287,7 +287,7 @@ public class DigitalModule extends Module {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
DIOJNI.freeDIO(m_digital_ports[channel - 1], status.asIntBuffer());
|
||||
DIOJNI.freeDIO(m_digital_ports[channel], status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
}
|
||||
|
||||
@@ -304,7 +304,7 @@ public class DigitalModule extends Module {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
DIOJNI.setDIO(m_digital_ports[channel - 1], (byte) (value ? 1 : 0),
|
||||
DIOJNI.setDIO(m_digital_ports[channel], (byte) (value ? 1 : 0),
|
||||
status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
}
|
||||
@@ -321,7 +321,7 @@ public class DigitalModule extends Module {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
boolean value = DIOJNI.getDIO(m_digital_ports[channel - 1], status.asIntBuffer()) != 0;
|
||||
boolean value = DIOJNI.getDIO(m_digital_ports[channel], status.asIntBuffer()) != 0;
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
return value;
|
||||
}
|
||||
@@ -357,7 +357,7 @@ public class DigitalModule extends Module {
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
boolean value = DIOJNI.getDIODirection(
|
||||
m_digital_ports[channel - 1], status.asIntBuffer()) != 0;
|
||||
m_digital_ports[channel], status.asIntBuffer()) != 0;
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
return value;
|
||||
}
|
||||
@@ -394,7 +394,7 @@ public class DigitalModule extends Module {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
DIOJNI.pulse(m_digital_ports[channel - 1], pulseLength, status.asIntBuffer());
|
||||
DIOJNI.pulse(m_digital_ports[channel], pulseLength, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
}
|
||||
|
||||
@@ -415,7 +415,7 @@ public class DigitalModule extends Module {
|
||||
float convertedPulse = (float) (pulseLength / 1.0e9 * (DIOJNI.getLoopTiming(status.asIntBuffer()) * 25));
|
||||
System.err
|
||||
.println("You should use the float version of pulse for portability. This is deprecated");
|
||||
DIOJNI.pulse(m_digital_ports[channel - 1], convertedPulse, status.asIntBuffer());
|
||||
DIOJNI.pulse(m_digital_ports[channel], convertedPulse, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
}
|
||||
|
||||
@@ -430,7 +430,7 @@ public class DigitalModule extends Module {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
boolean value = DIOJNI.isPulsing(m_digital_ports[channel - 1],
|
||||
boolean value = DIOJNI.isPulsing(m_digital_ports[channel],
|
||||
status.asIntBuffer()) != 0;
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
return value;
|
||||
|
||||
@@ -45,7 +45,7 @@ public abstract class DigitalSource extends InterruptableSensorBase {
|
||||
|
||||
try {
|
||||
channels.allocate((m_moduleNumber - 1) * kDigitalChannels
|
||||
+ m_channel - 1);
|
||||
+ m_channel);
|
||||
} catch (CheckedAllocationException ex) {
|
||||
throw new AllocationException("Digital input " + m_channel
|
||||
+ " on module " + m_moduleNumber + " is already allocated");
|
||||
@@ -63,7 +63,7 @@ public abstract class DigitalSource extends InterruptableSensorBase {
|
||||
}
|
||||
|
||||
public void free() {
|
||||
channels.free(((m_moduleNumber - 1) * kDigitalChannels + m_channel - 1));
|
||||
channels.free(((m_moduleNumber - 1) * kDigitalChannels + m_channel));
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
@@ -79,7 +79,7 @@ public abstract class DigitalSource extends InterruptableSensorBase {
|
||||
* @return channel routing number
|
||||
*/
|
||||
public int getChannelForRouting() {
|
||||
return m_channel - 1;
|
||||
return m_channel;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -31,7 +31,7 @@ public class DriverStation implements IInputOutput {
|
||||
/**
|
||||
* Analog channel to read the battery
|
||||
*/
|
||||
public static final int kBatteryChannel = 8;
|
||||
public static final int kBatteryChannel = 7;
|
||||
/**
|
||||
* Number of Joystick Ports
|
||||
*/
|
||||
|
||||
@@ -116,7 +116,7 @@ public class PWM extends SensorBase implements LiveWindowSendable {
|
||||
checkPWMModule(moduleNumber);
|
||||
checkPWMChannel(channel);
|
||||
try {
|
||||
allocated.allocate((moduleNumber - 1) * kPwmChannels + channel - 1);
|
||||
allocated.allocate((moduleNumber - 1) * kPwmChannels + channel);
|
||||
} catch (CheckedAllocationException e) {
|
||||
throw new AllocationException(
|
||||
"PWM channel " + channel + " on module " + moduleNumber + " is already allocated");
|
||||
@@ -159,7 +159,7 @@ public class PWM extends SensorBase implements LiveWindowSendable {
|
||||
public void free() {
|
||||
m_module.setPWM(m_channel, kPwmDisabled);
|
||||
m_module.freeDIO(m_channel);
|
||||
allocated.free((m_module.getModuleNumber() - 1) * kPwmChannels + m_channel - 1);
|
||||
allocated.free((m_module.getModuleNumber() - 1) * kPwmChannels + m_channel);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -139,14 +139,14 @@ public class Relay extends SensorBase implements IDeviceController,
|
||||
if (m_direction == Direction.kBoth
|
||||
|| m_direction == Direction.kForward) {
|
||||
relayChannels.allocate(((moduleNumber - 1) * kRelayChannels
|
||||
+ m_channel - 1) * 2);
|
||||
+ m_channel) * 2);
|
||||
UsageReporting.report(tResourceType.kResourceType_Relay,
|
||||
m_channel, moduleNumber - 1);
|
||||
}
|
||||
if (m_direction == Direction.kBoth
|
||||
|| m_direction == Direction.kReverse) {
|
||||
relayChannels.allocate(((moduleNumber - 1) * kRelayChannels
|
||||
+ m_channel - 1) * 2 + 1);
|
||||
+ m_channel) * 2 + 1);
|
||||
UsageReporting.report(tResourceType.kResourceType_Relay,
|
||||
m_channel + 128, moduleNumber - 1);
|
||||
}
|
||||
@@ -229,15 +229,15 @@ public class Relay extends SensorBase implements IDeviceController,
|
||||
|
||||
if (m_direction == Direction.kBoth || m_direction == Direction.kForward) {
|
||||
relayChannels.free(((m_module.getModuleNumber() - 1)
|
||||
* kRelayChannels + m_channel - 1) * 2);
|
||||
* kRelayChannels + m_channel) * 2);
|
||||
m_module.freeDIO(((m_module.getModuleNumber() - 1) * kRelayChannels
|
||||
+ m_channel - 1) * 2);
|
||||
+ m_channel) * 2);
|
||||
}
|
||||
if (m_direction == Direction.kBoth || m_direction == Direction.kReverse) {
|
||||
relayChannels.free(((m_module.getModuleNumber() - 1)
|
||||
* kRelayChannels + m_channel - 1) * 2 + 1);
|
||||
* kRelayChannels + m_channel) * 2 + 1);
|
||||
m_module.freeDIO(((m_module.getModuleNumber() - 1) * kRelayChannels
|
||||
+ m_channel - 1) * 2 + 1);
|
||||
+ m_channel) * 2 + 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -172,7 +172,7 @@ public abstract class SensorBase { // TODO: Refactor
|
||||
* @param channel The channel number to check.
|
||||
*/
|
||||
protected static void checkDigitalChannel(final int channel) {
|
||||
if (channel <= 0 || channel > kDigitalChannels) {
|
||||
if (channel < 0 || channel >= kDigitalChannels) {
|
||||
System.err.println("Requested digital channel number is out of range.");
|
||||
}
|
||||
}
|
||||
@@ -185,7 +185,7 @@ public abstract class SensorBase { // TODO: Refactor
|
||||
* @param channel The channel number to check.
|
||||
*/
|
||||
protected static void checkRelayChannel(final int channel) {
|
||||
if (channel <= 0 || channel > kRelayChannels) {
|
||||
if (channel < 0 || channel >= kRelayChannels) {
|
||||
System.err.println("Requested relay channel number is out of range.");
|
||||
throw new IndexOutOfBoundsException("Requested relay channel number is out of range.");
|
||||
}
|
||||
@@ -199,7 +199,7 @@ public abstract class SensorBase { // TODO: Refactor
|
||||
* @param channel The channel number to check.
|
||||
*/
|
||||
protected static void checkPWMChannel(final int channel) {
|
||||
if (channel <= 0 || channel > kPwmChannels) {
|
||||
if (channel < 0 || channel >= kPwmChannels) {
|
||||
System.err.println("Requested PWM channel number is out of range.");
|
||||
throw new IndexOutOfBoundsException("Requested PWM channel number is out of range.");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user