[chronojump/michrolab] Added gravitatory exercices types management



commit 25ad22838129e0d32487dfe0bf3911acb8e21b6d
Author: Xavier Padullés <testing chronojump org>
Date:   Wed Aug 31 10:47:17 2022 +0200

    Added gravitatory exercices types management

 arduino/michrolab/exercsiseManage.ino | 88 +++++++++++++++++++----------------
 arduino/michrolab/michrolab.ino       | 23 +++++----
 2 files changed, 62 insertions(+), 49 deletions(-)
---
diff --git a/arduino/michrolab/exercsiseManage.ino b/arduino/michrolab/exercsiseManage.ino
index 3573ab7a2..da7bb1a7f 100644
--- a/arduino/michrolab/exercsiseManage.ino
+++ b/arduino/michrolab/exercsiseManage.ino
@@ -1,45 +1,44 @@
 void addJump(String row)
 {
-  currentExerciseType = totalJumpTypes;
   int prevComaIndex = row.indexOf(":");
   int nextComaIndex = row.indexOf(",");
-  //currentExerciseType = row.substring(prevComaIndex + 1, nextComaIndex).toInt();
-  jumpTypes[currentExerciseType].id = row.substring(prevComaIndex + 1, nextComaIndex).toInt();
+  //totalJumpTypes = row.substring(prevComaIndex + 1, nextComaIndex).toInt();
+  jumpTypes[totalJumpTypes].id = row.substring(prevComaIndex + 1, nextComaIndex).toInt();
 
   prevComaIndex = nextComaIndex;
   nextComaIndex = row.indexOf(",", prevComaIndex + 1 );
-  jumpTypes[currentExerciseType].name = row.substring(prevComaIndex + 1 , nextComaIndex);
+  jumpTypes[totalJumpTypes].name = row.substring(prevComaIndex + 1 , nextComaIndex);
   prevComaIndex = nextComaIndex;
 
   prevComaIndex = nextComaIndex;
   nextComaIndex = row.indexOf(",", prevComaIndex + 1 );
-  jumpTypes[currentExerciseType].jumpLimit = row.substring(prevComaIndex + 1, nextComaIndex).toInt();
+  jumpTypes[totalJumpTypes].jumpLimit = row.substring(prevComaIndex + 1, nextComaIndex).toInt();
   prevComaIndex = nextComaIndex;
 
   prevComaIndex = nextComaIndex;
   nextComaIndex = row.indexOf(",", prevComaIndex + 1 );
-  jumpTypes[currentExerciseType].timeLimit = row.substring(prevComaIndex + 1, nextComaIndex).toFloat();
+  jumpTypes[totalJumpTypes].timeLimit = row.substring(prevComaIndex + 1, nextComaIndex).toFloat();
   prevComaIndex = nextComaIndex;
 
   prevComaIndex = nextComaIndex;
   nextComaIndex = row.indexOf(",", prevComaIndex + 1 );
-  jumpTypes[currentExerciseType].hardTimeLimit = (row.substring(prevComaIndex + 1 , nextComaIndex) == 1);
+  jumpTypes[totalJumpTypes].hardTimeLimit = (row.substring(prevComaIndex + 1 , nextComaIndex) == 1);
   prevComaIndex = nextComaIndex;
 
   prevComaIndex = nextComaIndex;
   nextComaIndex = row.indexOf(",", prevComaIndex + 1 );
-  jumpTypes[currentExerciseType].percentBodyWeight = row.substring(prevComaIndex + 1 , 
nextComaIndex).toFloat();
+  jumpTypes[totalJumpTypes].percentBodyWeight = row.substring(prevComaIndex + 1 , nextComaIndex).toFloat();
   prevComaIndex = nextComaIndex;
 
   prevComaIndex = nextComaIndex;
   nextComaIndex = row.indexOf(",", prevComaIndex + 1 );
-  jumpTypes[currentExerciseType].fall = row.substring(prevComaIndex + 1, nextComaIndex).toFloat();
+  jumpTypes[totalJumpTypes].fall = row.substring(prevComaIndex + 1, nextComaIndex).toFloat();
   prevComaIndex = nextComaIndex;
 
   prevComaIndex = nextComaIndex;
-  jumpTypes[currentExerciseType].startIn = (row.substring(prevComaIndex + 1, prevComaIndex + 2) == "1");
+  jumpTypes[totalJumpTypes].startIn = (row.substring(prevComaIndex + 1, prevComaIndex + 2) == "1");
   totalJumpTypes++;
-  Serial.println("totalJumpTypes: " + String(totalJumpTypes));
+  //Serial.println("totalJumpTypes: " + String(totalJumpTypes));
 }
 
 void saveJumpsList()
@@ -62,53 +61,65 @@ void saveJumpsList()
     jumpFile.print("," + String(jumpTypes[i].fall));
     jumpFile.println("," + String(jumpTypes[i].startIn));
   }
-  jumpFile.flush();
   jumpFile.close();
-}
-
-void deleteJumpTypes()
-{
-  totalJumpTypes = 0;
-//  for (int i = 0; i < totalJumpTypes; i++)
-//  {
-//    jumpTypes[i].id = 0;
-//    jumpTypes[i].name = "";
-//    jumpTypes[i].jumpLimit = 0;
-//    jumpTypes[i].timeLimit = 0;
-//    jumpTypes[i].hardTimeLimit = false;
-//    jumpTypes[i].percentBodyWeight = 0.0;
-//    jumpTypes[i].fall = 0.0;
-//    jumpTypes[i].startIn = true;
-//  }
+  Serial.println("Saved " + String(totalJumpTypes) + " to JUMPTYPE.TXT");
 }
 
 void addGravitatory(String row)
 {
   int prevComaIndex = row.indexOf(":");
   int nextComaIndex = row.indexOf(",");
-  //currentExerciseType = row.substring(prevComaIndex + 1, nextComaIndex).toInt();
-  gravTypes[currentExerciseType].id = row.substring(prevComaIndex + 1, nextComaIndex).toInt();
+  //totalGravTypes = row.substring(prevComaIndex + 1, nextComaIndex).toInt();
+  gravTypes[totalGravTypes].id = row.substring(prevComaIndex + 1, nextComaIndex).toInt();
 
   prevComaIndex = nextComaIndex;
   nextComaIndex = row.indexOf(",", prevComaIndex + 1 );
-  gravTypes[currentExerciseType].name = row.substring(prevComaIndex + 1 , nextComaIndex);
+  gravTypes[totalGravTypes].name = row.substring(prevComaIndex + 1 , nextComaIndex);
   prevComaIndex = nextComaIndex;
 
   prevComaIndex = nextComaIndex;
   nextComaIndex = row.indexOf(",", prevComaIndex + 1 );
-  gravTypes[currentExerciseType].description = row.substring(prevComaIndex + 1, nextComaIndex);
+  gravTypes[totalGravTypes].description = row.substring(prevComaIndex + 1, nextComaIndex);
   prevComaIndex = nextComaIndex;
 
   prevComaIndex = nextComaIndex;
   nextComaIndex = row.indexOf(",", prevComaIndex + 1 );
-  gravTypes[currentExerciseType].percentBodyWeight = row.substring(prevComaIndex + 1 , 
nextComaIndex).toFloat();
+  gravTypes[totalGravTypes].percentBodyWeight = row.substring(prevComaIndex + 1 , nextComaIndex).toFloat();
   prevComaIndex = nextComaIndex;
 
   prevComaIndex = nextComaIndex;
   nextComaIndex = row.indexOf(",", prevComaIndex + 1 );
-  gravTypes[currentExerciseType].speed1Rm = row.substring(prevComaIndex + 1, nextComaIndex).toFloat();
+  gravTypes[totalGravTypes].speed1Rm = row.substring(prevComaIndex + 1, nextComaIndex).toFloat();
+  totalGravTypes++;
+}
+
+void saveGravitatoryList()
+{
+  SD.remove("GRAVTYPE.TXT");
+ 
+  File gravFile = SD.open("GRAVTYPE.TXT", FILE_WRITE);
+
+//  if(gravFile) Serial.println("File created");
+//  else Serial.println("Error creating file");
+
+  for (unsigned int i = 0; i < totalGravTypes; i++)
+  {
+    gravFile.print(jumpTypes[i].id);
+    gravFile.print("," + String(gravTypes[i].name));
+    gravFile.print("," + gravTypes[i].description );
+    gravFile.print("," + String(gravTypes[i].percentBodyWeight));
+    gravFile.println("," + String(gravTypes[i].speed1Rm));
+  }
+  gravFile.close();
+  Serial.println("Saved " + String(totalGravTypes) + " to GRAVTYPE.TXT");
 }
 
+void readExercisesFile(String parameters){
+  parameters = parameters.substring(0, parameters.lastIndexOf(";"));
+  if ( parameters == "jumps" ) readExercisesFile(jumps);
+  else if ( parameters == "gravitatory" ) readExercisesFile(gravitatory);
+  else Serial.print("Not a valid parameter");
+}
 void readExercisesFile(exerciseType mode)
 {
   char readChar;
@@ -159,6 +170,7 @@ void readExercisesFile(exerciseType mode)
         }
       }
     }
+    Serial.println("Total:" + String(numRows));
   }
   exercisesFile.close();
 }
@@ -176,15 +188,13 @@ void printJumpTypesList()
     else Serial.print("No, ");
     Serial.print(String( jumpTypes[i].percentBodyWeight , 2) + "%, ");
     Serial.print(String( jumpTypes[i].fall , 2) + "cm, ");
-    if(jumpTypes[i].startIn) Serial.println("Yes, ");
-    else Serial.println("No, ");
+    if(jumpTypes[i].startIn) Serial.println("Yes");
+    else Serial.println("No");
   }
 }
 
 void printGravTypesList()
 {
-  Serial.println();
-  Serial.println("totalGravTypes: " + String(totalGravTypes) );
   Serial.println("id, name, description, percentBodyWeight, speed1RM");
   for (unsigned int i = 0; i < totalGravTypes; i++)
   {
@@ -192,6 +202,6 @@ void printGravTypesList()
     Serial.print(gravTypes[i].name + ", ");
     Serial.print(gravTypes[i].description + ", ");
     Serial.print(String( gravTypes[i].percentBodyWeight , 2) + "%, ");
-    Serial.println(String( gravTypes[i].speed1Rm , 2) + "m/s, ");
+    Serial.println(String( gravTypes[i].speed1Rm , 2) + "m/s");
   }
 }
diff --git a/arduino/michrolab/michrolab.ino b/arduino/michrolab/michrolab.ino
index 4ea83efeb..aeac19f21 100644
--- a/arduino/michrolab/michrolab.ino
+++ b/arduino/michrolab/michrolab.ino
@@ -595,12 +595,6 @@ void serialEvent() {
     tare();
   } else if (commandString == "get_transmission_format") {
     get_transmission_format();
-    /* Commented due to memory optimization
-      //  } else if (commandString == "send_sync_signal") {
-      //    sendSyncSignal();
-      //  } else if (commandString == "listen_sync_signal") {
-      //    listenSyncSignal();
-    */
   } else if (commandString == "addPerson") {
     addPerson(parameters);
   } else if (commandString == "readPersonsFile") {
@@ -616,15 +610,24 @@ void serialEvent() {
     Serial.println(group);
   } else if (commandString == "addJumpType") {
     addJump(parameters);
-    Serial.println("Jump added");
+    //Serial.println("Jump added");
   } else if (commandString == "getJumpTypes") {
     printJumpTypesList();
   } else if (commandString == "saveJumpTypes") {
     saveJumpsList();
   } else if (commandString == "deleteJumpTypes") {
-    deleteJumpTypes();
-    //  } else if (commandString == "saveGravit") {
-    //    saveGravitatory();
+    totalJumpTypes = 0;
+  } else if (commandString == "readExercisesFile") {
+    readExercisesFile(parameters);
+  } else if (commandString == "getGravitatoryTypes") {
+    printGravTypesList();
+  } else if (commandString == "addGravitatoryType") {
+    addGravitatory(parameters);
+    //Serial.println("Gravitatory added");  
+  } else if (commandString == "deleteGravitatoryTypes") {
+    totalGravTypes = 0;
+  } else if (commandString == "saveGravitatoryTypes") {
+    saveGravitatoryList();
   } else {
     Serial.println("Not a valid command");
   }


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