[chronojump/michrolab] Added force exercises management



commit 7bab2deb68faade2fe0b68f2fb06bc1229310dd5
Author: Xavier Padullés <testing chronojump org>
Date:   Fri Sep 16 19:15:25 2022 +0200

    Added force exercises management

 arduino/michrolab/exercsiseManage.ino | 87 +++++++++++++++++++++++++++++++----
 arduino/michrolab/michrolab.ino       | 33 ++++++++++---
 2 files changed, 106 insertions(+), 14 deletions(-)
---
diff --git a/arduino/michrolab/exercsiseManage.ino b/arduino/michrolab/exercsiseManage.ino
index cc387b7ab..f26a81c7d 100644
--- a/arduino/michrolab/exercsiseManage.ino
+++ b/arduino/michrolab/exercsiseManage.ino
@@ -161,13 +161,66 @@ void saveInertialList()
   Serial.println("Saved " + String(totalInertTypes) + " to GRAVTYPE.TXT");
 }
 
+void addForce(String row)
+{
+  //Serial.println(row);
+  int prevComaIndex = row.indexOf(":");
+  int nextComaIndex = row.indexOf(",");
+  forceTypes[totalForceTypes].id = row.substring(prevComaIndex + 1, nextComaIndex).toInt();
+
+  prevComaIndex = nextComaIndex;
+  nextComaIndex = row.indexOf(",", prevComaIndex + 1 );
+  forceTypes[totalForceTypes].name = row.substring(prevComaIndex + 1 , nextComaIndex);
+  prevComaIndex = nextComaIndex;
+
+  nextComaIndex = row.indexOf(",", prevComaIndex + 1 );
+  forceTypes[totalForceTypes].description = row.substring(prevComaIndex + 1, nextComaIndex);
+  prevComaIndex = nextComaIndex;
+
+  nextComaIndex = row.indexOf(",", prevComaIndex + 1 );
+  forceTypes[totalForceTypes].percentBodyWeight = row.substring(prevComaIndex + 1 , nextComaIndex).toFloat();
+  prevComaIndex = nextComaIndex;
+
+  nextComaIndex = row.indexOf(",", prevComaIndex + 1 );
+  forceTypes[totalForceTypes].angle = row.substring(prevComaIndex + 1 , nextComaIndex).toFloat();
+  prevComaIndex = nextComaIndex;
+
+  nextComaIndex = row.indexOf(",", prevComaIndex + 1 );
+  forceTypes[totalForceTypes].percentBodyWeight = ( row.substring(prevComaIndex + 1 , nextComaIndex) == 1 );
+  totalForceTypes++;
+}
+
+void saveForceList()
+{
+  SD.remove("FORCTYPE.TXT");
+ 
+  File forceFile = SD.open("FORCTYPE.TXT", FILE_WRITE);
+
+//  if(gravFile) Serial.println("File created");
+//  else Serial.println("Error creating file");
+
+  for (unsigned int i = 0; i < totalForceTypes; i++)
+  {
+    forceFile.print(forceTypes[i].id);
+    forceFile.print("," + String(forceTypes[i].name));
+    forceFile.print("," + forceTypes[i].description );
+    forceFile.print("," + String(forceTypes[i].percentBodyWeight));
+    forceFile.print("," + String(forceTypes[i].angle));
+    forceFile.println("," + String(forceTypes[i].tare));
+  }
+  forceFile.close();
+  Serial.println("Saved " + String(totalForceTypes) + " to FORCTYPE.TXT");
+}
+
 void readExercisesFile(String parameters){
   parameters = parameters.substring(0, parameters.lastIndexOf(";"));
   if ( parameters == "jumps" ) readExercisesFile(jumps);
   else if ( parameters == "gravitatory" ) readExercisesFile(gravitatory);
   else if ( parameters == "inertial" ) readExercisesFile(inertial);
+  else if ( parameters == "force" ) readExercisesFile( force );
   else Serial.print("Not a valid parameter");
 }
+
 void readExercisesFile(exerciseType mode)
 {
   char readChar;
@@ -179,14 +232,15 @@ void readExercisesFile(exerciseType mode)
   if (mode == jumps) {
     //Serial.println("J");
     file = "JUMPTYPE.TXT";
-  }
-  else if (mode == gravitatory) {
+  } else if (mode == gravitatory) {
     //Serial.println("G");
     file = "GRAVTYPE.TXT";
-  }
-  else if (mode == inertial) {
-    //Serial.println("G");
+  } else if (mode == inertial) {
+    //Serial.println("I");
     file = "INERTYPE.TXT";
+  } else if (mode == force) {
+    //Serial.println("F");
+    file = "FORCTYPE.TXT";
   }
 
   File  exercisesFile = SD.open(file);
@@ -222,6 +276,9 @@ void readExercisesFile(exerciseType mode)
         } else if (mode == inertial) {
           addInertial(readString);
           totalInertTypes = numRows;
+        } else if (mode == force) {
+          addForce(readString);
+          totalForceTypes = numRows;
         }
       }
     }
@@ -230,7 +287,7 @@ void readExercisesFile(exerciseType mode)
   exercisesFile.close();
 }
 
-void printJumpTypesList()
+void printJumpTypes()
 {
   Serial.println("id, name, jumpLimit,timeLimit, hardTimeLimit, percentBodyWeight, fall, startIn");
   for (unsigned int i = 0; i < totalJumpTypes; i++)
@@ -248,7 +305,7 @@ void printJumpTypesList()
   }
 }
 
-void printGravTypesList()
+void printGravTypes()
 {
   Serial.println("id, name, description, percentBodyWeight, speed1RM");
   for (unsigned int i = 0; i < totalGravTypes; i++)
@@ -261,7 +318,7 @@ void printGravTypesList()
   }
 }
 
-void printInertTypesList()
+void printInertTypes()
 {
   Serial.println("id, name, description, percentBodyWeight");
   for (unsigned int i = 0; i < totalInertTypes; i++)
@@ -273,6 +330,20 @@ void printInertTypesList()
   }
 }
 
+void printForceTypes()
+{
+  Serial.println("id, name, description, percentBodyWeight, angle, tare");
+  for (unsigned int i = 0; i < totalForceTypes; i++)
+  {
+    Serial.print(String(forceTypes[i].id) + ", ");
+    Serial.print(forceTypes[i].name + ", ");
+    Serial.print(forceTypes[i].description + ", ");
+    Serial.print(String( forceTypes[i].percentBodyWeight , 2) + "%, ");
+    Serial.print(String( forceTypes[i].angle , 2) + ", ");
+    Serial.println(forceTypes[i].tare);
+  }
+}
+
 void selectExerciseType(exerciseType mode)
 {
   tft.fillScreen(BLACK);
diff --git a/arduino/michrolab/michrolab.ino b/arduino/michrolab/michrolab.ino
index 774e65af1..276967d13 100644
--- a/arduino/michrolab/michrolab.ino
+++ b/arduino/michrolab/michrolab.ino
@@ -115,6 +115,7 @@ enum exerciseType {
   jumps,
   inertial,
   gravitatory,
+  force,
   encoderRace,
   photocelRace
 };
@@ -195,7 +196,7 @@ menuEntry mainMenu[10] = {
   { "System", "Performs calibration or\ntare and shows some system\ninformation.", &showSystemMenu}
 };
 
-int mainMenuItems = 8;
+int mainMenuItems = 9;
 
 menuEntry systemMenu[10] {
   { "Group", "Select the group you are going to use.\nUp to 9 groups can be\nselected", &selectGroup},
@@ -386,6 +387,18 @@ inertMachineType inertMachines[10];
 unsigned int totalInertMachines = 0;
 unsigned int currentInertMachine = 0;
 
+struct forceType {
+  unsigned int id;
+  String name;
+  String description;
+  float percentBodyWeight;
+  float angle;
+  bool tare;
+};
+
+forceType forceTypes[100];
+unsigned int totalForceTypes = 0;
+
 IntervalTimer rcaTimer;
 String fullFileName;
 File dataFile;
@@ -665,7 +678,7 @@ void serialEvent() {
     addJump(parameters);
     //Serial.println("Jump added");
   } else if (commandString == "getJumpTypes") {
-    printJumpTypesList();
+    printJumpTypes();
   } else if (commandString == "saveJumpTypes") {
     saveJumpsList();
   } else if (commandString == "deleteJumpTypes") {
@@ -673,16 +686,16 @@ void serialEvent() {
   } else if (commandString == "readExercisesFile") {
     readExercisesFile(parameters);
   } else if (commandString == "getGravitatoryTypes") {
-    printGravTypesList();
+    printGravTypes();
   } else if (commandString == "addGravitatoryType") {
     addGravitatory(parameters);
     //Serial.println("Gravitatory added");  
   } else if (commandString == "deleteGravitatoryTypes") {
     totalGravTypes = 0;
   } else if (commandString == "saveGravitatoryTypes") {
-    saveInertialList();
+    saveGravitatoryList();
   } else if (commandString == "getInertialTypes") {
-    printInertTypesList();
+    printInertTypes();
   } else if (commandString == "addInertialType") {
     addInertial(parameters);
     //Serial.println("Gravitatory added");  
@@ -696,6 +709,14 @@ void serialEvent() {
     saveInertMachines();
   } else if (commandString == "readInertialMachinesFile") {
     readInertMachineFile();
+  } else if (commandString == "getForceTypes") {
+    printForceTypes();
+  } else if (commandString == "addForceType") {
+    addForce(parameters);
+  } else if (commandString == "deleteForceTypes") {
+    totalForceTypes = 0;
+  } else if (commandString == "saveForceTypes") {
+    saveForceList();
   } else if (commandString == "startRaceAnalyzerCapture") {
     PcControlled = true;
     startRaceAnalyzerCapture();
@@ -1580,7 +1601,7 @@ void jumpsCapture()
 {
   attachInterrupt(rcaPin, changedRCA, CHANGE);
   if (totalJumpTypes == 0) readExercisesFile(jumps);
-  //printJumpTypesList();
+  //printJumpTypes();
   selectExerciseType(jumps);
   IntervalTimer testTime;             //Timer that controls the refreshing of time in lower right corner
   capturing = true;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]