diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 4020532..25b05d8 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -14,10 +14,9 @@ - - + - + @@ -424,6 +443,8 @@ - \ No newline at end of file diff --git a/code/arduino/Movement-sensor-code/Connectivity.cpp b/code/arduino/Movement-sensor-code/Connectivity.cpp index bfc3c04..955d7d0 100644 --- a/code/arduino/Movement-sensor-code/Connectivity.cpp +++ b/code/arduino/Movement-sensor-code/Connectivity.cpp @@ -21,9 +21,9 @@ void Connectivity::connectWiFi(char* ssid, char* pass){ // } const char* getServerURL = "http://145.92.8.132:443/get-ip"; -String ipAddress = ""; +char* ipAddress = ""; -String Connectivity::fetchIPAddress() { +const char* Connectivity::fetchIPAddress() { if (WiFi.status() == WL_CONNECTED) { HTTPClient http; WiFiClient client; @@ -32,7 +32,7 @@ String Connectivity::fetchIPAddress() { int httpCode = http.GET(); if (httpCode > 0) { if (httpCode == HTTP_CODE_OK) { - ipAddress = http.getString(); + ipAddress = strdup(http.getString().c_str()); } } else { Serial.printf("GET request failed, error: %s\n", http.errorToString(httpCode).c_str()); diff --git a/code/arduino/Movement-sensor-code/Connectivity.h b/code/arduino/Movement-sensor-code/Connectivity.h index 6de0109..37d528b 100644 --- a/code/arduino/Movement-sensor-code/Connectivity.h +++ b/code/arduino/Movement-sensor-code/Connectivity.h @@ -19,7 +19,7 @@ public: void websocketSetup(char* ip, uint16_t port, char* adress); void sendData(float roll, float pitch, float yaw); int httpPost(const char *serverAddress, const char *serverSubPath, const unsigned short serverPort, const char *data, const size_t dataLength, const char *contentType); - String fetchIPAddress(); + const char* fetchIPAddress(); private: ESP8266WiFiMulti wifi; diff --git a/code/arduino/Movement-sensor-code/Movement-sensor-code.ino b/code/arduino/Movement-sensor-code/Movement-sensor-code.ino index 061f12d..6540384 100644 --- a/code/arduino/Movement-sensor-code/Movement-sensor-code.ino +++ b/code/arduino/Movement-sensor-code/Movement-sensor-code.ino @@ -7,8 +7,6 @@ void setup() { Serial.begin(9600); } -unsigned long lastTime = 0; // will store the last time the code was run - void loop() { SensorManager::eulerAngles eulerRotation = sensorManager.getEulerAngles(); // SensorManager::acceleration rotationAcceleration = sensorManager.getAcelleration(); @@ -19,6 +17,11 @@ struct acceleration { float z = 9; } accelData; + if (!ipAquired) { + serverIp = connectivity.fetchIPAddress(); + 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 memset(buffer, 0, BUFFER_SIZE); @@ -34,10 +37,10 @@ struct acceleration { accelData.z, "data"); // %d = int, %f = floatation, %s = string - connectivity.httpPost(connectivity.fetchIPAddress(), "/", 3445, buffer, strlen(buffer), "application/json"); + connectivity.httpPost(serverIp, "/", 3445, buffer, strlen(buffer), "application/json"); lastTime = currentTime; } } //acceleration.X //acceleration.Y -//acceleration.Z +//acceleration.Z \ No newline at end of file diff --git a/code/arduino/Movement-sensor-code/headerFIle.h b/code/arduino/Movement-sensor-code/headerFIle.h index 8e3480e..bd6639b 100644 --- a/code/arduino/Movement-sensor-code/headerFIle.h +++ b/code/arduino/Movement-sensor-code/headerFIle.h @@ -15,3 +15,5 @@ WebSocketsClient webSocket; #define IP_ADDRESS "192.168.137.12" char *buffer = (char *)malloc(sizeof(char) * BUFFER_SIZE); +const char* serverIp = NULL; // Declare serverIp here +bool ipAquired = false; \ No newline at end of file diff --git a/code/server/incoming_request_handlers.js b/code/server/incoming_request_handlers.js index 1f8d257..ef583a1 100644 --- a/code/server/incoming_request_handlers.js +++ b/code/server/incoming_request_handlers.js @@ -1,3 +1,6 @@ + +const databaseQuery = 'SELECT * FROM `Exercise` ORDER BY RAND() LIMIT 1'; + /** * * @param {Request} request The incoming request @@ -8,45 +11,33 @@ function handleIncoming(request, response, app, pool) { - let query = 'SELECT * FROM Exercise WHERE ExerciseID = ?'; - let parameters = []; - - if (!request.hasOwnProperty('uid') || typeof request.uid !== 'number') - { - query = 'SELECT * FROM Exercise ORDER BY RAND() LIMIT 1'; - } else parameters.push(request.uid); - // Acquire database connection pool.getConnection() .then(conn => { - conn.query(query, parameters) + conn.query( + databaseQuery) .then(rows => { if (rows.length === 0) { response .status(404) - .send(JSON.stringify({error: 'Exercise not found'})); + .send(JSON.stringify({error: 'No exercises found in the database.'})); } else { - // Send back the data in the right format - let converted = rows.map(row => { - return { - exerciseId: row.ExerciseID, - name: row.Name, - muscleGroup: row.MuscleGroup, - shortDescription: row.ShortDescription, - description: row.Description, - imageUrl: row.ImageURL, - videoUrl: row.VideoURL, - path: row.Path, - duration: row.Duration - }; - }); - - response - .status(200) - .send(JSON.stringify(converted)); + let row = rows[0]; + response.status(200) + .send(JSON.stringify({ + exerciseId: row['ExerciseID'], + name: row['Name'], + muscleGroup: row['MuscleGroup'], + shortDescription: row['ShortDescription'], + description: row['Description'], + imageUrl: row['ImageURL'], + videoUrl: row['VideoURL'], + path: row['Path'], + duration: row['Duration'] + })) } }) .catch(error => { diff --git a/code/src/Fitbot/.idea/misc.xml b/code/src/Fitbot/.idea/misc.xml index a6192e8..b1965d6 100644 --- a/code/src/Fitbot/.idea/misc.xml +++ b/code/src/Fitbot/.idea/misc.xml @@ -35,13 +35,15 @@ - + + + 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 f5422cb..01b4b20 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 @@ -1,10 +1,15 @@ package com.example.fitbot.ui.activities; +import android.app.Dialog; import android.content.Context; +import android.graphics.drawable.ColorDrawable; import android.net.Uri; import android.os.Bundle; import android.util.Log; import android.widget.TextView; +import android.view.View; +import android.view.WindowManager; +import android.widget.Button; import android.widget.VideoView; import com.aldebaran.qi.sdk.QiContext; @@ -59,7 +64,17 @@ public class FitnessActivity extends RobotActivity implements RobotLifecycleCall VideoView videoView = findViewById(R.id.videoView); playVideo(videoView, this); NavigationManager.setupButtonNavigation(this, R.id.homeButtonFitness, MainActivity.class); + NavigationManager.setupButtonNavigation(this, R.id.skipButtonFitness, MainActivity.class); //Needs to skip exercises once those are implemented + NavigationManager.hideSystemUI(this); + + Button infoButtonFitness = findViewById(R.id.infoButtonFitness); + infoButtonFitness.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + showInfoDialog(); + } + }); } @Override @@ -163,4 +178,24 @@ public class FitnessActivity extends RobotActivity implements RobotLifecycleCall super.onDestroy(); } + + private void showInfoDialog() { + final Dialog dialog = new Dialog(this); + dialog.setContentView(R.layout.dialog_info); + + NavigationManager.hideSystemUI(this); + + dialog.getWindow().setDimAmount(0.5f); + dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT)); + dialog.setCancelable(true); + + Button closeButton = dialog.findViewById(R.id.closeButtonDialog); + closeButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + dialog.dismiss(); + } + }); + dialog.show(); + } } \ No newline at end of file diff --git a/code/src/Fitbot/app/src/main/res/drawable/ic_baseline_close_48.xml b/code/src/Fitbot/app/src/main/res/drawable/ic_baseline_close_48.xml new file mode 100644 index 0000000..72f8573 --- /dev/null +++ b/code/src/Fitbot/app/src/main/res/drawable/ic_baseline_close_48.xml @@ -0,0 +1,5 @@ + + + diff --git a/code/src/Fitbot/app/src/main/res/layout/dialog_info.xml b/code/src/Fitbot/app/src/main/res/layout/dialog_info.xml new file mode 100644 index 0000000..f64e32a --- /dev/null +++ b/code/src/Fitbot/app/src/main/res/layout/dialog_info.xml @@ -0,0 +1,45 @@ + + + + + + + +