[chronojump] Several improvements to discover (including use chronopicRegister for SerialNumbers)



commit 994643b23c0a1d13416b1d6cdd212eca6bcfb4b1
Author: Xavier de Blas <xaviblas gmail com>
Date:   Tue May 17 17:32:30 2022 +0200

    Several improvements to discover (including use chronopicRegister for SerialNumbers)

 src/execute/arduinoCapture.cs |  9 ++++++
 src/gui/app1/chronojump.cs    | 64 +++++++++++++++++++++++++++++++------------
 2 files changed, 55 insertions(+), 18 deletions(-)
---
diff --git a/src/execute/arduinoCapture.cs b/src/execute/arduinoCapture.cs
index 695831034..2b303b745 100644
--- a/src/execute/arduinoCapture.cs
+++ b/src/execute/arduinoCapture.cs
@@ -551,6 +551,8 @@ public class MicroDiscover : MicroComms
        public enum Status { NotStarted, Connecting, Detecting, Done };
        private List<Status> progressBar_l; //progressBars status
 
+       private List<string> portName_l;
+
        //devices discovered compatible with current mode
        private static List<ChronopicRegisterPort.Types> discovered_l;
 
@@ -561,6 +563,8 @@ public class MicroDiscover : MicroComms
        //1st trying a list of just one port
        public MicroDiscover (List<string> portName_l)
        {
+               this.portName_l = portName_l;
+
                micro_l = new List<Micro> ();
                microDiscoverManage_l = new List<MicroDiscoverManage> ();
                progressBar_l = new List<Status> ();
@@ -607,6 +611,8 @@ public class MicroDiscover : MicroComms
                        //add to list only the relevant, eg in races will be Wichro (and maybe Chronopic 
multitest)
                        if(success)
                                discovered_l.Add(micro.Discovered);
+                       else
+                               discovered_l.Add(ChronopicRegisterPort.Types.UNKNOWN);
 
                        progressBar_l[i] = Status.Done;
 
@@ -895,6 +901,9 @@ public class MicroDiscover : MicroComms
        }
        */
 
+       public List<string> PortName_l {
+               get { return portName_l; }
+       }
        public List<Status> ProgressBar_l {
                get { return progressBar_l; }
        }
diff --git a/src/gui/app1/chronojump.cs b/src/gui/app1/chronojump.cs
index 6c005dd8a..9a4f92dcc 100644
--- a/src/gui/app1/chronojump.cs
+++ b/src/gui/app1/chronojump.cs
@@ -4555,30 +4555,30 @@ public partial class ChronoJumpWindow
           ----------------- discover / detect devices --------->
           */
 
-       List<Gtk.Label> label_micro_discover_l;
        List<Gtk.ProgressBar> progressbar_micro_discover_l;
        List<Gtk.Button> button_micro_discover_l;
 
-       private void setup_progressbar_micro_discover_l (List<string> discoverPorts_l)
+       //private void setup_progressbar_micro_discover_l (List<string> discoverPorts_l)
+       private void setup_progressbar_micro_discover_l (List<ChronopicRegisterPort> connected_l)
        {
                // 1) delete widgets of previous calls
                UtilGtk.RemoveChildren(table_micro_discover);
 
                //table_micro_discover = new Gtk.Table((uint) microDiscover.ProgressBar_l.Count +1, 3, 
false); //not homogeneous
-               table_micro_discover.Resize((uint) discoverPorts_l.Count, 3);
+               table_micro_discover.Resize((uint) connected_l.Count, 3);
                table_micro_discover.ColumnSpacing = 20;
                table_micro_discover.RowSpacing = 12;
 
+
                // 2) create the lists of widgets to be able to access later
-               label_micro_discover_l = new List<Gtk.Label> ();
                progressbar_micro_discover_l = new List<Gtk.ProgressBar> ();
                button_micro_discover_l = new List<Gtk.Button> ();
 
                // 3) create widgets, lists, attach to table and show all
-               for (int i = 0; i < discoverPorts_l.Count; i ++)
+               for (int i = 0; i < connected_l.Count; i ++)
                {
-                       Gtk.Label l = new Gtk.Label(discoverPorts_l[i]);
-                       label_micro_discover_l.Add (l);
+                       //Gtk.Label l = new Gtk.Label(connected_l[i].ToStringSepBy("\n"));
+                       Gtk.Label l = new Gtk.Label(string.Format("{0}\n{1}", connected_l[i].Port, 
connected_l[i].SerialNumber));
                        table_micro_discover.Attach (l, (uint) 0, (uint) 1, (uint) i, (uint) i+1); //left, 
right, top, bottom
 
                        Gtk.ProgressBar pb = new Gtk.ProgressBar();
@@ -4613,6 +4613,24 @@ public partial class ChronoJumpWindow
                label_micro_discover_title.Text = string.Format(Catalog.GetString(
                                        "Detect device for mode: <b>{0}</b>"), modePrint(current_mode));
                label_micro_discover_title.UseMarkup = true;
+
+               // 2) get the serial numbers (and also the portName and type if saved on SQL)
+               chronopicRegisterUpdate (false);
+
+               List<ChronopicRegisterPort> connected_l = new List<ChronopicRegisterPort> ();
+               List<string> portName_l = new List<string> ();
+               foreach(ChronopicRegisterPort crp in chronopicRegister.Crpl.L)
+                        if(crp.Port != "")
+                       {
+                                connected_l.Add(crp);
+                                portName_l.Add(crp.Port);
+                       }
+
+               label_micro_discover_ports.Text = string.Format(Catalog.GetPluralString(
+                                       "Found 1 device.",
+                                       "Found {0} devices.",
+                                       connected_l.Count), connected_l.Count);
+
                app1s_notebook_sup_entered_from = notebook_sup.CurrentPage; //CONTACTS or ENCODER
                notebook_sup.CurrentPage = Convert.ToInt32(notebook_sup_pages.MICRODISCOVER);
                menus_and_mode_sensitive (false);
@@ -4621,11 +4639,15 @@ public partial class ChronoJumpWindow
                                new Pixbuf (null, Util.GetImagePath(false) + "image_cancel.png");
                label_button_micro_discover_cancel_close.Text = Catalog.GetString("Cancel");
 
-               if(discoverPorts_l != null && discoverPorts_l.Count > 0)
+               if(connected_l != null && connected_l.Count > 0)
                {
                        label_micro_discover_ports_detecting.Visible = true;
-                       microDiscover = new MicroDiscover (discoverPorts_l); //all ports
-                       setup_progressbar_micro_discover_l (discoverPorts_l);
+
+                       microDiscover = new MicroDiscover (portName_l);
+
+                       //setup_progressbar_micro_discover_l (discoverPorts_l);
+                       setup_progressbar_micro_discover_l (connected_l);
+
                        discoverThread = new Thread (new ThreadStart (discoverDo));
                        GLib.Idle.Add (new GLib.IdleHandler (pulseDiscoverGTK));
                        discoverThread.Start();
@@ -4653,9 +4675,10 @@ public partial class ChronoJumpWindow
                        return true;
                }
 
-               //update progressbar message
+               //gui updates while thread is alive
                for (int i = 0; i < progressbar_micro_discover_l.Count; i ++)
                {
+                       //progressbars
                        Gtk.ProgressBar pb = progressbar_micro_discover_l[i];
                        if (microDiscover.ProgressBar_l[i] == MicroDiscover.Status.NotStarted)
                        {
@@ -4672,6 +4695,13 @@ public partial class ChronoJumpWindow
                                        pb.Text = microDiscover.ProgressBar_l[i].ToString();
                                pb.Pulse ();
                        }
+
+                       if (i < microDiscover.Discovered_l.Count && discoverMatchCurrentMode 
(microDiscover.Discovered_l[i]))
+                       {
+                               (progressbar_micro_discover_l[i]).Text = 
ChronopicRegisterPort.TypePrint(microDiscover.Discovered_l[i]);
+                               button_micro_discover_l[i].Sensitive = true;
+                               button_micro_discover_l[i].Clicked += new 
EventHandler(on_discover_button_clicked);
+                       }
                }
 
                if(! discoverThread.IsAlive)
@@ -4688,13 +4718,9 @@ public partial class ChronoJumpWindow
 
                                (progressbar_micro_discover_l[i]).Fraction = 1;
 
-                               if (i < microDiscover.Discovered_l.Count && discoverMatchCurrentMode 
(microDiscover.Discovered_l[i]))
-                               {
-                                       LogB.Information("found in " + i);
-                                       (progressbar_micro_discover_l[i]).Text = 
ChronopicRegisterPort.TypePrint(microDiscover.Discovered_l[i]);
-                                       button_micro_discover_l[i].Sensitive = true;
-                                       button_micro_discover_l[i].Clicked += new 
EventHandler(on_discover_button_clicked);
-                               }
+                               if ( ! (i < microDiscover.Discovered_l.Count &&
+                                                       discoverMatchCurrentMode 
(microDiscover.Discovered_l[i])) )
+                                       (progressbar_micro_discover_l[i]).Text = "----";
                        }
 
                        label_micro_discover_ports_detecting.Visible = false;
@@ -4714,6 +4740,8 @@ public partial class ChronoJumpWindow
                if (current_mode == Constants.Modes.FORCESENSOR && crpt == 
ChronopicRegisterPort.Types.ARDUINO_FORCE)
                        return true;
 
+               //TODO: add for other modes
+
                return false;
        }
 


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