[chronojump/michrolab] Starting of the serial port exercices management



commit 0908359bbc54e05ef36e5d0b0e4c192a36aa51ab
Author: Xavier Padullés <testing chronojump org>
Date:   Tue Aug 30 08:26:44 2022 +0200

    Starting of the serial port exercices management

 arduino/michrolab/exercsiseManage.ino | 28 +++++++++++-
 arduino/michrolab/michrolab.ino       | 80 +++++++++++------------------------
 2 files changed, 51 insertions(+), 57 deletions(-)
---
diff --git a/arduino/michrolab/exercsiseManage.ino b/arduino/michrolab/exercsiseManage.ino
index 2d4575905..8112df109 100644
--- a/arduino/michrolab/exercsiseManage.ino
+++ b/arduino/michrolab/exercsiseManage.ino
@@ -39,6 +39,32 @@ void addJump(String row)
   jumpTypes[currentExerciseType].startIn = (row.substring(prevComaIndex + 1, prevComaIndex + 2) == "1");
 }
 
+void saveJumpsList()
+{
+  SD.remove("jumpType.txt");
+  if( !SD.exists("jumpType.txt") ) Serial.println("File doesn't exists");
+  else Serial.println("File exists");
+ 
+  File jumpFile = SD.open("jumpType.txt", FILE_WRITE);
+
+
+  for (int i = 0; i < totalJumps; i++)
+  {
+    jumpFile.print(jumpTypes[i].id);
+    jumpFile.print("," + String(jumpTypes[i].name));
+    jumpFile.print("," + String(jumpTypes[i].jumpLimit));
+    jumpFile.print("," + String(jumpTypes[i].timeLimit));
+    jumpFile.print("," + String(jumpTypes[i].hardTimeLimit));
+    jumpFile.print("," + String(jumpTypes[i].percentBodyWeight));
+    jumpFile.print("," + String(jumpTypes[i].fall));
+    jumpFile.println("," + String(jumpTypes[i].startIn));
+  }
+  jumpFile.flush();
+  jumpFile.close();
+  
+  Serial.println("Jump types saved in jumpType.txt");
+}
+
 void addGravitatory(String row)
 {
   int prevComaIndex = row.indexOf(":");
@@ -123,7 +149,7 @@ void readExercisesFile(exerciseType mode)
 void printJumpTypesList()
 {
   Serial.println("id, name, jumpLimit,timeLimit, hardTimeLimit, percentBodyWeight, fall, startIn");
-  for (unsigned int i = 0; i < totalGravTypes; i++)
+  for (unsigned int i = 0; i < totalJumpTypes; i++)
   {
     Serial.print(jumpTypes[i].id);
     Serial.print("," + jumpTypes[i].name + ", ");
diff --git a/arduino/michrolab/michrolab.ino b/arduino/michrolab/michrolab.ino
index 16aecfcaa..2d2f81f29 100644
--- a/arduino/michrolab/michrolab.ino
+++ b/arduino/michrolab/michrolab.ino
@@ -427,7 +427,15 @@ void setup() {
   currentExerciseType = 0;
 
   tft.fillScreen(BLACK);
-  startEncoderCapture();
+
+  readExercisesFile(jumps);
+  printJumpTypesList();
+  addJump("14,Prova,,0,0,0,0,0,1");
+  printJumpTypesList();
+  saveJumpsList();
+  readExercisesFile(jumps);
+  printJumpTypesList();
+  
   drawMenuBackground();
   backMenu();
   showMenuEntry(currentMenuIndex);
@@ -572,7 +580,7 @@ void printTftText(String text, int x, int y, unsigned int color, int fontSize, b
 void serialEvent() {
   String inputString = Serial.readString();
   String commandString = inputString.substring(0, inputString.lastIndexOf(":"));
-
+  String parameters = inputString.substring(commandString.indexOf(":") + 1);
 
   if (commandString == "start_capture") {
     PcControlled = true;
@@ -603,12 +611,21 @@ void serialEvent() {
       //    listenSyncSignal();
     */
   } else if (commandString == "addPerson") {
-    addPerson(inputString.substring(commandString.indexOf(":") + 1));
-  } else if (commandString == "getPersonsList") {
+    addPerson(parameters);
+  } else if (commandString == "getPersons") {
     printPersonsList();
-  } else if (commandString == "savePersonsList") {
+  } else if (commandString == "savePersons") {
     Serial.println("Going to savePersons...");
     savePersonsList();
+  } else if (commandString == "addJumpType") {
+    addJump(parameters);
+    Serial.println("Jump added");
+  } else if (commandString == "getJumpTypes") {
+    printJumpTypesList();
+  } else if (commandString == "saveJumpTypes") {
+    saveJumpsList();
+//  } else if (commandString == "saveGravit") {
+//    saveGravitatory();
   } else {
     Serial.println("Not a valid command");
   }
@@ -1187,53 +1204,6 @@ void captureBars(float fullScreen)
   }
 }
 
-void captureBarsFullScreen()
-{
-  maxString = "V";
-  float graphRange = 5;
-  int currentSlot = 0;
-  String fileName = "P" + String(currentPerson) + "-S" + String(setNumber);
-
-  if (sensor == incEncoder) fileName = fileName + "-G";
-  else if (sensor == incRotEncoder) fileName = fileName + "-I";
-  else if (sensor == loadCellincEncoder) fileName = fileName + "-P";
-
-  fullFileName = "/" + dirName + "/" + fileName + ".txt";
-  dataFile = SD.open(fullFileName.c_str(), FILE_WRITE);
-
-  tft.fillScreen(BLACK);
-
-  redrawAxes(tft, 30, 240, 290, 240, 290, 240, 0, graphRange, graphRange / 10, "", "", "", WHITE, GREY, 
WHITE, WHITE, BLACK, RED, true, 1);
-
-  while (capturing)
-  {
-    getEncoderDynamics();
-    if (redrawBars)
-    {
-      currentSlot = (numRepetitions - 1) % 10;
-      redrawBars = false;
-      if(bars[currentSlot] > maxAvgVelocity)
-      {
-        //printTftValue(maxAvgVelocity, 94, 215, 2, 1, BLACK);
-        maxAvgVelocity = bars[currentSlot];
-        //printTftValue(maxAvgVelocity, 94, 215, 2, 1);
-      }
-      if (bars[currentSlot] > graphRange)
-      {
-        redrawAxes(tft, 30, 240, 290, 240, 290, 240, 0, graphRange, graphRange / 10, "", "", "", WHITE, 
GREY, WHITE, WHITE, BLACK, RED, true, 1);
-        graphRange = bars[currentSlot] * 1.25;
-      }
-      redrawAxes(tft, 30, 240, 290, 240, 290, 240, 0, graphRange, graphRange / 10, "", "", "", WHITE, GREY, 
WHITE, WHITE, BLACK, RED, true, 1);
-      barPlot(30, 240, 290, 240, graphRange, 10, currentSlot, 0.75, RED);
-    }
-    redButton.update();
-    if (redButton.fell())
-    {
-      endEncoderCapture();
-    }
-  }
-}
-
 //text mode
 void saveEncoderSpeed()
 {
@@ -1579,10 +1549,8 @@ void jumpsCapture()
             Serial.print("R");
             tft.fillRect(30, 0, 290, 200, BLACK);
             bars[index] = 122.6 * lastPhaseTime * lastPhaseTime; //In cm
-            tft.setTextColor(BLACK);
             //We always add 10 to index to avoid the negative number in (index - 1) when index is 0
-            printTftValue(bars[(index + 10 - 1) % 10], 58, 215, 2, 2);
-            tft.setTextColor(WHITE);
+            printTftValue(bars[(index + 10 - 1) % 10], 58, 215, 2, 2, BLACK);
             printTftValue(bars[index], 58, 215, 2, 2);
             //Check if a new best jump is performed
             if (bars[index] > maxJump)
@@ -1615,7 +1583,7 @@ void jumpsCapture()
             dataFile.print("r");
             Serial.print("r");
           }
-          //Waiting first phase. TODO: Make it sensible to startIn parameter
+          //Waiting first phase.
         } else if (waitingFirstPhase && capturing) {
           //          Serial.print("#");
           //          if (rcaState) Serial.print("IN");


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