Cleaned up wpilibj enums (#167)

* Converted enumerated constants in wpilibj to enums and made their implementation more consistent

* Reflowed text in JNI calls and updated JNI signatures
This commit is contained in:
Tyler Veness
2016-07-13 23:39:58 -07:00
committed by Peter Johnson
parent fe7165a8f7
commit 20c6525b1d
18 changed files with 120 additions and 385 deletions

View File

@@ -51,7 +51,7 @@ public class ADXL345_I2C extends SensorBase implements Accelerometer, LiveWindow
@SuppressWarnings("MemberName")
public final byte value;
Axes(byte value) {
private Axes(byte value) {
this.value = value;
}
}
@@ -92,7 +92,7 @@ public class ADXL345_I2C extends SensorBase implements Accelerometer, LiveWindow
setRange(range);
HAL.report(tResourceType.kResourceType_ADXL345, tInstances.kADXL345_I2C);
LiveWindow.addSensor("ADXL345_I2C", port.getValue(), this);
LiveWindow.addSensor("ADXL345_I2C", port.value, this);
}

View File

@@ -53,7 +53,7 @@ public class ADXL345_SPI extends SensorBase implements Accelerometer, LiveWindow
@SuppressWarnings("MemberName")
public final byte value;
Axes(byte value) {
private Axes(byte value) {
this.value = value;
}
}
@@ -77,7 +77,7 @@ public class ADXL345_SPI extends SensorBase implements Accelerometer, LiveWindow
public ADXL345_SPI(SPI.Port port, Range range) {
m_spi = new SPI(port);
init(range);
LiveWindow.addSensor("ADXL345_SPI", port.getValue(), this);
LiveWindow.addSensor("ADXL345_SPI", port.value, this);
}
public void free() {

View File

@@ -45,20 +45,16 @@ public class ADXL362 extends SensorBase implements Accelerometer, LiveWindowSend
kY((byte) 0x02),
kZ((byte) 0x04);
/**
* The integer value representing this enumeration.
*/
@SuppressWarnings("MemberName")
public final byte value;
Axes(byte value) {
private Axes(byte value) {
this.value = value;
}
}
@SuppressWarnings("MemberName")
public static class AllAxes {
public double XAxis;
public double YAxis;
public double ZAxis;
@@ -98,7 +94,7 @@ public class ADXL362 extends SensorBase implements Accelerometer, LiveWindowSend
if (transferBuffer.get(2) != (byte) 0xF2) {
m_spi.free();
m_spi = null;
DriverStation.reportError("could not find ADXL362 on SPI port " + port.getValue(), false);
DriverStation.reportError("could not find ADXL362 on SPI port " + port.value, false);
return;
}
@@ -110,8 +106,8 @@ public class ADXL362 extends SensorBase implements Accelerometer, LiveWindowSend
transferBuffer.put(2, (byte) (kPowerCtl_Measure | kPowerCtl_UltraLowNoise));
m_spi.write(transferBuffer, 3);
HAL.report(tResourceType.kResourceType_ADXL362, port.getValue());
LiveWindow.addSensor("ADXL362", port.getValue(), this);
HAL.report(tResourceType.kResourceType_ADXL362, port.value);
LiveWindow.addSensor("ADXL362", port.value, this);
}
public void free() {

View File

@@ -67,18 +67,18 @@ public class ADXRS450_Gyro extends GyroBase implements Gyro, PIDSource, LiveWind
if ((readRegister(kPIDRegister) & 0xff00) != 0x5200) {
m_spi.free();
m_spi = null;
DriverStation.reportError("could not find ADXRS450 gyro on SPI port " + port.getValue(),
DriverStation.reportError("could not find ADXRS450 gyro on SPI port " + port.value,
false);
return;
}
m_spi.initAccumulator(kSamplePeriod, 0x20000000, 4, 0x0c00000e, 0x04000000,
10, 16, true, true);
m_spi.initAccumulator(kSamplePeriod, 0x20000000, 4, 0x0c00000e, 0x04000000, 10, 16,
true, true);
calibrate();
HAL.report(tResourceType.kResourceType_ADXRS450, port.getValue());
LiveWindow.addSensor("ADXRS450_Gyro", port.getValue(), this);
HAL.report(tResourceType.kResourceType_ADXRS450, port.value);
LiveWindow.addSensor("ADXRS450_Gyro", port.value, this);
}
@Override

View File

@@ -43,7 +43,6 @@ public class AnalogTriggerOutput extends DigitalSource {
* Exceptions dealing with improper operation of the Analog trigger output.
*/
public class AnalogTriggerOutputException extends RuntimeException {
/**
* Create a new exception with the given message.
*
@@ -52,7 +51,6 @@ public class AnalogTriggerOutput extends DigitalSource {
public AnalogTriggerOutputException(String message) {
super(message);
}
}
private final AnalogTrigger m_trigger;
@@ -78,7 +76,7 @@ public class AnalogTriggerOutput extends DigitalSource {
m_outputType = outputType;
HAL.report(tResourceType.kResourceType_AnalogTriggerOutput,
trigger.getIndex(), outputType.m_value);
trigger.getIndex(), outputType.value);
}
/**
@@ -97,7 +95,7 @@ public class AnalogTriggerOutput extends DigitalSource {
* @return The state of the analog trigger output.
*/
public boolean get() {
return AnalogJNI.getAnalogTriggerOutput(m_trigger.m_port, m_outputType.m_value);
return AnalogJNI.getAnalogTriggerOutput(m_trigger.m_port, m_outputType.value);
}
@Override
@@ -107,7 +105,7 @@ public class AnalogTriggerOutput extends DigitalSource {
@Override
public int getAnalogTriggerTypeForRouting() {
return m_outputType.m_value;
return m_outputType.value;
}
@Override
@@ -128,10 +126,11 @@ public class AnalogTriggerOutput extends DigitalSource {
kRisingPulse(AnalogJNI.AnalogTriggerType.kRisingPulse),
kFallingPulse(AnalogJNI.AnalogTriggerType.kFallingPulse);
private final int m_value;
@SuppressWarnings("MemberName")
private final int value;
AnalogTriggerType(int value) {
m_value = value;
private AnalogTriggerType(int value) {
this.value = value;
}
}
}

View File

@@ -50,13 +50,10 @@ public class Counter extends SensorBase implements CounterBase, LiveWindowSendab
*/
kExternalDirection(3);
/**
* The integer value representing this enumeration.
*/
@SuppressWarnings("MemberName")
public final int value;
Mode(int value) {
private Mode(int value) {
this.value = value;
}
}

View File

@@ -34,13 +34,10 @@ public interface CounterBase {
*/
k4X(2);
/**
* The integer value representing this enumeration.
*/
@SuppressWarnings("MemberName")
public final int value;
EncodingType(int value) {
private EncodingType(int value) {
this.value = value;
}
}

View File

@@ -23,18 +23,15 @@ import edu.wpi.first.wpilibj.util.BoundaryException;
public class I2C extends SensorBase {
public enum Port {
kOnboard(0), kMXP(1);
private int m_value;
Port(int value) {
m_value = value;
}
@SuppressWarnings("MemberName")
public final int value;
public int getValue() {
return m_value;
private Port(int value) {
this.value = value;
}
}
private final Port m_port;
private final int m_deviceAddress;
@@ -48,7 +45,7 @@ public class I2C extends SensorBase {
m_port = port;
m_deviceAddress = deviceAddress;
I2CJNI.i2CInitialize((byte) port.getValue());
I2CJNI.i2CInitialize((byte) port.value);
HAL.report(tResourceType.kResourceType_I2C, deviceAddress);
}
@@ -81,10 +78,8 @@ public class I2C extends SensorBase {
}
ByteBuffer dataReceivedBuffer = ByteBuffer.allocateDirect(receiveSize);
status = I2CJNI
.i2CTransaction((byte) m_port.getValue(), (byte) m_deviceAddress,
dataToSendBuffer, (byte) sendSize, dataReceivedBuffer,
(byte) receiveSize);
status = I2CJNI.i2CTransaction((byte) m_port.value, (byte) m_deviceAddress, dataToSendBuffer,
(byte) sendSize, dataReceivedBuffer, (byte) receiveSize);
if (receiveSize > 0 && dataReceived != null) {
dataReceivedBuffer.get(dataReceived);
}
@@ -121,10 +116,8 @@ public class I2C extends SensorBase {
"dataReceived is too small, must be at least " + receiveSize);
}
return I2CJNI
.i2CTransaction((byte) m_port.getValue(), (byte) m_deviceAddress,
dataToSend, (byte) sendSize, dataReceived, (byte) receiveSize)
< receiveSize;
return I2CJNI.i2CTransaction((byte) m_port.value, (byte) m_deviceAddress, dataToSend,
(byte) sendSize, dataReceived, (byte) receiveSize) < receiveSize;
}
/**
@@ -155,8 +148,8 @@ public class I2C extends SensorBase {
ByteBuffer dataToSendBuffer = ByteBuffer.allocateDirect(2);
dataToSendBuffer.put(buffer);
return I2CJNI.i2CWrite((byte) m_port.getValue(), (byte) m_deviceAddress,
dataToSendBuffer, (byte) buffer.length) < buffer.length;
return I2CJNI.i2CWrite((byte) m_port.value, (byte) m_deviceAddress, dataToSendBuffer,
(byte) buffer.length) < buffer.length;
}
/**
@@ -170,8 +163,8 @@ public class I2C extends SensorBase {
ByteBuffer dataToSendBuffer = ByteBuffer.allocateDirect(data.length);
dataToSendBuffer.put(data);
return I2CJNI.i2CWrite((byte) m_port.getValue(), (byte) m_deviceAddress,
dataToSendBuffer, (byte) data.length) < data.length;
return I2CJNI.i2CWrite((byte) m_port.value, (byte) m_deviceAddress, dataToSendBuffer,
(byte) data.length) < data.length;
}
/**
@@ -190,8 +183,7 @@ public class I2C extends SensorBase {
"buffer is too small, must be at least " + size);
}
return I2CJNI.i2CWrite((byte) m_port.getValue(), (byte) m_deviceAddress,
data, (byte) size) < size;
return I2CJNI.i2CWrite((byte) m_port.value, (byte) m_deviceAddress, data, (byte) size) < size;
}
/**
@@ -269,9 +261,8 @@ public class I2C extends SensorBase {
ByteBuffer dataReceivedBuffer = ByteBuffer.allocateDirect(count);
int retVal = I2CJNI
.i2CRead((byte) m_port.getValue(), (byte) m_deviceAddress, dataReceivedBuffer,
(byte) count);
int retVal = I2CJNI.i2CRead((byte) m_port.value, (byte) m_deviceAddress, dataReceivedBuffer,
(byte) count);
dataReceivedBuffer.get(buffer);
return retVal < count;
}
@@ -299,8 +290,8 @@ public class I2C extends SensorBase {
throw new IllegalArgumentException("buffer is too small, must be at least " + count);
}
return I2CJNI
.i2CRead((byte) m_port.getValue(), (byte) m_deviceAddress, buffer, (byte) count) < count;
return I2CJNI.i2CRead((byte) m_port.value, (byte) m_deviceAddress, buffer, (byte) count)
< count;
}
/**

View File

@@ -23,18 +23,7 @@ public abstract class InterruptableSensorBase extends SensorBase {
@SuppressWarnings("MemberName")
public final int value;
@SuppressWarnings("JavadocMethod")
public static WaitResult valueOf(int value) {
for (WaitResult mode : values()) {
if (mode.value == value) {
return mode;
}
}
return null;
}
WaitResult(int value) {
private WaitResult(int value) {
this.value = value;
}
}
@@ -153,7 +142,12 @@ public abstract class InterruptableSensorBase extends SensorBase {
}
int result = InterruptJNI.waitForInterrupt(m_interrupt, timeout, ignorePrevious);
return WaitResult.valueOf(result);
for (WaitResult mode : WaitResult.values()) {
if (mode.value == result) {
return mode;
}
}
return null;
}
/**

View File

@@ -30,43 +30,11 @@ public class Joystick extends GenericHID {
/**
* Represents an analog axis on a joystick.
*/
public static final class AxisType {
public enum AxisType {
kX(0), kY(1), kZ(2), kTwist(3), kThrottle(4), kNumAxis(5);
/**
* The integer value representing this enumeration.
*/
@SuppressWarnings("MemberName")
public final int value;
static final int kX_val = 0;
static final int kY_val = 1;
static final int kZ_val = 2;
static final int kTwist_val = 3;
static final int kThrottle_val = 4;
static final int kNumAxis_val = 5;
/**
* axis: x-axis.
*/
public static final AxisType kX = new AxisType(kX_val);
/**
* axis: y-axis.
*/
public static final AxisType kY = new AxisType(kY_val);
/**
* axis: z-axis.
*/
public static final AxisType kZ = new AxisType(kZ_val);
/**
* axis: twist.
*/
public static final AxisType kTwist = new AxisType(kTwist_val);
/**
* axis: throttle.
*/
public static final AxisType kThrottle = new AxisType(kThrottle_val);
/**
* axis: number of axis.
*/
public static final AxisType kNumAxis = new AxisType(kNumAxis_val);
private AxisType(int value) {
this.value = value;
@@ -76,28 +44,11 @@ public class Joystick extends GenericHID {
/**
* Represents a digital button on the JoyStick.
*/
public static final class ButtonType {
public enum ButtonType {
kTrigger(0), kTop(1), kNumButton(2);
/**
* The integer value representing this enumeration.
*/
@SuppressWarnings("MemberName")
public final int value;
static final int kTrigger_val = 0;
static final int kTop_val = 1;
static final int kNumButton_val = 2;
/**
* button: trigger.
*/
public static final ButtonType kTrigger = new ButtonType((kTrigger_val));
/**
* button: top button.
*/
public static final ButtonType kTop = new ButtonType(kTop_val);
/**
* button: num button types.
*/
public static final ButtonType kNumButton = new ButtonType((kNumButton_val));
private ButtonType(int value) {
this.value = value;
@@ -108,27 +59,8 @@ public class Joystick extends GenericHID {
/**
* Represents a rumble output on the JoyStick.
*/
public static final class RumbleType {
/**
* The integer value representing this enumeration.
*/
@SuppressWarnings("MemberName")
public final int value;
static final int kLeftRumble_val = 0;
static final int kRightRumble_val = 1;
/**
* Left Rumble.
*/
public static final RumbleType kLeftRumble = new RumbleType((kLeftRumble_val));
/**
* Right Rumble.
*/
public static final RumbleType kRightRumble = new RumbleType(kRightRumble_val);
private RumbleType(int value) {
this.value = value;
}
public enum RumbleType {
kLeftRumble, kRightRumble
}
private final DriverStation m_ds;
@@ -250,16 +182,16 @@ public class Joystick extends GenericHID {
* @return The value of the axis.
*/
public double getAxis(final AxisType axis) {
switch (axis.value) {
case AxisType.kX_val:
switch (axis) {
case kX:
return getX();
case AxisType.kY_val:
case kY:
return getY();
case AxisType.kZ_val:
case kZ:
return getZ();
case AxisType.kTwist_val:
case kTwist:
return getTwist();
case AxisType.kThrottle_val:
case kThrottle:
return getThrottle();
default:
return 0.0;
@@ -359,10 +291,10 @@ public class Joystick extends GenericHID {
* @return The state of the button.
*/
public boolean getButton(ButtonType button) {
switch (button.value) {
case ButtonType.kTrigger_val:
switch (button) {
case kTrigger:
return getTrigger();
case ButtonType.kTop_val:
case kTop:
return getTop();
default:
return false;
@@ -468,7 +400,7 @@ public class Joystick extends GenericHID {
} else if (value > 1) {
value = 1;
}
if (type.value == RumbleType.kLeftRumble_val) {
if (type == RumbleType.kLeftRumble) {
m_leftRumble = (short) (value * 65535);
} else {
m_rightRumble = (short) (value * 65535);

View File

@@ -32,32 +32,19 @@ public class PWM extends SensorBase implements LiveWindowSendable {
/**
* Represents the amount to multiply the minimum servo-pulse pwm period by.
*/
public static class PeriodMultiplier {
/**
* The integer value representing this enumeration.
*/
@SuppressWarnings("MemberName")
public final int value;
static final int k1X_val = 1;
static final int k2X_val = 2;
static final int k4X_val = 4;
public enum PeriodMultiplier {
/**
* Period Multiplier: don't skip pulses.
*/
public static final PeriodMultiplier k1X = new PeriodMultiplier(k1X_val);
k1X,
/**
* Period Multiplier: skip every other pulse.
*/
public static final PeriodMultiplier k2X = new PeriodMultiplier(k2X_val);
k2X,
/**
* Period Multiplier: skip three out of four pulses.
*/
public static final PeriodMultiplier k4X = new PeriodMultiplier(k4X_val);
private PeriodMultiplier(int value) {
this.value = value;
}
k4X
}
private int m_channel;
@@ -252,16 +239,16 @@ public class PWM extends SensorBase implements LiveWindowSendable {
* @param mult The period multiplier to apply to this channel
*/
public void setPeriodMultiplier(PeriodMultiplier mult) {
switch (mult.value) {
case PeriodMultiplier.k4X_val:
switch (mult) {
case k4X:
// Squelch 3 out of 4 outputs
PWMJNI.setPWMPeriodScale(m_handle, 3);
break;
case PeriodMultiplier.k2X_val:
case k2X:
// Squelch 1 out of 2 outputs
PWMJNI.setPWMPeriodScale(m_handle, 1);
break;
case PeriodMultiplier.k1X_val:
case k1X:
// Don't squelch any outputs
PWMJNI.setPWMPeriodScale(m_handle, 0);
break;

View File

@@ -51,32 +51,7 @@ public class Relay extends SensorBase implements MotorSafety, LiveWindowSendable
* The state to drive a Relay to.
*/
public enum Value {
/**
* value: off.
*/
kOff(0),
/**
* value: on for relays with defined direction.
*/
kOn(1),
/**
* value: forward.
*/
kForward(2),
/**
* value: reverse.
*/
kReverse(3);
/**
* The integer value representing this enumeration.
*/
@SuppressWarnings("MemberName")
public final int value;
Value(int value) {
this.value = value;
}
kOff, kOn, kForward, kReverse
}
/**
@@ -87,26 +62,15 @@ public class Relay extends SensorBase implements MotorSafety, LiveWindowSendable
* direction: both directions are valid.
*/
kBoth(0),
kBoth,
/**
* direction: Only forward is valid.
*/
kForward(1),
kForward,
/**
* direction: only reverse is valid.
*/
kReverse(2);
/**
* The integer value representing this enumeration.
*/
@SuppressWarnings("MemberName")
public final int value;
Direction(int value) {
this.value = value;
}
kReverse
}
private final int m_channel;

View File

@@ -28,33 +28,11 @@ public class RobotDrive implements MotorSafety {
/**
* The location of a motor on the robot for the purpose of driving.
*/
public static class MotorType {
public enum MotorType {
kFrontLeft(0), kFrontRight(1), kRearLeft(2), kRearRight(3);
/**
* The integer value representing this enumeration.
*/
@SuppressWarnings("MemberName")
public final int value;
static final int kFrontLeft_val = 0;
static final int kFrontRight_val = 1;
static final int kRearLeft_val = 2;
static final int kRearRight_val = 3;
/**
* motortype: front left.
*/
public static final MotorType kFrontLeft = new MotorType(kFrontLeft_val);
/**
* motortype: front right.
*/
public static final MotorType kFrontRight = new MotorType(kFrontRight_val);
/**
* motortype: rear left.
*/
public static final MotorType kRearLeft = new MotorType(kRearLeft_val);
/**
* motortype: rear right.
*/
public static final MotorType kRearRight = new MotorType(kRearRight_val);
private MotorType(int value) {
this.value = value;
@@ -496,16 +474,16 @@ public class RobotDrive implements MotorSafety {
yIn = rotated[1];
double[] wheelSpeeds = new double[kMaxNumberOfMotors];
wheelSpeeds[MotorType.kFrontLeft_val] = xIn + yIn + rotation;
wheelSpeeds[MotorType.kFrontRight_val] = -xIn + yIn - rotation;
wheelSpeeds[MotorType.kRearLeft_val] = -xIn + yIn + rotation;
wheelSpeeds[MotorType.kRearRight_val] = xIn + yIn - rotation;
wheelSpeeds[MotorType.kFrontLeft.value] = xIn + yIn + rotation;
wheelSpeeds[MotorType.kFrontRight.value] = -xIn + yIn - rotation;
wheelSpeeds[MotorType.kRearLeft.value] = -xIn + yIn + rotation;
wheelSpeeds[MotorType.kRearRight.value] = xIn + yIn - rotation;
normalize(wheelSpeeds);
m_frontLeftMotor.set(wheelSpeeds[MotorType.kFrontLeft_val] * m_maxOutput);
m_frontRightMotor.set(wheelSpeeds[MotorType.kFrontRight_val] * m_maxOutput);
m_rearLeftMotor.set(wheelSpeeds[MotorType.kRearLeft_val] * m_maxOutput);
m_rearRightMotor.set(wheelSpeeds[MotorType.kRearRight_val] * m_maxOutput);
m_frontLeftMotor.set(wheelSpeeds[MotorType.kFrontLeft.value] * m_maxOutput);
m_frontRightMotor.set(wheelSpeeds[MotorType.kFrontRight.value] * m_maxOutput);
m_rearLeftMotor.set(wheelSpeeds[MotorType.kRearLeft.value] * m_maxOutput);
m_rearRightMotor.set(wheelSpeeds[MotorType.kRearRight.value] * m_maxOutput);
if (m_safetyHelper != null) {
m_safetyHelper.feed();
@@ -539,17 +517,17 @@ public class RobotDrive implements MotorSafety {
double sinD = Math.sin(dirInRad);
double[] wheelSpeeds = new double[kMaxNumberOfMotors];
wheelSpeeds[MotorType.kFrontLeft_val] = (sinD * magnitude + rotation);
wheelSpeeds[MotorType.kFrontRight_val] = (cosD * magnitude - rotation);
wheelSpeeds[MotorType.kRearLeft_val] = (cosD * magnitude + rotation);
wheelSpeeds[MotorType.kRearRight_val] = (sinD * magnitude - rotation);
wheelSpeeds[MotorType.kFrontLeft.value] = (sinD * magnitude + rotation);
wheelSpeeds[MotorType.kFrontRight.value] = (cosD * magnitude - rotation);
wheelSpeeds[MotorType.kRearLeft.value] = (cosD * magnitude + rotation);
wheelSpeeds[MotorType.kRearRight.value] = (sinD * magnitude - rotation);
normalize(wheelSpeeds);
m_frontLeftMotor.set(wheelSpeeds[MotorType.kFrontLeft_val] * m_maxOutput);
m_frontRightMotor.set(wheelSpeeds[MotorType.kFrontRight_val] * m_maxOutput);
m_rearLeftMotor.set(wheelSpeeds[MotorType.kRearLeft_val] * m_maxOutput);
m_rearRightMotor.set(wheelSpeeds[MotorType.kRearRight_val] * m_maxOutput);
m_frontLeftMotor.set(wheelSpeeds[MotorType.kFrontLeft.value] * m_maxOutput);
m_frontRightMotor.set(wheelSpeeds[MotorType.kFrontRight.value] * m_maxOutput);
m_rearLeftMotor.set(wheelSpeeds[MotorType.kRearLeft.value] * m_maxOutput);
m_rearRightMotor.set(wheelSpeeds[MotorType.kRearRight.value] * m_maxOutput);
if (m_safetyHelper != null) {
m_safetyHelper.feed();
@@ -652,17 +630,17 @@ public class RobotDrive implements MotorSafety {
* @param isInverted True if the motor should be inverted when operated.
*/
public void setInvertedMotor(MotorType motor, boolean isInverted) {
switch (motor.value) {
case MotorType.kFrontLeft_val:
switch (motor) {
case kFrontLeft:
m_frontLeftMotor.setInverted(isInverted);
break;
case MotorType.kFrontRight_val:
case kFrontRight:
m_frontRightMotor.setInverted(isInverted);
break;
case MotorType.kRearLeft_val:
case kRearLeft:
m_rearLeftMotor.setInverted(isInverted);
break;
case MotorType.kRearRight_val:
case kRearRight:
m_rearRightMotor.setInverted(isInverted);
break;
default:

View File

@@ -22,14 +22,11 @@ public class SPI extends SensorBase {
public enum Port {
kOnboardCS0(0), kOnboardCS1(1), kOnboardCS2(2), kOnboardCS3(3), kMXP(4);
private int m_value;
@SuppressWarnings("MemberName")
public int value;
Port(int value) {
m_value = value;
}
public int getValue() {
return m_value;
private Port(int value) {
this.value = value;
}
}
@@ -46,7 +43,7 @@ public class SPI extends SensorBase {
* @param port the physical SPI port
*/
public SPI(Port port) {
m_port = (byte) port.getValue();
m_port = (byte) port.value;
devices++;
SPIJNI.spiInitialize(m_port);

View File

@@ -32,52 +32,22 @@ public class SerialPort {
public enum Port {
kOnboard(0), kMXP(1), kUSB(2);
private int m_value;
@SuppressWarnings("MemberName")
public int value;
Port(int value) {
m_value = value;
}
public int getValue() {
return m_value;
private Port(int value) {
this.value = value;
}
}
/**
* Represents the parity to use for serial communications.
*/
public static class Parity {
public enum Parity {
kNone(0), kOdd(1), kEven(2), kMark(3), kSpace(4);
/**
* The integer value representing this enumeration.
*/
@SuppressWarnings("MemberName")
public final int value;
static final int kNone_val = 0;
static final int kOdd_val = 1;
static final int kEven_val = 2;
static final int kMark_val = 3;
static final int kSpace_val = 4;
/**
* parity: Use no parity.
*/
public static final Parity kNone = new Parity(kNone_val);
/**
* parity: Use odd parity.
*/
public static final Parity kOdd = new Parity(kOdd_val);
/**
* parity: Use even parity.
*/
public static final Parity kEven = new Parity(kEven_val);
/**
* parity: Use mark parity.
*/
public static final Parity kMark = new Parity(kMark_val);
/**
* parity: Use space parity.
*/
public static final Parity kSpace = new Parity((kSpace_val));
private Parity(int value) {
this.value = value;
@@ -87,28 +57,11 @@ public class SerialPort {
/**
* Represents the number of stop bits to use for Serial Communication.
*/
public static class StopBits {
public enum StopBits {
kOne(0), kOnePointFive(1), kTwo(2);
/**
* The integer value representing this enumeration.
*/
@SuppressWarnings("MemberName")
public final int value;
static final int kOne_val = 10;
static final int kOnePointFive_val = 15;
static final int kTwo_val = 20;
/**
* stopBits: use 1.
*/
public static final StopBits kOne = new StopBits(kOne_val);
/**
* stopBits: use 1.5.
*/
public static final StopBits kOnePointFive = new StopBits(kOnePointFive_val);
/**
* stopBits: use 2.
*/
public static final StopBits kTwo = new StopBits(kTwo_val);
private StopBits(int value) {
this.value = value;
@@ -118,33 +71,11 @@ public class SerialPort {
/**
* Represents what type of flow control to use for serial communication.
*/
public static class FlowControl {
public enum FlowControl {
kNone(0), kXonXoff(1), kRtsCts(2), kDtsDsr(3);
/**
* The integer value representing this enumeration.
*/
@SuppressWarnings("MemberName")
public final int value;
static final int kNone_val = 0;
static final int kXonXoff_val = 1;
static final int kRtsCts_val = 2;
static final int kDtrDsr_val = 4;
/**
* flowControl: use none.
*/
public static final FlowControl kNone = new FlowControl(kNone_val);
/**
* flowcontrol: use on/off.
*/
public static final FlowControl kXonXoff = new FlowControl(kXonXoff_val);
/**
* flowcontrol: use rts cts.
*/
public static final FlowControl kRtsCts = new FlowControl(kRtsCts_val);
/**
* flowcontrol: use dts dsr.
*/
public static final FlowControl kDtrDsr = new FlowControl(kDtrDsr_val);
private FlowControl(int value) {
this.value = value;
@@ -154,23 +85,11 @@ public class SerialPort {
/**
* Represents which type of buffer mode to use when writing to a serial m_port.
*/
public static class WriteBufferMode {
public enum WriteBufferMode {
kFlushOnAccess(0), kFlushWhenFull(1);
/**
* The integer value representing this enumeration.
*/
@SuppressWarnings("MemberName")
public final int value;
static final int kFlushOnAccess_val = 1;
static final int kFlushWhenFull_val = 2;
/**
* Flush on access.
*/
public static final WriteBufferMode kFlushOnAccess = new WriteBufferMode(kFlushOnAccess_val);
/**
* Flush when full.
*/
public static final WriteBufferMode kFlushWhenFull = new WriteBufferMode(kFlushWhenFull_val);
private WriteBufferMode(int value) {
this.value = value;
@@ -188,7 +107,7 @@ public class SerialPort {
*/
public SerialPort(final int baudRate, Port port, final int dataBits, Parity parity,
StopBits stopBits) {
m_port = (byte) port.getValue();
m_port = (byte) port.value;
SerialPortJNI.serialInitializePort(m_port);
SerialPortJNI.serialSetBaudRate(m_port, baudRate);