[chronojump] Race Analyzer. Fixed not finishing until pps pulses from encoder



commit 6c48b11c2d71a0a3c0697f90863c5627abd0a9e9
Author: Xavier Padullés <x padulles gmail com>
Date:   Wed Feb 20 16:40:53 2019 +0100

    Race Analyzer. Fixed not finishing until pps pulses from encoder

 arduino/raceAnalyzer/raceAnalyzer.ino | 40 ++++++++++++++++++++---------------
 1 file changed, 23 insertions(+), 17 deletions(-)
---
diff --git a/arduino/raceAnalyzer/raceAnalyzer.ino b/arduino/raceAnalyzer/raceAnalyzer.ino
index c2571163..ccb59b61 100644
--- a/arduino/raceAnalyzer/raceAnalyzer.ino
+++ b/arduino/raceAnalyzer/raceAnalyzer.ino
@@ -55,7 +55,7 @@ void loop() {
   long int total = 0;
   int nReadings = 0;
   int offsettedData = 0;
-  
+
 
   if (capturing)
   {
@@ -65,6 +65,12 @@ void loop() {
       offsettedData = readOffsettedData(0);
       total += offsettedData;
       nReadings++;
+      if (Serial.available() > 0) {
+        changingTime = micros();
+        lastEncoderDisplacement = encoderDisplacement;
+        encoderDisplacement = 0;
+        processSample = true;
+      }
     }
 
     unsigned long Time = changingTime;
@@ -81,8 +87,8 @@ void loop() {
     totalTime += elapsedTime;
     int meanOffsettedData = total / nReadings;
     lastTime = Time;
-    
-      //Sending in text mode
+
+    //Sending in text mode
     Serial.print(lastEncoderDisplacement);
     Serial.print(";");
     Serial.print(totalTime);
@@ -91,17 +97,17 @@ void loop() {
 
     processSample = false;
 
-//    //Sending in binary mode
-//    sendInt(lastEncoderDisplacement);
-//    sendInt(totalTime);
-//    sendInt(offsettedData);
-//
-//    //End of the binari sample
-//    Serial.write(0xff);
-//    Serial.write(0xff);
-//    Serial.write(0xff);
-//    Serial.write(0xff);
-   
+    //    //Sending in binary mode
+    //    sendInt(lastEncoderDisplacement);
+    //    sendInt(totalTime);
+    //    sendInt(offsettedData);
+    //
+    //    //End of the binari sample
+    //    Serial.write(0xff);
+    //    Serial.write(0xff);
+    //    Serial.write(0xff);
+    //    Serial.write(0xff);
+
   }
 }
 
@@ -114,7 +120,7 @@ void changingA() {
     encoderDisplacement++;
     //digitalWrite(13, LOW);
   }
-  if (abs(encoderDisplacement) >= pps){
+  if (abs(encoderDisplacement) >= pps) {
     lastEncoderDisplacement = encoderDisplacement;
     encoderDisplacement = 0;
     processSample = true;
@@ -137,8 +143,8 @@ void serialEvent()
     get_pps();
   } else if (commandString == "tare") {
     tare();
-  } else if (commandString == "get_transmission_format"){
-        get_transmission_format();
+  } else if (commandString == "get_transmission_format") {
+    get_transmission_format();
     //  } else if (commandString == "get_calibration_factor") {
     //    get_calibration_factor();
     //  } else if (commandString == "set_calibration_factor") {


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