This commit is contained in:
2024-06-05 16:57:12 +02:00
parent f53d628d3b
commit e30fe9d108
2 changed files with 27 additions and 4 deletions

View File

@@ -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 circleId = isGoodRep ? R.drawable.progress_circle_good : R.drawable.progress_circle_bad;
int soundId = isGoodRep ? R.raw.good_sound : R.raw.wrong_sound; int soundId = isGoodRep ? R.raw.good_sound : R.raw.wrong_sound;
progressCircle.setProgressDrawable(ContextCompat.getDrawable(this, circleId)); 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); ObjectAnimator animator = ObjectAnimator.ofFloat(progressCircle, "alpha", 1f, 0f, 1f);
animator.setDuration(700); // Burst duration animator.setDuration(700); // Burst duration

View File

@@ -23,7 +23,7 @@ import java.util.List;
public class InputProcessor { public class InputProcessor {
private List<Vector3f>[] selfRotationVectorPaths; // Relative path of the motion data private List<Vector3f>[] selfRotationVectorPaths = null; // Relative path of the motion data
private Vector3f[][] targetRotationVectorPaths; // Target path of the motion data private Vector3f[][] targetRotationVectorPaths; // Target path of the motion data
private float exerciseRepetitionDurationInSeconds = 0.0f; private float exerciseRepetitionDurationInSeconds = 0.0f;
@@ -105,7 +105,11 @@ public class InputProcessor {
// Error checking thread. // Error checking thread.
(new Thread(() -> { (new Thread(() -> {
Log.i("InputProcessor", "Movement Checking Thread started"); Log.i("InputProcessor", "Movement Checking Thread started");
while (this.exercisesRemaining > 0) { while (this.exercisesRemaining > 0) {
if ( this.totalChecks == 0)
continue;
boolean isFaulty = this.isFaultyMovement(); boolean isFaulty = this.isFaultyMovement();
Log.i("InputProcessor", "Movement checked: " + (isFaulty ? "Faulty" : "Good")); Log.i("InputProcessor", "Movement checked: " + (isFaulty ? "Faulty" : "Good"));
@@ -117,7 +121,11 @@ public class InputProcessor {
this.checksPerformed++; this.checksPerformed++;
if (this.checksPerformed >= this.totalChecks) if (this.checksPerformed >= this.totalChecks)
{
this.checksPerformed = 0;
this.exercisesRemaining--;
acquireExercise(); acquireExercise();
}
try { try {
Thread.sleep((long) (this.errorCheckInterval_s * 1000)); Thread.sleep((long) (this.errorCheckInterval_s * 1000));
@@ -134,14 +142,15 @@ public class InputProcessor {
* @param exercise The exercise to move on to. * @param exercise The exercise to move on to.
*/ */
private void nextExercise(Exercise exercise) { 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 // Move to end screen on main activity
this.parentActivity.runOnUiThread(() -> NavigationManager.navigateToActivity(this.parentActivity, EndScreenActivity.class)); this.parentActivity.runOnUiThread(() -> NavigationManager.navigateToActivity(this.parentActivity, EndScreenActivity.class));
return; return;
} }
Log.i("InputProcessor", "Acquired next exercise: " + exercise.name);
ExerciseManager.TOTAL_REPETITIONS_REQUIRED += ExerciseManager.DEFAULT_EXERCISE_REPETITIONS; ExerciseManager.TOTAL_REPETITIONS_REQUIRED += ExerciseManager.DEFAULT_EXERCISE_REPETITIONS;
ExerciseManager.TOTAL_EXERCISES_PREFORMED++; ExerciseManager.TOTAL_EXERCISES_PREFORMED++;
@@ -241,6 +250,14 @@ public class InputProcessor {
*/ */
private void acquireExercise() { 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."); Log.i("MotionProcessor", "Fetching exercise data.");
this.parentActivity.fetchExerciseAsync(this::nextExercise, (nil) -> { this.parentActivity.fetchExerciseAsync(this::nextExercise, (nil) -> {
@@ -405,11 +422,17 @@ public class InputProcessor {
int i, referenceIndex; int i, referenceIndex;
float distance; float distance;
if (selfRotationVectorPaths == null ||
this.selfRotationVectorPaths.length == 0 ||
this.selfRotationVectorPaths[0].size() == 0)
return true;
for (i = 0; i < selfRotationVectorPaths.length; i++) { for (i = 0; i < selfRotationVectorPaths.length; i++) {
referenceIndex = (int) (Math.round( referenceIndex = (int) (Math.round(
((this.secondsPassed % this.exerciseRepetitionDurationInSeconds) / ((this.secondsPassed % this.exerciseRepetitionDurationInSeconds) /
(this.exerciseRepetitionDurationInSeconds)) * this.targetRotationVectorPaths[i].length)) (this.exerciseRepetitionDurationInSeconds)) * this.targetRotationVectorPaths[i].length))
% 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 // If distance is greater than the threshold, return true
distance = this.selfRotationVectorPaths[i].get(this.selfRotationVectorPaths[i].size() - 1).distance( distance = this.selfRotationVectorPaths[i].get(this.selfRotationVectorPaths[i].size() - 1).distance(
this.targetRotationVectorPaths[i][referenceIndex]); this.targetRotationVectorPaths[i][referenceIndex]);