mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-23 01:21:42 +00:00
Use Java 17 features (#6691)
Uses enhanced instanceof (and simplify equals methods) Uses switch expressions and arrow labels Seal and finalize some Shuffleboard classes Co-authored-by: Sam Carlberg <sam@slfc.dev>
This commit is contained in:
@@ -1057,16 +1057,11 @@ public class ADIS16448_IMU implements AutoCloseable, Sendable {
|
||||
* @return Yaw axis angle in degrees (CCW positive).
|
||||
*/
|
||||
public synchronized double getAngle() {
|
||||
switch (m_yaw_axis) {
|
||||
case kX:
|
||||
return getGyroAngleX();
|
||||
case kY:
|
||||
return getGyroAngleY();
|
||||
case kZ:
|
||||
return getGyroAngleZ();
|
||||
default:
|
||||
return 0.0;
|
||||
}
|
||||
return switch (m_yaw_axis) {
|
||||
case kX -> getGyroAngleX();
|
||||
case kY -> getGyroAngleY();
|
||||
case kZ -> getGyroAngleZ();
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1075,16 +1070,11 @@ public class ADIS16448_IMU implements AutoCloseable, Sendable {
|
||||
* @return Yaw axis angular rate in degrees per second (CCW positive).
|
||||
*/
|
||||
public synchronized double getRate() {
|
||||
switch (m_yaw_axis) {
|
||||
case kX:
|
||||
return getGyroRateX();
|
||||
case kY:
|
||||
return getGyroRateY();
|
||||
case kZ:
|
||||
return getGyroRateZ();
|
||||
default:
|
||||
return 0.0;
|
||||
}
|
||||
return switch (m_yaw_axis) {
|
||||
case kX -> getGyroRateX();
|
||||
case kY -> getGyroRateY();
|
||||
case kZ -> getGyroRateZ();
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1061,30 +1061,21 @@ public class ADIS16470_IMU implements AutoCloseable, Sendable {
|
||||
* @param angle A double in degrees (CCW positive)
|
||||
*/
|
||||
public void setGyroAngle(IMUAxis axis, double angle) {
|
||||
switch (axis) {
|
||||
case kYaw:
|
||||
axis = m_yaw_axis;
|
||||
break;
|
||||
case kPitch:
|
||||
axis = m_pitch_axis;
|
||||
break;
|
||||
case kRoll:
|
||||
axis = m_roll_axis;
|
||||
break;
|
||||
default:
|
||||
}
|
||||
axis =
|
||||
switch (axis) {
|
||||
case kYaw -> m_yaw_axis;
|
||||
case kPitch -> m_pitch_axis;
|
||||
case kRoll -> m_roll_axis;
|
||||
default -> axis;
|
||||
};
|
||||
|
||||
switch (axis) {
|
||||
case kX:
|
||||
this.setGyroAngleX(angle);
|
||||
break;
|
||||
case kY:
|
||||
this.setGyroAngleY(angle);
|
||||
break;
|
||||
case kZ:
|
||||
this.setGyroAngleZ(angle);
|
||||
break;
|
||||
default:
|
||||
case kX -> setGyroAngleX(angle);
|
||||
case kY -> setGyroAngleY(angle);
|
||||
case kZ -> setGyroAngleZ(angle);
|
||||
default -> {
|
||||
// NOP
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1131,39 +1122,35 @@ public class ADIS16470_IMU implements AutoCloseable, Sendable {
|
||||
* @return The axis angle in degrees (CCW positive).
|
||||
*/
|
||||
public synchronized double getAngle(IMUAxis axis) {
|
||||
switch (axis) {
|
||||
case kYaw:
|
||||
axis = m_yaw_axis;
|
||||
break;
|
||||
case kPitch:
|
||||
axis = m_pitch_axis;
|
||||
break;
|
||||
case kRoll:
|
||||
axis = m_roll_axis;
|
||||
break;
|
||||
default:
|
||||
}
|
||||
axis =
|
||||
switch (axis) {
|
||||
case kYaw -> m_yaw_axis;
|
||||
case kPitch -> m_pitch_axis;
|
||||
case kRoll -> m_roll_axis;
|
||||
default -> axis;
|
||||
};
|
||||
|
||||
switch (axis) {
|
||||
case kX:
|
||||
return switch (axis) {
|
||||
case kX -> {
|
||||
if (m_simGyroAngleX != null) {
|
||||
return m_simGyroAngleX.get();
|
||||
yield m_simGyroAngleX.get();
|
||||
}
|
||||
return m_integ_angle_x;
|
||||
case kY:
|
||||
yield m_integ_angle_x;
|
||||
}
|
||||
case kY -> {
|
||||
if (m_simGyroAngleY != null) {
|
||||
return m_simGyroAngleY.get();
|
||||
yield m_simGyroAngleY.get();
|
||||
}
|
||||
return m_integ_angle_y;
|
||||
case kZ:
|
||||
yield m_integ_angle_y;
|
||||
}
|
||||
case kZ -> {
|
||||
if (m_simGyroAngleZ != null) {
|
||||
return m_simGyroAngleZ.get();
|
||||
yield m_simGyroAngleZ.get();
|
||||
}
|
||||
return m_integ_angle_z;
|
||||
default:
|
||||
}
|
||||
|
||||
return 0.0;
|
||||
yield m_integ_angle_z;
|
||||
}
|
||||
default -> 0.0;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1172,25 +1159,27 @@ public class ADIS16470_IMU implements AutoCloseable, Sendable {
|
||||
* @return The Yaw axis angle in degrees (CCW positive).
|
||||
*/
|
||||
public synchronized double getAngle() {
|
||||
switch (m_yaw_axis) {
|
||||
case kX:
|
||||
return switch (m_yaw_axis) {
|
||||
case kX -> {
|
||||
if (m_simGyroAngleX != null) {
|
||||
return m_simGyroAngleX.get();
|
||||
yield m_simGyroAngleX.get();
|
||||
}
|
||||
return m_integ_angle_x;
|
||||
case kY:
|
||||
yield m_integ_angle_x;
|
||||
}
|
||||
case kY -> {
|
||||
if (m_simGyroAngleY != null) {
|
||||
return m_simGyroAngleY.get();
|
||||
yield m_simGyroAngleY.get();
|
||||
}
|
||||
return m_integ_angle_y;
|
||||
case kZ:
|
||||
yield m_integ_angle_y;
|
||||
}
|
||||
case kZ -> {
|
||||
if (m_simGyroAngleZ != null) {
|
||||
return m_simGyroAngleZ.get();
|
||||
yield m_simGyroAngleZ.get();
|
||||
}
|
||||
return m_integ_angle_z;
|
||||
default:
|
||||
}
|
||||
return 0.0;
|
||||
yield m_integ_angle_z;
|
||||
}
|
||||
default -> 0.0;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1200,38 +1189,35 @@ public class ADIS16470_IMU implements AutoCloseable, Sendable {
|
||||
* @return Axis angular rate in degrees per second (CCW positive).
|
||||
*/
|
||||
public synchronized double getRate(IMUAxis axis) {
|
||||
switch (axis) {
|
||||
case kYaw:
|
||||
axis = m_yaw_axis;
|
||||
break;
|
||||
case kPitch:
|
||||
axis = m_pitch_axis;
|
||||
break;
|
||||
case kRoll:
|
||||
axis = m_roll_axis;
|
||||
break;
|
||||
default:
|
||||
}
|
||||
axis =
|
||||
switch (axis) {
|
||||
case kYaw -> m_yaw_axis;
|
||||
case kPitch -> m_pitch_axis;
|
||||
case kRoll -> m_roll_axis;
|
||||
default -> axis;
|
||||
};
|
||||
|
||||
switch (axis) {
|
||||
case kX:
|
||||
return switch (axis) {
|
||||
case kX -> {
|
||||
if (m_simGyroRateX != null) {
|
||||
return m_simGyroRateX.get();
|
||||
yield m_simGyroRateX.get();
|
||||
}
|
||||
return m_gyro_rate_x;
|
||||
case kY:
|
||||
yield m_gyro_rate_x;
|
||||
}
|
||||
case kY -> {
|
||||
if (m_simGyroRateY != null) {
|
||||
return m_simGyroRateY.get();
|
||||
yield m_simGyroRateY.get();
|
||||
}
|
||||
return m_gyro_rate_y;
|
||||
case kZ:
|
||||
yield m_gyro_rate_y;
|
||||
}
|
||||
case kZ -> {
|
||||
if (m_simGyroRateZ != null) {
|
||||
return m_simGyroRateZ.get();
|
||||
yield m_simGyroRateZ.get();
|
||||
}
|
||||
return m_gyro_rate_z;
|
||||
default:
|
||||
}
|
||||
return 0.0;
|
||||
yield m_gyro_rate_z;
|
||||
}
|
||||
default -> 0.0;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1240,25 +1226,27 @@ public class ADIS16470_IMU implements AutoCloseable, Sendable {
|
||||
* @return Yaw axis angular rate in degrees per second (CCW positive).
|
||||
*/
|
||||
public synchronized double getRate() {
|
||||
switch (m_yaw_axis) {
|
||||
case kX:
|
||||
return switch (m_yaw_axis) {
|
||||
case kX -> {
|
||||
if (m_simGyroRateX != null) {
|
||||
return m_simGyroRateX.get();
|
||||
yield m_simGyroRateX.get();
|
||||
}
|
||||
return m_gyro_rate_x;
|
||||
case kY:
|
||||
yield m_gyro_rate_x;
|
||||
}
|
||||
case kY -> {
|
||||
if (m_simGyroRateY != null) {
|
||||
return m_simGyroRateY.get();
|
||||
yield m_simGyroRateY.get();
|
||||
}
|
||||
return m_gyro_rate_y;
|
||||
case kZ:
|
||||
yield m_gyro_rate_y;
|
||||
}
|
||||
case kZ -> {
|
||||
if (m_simGyroRateZ != null) {
|
||||
return m_simGyroRateZ.get();
|
||||
yield m_simGyroRateZ.get();
|
||||
}
|
||||
return m_gyro_rate_z;
|
||||
default:
|
||||
}
|
||||
return 0.0;
|
||||
yield m_gyro_rate_z;
|
||||
}
|
||||
default -> 0.0;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -182,23 +182,13 @@ public class ADXL345_I2C implements NTSendable, AutoCloseable {
|
||||
* measure.
|
||||
*/
|
||||
public final void setRange(Range range) {
|
||||
final byte value;
|
||||
switch (range) {
|
||||
case k2G:
|
||||
value = 0;
|
||||
break;
|
||||
case k4G:
|
||||
value = 1;
|
||||
break;
|
||||
case k8G:
|
||||
value = 2;
|
||||
break;
|
||||
case k16G:
|
||||
value = 3;
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("Missing case for range type " + range);
|
||||
}
|
||||
final byte value =
|
||||
switch (range) {
|
||||
case k2G -> 0;
|
||||
case k4G -> 1;
|
||||
case k8G -> 2;
|
||||
case k16G -> 3;
|
||||
};
|
||||
|
||||
// Specify the data format to read
|
||||
m_i2c.write(kDataFormatRegister, kDataFormat_FullRes | value);
|
||||
|
||||
@@ -171,23 +171,13 @@ public class ADXL345_SPI implements NTSendable, AutoCloseable {
|
||||
* measure.
|
||||
*/
|
||||
public void setRange(Range range) {
|
||||
final byte value;
|
||||
switch (range) {
|
||||
case k2G:
|
||||
value = 0;
|
||||
break;
|
||||
case k4G:
|
||||
value = 1;
|
||||
break;
|
||||
case k8G:
|
||||
value = 2;
|
||||
break;
|
||||
case k16G:
|
||||
value = 3;
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("Missing case for range type " + range);
|
||||
}
|
||||
final byte value =
|
||||
switch (range) {
|
||||
case k2G -> 0;
|
||||
case k4G -> 1;
|
||||
case k8G -> 2;
|
||||
case k16G -> 3;
|
||||
};
|
||||
|
||||
// Specify the data format to read
|
||||
byte[] commands = new byte[] {kDataFormatRegister, (byte) (kDataFormat_FullRes | value)};
|
||||
|
||||
@@ -193,23 +193,21 @@ public class ADXL362 implements NTSendable, AutoCloseable {
|
||||
return;
|
||||
}
|
||||
|
||||
final byte value;
|
||||
switch (range) {
|
||||
case k2G:
|
||||
value = kFilterCtl_Range2G;
|
||||
m_gsPerLSB = 0.001;
|
||||
break;
|
||||
case k4G:
|
||||
value = kFilterCtl_Range4G;
|
||||
m_gsPerLSB = 0.002;
|
||||
break;
|
||||
case k8G:
|
||||
value = kFilterCtl_Range8G;
|
||||
m_gsPerLSB = 0.004;
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("Missing case for range type " + range);
|
||||
}
|
||||
final byte value =
|
||||
switch (range) {
|
||||
case k2G -> {
|
||||
m_gsPerLSB = 0.001;
|
||||
yield kFilterCtl_Range2G;
|
||||
}
|
||||
case k4G -> {
|
||||
m_gsPerLSB = 0.002;
|
||||
yield kFilterCtl_Range4G;
|
||||
}
|
||||
case k8G -> {
|
||||
m_gsPerLSB = 0.004;
|
||||
yield kFilterCtl_Range8G;
|
||||
}
|
||||
};
|
||||
|
||||
// Specify the data format to read
|
||||
byte[] commands =
|
||||
|
||||
@@ -74,24 +74,12 @@ public class AddressableLEDBuffer {
|
||||
final int X = (chroma * remainder) >> 8;
|
||||
|
||||
switch (region) {
|
||||
case 0:
|
||||
setRGB(index, v, X + m, m);
|
||||
break;
|
||||
case 1:
|
||||
setRGB(index, v - X, v, m);
|
||||
break;
|
||||
case 2:
|
||||
setRGB(index, m, v, X + m);
|
||||
break;
|
||||
case 3:
|
||||
setRGB(index, m, v - X, v);
|
||||
break;
|
||||
case 4:
|
||||
setRGB(index, X + m, m, v);
|
||||
break;
|
||||
default:
|
||||
setRGB(index, v, m, v - X);
|
||||
break;
|
||||
case 0 -> setRGB(index, v, X + m, m);
|
||||
case 1 -> setRGB(index, v - X, v, m);
|
||||
case 2 -> setRGB(index, m, v, X + m);
|
||||
case 3 -> setRGB(index, m, v - X, v);
|
||||
case 4 -> setRGB(index, X + m, m, v);
|
||||
default -> setRGB(index, v, m, v - X);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ package edu.wpi.first.wpilibj;
|
||||
|
||||
import static edu.wpi.first.util.ErrorMessages.requireNonNullParam;
|
||||
|
||||
import edu.wpi.first.wpilibj.SynchronousInterrupt.WaitResult;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
@@ -132,25 +131,22 @@ public class AsynchronousInterrupt implements AutoCloseable {
|
||||
if (!m_keepRunning.get()) {
|
||||
break;
|
||||
}
|
||||
if (result == WaitResult.kTimeout) {
|
||||
continue;
|
||||
}
|
||||
|
||||
boolean rising = false;
|
||||
boolean falling = false;
|
||||
switch (result) {
|
||||
case kBoth:
|
||||
case kBoth -> {
|
||||
rising = true;
|
||||
falling = true;
|
||||
break;
|
||||
case kFallingEdge:
|
||||
}
|
||||
case kFallingEdge -> {
|
||||
falling = true;
|
||||
break;
|
||||
case kRisingEdge:
|
||||
}
|
||||
case kRisingEdge -> {
|
||||
rising = true;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
default -> {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
m_callback.accept(rising, falling);
|
||||
|
||||
@@ -58,20 +58,14 @@ public class BuiltInAccelerometer implements Sendable, AutoCloseable {
|
||||
public final void setRange(Range range) {
|
||||
AccelerometerJNI.setAccelerometerActive(false);
|
||||
|
||||
switch (range) {
|
||||
case k2G:
|
||||
AccelerometerJNI.setAccelerometerRange(0);
|
||||
break;
|
||||
case k4G:
|
||||
AccelerometerJNI.setAccelerometerRange(1);
|
||||
break;
|
||||
case k8G:
|
||||
AccelerometerJNI.setAccelerometerRange(2);
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("Missing case for range type " + range);
|
||||
}
|
||||
int rangeValue =
|
||||
switch (range) {
|
||||
case k2G -> 0;
|
||||
case k4G -> 1;
|
||||
case k8G -> 2;
|
||||
};
|
||||
|
||||
AccelerometerJNI.setAccelerometerRange(rangeValue);
|
||||
AccelerometerJNI.setAccelerometerActive(true);
|
||||
}
|
||||
|
||||
|
||||
@@ -31,16 +31,12 @@ public enum CompressorConfigType {
|
||||
* @return type
|
||||
*/
|
||||
public static CompressorConfigType fromValue(int value) {
|
||||
switch (value) {
|
||||
case REVPHJNI.COMPRESSOR_CONFIG_TYPE_HYBRID:
|
||||
return Hybrid;
|
||||
case REVPHJNI.COMPRESSOR_CONFIG_TYPE_ANALOG:
|
||||
return Analog;
|
||||
case REVPHJNI.COMPRESSOR_CONFIG_TYPE_DIGITAL:
|
||||
return Digital;
|
||||
default:
|
||||
return Disabled;
|
||||
}
|
||||
return switch (value) {
|
||||
case REVPHJNI.COMPRESSOR_CONFIG_TYPE_HYBRID -> Hybrid;
|
||||
case REVPHJNI.COMPRESSOR_CONFIG_TYPE_ANALOG -> Analog;
|
||||
case REVPHJNI.COMPRESSOR_CONFIG_TYPE_DIGITAL -> Digital;
|
||||
default -> Disabled;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -382,21 +382,13 @@ public final class DataLogManager {
|
||||
DriverStation.MatchType matchType = DriverStation.getMatchType();
|
||||
if (matchType != DriverStation.MatchType.None) {
|
||||
// rename per match info
|
||||
char matchTypeChar;
|
||||
switch (matchType) {
|
||||
case Practice:
|
||||
matchTypeChar = 'P';
|
||||
break;
|
||||
case Qualification:
|
||||
matchTypeChar = 'Q';
|
||||
break;
|
||||
case Elimination:
|
||||
matchTypeChar = 'E';
|
||||
break;
|
||||
default:
|
||||
matchTypeChar = '_';
|
||||
break;
|
||||
}
|
||||
char matchTypeChar =
|
||||
switch (matchType) {
|
||||
case Practice -> 'P';
|
||||
case Qualification -> 'Q';
|
||||
case Elimination -> 'E';
|
||||
default -> '_';
|
||||
};
|
||||
m_log.setFilename(
|
||||
"FRC_"
|
||||
+ m_timeFormatter.format(LocalDateTime.now(m_utc))
|
||||
|
||||
@@ -125,21 +125,12 @@ public class DoubleSolenoid implements Sendable, AutoCloseable {
|
||||
* @param value The value to set (Off, Forward, Reverse)
|
||||
*/
|
||||
public void set(final Value value) {
|
||||
int setValue;
|
||||
|
||||
switch (value) {
|
||||
case kOff:
|
||||
setValue = 0;
|
||||
break;
|
||||
case kForward:
|
||||
setValue = m_forwardMask;
|
||||
break;
|
||||
case kReverse:
|
||||
setValue = m_reverseMask;
|
||||
break;
|
||||
default:
|
||||
throw new AssertionError("Illegal value: " + value);
|
||||
}
|
||||
int setValue =
|
||||
switch (value) {
|
||||
case kOff -> 0;
|
||||
case kForward -> m_forwardMask;
|
||||
case kReverse -> m_reverseMask;
|
||||
};
|
||||
|
||||
m_module.setSolenoids(m_mask, setValue);
|
||||
}
|
||||
|
||||
@@ -137,34 +137,17 @@ public final class DriverStation {
|
||||
|
||||
private void sendMatchData() {
|
||||
AllianceStationID allianceID = DriverStationJNI.getAllianceStation();
|
||||
boolean isRedAlliance = false;
|
||||
int stationNumber = 1;
|
||||
switch (allianceID) {
|
||||
case Blue1:
|
||||
isRedAlliance = false;
|
||||
stationNumber = 1;
|
||||
break;
|
||||
case Blue2:
|
||||
isRedAlliance = false;
|
||||
stationNumber = 2;
|
||||
break;
|
||||
case Blue3:
|
||||
isRedAlliance = false;
|
||||
stationNumber = 3;
|
||||
break;
|
||||
case Red1:
|
||||
isRedAlliance = true;
|
||||
stationNumber = 1;
|
||||
break;
|
||||
case Red2:
|
||||
isRedAlliance = true;
|
||||
stationNumber = 2;
|
||||
break;
|
||||
default:
|
||||
isRedAlliance = true;
|
||||
stationNumber = 3;
|
||||
break;
|
||||
}
|
||||
final int stationNumber =
|
||||
switch (allianceID) {
|
||||
case Blue1, Red1 -> 1;
|
||||
case Blue2, Red2 -> 2;
|
||||
case Blue3, Red3, Unknown -> 3;
|
||||
};
|
||||
final boolean isRedAlliance =
|
||||
switch (allianceID) {
|
||||
case Blue1, Blue2, Blue3 -> false;
|
||||
case Red1, Red2, Red3, Unknown -> true;
|
||||
};
|
||||
|
||||
String currentEventName;
|
||||
String currentGameSpecificMessage;
|
||||
@@ -1059,16 +1042,12 @@ public final class DriverStation {
|
||||
} finally {
|
||||
m_cacheDataMutex.unlock();
|
||||
}
|
||||
switch (matchType) {
|
||||
case 1:
|
||||
return MatchType.Practice;
|
||||
case 2:
|
||||
return MatchType.Qualification;
|
||||
case 3:
|
||||
return MatchType.Elimination;
|
||||
default:
|
||||
return MatchType.None;
|
||||
}
|
||||
return switch (matchType) {
|
||||
case 1 -> MatchType.Practice;
|
||||
case 2 -> MatchType.Qualification;
|
||||
case 3 -> MatchType.Elimination;
|
||||
default -> MatchType.None;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -562,16 +562,11 @@ public class Encoder implements CounterBase, Sendable, AutoCloseable {
|
||||
* @return decoding scale factor
|
||||
*/
|
||||
public double getDecodingScaleFactor() {
|
||||
switch (m_encodingType) {
|
||||
case k1X:
|
||||
return 1.0;
|
||||
case k2X:
|
||||
return 0.5;
|
||||
case k4X:
|
||||
return 0.25;
|
||||
default:
|
||||
return 0.0;
|
||||
}
|
||||
return switch (m_encodingType) {
|
||||
case k1X -> 1.0;
|
||||
case k2X -> 0.5;
|
||||
case k4X -> 0.25;
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -457,17 +457,12 @@ public class GenericHID {
|
||||
value = MathUtil.clamp(value, 0, 1);
|
||||
int rumbleValue = (int) (value * 65535);
|
||||
switch (type) {
|
||||
case kLeftRumble:
|
||||
this.m_leftRumble = rumbleValue;
|
||||
break;
|
||||
case kRightRumble:
|
||||
this.m_rightRumble = rumbleValue;
|
||||
break;
|
||||
case kBothRumble:
|
||||
default:
|
||||
case kLeftRumble -> this.m_leftRumble = rumbleValue;
|
||||
case kRightRumble -> this.m_rightRumble = rumbleValue;
|
||||
default -> {
|
||||
this.m_leftRumble = rumbleValue;
|
||||
this.m_rightRumble = rumbleValue;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
DriverStationJNI.setJoystickOutputs(
|
||||
|
||||
@@ -323,59 +323,77 @@ public abstract class IterativeRobotBase extends RobotBase {
|
||||
// If mode changed, call mode exit and entry functions
|
||||
if (m_lastMode != mode) {
|
||||
// Call last mode's exit function
|
||||
if (m_lastMode == Mode.kDisabled) {
|
||||
disabledExit();
|
||||
} else if (m_lastMode == Mode.kAutonomous) {
|
||||
autonomousExit();
|
||||
} else if (m_lastMode == Mode.kTeleop) {
|
||||
teleopExit();
|
||||
} else if (m_lastMode == Mode.kTest) {
|
||||
if (m_lwEnabledInTest) {
|
||||
LiveWindow.setEnabled(false);
|
||||
Shuffleboard.disableActuatorWidgets();
|
||||
switch (m_lastMode) {
|
||||
case kDisabled -> disabledExit();
|
||||
case kAutonomous -> autonomousExit();
|
||||
case kTeleop -> teleopExit();
|
||||
case kTest -> {
|
||||
if (m_lwEnabledInTest) {
|
||||
LiveWindow.setEnabled(false);
|
||||
Shuffleboard.disableActuatorWidgets();
|
||||
}
|
||||
testExit();
|
||||
}
|
||||
default -> {
|
||||
// NOP
|
||||
}
|
||||
testExit();
|
||||
}
|
||||
|
||||
// Call current mode's entry function
|
||||
if (mode == Mode.kDisabled) {
|
||||
disabledInit();
|
||||
m_watchdog.addEpoch("disabledInit()");
|
||||
} else if (mode == Mode.kAutonomous) {
|
||||
autonomousInit();
|
||||
m_watchdog.addEpoch("autonomousInit()");
|
||||
} else if (mode == Mode.kTeleop) {
|
||||
teleopInit();
|
||||
m_watchdog.addEpoch("teleopInit()");
|
||||
} else if (mode == Mode.kTest) {
|
||||
if (m_lwEnabledInTest) {
|
||||
LiveWindow.setEnabled(true);
|
||||
Shuffleboard.enableActuatorWidgets();
|
||||
switch (mode) {
|
||||
case kDisabled -> {
|
||||
disabledInit();
|
||||
m_watchdog.addEpoch("disabledInit()");
|
||||
}
|
||||
case kAutonomous -> {
|
||||
autonomousInit();
|
||||
m_watchdog.addEpoch("autonomousInit()");
|
||||
}
|
||||
case kTeleop -> {
|
||||
teleopInit();
|
||||
m_watchdog.addEpoch("teleopInit()");
|
||||
}
|
||||
case kTest -> {
|
||||
if (m_lwEnabledInTest) {
|
||||
LiveWindow.setEnabled(true);
|
||||
Shuffleboard.enableActuatorWidgets();
|
||||
}
|
||||
testInit();
|
||||
m_watchdog.addEpoch("testInit()");
|
||||
}
|
||||
default -> {
|
||||
// NOP
|
||||
}
|
||||
testInit();
|
||||
m_watchdog.addEpoch("testInit()");
|
||||
}
|
||||
|
||||
m_lastMode = mode;
|
||||
}
|
||||
|
||||
// Call the appropriate function depending upon the current robot mode
|
||||
if (mode == Mode.kDisabled) {
|
||||
DriverStationJNI.observeUserProgramDisabled();
|
||||
disabledPeriodic();
|
||||
m_watchdog.addEpoch("disabledPeriodic()");
|
||||
} else if (mode == Mode.kAutonomous) {
|
||||
DriverStationJNI.observeUserProgramAutonomous();
|
||||
autonomousPeriodic();
|
||||
m_watchdog.addEpoch("autonomousPeriodic()");
|
||||
} else if (mode == Mode.kTeleop) {
|
||||
DriverStationJNI.observeUserProgramTeleop();
|
||||
teleopPeriodic();
|
||||
m_watchdog.addEpoch("teleopPeriodic()");
|
||||
} else {
|
||||
DriverStationJNI.observeUserProgramTest();
|
||||
testPeriodic();
|
||||
m_watchdog.addEpoch("testPeriodic()");
|
||||
switch (mode) {
|
||||
case kDisabled -> {
|
||||
DriverStationJNI.observeUserProgramDisabled();
|
||||
disabledPeriodic();
|
||||
m_watchdog.addEpoch("disabledPeriodic()");
|
||||
}
|
||||
case kAutonomous -> {
|
||||
DriverStationJNI.observeUserProgramAutonomous();
|
||||
autonomousPeriodic();
|
||||
m_watchdog.addEpoch("autonomousPeriodic()");
|
||||
}
|
||||
case kTeleop -> {
|
||||
DriverStationJNI.observeUserProgramTeleop();
|
||||
teleopPeriodic();
|
||||
m_watchdog.addEpoch("teleopPeriodic()");
|
||||
}
|
||||
case kTest -> {
|
||||
DriverStationJNI.observeUserProgramTest();
|
||||
testPeriodic();
|
||||
m_watchdog.addEpoch("testPeriodic()");
|
||||
}
|
||||
default -> {
|
||||
// NOP
|
||||
}
|
||||
}
|
||||
|
||||
robotPeriodic();
|
||||
|
||||
@@ -211,22 +211,14 @@ public class PWM implements Sendable, AutoCloseable {
|
||||
* @param mult The period multiplier to apply to this channel
|
||||
*/
|
||||
public void setPeriodMultiplier(PeriodMultiplier mult) {
|
||||
switch (mult) {
|
||||
case k4X:
|
||||
// Squelch 3 out of 4 outputs
|
||||
PWMJNI.setPWMPeriodScale(m_handle, 3);
|
||||
break;
|
||||
case k2X:
|
||||
// Squelch 1 out of 2 outputs
|
||||
PWMJNI.setPWMPeriodScale(m_handle, 1);
|
||||
break;
|
||||
case k1X:
|
||||
// Don't squelch any outputs
|
||||
PWMJNI.setPWMPeriodScale(m_handle, 0);
|
||||
break;
|
||||
default:
|
||||
// Cannot hit this, limited by PeriodMultiplier enum
|
||||
}
|
||||
int scale =
|
||||
switch (mult) {
|
||||
case k4X -> 3; // Squelch 3 out of 4 outputs
|
||||
case k2X -> 1; // Squelch 1 out of 2 outputs
|
||||
case k1X -> 0; // Don't squelch any outputs
|
||||
};
|
||||
|
||||
PWMJNI.setPWMPeriodScale(m_handle, scale);
|
||||
}
|
||||
|
||||
/** Latches PWM to zero. */
|
||||
|
||||
@@ -14,12 +14,10 @@ public interface PneumaticsBase extends AutoCloseable {
|
||||
* @return module
|
||||
*/
|
||||
static PneumaticsBase getForType(int module, PneumaticsModuleType type) {
|
||||
if (type == PneumaticsModuleType.CTREPCM) {
|
||||
return new PneumaticsControlModule(module);
|
||||
} else if (type == PneumaticsModuleType.REVPH) {
|
||||
return new PneumaticHub(module);
|
||||
}
|
||||
throw new IllegalArgumentException("Unknown module type");
|
||||
return switch (type) {
|
||||
case CTREPCM -> new PneumaticsControlModule(module);
|
||||
case REVPH -> new PneumaticHub(module);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -29,12 +27,10 @@ public interface PneumaticsBase extends AutoCloseable {
|
||||
* @return module default
|
||||
*/
|
||||
static int getDefaultForType(PneumaticsModuleType type) {
|
||||
if (type == PneumaticsModuleType.CTREPCM) {
|
||||
return SensorUtil.getDefaultCTREPCMModule();
|
||||
} else if (type == PneumaticsModuleType.REVPH) {
|
||||
return SensorUtil.getDefaultREVPHModule();
|
||||
}
|
||||
throw new IllegalArgumentException("Unknown module type");
|
||||
return switch (type) {
|
||||
case CTREPCM -> SensorUtil.getDefaultCTREPCMModule();
|
||||
case REVPH -> SensorUtil.getDefaultREVPHModule();
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -182,23 +182,23 @@ public class Relay extends MotorSafety implements Sendable, AutoCloseable {
|
||||
*/
|
||||
public void set(Value value) {
|
||||
switch (value) {
|
||||
case kOff:
|
||||
case kOff -> {
|
||||
if (m_direction == Direction.kBoth || m_direction == Direction.kForward) {
|
||||
RelayJNI.setRelay(m_forwardHandle, false);
|
||||
}
|
||||
if (m_direction == Direction.kBoth || m_direction == Direction.kReverse) {
|
||||
RelayJNI.setRelay(m_reverseHandle, false);
|
||||
}
|
||||
break;
|
||||
case kOn:
|
||||
}
|
||||
case kOn -> {
|
||||
if (m_direction == Direction.kBoth || m_direction == Direction.kForward) {
|
||||
RelayJNI.setRelay(m_forwardHandle, true);
|
||||
}
|
||||
if (m_direction == Direction.kBoth || m_direction == Direction.kReverse) {
|
||||
RelayJNI.setRelay(m_reverseHandle, true);
|
||||
}
|
||||
break;
|
||||
case kForward:
|
||||
}
|
||||
case kForward -> {
|
||||
if (m_direction == Direction.kReverse) {
|
||||
throw new InvalidValueException(
|
||||
"A relay configured for reverse cannot be set to " + "forward");
|
||||
@@ -209,8 +209,8 @@ public class Relay extends MotorSafety implements Sendable, AutoCloseable {
|
||||
if (m_direction == Direction.kBoth) {
|
||||
RelayJNI.setRelay(m_reverseHandle, false);
|
||||
}
|
||||
break;
|
||||
case kReverse:
|
||||
}
|
||||
case kReverse -> {
|
||||
if (m_direction == Direction.kForward) {
|
||||
throw new InvalidValueException(
|
||||
"A relay configured for forward cannot be set to " + "reverse");
|
||||
@@ -221,9 +221,10 @@ public class Relay extends MotorSafety implements Sendable, AutoCloseable {
|
||||
if (m_direction == Direction.kBoth || m_direction == Direction.kReverse) {
|
||||
RelayJNI.setRelay(m_reverseHandle, true);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
}
|
||||
default -> {
|
||||
// Cannot hit this, limited by Value enum
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -91,43 +91,28 @@ public abstract class RobotBase implements AutoCloseable {
|
||||
@Override
|
||||
public void reportUsage(MathUsageId id, int count) {
|
||||
switch (id) {
|
||||
case kKinematics_DifferentialDrive:
|
||||
HAL.report(
|
||||
tResourceType.kResourceType_Kinematics,
|
||||
tInstances.kKinematics_DifferentialDrive);
|
||||
break;
|
||||
case kKinematics_MecanumDrive:
|
||||
HAL.report(
|
||||
tResourceType.kResourceType_Kinematics, tInstances.kKinematics_MecanumDrive);
|
||||
break;
|
||||
case kKinematics_SwerveDrive:
|
||||
HAL.report(
|
||||
tResourceType.kResourceType_Kinematics, tInstances.kKinematics_SwerveDrive);
|
||||
break;
|
||||
case kTrajectory_TrapezoidProfile:
|
||||
HAL.report(tResourceType.kResourceType_TrapezoidProfile, count);
|
||||
break;
|
||||
case kFilter_Linear:
|
||||
HAL.report(tResourceType.kResourceType_LinearFilter, count);
|
||||
break;
|
||||
case kOdometry_DifferentialDrive:
|
||||
HAL.report(
|
||||
tResourceType.kResourceType_Odometry, tInstances.kOdometry_DifferentialDrive);
|
||||
break;
|
||||
case kOdometry_SwerveDrive:
|
||||
HAL.report(tResourceType.kResourceType_Odometry, tInstances.kOdometry_SwerveDrive);
|
||||
break;
|
||||
case kOdometry_MecanumDrive:
|
||||
HAL.report(tResourceType.kResourceType_Odometry, tInstances.kOdometry_MecanumDrive);
|
||||
break;
|
||||
case kController_PIDController2:
|
||||
HAL.report(tResourceType.kResourceType_PIDController2, count);
|
||||
break;
|
||||
case kController_ProfiledPIDController:
|
||||
HAL.report(tResourceType.kResourceType_ProfiledPIDController, count);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
case kKinematics_DifferentialDrive -> HAL.report(
|
||||
tResourceType.kResourceType_Kinematics, tInstances.kKinematics_DifferentialDrive);
|
||||
case kKinematics_MecanumDrive -> HAL.report(
|
||||
tResourceType.kResourceType_Kinematics, tInstances.kKinematics_MecanumDrive);
|
||||
case kKinematics_SwerveDrive -> HAL.report(
|
||||
tResourceType.kResourceType_Kinematics, tInstances.kKinematics_SwerveDrive);
|
||||
case kTrajectory_TrapezoidProfile -> HAL.report(
|
||||
tResourceType.kResourceType_TrapezoidProfile, count);
|
||||
case kFilter_Linear -> HAL.report(tResourceType.kResourceType_LinearFilter, count);
|
||||
case kOdometry_DifferentialDrive -> HAL.report(
|
||||
tResourceType.kResourceType_Odometry, tInstances.kOdometry_DifferentialDrive);
|
||||
case kOdometry_SwerveDrive -> HAL.report(
|
||||
tResourceType.kResourceType_Odometry, tInstances.kOdometry_SwerveDrive);
|
||||
case kOdometry_MecanumDrive -> HAL.report(
|
||||
tResourceType.kResourceType_Odometry, tInstances.kOdometry_MecanumDrive);
|
||||
case kController_PIDController2 -> HAL.report(
|
||||
tResourceType.kResourceType_PIDController2, count);
|
||||
case kController_ProfiledPIDController -> HAL.report(
|
||||
tResourceType.kResourceType_ProfiledPIDController, count);
|
||||
default -> {
|
||||
// NOP
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -345,18 +345,13 @@ public final class RobotController {
|
||||
* @return state
|
||||
*/
|
||||
public static RadioLEDState fromValue(int value) {
|
||||
switch (value) {
|
||||
case LEDJNI.RADIO_LED_STATE_OFF:
|
||||
return RadioLEDState.kOff;
|
||||
case LEDJNI.RADIO_LED_STATE_GREEN:
|
||||
return RadioLEDState.kGreen;
|
||||
case LEDJNI.RADIO_LED_STATE_RED:
|
||||
return RadioLEDState.kRed;
|
||||
case LEDJNI.RADIO_LED_STATE_ORANGE:
|
||||
return RadioLEDState.kOrange;
|
||||
default:
|
||||
return RadioLEDState.kOff;
|
||||
}
|
||||
return switch (value) {
|
||||
case LEDJNI.RADIO_LED_STATE_OFF -> RadioLEDState.kOff;
|
||||
case LEDJNI.RADIO_LED_STATE_GREEN -> RadioLEDState.kGreen;
|
||||
case LEDJNI.RADIO_LED_STATE_RED -> RadioLEDState.kRed;
|
||||
case LEDJNI.RADIO_LED_STATE_ORANGE -> RadioLEDState.kOrange;
|
||||
default -> RadioLEDState.kOff;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -29,11 +29,10 @@ public enum RuntimeType {
|
||||
* @return Matching runtime type
|
||||
*/
|
||||
public static RuntimeType getValue(int type) {
|
||||
if (type == HALUtil.RUNTIME_ROBORIO) {
|
||||
return RuntimeType.kRoboRIO;
|
||||
} else if (type == HALUtil.RUNTIME_ROBORIO2) {
|
||||
return RuntimeType.kRoboRIO2;
|
||||
}
|
||||
return RuntimeType.kSimulation;
|
||||
return switch (type) {
|
||||
case HALUtil.RUNTIME_ROBORIO -> RuntimeType.kRoboRIO;
|
||||
case HALUtil.RUNTIME_ROBORIO2 -> RuntimeType.kRoboRIO2;
|
||||
default -> RuntimeType.kSimulation;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,10 +50,7 @@ public class TimedRobot extends IterativeRobotBase {
|
||||
|
||||
@Override
|
||||
public boolean equals(Object rhs) {
|
||||
if (rhs instanceof Callback) {
|
||||
return Double.compare(expirationTime, ((Callback) rhs).expirationTime) == 0;
|
||||
}
|
||||
return false;
|
||||
return rhs instanceof Callback callback && expirationTime == callback.expirationTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -62,10 +62,8 @@ public class Watchdog implements Closeable, Comparable<Watchdog> {
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof Watchdog) {
|
||||
return Double.compare(m_expirationTimeSeconds, ((Watchdog) obj).m_expirationTimeSeconds) == 0;
|
||||
}
|
||||
return false;
|
||||
return obj instanceof Watchdog watchdog
|
||||
&& Double.compare(m_expirationTimeSeconds, watchdog.m_expirationTimeSeconds) == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,7 +16,8 @@ import java.util.function.LongSupplier;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/** Common interface for objects that can contain shuffleboard components. */
|
||||
public interface ShuffleboardContainer extends ShuffleboardValue {
|
||||
public sealed interface ShuffleboardContainer extends ShuffleboardValue
|
||||
permits ShuffleboardLayout, ShuffleboardTab {
|
||||
/**
|
||||
* Gets the components that are direct children of this container.
|
||||
*
|
||||
|
||||
@@ -103,11 +103,11 @@ final class ShuffleboardInstance implements ShuffleboardRoot {
|
||||
*/
|
||||
private void apply(ShuffleboardContainer container, Consumer<ComplexWidget> func) {
|
||||
for (ShuffleboardComponent<?> component : container.getComponents()) {
|
||||
if (component instanceof ComplexWidget) {
|
||||
func.accept((ComplexWidget) component);
|
||||
if (component instanceof ComplexWidget widget) {
|
||||
func.accept(widget);
|
||||
}
|
||||
if (component instanceof ShuffleboardContainer) {
|
||||
apply((ShuffleboardContainer) component, func);
|
||||
if (component instanceof ShuffleboardContainer nestedContainer) {
|
||||
apply(nestedContainer, func);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ import java.util.function.LongSupplier;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/** A layout in a Shuffleboard tab. Layouts can contain widgets and other layouts. */
|
||||
public class ShuffleboardLayout extends ShuffleboardComponent<ShuffleboardLayout>
|
||||
public final class ShuffleboardLayout extends ShuffleboardComponent<ShuffleboardLayout>
|
||||
implements ShuffleboardContainer {
|
||||
private final ContainerHelper m_helper = new ContainerHelper(this);
|
||||
|
||||
|
||||
@@ -59,8 +59,8 @@ public final class SimpleWidget extends ShuffleboardWidget<SimpleWidget> impleme
|
||||
|
||||
private void forceGenerate() {
|
||||
ShuffleboardContainer parent = getParent();
|
||||
while (parent instanceof ShuffleboardLayout) {
|
||||
parent = ((ShuffleboardLayout) parent).getParent();
|
||||
while (parent instanceof ShuffleboardLayout layout) {
|
||||
parent = layout.getParent();
|
||||
}
|
||||
ShuffleboardTab tab = (ShuffleboardTab) parent;
|
||||
tab.getRoot().update();
|
||||
|
||||
@@ -93,21 +93,16 @@ public class CallbackStore implements AutoCloseable {
|
||||
@Override
|
||||
public void close() {
|
||||
switch (m_cancelType) {
|
||||
case kAlreadyCancelled:
|
||||
case kAlreadyCancelled -> {
|
||||
// Already cancelled so do nothing so that close() is idempotent.
|
||||
return;
|
||||
case kNormalCancel:
|
||||
m_cancelCallback.cancel(m_index, m_uid);
|
||||
break;
|
||||
case kChannelCancel:
|
||||
m_cancelCallbackChannel.cancel(m_index, m_channel, m_uid);
|
||||
break;
|
||||
case kNoIndexCancel:
|
||||
m_cancelCallbackNoIndex.cancel(m_uid);
|
||||
break;
|
||||
default:
|
||||
}
|
||||
case kNormalCancel -> m_cancelCallback.cancel(m_index, m_uid);
|
||||
case kChannelCancel -> m_cancelCallbackChannel.cancel(m_index, m_channel, m_uid);
|
||||
case kNoIndexCancel -> m_cancelCallbackNoIndex.cancel(m_uid);
|
||||
default -> {
|
||||
assert false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
m_cancelType = kAlreadyCancelled;
|
||||
}
|
||||
|
||||
@@ -228,24 +228,16 @@ public final class DriverStationSim {
|
||||
* @return the alliance station color and number
|
||||
*/
|
||||
public static AllianceStationID getAllianceStationId() {
|
||||
switch (DriverStationDataJNI.getAllianceStationId()) {
|
||||
case DriverStationJNI.kUnknownAllianceStation:
|
||||
return AllianceStationID.Unknown;
|
||||
case DriverStationJNI.kRed1AllianceStation:
|
||||
return AllianceStationID.Red1;
|
||||
case DriverStationJNI.kRed2AllianceStation:
|
||||
return AllianceStationID.Red2;
|
||||
case DriverStationJNI.kRed3AllianceStation:
|
||||
return AllianceStationID.Red3;
|
||||
case DriverStationJNI.kBlue1AllianceStation:
|
||||
return AllianceStationID.Blue1;
|
||||
case DriverStationJNI.kBlue2AllianceStation:
|
||||
return AllianceStationID.Blue2;
|
||||
case DriverStationJNI.kBlue3AllianceStation:
|
||||
return AllianceStationID.Blue3;
|
||||
default:
|
||||
return AllianceStationID.Unknown;
|
||||
}
|
||||
return switch (DriverStationDataJNI.getAllianceStationId()) {
|
||||
case DriverStationJNI.kUnknownAllianceStation -> AllianceStationID.Unknown;
|
||||
case DriverStationJNI.kRed1AllianceStation -> AllianceStationID.Red1;
|
||||
case DriverStationJNI.kRed2AllianceStation -> AllianceStationID.Red2;
|
||||
case DriverStationJNI.kRed3AllianceStation -> AllianceStationID.Red3;
|
||||
case DriverStationJNI.kBlue1AllianceStation -> AllianceStationID.Blue1;
|
||||
case DriverStationJNI.kBlue2AllianceStation -> AllianceStationID.Blue2;
|
||||
case DriverStationJNI.kBlue3AllianceStation -> AllianceStationID.Blue3;
|
||||
default -> AllianceStationID.Unknown;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -254,32 +246,16 @@ public final class DriverStationSim {
|
||||
* @param allianceStationId the new alliance station
|
||||
*/
|
||||
public static void setAllianceStationId(AllianceStationID allianceStationId) {
|
||||
int allianceStation;
|
||||
switch (allianceStationId) {
|
||||
case Unknown:
|
||||
allianceStation = DriverStationJNI.kUnknownAllianceStation;
|
||||
break;
|
||||
case Red1:
|
||||
allianceStation = DriverStationJNI.kRed1AllianceStation;
|
||||
break;
|
||||
case Red2:
|
||||
allianceStation = DriverStationJNI.kRed2AllianceStation;
|
||||
break;
|
||||
case Red3:
|
||||
allianceStation = DriverStationJNI.kRed3AllianceStation;
|
||||
break;
|
||||
case Blue1:
|
||||
allianceStation = DriverStationJNI.kBlue1AllianceStation;
|
||||
break;
|
||||
case Blue2:
|
||||
allianceStation = DriverStationJNI.kBlue2AllianceStation;
|
||||
break;
|
||||
case Blue3:
|
||||
allianceStation = DriverStationJNI.kBlue3AllianceStation;
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
int allianceStation =
|
||||
switch (allianceStationId) {
|
||||
case Unknown -> DriverStationJNI.kUnknownAllianceStation;
|
||||
case Red1 -> DriverStationJNI.kRed1AllianceStation;
|
||||
case Red2 -> DriverStationJNI.kRed2AllianceStation;
|
||||
case Red3 -> DriverStationJNI.kRed3AllianceStation;
|
||||
case Blue1 -> DriverStationJNI.kBlue1AllianceStation;
|
||||
case Blue2 -> DriverStationJNI.kBlue2AllianceStation;
|
||||
case Blue3 -> DriverStationJNI.kBlue3AllianceStation;
|
||||
};
|
||||
DriverStationDataJNI.setAllianceStationId(allianceStation);
|
||||
}
|
||||
|
||||
@@ -507,23 +483,13 @@ public final class DriverStationSim {
|
||||
* @param type the match type
|
||||
*/
|
||||
public static void setMatchType(DriverStation.MatchType type) {
|
||||
int matchType;
|
||||
switch (type) {
|
||||
case Practice:
|
||||
matchType = 1;
|
||||
break;
|
||||
case Qualification:
|
||||
matchType = 2;
|
||||
break;
|
||||
case Elimination:
|
||||
matchType = 3;
|
||||
break;
|
||||
case None:
|
||||
matchType = 0;
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
int matchType =
|
||||
switch (type) {
|
||||
case Practice -> 1;
|
||||
case Qualification -> 2;
|
||||
case Elimination -> 3;
|
||||
case None -> 0;
|
||||
};
|
||||
DriverStationDataJNI.setMatchType(matchType);
|
||||
}
|
||||
|
||||
|
||||
@@ -21,14 +21,10 @@ public abstract class PneumaticsBaseSim {
|
||||
* @return the module object.
|
||||
*/
|
||||
public static PneumaticsBaseSim getForType(int module, PneumaticsModuleType type) {
|
||||
switch (type) {
|
||||
case CTREPCM:
|
||||
return new CTREPCMSim(module);
|
||||
case REVPH:
|
||||
return new REVPHSim(module);
|
||||
default:
|
||||
throw new IllegalArgumentException("Unknown module type");
|
||||
}
|
||||
return switch (type) {
|
||||
case CTREPCM -> new CTREPCMSim(module);
|
||||
case REVPH -> new REVPHSim(module);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -126,20 +126,14 @@ public class Color {
|
||||
// Goes from 0 to chroma as hue increases
|
||||
final int X = (chroma * remainder) >> 8;
|
||||
|
||||
switch (region) {
|
||||
case 0:
|
||||
return new Color(v, X + m, m);
|
||||
case 1:
|
||||
return new Color(v - X, v, m);
|
||||
case 2:
|
||||
return new Color(m, v, X + m);
|
||||
case 3:
|
||||
return new Color(m, v - X, v);
|
||||
case 4:
|
||||
return new Color(X + m, m, v);
|
||||
default:
|
||||
return new Color(v, m, v - X);
|
||||
}
|
||||
return switch (region) {
|
||||
case 0 -> new Color(v, X + m, m);
|
||||
case 1 -> new Color(v - X, v, m);
|
||||
case 2 -> new Color(m, v, X + m);
|
||||
case 3 -> new Color(m, v - X, v);
|
||||
case 4 -> new Color(X + m, m, v);
|
||||
default -> new Color(v, m, v - X);
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user