Skip to content

Commit dc5eff9

Browse files
authored
Merge pull request #90 from strykeforce/fix-warnings
Fix warnings and deprecations
2 parents 36dd67c + 7fb6920 commit dc5eff9

File tree

5 files changed

+24
-20
lines changed

5 files changed

+24
-20
lines changed

build.gradle

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,15 @@ compileKotlin {
9696
}
9797
}
9898

99+
compileTestKotlin {
100+
kotlinOptions {
101+
jvmTarget = "11"
102+
103+
// For creation of default methods in interfaces
104+
freeCompilerArgs += "-Xjvm-default=all"
105+
}
106+
}
107+
99108

100109
java {
101110
withSourcesJar()

gradle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
githubUrl=https://github.com/strykeforce/thirdcoast
22
kotlin.code.style=official
3+
kapt.use.worker.api=true

src/main/java/org/strykeforce/swerve/TalonSwerveModule.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,18 +115,16 @@ public void resetDriveEncoder() {
115115
public void storeAzimuthZeroReference() {
116116
int index = getWheelIndex();
117117
int position = getAzimuthAbsoluteEncoderCounts();
118-
Preferences preferences = Preferences.getInstance();
119118
String key = String.format("SwerveDrive/wheel.%d", index);
120-
preferences.putInt(key, position);
119+
Preferences.setInt(key, position);
121120
logger.info("azimuth {}: saved zero = {}", index, position);
122121
}
123122

124123
@Override
125124
public void loadAndSetAzimuthZeroReference() {
126125
int index = getWheelIndex();
127-
Preferences preferences = Preferences.getInstance();
128126
String key = String.format("SwerveDrive/wheel.%d", index);
129-
int reference = preferences.getInt(key, Integer.MIN_VALUE);
127+
int reference = Preferences.getInt(key, Integer.MIN_VALUE);
130128
if (reference == Integer.MIN_VALUE) {
131129
logger.error("no saved azimuth zero reference for swerve module {}", index);
132130
throw new IllegalStateException();

src/main/kotlin/org/strykeforce/console/MCP23008.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class MCP23008 {
5252

5353
fun getSwitch(switch: Console.Switch): Boolean {
5454
val buffer = ByteArray(1)
55-
if (timer.hasPeriodPassed(POLL_SECONDS)) {
55+
if (timer.advanceIfElapsed(POLL_SECONDS)) {
5656
expander.read(GPIO, buffer.size, buffer)
5757
switchState = buffer[0].toUByte()
5858
// logger.debug { switchState.toUByte().toString(2) }

src/test/java/org/strykeforce/swerve/TalonSwerveModuleTest.java

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ void resetDriveEncoder() {
8484

8585
@Nested
8686
@DisplayName("When setting azimuth zero")
87-
class WhenSettingAzimuthZero {
87+
class TestWhenSettingAzimuthZero {
8888

8989
TalonSRX azimuthTalon;
9090
TalonFX driveTalon;
@@ -119,39 +119,37 @@ void storeAzimuthZeroReference() {
119119
.wheelDiameterInches(kWheelDiameterInches)
120120
.driveMaximumMetersPerSecond(kMaxSpeedMetersPerSecond);
121121

122-
Preferences preferences = Preferences.getInstance();
123-
124122
int expectedZeroReference = 27;
125123
int index = 0; // fixture wheel is LF
126124
String key = String.format("SwerveDrive/wheel.%d", index);
127125
module = builder.wheelLocationMeters(new Translation2d(1, 1)).build();
128126
when(sensorCollection.getPulseWidthPosition()).thenReturn(expectedZeroReference);
129127
module.storeAzimuthZeroReference();
130-
assertEquals(expectedZeroReference, preferences.getInt(key, -1));
128+
assertEquals(expectedZeroReference, Preferences.getInt(key, -1));
131129

132130
expectedZeroReference = 67;
133131
index = 1; // fixture wheel is RF
134132
key = String.format("SwerveDrive/wheel.%d", index);
135133
module = builder.wheelLocationMeters(new Translation2d(1, -1)).build();
136134
when(sensorCollection.getPulseWidthPosition()).thenReturn(expectedZeroReference);
137135
module.storeAzimuthZeroReference();
138-
assertEquals(expectedZeroReference, preferences.getInt(key, -1));
136+
assertEquals(expectedZeroReference, Preferences.getInt(key, -1));
139137

140138
expectedZeroReference = 2767;
141139
index = 2; // fixture wheel is LR
142140
key = String.format("SwerveDrive/wheel.%d", index);
143141
module = builder.wheelLocationMeters(new Translation2d(-1, 1)).build();
144142
when(sensorCollection.getPulseWidthPosition()).thenReturn(expectedZeroReference);
145143
module.storeAzimuthZeroReference();
146-
assertEquals(expectedZeroReference, preferences.getInt(key, -1));
144+
assertEquals(expectedZeroReference, Preferences.getInt(key, -1));
147145

148146
expectedZeroReference = 6727;
149147
index = 3; // fixture wheel is RR
150148
key = String.format("SwerveDrive/wheel.%d", index);
151149
module = builder.wheelLocationMeters(new Translation2d(-1, -1)).build();
152150
when(sensorCollection.getPulseWidthPosition()).thenReturn(expectedZeroReference);
153151
module.storeAzimuthZeroReference();
154-
assertEquals(expectedZeroReference & 0xFFF, preferences.getInt(key, -1));
152+
assertEquals(expectedZeroReference & 0xFFF, Preferences.getInt(key, -1));
155153
}
156154

157155
@ParameterizedTest
@@ -160,8 +158,7 @@ void storeAzimuthZeroReference() {
160158
void shouldSetAzimuthZero(int absoluteEncoderPosition, int zeroReference, double setpoint) {
161159
int index = 0; // fixture wheel is LF
162160
String key = String.format("SwerveDrive/wheel.%d", index);
163-
Preferences preferences = Preferences.getInstance();
164-
preferences.putInt(key, zeroReference);
161+
Preferences.setInt(key, zeroReference);
165162
when(sensorCollection.getPulseWidthPosition()).thenReturn(absoluteEncoderPosition);
166163
when(azimuthTalon.setSelectedSensorPosition(eq(setpoint), anyInt(), anyInt()))
167164
.thenReturn(ErrorCode.valueOf(0));
@@ -174,9 +171,8 @@ void shouldSetAzimuthZero(int absoluteEncoderPosition, int zeroReference, double
174171
void shouldThrowExceptionIfNoNetworkTablesReference() {
175172
int index = 0; // fixture wheel is LF
176173
String key = String.format("SwerveDrive/wheel.%d", index);
177-
Preferences preferences = Preferences.getInstance();
178-
preferences.remove(key);
179-
int reference = preferences.getInt(key, Integer.MIN_VALUE);
174+
Preferences.remove(key);
175+
int reference = Preferences.getInt(key, Integer.MIN_VALUE);
180176
assertEquals(Integer.MIN_VALUE, reference);
181177

182178
when(sensorCollection.getPulseWidthPosition()).thenReturn(0);
@@ -219,7 +215,7 @@ void rotation2DShouldWorkAsExpected() {
219215

220216
@Nested
221217
@DisplayName("Should not validate")
222-
class ShouldNotValidate {
218+
class TestShouldNotValidate {
223219

224220
private TalonSRX azimuthTalon;
225221
private TalonFX driveTalon;
@@ -301,7 +297,7 @@ void whenWheelLocationNotSet() {
301297

302298
@Nested
303299
@DisplayName("Should get module state")
304-
class ShouldGetModuleState {
300+
class TestShouldGetModuleState {
305301

306302
private TalonSRX azimuthTalon;
307303
private TalonFX driveTalon;
@@ -451,7 +447,7 @@ void getWheelLocationMeters() {
451447

452448
@Nested
453449
@DisplayName("Should set module state")
454-
class ShouldSetModuleState {
450+
class TestShouldSetModuleState {
455451

456452
final ArgumentCaptor<Double> captor = ArgumentCaptor.forClass(Double.class);
457453
private TalonSRX azimuthTalon;

0 commit comments

Comments
 (0)