Skip to content

Commit c43a679

Browse files
authored
Merge branch 'master' into safe-mode
2 parents 73cb8ef + 1be3fcf commit c43a679

23 files changed

Lines changed: 281 additions & 140 deletions

.github/workflows/gradle.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@ jobs:
88
runs-on: ubuntu-latest
99

1010
steps:
11-
- uses: actions/checkout@v2
11+
- uses: actions/checkout@v3
1212
with:
1313
submodules: 'recursive'
14-
- name: Set up JDK 11
15-
uses: actions/setup-java@v1
14+
- name: Set up JDK 17
15+
uses: actions/setup-java@v3
1616
with:
17-
java-version: 11
17+
distribution: 'temurin'
18+
java-version: 17
1819
- name: Build with Gradle
1920
run: ./gradlew build

.github/workflows/javadoc.yml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
1-
name: Deploy Javadoc
1+
name: Javadoc
22

33
on: [push]
44

55
jobs:
66
build-javadoc:
77
runs-on: ubuntu-latest
88
steps:
9-
- uses: actions/checkout@v2
9+
- uses: actions/checkout@v3
1010
with:
1111
submodules: 'recursive'
12-
- name: Set up JDK 11
13-
uses: actions/setup-java@v1
12+
- name: Set up JDK 17
13+
uses: actions/setup-java@v3
1414
with:
15-
java-version: 11
15+
distribution: 'temurin'
16+
java-version: 17
1617
- name: Generate Javadoc
1718
run: ./gradlew javadoc
1819
- name: Build Artifact
19-
uses: actions/upload-pages-artifact@v1.0.5
20+
uses: actions/upload-pages-artifact@v1
2021
with:
2122
path: ./build/docs/javadoc
2223
deploy-javadoc:
@@ -32,4 +33,4 @@ jobs:
3233
steps:
3334
- name: Deploy to GitHub Pages
3435
id: deployment
35-
uses: actions/deploy-pages@v1.2.3
36+
uses: actions/deploy-pages@v1

.github/workflows/release.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Create Release
2+
3+
on:
4+
push:
5+
tags:
6+
- '[0-9]+.[0-9]+.[0-9]+'
7+
8+
jobs:
9+
release:
10+
name: Release Tag
11+
runs-on: ubuntu-latest
12+
permissions:
13+
contents: write
14+
steps:
15+
- name: Create Release
16+
env:
17+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
18+
tag: ${{ github.ref_name }}
19+
run: |
20+
gh release create "$tag" --repo="$GITHUB_REPOSITORY" --title="$tag" --generate-notes

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
plugins {
22
id "java"
3-
id "edu.wpi.first.GradleRIO" version "2023.4.2"
3+
id "edu.wpi.first.GradleRIO" version "2023.4.3"
44
id "maven-publish"
55
}
66

jitpack.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
jdk: openjdk11
1+
jdk: openjdk17

src/main/java/org/carlmontrobotics/MotorConfig.java

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/main/java/org/carlmontrobotics/lib199/CachedSparkMax.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.revrobotics.RelativeEncoder;
55
import com.revrobotics.SparkMaxPIDController;
66

7+
@Deprecated
78
public class CachedSparkMax extends CANSparkMax {
89

910
private RelativeEncoder encoder;

src/main/java/org/carlmontrobotics/lib199/Lib199Subsystem.java

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,39 @@
11
package org.carlmontrobotics.lib199;
22

3-
import java.util.ArrayList;
3+
import java.util.concurrent.CopyOnWriteArrayList;
44
import java.util.function.Consumer;
55

6+
import edu.wpi.first.wpilibj.RobotBase;
67
import edu.wpi.first.wpilibj2.command.Subsystem;
78

89
public class Lib199Subsystem implements Subsystem {
910

1011
private static final Lib199Subsystem INSTANCE = new Lib199Subsystem();
11-
private static final ArrayList<Runnable> periodicMethods = new ArrayList<>();
12-
private static final ArrayList<Runnable> periodicSimulationMethods = new ArrayList<>();
12+
private static final CopyOnWriteArrayList<Runnable> periodicMethods = new CopyOnWriteArrayList<>();
13+
private static final CopyOnWriteArrayList<Runnable> periodicSimulationMethods = new CopyOnWriteArrayList<>();
14+
private static final CopyOnWriteArrayList<Runnable> asyncPeriodicMethods = new CopyOnWriteArrayList<>();
15+
private static final CopyOnWriteArrayList<Runnable> asyncPeriodicSimulationMethods = new CopyOnWriteArrayList<>();
1316
private static final Consumer<Runnable> RUN_RUNNABLE = Runnable::run;
1417

18+
private static final Thread asyncPeriodicThread;
19+
20+
public static final long asyncSleepTime = 20;
21+
1522
static {
1623
ensureRegistered();
24+
25+
asyncPeriodicThread = new Thread(() -> {
26+
while(true) {
27+
INSTANCE.asyncPeriodic();
28+
try {
29+
Thread.sleep(asyncSleepTime);
30+
} catch(InterruptedException e) {}
31+
}
32+
});
33+
asyncPeriodicThread.setDaemon(true);
34+
asyncPeriodicThread.start();
1735
}
18-
36+
1937
private static boolean registered = false;
2038

2139
private static void ensureRegistered() {
@@ -30,10 +48,27 @@ public static void registerPeriodic(Runnable method) {
3048
periodicMethods.add(method);
3149
}
3250

51+
@Deprecated
52+
/**
53+
* @deprecated Use registerSimulationPeriodic
54+
* @param method
55+
*/
3356
public static void simulationPeriodic(Runnable method) {
57+
registerSimulationPeriodic(method);
58+
}
59+
60+
public static void registerSimulationPeriodic(Runnable method) {
3461
periodicSimulationMethods.add(method);
3562
}
3663

64+
public static void registerAsyncPeriodic(Runnable method) {
65+
asyncPeriodicMethods.add(method);
66+
}
67+
68+
public static void registerAsyncSimulationPeriodic(Runnable method) {
69+
if(RobotBase.isSimulation()) asyncPeriodicSimulationMethods.add(method);
70+
}
71+
3772
@Override
3873
public void periodic() {
3974
periodicMethods.forEach(RUN_RUNNABLE);
@@ -44,6 +79,11 @@ public void simulationPeriodic() {
4479
periodicSimulationMethods.forEach(RUN_RUNNABLE);
4580
}
4681

82+
public void asyncPeriodic() {
83+
asyncPeriodicMethods.forEach(RUN_RUNNABLE);
84+
asyncPeriodicSimulationMethods.forEach(RUN_RUNNABLE);
85+
}
86+
4787
private Lib199Subsystem() {}
4888

4989
}

src/main/java/org/carlmontrobotics/lib199/Mocks.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66
import java.lang.reflect.Modifier;
77
import java.util.ArrayList;
88
import java.util.Arrays;
9-
import java.util.Collections;
109
import java.util.HashMap;
11-
import java.util.List;
10+
import java.util.concurrent.CopyOnWriteArrayList;
1211
import java.util.function.Consumer;
1312
import java.util.function.Predicate;
1413
import java.util.stream.Collectors;
@@ -21,10 +20,10 @@
2120

2221
public final class Mocks {
2322

24-
private static final List<WeakReference<Object>> MOCKS = Collections.synchronizedList(new ArrayList<>());
23+
private static final CopyOnWriteArrayList<WeakReference<Object>> MOCKS = new CopyOnWriteArrayList<>();
2524
private static final Predicate<WeakReference<?>> IS_REFERENCE_CLEARED = reference -> reference.get() == null;
2625
private static final Consumer<WeakReference<Object>> CLEAR_INVOCATIONS_ON_REFERENCED_MOCK = reference -> Mockito.clearInvocations(reference.get());
27-
private static final Predicate<WeakReference<Object>> CLEAR_INVOCATIONS_ON_REFERENCED_MOCK_IF_REFERNCE_NOT_CLEARED = reference -> {
26+
private static final Predicate<WeakReference<Object>> CLEAR_INVOCATIONS_ON_REFERENCED_MOCK_IF_REFERENCE_NOT_CLEARED = reference -> {
2827
if(IS_REFERENCE_CLEARED.test(reference)) return true;
2928
CLEAR_INVOCATIONS_ON_REFERENCED_MOCK.accept(reference);
3029
return false;
@@ -37,7 +36,7 @@ public final class Mocks {
3736
// 2) Garbage collected references are removed
3837
// 3) Mock is garbage collected
3938
// 4) Mock invocations are cleared -> throws NullPointerException
40-
Lib199Subsystem.registerPeriodic(() -> MOCKS.removeIf(CLEAR_INVOCATIONS_ON_REFERENCED_MOCK_IF_REFERNCE_NOT_CLEARED));
39+
Lib199Subsystem.registerAsyncPeriodic(() -> MOCKS.removeIf(CLEAR_INVOCATIONS_ON_REFERENCED_MOCK_IF_REFERENCE_NOT_CLEARED));
4140
}
4241

4342
/**
@@ -61,7 +60,7 @@ public static <T, U> T createMock(Class<T> classToMock, U implClass, Class<?>...
6160
* @param <U> the class type which will be used to provide method implementations
6261
* @param classToMock the class type which will be mocked
6362
* @param implClass the object to which to try to forward method calls
64-
* @param forwardUnknownCalls whether methods which are not overriden will call their real methods
63+
* @param forwardUnknownCalls whether methods which are not overridden will call their real methods
6564
* @param interfaces a list of interfaces which the mocked object should extend
6665
* @return an instance of <code>T</code> in which some or all of the classes methods are replaced with a mocked implementation from <code>U</code>
6766
* @see #createMock(Class, Object, Class...)
@@ -77,7 +76,7 @@ public static <T, U> T createMock(Class<T> classToMock, U implClass, boolean for
7776
* @param <U> the class type which will be used to provide method implementations
7877
* @param classToMock the class type which will be mocked
7978
* @param implClass the object to which to try to forward method calls
80-
* @param defaultAnswer The answer to use when no overriden implementation is found
79+
* @param defaultAnswer The answer to use when no overridden implementation is found
8180
* @param interfaces a list of interfaces which the mocked object should extend
8281
* @return an instance of <code>T</code> in which some or all of the classes methods are replaced with a mocked implementation from <code>U</code>
8382
* @see #createMock(Class, Object, Class...)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package org.carlmontrobotics.lib199;
2+
3+
public class MotorConfig {
4+
5+
public static final MotorConfig NEO = new MotorConfig(70, 40);
6+
public static final MotorConfig NEO_550 = new MotorConfig(40, 20);
7+
8+
public final int temperatureLimitCelsius, currentLimitAmps;
9+
10+
public MotorConfig(int temperatureLimitCelsius, int currentLimitAmps) {
11+
this.temperatureLimitCelsius = temperatureLimitCelsius;
12+
this.currentLimitAmps = currentLimitAmps;
13+
}
14+
15+
}

0 commit comments

Comments
 (0)