diff --git a/code/src/Fitbot/app/src/main/java/com/example/fitbot/ui/activities/FitnessActivity.java b/code/src/Fitbot/app/src/main/java/com/example/fitbot/ui/activities/FitnessActivity.java index bc8c909..0257f6c 100644 --- a/code/src/Fitbot/app/src/main/java/com/example/fitbot/ui/activities/FitnessActivity.java +++ b/code/src/Fitbot/app/src/main/java/com/example/fitbot/ui/activities/FitnessActivity.java @@ -272,7 +272,7 @@ public class FitnessActivity extends RobotActivity implements RobotLifecycleCall int circleId = isGoodRep ? R.drawable.progress_circle_good : R.drawable.progress_circle_bad; int soundId = isGoodRep ? R.raw.good_sound : R.raw.wrong_sound; progressCircle.setProgressDrawable(ContextCompat.getDrawable(this, circleId)); - MediaPlayer.create(this, soundId).start(); + // MediaPlayer.create(this, soundId).start(); ObjectAnimator animator = ObjectAnimator.ofFloat(progressCircle, "alpha", 1f, 0f, 1f); animator.setDuration(700); // Burst duration 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 f2ded90..8d5a471 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 @@ -23,7 +23,7 @@ import java.util.List; public class InputProcessor { - private List[] selfRotationVectorPaths; // Relative path of the motion data + private List[] selfRotationVectorPaths = null; // Relative path of the motion data private Vector3f[][] targetRotationVectorPaths; // Target path of the motion data private float exerciseRepetitionDurationInSeconds = 0.0f; @@ -105,7 +105,11 @@ public class InputProcessor { // Error checking thread. (new Thread(() -> { Log.i("InputProcessor", "Movement Checking Thread started"); + while (this.exercisesRemaining > 0) { + + if ( this.totalChecks == 0) + continue; boolean isFaulty = this.isFaultyMovement(); Log.i("InputProcessor", "Movement checked: " + (isFaulty ? "Faulty" : "Good")); @@ -117,7 +121,11 @@ public class InputProcessor { this.checksPerformed++; if (this.checksPerformed >= this.totalChecks) + { + this.checksPerformed = 0; + this.exercisesRemaining--; acquireExercise(); + } try { Thread.sleep((long) (this.errorCheckInterval_s * 1000)); @@ -134,14 +142,15 @@ public class InputProcessor { * @param exercise The exercise to move on to. */ private void nextExercise(Exercise exercise) { - Log.i("InputProcessor", "Acquired next exercise: " + exercise.name); - if (this.exercisesRemaining-- <= 0) { + if (this.exercisesRemaining <= 0) { + Log.i("InputProcessor", "Moving to end screen; finished all exercises"); // Move to end screen on main activity this.parentActivity.runOnUiThread(() -> NavigationManager.navigateToActivity(this.parentActivity, EndScreenActivity.class)); return; } + Log.i("InputProcessor", "Acquired next exercise: " + exercise.name); ExerciseManager.TOTAL_REPETITIONS_REQUIRED += ExerciseManager.DEFAULT_EXERCISE_REPETITIONS; ExerciseManager.TOTAL_EXERCISES_PREFORMED++; @@ -241,6 +250,14 @@ public class InputProcessor { */ private void acquireExercise() { + if ( this.exercisesRemaining <= 0) + { + Log.i("InputProcessor", "Exercises finished"); + this.parentActivity.runOnUiThread(() -> { + NavigationManager.navigateToActivity(this.parentActivity, EndScreenActivity.class); + }); + } + Log.i("MotionProcessor", "Fetching exercise data."); this.parentActivity.fetchExerciseAsync(this::nextExercise, (nil) -> { @@ -405,11 +422,17 @@ public class InputProcessor { int i, referenceIndex; float distance; + if (selfRotationVectorPaths == null || + this.selfRotationVectorPaths.length == 0 || + this.selfRotationVectorPaths[0].size() == 0) + return true; + for (i = 0; i < selfRotationVectorPaths.length; i++) { referenceIndex = (int) (Math.round( ((this.secondsPassed % this.exerciseRepetitionDurationInSeconds) / (this.exerciseRepetitionDurationInSeconds)) * this.targetRotationVectorPaths[i].length)) % this.targetRotationVectorPaths[i].length; + referenceIndex = Math.min(1, Math.max(0, referenceIndex)); // If distance is greater than the threshold, return true distance = this.selfRotationVectorPaths[i].get(this.selfRotationVectorPaths[i].size() - 1).distance( this.targetRotationVectorPaths[i][referenceIndex]);