[chronojump/FS-LCD-Menu] Fixed end_capture



commit 4b4deaa7eff8578010fbfb5fbfbfbbb704e723c2
Author: Xavier Padullés <x padulles gmail com>
Date:   Thu Dec 16 18:41:53 2021 +0100

    Fixed end_capture

 arduino/ForceSensorLCD/ForceSensorLCD.ino | 104 ++++++++++++++++--------------
 1 file changed, 56 insertions(+), 48 deletions(-)
---
diff --git a/arduino/ForceSensorLCD/ForceSensorLCD.ino b/arduino/ForceSensorLCD/ForceSensorLCD.ino
index 8323ae0d6..f2a0b7e8a 100644
--- a/arduino/ForceSensorLCD/ForceSensorLCD.ino
+++ b/arduino/ForceSensorLCD/ForceSensorLCD.ino
@@ -252,66 +252,78 @@ void setup() {
 
 void loop()
 {
-  blueButtonState = digitalRead(blueButtonPin);
-  if (blueButtonState) {
-    menu++;
-    menu = menu % 5;
-    showMenu();
-  }
-  delay(100);
-
-  redButtonState = digitalRead(redButtonPin);
-  if (redButtonState)
+  if (!capturing)
   {
-//    lcd.clear();
-//    lcd.setCursor(1, 0);
-//    lcd.print(menu);
-//    lcd.setCursor(3, 0);
-//    lcd.print(menuList[menu]);
-//    lcd.setCursor(2, 1);
-
-    if (menu == 0)
-    {
-      lcd.print("Capturing");
-      start_capture();
-      capture();
-    } else if (menu == 1)
-    {
-      tare();
-      start_capture();
-      capture();
-    } else if (menu == 2)
-    {
-      tare();
-      menu = 0;
-      showMenu();
-    } else if (menu == 3)
-    {
-      calibrateLCD();
-      menu = 0;
+    blueButtonState = digitalRead(blueButtonPin);
+    if (blueButtonState) {
+      blueButtonState = false;
+      menu++;
+      menu = menu % 5;
       showMenu();
-    } else if (menu == 4)
+    }
+    delay(100);
+
+    redButtonState = digitalRead(redButtonPin);
+    if (redButtonState)
     {
-      showSystemInfo();
-      menu = 0;
-      showMenu();
+      //    Serial.println("redButton");
+      //    lcd.clear();
+      //    lcd.setCursor(1, 0);
+      //    lcd.print(menu);
+      //    lcd.setCursor(3, 0);
+      //    lcd.print(menuList[menu]);
+      //    lcd.setCursor(2, 1);
+
+      if (menu == 0)
+      {
+        lcd.clear();
+        lcd.setCursor(0, 0);
+        lcd.print("Starting capture");
+        lcd.print("Capturing");
+        delay(200);
+        start_capture();
+      } else if (menu == 1)
+      {
+        tare();
+        start_capture();
+      } else if (menu == 2)
+      {
+        tare();
+        menu = 0;
+        showMenu();
+      } else if (menu == 3)
+      {
+        calibrateLCD();
+        menu = 0;
+        showMenu();
+      } else if (menu == 4)
+      {
+        showSystemInfo();
+        menu = 0;
+        showMenu();
+      }
+      redButtonState = false;
     }
+  } else
+  {
+    capture();
   }
 }
 
 void showMenu(void)
 {
+  //  Serial.println("Menu");
   lcd.clear();
   showBatteryLevel();
   lcd.setCursor(1, 0);
   lcd.print(menuList[menu]);
   lcd.createChar(6, menuChar);
-  lcd.setCursor(15,0);
+  lcd.setCursor(15, 0);
   lcd.write(byte (6));
   lcd.createChar(7, recordChar);
   lcd.setCursor(15, 1);
   lcd.write(byte (7));
-  lcd.setCursor(3,1);
+  lcd.setCursor(3, 1);
 
   if (menu == 0)
   {
@@ -335,7 +347,7 @@ void showMenu(void)
 void capture(void)
 {
   MsTimer2::stop();
-  while (capturing)
+  if (capturing)
   {
     //Checking the RCA state
     if (rcaState != lastRcaState) {       //Event generated by the RCA
@@ -516,7 +528,7 @@ void serialEvent() {
 
   if (commandString == "start_capture") {
     start_capture();
-    capture();
+    //capture();
   } else if (commandString == "end_capture") {
     end_capture();
   } else if (commandString == "get_version") {
@@ -548,9 +560,6 @@ void serialEvent() {
 
 void start_capture()
 {
-  lcd.clear();
-  lcd.setCursor(0, 0);
-  lcd.print("Starting capture");
   Serial.println("Starting capture...");
   totalTime = 0;
   lastTime = micros();
@@ -561,7 +570,6 @@ void start_capture()
   rfdCalculed = false;
   rfdValueMax = 0;
   capturing = true;
-  delay(500);
 }
 
 void end_capture()


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