[chronojump/michrolab] Encoder detected on discover, widgets work correctly



commit 4af98f27df37e8c7a55d5b1af94a7dbd212651f4
Author: Xavier de Blas <xaviblas gmail com>
Date:   Fri Jun 24 15:29:25 2022 +0200

    Encoder detected on discover, widgets work correctly

 glade/app1.glade              | 52 ++++++++++++++++++++++++++-----------------
 src/constants.cs              |  4 ++++
 src/execute/arduinoCapture.cs | 26 +++++++++++++++++++++-
 src/gui/app1/chronojump.cs    |  6 +++++
 src/gui/app1/encoder.cs       |  8 +++++++
 src/gui/chronopicRegister.cs  |  5 +++++
 src/gui/networks.cs           |  6 +++++
 7 files changed, 85 insertions(+), 22 deletions(-)
---
diff --git a/glade/app1.glade b/glade/app1.glade
index 8948725f1..5672738a9 100644
--- a/glade/app1.glade
+++ b/glade/app1.glade
@@ -5477,8 +5477,8 @@ EncoderInertialCapture</property>
                                                             </child>
                                                             </widget>
                                                             <packing>
-                                                            <property name="expand">True</property>
-                                                            <property name="fill">True</property>
+                                                            <property name="expand">False</property>
+                                                            <property name="fill">False</property>
                                                             <property name="position">0</property>
                                                             </packing>
                                                             </child>
@@ -5575,8 +5575,8 @@ EncoderInertialCapture</property>
                                                             </child>
                                                             </widget>
                                                             <packing>
-                                                            <property name="expand">True</property>
-                                                            <property name="fill">True</property>
+                                                            <property name="expand">False</property>
+                                                            <property name="fill">False</property>
                                                             <property name="position">1</property>
                                                             </packing>
                                                             </child>
@@ -31890,7 +31890,6 @@ Concentric</property>
                                                             <property name="can_focus">False</property>
                                                             <child>
                                                             <widget class="GtkButton" 
id="button_encoder_detect">
-                                                            <property name="visible">True</property>
                                                             <property name="can_focus">True</property>
                                                             <property name="can_default">True</property>
                                                             <property name="receives_default">True</property>
@@ -32804,34 +32803,37 @@ Concentric</property>
                                                             <property name="position">0</property>
                                                             </packing>
                                                             </child>
+                                                            </widget>
+                                                            <packing>
+                                                            <property name="expand">False</property>
+                                                            <property name="fill">False</property>
+                                                            <property name="position">0</property>
+                                                            </packing>
+                                                            </child>
+                                                            <child>
+                                                            <widget class="GtkAlignment" id="alignment45">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">False</property>
+                                                            <property name="right_padding">6</property>
+                                                            <child>
+                                                            <widget class="GtkHBox" id="hbox322">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">False</property>
                                                             <child>
                                                             <widget class="GtkCheckButton" 
id="check_encoder_networks_upload">
                                                             <property name="label" translatable="yes">Upload 
next capture</property>
-                                                            <property name="visible">True</property>
                                                             <property name="can_focus">True</property>
                                                             <property 
name="receives_default">False</property>
                                                             <property name="active">True</property>
                                                             <property name="draw_indicator">True</property>
                                                             </widget>
                                                             <packing>
-                                                            <property name="expand">True</property>
-                                                            <property name="fill">True</property>
-                                                            <property name="position">1</property>
-                                                            </packing>
-                                                            </child>
-                                                            </widget>
-                                                            <packing>
-                                                            <property name="expand">True</property>
-                                                            <property name="fill">True</property>
+                                                            <property name="expand">False</property>
+                                                            <property name="fill">False</property>
                                                             <property name="position">0</property>
                                                             </packing>
                                                             </child>
                                                             <child>
-                                                            <widget class="GtkAlignment" id="alignment45">
-                                                            <property name="visible">True</property>
-                                                            <property name="can_focus">False</property>
-                                                            <property name="right_padding">6</property>
-                                                            <child>
                                                             <widget class="GtkHBox" id="hbox_video_encoder">
                                                             <property name="visible">True</property>
                                                             <property name="can_focus">False</property>
@@ -32900,7 +32902,7 @@ Concentric</property>
                                                             <property name="draw_indicator">False</property>
                                                             <signal name="clicked" 
handler="on_checkbutton_video_encoder_clicked" swapped="no"/>
                                                             <child>
-                                                            <widget class="GtkHBox" id="hbox322">
+                                                            <widget class="GtkHBox" id="hbox380">
                                                             <property name="visible">True</property>
                                                             <property name="can_focus">False</property>
                                                             <property name="spacing">2</property>
@@ -32992,11 +32994,19 @@ Concentric</property>
                                                             </packing>
                                                             </child>
                                                             </widget>
+                                                            <packing>
+                                                            <property name="expand">True</property>
+                                                            <property name="fill">True</property>
+                                                            <property name="position">1</property>
+                                                            </packing>
+                                                            </child>
+                                                            </widget>
                                                             </child>
                                                             </widget>
                                                             <packing>
                                                             <property name="expand">False</property>
                                                             <property name="fill">True</property>
+                                                            <property name="pack_type">end</property>
                                                             <property name="position">1</property>
                                                             </packing>
                                                             </child>
diff --git a/src/constants.cs b/src/constants.cs
index baad55c8b..f0a4ef8fa 100644
--- a/src/constants.cs
+++ b/src/constants.cs
@@ -1059,6 +1059,10 @@ public class Constants
                RT, OTHER } //OTHER can be: Multichronopic, Pulse
 
        //to shorten code on the rest of the software
+       public static bool ModeIsENCODER (Modes mode)
+       {
+               return (mode == Modes.POWERGRAVITATORY || mode == Modes.POWERINERTIAL);
+       }
        public static bool ModeIsFORCESENSOR (Modes mode)
        {
                return (mode == Modes.FORCESENSORISOMETRIC || mode == Modes.FORCESENSORELASTIC);
diff --git a/src/execute/arduinoCapture.cs b/src/execute/arduinoCapture.cs
index fd80b53c1..a1eb02010 100644
--- a/src/execute/arduinoCapture.cs
+++ b/src/execute/arduinoCapture.cs
@@ -546,7 +546,7 @@ public class MicroDiscover : MicroComms
        private string forceSensorStr = "Force_Sensor-";
        private string raceAnalyzerStr = "Race_Analyzer-";
        private string wichroStr = "Wifi-Controller-"; //Will be used for Wichro and Quick, then user will 
decide. "local:get_channel;" to know the channel
-       //private string encoderStr = "J"; //for encoder send a J and receive a J
+       private string encoderStr = "J"; //for encoder send a J and receive a J
 
        public enum Status { NotStarted, Connecting, Detecting, Done };
        private List<Status> progressBar_l; //progressBars status
@@ -639,6 +639,8 @@ public class MicroDiscover : MicroComms
                                        success = discoverForceSensor ();
                                else if(mode == Constants.Modes.RUNSENCODER)
                                        success = discoverRaceAnalyzer ();
+                               else if (Constants.ModeIsENCODER (mode))
+                                       success = discoverEncoder ();
                        } else
                                micro.Discovered = ChronopicRegisterPort.Types.UNKNOWN;
 
@@ -832,6 +834,28 @@ public class MicroDiscover : MicroComms
                return success;
        }
 
+       private bool discoverEncoder ()
+       {
+               bool success = false;
+               List<string> responseExpected_l = new List<string>();
+               responseExpected_l.Add (encoderStr);
+               if(cancel)
+                       return false;
+
+               if(getVersion ("J", responseExpected_l, true, 2000))
+               {
+                       LogB.Information("Discover found this device: " + micro.Response);
+                       if(micro.Response.Contains(encoderStr))
+                       {
+                               micro.Discovered = ChronopicRegisterPort.Types.ENCODER;
+                               success = true;
+                       }
+               }
+
+               flush(); //empty the port for future use
+               return success;
+       }
+
        private bool discoverMultitest ()
        {
                bool success = false;
diff --git a/src/gui/app1/chronojump.cs b/src/gui/app1/chronojump.cs
index 757b6a84a..79d96529c 100644
--- a/src/gui/app1/chronojump.cs
+++ b/src/gui/app1/chronojump.cs
@@ -299,8 +299,11 @@ public partial class ChronoJumpWindow
        [Widget] Gtk.Label label_micro_discover_not_found;
        [Widget] Gtk.Table table_micro_discover;
        [Widget] Gtk.HBox hbox_contacts_detect_and_execute;
+       [Widget] Gtk.HBox hbox_encoder_detect_and_execute;
        [Widget] Gtk.Button button_contacts_detect;
+       [Widget] Gtk.Button button_encoder_detect;
        [Widget] Gtk.Button button_contacts_detect_small;
+       [Widget] Gtk.Button button_encoder_detect_small;
        [Widget] Gtk.EventBox eventbox_button_micro_discover_cancel_close;
        [Widget] Gtk.Image image_button_micro_discover_cancel_close;
        [Widget] Gtk.Label label_button_micro_discover_cancel_close;
@@ -4637,6 +4640,9 @@ public partial class ChronoJumpWindow
                {
                        button_contacts_detect.Visible = show;
                        hbox_contacts_detect_and_execute.Visible = ! show;
+
+                       button_encoder_detect.Visible = show;
+                       hbox_encoder_detect_and_execute.Visible = ! show;
                }
        }
 
diff --git a/src/gui/app1/encoder.cs b/src/gui/app1/encoder.cs
index 760952e56..6dd7fca8f 100644
--- a/src/gui/app1/encoder.cs
+++ b/src/gui/app1/encoder.cs
@@ -991,8 +991,16 @@ public partial class ChronoJumpWindow
                else //if we are NOT capturing on the background …
                {
                        //check if chronopics have changed
+                       /*
                        if(! canCaptureEncoder() )
                                return;
+                               */
+                       chronopicRegister.ListSelectedForAllModes (); //debug
+                       if (chronopicRegister.GetSelectedForMode (current_mode).Port == "")
+                       {
+                               if (! configChronojump.Compujump)
+                                       on_button_detect_clicked (new object (), new EventArgs ()); //open 
discover win
+                       }
 
                        if(encoderConfigurationCurrent.has_inertia)
                        {
diff --git a/src/gui/chronopicRegister.cs b/src/gui/chronopicRegister.cs
index d3d46059c..83c64547d 100644
--- a/src/gui/chronopicRegister.cs
+++ b/src/gui/chronopicRegister.cs
@@ -385,6 +385,11 @@ public class DiscoverWindow
                        return true;
                else if (current_mode == Constants.Modes.RUNSENCODER && crpt == 
ChronopicRegisterPort.Types.ARDUINO_RUN_ENCODER)
                        return true;
+               else if (
+                               (current_mode == Constants.Modes.POWERGRAVITATORY ||
+                                current_mode == Constants.Modes.POWERINERTIAL) &&
+                               crpt == ChronopicRegisterPort.Types.ENCODER )
+                       return true;
 
                return false;
        }
diff --git a/src/gui/networks.cs b/src/gui/networks.cs
index 01953b7cb..83f5d7e4a 100644
--- a/src/gui/networks.cs
+++ b/src/gui/networks.cs
@@ -261,10 +261,16 @@ public partial class ChronoJumpWindow
                        button_contacts_devices_networks.Visible = true;
                        button_encoder_devices_networks.Visible = true;
                        button_contacts_detect_small.Visible = false;
+                       button_threshold.Visible = false;
+                       //button_force_sensor_adjust.Visible = false;
+                       button_encoder_detect_small.Visible = false;
                } else {
                        button_contacts_devices_networks.Visible = false;
                        button_encoder_devices_networks.Visible = false;
                        button_contacts_detect_small.Visible = true;
+                       button_threshold.Visible = true;
+                       //button_force_sensor_adjust.Visible = true;
+                       button_encoder_detect_small.Visible = true;
                }
 
                if(configChronojump.Raspberry)


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