[chronojump/optimizeRFD] Race analyzer set_pps if != 10 and version >= 0.4



commit 9077b6336854ff998898d7da40b64b2d414ca2be
Author: Xavier de Blas <xaviblas gmail com>
Date:   Thu Dec 31 13:29:07 2020 +0100

    Race analyzer set_pps if != 10 and version >= 0.4

 glade/preferences_win.glade | 174 +++++++++++++++++++++++++++++++++++---------
 src/gui/app1/runEncoder.cs  |  35 ++++++++-
 src/gui/preferences.cs      |   7 ++
 3 files changed, 178 insertions(+), 38 deletions(-)
---
diff --git a/glade/preferences_win.glade b/glade/preferences_win.glade
index f645dff8d..b71969215 100644
--- a/glade/preferences_win.glade
+++ b/glade/preferences_win.glade
@@ -5051,27 +5051,42 @@ It starts before and arrives there with some speed.</property>
                                     <property name="can_focus">False</property>
                                     <property name="border_width">8</property>
                                     <child>
-                                      <widget class="GtkHBox" id="hbox60">
+                                      <widget class="GtkTable" id="table8">
                                         <property name="visible">True</property>
                                         <property name="can_focus">False</property>
-                                        <property name="spacing">20</property>
+                                        <property name="n_rows">2</property>
+                                        <property name="n_columns">3</property>
+                                        <property name="column_spacing">8</property>
+                                        <property name="row_spacing">12</property>
+                                        <child>
+                                          <widget class="GtkLabel" id="label_run_encoder_acceleration">
+                                            <property name="visible">True</property>
+                                            <property name="can_focus">False</property>
+                                            <property name="xalign">0</property>
+                                            <property name="label" translatable="yes">Minimum 
acceleration</property>
+                                          </widget>
+                                          <packing>
+                                            <property name="x_options">GTK_FILL</property>
+                                          </packing>
+                                        </child>
+                                        <child>
+                                          <widget class="GtkLabel" id="label_run_encoder_pps">
+                                            <property name="visible">True</property>
+                                            <property name="can_focus">False</property>
+                                            <property name="xalign">0</property>
+                                            <property name="label">PPS</property>
+                                          </widget>
+                                          <packing>
+                                            <property name="top_attach">1</property>
+                                            <property name="bottom_attach">2</property>
+                                            <property name="x_options">GTK_FILL</property>
+                                          </packing>
+                                        </child>
                                         <child>
                                           <widget class="GtkHBox" id="hbox_run_encoder_acceleration_start">
                                             <property name="visible">True</property>
                                             <property name="can_focus">False</property>
                                             <property name="spacing">6</property>
-                                            <child>
-                                              <widget class="GtkLabel" id="label_run_encoder_acceleration">
-                                                <property name="visible">True</property>
-                                                <property name="can_focus">False</property>
-                                                <property name="label" translatable="yes">Minimum 
acceleration</property>
-                                              </widget>
-                                              <packing>
-                                                <property name="expand">False</property>
-                                                <property name="fill">True</property>
-                                                <property name="position">0</property>
-                                              </packing>
-                                            </child>
                                             <child>
                                               <widget class="GtkSpinButton" 
id="spin_run_encoder_acceleration">
                                                 <property name="visible">True</property>
@@ -5090,7 +5105,7 @@ It starts before and arrives there with some speed.</property>
                                               <packing>
                                                 <property name="expand">False</property>
                                                 <property name="fill">False</property>
-                                                <property name="position">1</property>
+                                                <property name="position">0</property>
                                               </packing>
                                             </child>
                                             <child>
@@ -5103,27 +5118,33 @@ It starts before and arrives there with some speed.</property>
                                               <packing>
                                                 <property name="expand">False</property>
                                                 <property name="fill">False</property>
-                                                <property name="position">2</property>
+                                                <property name="position">1</property>
                                               </packing>
                                             </child>
                                           </widget>
                                           <packing>
-                                            <property name="expand">False</property>
-                                            <property name="fill">False</property>
-                                            <property name="position">0</property>
+                                            <property name="left_attach">1</property>
+                                            <property name="right_attach">2</property>
+                                            <property name="x_options"/>
                                           </packing>
                                         </child>
                                         <child>
-                                          <widget class="GtkHBox" id="hbox61">
+                                          <widget class="GtkHBox" id="hbox86">
                                             <property name="visible">True</property>
                                             <property name="can_focus">False</property>
-                                            <property name="spacing">6</property>
                                             <child>
-                                              <widget class="GtkLabel" id="label125">
+                                              <widget class="GtkSpinButton" id="spin_run_encoder_pps">
                                                 <property name="visible">True</property>
-                                                <property name="can_focus">False</property>
-                                                <property name="xalign">0</property>
-                                                <property name="label" 
translatable="yes">Recommended:</property>
+                                                <property name="can_focus">True</property>
+                                                <property name="invisible_char">●</property>
+                                                <property name="invisible_char_set">True</property>
+                                                <property name="primary_icon_activatable">False</property>
+                                                <property name="secondary_icon_activatable">False</property>
+                                                <property name="primary_icon_sensitive">True</property>
+                                                <property name="secondary_icon_sensitive">True</property>
+                                                <property name="adjustment">10 1 1000 1 1 0</property>
+                                                <property name="climb_rate">1</property>
+                                                <property name="numeric">True</property>
                                               </widget>
                                               <packing>
                                                 <property name="expand">False</property>
@@ -5131,24 +5152,105 @@ It starts before and arrives there with some speed.</property>
                                                 <property name="position">0</property>
                                               </packing>
                                             </child>
+                                          </widget>
+                                          <packing>
+                                            <property name="left_attach">1</property>
+                                            <property name="right_attach">2</property>
+                                            <property name="top_attach">1</property>
+                                            <property name="bottom_attach">2</property>
+                                            <property name="x_options">GTK_FILL</property>
+                                          </packing>
+                                        </child>
+                                        <child>
+                                          <widget class="GtkAlignment" id="alignment29">
+                                            <property name="visible">True</property>
+                                            <property name="can_focus">False</property>
+                                            <property name="left_padding">20</property>
                                             <child>
-                                              <widget class="GtkLabel" id="label126">
+                                              <widget class="GtkHBox" id="hbox61">
                                                 <property name="visible">True</property>
                                                 <property name="can_focus">False</property>
-                                                <property name="xalign">0</property>
-                                                <property name="label">10 m/s^2</property>
+                                                <property name="spacing">6</property>
+                                                <child>
+                                                  <widget class="GtkLabel" id="label125">
+                                                    <property name="visible">True</property>
+                                                    <property name="can_focus">False</property>
+                                                    <property name="xalign">0</property>
+                                                    <property name="label" 
translatable="yes">Recommended:</property>
+                                                  </widget>
+                                                  <packing>
+                                                    <property name="expand">False</property>
+                                                    <property name="fill">False</property>
+                                                    <property name="position">0</property>
+                                                  </packing>
+                                                </child>
+                                                <child>
+                                                  <widget class="GtkLabel" id="label126">
+                                                    <property name="visible">True</property>
+                                                    <property name="can_focus">False</property>
+                                                    <property name="xalign">0</property>
+                                                    <property name="label">10 m/s^2</property>
+                                                  </widget>
+                                                  <packing>
+                                                    <property name="expand">False</property>
+                                                    <property name="fill">False</property>
+                                                    <property name="position">1</property>
+                                                  </packing>
+                                                </child>
                                               </widget>
-                                              <packing>
-                                                <property name="expand">False</property>
-                                                <property name="fill">False</property>
-                                                <property name="position">1</property>
-                                              </packing>
                                             </child>
                                           </widget>
                                           <packing>
-                                            <property name="expand">False</property>
-                                            <property name="fill">False</property>
-                                            <property name="position">1</property>
+                                            <property name="left_attach">2</property>
+                                            <property name="right_attach">3</property>
+                                            <property name="x_options"/>
+                                          </packing>
+                                        </child>
+                                        <child>
+                                          <widget class="GtkAlignment" id="alignment30">
+                                            <property name="visible">True</property>
+                                            <property name="can_focus">False</property>
+                                            <property name="left_padding">20</property>
+                                            <child>
+                                              <widget class="GtkHBox" id="hbox85">
+                                                <property name="visible">True</property>
+                                                <property name="can_focus">False</property>
+                                                <property name="spacing">6</property>
+                                                <child>
+                                                  <widget class="GtkLabel" id="label149">
+                                                    <property name="visible">True</property>
+                                                    <property name="can_focus">False</property>
+                                                    <property name="xalign">0</property>
+                                                    <property name="label" 
translatable="yes">Recommended:</property>
+                                                  </widget>
+                                                  <packing>
+                                                    <property name="expand">False</property>
+                                                    <property name="fill">False</property>
+                                                    <property name="position">0</property>
+                                                  </packing>
+                                                </child>
+                                                <child>
+                                                  <widget class="GtkLabel" id="label150">
+                                                    <property name="visible">True</property>
+                                                    <property name="can_focus">False</property>
+                                                    <property name="xalign">0</property>
+                                                    <property name="label">10</property>
+                                                  </widget>
+                                                  <packing>
+                                                    <property name="expand">False</property>
+                                                    <property name="fill">False</property>
+                                                    <property name="position">1</property>
+                                                  </packing>
+                                                </child>
+                                              </widget>
+                                            </child>
+                                          </widget>
+                                          <packing>
+                                            <property name="left_attach">2</property>
+                                            <property name="right_attach">3</property>
+                                            <property name="top_attach">1</property>
+                                            <property name="bottom_attach">2</property>
+                                            <property name="x_options">GTK_FILL</property>
                                           </packing>
                                         </child>
                                       </widget>
diff --git a/src/gui/app1/runEncoder.cs b/src/gui/app1/runEncoder.cs
index 9afdeed8e..294a09888 100644
--- a/src/gui/app1/runEncoder.cs
+++ b/src/gui/app1/runEncoder.cs
@@ -68,6 +68,7 @@ public partial class ChronoJumpWindow
        private RunEncoderExercise currentRunEncoderExercise;
        DateTime runEncoderTimeStartCapture;
        bool runEncoderCaptureSimulated;
+       string runEncoderFirmwareVersion;
 
        static string lastRunEncoderFile = "";
        static string lastRunEncoderFullPath = "";
@@ -139,8 +140,8 @@ public partial class ChronoJumpWindow
 
                LogB.Information(" RE connect 6: get version");
 
-               string version = runEncoderCheckVersionDo();
-               LogB.Information("Version found: [" + version + "]");
+               runEncoderFirmwareVersion = runEncoderCheckVersionDo();
+               LogB.Information("Version found: [" + runEncoderFirmwareVersion + "]");
 
                portREOpened = true;
                runEncoderPulseMessage = "Connected!";
@@ -214,6 +215,23 @@ public partial class ChronoJumpWindow
                return true;
        }
 
+       private string runEncoderReceiveFeedback(string expected)
+       {
+               string str = "";
+               do {
+                       Thread.Sleep(100); //sleep to let arduino start reading
+                       try {
+                               str = portRE.ReadLine();
+                       } catch {
+                               runEncoderProcessError = true;
+                               return "";
+                       }
+                       LogB.Information("runEncoder feedback string: " + str);
+               }
+               while(! str.Contains(expected));
+               return str;
+       }
+
        private void on_runs_encoder_capture_clicked ()
        {
                if(UtilGtk.ComboGetActive(combo_run_encoder_exercise) == "")
@@ -412,6 +430,19 @@ public partial class ChronoJumpWindow
 
                lastChangedTime = 0;
 
+                double versionDouble = 
Convert.ToDouble(Util.ChangeDecimalSeparator(runEncoderFirmwareVersion));
+               if(preferences.runEncoderPPS != 10 && //10 is the default value on the .ino
+                               versionDouble >= Convert.ToDouble(Util.ChangeDecimalSeparator("0.4"))
+                               )
+               {
+                       if(! runEncoderSendCommand(string.Format("set_pps:{0};", preferences.runEncoderPPS), 
"Sending pps", "Catched at set_pps"))
+                               return;
+
+                       //read confirmation data
+                       if(runEncoderReceiveFeedback("pps set to") == "")
+                               return;
+               }
+
                string command = "start_capture:";
                if(runEncoderCaptureSimulated)
                        command = "start_simulation:";
diff --git a/src/gui/preferences.cs b/src/gui/preferences.cs
index 686d951d6..13c12b57a 100644
--- a/src/gui/preferences.cs
+++ b/src/gui/preferences.cs
@@ -188,6 +188,7 @@ public class PreferencesWindow
 
        //runEncoder tab
        [Widget] Gtk.SpinButton spin_run_encoder_acceleration;
+       [Widget] Gtk.SpinButton spin_run_encoder_pps;
 
        //multimedia tab
        [Widget] Gtk.CheckButton checkbutton_volume;
@@ -736,6 +737,7 @@ public class PreferencesWindow
 
                //runEncoder -->
                PreferencesWindowBox.spin_run_encoder_acceleration.Value = preferences.runEncoderMinAccel;
+               PreferencesWindowBox.spin_run_encoder_pps.Value = preferences.runEncoderPPS;
 
                //language -->
                if(preferences.language == "")
@@ -2158,6 +2160,11 @@ public class PreferencesWindow
                                preferences.runEncoderMinAccel,
                                Convert.ToDouble(spin_run_encoder_acceleration.Value));
 
+               preferences.runEncoderPPS = Preferences.PreferencesChange(
+                               SqlitePreferences.RunEncoderPPS,
+                               preferences.runEncoderPPS,
+                               Convert.ToInt32(spin_run_encoder_pps.Value));
+
                //multimedia ----
                if( preferences.volumeOn != PreferencesWindowBox.checkbutton_volume.Active ) {
                        SqlitePreferences.Update("volumeOn", 
PreferencesWindowBox.checkbutton_volume.Active.ToString(), true);


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