From b129e903ab9fa45752fa7bd9443b6bf776b8f552 Mon Sep 17 00:00:00 2001 From: Ryan Brott Date: Sun, 5 Nov 2023 11:32:37 -0800 Subject: [PATCH] Format code My current process is * Import checkstyle into project configuration. * Run Reformat Code on each module, with Optimize Imports and '*.java' file mask --- .../acmerobotics/dashboard/DashboardCore.java | 33 +-- .../acmerobotics/dashboard/RobotStatus.java | 4 +- .../acmerobotics/dashboard/canvas/Canvas.java | 35 ++- .../acmerobotics/dashboard/canvas/Grid.java | 3 +- .../acmerobotics/dashboard/canvas/Image.java | 3 +- .../dashboard/canvas/Rotation.java | 1 + .../acmerobotics/dashboard/canvas/Text.java | 3 +- .../dashboard/canvas/Translate.java | 1 + .../dashboard/config/ValueProvider.java | 2 + .../config/reflection/ArrayProvider.java | 25 +- .../config/reflection/FieldProvider.java | 2 +- .../config/reflection/ReflectionConfig.java | 55 ++--- .../config/variable/ConfigVariable.java | 1 + .../variable/ConfigVariableDeserializer.java | 29 ++- .../variable/ConfigVariableSerializer.java | 7 +- .../config/variable/VariableType.java | 1 + .../dashboard/message/Message.java | 1 + .../message/MessageDeserializer.java | 5 +- .../message/redux/ReceiveOpModeList.java | 1 - .../message/redux/ReceiveTelemetry.java | 1 - .../dashboard/telemetry/TelemetryPacket.java | 5 +- .../dashboard/SerializationTests.java | 6 +- .../dashboard/TestDashboardInstance.java | 25 +- .../dashboard/TestFieldVersatilityOpMode.java | 38 +-- .../dashboard/TestSineWaveOpMode.java | 4 +- .../testopmode/TestOpModeManager.java | 17 +- .../acmerobotics/dashboard/FtcDashboard.java | 229 ++++++++++-------- .../telemetry/MultipleTelemetry.java | 7 +- .../ftc/teamcode/ArrayTestOpMode.java | 12 +- .../ftc/teamcode/FieldVersatilityOpMode.java | 20 +- .../ftc/teamcode/GamepadTestOpMode.java | 14 +- .../ftc/teamcode/ImageOpMode.java | 5 +- .../ftc/teamcode/OrbitOpMode.java | 18 +- .../ftc/teamcode/SineWaveOpMode.java | 6 +- .../teamcode/VisionPortalStreamingOpMode.java | 18 +- 35 files changed, 355 insertions(+), 282 deletions(-) diff --git a/DashboardCore/src/main/java/com/acmerobotics/dashboard/DashboardCore.java b/DashboardCore/src/main/java/com/acmerobotics/dashboard/DashboardCore.java index ab6fa9591..848807f3d 100644 --- a/DashboardCore/src/main/java/com/acmerobotics/dashboard/DashboardCore.java +++ b/DashboardCore/src/main/java/com/acmerobotics/dashboard/DashboardCore.java @@ -1,6 +1,5 @@ package com.acmerobotics.dashboard; -import com.acmerobotics.dashboard.canvas.Canvas; import com.acmerobotics.dashboard.config.ValueProvider; import com.acmerobotics.dashboard.config.variable.BasicVariable; import com.acmerobotics.dashboard.config.variable.ConfigVariableDeserializer; @@ -15,7 +14,6 @@ import com.acmerobotics.dashboard.telemetry.TelemetryPacket; import com.google.gson.Gson; import com.google.gson.GsonBuilder; - import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -44,13 +42,13 @@ public class DashboardCore { // NOTE: Helps to have this here for testing public static final Gson GSON = new GsonBuilder() - .registerTypeAdapter(Message.class, new MessageDeserializer()) - .registerTypeAdapter(BasicVariable.class, new ConfigVariableSerializer()) - .registerTypeAdapter(BasicVariable.class, new ConfigVariableDeserializer()) - .registerTypeAdapter(CustomVariable.class, new ConfigVariableSerializer()) - .registerTypeAdapter(CustomVariable.class, new ConfigVariableDeserializer()) - .serializeNulls() - .create(); + .registerTypeAdapter(Message.class, new MessageDeserializer()) + .registerTypeAdapter(BasicVariable.class, new ConfigVariableSerializer()) + .registerTypeAdapter(BasicVariable.class, new ConfigVariableDeserializer()) + .registerTypeAdapter(CustomVariable.class, new ConfigVariableSerializer()) + .registerTypeAdapter(CustomVariable.class, new ConfigVariableDeserializer()) + .serializeNulls() + .create(); private class TelemetryUpdateRunnable implements Runnable { @Override @@ -70,7 +68,8 @@ public void run() { // only the latest packet field overlay is used // this helps save bandwidth, especially for more complex overlays - for (TelemetryPacket packet : telemetryToSend.subList(0, telemetryToSend.size() - 1)) { + for (TelemetryPacket packet : telemetryToSend.subList(0, + telemetryToSend.size() - 1)) { packet.fieldOverlay().clear(); } @@ -85,7 +84,8 @@ public void run() { } public DashboardCore() { - telemetryExecutorService = Executors.newSingleThreadExecutor(r -> new Thread(r, "dash telemetry")); + telemetryExecutorService = + Executors.newSingleThreadExecutor(r -> new Thread(r, "dash telemetry")); telemetryExecutorService.submit(new TelemetryUpdateRunnable()); } @@ -189,6 +189,7 @@ public int getTelemetryTransmissionInterval() { /** * Sets the telemetry transmission interval. + * * @param newTransmissionInterval transmission interval in milliseconds */ public void setTelemetryTransmissionInterval(int newTransmissionInterval) { @@ -207,7 +208,7 @@ public void updateConfig() { /** * Executes {@param function} in an exclusive context for thread-safe config tree modification * and calls {@link #updateConfig()} to keep clients up to date. - * + *

* Do not leak the config tree outside the function. * * @param function @@ -220,10 +221,11 @@ public void withConfigRoot(CustomVariableConsumer function) { /** * Add config variable with custom provider. + * * @param category top-level category - * @param name variable name + * @param name variable name * @param provider getter/setter for the variable - * @param variable type + * @param variable type */ public void addConfigVariable(String category, String name, ValueProvider provider) { configRoot.with(v -> { @@ -241,8 +243,9 @@ public void addConfigVariable(String category, String name, ValueProvider /** * Remove a config variable. + * * @param category top-level category - * @param name variable name + * @param name variable name */ public void removeConfigVariable(String category, String name) { configRoot.with(v -> { diff --git a/DashboardCore/src/main/java/com/acmerobotics/dashboard/RobotStatus.java b/DashboardCore/src/main/java/com/acmerobotics/dashboard/RobotStatus.java index 7f936455e..cf9fe3513 100644 --- a/DashboardCore/src/main/java/com/acmerobotics/dashboard/RobotStatus.java +++ b/DashboardCore/src/main/java/com/acmerobotics/dashboard/RobotStatus.java @@ -24,7 +24,9 @@ public enum OpModeStatus { /** * Creates a status object with the default values. */ - public RobotStatus(boolean enabled, boolean available, String activeOpMode, OpModeStatus activeOpModeStatus, String warningMessage, String errorMessage) { + public RobotStatus(boolean enabled, boolean available, String activeOpMode, + OpModeStatus activeOpModeStatus, String warningMessage, + String errorMessage) { this.enabled = enabled; this.available = available; this.activeOpMode = activeOpMode; diff --git a/DashboardCore/src/main/java/com/acmerobotics/dashboard/canvas/Canvas.java b/DashboardCore/src/main/java/com/acmerobotics/dashboard/canvas/Canvas.java index d98e17d7d..a42443632 100644 --- a/DashboardCore/src/main/java/com/acmerobotics/dashboard/canvas/Canvas.java +++ b/DashboardCore/src/main/java/com/acmerobotics/dashboard/canvas/Canvas.java @@ -25,18 +25,23 @@ public Canvas setTranslation(double x, double y) { return this; } - public Canvas strokeText(String text, double x, double y, String font, double theta, boolean usePageFrame) { + public Canvas strokeText(String text, double x, double y, String font, double theta, + boolean usePageFrame) { ops.add(new Text(text, x, y, font, theta, true, usePageFrame)); return this; } + public Canvas strokeText(String text, double x, double y, String font, double theta) { strokeText(text, x, y, font, theta, true); return this; } - public Canvas fillText(String text, double x, double y, String font, double theta, boolean usePageFrame) { + + public Canvas fillText(String text, double x, double y, String font, double theta, + boolean usePageFrame) { ops.add(new Text(text, x, y, font, theta, false, usePageFrame)); return this; } + public Canvas fillText(String text, double x, double y, String font, double theta) { fillText(text, x, y, font, theta, true); return this; @@ -68,19 +73,19 @@ public Canvas strokePolyline(double[] xPoints, double[] yPoints) { } public Canvas strokeLine(double x1, double y1, double x2, double y2) { - strokePolyline(new double[] { x1, x2 }, new double[] { y1, y2 }); + strokePolyline(new double[] {x1, x2}, new double[] {y1, y2}); return this; } public Canvas fillRect(double x, double y, double width, double height) { - fillPolygon(new double[] { x, x + width, x + width, x }, - new double[] { y, y, y + height, y + height }); + fillPolygon(new double[] {x, x + width, x + width, x}, + new double[] {y, y, y + height, y + height}); return this; } public Canvas strokeRect(double x, double y, double width, double height) { - strokePolygon(new double[] { x, x + width, x + width, x }, - new double[] { y, y, y + height, y + height }); + strokePolygon(new double[] {x, x + width, x + width, x}, + new double[] {y, y, y + height, y + height}); return this; } @@ -115,17 +120,23 @@ public Canvas drawImage(String path, double x, double y, double width, double he return this; } - public Canvas drawImage(String path, double x, double y, double width, double height, double theta, double pivotX, double pivotY, boolean usePageFrame) { + public Canvas drawImage(String path, double x, double y, double width, double height, + double theta, double pivotX, double pivotY, boolean usePageFrame) { ops.add(new Image(path, x, y, width, height, theta, pivotX, pivotY, usePageFrame)); return this; } - public Canvas drawGrid(double x, double y, double width, double height, int numTicksX, int numTicksY) { - drawGrid(x, y, width, height, numTicksX, numTicksY, 0, 0,0, true); + public Canvas drawGrid(double x, double y, double width, double height, int numTicksX, + int numTicksY) { + drawGrid(x, y, width, height, numTicksX, numTicksY, 0, 0, 0, true); return this; } - public Canvas drawGrid(double x, double y, double width, double height, int numTicksX, int numTicksY, double theta, double pivotX, double pivotY, boolean usePageFrame) { - ops.add(new Grid(x, y, width, height, numTicksX, numTicksY, theta, pivotX, pivotY, usePageFrame)); + + public Canvas drawGrid(double x, double y, double width, double height, int numTicksX, + int numTicksY, double theta, double pivotX, double pivotY, + boolean usePageFrame) { + ops.add(new Grid(x, y, width, height, numTicksX, numTicksY, theta, pivotX, pivotY, + usePageFrame)); return this; } diff --git a/DashboardCore/src/main/java/com/acmerobotics/dashboard/canvas/Grid.java b/DashboardCore/src/main/java/com/acmerobotics/dashboard/canvas/Grid.java index 85f76ff78..7521ee29e 100644 --- a/DashboardCore/src/main/java/com/acmerobotics/dashboard/canvas/Grid.java +++ b/DashboardCore/src/main/java/com/acmerobotics/dashboard/canvas/Grid.java @@ -8,7 +8,8 @@ public class Grid extends CanvasOp { private double theta, pivotX, pivotY; private boolean usePageFrame; - public Grid(double x, double y, double width, double height, int numTicksX, int numTicksY, double theta, double pivotX, double pivotY, boolean usePageFrame) { + public Grid(double x, double y, double width, double height, int numTicksX, int numTicksY, + double theta, double pivotX, double pivotY, boolean usePageFrame) { super(Type.GRID); this.x = x; diff --git a/DashboardCore/src/main/java/com/acmerobotics/dashboard/canvas/Image.java b/DashboardCore/src/main/java/com/acmerobotics/dashboard/canvas/Image.java index 3d66974b4..4810d9869 100644 --- a/DashboardCore/src/main/java/com/acmerobotics/dashboard/canvas/Image.java +++ b/DashboardCore/src/main/java/com/acmerobotics/dashboard/canvas/Image.java @@ -8,7 +8,8 @@ public class Image extends CanvasOp { private double theta, pivotX, pivotY; private boolean usePageFrame; - public Image(String path, double x, double y, double width, double height, double theta, double pivotX, double pivotY, boolean usePageFrame) { + public Image(String path, double x, double y, double width, double height, double theta, + double pivotX, double pivotY, boolean usePageFrame) { super(Type.IMAGE); this.path = path; diff --git a/DashboardCore/src/main/java/com/acmerobotics/dashboard/canvas/Rotation.java b/DashboardCore/src/main/java/com/acmerobotics/dashboard/canvas/Rotation.java index 8683cb2a6..a5d019cd0 100644 --- a/DashboardCore/src/main/java/com/acmerobotics/dashboard/canvas/Rotation.java +++ b/DashboardCore/src/main/java/com/acmerobotics/dashboard/canvas/Rotation.java @@ -2,6 +2,7 @@ public class Rotation extends CanvasOp { private double rotation; + public Rotation(double radians) { super(Type.ROTATION); diff --git a/DashboardCore/src/main/java/com/acmerobotics/dashboard/canvas/Text.java b/DashboardCore/src/main/java/com/acmerobotics/dashboard/canvas/Text.java index fc33e5633..9bd931df3 100644 --- a/DashboardCore/src/main/java/com/acmerobotics/dashboard/canvas/Text.java +++ b/DashboardCore/src/main/java/com/acmerobotics/dashboard/canvas/Text.java @@ -9,7 +9,8 @@ public class Text extends CanvasOp { private boolean stroke; private boolean usePageFrame; - public Text(String text, double x, double y, String font, double theta, boolean stroke, boolean usePageFrame) { + public Text(String text, double x, double y, String font, double theta, boolean stroke, + boolean usePageFrame) { super(Type.TEXT); this.text = text; this.x = x; diff --git a/DashboardCore/src/main/java/com/acmerobotics/dashboard/canvas/Translate.java b/DashboardCore/src/main/java/com/acmerobotics/dashboard/canvas/Translate.java index 429f2d924..bbc667c03 100644 --- a/DashboardCore/src/main/java/com/acmerobotics/dashboard/canvas/Translate.java +++ b/DashboardCore/src/main/java/com/acmerobotics/dashboard/canvas/Translate.java @@ -3,6 +3,7 @@ public class Translate extends CanvasOp { private double x; private double y; + public Translate(double x, double y) { super(Type.TRANSLATE); diff --git a/DashboardCore/src/main/java/com/acmerobotics/dashboard/config/ValueProvider.java b/DashboardCore/src/main/java/com/acmerobotics/dashboard/config/ValueProvider.java index edaa90c33..2c0e48047 100644 --- a/DashboardCore/src/main/java/com/acmerobotics/dashboard/config/ValueProvider.java +++ b/DashboardCore/src/main/java/com/acmerobotics/dashboard/config/ValueProvider.java @@ -2,6 +2,7 @@ /** * A generic interface for providing and storing a single value. + * * @param type of the value */ public interface ValueProvider { @@ -12,6 +13,7 @@ public interface ValueProvider { /** * Updates the value. {@link #get()} should now return this new value. + * * @param value */ void set(T value); diff --git a/DashboardCore/src/main/java/com/acmerobotics/dashboard/config/reflection/ArrayProvider.java b/DashboardCore/src/main/java/com/acmerobotics/dashboard/config/reflection/ArrayProvider.java index 74420ecf1..e89e3df63 100644 --- a/DashboardCore/src/main/java/com/acmerobotics/dashboard/config/reflection/ArrayProvider.java +++ b/DashboardCore/src/main/java/com/acmerobotics/dashboard/config/reflection/ArrayProvider.java @@ -1,7 +1,6 @@ package com.acmerobotics.dashboard.config.reflection; import com.acmerobotics.dashboard.config.ValueProvider; - import java.lang.reflect.Array; import java.lang.reflect.Field; @@ -9,11 +8,13 @@ public class ArrayProvider implements ValueProvider { private final Field field; private final Object parent; private final int[] indices; + public ArrayProvider(Field field, Object parent, int... indices) { this.field = field; this.parent = parent; this.indices = indices; } + @SuppressWarnings("unchecked") @Override public T get() { @@ -21,34 +22,34 @@ public T get() { return (T) getArrayRecursive(field.get(parent), indices); } catch (IllegalAccessException e) { throw new RuntimeException(e); - } catch(ArrayIndexOutOfBoundsException e) - { + } catch (ArrayIndexOutOfBoundsException e) { return null; } } + @Override public void set(T value) { try { setArrayRecursive(field.get(parent), value, indices); } catch (IllegalAccessException e) { throw new RuntimeException(e); - }catch(ArrayIndexOutOfBoundsException ignored) { } + } catch (ArrayIndexOutOfBoundsException ignored) { + } } - public static Object getArrayRecursive(Object object, int[] indices) throws ArrayIndexOutOfBoundsException, IllegalAccessException - { + public static Object getArrayRecursive(Object object, int[] indices) + throws ArrayIndexOutOfBoundsException, IllegalAccessException { for (int index : indices) { object = Array.get(object, index); } return object; } - public static void setArrayRecursive(Object object, Object value, int[] indices) - { - for(int i=0;i< indices.length-1;i++) - { - object=Array.get(object,indices[i]); + + public static void setArrayRecursive(Object object, Object value, int[] indices) { + for (int i = 0; i < indices.length - 1; i++) { + object = Array.get(object, indices[i]); } - Array.set(object,indices[indices.length-1], value); + Array.set(object, indices[indices.length - 1], value); } } diff --git a/DashboardCore/src/main/java/com/acmerobotics/dashboard/config/reflection/FieldProvider.java b/DashboardCore/src/main/java/com/acmerobotics/dashboard/config/reflection/FieldProvider.java index 47ad205c7..5a5a1b132 100644 --- a/DashboardCore/src/main/java/com/acmerobotics/dashboard/config/reflection/FieldProvider.java +++ b/DashboardCore/src/main/java/com/acmerobotics/dashboard/config/reflection/FieldProvider.java @@ -1,11 +1,11 @@ package com.acmerobotics.dashboard.config.reflection; import com.acmerobotics.dashboard.config.ValueProvider; - import java.lang.reflect.Field; /** * Value provider backed by a class field. + * * @param type of the class field */ public class FieldProvider implements ValueProvider { diff --git a/DashboardCore/src/main/java/com/acmerobotics/dashboard/config/reflection/ReflectionConfig.java b/DashboardCore/src/main/java/com/acmerobotics/dashboard/config/reflection/ReflectionConfig.java index 73fe6b791..db6d29eea 100644 --- a/DashboardCore/src/main/java/com/acmerobotics/dashboard/config/reflection/ReflectionConfig.java +++ b/DashboardCore/src/main/java/com/acmerobotics/dashboard/config/reflection/ReflectionConfig.java @@ -4,21 +4,21 @@ import com.acmerobotics.dashboard.config.variable.ConfigVariable; import com.acmerobotics.dashboard.config.variable.CustomVariable; import com.acmerobotics.dashboard.config.variable.VariableType; - import java.lang.reflect.Array; import java.lang.reflect.Field; import java.lang.reflect.Modifier; import java.util.Arrays; public class ReflectionConfig { - private ReflectionConfig() {} + private ReflectionConfig() { + } public static CustomVariable createVariableFromClass(Class configClass) { CustomVariable customVariable = new CustomVariable(); for (Field field : configClass.getFields()) { if (!Modifier.isStatic(field.getModifiers()) - || Modifier.isFinal(field.getModifiers())) { + || Modifier.isFinal(field.getModifiers())) { continue; } customVariable.putVariable(field.getName(), createVariableFromField(field, null)); @@ -26,7 +26,9 @@ public static CustomVariable createVariableFromClass(Class configClass) { return customVariable; } - private static ConfigVariable createVariableFromArrayField(Field field, Class fieldClass, Object parent, int[] indices) { + + private static ConfigVariable createVariableFromArrayField(Field field, Class fieldClass, + Object parent, int[] indices) { VariableType type = VariableType.fromClass(fieldClass); switch (type) { case BOOLEAN: @@ -34,14 +36,14 @@ private static ConfigVariable createVariableFromArrayField(Field field, Clas case DOUBLE: case STRING: case ENUM: - return new BasicVariable<>(type, new ArrayProvider(field, parent,Arrays.copyOf(indices, indices.length))); + return new BasicVariable<>(type, new ArrayProvider(field, parent, + Arrays.copyOf(indices, indices.length))); case CUSTOM: try { Object value = null; try { value = ArrayProvider.getArrayRecursive(field.get(parent), indices); - }catch (ArrayIndexOutOfBoundsException ignored ) - { + } catch (ArrayIndexOutOfBoundsException ignored) { } @@ -49,18 +51,17 @@ private static ConfigVariable createVariableFromArrayField(Field field, Clas return new CustomVariable(null); } CustomVariable customVariable = new CustomVariable(); - if(fieldClass.isArray()) - { - int[] newIndices = Arrays.copyOf(indices, indices.length+1); + if (fieldClass.isArray()) { + int[] newIndices = Arrays.copyOf(indices, indices.length + 1); - for(int i = 0; i createVariableFromArrayField(Field field, Clas String name = nestedField.getName(); customVariable.putVariable(name, - createVariableFromField(nestedField, value)); + createVariableFromField(nestedField, value)); } } return customVariable; @@ -77,9 +78,10 @@ private static ConfigVariable createVariableFromArrayField(Field field, Clas } default: throw new RuntimeException("Unsupported field type: " + - fieldClass.getName()); + fieldClass.getName()); } } + private static ConfigVariable createVariableFromField(Field field, Object parent) { Class fieldClass = field.getType(); VariableType type = VariableType.fromClass(fieldClass); @@ -97,14 +99,13 @@ private static ConfigVariable createVariableFromField(Field field, Object par return new CustomVariable(null); } CustomVariable customVariable = new CustomVariable(); - if(fieldClass.isArray()) - { - for(int i = 0; i createVariableFromField(Field field, Object par String name = nestedField.getName(); customVariable.putVariable(name, - createVariableFromField(nestedField, value)); + createVariableFromField(nestedField, value)); } } return customVariable; @@ -121,7 +122,7 @@ private static ConfigVariable createVariableFromField(Field field, Object par } default: throw new RuntimeException("Unsupported field type: " + - fieldClass.getName()); + fieldClass.getName()); } } } diff --git a/DashboardCore/src/main/java/com/acmerobotics/dashboard/config/variable/ConfigVariable.java b/DashboardCore/src/main/java/com/acmerobotics/dashboard/config/variable/ConfigVariable.java index 04897699d..1a67d4647 100644 --- a/DashboardCore/src/main/java/com/acmerobotics/dashboard/config/variable/ConfigVariable.java +++ b/DashboardCore/src/main/java/com/acmerobotics/dashboard/config/variable/ConfigVariable.java @@ -14,6 +14,7 @@ public abstract class ConfigVariable { // Set.of() is unfortunately unavailable private static final Set RESERVED_KEYS = new HashSet<>(); + static { RESERVED_KEYS.add(TYPE_KEY); RESERVED_KEYS.add(VALUE_KEY); diff --git a/DashboardCore/src/main/java/com/acmerobotics/dashboard/config/variable/ConfigVariableDeserializer.java b/DashboardCore/src/main/java/com/acmerobotics/dashboard/config/variable/ConfigVariableDeserializer.java index 4b7bc8de1..e56084028 100644 --- a/DashboardCore/src/main/java/com/acmerobotics/dashboard/config/variable/ConfigVariableDeserializer.java +++ b/DashboardCore/src/main/java/com/acmerobotics/dashboard/config/variable/ConfigVariableDeserializer.java @@ -6,7 +6,6 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParseException; - import java.lang.reflect.Type; import java.util.Map; @@ -14,20 +13,24 @@ public class ConfigVariableDeserializer implements JsonDeserializer deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) - throws JsonParseException { + throws JsonParseException { JsonObject obj = jsonElement.getAsJsonObject(); VariableType varType = jsonDeserializationContext.deserialize( - obj.get(ConfigVariable.TYPE_KEY), VariableType.class); + obj.get(ConfigVariable.TYPE_KEY), VariableType.class); JsonElement valueEl = obj.get(ConfigVariable.VALUE_KEY); switch (varType) { case BOOLEAN: - return new BasicVariable<>(varType, new ConstantProvider<>(valueEl.isJsonNull() ? null : valueEl.getAsBoolean())); + return new BasicVariable<>(varType, + new ConstantProvider<>(valueEl.isJsonNull() ? null : valueEl.getAsBoolean())); case INT: - return new BasicVariable<>(varType, new ConstantProvider<>(valueEl.isJsonNull() ? null : valueEl.getAsInt())); + return new BasicVariable<>(varType, + new ConstantProvider<>(valueEl.isJsonNull() ? null : valueEl.getAsInt())); case DOUBLE: - return new BasicVariable<>(varType, new ConstantProvider<>(valueEl.isJsonNull() ? null : valueEl.getAsDouble())); + return new BasicVariable<>(varType, + new ConstantProvider<>(valueEl.isJsonNull() ? null : valueEl.getAsDouble())); case STRING: - return new BasicVariable<>(varType, new ConstantProvider<>(valueEl.isJsonNull() ? null : valueEl.getAsString())); + return new BasicVariable<>(varType, + new ConstantProvider<>(valueEl.isJsonNull() ? null : valueEl.getAsString())); case ENUM: if (valueEl.isJsonNull()) { return new BasicVariable<>(varType, new ConstantProvider<>(null)); @@ -35,10 +38,10 @@ public ConfigVariable deserialize(JsonElement jsonElement, Type type, try { Class enumClass = Class.forName( - obj.get(ConfigVariable.ENUM_CLASS_KEY).getAsString()); + obj.get(ConfigVariable.ENUM_CLASS_KEY).getAsString()); return new BasicVariable<>(varType, new ConstantProvider<>( - jsonDeserializationContext.deserialize( - obj.get(ConfigVariable.VALUE_KEY), enumClass))); + jsonDeserializationContext.deserialize( + obj.get(ConfigVariable.VALUE_KEY), enumClass))); } catch (ClassNotFoundException e) { throw new RuntimeException(); } @@ -52,14 +55,14 @@ public ConfigVariable deserialize(JsonElement jsonElement, Type type, for (Map.Entry entry : valueObj.entrySet()) { JsonObject childObj = entry.getValue().getAsJsonObject(); VariableType childType = jsonDeserializationContext.deserialize( - childObj.get(ConfigVariable.TYPE_KEY), VariableType.class); + childObj.get(ConfigVariable.TYPE_KEY), VariableType.class); ConfigVariable child; if (childType == VariableType.CUSTOM) { child = jsonDeserializationContext.deserialize( - entry.getValue(), CustomVariable.class); + entry.getValue(), CustomVariable.class); } else { child = jsonDeserializationContext.deserialize( - entry.getValue(), BasicVariable.class); + entry.getValue(), BasicVariable.class); } customVariable.putVariable(entry.getKey(), child); diff --git a/DashboardCore/src/main/java/com/acmerobotics/dashboard/config/variable/ConfigVariableSerializer.java b/DashboardCore/src/main/java/com/acmerobotics/dashboard/config/variable/ConfigVariableSerializer.java index 6442c0f0d..f691532b5 100644 --- a/DashboardCore/src/main/java/com/acmerobotics/dashboard/config/variable/ConfigVariableSerializer.java +++ b/DashboardCore/src/main/java/com/acmerobotics/dashboard/config/variable/ConfigVariableSerializer.java @@ -6,7 +6,6 @@ import com.google.gson.JsonPrimitive; import com.google.gson.JsonSerializationContext; import com.google.gson.JsonSerializer; - import java.lang.reflect.Type; public class ConfigVariableSerializer implements JsonSerializer> { @@ -17,7 +16,7 @@ public JsonElement serialize(ConfigVariable configVariable, Type type, JsonObject obj = new JsonObject(); obj.add(ConfigVariable.TYPE_KEY, - jsonSerializationContext.serialize(configVariable.getType())); + jsonSerializationContext.serialize(configVariable.getType())); if (value == null) { obj.add(ConfigVariable.VALUE_KEY, null); @@ -28,12 +27,12 @@ public JsonElement serialize(ConfigVariable configVariable, Type type, obj.add(ConfigVariable.VALUE_KEY, new JsonPrimitive(String.valueOf(value))); } else { obj.add(ConfigVariable.VALUE_KEY, - jsonSerializationContext.serialize(value)); + jsonSerializationContext.serialize(value)); } if (configVariable.getType() == VariableType.ENUM) { obj.add(ConfigVariable.ENUM_CLASS_KEY, new JsonPrimitive( - value.getClass().getName())); + value.getClass().getName())); JsonArray values = new JsonArray(); for (Object o : value.getClass().getEnumConstants()) { values.add(o.toString()); diff --git a/DashboardCore/src/main/java/com/acmerobotics/dashboard/config/variable/VariableType.java b/DashboardCore/src/main/java/com/acmerobotics/dashboard/config/variable/VariableType.java index cf4f7a498..b11c16d8d 100644 --- a/DashboardCore/src/main/java/com/acmerobotics/dashboard/config/variable/VariableType.java +++ b/DashboardCore/src/main/java/com/acmerobotics/dashboard/config/variable/VariableType.java @@ -26,6 +26,7 @@ public enum VariableType { /** * Returns the variable type corresponding to the class provided. + * * @param klass */ public static VariableType fromClass(Class klass) { diff --git a/DashboardCore/src/main/java/com/acmerobotics/dashboard/message/Message.java b/DashboardCore/src/main/java/com/acmerobotics/dashboard/message/Message.java index bef7669e9..1f617d4b5 100644 --- a/DashboardCore/src/main/java/com/acmerobotics/dashboard/message/Message.java +++ b/DashboardCore/src/main/java/com/acmerobotics/dashboard/message/Message.java @@ -8,6 +8,7 @@ public class Message { /** * Creates a message. + * * @param type message type */ public Message(MessageType type) { diff --git a/DashboardCore/src/main/java/com/acmerobotics/dashboard/message/MessageDeserializer.java b/DashboardCore/src/main/java/com/acmerobotics/dashboard/message/MessageDeserializer.java index 811899759..05c4ec453 100644 --- a/DashboardCore/src/main/java/com/acmerobotics/dashboard/message/MessageDeserializer.java +++ b/DashboardCore/src/main/java/com/acmerobotics/dashboard/message/MessageDeserializer.java @@ -6,7 +6,6 @@ import com.google.gson.JsonObject; import com.google.gson.JsonParseException; import com.google.gson.reflect.TypeToken; - import java.lang.reflect.Type; /** @@ -16,10 +15,10 @@ public class MessageDeserializer implements JsonDeserializer { @Override public Message deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) - throws JsonParseException { + throws JsonParseException { JsonObject messageObj = jsonElement.getAsJsonObject(); MessageType messageType = jsonDeserializationContext.deserialize( - messageObj.get("type"), MessageType.class); + messageObj.get("type"), MessageType.class); if (messageType == null || messageType.msgClass == null) { return null; } diff --git a/DashboardCore/src/main/java/com/acmerobotics/dashboard/message/redux/ReceiveOpModeList.java b/DashboardCore/src/main/java/com/acmerobotics/dashboard/message/redux/ReceiveOpModeList.java index 8379ae105..e3b62ff4d 100644 --- a/DashboardCore/src/main/java/com/acmerobotics/dashboard/message/redux/ReceiveOpModeList.java +++ b/DashboardCore/src/main/java/com/acmerobotics/dashboard/message/redux/ReceiveOpModeList.java @@ -2,7 +2,6 @@ import com.acmerobotics.dashboard.message.Message; import com.acmerobotics.dashboard.message.MessageType; - import java.util.List; public class ReceiveOpModeList extends Message { diff --git a/DashboardCore/src/main/java/com/acmerobotics/dashboard/message/redux/ReceiveTelemetry.java b/DashboardCore/src/main/java/com/acmerobotics/dashboard/message/redux/ReceiveTelemetry.java index f8c03b3c8..7e2048c08 100644 --- a/DashboardCore/src/main/java/com/acmerobotics/dashboard/message/redux/ReceiveTelemetry.java +++ b/DashboardCore/src/main/java/com/acmerobotics/dashboard/message/redux/ReceiveTelemetry.java @@ -3,7 +3,6 @@ import com.acmerobotics.dashboard.message.Message; import com.acmerobotics.dashboard.message.MessageType; import com.acmerobotics.dashboard.telemetry.TelemetryPacket; - import java.util.List; public class ReceiveTelemetry extends Message { diff --git a/DashboardCore/src/main/java/com/acmerobotics/dashboard/telemetry/TelemetryPacket.java b/DashboardCore/src/main/java/com/acmerobotics/dashboard/telemetry/TelemetryPacket.java index a2d38705e..a33621ea2 100644 --- a/DashboardCore/src/main/java/com/acmerobotics/dashboard/telemetry/TelemetryPacket.java +++ b/DashboardCore/src/main/java/com/acmerobotics/dashboard/telemetry/TelemetryPacket.java @@ -1,7 +1,6 @@ package com.acmerobotics.dashboard.telemetry; import com.acmerobotics.dashboard.canvas.Canvas; - import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -19,6 +18,7 @@ public class TelemetryPacket { private Canvas fieldOverlay; private static final Canvas DEFAULT_FIELD = new Canvas(); + static { DEFAULT_FIELD.setAlpha(0.4); DEFAULT_FIELD.drawImage("/dash/centerstage.webp", 0, 0, 144, 144); @@ -45,6 +45,7 @@ public TelemetryPacket() { /** * Stores a single key-value pair. + * * @param key * @param value */ @@ -54,6 +55,7 @@ public void put(String key, Object value) { /** * Stores all entries of the provided map. + * * @param map */ public void putAll(Map map) { @@ -64,6 +66,7 @@ public void putAll(Map map) { /** * Adds a line to the telemetry log. + * * @param line */ public void addLine(String line) { diff --git a/DashboardCore/src/test/java/com/acmerobotics/dashboard/SerializationTests.java b/DashboardCore/src/test/java/com/acmerobotics/dashboard/SerializationTests.java index 425661910..0619f25d3 100644 --- a/DashboardCore/src/test/java/com/acmerobotics/dashboard/SerializationTests.java +++ b/DashboardCore/src/test/java/com/acmerobotics/dashboard/SerializationTests.java @@ -2,16 +2,12 @@ import static org.junit.jupiter.api.Assertions.assertTrue; -import com.acmerobotics.dashboard.DashboardCore; -import com.acmerobotics.dashboard.RobotStatus; import com.acmerobotics.dashboard.config.reflection.ReflectionConfig; import com.acmerobotics.dashboard.config.variable.BasicVariable; import com.acmerobotics.dashboard.config.variable.ConfigVariable; import com.acmerobotics.dashboard.config.variable.CustomVariable; - -import org.junit.jupiter.api.Test; - import java.util.Map; +import org.junit.jupiter.api.Test; public class SerializationTests { diff --git a/DashboardCore/src/test/java/com/acmerobotics/dashboard/TestDashboardInstance.java b/DashboardCore/src/test/java/com/acmerobotics/dashboard/TestDashboardInstance.java index 3fb819ebf..7b1061069 100644 --- a/DashboardCore/src/test/java/com/acmerobotics/dashboard/TestDashboardInstance.java +++ b/DashboardCore/src/test/java/com/acmerobotics/dashboard/TestDashboardInstance.java @@ -1,9 +1,5 @@ package com.acmerobotics.dashboard; -import com.acmerobotics.dashboard.DashboardCore; -import com.acmerobotics.dashboard.RobotStatus; -import com.acmerobotics.dashboard.SendFun; -import com.acmerobotics.dashboard.SocketHandler; import com.acmerobotics.dashboard.config.ValueProvider; import com.acmerobotics.dashboard.message.Message; import com.acmerobotics.dashboard.message.redux.InitOpMode; @@ -12,12 +8,10 @@ import com.acmerobotics.dashboard.telemetry.TelemetryPacket; import com.acmerobotics.dashboard.testopmode.TestOpMode; import com.acmerobotics.dashboard.testopmode.TestOpModeManager; - -import java.io.IOException; -import java.util.stream.Collectors; - import fi.iki.elonen.NanoHTTPD; import fi.iki.elonen.NanoWSD; +import java.io.IOException; +import java.util.stream.Collectors; enum TestEnum { Value1, @@ -65,15 +59,16 @@ protected void onOpen() { opModeManager.setSendFun(this); send(new ReceiveOpModeList( - opModeManager - .getTestOpModes() - .stream().map(TestOpMode::getName) - .collect(Collectors.toList()) + opModeManager + .getTestOpModes() + .stream().map(TestOpMode::getName) + .collect(Collectors.toList()) )); } @Override - protected void onClose(NanoWSD.WebSocketFrame.CloseCode code, String reason, boolean initiatedByRemote) { + protected void onClose(NanoWSD.WebSocketFrame.CloseCode code, String reason, + boolean initiatedByRemote) { sh.onClose(); opModeManager.clearSendFun(); @@ -101,7 +96,7 @@ protected void onMessage(NanoWSD.WebSocketFrame message) { } send(new ReceiveRobotStatus( - new RobotStatus(core.enabled, true, opModeName, opModeStatus, "", "") + new RobotStatus(core.enabled, true, opModeName, opModeStatus, "", "") )); break; } @@ -209,7 +204,7 @@ public void update() { } } - public void sendTelemetryPacket(TelemetryPacket t){ + public void sendTelemetryPacket(TelemetryPacket t) { core.sendTelemetryPacket(t); } } diff --git a/DashboardCore/src/test/java/com/acmerobotics/dashboard/TestFieldVersatilityOpMode.java b/DashboardCore/src/test/java/com/acmerobotics/dashboard/TestFieldVersatilityOpMode.java index 04aa37aed..b17933721 100644 --- a/DashboardCore/src/test/java/com/acmerobotics/dashboard/TestFieldVersatilityOpMode.java +++ b/DashboardCore/src/test/java/com/acmerobotics/dashboard/TestFieldVersatilityOpMode.java @@ -17,7 +17,8 @@ public class TestFieldVersatilityOpMode extends TestOpMode { public static double SPIN_FREQUENCY = 0.25; public static double ORBITAL_RADIUS = 50; public static double SIDE_LENGTH = 10; - public static String ALTIMGSRC = "https://upload.wikimedia.org/wikipedia/commons/4/45/Football_field.svg"; + public static String ALTIMGSRC = + "https://upload.wikimedia.org/wikipedia/commons/4/45/Football_field.svg"; //public static String ALTIMGSRC = "dist/assets/play_arrow.95e2d7e4.svg"; public static double ALTIMGX = 0; //try 24 public static double ALTIMGY = 0; //try 24 @@ -52,19 +53,20 @@ public TestFieldVersatilityOpMode() { @Override protected void init() { dashboard = TestDashboardInstance.getInstance(); - dashboard.core.addConfigVariable("Test", "ORIGIN_HEADING_OFFSET", new ValueProvider() { - private double x; - - @Override - public Double get() { - return x; - } - - @Override - public void set(Double value) { - x = value; - } - }); + dashboard.core.addConfigVariable("Test", "ORIGIN_HEADING_OFFSET", + new ValueProvider() { + private double x; + + @Override + public Double get() { + return x; + } + + @Override + public void set(Double value) { + x = value; + } + }); dashboard.core.addConfigVariable("Test", "RED_ALLIANCE", new ValueProvider() { private boolean red; @@ -103,7 +105,7 @@ protected void loop() throws InterruptedException { byPoints[i] += by; } dashboard.addData("x", AMPLITUDE * Math.sin( - 2 * Math.PI * FREQUENCY * (System.currentTimeMillis() / 1000d) + Math.toRadians(PHASE) + 2 * Math.PI * FREQUENCY * (System.currentTimeMillis() / 1000d) + Math.toRadians(PHASE) )); dashboard.addData("theta", angleAnim); dashboard.update(); @@ -126,7 +128,8 @@ protected void loop() throws InterruptedException { //this will be drawn in the pageFrame orientation .drawGrid(0, 0, 144, 144, 7, 7) //disabling the pageFrame will draw a grid in the current transform - .drawGrid(GRIDX, GRIDY, GRIDW, GRIDH, GRID_LINESX, GRID_LINESY, Math.toRadians(GRID_THETA_DEGREES), GRID_PIVOTX, GRID_PIVOTY, GRID_USE_PAGE_FRAME) + .drawGrid(GRIDX, GRIDY, GRIDW, GRIDH, GRID_LINESX, GRID_LINESY, + Math.toRadians(GRID_THETA_DEGREES), GRID_PIVOTX, GRID_PIVOTY, GRID_USE_PAGE_FRAME) //.drawGrid(GRIDX, GRIDY, GRIDW, GRIDH, GRID_LINESX, GRID_LINESY, angleAnim, GRID_PIVOTX, GRID_PIVOTY, GRID_USE_PAGE_FRAME) //you can draw multiple images and can rotate them around a specified anchor/pivot point and draw them in the current transform instead of the page frame @@ -150,7 +153,8 @@ protected void loop() throws InterruptedException { .setStroke("green") .strokeLine(0, 0, 0, 24) //y axis .setFill("green") - .strokeText("Y axis", 0, (RED_ALLIANCE ? 24 : 0), "8px serif", -Math.PI / 2 * (RED_ALLIANCE ? -1 : 1), false) + .strokeText("Y axis", 0, (RED_ALLIANCE ? 24 : 0), "8px serif", + -Math.PI / 2 * (RED_ALLIANCE ? -1 : 1), false) .setStroke("red") .strokeLine(0, 0, 24, 0) //x axis .setFill("red") diff --git a/DashboardCore/src/test/java/com/acmerobotics/dashboard/TestSineWaveOpMode.java b/DashboardCore/src/test/java/com/acmerobotics/dashboard/TestSineWaveOpMode.java index f67f940d2..b4f80fc3c 100644 --- a/DashboardCore/src/test/java/com/acmerobotics/dashboard/TestSineWaveOpMode.java +++ b/DashboardCore/src/test/java/com/acmerobotics/dashboard/TestSineWaveOpMode.java @@ -9,7 +9,7 @@ public class TestSineWaveOpMode extends TestOpMode { public static double FREQUENCY = 0.25; - public TestSineWaveOpMode(){ + public TestSineWaveOpMode() { super("TestSineWaveOpMode"); } @@ -21,7 +21,7 @@ protected void init() { @Override protected void loop() throws InterruptedException { dashboard.addData("x", AMPLITUDE * Math.sin( - 2 * Math.PI * FREQUENCY * (System.currentTimeMillis() / 1000d) + Math.toRadians(PHASE) + 2 * Math.PI * FREQUENCY * (System.currentTimeMillis() / 1000d) + Math.toRadians(PHASE) )); dashboard.update(); Thread.sleep(10); diff --git a/DashboardCore/src/test/java/com/acmerobotics/dashboard/testopmode/TestOpModeManager.java b/DashboardCore/src/test/java/com/acmerobotics/dashboard/testopmode/TestOpModeManager.java index 41f1cc4d9..6c72e4c46 100644 --- a/DashboardCore/src/test/java/com/acmerobotics/dashboard/testopmode/TestOpModeManager.java +++ b/DashboardCore/src/test/java/com/acmerobotics/dashboard/testopmode/TestOpModeManager.java @@ -1,14 +1,14 @@ package com.acmerobotics.dashboard.testopmode; import com.acmerobotics.dashboard.SendFun; -import com.acmerobotics.dashboard.TestSineWaveOpMode; import com.acmerobotics.dashboard.TestFieldVersatilityOpMode; - +import com.acmerobotics.dashboard.TestSineWaveOpMode; import java.util.Arrays; import java.util.List; public class TestOpModeManager { - private final List testOpModes = Arrays.asList(new TestSineWaveOpMode(), new TestFieldVersatilityOpMode()); + private final List testOpModes = + Arrays.asList(new TestSineWaveOpMode(), new TestFieldVersatilityOpMode()); private TestOpMode activeOpMode = null; SendFun sendFun; @@ -22,8 +22,9 @@ public TestOpMode getActiveOpMode() { } public void initOpMode(String opModeName) { - if (activeOpMode != null) + if (activeOpMode != null) { activeOpMode.internalStop(); + } for (TestOpMode opMode : testOpModes) { if (opMode.getName().equals(opModeName)) { @@ -37,13 +38,17 @@ public void initOpMode(String opModeName) { } public void startOpMode() { - if (activeOpMode == null) return; + if (activeOpMode == null) { + return; + } activeOpMode.internalStart(); } public void stopOpMode() { - if (activeOpMode == null) return; + if (activeOpMode == null) { + return; + } activeOpMode.internalStop(); activeOpMode = null; diff --git a/FtcDashboard/src/main/java/com/acmerobotics/dashboard/FtcDashboard.java b/FtcDashboard/src/main/java/com/acmerobotics/dashboard/FtcDashboard.java index ff5b4cf54..e6696becb 100644 --- a/FtcDashboard/src/main/java/com/acmerobotics/dashboard/FtcDashboard.java +++ b/FtcDashboard/src/main/java/com/acmerobotics/dashboard/FtcDashboard.java @@ -13,8 +13,6 @@ import android.view.MenuItem; import android.widget.LinearLayout; import android.widget.TextView; - -import com.acmerobotics.dashboard.canvas.Canvas; import com.acmerobotics.dashboard.config.Config; import com.acmerobotics.dashboard.config.ValueProvider; import com.acmerobotics.dashboard.config.reflection.ReflectionConfig; @@ -38,7 +36,19 @@ import com.qualcomm.robotcore.util.ThreadPool; import com.qualcomm.robotcore.util.WebHandlerManager; import com.qualcomm.robotcore.util.WebServer; - +import dalvik.system.DexFile; +import fi.iki.elonen.NanoHTTPD; +import fi.iki.elonen.NanoWSD; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.ExecutorService; import org.firstinspires.ftc.ftccommon.external.OnCreate; import org.firstinspires.ftc.ftccommon.external.OnCreateEventLoop; import org.firstinspires.ftc.ftccommon.external.OnCreateMenu; @@ -57,21 +67,6 @@ import org.firstinspires.ftc.robotcore.internal.webserver.WebHandler; import org.firstinspires.ftc.robotserver.internal.webserver.MimeTypesUtil; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.ExecutorService; - -import dalvik.system.DexFile; -import fi.iki.elonen.NanoHTTPD; -import fi.iki.elonen.NanoWSD; - /** * Main class for interacting with the instance. */ @@ -134,6 +129,7 @@ public static void attachEventLoop(Context context, FtcEventLoop eventLoop) { /** * Populates the menu with dashboard enable/disable options. + * * @param menu menu */ @OnCreateMenu @@ -148,7 +144,8 @@ public static void populateMenu(Context context, Menu menu) { */ @OnDestroy public static void stop(Context context) { - if (!FtcRobotControllerWatchdogService.isLaunchActivity(AppUtil.getInstance().getRootActivity())) { + if (!FtcRobotControllerWatchdogService.isLaunchActivity( + AppUtil.getInstance().getRootActivity())) { // prevent premature stop when the app is launched via hardware attachment return; } @@ -161,6 +158,7 @@ public static void stop(Context context) { /** * Returns the active instance instance. This should be called after {@link #start(Context)}. + * * @return active instance instance or null outside of its lifecycle */ public static FtcDashboard getInstance() { @@ -171,20 +169,22 @@ public static FtcDashboard getInstance() { private NanoWSD server = new NanoWSD(8000) { @Override - protected NanoWSD.WebSocket openWebSocket (NanoHTTPD.IHTTPSession handshake){ + protected NanoWSD.WebSocket openWebSocket(NanoHTTPD.IHTTPSession handshake) { return new DashWebSocket(handshake); } }; private SharedPreferences prefs; - private final List enableMenuItems, disableMenuItems; + private final List enableMenuItems; + private final List disableMenuItems; private Telemetry telemetry = new TelemetryAdapter(); private ExecutorService cameraStreamExecutor; private int imageQuality = DEFAULT_IMAGE_QUALITY; - private final List varsToRemove = new ArrayList<>(); // only modified inside withConfigRoot + // only modified inside withConfigRoot + private final List varsToRemove = new ArrayList<>(); private FtcEventLoop eventLoop; private OpModeManagerImpl opModeManager; @@ -221,8 +221,8 @@ public void run() { }); lastGamepadTimestamp = 0; } else { - Thread.sleep(GAMEPAD_WATCHDOG_INTERVAL - - (timestamp - lastGamepadTimestamp)); + Thread.sleep(GAMEPAD_WATCHDOG_INTERVAL + - (timestamp - lastGamepadTimestamp)); } } catch (InterruptedException e) { break; @@ -460,7 +460,7 @@ private CameraStreamRunnable(CameraStreamSource source, double maxFps) { public void run() { while (!Thread.currentThread().isInterrupted()) { try { - long timestamp = System.currentTimeMillis(); + final long timestamp = System.currentTimeMillis(); if (core.clientCount() == 0) { Thread.sleep(250); @@ -482,8 +482,8 @@ public void accept(Bitmap value) { continue; } - long sleepTime = (long) (1000 / maxFps - - (System.currentTimeMillis() - timestamp)); + long sleepTime = (long) (1000 / maxFps + - (System.currentTimeMillis() - timestamp)); Thread.sleep(Math.max(sleepTime, 0)); } catch (InterruptedException e) { Thread.currentThread().interrupt(); @@ -493,12 +493,12 @@ public void accept(Bitmap value) { } private static final Set IGNORED_PACKAGES = new HashSet<>(Arrays.asList( - "java", - "android", - "com.sun", - "com.vuforia", - "com.google", - "kotlin" + "java", + "android", + "com.sun", + "com.vuforia", + "com.google", + "kotlin" )); private static void addConfigClasses(CustomVariable customVariable) { @@ -527,7 +527,7 @@ private static void addConfigClasses(CustomVariable customVariable) { Class configClass = Class.forName(className, false, classLoader); if (!configClass.isAnnotationPresent(Config.class) - || configClass.isAnnotationPresent(Disabled.class)) { + || configClass.isAnnotationPresent(Disabled.class)) { continue; } @@ -537,7 +537,8 @@ private static void addConfigClasses(CustomVariable customVariable) { name = altName; } - customVariable.putVariable(name, ReflectionConfig.createVariableFromClass(configClass)); + customVariable.putVariable(name, + ReflectionConfig.createVariableFromClass(configClass)); } catch (ClassNotFoundException | NoClassDefFoundError ignored) { // dash is unable to access many classes and reporting every instance // only clutters the logs @@ -581,7 +582,8 @@ protected void onOpen() { } @Override - protected void onClose(NanoWSD.WebSocketFrame.CloseCode code, String reason, boolean initiatedByRemote) { + protected void onClose(NanoWSD.WebSocketFrame.CloseCode code, String reason, + boolean initiatedByRemote) { sh.onClose(); updateStatusView(); @@ -670,12 +672,14 @@ private boolean getAutoEnable() { private void setAutoEnable(boolean autoEnable) { prefs.edit() - .putBoolean(PREFS_AUTO_ENABLE_KEY, autoEnable) - .apply(); + .putBoolean(PREFS_AUTO_ENABLE_KEY, autoEnable) + .apply(); } private void enable() { - if (core.enabled) return; + if (core.enabled) { + return; + } setAutoEnable(true); @@ -688,7 +692,9 @@ private void enable() { } private void disable() { - if (!core.enabled) return; + if (!core.enabled) { + return; + } setAutoEnable(false); @@ -704,28 +710,30 @@ private void disable() { private void injectStatusView() { Activity activity = AppUtil.getInstance().getActivity(); - if (activity == null) return; + if (activity == null) { + return; + } connectionStatusTextView = new TextView(activity); connectionStatusTextView.setTypeface(Typeface.DEFAULT_BOLD); int color = activity.getResources().getColor(R.color.dashboardColor); connectionStatusTextView.setTextColor(color); int horizontalMarginId = activity.getResources().getIdentifier( - "activity_horizontal_margin", "dimen", activity.getPackageName()); + "activity_horizontal_margin", "dimen", activity.getPackageName()); int horizontalMargin = (int) activity.getResources().getDimension(horizontalMarginId); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( - LinearLayout.LayoutParams.MATCH_PARENT, - LinearLayout.LayoutParams.WRAP_CONTENT + LinearLayout.LayoutParams.MATCH_PARENT, + LinearLayout.LayoutParams.WRAP_CONTENT ); params.setMargins(horizontalMargin, 0, horizontalMargin, 0); connectionStatusTextView.setLayoutParams(params); int parentLayoutId = activity.getResources().getIdentifier( - "entire_screen", "id", activity.getPackageName()); + "entire_screen", "id", activity.getPackageName()); parentLayout = activity.findViewById(parentLayoutId); int childCount = parentLayout.getChildCount(); int relativeLayoutId = activity.getResources().getIdentifier( - "RelativeLayout", "id", activity.getPackageName()); + "RelativeLayout", "id", activity.getPackageName()); int i; for (i = 0; i < childCount; i++) { if (parentLayout.getChildAt(i).getId() == relativeLayoutId) { @@ -777,7 +785,8 @@ public void run() { connStatus = connections + " connections"; } - connectionStatusTextView.setText("Dashboard: " + serverStatus + ", " + connStatus); + connectionStatusTextView.setText( + "Dashboard: " + serverStatus + ", " + connStatus); } }); } @@ -787,14 +796,14 @@ private WebHandler newStaticAssetHandler(final AssetManager assetManager, final return new WebHandler() { @Override public NanoHTTPD.Response getResponse(NanoHTTPD.IHTTPSession session) - throws IOException { + throws IOException { if (session.getMethod() == NanoHTTPD.Method.GET) { String mimeType = MimeTypesUtil.determineMimeType(file); return NanoHTTPD.newChunkedResponse(NanoHTTPD.Response.Status.OK, - mimeType, assetManager.open(file)); + mimeType, assetManager.open(file)); } else { return NanoHTTPD.newFixedLengthResponse(NanoHTTPD.Response.Status.NOT_FOUND, - NanoHTTPD.MIME_PLAINTEXT, ""); + NanoHTTPD.MIME_PLAINTEXT, ""); } } }; @@ -805,7 +814,9 @@ private void addAssetWebHandlers(WebHandlerManager webHandlerManager, try { String[] list = assetManager.list(path); - if (list == null) return; + if (list == null) { + return; + } if (list.length > 0) { for (String file : list) { @@ -813,7 +824,7 @@ private void addAssetWebHandlers(WebHandlerManager webHandlerManager, } } else { webHandlerManager.register("/" + path, - newStaticAssetHandler(assetManager, path)); + newStaticAssetHandler(assetManager, path)); } } catch (IOException e) { Log.w(TAG, e); @@ -821,18 +832,22 @@ private void addAssetWebHandlers(WebHandlerManager webHandlerManager, } private void internalAttachWebServer(WebServer webServer) { - if (webServer == null) return; + if (webServer == null) { + return; + } Activity activity = AppUtil.getInstance().getActivity(); - if (activity == null) return; + if (activity == null) { + return; + } WebHandlerManager webHandlerManager = webServer.getWebHandlerManager(); AssetManager assetManager = activity.getAssets(); webHandlerManager.register("/dash", - newStaticAssetHandler(assetManager, "dash/index.html")); + newStaticAssetHandler(assetManager, "dash/index.html")); webHandlerManager.register("/dash/", - newStaticAssetHandler(assetManager, "dash/index.html")); + newStaticAssetHandler(assetManager, "dash/index.html")); addAssetWebHandlers(webHandlerManager, assetManager, "dash"); addAssetWebHandlers(webHandlerManager, assetManager, "images"); @@ -919,31 +934,33 @@ public boolean onMenuItemClick(MenuItem item) { private void internalRegisterOpMode(OpModeManager manager) { manager.register( - new OpModeMeta.Builder() - .setName("Enable/Disable Dashboard") - .setFlavor(OpModeMeta.Flavor.TELEOP) - .setGroup("dash") - .build(), - new LinearOpMode() { - @Override - public void runOpMode() throws InterruptedException { - telemetry.log().add(Misc.formatInvariant("Dashboard is currently %s. Press Start to %s it.", - core.enabled ? "enabled" : "disabled", core.enabled ? "disable" : "enable")); - telemetry.update(); + new OpModeMeta.Builder() + .setName("Enable/Disable Dashboard") + .setFlavor(OpModeMeta.Flavor.TELEOP) + .setGroup("dash") + .build(), + new LinearOpMode() { + @Override + public void runOpMode() throws InterruptedException { + telemetry.log().add( + Misc.formatInvariant("Dashboard is currently %s. Press Start to %s it.", + core.enabled ? "enabled" : "disabled", + core.enabled ? "disable" : "enable")); + telemetry.update(); - waitForStart(); + waitForStart(); - if (isStopRequested()) { - return; - } - - if (core.enabled) { - disable(); - } else { - enable(); - } - } - }); + if (isStopRequested()) { + return; + } + + if (core.enabled) { + disable(); + } else { + enable(); + } + } + }); } /** @@ -983,6 +1000,7 @@ public int getTelemetryTransmissionInterval() { /** * Sets the telemetry transmission interval. + * * @param newTransmissionInterval transmission interval in milliseconds */ public void setTelemetryTransmissionInterval(int newTransmissionInterval) { @@ -1000,9 +1018,9 @@ public void updateConfig() { * Executes {@param function} in an exclusive context for thread-safe config tree modification * and calls {@link #updateConfig()} to keep clients up to date. * - * Do not leak the config tree outside the function. + *

Do not leak the config tree outside the function. * - * @param function + * @param function custom variable consumer */ public void withConfigRoot(CustomVariableConsumer function) { core.withConfigRoot(function); @@ -1010,10 +1028,11 @@ public void withConfigRoot(CustomVariableConsumer function) { /** * Add config variable with custom provider that is automatically removed when op mode ends. + * * @param category top-level category - * @param name variable name + * @param name variable name * @param provider getter/setter for the variable - * @param variable type + * @param variable type */ public void addConfigVariable(String category, String name, ValueProvider provider) { core.addConfigVariable(category, name, provider); @@ -1021,13 +1040,15 @@ public void addConfigVariable(String category, String name, ValueProvider /** * Add config variable with custom provider. - * @param category top-level category - * @param name variable name - * @param provider getter/setter for the variable + * + * @param category top-level category + * @param name variable name + * @param provider getter/setter for the variable * @param autoRemove if true, the variable is removed on op mode termination - * @param variable type + * @param variable type */ - public void addConfigVariable(final String category, final String name, final ValueProvider provider, + public void addConfigVariable(final String category, final String name, + final ValueProvider provider, final boolean autoRemove) { withConfigRoot(new CustomVariableConsumer() { @Override @@ -1035,7 +1056,7 @@ public void accept(CustomVariable configRoot) { core.addConfigVariable(category, name, provider); if (autoRemove) { - varsToRemove.add(new String[]{category, name}); + varsToRemove.add(new String[] {category, name}); } } }); @@ -1043,8 +1064,9 @@ public void accept(CustomVariable configRoot) { /** * Remove a config variable. + * * @param category top-level category - * @param name variable name + * @param name variable name */ public void removeConfigVariable(String category, String name) { core.removeConfigVariable(category, name); @@ -1053,6 +1075,7 @@ public void removeConfigVariable(String category, String name) { /** * Sends an image to the dashboard for display (MJPEG style). Note that the encoding process is * synchronous. Stops the active stream if running. + * * @param bitmap bitmap to send */ public void sendImage(Bitmap bitmap) { @@ -1067,6 +1090,7 @@ public void sendImage(Bitmap bitmap) { /** * Sends a stream of camera frames at a regular interval. + * * @param source camera stream source * @param maxFps maximum frames per second; 0 indicates unlimited */ @@ -1093,7 +1117,7 @@ public void stopCameraStream() { /** * Returns the image quality used by {@link #sendImage(Bitmap)} and - * {@link #startCameraStream(CameraStreamSource, double)} + * {@link #startCameraStream(CameraStreamSource, double)}. */ public int getImageQuality() { return imageQuality; @@ -1101,7 +1125,7 @@ public int getImageQuality() { /** * Sets the image quality used by {@link #sendImage(Bitmap)} and - * {@link #startCameraStream(CameraStreamSource, double)} + * {@link #startCameraStream(CameraStreamSource, double)}. */ public void setImageQuality(int quality) { imageQuality = quality; @@ -1139,15 +1163,16 @@ public static void copyIntoSdkGamepad(ReceiveGamepadState.Gamepad src, Gamepad d dst.touchpad = src.touchpad; } - private void updateGamepads(ReceiveGamepadState.Gamepad gamepad1, ReceiveGamepadState.Gamepad gamepad2) { + private void updateGamepads(ReceiveGamepadState.Gamepad gamepad1, + ReceiveGamepadState.Gamepad gamepad2) { activeOpMode.with(o -> { // for now, the dashboard only overrides synthetic gamepads if (o.status == RobotStatus.OpModeStatus.STOPPED) { return; } - if (o.opMode.gamepad1.getGamepadId() != Gamepad.ID_UNASSOCIATED || - o.opMode.gamepad2.getGamepadId() != Gamepad.ID_UNASSOCIATED) { + if (o.opMode.gamepad1.getGamepadId() != Gamepad.ID_UNASSOCIATED + || o.opMode.gamepad2.getGamepadId() != Gamepad.ID_UNASSOCIATED) { return; } @@ -1159,14 +1184,15 @@ private void updateGamepads(ReceiveGamepadState.Gamepad gamepad1, ReceiveGamepad private RobotStatus getRobotStatus() { if (opModeManager == null) { - return new RobotStatus(core.enabled, false, "", RobotStatus.OpModeStatus.STOPPED, "", ""); + return new RobotStatus(core.enabled, false, "", RobotStatus.OpModeStatus.STOPPED, "", + ""); } else { return activeOpMode.with(o -> { return new RobotStatus( - core.enabled, true, opModeManager.getActiveOpModeName(), - // status is an enum so it's okay to return a copy here. - o.status, - RobotLog.getGlobalWarningMessage().message, RobotLog.getGlobalErrorMsg() + core.enabled, true, opModeManager.getActiveOpModeName(), + // status is an enum so it's okay to return a copy here. + o.status, + RobotLog.getGlobalWarningMessage().message, RobotLog.getGlobalErrorMsg() ); }); } @@ -1224,7 +1250,8 @@ public void accept(CustomVariable configRoot) { for (String[] var : varsToRemove) { String category = var[0]; String name = var[1]; - CustomVariable catVar = (CustomVariable) configRoot.getVariable(category); + CustomVariable catVar = + (CustomVariable) configRoot.getVariable(category); catVar.removeVariable(name); if (catVar.size() == 0) { configRoot.removeVariable(category); diff --git a/FtcDashboard/src/main/java/com/acmerobotics/dashboard/telemetry/MultipleTelemetry.java b/FtcDashboard/src/main/java/com/acmerobotics/dashboard/telemetry/MultipleTelemetry.java index ccd189580..aae37a221 100644 --- a/FtcDashboard/src/main/java/com/acmerobotics/dashboard/telemetry/MultipleTelemetry.java +++ b/FtcDashboard/src/main/java/com/acmerobotics/dashboard/telemetry/MultipleTelemetry.java @@ -1,13 +1,11 @@ package com.acmerobotics.dashboard.telemetry; import androidx.annotation.Nullable; - -import org.firstinspires.ftc.robotcore.external.Func; -import org.firstinspires.ftc.robotcore.external.Telemetry; - import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import org.firstinspires.ftc.robotcore.external.Func; +import org.firstinspires.ftc.robotcore.external.Telemetry; /** * Delegate for a list of multiple telemetry objects. @@ -26,6 +24,7 @@ public MultipleTelemetry(Telemetry... telemetryList) { /** * Adds another telemetry object. + * * @param telemetry */ public void addTelemetry(Telemetry telemetry) { diff --git a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/ArrayTestOpMode.java b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/ArrayTestOpMode.java index 6bdb0dc23..8bca6be85 100644 --- a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/ArrayTestOpMode.java +++ b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/ArrayTestOpMode.java @@ -11,18 +11,20 @@ @TeleOp public class ArrayTestOpMode extends LinearOpMode { public static class NestedClass { - public int a,b; + public int a, b; } + public static int[] array = new int[3]; - public static NestedClass[] innerArray = new NestedClass[] { new NestedClass(), new NestedClass(), new NestedClass()}; + public static NestedClass[] innerArray = + new NestedClass[] {new NestedClass(), new NestedClass(), new NestedClass()}; + @Override public void runOpMode() { telemetry = new MultipleTelemetry(telemetry, FtcDashboard.getInstance().getTelemetry()); waitForStart(); - array=new int[2]; - while(opModeIsActive()) - { + array = new int[2]; + while (opModeIsActive()) { telemetry.addData("array0", array[0]); telemetry.addData("array1", array[1]); telemetry.addData("innerArray0A", innerArray[0].a); diff --git a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/FieldVersatilityOpMode.java b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/FieldVersatilityOpMode.java index 14516496b..943e65611 100644 --- a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/FieldVersatilityOpMode.java +++ b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/FieldVersatilityOpMode.java @@ -23,7 +23,8 @@ public class FieldVersatilityOpMode extends LinearOpMode { public static double SPIN_FREQUENCY = 0.25; public static double ORBITAL_RADIUS = 50; public static double SIDE_LENGTH = 10; - public static String ALTIMGSRC = "https://upload.wikimedia.org/wikipedia/commons/4/45/Football_field.svg"; + public static String ALTIMGSRC = + "https://upload.wikimedia.org/wikipedia/commons/4/45/Football_field.svg"; //public static String ALTIMGSRC = "dist/assets/play_arrow.95e2d7e4.svg"; public static double ALTIMGX = 0; //try 24 public static double ALTIMGY = 0; //try 24 @@ -66,7 +67,9 @@ public void runOpMode() throws InterruptedException { waitForStart(); - if (isStopRequested()) return; + if (isStopRequested()) { + return; + } while (opModeIsActive()) { double time = getRuntime(); @@ -91,7 +94,8 @@ public void runOpMode() throws InterruptedException { byPoints[i] += by; } telemetry.addData("x", AMPLITUDE * Math.sin( - 2 * Math.PI * FREQUENCY * (System.currentTimeMillis() / 1000d) + Math.toRadians(PHASE) + 2 * Math.PI * FREQUENCY * (System.currentTimeMillis() / 1000d) + + Math.toRadians(PHASE) )); telemetry.addData("theta", angleAnim); telemetry.update(); @@ -113,7 +117,9 @@ public void runOpMode() throws InterruptedException { //this will be drawn in the pageFrame orientation .drawGrid(0, 0, 144, 144, 7, 7) //disabling the pageFrame will draw a grid in the current transform - .drawGrid(GRIDX, GRIDY, GRIDW, GRIDH, GRID_LINESX, GRID_LINESY, Math.toRadians(GRID_THETA_DEGREES), GRID_PIVOTX, GRID_PIVOTY, GRID_USE_PAGE_FRAME) + .drawGrid(GRIDX, GRIDY, GRIDW, GRIDH, GRID_LINESX, GRID_LINESY, + Math.toRadians(GRID_THETA_DEGREES), GRID_PIVOTX, GRID_PIVOTY, + GRID_USE_PAGE_FRAME) //.drawGrid(GRIDX, GRIDY, GRIDW, GRIDH, GRID_LINESX, GRID_LINESY, angleAnim, GRID_PIVOTX, GRID_PIVOTY, GRID_USE_PAGE_FRAME) //you can draw multiple images and can rotate them around a specified anchor/pivot point and draw them in the current transform instead of the page frame @@ -137,7 +143,8 @@ public void runOpMode() throws InterruptedException { .setStroke("green") .strokeLine(0, 0, 0, 24) //y axis .setFill("green") - .strokeText("Y axis", 0, (RED_ALLIANCE ? 24 : 0), "8px serif", -Math.PI / 2 * (RED_ALLIANCE ? -1 : 1), false) + .strokeText("Y axis", 0, (RED_ALLIANCE ? 24 : 0), "8px serif", + -Math.PI / 2 * (RED_ALLIANCE ? -1 : 1), false) .setStroke("red") .strokeLine(0, 0, 24, 0) //x axis .setFill("red") @@ -154,7 +161,8 @@ public void runOpMode() throws InterruptedException { //you can draw multiple images and can rotate them around a specified pivot point, and draw them in the current transform instead of the page frame .drawImage("/dash/powerplay.png", 24, 24, 48, 48, angleAnim, 24, 24, false) .setAlpha(1.0) - .fillText(TXTTEXT, TXTX, TXTY, TXTFONT, Math.toRadians(TXT_THETA_DEGREES), TXT_USE_PAGE_FRAME); + .fillText(TXTTEXT, TXTX, TXTY, TXTFONT, Math.toRadians(TXT_THETA_DEGREES), + TXT_USE_PAGE_FRAME); dashboard.sendTelemetryPacket(packet); diff --git a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/GamepadTestOpMode.java b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/GamepadTestOpMode.java index 910f8d5f0..3d9df2dae 100644 --- a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/GamepadTestOpMode.java +++ b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/GamepadTestOpMode.java @@ -5,11 +5,9 @@ import com.qualcomm.robotcore.eventloop.opmode.Autonomous; import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode; import com.qualcomm.robotcore.hardware.Gamepad; - -import org.firstinspires.ftc.robotcore.external.Telemetry; - import java.lang.reflect.Field; import java.lang.reflect.Modifier; +import org.firstinspires.ftc.robotcore.external.Telemetry; /* * Test the dashboard gamepad integration. @@ -19,9 +17,11 @@ public class GamepadTestOpMode extends LinearOpMode { private static void logGamepad(Telemetry telemetry, Gamepad gamepad, String prefix) { telemetry.addData(prefix + "Synthetic", - gamepad.getGamepadId() == Gamepad.ID_UNASSOCIATED); + gamepad.getGamepadId() == Gamepad.ID_UNASSOCIATED); for (Field field : gamepad.getClass().getFields()) { - if (Modifier.isStatic(field.getModifiers())) continue; + if (Modifier.isStatic(field.getModifiers())) { + continue; + } try { telemetry.addData(prefix + field.getName(), field.get(gamepad)); @@ -38,7 +38,9 @@ public void runOpMode() throws InterruptedException { waitForStart(); - if (isStopRequested()) return; + if (isStopRequested()) { + return; + } while (opModeIsActive()) { logGamepad(telemetry, gamepad1, "gamepad1"); diff --git a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/ImageOpMode.java b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/ImageOpMode.java index 704674dac..0cd7c8a3a 100644 --- a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/ImageOpMode.java +++ b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/ImageOpMode.java @@ -3,7 +3,6 @@ import com.acmerobotics.dashboard.FtcDashboard; import com.acmerobotics.dashboard.config.Config; import com.acmerobotics.dashboard.telemetry.TelemetryPacket; -import com.qualcomm.robotcore.eventloop.opmode.Autonomous; import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode; import com.qualcomm.robotcore.eventloop.opmode.TeleOp; @@ -16,7 +15,9 @@ public void runOpMode() throws InterruptedException { //FtcDashboard.setDrawDefaultField(false); waitForStart(); - if (isStopRequested()) return; + if (isStopRequested()) { + return; + } while (opModeIsActive()) { TelemetryPacket packet = new TelemetryPacket(); diff --git a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/OrbitOpMode.java b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/OrbitOpMode.java index 10a6e97b1..a631ef837 100644 --- a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/OrbitOpMode.java +++ b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/OrbitOpMode.java @@ -33,7 +33,9 @@ public void runOpMode() throws InterruptedException { waitForStart(); - if (isStopRequested()) return; + if (isStopRequested()) { + return; + } while (opModeIsActive()) { double time = getRuntime(); @@ -42,8 +44,8 @@ public void runOpMode() throws InterruptedException { double by = ORBITAL_RADIUS * Math.sin(2 * Math.PI * ORBITAL_FREQUENCY * time); double l = SIDE_LENGTH / 2; - double[] bxPoints = { l, -l, -l, l }; - double[] byPoints = { l, l, -l, -l }; + double[] bxPoints = {l, -l, -l, l}; + double[] byPoints = {l, l, -l, -l}; rotatePoints(bxPoints, byPoints, 2 * Math.PI * SPIN_FREQUENCY * time); for (int i = 0; i < 4; i++) { bxPoints[i] += bx; @@ -52,11 +54,11 @@ public void runOpMode() throws InterruptedException { TelemetryPacket packet = new TelemetryPacket(); packet.fieldOverlay() - .setStrokeWidth(1) - .setStroke("goldenrod") - .strokeCircle(0, 0, ORBITAL_RADIUS) - .setFill("black") - .fillPolygon(bxPoints, byPoints); + .setStrokeWidth(1) + .setStroke("goldenrod") + .strokeCircle(0, 0, ORBITAL_RADIUS) + .setFill("black") + .fillPolygon(bxPoints, byPoints); dashboard.sendTelemetryPacket(packet); sleep(20); diff --git a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/SineWaveOpMode.java b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/SineWaveOpMode.java index 9f1919197..695317516 100644 --- a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/SineWaveOpMode.java +++ b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/SineWaveOpMode.java @@ -23,11 +23,13 @@ public void runOpMode() throws InterruptedException { waitForStart(); - if (isStopRequested()) return; + if (isStopRequested()) { + return; + } while (opModeIsActive()) { telemetry.addData("x", AMPLITUDE * Math.sin( - 2 * Math.PI * FREQUENCY * getRuntime() + Math.toRadians(PHASE) + 2 * Math.PI * FREQUENCY * getRuntime() + Math.toRadians(PHASE) )); telemetry.update(); diff --git a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/VisionPortalStreamingOpMode.java b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/VisionPortalStreamingOpMode.java index 3163585ad..3132f83f3 100644 --- a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/VisionPortalStreamingOpMode.java +++ b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/VisionPortalStreamingOpMode.java @@ -2,11 +2,10 @@ import android.graphics.Bitmap; import android.graphics.Canvas; - import com.acmerobotics.dashboard.FtcDashboard; import com.qualcomm.robotcore.eventloop.opmode.Autonomous; import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode; - +import java.util.concurrent.atomic.AtomicReference; import org.firstinspires.ftc.robotcore.external.function.Consumer; import org.firstinspires.ftc.robotcore.external.function.Continuation; import org.firstinspires.ftc.robotcore.external.hardware.camera.BuiltinCameraDirection; @@ -17,12 +16,11 @@ import org.opencv.android.Utils; import org.opencv.core.Mat; -import java.util.concurrent.atomic.AtomicReference; - @Autonomous public class VisionPortalStreamingOpMode extends LinearOpMode { public static class CameraStreamProcessor implements VisionProcessor, CameraStreamSource { - private final AtomicReference lastFrame = new AtomicReference<>(Bitmap.createBitmap(1, 1, Bitmap.Config.RGB_565)); + private final AtomicReference lastFrame = + new AtomicReference<>(Bitmap.createBitmap(1, 1, Bitmap.Config.RGB_565)); @Override public void init(int width, int height, CameraCalibration calibration) { @@ -38,7 +36,9 @@ public Object processFrame(Mat frame, long captureTimeNanos) { } @Override - public void onDrawFrame(Canvas canvas, int onscreenWidth, int onscreenHeight, float scaleBmpPxToCanvasPx, float scaleCanvasDensity, Object userContext) { + public void onDrawFrame(Canvas canvas, int onscreenWidth, int onscreenHeight, + float scaleBmpPxToCanvasPx, float scaleCanvasDensity, + Object userContext) { // do nothing } @@ -53,9 +53,9 @@ public void runOpMode() throws InterruptedException { final CameraStreamProcessor processor = new CameraStreamProcessor(); new VisionPortal.Builder() - .addProcessor(processor) - .setCamera(BuiltinCameraDirection.BACK) - .build(); + .addProcessor(processor) + .setCamera(BuiltinCameraDirection.BACK) + .build(); FtcDashboard.getInstance().startCameraStream(processor, 0);