[chronojump/michrolab] captureBars can be in fullScreen mode



commit 612c83370d5135015fdefe303cc9a2f10c73abfd
Author: Xavier Padullés <testing chronojump org>
Date:   Mon Aug 29 11:10:38 2022 +0200

    captureBars can be in fullScreen mode

 arduino/michrolab/graphs.ino    |   9 ++--
 arduino/michrolab/michrolab.ino | 100 +++++++++++++++++++++++++++++++---------
 2 files changed, 84 insertions(+), 25 deletions(-)
---
diff --git a/arduino/michrolab/graphs.ino b/arduino/michrolab/graphs.ino
index 1bfb9d27b..0fe6d9254 100644
--- a/arduino/michrolab/graphs.ino
+++ b/arduino/michrolab/graphs.ino
@@ -61,8 +61,10 @@ void Graph(ILI9341_t3 & d, double x, double y, double gx, double gy, double w, d
   oy = y;
 
 }
-
-void redrawAxes(ILI9341_t3 & d, double gx, double gy, double w, double h, double xlo, double xhi, double 
ylo, double yhi, double yinc, String title, String xlabel, String ylabel, unsigned int gcolor, unsigned int 
acolor, unsigned int pcolor, unsigned int tcolor, unsigned int bcolor, unsigned int goalColor, boolean resize)
+void redrawAxes(ILI9341_t3 & d, double gx, double gy, double w, double h, double xlo, double xhi, double 
ylo, double yhi, double yinc, String title, String xlabel, String ylabel, unsigned int gcolor, unsigned int 
acolor, unsigned int pcolor, unsigned int tcolor, unsigned int bcolor, unsigned int goalColor, boolean 
resize){
+  redrawAxes(d, gx, gy, w, h, xlo, xhi, ylo, yhi, yinc, title, xlabel, ylabel, gcolor, acolor, pcolor, 
tcolor, bcolor, goalColor, resize, 0);
+}
+void redrawAxes(ILI9341_t3 & d, double gx, double gy, double w, double h, double xlo, double xhi, double 
ylo, double yhi, double yinc, String title, String xlabel, String ylabel, unsigned int gcolor, unsigned int 
acolor, unsigned int pcolor, unsigned int tcolor, unsigned int bcolor, unsigned int goalColor, boolean 
resize, int dec)
 {
   //double ydiv, xdiv;
   // initialize old x and old y in order to draw the first point of the graph
@@ -100,7 +102,8 @@ void redrawAxes(ILI9341_t3 & d, double gx, double gy, double w, double h, double
     //If the scale has changed the numbers must be redrawn
     if (resize)
     {
-      printTftValue(i, gx - 6, yAxis - 3, 1, 0);
+      if(dec == 0) printTftValue(i, gx - 6, yAxis - 3, 1, dec);
+      else if(dec > 0) printTftValue(i, gx - 6 - 5*(dec + 1), yAxis - 3, 1, dec);
     }
   }
 
diff --git a/arduino/michrolab/michrolab.ino b/arduino/michrolab/michrolab.ino
index 69003f925..031cf7df7 100644
--- a/arduino/michrolab/michrolab.ino
+++ b/arduino/michrolab/michrolab.ino
@@ -426,7 +426,7 @@ void setup() {
   currentExerciseType = 0;
 
   tft.fillScreen(BLACK);
-
+  startEncoderCapture();
   drawMenuBackground();
   backMenu();
   showMenuEntry(currentMenuIndex);
@@ -1121,10 +1121,11 @@ void captureRaw()
   if (!capturingPreSteadiness) setNumber++;
 }
 
-void captureBars()
+void captureBars() {captureBars(false);}
+void captureBars(float fullScreen)
 {
   maxString = "V";
-  float graphRange = 10;
+  float graphRange = 5;
   int currentSlot = 0;
   String fileName = "P" + String(currentPerson) + "-S" + String(setNumber);
 
@@ -1136,15 +1137,69 @@ void captureBars()
   dataFile = SD.open(fullFileName.c_str(), FILE_WRITE);
 
   tft.fillScreen(BLACK);
+  
+  float h = 0;
+  if (fullScreen) h = 240;
+  else h = 200;
+  
+  if (!fullScreen)
+  {
+    //Info at the lower part of the screen
+    printTftText(maxString, 10, 215, WHITE, 2);
+    printTftText("max", 22, 223, WHITE, 1);
+    printTftText(":", 40, 215, WHITE, 2);
+    printTftValue(maxAvgVelocity, 94, 215, 2, 1);
+    updatePersonSet();
+  }
 
-  //Info at the lower part of the screen
-  printTftText(maxString, 10, 215, WHITE, 2);
-  printTftText("max", 22, 223, WHITE, 1);
-  printTftText(":", 40, 215, WHITE, 2);
-  printTftValue(maxAvgVelocity, 94, 215, 2, 1);
-  updatePersonSet();
+  redrawAxes(tft, 30, h, 290, h, 290, h, 0, graphRange, graphRange / 10, "", "", "", WHITE, GREY, WHITE, 
WHITE, BLACK, RED, true, 1);
 
-  redrawAxes(tft, 30, 200, 290, 200, 290, 200, 0, graphRange, graphRange / 10, "", "", "", WHITE, GREY, 
WHITE, WHITE, BLACK, RED, true);
+  while (capturing)
+  {
+    getEncoderDynamics();
+    if (redrawBars)
+    {
+      currentSlot = (numRepetitions - 1) % 10;
+      redrawBars = false;
+      if(bars[currentSlot] > maxAvgVelocity)
+      {
+        if (!fullScreen) printTftValue(maxAvgVelocity, 94, 215, 2, 1, BLACK);
+        maxAvgVelocity = bars[currentSlot];
+        if (!fullScreen) printTftValue(maxAvgVelocity, 94, 215, 2, 1);
+      }
+      if (bars[currentSlot] > graphRange)
+      {
+        redrawAxes(tft, 30, h, 290, h, 290, h, 0, graphRange, graphRange / 10, "", "", "", WHITE, GREY, 
WHITE, WHITE, BLACK, RED, true, 1);
+        graphRange = bars[currentSlot] * 1.25;
+      }
+      redrawAxes(tft, 30, h, 290, h, 290, h, 0, graphRange, graphRange / 10, "", "", "", WHITE, GREY, WHITE, 
WHITE, BLACK, RED, true, 1);
+      barPlot(30, h, 290, h, graphRange, 10, currentSlot, 0.75, RED);
+    }
+    redButton.update();
+    if (redButton.fell())
+    {
+      endEncoderCapture();
+    }
+  }
+}
+
+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)
   {
@@ -1155,17 +1210,17 @@ void captureBars()
       redrawBars = false;
       if(bars[currentSlot] > maxAvgVelocity)
       {
-        printTftValue(maxAvgVelocity, 94, 215, 2, 1, BLACK);
+        //printTftValue(maxAvgVelocity, 94, 215, 2, 1, BLACK);
         maxAvgVelocity = bars[currentSlot];
-        printTftValue(maxAvgVelocity, 94, 215, 2, 1);
+        //printTftValue(maxAvgVelocity, 94, 215, 2, 1);
       }
       if (bars[currentSlot] > graphRange)
       {
-        redrawAxes(tft, 30, 200, 290, 200, 290, 200, 0, graphRange, graphRange / 10, "", "", "", WHITE, 
GREY, WHITE, WHITE, BLACK, RED, true);
+        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, 200, 290, 200, 290, 200, 0, graphRange, graphRange / 10, "", "", "", WHITE, GREY, 
WHITE, WHITE, BLACK, RED, true);
-      barPlot(30, 200, 290, 200, graphRange, 10, currentSlot, 0.75, RED);
+      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())
@@ -1222,6 +1277,7 @@ void getEncoderDynamics()
     //TODO: Calculate positoion depending on the parameters of the encoder/machine
     if (inertialMode) position = - abs(position);
     measured = (float)(position - lastEncoderPosition) * 1000 / (duration);
+    if(measured > measuredMax) measuredMax = measured;
     //measured = position;
     //    if(position != lastEncoderPosition) Serial.println(String(localMax) + "\t" + 
String(lastEncoderPosition) +
     //      "\t" + String(position) + "\t" + String(encoderPhase * (position - localMax)));
@@ -1264,12 +1320,12 @@ void getEncoderDynamics()
       bars[numRepetitions % 10] = abs(avgVelocity);
       redrawBars = true;
 
-      //      for(int i = 0; i<10; i++)
-      //      {
-      //        Serial.print(bars[ (numRepetitions%10 - i + 10) % 10]);
-      //        Serial.print("\t");
-      //      }
-      //      Serial.println();
+//      for(int i = 0; i<10; i++)
+//      {
+//        Serial.print(bars[ (numRepetitions%10 - i + 10) % 10]);
+//        Serial.print("\t");
+//      }
+//      Serial.println();
 
       numRepetitions++;
       if (avgVelocity > maxAvgVelocity)
@@ -1315,7 +1371,7 @@ void startEncoderCapture(void)
   selectValueDialog("Select the load you are\ngoing to move", "0,5,20,200", "0.5,1,5", 1);
   //captureRaw();
   encoderTimer.begin(saveEncoderSpeed, 1000);
-  captureBars();
+  captureBars(false);
 }
 
 void endEncoderCapture()


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