[chronojump] DB: 1.67 forceSensor tare before capture implemented



commit e2cca0314a4209a4f5fe25232ebc02a79a7b5a89
Author: Xavier de Blas <xaviblas gmail com>
Date:   Thu Sep 5 15:37:10 2019 +0200

    DB: 1.67 forceSensor tare before capture implemented

 src/forceSensor.cs        | 11 +++++++++--
 src/gui/forceSensor.cs    | 45 ++++++++++++++++++++++++++++++++-------------
 src/sqlite/forceSensor.cs | 14 +++++++++-----
 src/sqlite/main.cs        | 10 +++++++---
 4 files changed, 57 insertions(+), 23 deletions(-)
---
diff --git a/src/forceSensor.cs b/src/forceSensor.cs
index e2af47f3..7f31bdad 100644
--- a/src/forceSensor.cs
+++ b/src/forceSensor.cs
@@ -49,6 +49,7 @@ public class ForceSensorExercise
        private string resistance;
        private int angleDefault;
        private string description;
+       private bool tareBeforeCapture;
 
        public ForceSensorExercise()
        {
@@ -59,7 +60,8 @@ public class ForceSensorExercise
                this.name = name;
        }
 
-       public ForceSensorExercise(int uniqueID, string name, int percentBodyWeight, string resistance, int 
angleDefault, string description)
+       public ForceSensorExercise(int uniqueID, string name, int percentBodyWeight, string resistance, int 
angleDefault,
+                       string description, bool tareBeforeCapture)
        {
                this.uniqueID = uniqueID;
                this.name = name;
@@ -67,12 +69,13 @@ public class ForceSensorExercise
                this.resistance = resistance;
                this.angleDefault = angleDefault;
                this.description = description;
+               this.tareBeforeCapture = tareBeforeCapture;
        }
 
        public override string ToString()
        {
                return uniqueID.ToString() + ":" + name + ":" + percentBodyWeight.ToString() + ":" +
-                       resistance + ":" + angleDefault.ToString() + ":" + description;
+                       resistance + ":" + angleDefault.ToString() + ":" + description + ":" + 
tareBeforeCapture.ToString();
        }
 
        public int UniqueID
@@ -99,6 +102,10 @@ public class ForceSensorExercise
        {
                get { return description; }
        }
+       public bool TareBeforeCapture
+       {
+               get { return tareBeforeCapture; }
+       }
 }
 
 /*
diff --git a/src/gui/forceSensor.cs b/src/gui/forceSensor.cs
index 0a01c566..9425b00e 100644
--- a/src/gui/forceSensor.cs
+++ b/src/gui/forceSensor.cs
@@ -333,7 +333,7 @@ public partial class ChronoJumpWindow
                return true;
        }
 
-       enum forceSensorOtherModeEnum { TARE, CALIBRATE, CAPTURE_PRE, CHECK_VERSION }
+       enum forceSensorOtherModeEnum { TARE, CALIBRATE, CAPTURE_PRE, TARE_AND_CAPTURE_PRE, CHECK_VERSION }
        static forceSensorOtherModeEnum forceSensorOtherMode;
 
        //buttons: tare, calibrate, check version and capture (via on_button_execute_test_cicked) come here
@@ -367,8 +367,16 @@ public partial class ChronoJumpWindow
                else if (o == (object) button_execute_test)
                {
                        forceSensorButtonsSensitive(false);
-                       forceSensorOtherMode = forceSensorOtherModeEnum.CAPTURE_PRE;
-                       forceOtherThread = new Thread(new ThreadStart(forceSensorCapturePre));
+
+                       assignCurrentForceSensorExercise();
+                       if(currentForceSensorExercise.TareBeforeCapture)
+                       {
+                               forceSensorOtherMode = forceSensorOtherModeEnum.TARE_AND_CAPTURE_PRE;
+                               forceOtherThread = new Thread(new ThreadStart(forceSensorTareAndCapturePre));
+                       } else {
+                               forceSensorOtherMode = forceSensorOtherModeEnum.CAPTURE_PRE;
+                               forceOtherThread = new Thread(new ThreadStart(forceSensorCapturePre));
+                       }
                }
                else { //if (o == (object) button_check_version)
                        forceSensorButtonsSensitive(false);
@@ -432,7 +440,7 @@ public partial class ChronoJumpWindow
                        }
                        else if(forceSensorOtherMode == forceSensorOtherModeEnum.CHECK_VERSION)
                                forceSensorButtonsSensitive(true);
-                       else //if(forceSensorOtherMode == forceSensorOtherModeEnum.CAPTURE_PRE)
+                       else if(forceSensorOtherMode == forceSensorOtherModeEnum.TARE_AND_CAPTURE_PRE || 
forceSensorOtherMode == forceSensorOtherModeEnum.CAPTURE_PRE)
                                forceSensorCapturePre2();
 
                        return false;
@@ -592,6 +600,12 @@ public partial class ChronoJumpWindow
                return (str == "binary");
        }
 
+       //Attention: no GTK here!!
+       private void forceSensorTareAndCapturePre()
+       {
+               forceSensorTare();
+               forceSensorCapturePre();
+       }
        //Attention: no GTK here!!
        private void forceSensorCapturePre()
        {
@@ -754,7 +768,8 @@ public partial class ChronoJumpWindow
 
                Util.CreateForceSensorSessionDirIfNeeded (currentSession.UniqueID);
 
-               assignCurrentForceSensorExercise();
+               //done at on_buttons_force_sensor_clicked()
+               //assignCurrentForceSensorExercise();
 
                string fileNamePre = currentPerson.Name + "_" +
                        Catalog.GetString(currentForceSensorExercise.Name) + "_" +
@@ -1803,7 +1818,7 @@ LogB.Information(" re R ");
                ArrayList a2 = new ArrayList();
                ArrayList a3 = new ArrayList();
                ArrayList a4 = new ArrayList();
-               //ArrayList a5 = new ArrayList();
+               ArrayList a5 = new ArrayList();
 
                //0 is the widgget to show; 1 is the editable; 2 id default value
                a1.Add(Constants.GenericWindowShow.ENTRY); a1.Add(true); a1.Add(ex.Name); //name can be 
changed (opposite to encoder), because we use always the uniqueID
@@ -1818,8 +1833,8 @@ LogB.Information(" re R ");
                a4.Add(Constants.GenericWindowShow.ENTRY3); a4.Add(true); a4.Add(ex.Description);
                bigArray.Add(a4);
 
-               //a5.Add(Constants.GenericWindowShow.SPININT2); a5.Add(true); a5.Add(ex.AngleDefault);
-               //bigArray.Add(a5);
+               a5.Add(Constants.GenericWindowShow.CHECK1); a5.Add(true); 
a5.Add(Util.BoolToRBool(ex.TareBeforeCapture));
+               bigArray.Add(a5);
 
 
                genericWin = GenericWindow.Show(Catalog.GetString("Exercise"), false,   //don't show now
@@ -1832,6 +1847,7 @@ LogB.Information(" re R ");
                genericWin.LabelEntry3 = Catalog.GetString("Description");
                //genericWin.LabelSpinInt2 = Catalog.GetString("Default angle");
                //genericWin.SetSpin2Range(0,180);
+               genericWin.SetCheck1Label(Catalog.GetString("Tare before capture"));
 
                genericWin.ShowButtonCancel(false);
 
@@ -1853,7 +1869,7 @@ LogB.Information(" re R ");
                ArrayList a2 = new ArrayList();
                ArrayList a3 = new ArrayList();
                ArrayList a4 = new ArrayList();
-               //ArrayList a5 = new ArrayList();
+               ArrayList a5 = new ArrayList();
 
                //0 is the widgget to show; 1 is the editable; 2 id default value
                a1.Add(Constants.GenericWindowShow.ENTRY); a1.Add(true); a1.Add("");
@@ -1868,8 +1884,8 @@ LogB.Information(" re R ");
                a4.Add(Constants.GenericWindowShow.ENTRY3); a4.Add(true); a4.Add("");
                bigArray.Add(a4);
 
-               //a5.Add(Constants.GenericWindowShow.SPININT2); a5.Add(true); a5.Add("");
-               //bigArray.Add(a5);
+               a5.Add(Constants.GenericWindowShow.CHECK1); a5.Add(true); a5.Add("False");
+               bigArray.Add(a5);
 
 
                genericWin = GenericWindow.Show(Catalog.GetString("Exercise"), false,   //don't show now
@@ -1880,6 +1896,7 @@ LogB.Information(" re R ");
                genericWin.LabelEntry3 = Catalog.GetString("Description");
                //genericWin.LabelSpinInt2 = Catalog.GetString("Default angle");
                //genericWin.SetSpin2Range(0,180);
+               genericWin.SetCheck1Label(Catalog.GetString("Tare before capture"));
 
                genericWin.SetButtonAcceptLabel(Catalog.GetString("Add"));
 
@@ -1926,7 +1943,8 @@ LogB.Information(" re R ");
                                SqliteForceSensorExercise.Insert(false, -1, name, genericWin.SpinIntSelected,
                                                genericWin.Entry2Selected,
                                                genericWin.SpinInt2Selected,
-                                               genericWin.Entry3Selected
+                                               genericWin.Entry3Selected,
+                                               genericWin.GetCheck1
                                                );
                        else {
                                ForceSensorExercise ex = new ForceSensorExercise(
@@ -1935,7 +1953,8 @@ LogB.Information(" re R ");
                                                genericWin.SpinIntSelected,
                                                genericWin.Entry2Selected,
                                                genericWin.SpinInt2Selected,
-                                               genericWin.Entry3Selected
+                                               genericWin.Entry3Selected,
+                                               genericWin.GetCheck1
                                                );
                                SqliteForceSensorExercise.Update(false, ex);
                        }
diff --git a/src/sqlite/forceSensor.cs b/src/sqlite/forceSensor.cs
index 50e17666..9fc66c33 100644
--- a/src/sqlite/forceSensor.cs
+++ b/src/sqlite/forceSensor.cs
@@ -46,14 +46,15 @@ class SqliteForceSensorExercise : Sqlite
                        "percentBodyWeight INT, " +
                        "resistance TEXT, " +
                        "angleDefault INT, " +
-                       "description TEXT )";
+                       "description TEXT, " +
+                       "tareBeforeCapture INT)";
                dbcmd.ExecuteNonQuery();
        }
 
        //undefined defaultAngle will be 1000
        //note execution can have a different angle than the default angle
        public static void Insert (bool dbconOpened, int uniqueID, string name, int percentBodyWeight,
-                       string resistance, int angleDefault, string description)
+                       string resistance, int angleDefault, string description, bool tareBeforeCapture)
        {
                if(! dbconOpened)
                        Sqlite.Open();
@@ -65,7 +66,8 @@ class SqliteForceSensorExercise : Sqlite
                dbcmd.CommandText = "INSERT INTO " + table +
                                " (uniqueID, name, percentBodyWeight, resistance, angleDefault, description)" 
+
                                " VALUES (" + uniqueIDStr + ", \"" + name + "\", " + percentBodyWeight + ", 
\"" +
-                               resistance + "\", " + angleDefault + ", \"" + description + "\")";
+                               resistance + "\", " + angleDefault + ", \"" + description + "\", " +
+                               Util.BoolToInt(tareBeforeCapture).ToString() + ")";
                LogB.SQL(dbcmd.CommandText.ToString());
                dbcmd.ExecuteNonQuery();
 
@@ -90,7 +92,8 @@ class SqliteForceSensorExercise : Sqlite
                        ", resistance = \"" + ex.Resistance +
                        "\", angleDefault = " + ex.AngleDefault +
                        ", description = \"" + ex.Description +
-                       "\" WHERE uniqueID = " + ex.UniqueID;
+                       "\", tareBeforeCapture = " + Util.BoolToInt(ex.TareBeforeCapture).ToString() +
+                       " WHERE uniqueID = " + ex.UniqueID;
 
                LogB.SQL(dbcmd.CommandText.ToString());
                dbcmd.ExecuteNonQuery();
@@ -137,7 +140,8 @@ class SqliteForceSensorExercise : Sqlite
                                                Convert.ToInt32(reader[2].ToString()),  //percentBodyWeight
                                                reader[3].ToString(),                   //resistance
                                                angleDefault,
-                                               reader[5].ToString()                    //description
+                                               reader[5].ToString(),                   //description
+                                               Util.IntToBool(Convert.ToInt32(reader[6].ToString()))   
//tareBeforeCapture
                                                );
                                array.Add(ex);
                        }
diff --git a/src/sqlite/main.cs b/src/sqlite/main.cs
index e2b51338..4e4c07a8 100644
--- a/src/sqlite/main.cs
+++ b/src/sqlite/main.cs
@@ -125,7 +125,7 @@ class Sqlite
        /*
         * Important, change this if there's any update to database
         */
-       static string lastChronojumpDatabaseVersion = "1.66";
+       static string lastChronojumpDatabaseVersion = "1.67";
 
        public Sqlite() {
        }
@@ -2419,8 +2419,11 @@ class Sqlite
 
                                currentVersion = updateVersion("1.66");
                        }
-
-
+                       if(currentVersion == "1.66")
+                       {
+                               executeSQL("ALTER TABLE " + Constants.ForceSensorExerciseTable + " ADD COLUMN 
tareBeforeCapture INT NOT NULL DEFAULT 0;");
+                               currentVersion = updateVersion("1.67");
+                       }
 
 
                        // --- add more updates here
@@ -2608,6 +2611,7 @@ class Sqlite
                SqliteJson.createTableUploadExhibitionTestTemp ();
 
                //changes [from - to - desc]
+               //1.66 - 1.67 Converted DB to 1.67 ALTER TABLE Constants.ForceSensorExerciseTable ADD COLUMN 
tareBeforeCapture INT
                //1.65 - 1.66 Converted DB to 1.66 Added to preferences: encoderCaptureSecondaryVariableShow
                //1.64 - 1.65 Converted DB to 1.65 Added to preferences: encoderCaptureSecondaryVariable
                //1.63 - 1.64 Converted DB to 1.64 Added to preferences: videoDevicePixelFormat


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