Merge remote-tracking branch 'origin/main'

# Conflicts:
#	code/src/Fitbot/app/src/main/java/com/example/fitbot/ui/activities/FitnessActivity.java
This commit is contained in:
Luca Warmenhoven
2024-06-05 11:30:03 +02:00
24 changed files with 637 additions and 278 deletions

View File

@@ -33,8 +33,12 @@ const char* Connectivity::fetchIPAddress() {
int httpCode = http.GET();
if (httpCode > 0) {
if (httpCode == HTTP_CODE_OK) {
// If successful (code 200), read the response body and store the IP address
ipAddress = strdup(http.getString().c_str());
// If successful (code 200), read the response body and parse the IP address
String response = http.getString();
StaticJsonDocument<200> doc;
deserializeJson(doc, response);
const char* ip = doc["ip"]; // Extract the IP address
ipAddress = strdup(ip);
}
} else {
Serial.printf("GET request failed, error: %s\n", http.errorToString(httpCode).c_str());

View File

@@ -11,6 +11,8 @@
#include <ESP8266WiFiSTA.h>
#include <WiFiClient.h>
#include <WiFiClientSecure.h>
#include <ArduinoJson.h>
class Connectivity {

View File

@@ -4,11 +4,12 @@ void setup() {
//connect to internet and start sensor
connectivity.connectWiFi(ssid, pass);
sensorManager.sensorSetup();
Serial.begin(9600);
Serial.begin(115200);
Serial.println("startup");
}
void loop() {
SensorManager::eulerAngles eulerRotation = sensorManager.getEulerAngles();
SensorManager::RotationQuaternions Rotation = sensorManager.getQuaternions();
// SensorManager::acceleration rotationAcceleration = sensorManager.getAcelleration();
struct acceleration {
@@ -18,9 +19,10 @@ struct acceleration {
} accelData;
if (!ipAquired) {
serverIp = connectivity.fetchIPAddress();
serverIp = connectivity.fetchIPAddress(); // Assign the value here
ipAquired = true;
}
unsigned long lastTime = 0; // will store the last time the code was run
unsigned long currentTime = millis();
if (currentTime - lastTime >= 100) { // 100 ms has passed
@@ -29,15 +31,17 @@ struct acceleration {
buffer,
"{\"deviceId\": %d, \"rotationX\": %f, \"rotationY\": %f, \"rotationZ\": %f, \"accelerationX\": %f, \"accelerationY\": %f, \"accelerationZ\": %f, \"type\": %s}",
DEVICE_ID,
eulerRotation.roll,
eulerRotation.pitch,
eulerRotation.yaw,
accelData.x,
Rotation.i,
Rotation.j,
Rotation.k,
Rotation.w,
accelData.y,
accelData.z,
"data");
// %d = int, %f = floatation, %s = string
connectivity.httpPost("192.168.137.30", "/", 3445, buffer, strlen(buffer), "application/json");
connectivity.httpPost(serverIp, "/", 3445, buffer, strlen(buffer), "application/json");
Serial.println(serverIp);
Serial.println(buffer);
lastTime = currentTime;
}
}

View File

@@ -22,14 +22,17 @@ public:
eulerAngles getEulerAngles();
acceleration getAcelleration();
bool sensorTap();
private:
struct RotationQuaternions {
struct RotationQuaternions {
float i;
float j;
float k;
float w;
};
RotationQuaternions getQuaternions();
private:
BNO080 myIMU;
};

View File

@@ -8,8 +8,8 @@ Connectivity connectivity;
WebSocketsClient webSocket;
#define USE_SERIAL Serial
#define ssid "1235678i"
#define pass "12345678"
#define ssid "msi 5556"
#define pass "abc12345"
#define BUFFER_SIZE 1024
#define DEVICE_ID 1
#define IP_ADDRESS "192.168.137.12"

View File

@@ -22,6 +22,7 @@
<entry key="..\:/Users/sebas/Documents/HvA/Reposetories/muupooviixee66/code/src/Fitbot/app/src/main/res/drawable-v24/ic_launcher_foreground.xml" value="0.25" />
<entry key="..\:/Users/sebas/Documents/HvA/Reposetories/muupooviixee66/code/src/Fitbot/app/src/main/res/drawable/big_red_button_gradient.xml" value="0.2555" />
<entry key="..\:/Users/sebas/Documents/HvA/Reposetories/muupooviixee66/code/src/Fitbot/app/src/main/res/drawable/border_background.xml" value="0.2475" />
<entry key="..\:/Users/sebas/Documents/HvA/Reposetories/muupooviixee66/code/src/Fitbot/app/src/main/res/drawable/border_background_2.xml" value="0.2475" />
<entry key="..\:/Users/sebas/Documents/HvA/Reposetories/muupooviixee66/code/src/Fitbot/app/src/main/res/drawable/border_background_3.xml" value="0.2475" />
<entry key="..\:/Users/sebas/Documents/HvA/Reposetories/muupooviixee66/code/src/Fitbot/app/src/main/res/drawable/box_background.xml" value="0.2555" />
<entry key="..\:/Users/sebas/Documents/HvA/Reposetories/muupooviixee66/code/src/Fitbot/app/src/main/res/drawable/darkred_button_gradient.xml" value="0.346" />

View File

@@ -13,6 +13,8 @@ public class EndScreenActivity extends AppCompatActivity {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_end_screen);
NavigationManager.hideSystemUI(this);
NavigationManager.setupButtonNavigation(this, R.id.homeButtonEndScreen, MainActivity.class);
NavigationManager.setupButtonNavigation(this, R.id.startButtonEndScreen, FitnessActivity.class);
}

View File

@@ -2,11 +2,17 @@ package com.example.fitbot.ui.activities;
import android.app.Dialog;
import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.VideoView;
@@ -53,7 +59,7 @@ public class FitnessActivity extends RobotActivity implements RobotLifecycleCall
private static final float SENSOR_SAMPLE_RATE = 10.0f;
private static final int EXERCISE_COUNT = 5;
private static int EXERCISE_REP = 10;
private static int EXERCISE_REP = 1;
private static final float EXERCISE_SPEED_MULTIPLIER = 1.0f;
@Override
@@ -67,6 +73,13 @@ public class FitnessActivity extends RobotActivity implements RobotLifecycleCall
this.exerciseShortDescriptionTextView = findViewById(R.id.textViewFitnessShortDescription);
//this.exerciseDescriptionTextView = findViewById(R.id.textViewDialogDescription);
// Set the repetition count for the exercise
EXERCISE_REP = 1;
// Set color of loading circle
ProgressBar loadingCircle = findViewById(R.id.loadingCircle);
loadingCircle.setIndeterminateTintList(ColorStateList.valueOf(Color.RED));
// Navigation Buttons
NavigationManager.setupButtonNavigation(this, R.id.homeButtonFitness, MainActivity.class);
NavigationManager.setupButtonNavigation(this, R.id.skipButtonFitness, MainActivity.class); //Needs to skip exercises once those are implemented
@@ -99,7 +112,7 @@ public class FitnessActivity extends RobotActivity implements RobotLifecycleCall
exerciseStatusElement.post(() -> {
this.fetchExerciseAsync((exercise) -> {
// Acquire paths from the exercise and provide them to the motion processor
Vector3f[][] vectors = new Vector3f[][]{exercise.leftPath.getAngleVectors(), exercise.rightPath.getAngleVectors()};
Vector3f[][] vectors = new Vector3f[][]{exercise.leftPath.getVectors(), exercise.rightPath.getVectors()};
motionProcessor = new InputProcessor(vectors, exercise.exerciseTimeInSeconds, SENSOR_SAMPLE_RATE);
@@ -126,7 +139,7 @@ public class FitnessActivity extends RobotActivity implements RobotLifecycleCall
public void fetchExerciseAsync(Exercise.ExerciseFetchHandler onSuccessfulFetch, Exercise.ExerciseFetchHandler onFailedFetch) {
// For some stupid reason we cannot perform network operations on the main thread.
// therefore we'll have to do it like this...
(new Thread(() -> {
new Thread(() -> {
Exercise exercise = ExerciseManager.fetchExerciseFromDatabase();
if (exercise == null) {
onFailedFetch.handle(null);
@@ -142,14 +155,28 @@ public class FitnessActivity extends RobotActivity implements RobotLifecycleCall
VideoView videoView = findViewById(R.id.videoView);
playVideo(videoView, this);
// Set a listener to repeat the video
while (EXERCISE_REP > 1) {
videoView.setOnCompletionListener(mp -> videoView.start()); // start the video again);
EXERCISE_REP--;
}
// When the video has started playing remove the loading circle
videoView.setOnInfoListener((mp, what, extra) -> {
if (what == MediaPlayer.MEDIA_INFO_VIDEO_RENDERING_START) {
ProgressBar loadingCircle = findViewById(R.id.loadingCircle);
loadingCircle.setVisibility(View.GONE);
return true;
}
return false;
});
videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
if (EXERCISE_REP < EXERCISE_COUNT) {
videoView.start(); // start the video again
EXERCISE_REP++;
}
}
});
});
}
})).start();
}).start();
}
/**
@@ -158,7 +185,7 @@ public class FitnessActivity extends RobotActivity implements RobotLifecycleCall
* @param videoView The VideoView to play the video in
* @param context The context to use
*/
public static void playVideo(VideoView videoView, Context context) {
public void playVideo(VideoView videoView, Context context) {
// Set up the video player
if (videoView != null) {
videoView.setVideoPath(exerciseVideoUrl);

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/lightBlue" />
<stroke android:width="2dp" android:color="#FF0000" />
<stroke android:width="2dp" android:color="#FFFFFF" />
<corners android:radius="20dp" />
</shape>

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/midBlue" />
<stroke android:width="2dp" android:color="#FF0000" />
<stroke android:width="2dp" android:color="#FFFFFF" />
<corners android:radius="10dp" />
</shape>

View File

@@ -12,7 +12,7 @@
android:layout_height="450dp"
android:layout_marginStart="80dp"
android:layout_marginTop="24dp"
android:background="@drawable/border_background_2"
android:background="@drawable/border_background"
android:orientation="vertical"
android:padding="16dp"
app:layout_constraintStart_toStartOf="parent"
@@ -24,7 +24,7 @@
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:layout_marginBottom="40dp"
android:background="@drawable/border_background"
android:background="@drawable/border_background_3"
android:orientation="vertical"
android:paddingVertical="15dp"
android:paddingHorizontal="20dp"
@@ -40,11 +40,11 @@
</LinearLayout>
<LinearLayout
android:layout_width="700dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:background="@drawable/border_background"
android:background="@drawable/border_background_3"
android:orientation="vertical"
android:padding="16dp"
app:layout_constraintStart_toStartOf="parent"
@@ -60,11 +60,11 @@
</LinearLayout>
<LinearLayout
android:layout_width="700dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:background="@drawable/border_background"
android:background="@drawable/border_background_3"
android:orientation="vertical"
android:padding="16dp"
app:layout_constraintStart_toStartOf="parent"

View File

@@ -11,140 +11,138 @@
tools:openDrawer="start">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_width="450dp"
android:layout_height="450dp"
android:layout_gravity="center"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp"
android:background="@drawable/border_background_2"
android:orientation="horizontal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.505"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<RelativeLayout
android:layout_width="410dp"
android:layout_height="410dp"
android:layout_marginVertical="20dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="15dp"
android:background="@drawable/border_background"
android:layout_gravity="center">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
app:cardCornerRadius="20dp">
<VideoView
android:id="@+id/videoView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<RelativeLayout
android:id="@+id/loadingPanel"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center" >
<ProgressBar
android:id="@+id/loadingCircle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminate="true"
android:progressTint="@color/white"/>
</RelativeLayout>
<Button
android:id="@+id/infoButtonFitness"
android:layout_width="45dp"
android:layout_height="45dp"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:background="@drawable/red_button_gradient"
android:drawableTop="@drawable/ic_baseline_info_40"
android:drawableTint="@color/white"
android:padding="2.5dp"
android:layout_margin="10dp"
android:padding="5dp"
tools:ignore="SpeakableTextPresentCheck" />
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="300dp"
android:layout_height="300dp"
android:layout_centerInParent="true"
android:layout_marginStart="50dp"
android:layout_marginTop="50dp"
android:layout_marginEnd="50dp"
android:layout_marginBottom="50dp"
card_view:cardCornerRadius="30dp">
</android.support.v7.widget.CardView>
<VideoView
android:id="@+id/videoView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</android.support.v7.widget.CardView>
<LinearLayout
android:layout_width="450dp"
android:layout_height="450dp"
android:layout_marginTop="20dp"
android:layout_marginEnd="20dp"
android:background="@drawable/border_background"
android:orientation="vertical"
android:padding="20dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent">
</RelativeLayout>
<TextView
android:id="@+id/textViewFitnessTitle"
style="@style/TextStyleTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="@string/title"
android:textAlignment="center" />
<LinearLayout
android:layout_width="410dp"
android:layout_height="410dp"
android:layout_gravity="center"
android:layout_marginVertical="20dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="30dp"
android:padding="10dp"
android:background="@drawable/border_background"
android:orientation="vertical"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_margin="10dp"
android:background="@drawable/border_background_3"
android:padding="5dp">
<TextView
android:id="@+id/textViewFitnessTitle"
style="@style/TextStyleTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/title"
android:textAlignment="center"
android:layout_gravity="center_horizontal" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/border_background_3"
android:padding="5dp"
android:layout_margin="5dp"
android:layout_gravity="center_horizontal">
<TextView
android:id="@+id/textViewFitnessShortDescription"
style="@style/TextStyleDesc"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/context"
android:textAlignment="center" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/border_background_3"
android:padding="5dp"
android:layout_margin="5dp"
android:layout_gravity="center_horizontal">
<TextView
android:id="@+id/textViewFitnessBar"
style="@style/TextStyle"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/context"
android:textAlignment="center" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/border_background_3"
android:padding="5dp"
android:layout_margin="5dp"
android:layout_gravity="center_horizontal">
<TextView
android:id="@+id/textViewFitnessScore"
style="@style/TextStyle"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/context"
android:textAlignment="center" />
</LinearLayout>
android:id="@+id/textViewFitnessShortDescription"
style="@style/TextStyleDesc"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/context"
android:textAlignment="center" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_margin="10dp"
android:background="@drawable/border_background_3"
android:padding="5dp">
<TextView
android:id="@+id/textViewFitnessReps"
style="@style/TextStyle"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/context"
android:textAlignment="center" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_margin="10dp"
android:background="@drawable/border_background_3"
android:padding="5dp">
<TextView
android:id="@+id/textViewFitnessScore"
style="@style/TextStyle"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/context"
android:textAlignment="center" />
</LinearLayout>
<com.example.fitbot.ui.components.ExerciseStatusElement
android:id="@+id/personalMotionPreviewElement"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<Button
android:id="@+id/homeButtonFitness"
android:layout_width="150dp"
android:layout_height="75dp"
android:layout_marginStart="200dp"
android:layout_marginStart="175dp"
android:layout_marginBottom="30dp"
android:background="@drawable/red_button_gradient"
android:drawableTop="@drawable/ic_baseline_home_48"
@@ -158,7 +156,7 @@
android:id="@+id/skipButtonFitness"
android:layout_width="150dp"
android:layout_height="75dp"
android:layout_marginEnd="200dp"
android:layout_marginEnd="175dp"
android:layout_marginBottom="30dp"
android:background="@drawable/red_button_gradient"
android:drawableTop="@drawable/ic_baseline_skip_next_48"
@@ -168,13 +166,4 @@
app:layout_constraintEnd_toEndOf="parent"
tools:ignore="SpeakableTextPresentCheck" />
<com.example.fitbot.ui.components.ExerciseStatusElement
android:id="@+id/personalMotionPreviewElement"
android:layout_width="10dp"
android:layout_height="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>

View File

@@ -28,7 +28,7 @@
android:layout_height="450dp"
android:layout_marginStart="80dp"
android:layout_marginTop="24dp"
android:background="@drawable/border_background_2"
android:background="@drawable/border_background"
android:orientation="vertical"
android:padding="16dp"
app:layout_constraintStart_toStartOf="parent"
@@ -40,10 +40,9 @@
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:layout_marginBottom="40dp"
android:background="@drawable/border_background"
android:padding="16dp"
android:background="@drawable/border_background_3"
android:orientation="vertical"
android:paddingVertical="15dp"
android:paddingHorizontal="20dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
@@ -56,11 +55,11 @@
</LinearLayout>
<LinearLayout
android:layout_width="700dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:background="@drawable/border_background"
android:background="@drawable/border_background_3"
android:orientation="vertical"
android:padding="16dp"
app:layout_constraintStart_toStartOf="parent"
@@ -76,11 +75,11 @@
</LinearLayout>
<LinearLayout
android:layout_width="700dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:background="@drawable/border_background"
android:background="@drawable/border_background_3"
android:orientation="vertical"
android:padding="16dp"
app:layout_constraintStart_toStartOf="parent"

View File

@@ -15,6 +15,7 @@
android:layout_marginStart="10dp"
android:layout_marginTop="20dp"
android:src="@drawable/robot_logo"
android:tint="@color/white"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
@@ -24,7 +25,7 @@
android:layout_marginTop="60dp"
android:text="FitBot"
android:textSize="48sp"
android:textColor="@color/darkBlue"
android:textColor="@color/white"
app:layout_constraintStart_toEndOf="@+id/imageView"
app:layout_constraintTop_toTopOf="parent" />

View File

@@ -26,7 +26,7 @@
</style>
<style name="TextStyleDesc">
<item name="android:textSize">14sp</item>
<item name="android:textSize">20sp</item>
<item name="android:textColor">#FFFFFF</item>
<item name= "android:textStyle">bold</item>
<item name="android:padding">6dp</item>