From 627b50f7d50781beb51870f3da1ed53ca8cb6a38 Mon Sep 17 00:00:00 2001 From: Luca Warmenhoven Date: Mon, 3 Jun 2024 14:55:24 +0200 Subject: [PATCH] Updated some stuff --- .../ui/components/ExerciseStatusElement.java | 71 +++++++++---------- .../example/fitbot/util/path/GesturePath.java | 2 + .../util/processing/InputProcessor.java | 2 + 3 files changed, 36 insertions(+), 39 deletions(-) diff --git a/code/src/Fitbot/app/src/main/java/com/example/fitbot/ui/components/ExerciseStatusElement.java b/code/src/Fitbot/app/src/main/java/com/example/fitbot/ui/components/ExerciseStatusElement.java index e8b2351..293068c 100644 --- a/code/src/Fitbot/app/src/main/java/com/example/fitbot/ui/components/ExerciseStatusElement.java +++ b/code/src/Fitbot/app/src/main/java/com/example/fitbot/ui/components/ExerciseStatusElement.java @@ -18,12 +18,7 @@ import com.example.fitbot.util.NavigationManager; import com.example.fitbot.util.processing.IInputHandler; import com.example.fitbot.util.processing.InputProcessor; -import org.joml.Matrix4f; -import org.joml.Vector2f; import org.joml.Vector3f; -import org.joml.Vector4f; - -import java.util.concurrent.ConcurrentLinkedQueue; public class ExerciseStatusElement extends View implements IInputHandler { @@ -87,8 +82,6 @@ public class ExerciseStatusElement extends View implements IInputHandler { // Handler that is called every time the motion processor receives new data. - - } /** @@ -127,40 +120,40 @@ public class ExerciseStatusElement extends View implements IInputHandler { @Override public void accept(Vector3f rotationVector, int sensorId) { - Log.i("MotionProcessor", "Rotation vector received: " + rotationVector); - Log.i("MotionProcessor", "Last error offset:" + this.motionProcessor.getError(sensorId, this.motionProcessor.secondsPassed())); + Log.i("MotionProcessor", "Rotation vector received: " + rotationVector); + Log.i("MotionProcessor", "Last error offset:" + this.motionProcessor.getError(sensorId, this.motionProcessor.secondsPassed())); - // Check whether the current exercise has been completed. - // This is determined by the duration of the exercise, and the amount of time that has passed. - // The duration of the exercise originates from the database, and is stored in seconds. - // Whenever 'useExercise' is called, the timer resets and this method will be called again. - if (this.motionProcessor.hasFinished() && !this.motionProcessor.isRecording()) { - // If for some reason the parent activity is not defined, - // move back to the main screen. - if (this.parentActivity == null) { - // Move to main screen - Log.i("MotionProcessor", "Parent activity was null."); - NavigationManager.navigateToActivity(getContext(), MainActivity.class); - return; - } - // Move on to the next exercise, or finish. - if (this.exerciseCount > 0) { - this.exerciseCount--; - this.parentActivity.fetchExerciseAsync((newExercise) -> { - this.motionProcessor.useExercise(newExercise); - - // Whenever the database retrieval failed, we return to the main screen. - }, (failed) -> { - // Move to main screen - Log.i("MotionProcessor", "Failed to fetch exercise from database"); - NavigationManager.navigateToActivity(parentActivity, MainActivity.class); - }); - } else { - // Finish the exercise. - Log.i("MotionProcessor", "Exercise has finished"); - NavigationManager.navigateToActivity(parentActivity, EndScreenActivity.class); - } + // Check whether the current exercise has been completed. + // This is determined by the duration of the exercise, and the amount of time that has passed. + // The duration of the exercise originates from the database, and is stored in seconds. + // Whenever 'useExercise' is called, the timer resets and this method will be called again. + if (this.motionProcessor.hasFinished() && !this.motionProcessor.isRecording()) { + // If for some reason the parent activity is not defined, + // move back to the main screen. + if (this.parentActivity == null) { + // Move to main screen + Log.i("MotionProcessor", "Parent activity was null."); + NavigationManager.navigateToActivity(getContext(), MainActivity.class); + return; } + // Move on to the next exercise, or finish. + if (this.exerciseCount > 0) { + this.exerciseCount--; + this.parentActivity.fetchExerciseAsync((newExercise) -> { + this.motionProcessor.useExercise(newExercise); + + // Whenever the database retrieval failed, we return to the main screen. + }, (failed) -> { + // Move to main screen + Log.i("MotionProcessor", "Failed to fetch exercise from database"); + NavigationManager.navigateToActivity(parentActivity, MainActivity.class); + }); + } else { + // Finish the exercise. + Log.i("MotionProcessor", "Exercise has finished"); + NavigationManager.navigateToActivity(parentActivity, EndScreenActivity.class); + } + } } } diff --git a/code/src/Fitbot/app/src/main/java/com/example/fitbot/util/path/GesturePath.java b/code/src/Fitbot/app/src/main/java/com/example/fitbot/util/path/GesturePath.java index 14e7706..0b6a857 100644 --- a/code/src/Fitbot/app/src/main/java/com/example/fitbot/util/path/GesturePath.java +++ b/code/src/Fitbot/app/src/main/java/com/example/fitbot/util/path/GesturePath.java @@ -92,6 +92,8 @@ public class GesturePath { */ public static GesturePath fromString(String input) { + if (input == null) + throw new IllegalArgumentException("Input string cannot be null"); byte[] bytes = input.getBytes(); // Check if the input string contains a valid amount of bytes (12 bytes per vector) diff --git a/code/src/Fitbot/app/src/main/java/com/example/fitbot/util/processing/InputProcessor.java b/code/src/Fitbot/app/src/main/java/com/example/fitbot/util/processing/InputProcessor.java index 52c8524..a39dad6 100644 --- a/code/src/Fitbot/app/src/main/java/com/example/fitbot/util/processing/InputProcessor.java +++ b/code/src/Fitbot/app/src/main/java/com/example/fitbot/util/processing/InputProcessor.java @@ -101,6 +101,7 @@ public class InputProcessor { if (recording) { this.secondsPassed = 0.0D; this.lastTime = System.currentTimeMillis(); + this.selfRotationVectorPaths = new Vector3f[2][(int) (duration * this.sampleRate)]; } } @@ -179,6 +180,7 @@ public class InputProcessor { int deviceId = object.get("deviceId").getAsInt(); String type = object.get("type").getAsString(); + // Parse the retrieved data parseRotationVector(rotation, deviceId); } catch (Exception e) { Log.i("MotionProcessor", "Failed to parse packet data.");