[chronojump/FS-TFT-Menu] Imported Xavi Cano implementation of force graph during capture



commit a6b8fda972cab1acd739cac50d1837cf6e1be72b
Author: xpadulles <x padulles gmail com>
Date:   Wed Apr 20 18:11:36 2022 +0200

    Imported Xavi Cano implementation of force graph during capture

 arduino/ForceSensorTFT/ForceSensorTFT.ino | 114 +++++++++++++++++++++++++++++-
 1 file changed, 111 insertions(+), 3 deletions(-)
---
diff --git a/arduino/ForceSensorTFT/ForceSensorTFT.ino b/arduino/ForceSensorTFT/ForceSensorTFT.ino
index d8be77726..50ef7b0ba 100644
--- a/arduino/ForceSensorTFT/ForceSensorTFT.ino
+++ b/arduino/ForceSensorTFT/ForceSensorTFT.ino
@@ -99,7 +99,8 @@ bool blueButtonState;
 unsigned short lcdDelay = 25; //to be able to see the screen. Seconds are also printed in delay but 25 
values are less than one second
 unsigned short lcdCount = 0;
 float measuredLcdDelayMax = 0; //The max in the lcdDelay periodca
-float measuredMax = 0; // The max since starting capture
+float measuredMax = 20; // The max since starting capture
+float measuredMin = -20;
 float measured = scale.get_units();
 
 /***** Atention!!! *****
@@ -1085,8 +1086,10 @@ void showMenu(void)
 void capture(void)
 {
   MsTimer2::stop();
+  int xGraph = 0;
   if (capturing)
   {
+    while (xGraph !=300) {
     //Checking the RCA state
     if (rcaState != lastRcaState) {       //Event generated by the RCA
       Serial.print(rcaTime);
@@ -1169,14 +1172,20 @@ void capture(void)
       if (abs(measured) > abs(measuredLcdDelayMax)) {
         measuredLcdDelayMax = measured;
       }
-      if (abs(measured) > abs(measuredMax)) {
+      if (measured > measuredMax) {
         measuredMax = measured;
       }
+      if (measured < measuredMin) {
+        measuredMin = measured;
+      }
 
       Serial.print(totalTime); Serial.print(";");
       Serial.println(measured, 2); //scale.get_units() returns a float
 
-      printOnLcd();
+      //printOnLcd();
+      //Graph(tft, x, v, 30, 240, 320, 240, 0, 320, 100, 0, v_max, 100, "", "", "", WHITE, WHITE, BLUE, 
WHITE, BLACK, display1);
+      Graph(tft, xGraph, measured, 30, 240, 320, 240, -20, 320, 100, measuredMin, measuredMax, 100, "", "", 
"", WHITE, WHITE, BLUE, WHITE, BLACK, display1);
+      xGraph++;
     }
 
     //Pressing blue or red button ends the capture
@@ -1197,6 +1206,10 @@ void capture(void)
         start_capture();
       }
     }
+    }
+    xGraph = 0;
+    tft.fillScreen(BLACK);
+    display1 = true;
   }
   MsTimer2::start();
 }
@@ -1228,6 +1241,8 @@ void printOnLcd() {
 }
 
 
+
+
 void printLcdFormat (float val, int xStart, int y, int decimal) {
 
   /*How many characters are to the left of the units number.
@@ -1839,3 +1854,96 @@ void showSteadinessResults()
   MsTimer2::start();
   showMenu();
 }
+
+void Graph(Adafruit_ILI9341 &d, double x, double y, double gx, double gy, double w, double h, double xlo, 
double xhi, double xinc, 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, 
boolean &redraw) 
+{
+
+  double ydiv, xdiv;
+  // initialize old x and old y in order to draw the first point of the graph
+  // but save the transformed value
+  // note my transform funcition is the same as the map function, except the map uses long and we need 
doubles
+  //static double ox = (x - xlo) * ( w) / (xhi - xlo) + gx;
+  //static double oy = (y - ylo) * (gy - h - gy) / (yhi - ylo) + gy;
+  double i;
+  double temp;
+  int rot, newrot;
+
+  if (redraw == true) 
+  {
+
+    redraw = false;
+    ox = (x - xlo) * ( w) / (xhi - xlo) + gx;
+    oy = (y - ylo) * (gy - h - gy) / (yhi - ylo) + gy;
+    // draw y scale
+    for ( i = ylo; i <= yhi; i += yinc) 
+    {
+      // compute the transform
+      temp =  (i - ylo) * (gy - h - gy) / (yhi - ylo) + gy;
+
+      if (i == 0) 
+      {
+        d.drawLine(gx, temp, gx + w, temp, acolor);
+      }
+      else 
+      {
+        d.drawLine(gx, temp, gx + w, temp, gcolor);
+      }
+
+      d.setTextSize(1);
+      d.setTextColor(tcolor, bcolor);
+      //d.setCursor(gx - 40, temp);
+      d.setCursor(gx - 30, temp);
+      // precision is default Arduino--this could really use some format control
+      d.println((int)round(i));
+    }
+    // draw x scale
+    for (i = xlo; i <= xhi; i += xinc) {
+
+      // compute the transform
+
+      temp =  (i - xlo) * ( w) / (xhi - xlo) + gx;
+      if (i == 0) {
+        d.drawLine(temp, gy, temp, gy - h, acolor);
+      }
+      else {
+        d.drawLine(temp, gy, temp, gy - h, gcolor);
+      }
+
+      d.setTextSize(1);
+      d.setTextColor(tcolor, bcolor);
+      d.setCursor(temp, gy + 10);
+      // precision is default Arduino--this could really use some format control
+      d.println(round(i));
+    }
+
+    //now draw the labels
+    d.setTextSize(2);
+    d.setTextColor(tcolor, bcolor);
+    d.setCursor(gx , gy - h - 30);
+    d.println(title);
+
+    d.setTextSize(1);
+    d.setTextColor(acolor, bcolor);
+    d.setCursor(gx , gy + 20);
+    d.println(xlabel);
+
+    d.setTextSize(1);
+    d.setTextColor(acolor, bcolor);
+    d.setCursor(gx - 30, gy - h - 10);
+    d.println(ylabel);
+
+
+  }
+
+  //graph drawn now plot the data
+  // the entire plotting code are these few lines...
+  // recall that ox and oy are initialized as static above
+  x =  (x - xlo) * ( w) / (xhi - xlo) + gx;
+  y =  (y - ylo) * (gy - h - gy) / (yhi - ylo) + gy;
+  d.drawLine(ox, oy, x, y, pcolor);
+  d.drawLine(ox, oy + 1, x, y + 1, pcolor);
+  d.drawLine(ox, oy - 1, x, y - 1, pcolor);
+  ox = x;
+  oy = y;
+
+}


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