[chronojump] forceSensor: Fixed initital tare and calibrate from previous values



commit 35895261ce9d9608f236497be539af7959175635
Author: Xavier de Blas <xaviblas gmail com>
Date:   Tue Nov 21 21:26:50 2017 +0100

    forceSensor: Fixed initital tare and calibrate from previous values

 src/gui/forceSensor.cs |   46 ++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 40 insertions(+), 6 deletions(-)
---
diff --git a/src/gui/forceSensor.cs b/src/gui/forceSensor.cs
index fbfee7d..14bd2d4 100644
--- a/src/gui/forceSensor.cs
+++ b/src/gui/forceSensor.cs
@@ -186,20 +186,35 @@ public partial class ChronoJumpWindow
                        return false;
                }
 
-               LogB.Information(" FS connect 5: adjusting parameters...");
-               //set adjust parameters
+               LogB.Information(" FS connect 5: let arduino start");
+
+               Thread.Sleep(3000); //sleep to let arduino start reading serial event
+
+               LogB.Information(" FS connect 6: adjusting parameters...");
+
+               //set_tare
                if(! forceSensorSendCommand("set_tare:" + preferences.forceSensorTare.ToString() + ";",
-                                       "Connecting ...", "Catched adjusting tare"))
+                                       "Setting previous tare ...", "Catched adjusting tare"))
                        return false;
 
+               //read confirmation data
+               if(! forceSensorReceiveFeedback("Tare set"))
+                       return false;
+
+
+               //set_calibration_factor
                if(! forceSensorSendCommand("set_calibration_factor:" + 
preferences.forceSensorCalibrationFactor.ToString() + ";",
-                                       "Connecting ...", "Catched adjusting calibration factor"))
+                                       "Setting previous calibration factor ...", "Catched adjusting 
calibration factor"))
                        return false;
 
+               //read confirmation data
+               if(! forceSensorReceiveFeedback("Calibration factor set"))
+                       return false;
+
+
                portFSOpened = true;
-               Thread.Sleep(2500); //sleep to let arduino start reading
                forceSensorOtherMessage = "Connected!";
-               LogB.Information(" FS connect 6: connected!");
+               LogB.Information(" FS connect 7: connected and adjusted!");
                return true;
        }
        private void forceSensorDisconnect()
@@ -215,6 +230,7 @@ public partial class ChronoJumpWindow
                forceSensorOtherMessage = displayMessage;
 
                try {
+                       LogB.Information("Force sensor command |" + command + "|");
                        portFS.WriteLine(command);
                        forceSensorTimeStart = DateTime.Now;
                }
@@ -231,6 +247,24 @@ public partial class ChronoJumpWindow
                return true;
        }
 
+       //use this method for other feedback, but beware some of the commands do a Trim on ReadLine
+       private bool forceSensorReceiveFeedback(string expected)
+       {
+               string str = "";
+               do {
+                       Thread.Sleep(100); //sleep to let arduino start reading
+                       try {
+                               str = portFS.ReadLine();
+                       } catch {
+                               forceSensorOtherMessage = "Disconnected";
+                               return false;
+                       }
+                       LogB.Information("init string: " + str);
+               }
+               while(! str.Contains(expected));
+               return true;
+       }
+
        enum forceSensorOtherModeEnum { TARE, CALIBRATE, CAPTURE_PRE, CHECK_VERSION }
        static forceSensorOtherModeEnum forceSensorOtherMode;
 


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