[chronojump] RFD SQL and preferences. Done!



commit 525b3a494847cf52edb4d0b0c41cc8105a1b91bb
Author: Xavier de Blas <xaviblas gmail com>
Date:   Mon Apr 24 12:24:26 2017 +0200

    RFD SQL and preferences. Done!

 src/forceSensor.cs        |   38 +++++++++++++++++++++-
 src/gui/chronojump.cs     |    1 +
 src/gui/preferences.cs    |   80 +++++++++++++++++++++++++++++++++++++++++++-
 src/sqlite/forceSensor.cs |   18 ++++++++++
 4 files changed, 134 insertions(+), 3 deletions(-)
---
diff --git a/src/forceSensor.cs b/src/forceSensor.cs
index f1aa751..a5b7b64 100644
--- a/src/forceSensor.cs
+++ b/src/forceSensor.cs
@@ -38,7 +38,7 @@ public class ForceSensorRFD
        private static string type_PERCENT_F_MAX_name = "% Force max";
        private static string type_RFD_MAX_name = "RFD max";
 
-       private string code; //RFD1...4
+       public string code; //RFD1...4
        public bool active;
        public Functions function;
        public Types type;
@@ -55,6 +55,17 @@ public class ForceSensorRFD
                this.num2 = num2;
        }
 
+       public bool Changed(ForceSensorRFD newRFD)
+       {
+               if(
+                               code == newRFD.code && active == newRFD.active &&
+                               function == newRFD.function && type == newRFD.type &&
+                               num1 == newRFD.num1 && num2 == newRFD.num2)
+                       return false;
+
+               return true;
+       }
+
        public static string [] FunctionsArray(bool translated)
        {
                if(translated)
@@ -129,6 +140,31 @@ public class ForceSensorRFD
                        num2.ToString();
        }
 
+       public static string Function_RAW_name
+       {
+               get { return function_RAW_name; }
+       }
+       public static string Function_FITTED_name
+       {
+               get { return function_FITTED_name; }
+       }
+
+       public static string Type_INSTANTANEOUS_name
+       {
+               get { return type_INSTANTANEOUS_name; }
+       }
+       public static string Type_AVERAGE_name
+       {
+               get { return type_AVERAGE_name; }
+       }
+       public static string Type_PERCENT_F_MAX_name
+       {
+               get { return type_PERCENT_F_MAX_name; }
+       }
+       public static string Type_RFD_MAX_name
+       {
+               get { return type_RFD_MAX_name; }
+       }
 }
 
 /*
diff --git a/src/gui/chronojump.cs b/src/gui/chronojump.cs
index bfde035..742252e 100644
--- a/src/gui/chronojump.cs
+++ b/src/gui/chronojump.cs
@@ -2715,6 +2715,7 @@ public partial class ChronoJumpWindow
        private void on_preferences_accepted (object o, EventArgs args) 
        {
                preferences = preferencesWin.GetPreferences;
+               rfdList = preferencesWin.GetRFDList;
 
                if(checkbutton_video.Active) {
                        videoCapturePrepare(false); //if error, show message
diff --git a/src/gui/preferences.cs b/src/gui/preferences.cs
index be8724e..01f5aeb 100644
--- a/src/gui/preferences.cs
+++ b/src/gui/preferences.cs
@@ -664,6 +664,61 @@ public class PreferencesWindow
                }
        }
 
+       private List<ForceSensorRFD> getRFDValues()
+       {
+               List<ForceSensorRFD> l = new List<ForceSensorRFD>();
+               l.Add(getRFDValue("RFD1", check_force_1, combo_force_1_function, combo_force_1_type,
+                               spinbutton_force_1_at_ms, spinbutton_force_1_at_percent,
+                               spinbutton_force_1_from, spinbutton_force_1_to));
+               l.Add(getRFDValue("RFD2", check_force_2, combo_force_2_function, combo_force_2_type,
+                               spinbutton_force_2_at_ms, spinbutton_force_2_at_percent,
+                               spinbutton_force_2_from, spinbutton_force_2_to));
+               l.Add(getRFDValue("RFD3", check_force_3, combo_force_3_function, combo_force_3_type,
+                               spinbutton_force_3_at_ms, spinbutton_force_3_at_percent,
+                               spinbutton_force_3_from, spinbutton_force_3_to));
+               l.Add(getRFDValue("RFD4", check_force_4, combo_force_4_function, combo_force_4_type,
+                               spinbutton_force_4_at_ms, spinbutton_force_4_at_percent,
+                               spinbutton_force_4_from, spinbutton_force_4_to));
+               return l;
+       }
+       private ForceSensorRFD getRFDValue(string code, Gtk.CheckButton check, Gtk.ComboBox 
combo_force_function, Gtk.ComboBox combo_force_type,
+                               Gtk.SpinButton spinbutton_force_at_ms, Gtk.SpinButton 
spinbutton_force_at_percent,
+                               Gtk.SpinButton spinbutton_force_from, Gtk.SpinButton spinbutton_force_to)
+       {
+               bool active = check.Active;
+               int num1 = -1;
+               int num2 = -1;
+
+               ForceSensorRFD.Functions function;
+               if(UtilGtk.ComboGetActive(combo_force_function) == ForceSensorRFD.Function_RAW_name)
+                       function = ForceSensorRFD.Functions.RAW;
+               else //(UtilGtk.ComboGetActive(combo_force_function) == ForceSensorRFD.Function_FITTED_name)
+                       function = ForceSensorRFD.Functions.FITTED;
+
+               ForceSensorRFD.Types type;
+               string typeStr = UtilGtk.ComboGetActive(combo_force_type);
+               if(typeStr == Catalog.GetString(ForceSensorRFD.Type_INSTANTANEOUS_name))
+               {
+                       num1 = Convert.ToInt32(spinbutton_force_at_ms.Value);
+                       type = ForceSensorRFD.Types.INSTANTANEOUS;
+               }
+               else if(typeStr == Catalog.GetString(ForceSensorRFD.Type_AVERAGE_name))
+               {
+                       num1 = Convert.ToInt32(spinbutton_force_from.Value);
+                       num2 = Convert.ToInt32(spinbutton_force_to.Value);
+                       type = ForceSensorRFD.Types.AVERAGE;
+               }
+               else if(typeStr == Catalog.GetString(ForceSensorRFD.Type_PERCENT_F_MAX_name))
+               {
+                       num1 = Convert.ToInt32(spinbutton_force_at_percent.Value);
+                       type = ForceSensorRFD.Types.PERCENT_F_MAX;
+               }
+               else // (typeStr == Catalog.GetString(ForceSensorRFD.Type_RFD_MAX_name))
+                       type = ForceSensorRFD.Types.RFD_MAX;
+
+               return new ForceSensorRFD(code, active, function, type, num1, num2);
+       }
+
        private void on_button_force_rfd_default_clicked (object o, EventArgs args)
        {
                Sqlite.Open();
@@ -1434,9 +1489,26 @@ public class PreferencesWindow
 
                SqlitePreferences.Update("encoder1RMMethod", encoder1RMMethod.ToString(), true);
                preferences.encoder1RMMethod = encoder1RMMethod;
-               
+
+               //---- force sensor
+
+               List<ForceSensorRFD> newRFDList = getRFDValues();
+               int i = 0;
+               foreach(ForceSensorRFD rfd in newRFDList)
+               {
+                       if(rfdList[i].Changed(rfd))
+                       {
+                               SqliteForceSensor.Update(true, rfd);
+                               rfdList[i] = rfd;
+                       }
+                       i ++;
+               }
+
+               // end of force sensor
+
+
                //---- end of encoder other
-               
+
                //multimedia ----
                if( preferences.volumeOn != PreferencesWindowBox.checkbutton_volume.Active ) {
                        SqlitePreferences.Update("volumeOn", 
PreferencesWindowBox.checkbutton_volume.Active.ToString(), true);
@@ -1535,4 +1607,8 @@ public class PreferencesWindow
                get { return preferences;  }
        }
 
+       public List<ForceSensorRFD> GetRFDList
+       {
+               get { return rfdList;  }
+       }
 }
diff --git a/src/sqlite/forceSensor.cs b/src/sqlite/forceSensor.cs
index d627230..1285ff4 100644
--- a/src/sqlite/forceSensor.cs
+++ b/src/sqlite/forceSensor.cs
@@ -78,6 +78,24 @@ class SqliteForceSensor : Sqlite
                closeIfNeeded(dbconOpened);
        }
 
+       public static void Update(bool dbconOpened, ForceSensorRFD rfd)
+       {
+               openIfNeeded(dbconOpened);
+
+               dbcmd.CommandText = "UPDATE " + table + " SET " +
+                       " active = " + Util.BoolToInt(rfd.active).ToString() + "," +
+                       " function = \"" + rfd.function.ToString() + "\"" + "," +
+                       " type = \"" + rfd.type.ToString() + "\"" + "," +
+                       " num1 = " + rfd.num1.ToString() + "," +
+                       " num2 = " + rfd.num2.ToString() +
+                       " WHERE code = \"" + rfd.code + "\"";
+
+               LogB.SQL(dbcmd.CommandText.ToString());
+               dbcmd.ExecuteNonQuery();
+
+               closeIfNeeded(dbconOpened);
+       }
+
        //used when button_force_rfd_default is clicked
        public static void DeleteAll(bool dbconOpened)
        {


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