[chronojump] Autodetect encoder done! normal Chronopic pending



commit 3bcd6486c8d491c13631d106582a9cc468cda4fd
Author: Xavier de Blas <xaviblas gmail com>
Date:   Sat Mar 28 12:28:12 2015 +0100

    Autodetect encoder done! normal Chronopic pending

 glade/chronojump.glade |  136 +++++++++++++++++++++++++++++++++++++++++-------
 src/chronopic.cs       |   20 +++++---
 src/gui/chronojump.cs  |   92 ++++++++++++++++----------------
 src/gui/chronopic.cs   |   27 ++++++++--
 src/gui/encoder.cs     |    4 +-
 src/util.cs            |    9 +++
 6 files changed, 209 insertions(+), 79 deletions(-)
---
diff --git a/glade/chronojump.glade b/glade/chronojump.glade
index 97d4e4d..9c3523c 100644
--- a/glade/chronojump.glade
+++ b/glade/chronojump.glade
@@ -6609,6 +6609,9 @@ Second Chronopic to platforms.</property>
                                                         <child>
                                                           <placeholder/>
                                                         </child>
+                                                        <child>
+                                                          <placeholder/>
+                                                        </child>
                                                       </widget>
                                                       <packing>
                                                         <property name="expand">True</property>
@@ -7468,6 +7471,9 @@ Second Chronopic to platforms.</property>
                                                             <child>
                                                             <placeholder/>
                                                             </child>
+                                                            <child>
+                                                            <placeholder/>
+                                                            </child>
                                                             </widget>
                                                             </child>
                                                             <child>
@@ -8579,6 +8585,9 @@ Second Chronopic to platforms.</property>
                                                             <child>
                                                             <placeholder/>
                                                             </child>
+                                                            <child>
+                                                            <placeholder/>
+                                                            </child>
                                                             </widget>
                                                             <packing>
                                                             <property name="position">2</property>
@@ -9331,6 +9340,9 @@ Second Chronopic to platforms.</property>
                                                             <child>
                                                             <placeholder/>
                                                             </child>
+                                                            <child>
+                                                            <placeholder/>
+                                                            </child>
                                                             </widget>
                                                             <packing>
                                                             <property name="position">4</property>
@@ -13354,18 +13366,66 @@ on current Chronojump version.</property>
                                                 <property name="visible">True</property>
                                                 <property name="app_paintable">True</property>
                                                 <property name="can_focus">True</property>
-                                                <property name="spacing">8</property>
+                                                <property name="spacing">10</property>
                                                 <child>
-                                                  <widget class="GtkLabel" id="label_chronopic_encoder">
+                                                  <widget class="GtkHBox" id="hbox75">
                                                     <property name="visible">True</property>
                                                     <property name="can_focus">False</property>
-                                                    <property name="xpad">5</property>
-                                                    <property name="label" translatable="yes">Encoder 
disconnected</property>
-                                                    <property name="use_markup">True</property>
+                                                    <property name="spacing">2</property>
+                                                    <child>
+                                                      <widget class="GtkHBox" id="hbox95">
+                                                        <property name="visible">True</property>
+                                                        <property name="can_focus">False</property>
+                                                        <child>
+                                                          <widget class="GtkImage" 
id="image_chronopic_encoder_no">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">False</property>
+                                                            <property name="stock">gtk-no</property>
+                                                            <property name="icon-size">2</property>
+                                                          </widget>
+                                                          <packing>
+                                                            <property name="expand">False</property>
+                                                            <property name="fill">True</property>
+                                                            <property name="position">0</property>
+                                                          </packing>
+                                                        </child>
+                                                        <child>
+                                                          <widget class="GtkImage" 
id="image_chronopic_encoder_yes">
+                                                            <property name="can_focus">False</property>
+                                                            <property name="stock">gtk-yes</property>
+                                                            <property name="icon-size">3</property>
+                                                          </widget>
+                                                          <packing>
+                                                            <property name="expand">False</property>
+                                                            <property name="fill">True</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>
+                                                      </packing>
+                                                    </child>
+                                                    <child>
+                                                      <widget class="GtkLabel" id="label_chronopic_encoder">
+                                                        <property name="visible">True</property>
+                                                        <property name="can_focus">False</property>
+                                                        <property name="xpad">5</property>
+                                                        <property name="label" translatable="yes">Encoder 
disconnected</property>
+                                                        <property name="use_markup">True</property>
+                                                      </widget>
+                                                      <packing>
+                                                        <property name="expand">False</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>
@@ -13406,18 +13466,6 @@ on current Chronojump version.</property>
                                           </packing>
                                         </child>
                                         <child>
-                                          <widget class="GtkLabel" id="label_chronopic_encoder_detected">
-                                            <property name="visible">True</property>
-                                            <property name="can_focus">False</property>
-                                          </widget>
-                                          <packing>
-                                            <property name="expand">False</property>
-                                            <property name="fill">False</property>
-                                            <property name="pack_type">end</property>
-                                            <property name="position">2</property>
-                                          </packing>
-                                        </child>
-                                        <child>
                                           <widget class="GtkButton" id="button_encoder_maximize">
                                             <property name="label">gtk-zoom-fit</property>
                                             <property name="can_focus">True</property>
@@ -13429,9 +13477,12 @@ on current Chronojump version.</property>
                                             <property name="expand">False</property>
                                             <property name="fill">False</property>
                                             <property name="pack_type">end</property>
-                                            <property name="position">3</property>
+                                            <property name="position">2</property>
                                           </packing>
                                         </child>
+                                        <child>
+                                          <placeholder/>
+                                        </child>
                                       </widget>
                                       <packing>
                                         <property name="expand">False</property>
@@ -19827,6 +19878,9 @@ by you</property>
                         <child>
                           <placeholder/>
                         </child>
+                        <child>
+                          <placeholder/>
+                        </child>
                       </widget>
                     </child>
                   </widget>
@@ -20487,6 +20541,9 @@ by you</property>
                         <child>
                           <placeholder/>
                         </child>
+                        <child>
+                          <placeholder/>
+                        </child>
                       </widget>
                     </child>
                   </widget>
@@ -21639,6 +21696,9 @@ by you</property>
               <placeholder/>
             </child>
             <child>
+              <placeholder/>
+            </child>
+            <child>
               <widget class="GtkButton" id="button_video_url">
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
@@ -21848,6 +21908,9 @@ by you</property>
             <child>
               <placeholder/>
             </child>
+            <child>
+              <placeholder/>
+            </child>
           </widget>
           <packing>
             <property name="expand">True</property>
@@ -31747,6 +31810,24 @@ options</property>
                             <child>
                               <placeholder/>
                             </child>
+                            <child>
+                              <placeholder/>
+                            </child>
+                            <child>
+                              <placeholder/>
+                            </child>
+                            <child>
+                              <placeholder/>
+                            </child>
+                            <child>
+                              <placeholder/>
+                            </child>
+                            <child>
+                              <placeholder/>
+                            </child>
+                            <child>
+                              <placeholder/>
+                            </child>
                           </widget>
                         </child>
                       </widget>
@@ -33787,6 +33868,9 @@ To differentiate between male and female, use the values 1/0, or m/f, or M/F on
                                 <child>
                                   <placeholder/>
                                 </child>
+                                <child>
+                                  <placeholder/>
+                                </child>
                               </widget>
                             </child>
                           </widget>
@@ -34485,6 +34569,9 @@ To differentiate between male and female, use the values 1/0, or m/f, or M/F on
                         <child>
                           <placeholder/>
                         </child>
+                        <child>
+                          <placeholder/>
+                        </child>
                       </widget>
                     </child>
                   </widget>
@@ -37149,6 +37236,9 @@ show elevation as:</property>
                         <child>
                           <placeholder/>
                         </child>
+                        <child>
+                          <placeholder/>
+                        </child>
                       </widget>
                       <packing>
                         <property name="left_attach">2</property>
@@ -37473,6 +37563,9 @@ show elevation as:</property>
                     <child>
                       <placeholder/>
                     </child>
+                    <child>
+                      <placeholder/>
+                    </child>
                   </widget>
                 </child>
               </widget>
@@ -37812,6 +37905,9 @@ show elevation as:</property>
                     <child>
                       <placeholder/>
                     </child>
+                    <child>
+                      <placeholder/>
+                    </child>
                   </widget>
                 </child>
               </widget>
diff --git a/src/chronopic.cs b/src/chronopic.cs
index 79fe595..2afb4bf 100644
--- a/src/chronopic.cs
+++ b/src/chronopic.cs
@@ -621,6 +621,18 @@ public class ChronopicStartReactionTime : ChronopicAuto
        }
 }
 
+public static class ChronopicPorts
+{
+       public static string [] GetPorts() {
+               if(UtilAll.GetOSEnum() == UtilAll.OperatingSystems.LINUX)
+                       return Directory.GetFiles("/dev/", "ttyUSB*");
+               else if(UtilAll.GetOSEnum() == UtilAll.OperatingSystems.MACOSX)
+                       return Directory.GetFiles("/dev/", "tty.usbserial*");
+               else // WINDOWS
+                       return SerialPort.GetPortNames();
+       }
+}
+
 public class ChronopicAutoDetect
 {
        public enum ChronopicType { UNDETECTED, NORMAL, ENCODER }
@@ -658,13 +670,7 @@ public class ChronopicAutoDetect
        {
                LogB.Information("starting port detection");
 
-               string [] usbSerial;
-               if(UtilAll.GetOSEnum() == UtilAll.OperatingSystems.LINUX)
-                       usbSerial = Directory.GetFiles("/dev/", "ttyUSB*");
-               else if(UtilAll.GetOSEnum() == UtilAll.OperatingSystems.MACOSX)
-                       usbSerial = Directory.GetFiles("/dev/", "tty.usbserial*");
-               else // WINDOWS
-                       usbSerial = SerialPort.GetPortNames();
+               string [] usbSerial = ChronopicPorts.GetPorts();
 
                foreach(string port in usbSerial) 
                {
diff --git a/src/gui/chronojump.cs b/src/gui/chronojump.cs
index 8e8f5ab..fdef517 100644
--- a/src/gui/chronojump.cs
+++ b/src/gui/chronojump.cs
@@ -212,7 +212,8 @@ public partial class ChronoJumpWindow
        //[Widget] Gtk.Image image_connected_chronopics;
        [Widget] Gtk.Viewport viewport_chronopic_encoder;
        [Widget] Gtk.Label label_chronopic_encoder;
-       [Widget] Gtk.Label label_chronopic_encoder_detected;
+       [Widget] Gtk.Image image_chronopic_encoder_no;
+       [Widget] Gtk.Image image_chronopic_encoder_yes;
        
        [Widget] Gtk.HBox hbox_video_capture;
        [Widget] Gtk.Label label_video_feedback;
@@ -544,7 +545,7 @@ public partial class ChronoJumpWindow
                repetitiveConditionsWin = RepetitiveConditionsWindow.Create();
                repetitiveConditionsWin.FakeButtonClose.Clicked += new 
EventHandler(on_repetitive_conditions_closed);
 
-               createChronopicWindow(false);
+               createChronopicWindow(false, "");
        
                on_extra_window_multichronopic_test_changed(new object(), new EventArgs());
                on_extra_window_pulses_test_changed(new object(), new EventArgs());
@@ -2889,11 +2890,11 @@ public partial class ChronoJumpWindow
        
                        if(cad.Detected != "") {
                                LogB.Information("Detected at port: " + cad.Detected);
-                               label_chronopic_encoder_detected.Text = "Detected: " + cad.Detected;
+                               createChronopicWindow(true, cad.Detected);
                        }
                        else {
-                               LogB.Information("Not detected.");
-                               label_chronopic_encoder_detected.Text = "";
+                               LogB.Warning("Not detected.");
+                               createChronopicWindow(true, Util.GetDefaultPort());
                        }
                } else {
                        LogB.Information("Detecting normal Chronopic... ");
@@ -2918,7 +2919,7 @@ public partial class ChronoJumpWindow
                if(! UtilAll.IsWindows ()) {
                        if(! File.Exists(chronopicWin.GetContactsFirstPort())) {
                                LogB.Information("Chronopic has been disconnected");
-                               createChronopicWindow(true);
+                               createChronopicWindow(true, "");
                                chronopicWin.Connected = false;
                                return;
                        }
@@ -2928,7 +2929,7 @@ public partial class ChronoJumpWindow
                bool ok = (chronopicWin.CP).Read_platform(out ps);
                if(!ok) {
                        LogB.Information("Chronopic has been disconnected");
-                       createChronopicWindow(true);
+                       createChronopicWindow(true, "");
                        chronopicWin.Connected = false;
                        return;
                }
@@ -3512,7 +3513,7 @@ public partial class ChronoJumpWindow
                if(! UtilAll.IsWindows() && chronopicWin.Connected) {
                        if(! File.Exists(chronopicWin.GetContactsFirstPort())) {
                                LogB.Information("Chronopic has been disconnected");
-                               createChronopicWindow(true);
+                               createChronopicWindow(true, "");
                                chronopicWin.Connected = false;
                                return;
                        }
@@ -3794,11 +3795,8 @@ public partial class ChronoJumpWindow
                        if(! execute_auto_doing)
                                sensitiveGuiYesEvent();
                } 
-               else if( currentEventExecute.ChronopicDisconnected ) {
-                       LogB.Information("DISCONNECTED gui/cj");
-                       createChronopicWindow(true);
-                       chronopicWin.Connected = false;
-               }
+               else if( currentEventExecute.ChronopicDisconnected )
+                       chronopicDisconnectedWhileExecuting();
                
                //unhide buttons that allow jumping
                if(execute_auto_doing) {
@@ -3807,6 +3805,12 @@ public partial class ChronoJumpWindow
                        sensitiveGuiAutoExecuteOrWait (false);
                }
        }
+
+       private void chronopicDisconnectedWhileExecuting() {
+               LogB.Error("DISCONNECTED gui/cj");
+               createChronopicWindow(true, "");
+               chronopicWin.Connected = false;
+       }
                
        private void on_test_finished_can_touch_gtk (object o, EventArgs args)
        {
@@ -3967,11 +3971,8 @@ public partial class ChronoJumpWindow
                        //possible deletion of last jump can make the jumps on event window be false
                        event_execute_LabelEventValue = currentJumpRj.Jumps;
                } 
-               else if( currentEventExecute.ChronopicDisconnected ) {
-                       LogB.Information("DISCONNECTED gui/cj");
-                       createChronopicWindow(true);
-                       chronopicWin.Connected = false;
-               }
+               else if( currentEventExecute.ChronopicDisconnected )
+                       chronopicDisconnectedWhileExecuting();
                
                //delete the temp tables if exists
                Sqlite.DeleteTempEvents("tempJumpRj");
@@ -4105,11 +4106,8 @@ public partial class ChronoJumpWindow
                        //put correct time value in eventWindow (put the time from chronopic and not onTimer 
soft chronometer)
                        event_execute_LabelTimeValue = currentRun.Time;
                }
-               else if( currentEventExecute.ChronopicDisconnected ) {
-                       LogB.Information("DISCONNECTED gui/cj");
-                       createChronopicWindow(true);
-                       chronopicWin.Connected = false;
-               }
+               else if( currentEventExecute.ChronopicDisconnected )
+                       chronopicDisconnectedWhileExecuting();
        }
 
        /* ---------------------------------------------------------
@@ -4247,11 +4245,8 @@ public partial class ChronoJumpWindow
                        //possible deletion of last run can make the runs on event window be false
                        event_execute_LabelEventValue = currentRunInterval.Tracks;
                }
-               else if( currentEventExecute.ChronopicDisconnected ) {
-                       LogB.Information("DISCONNECTED gui/cj");
-                       createChronopicWindow(true);
-                       chronopicWin.Connected = false;
-               }
+               else if( currentEventExecute.ChronopicDisconnected )
+                       chronopicDisconnectedWhileExecuting();
                
                //delete the temp tables if exists
                Sqlite.DeleteTempEvents("tempRunInterval");
@@ -4344,11 +4339,8 @@ public partial class ChronoJumpWindow
                        //unhide buttons for delete last reaction time
                        sensitiveGuiYesEvent();
                }
-               else if( currentEventExecute.ChronopicDisconnected ) {
-                       LogB.Information("DISCONNECTED gui/cj");
-                       createChronopicWindow(true);
-                       chronopicWin.Connected = false;
-               }
+               else if( currentEventExecute.ChronopicDisconnected )
+                       chronopicDisconnectedWhileExecuting();
        }
 
        private void on_button_rt_3_on_clicked (object o, EventArgs args) {
@@ -4501,11 +4493,8 @@ public partial class ChronoJumpWindow
                        //put correct time value in eventWindow (put the time from chronopic and not onTimer 
soft chronometer)
                        event_execute_LabelTimeValue = Util.GetTotalTime(currentPulse.TimesString);
                }
-               else if( currentEventExecute.ChronopicDisconnected ) {
-                       LogB.Information("DISCONNECTED gui/cj");
-                       createChronopicWindow(true);
-                       chronopicWin.Connected = false;
-               }
+               else if( currentEventExecute.ChronopicDisconnected )
+                       chronopicDisconnectedWhileExecuting();
        }
 
        /* ---------------------------------------------------------
@@ -4514,14 +4503,21 @@ public partial class ChronoJumpWindow
         */
 
        //recreate is used when a Chronopic was disconnected
-       private void createChronopicWindow(bool recreate) {
+       //
+       //encoderPort is usually "" and will be Util.GetDefaultPort
+       //but, since 1.5.1 when selecting encoder option from main menu,
+       //then encoderPort will be found and send here
+       private void createChronopicWindow(bool recreate, string encoderPort) {
                ArrayList cpd = new ArrayList();
                for(int i=1; i<=4;i++) {
                        ChronopicPortData a = new ChronopicPortData(i,"",false);
                        cpd.Add(a);
                }
 
-               chronopicWin = ChronopicWindow.Create(cpd, Util.GetDefaultPort(), recreate, 
preferences.volumeOn);
+               if(encoderPort == "")
+                       encoderPort = Util.GetDefaultPort();
+
+               chronopicWin = ChronopicWindow.Create(cpd, encoderPort, recreate, preferences.volumeOn);
                //chronopicWin.FakeButtonCancelled.Clicked += new EventHandler(on_chronopic_window_cancelled);
                
                if(notebook_sup.CurrentPage == 0)
@@ -4613,9 +4609,16 @@ public partial class ChronoJumpWindow
                LogB.Debug("gui/chronojump.cs encoderPort:", encoderPort);
 
                if(encoderPort != null && encoderPort != "" && encoderPort != Util.GetDefaultPort())
+               {
                        label_chronopic_encoder.Text = Catalog.GetString("Encoder connected");
-               else
+                       image_chronopic_encoder_no.Visible = false;
+                       image_chronopic_encoder_yes.Visible = true;
+               }
+               else {
                        label_chronopic_encoder.Text = Catalog.GetString("Encoder disconnected");
+                       image_chronopic_encoder_no.Visible = true;
+                       image_chronopic_encoder_yes.Visible = false;
+               }
                
                if(colorize)
                        UtilGtk.ChronopicColors(viewport_chronopic_encoder, 
@@ -4783,11 +4786,8 @@ LogB.Debug("X");
                        //unhide buttons for delete last test
                        sensitiveGuiYesEvent();
                }
-               else if( currentEventExecute.ChronopicDisconnected ) {
-                       LogB.Information("DISCONNECTED gui/cj");
-                       createChronopicWindow(true);
-                       chronopicWin.Connected = false;
-               }
+               else if( currentEventExecute.ChronopicDisconnected )
+                       chronopicDisconnectedWhileExecuting();
        }
                
 
diff --git a/src/gui/chronopic.cs b/src/gui/chronopic.cs
index 5930dc7..1c7c4fd 100644
--- a/src/gui/chronopic.cs
+++ b/src/gui/chronopic.cs
@@ -195,7 +195,9 @@ public class ChronopicWindow
                */
        }
        
-       //recreate is used when a Chronopic was disconnected
+       //recreate is false the first time (on initialization of ChronoJumpWindow at gui/chronojump.cs)
+       //after that is true. Usually is used to manage a disconnected chronopic or other ports problems
+       //
        //port names come from gui/chronojump.cs to this method (myCpd)
        static public ChronopicWindow Create (ArrayList myCpd, string myEncoderPort, bool recreate, bool 
volumeOn)
        {
@@ -210,7 +212,8 @@ public class ChronopicWindow
                //ChronopicWindowBox.chronopic_window.Show ();
                
                ChronopicWindowBox.volumeOn = volumeOn;
-               encoderPort = myEncoderPort;
+
+               ChronopicWindowBox.setEncoderPort(myEncoderPort);       
 
                ChronopicWindowBox.fakeWindowDone = new Gtk.Button();
                //ChronopicWindowBox.fakeWindowReload = new Gtk.Button();
@@ -237,6 +240,7 @@ public class ChronopicWindow
                        ChronopicWindowBox.notebook_main.CurrentPage = 1;
                
                ChronopicWindowBox.createCombos();
+               ChronopicWindowBox.setEncoderPort(encoderPort); 
 
                //ports info comes from gui/chronojump.cs to Create mehod
                ChronopicWindowBox.info();
@@ -247,8 +251,15 @@ public class ChronopicWindow
                return ChronopicWindowBox;
        }
 
-       private void setDefaultValues() {
-               
+       private void setEncoderPort(string myEncoderPort) {
+               if(Util.FoundInStringArray(ChronopicPorts.GetPorts(), myEncoderPort))
+                       encoderPort = myEncoderPort;
+               else
+                       encoderPort = Util.GetDefaultPort();
+       }
+
+       private void setDefaultValues() 
+       {
                label_connect_contacts.Text = "<b>" + label_connect_contacts.Text + "</b>";
                label_connect_encoder.Text = "<b>" + label_connect_encoder.Text + "</b>";
                label_connect_contacts.UseMarkup = true;
@@ -998,10 +1009,18 @@ public class ChronopicWindow
        }
 
        public string GetEncoderPort() {
+               /*
                if(isWindows)
                        return UtilGtk.ComboGetActive(combo_windows_encoder);
                else
                        return UtilGtk.ComboGetActive(combo_linux_encoder);
+                       */
+               /*
+                * better like this because this can be created from Create
+                * and readed from the software
+                * without needing to define the combos (from View)
+                */
+               return encoderPort;
        }
 
 
diff --git a/src/gui/encoder.cs b/src/gui/encoder.cs
index 04180e7..97c5328 100644
--- a/src/gui/encoder.cs
+++ b/src/gui/encoder.cs
@@ -408,7 +408,7 @@ public partial class ChronoJumpWindow
                if(errorMessage != "") {
                        LogB.Warning(errorMessage);
                        new DialogMessage(Constants.MessageTypes.WARNING, Catalog.GetString(errorMessage));
-                       createChronopicWindow(true);
+                       createChronopicWindow(true, "");
                        return false;
                }
 
@@ -4799,7 +4799,7 @@ public partial class ChronoJumpWindow
                                        Catalog.GetString("Chronopic port is not configured."));
                                LogB.Error("Chronopic port is not configured.");
                        
-                               createChronopicWindow(true);
+                               createChronopicWindow(true, "");
                                return;
                        }
                } else if(
diff --git a/src/util.cs b/src/util.cs
index 2492c42..35084f8 100644
--- a/src/util.cs
+++ b/src/util.cs
@@ -1316,6 +1316,15 @@ public class Util
 
                return false;
        }
+       
+       public static bool FoundInStringArray(string [] a, string str) {
+               foreach (string str2 in a)
+                       if(str2 == str)
+                               return true;
+
+               return false;
+       }
+
 
        /*
        //delete a row of and arraylist of string[] if the string[0] is the value coming from startsWith


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