[chronojump] ChangeMultitestFirmware working again



commit 565247f6055a7c4c0ba2f5e089a2c9e64d214423
Author: Xavier de Blas <xaviblas gmail com>
Date:   Wed Oct 12 23:52:34 2016 +0200

    ChangeMultitestFirmware working again

 src/chronopic2016.cs         |   91 +++++++++++++++++++++++++++-
 src/gui/chronojump.cs        |  138 ++++++------------------------------------
 src/gui/chronopicRegister.cs |    2 +-
 3 files changed, 108 insertions(+), 123 deletions(-)
---
diff --git a/src/chronopic2016.cs b/src/chronopic2016.cs
index 51f1395..38aa4da 100644
--- a/src/chronopic2016.cs
+++ b/src/chronopic2016.cs
@@ -88,9 +88,94 @@ public class Chronopic2016
                return str;
        }
 
-       public int ChangeMultitestFirmware (int debounceChange)
+
+       // ----- change multitest firmware START ----->
+
+       private bool previousMultitestFirmwareDefined = false;
+       private Constants.Menuitem_modes previousMultitestFirmware;
+
+       //change debounce time automatically on change menuitem mode (if multitest firmware)
+       //return values:
+       //-1 error
+       //0 don't need to change
+       //10 or 50 the change value
+       public int ChangeMultitestFirmwareMaybe(Constants.Menuitem_modes m)
        {
-               LogB.Information("change_multitest_firmware 3 a");
+
+               LogB.Information("ChangeMultitestFirmwareMaybe (A)");
+
+               //---- 1 if don't need to change, return
+               if(previousMultitestFirmwareDefined &&
+                               ! Constants.Menuitem_mode_multitest_should_change(previousMultitestFirmware, 
m))
+               {
+                       LogB.Information("don't need to change multitest firmware");
+                       return 0;
+               }
+
+
+               //bool ok = cp.Read_platform(out platformState);
+               //seems better to have a new platformState:
+               Chronopic.Plataforma ps;
+               bool ok = cp.Read_platform(out ps);
+               if(! ok) {
+                       LogB.Information("Chronopic has been disconnected");
+                       //createChronopicWindow(true, "");
+                       //chronopicWin.Connected = false;
+                       return -1;
+               }
+
+
+               /*
+                * method 1. Unused
+               try {
+                       ChronopicAuto ca = new ChronopicAutoCheck();
+                       //problems with windows using this:
+                       string chronopicVersion = ca.Read(chronopicWin.SP);
+                       LogB.Debug("version: " + chronopicVersion);
+               } catch {
+                       LogB.Information("Could not read from Chronopic with method 1");
+                       return;
+               }*/
+
+               //---- 4 try to communicate with multitest firmware (return if cannot connect)
+
+               LogB.Information("ChangeMultitestFirmwareMaybe (B)");
+               bool isChronopicAuto = false;
+               try {
+                       string result = CheckAuto(out isChronopicAuto);
+                       LogB.Debug("version: " + result);
+               } catch {
+                       LogB.Information("Could not read from Chronopic with method 2");
+                       return -1;
+               }
+
+               //---- 5 change 10 <-> 50 ms
+               int returnValue = -1;
+
+               LogB.Information("ChangeMultitestFirmwareMaybe (C)");
+               if(isChronopicAuto) {
+                       int debounceChange = 50;
+                       if(m == Constants.Menuitem_modes.RUNSSIMPLE || m == 
Constants.Menuitem_modes.RUNSINTERVALLIC)
+                               debounceChange = 10;
+
+                       int msChanged = changeMultitestFirmwareDo(debounceChange);
+                       if(msChanged == 50)
+                               returnValue = 50;
+                       else if(msChanged == 10)
+                               returnValue = 10;
+               }
+
+               previousMultitestFirmwareDefined = true;
+               previousMultitestFirmware = m;
+
+               LogB.Information("ChangeMultitestFirmwareMaybe (D)");
+
+               return returnValue;
+       }
+
+       private int changeMultitestFirmwareDo (int debounceChange)
+       {
+               LogB.Information("ChangeMultitestFirmwareDo");
                try {
                        //write change
                        ChronopicAuto ca = new ChronopicAutoChangeDebounce();
@@ -126,6 +211,8 @@ public class Chronopic2016
                return -1;
        }
 
+       // <----- change multitest firmware END
+
        public void SerialPortsCloseIfNeeded() {
                if(sp != null && sp.IsOpen) {
                        LogB.Information("Closing sp");
diff --git a/src/gui/chronojump.cs b/src/gui/chronojump.cs
index d9f964e..4981f22 100644
--- a/src/gui/chronojump.cs
+++ b/src/gui/chronojump.cs
@@ -2957,13 +2957,14 @@ public partial class ChronoJumpWindow
 
 
                //change multitest firmware or autoDetectChronopic
-               if(Constants.Menuitem_mode_IsContacts(m))
-               {
+               //if(Constants.Menuitem_mode_IsContacts(m))
+               //{
                        //if(chronopicWin.Connected)
-                               change_multitest_firmware(m);
+                               //change_multitest_firmware(m);
+
                        //else
                        //      autoDetectChronopic(m); //on contacts will perform change_multitest_firmware 
at the end
-               }
+               //}
                //else if(wizardPortEncoder == "")
                //      autoDetectChronopic(m);
 
@@ -3078,122 +3079,6 @@ public partial class ChronoJumpWindow
        }
        */
                
-       private bool previousMultitestFirmwareDefined = false;
-       private Constants.Menuitem_modes previousMultitestFirmware;
-
-       //change debounce time automatically on change menuitem mode (if multitest firmware)
-       private void change_multitest_firmware(Constants.Menuitem_modes m) 
-       {
-
-               LogB.Information("change_multitest_firmware");
-               LogB.Information("Disabled temporarily");
-               //TODO: enable again. Active once first connection is done. Problem is cp is not initialized
-               return;
-
-               //---- 1 if don't need to change, return
-               if(previousMultitestFirmwareDefined && 
-                               ! Constants.Menuitem_mode_multitest_should_change(previousMultitestFirmware, 
m)) 
-               {
-                       LogB.Information("don't need to change multitest firmware");
-                       return;
-               }
-
-               label_chronopics_multitest.Text = "";
-
-               if(! canCaptureContacts())
-                       return;
-
-               /*
-               //---- 2 if is not connected, return
-
-               if(! chronopicWin.Connected)
-               return;
-
-               //---- 3 if port does not exists, show cp window and return
-
-               //http://www.raspberrypi.org/forums/viewtopic.php?f=66&t=88415
-               //https://bugzilla.xamarin.com/show_bug.cgi?id=15514
-               if(! UtilAll.IsWindows ()) {
-               if(! File.Exists(chronopicWin.GetContactsFirstPort())) {
-               LogB.Information("Chronopic has been disconnected");
-               createChronopicWindow(true, "");
-               chronopicWin.Connected = false;
-               return;
-               }
-               }
-               */
-
-               LogB.Information("change_multitest_firmware 1");
-
-               /*
-                       LogB.Debug("chronopicWin is null? " + (chronopicWin == null).ToString());
-
-                       int cps = chronopicWin.NumConnected();
-                       LogB.Debug("cps: " + cps.ToString());
-
-                       LogB.Debug("chronopicWin.Connected? " + chronopicWin.Connected.ToString());
-                       */
-
-               Chronopic.Plataforma ps;
-               bool ok = (cp2016.CP).Read_platform(out ps);
-               if(!ok) {
-                       LogB.Information("Chronopic has been disconnected");
-                       //createChronopicWindow(true, "");
-                       //chronopicWin.Connected = false;
-                       return;
-               }
-
-
-               LogB.Information("change_multitest_firmware 2");
-               ChronopicAuto ca;
-
-               /*      
-                       try {
-                       ca = new ChronopicAutoCheck();
-               //problems with windows using this:
-               string chronopicVersion = ca.Read(chronopicWin.SP);
-               LogB.Debug("version: " + chronopicVersion);
-               } catch {
-               LogB.Information("Could not read from Chronopic with method 1");
-               return;
-               }
-               */
-
-               //---- 4 try to communicate with multitest firmware (return if cannot connect)
-
-               LogB.Information("Trying method 2");
-               bool isChronopicAuto = false;
-               try {
-                       string result = cp2016.CheckAuto(out isChronopicAuto);
-                       LogB.Debug("version: " + result);
-               } catch {
-                       LogB.Information("Could not read from Chronopic with method 2");
-                       return;
-               }
-
-               //---- 5 change 10 <-> 50 ms
-
-               LogB.Information("change_multitest_firmware 3");
-               if(isChronopicAuto) {
-                       int debounceChange = 50;
-                       if(m == Constants.Menuitem_modes.RUNSSIMPLE || m == 
Constants.Menuitem_modes.RUNSINTERVALLIC)
-                               debounceChange = 10;
-
-                       int msChanged = cp2016.ChangeMultitestFirmware(debounceChange);
-                       if(msChanged != -1) {
-                               if(msChanged == 50)
-                                       label_chronopics_multitest.Text = "[" + Catalog.GetString("Jumps") + 
"]";
-                               else if(msChanged == 10)
-                                       label_chronopics_multitest.Text = "[" + Catalog.GetString("Runs") + 
"]";
-                               else
-                                       label_chronopics_multitest.Text = "";
-                       } else
-                               label_chronopics_multitest.Text = "";
-               }
-
-               previousMultitestFirmwareDefined = true;
-               previousMultitestFirmware = m;
-       }
 
        private Constants.Menuitem_modes getMenuItemMode() 
        {
@@ -3770,6 +3655,19 @@ public partial class ChronoJumpWindow
                                        return;
                                }
                        }
+
+                       //change multitest stuff
+                       int changed = cp2016.ChangeMultitestFirmwareMaybe(getMenuItemMode());
+
+                       //TODO: this is debug info. Remove this for 1.6.3
+                       if(changed == -1)
+                               label_chronopics_multitest.Text = "";
+                       else if(changed == 50)
+                               label_chronopics_multitest.Text =
+                                       "[" + Catalog.GetString("Jumps") + "]";
+                       else if(changed == 10)
+                               label_chronopics_multitest.Text =
+                                       "[" + Catalog.GetString("Runs") + "]";
                } else {
                        //simulated tests are only allowed on SIMULATED session
                        if(currentSession.Name != Constants.SessionSimulatedName) {
diff --git a/src/gui/chronopicRegister.cs b/src/gui/chronopicRegister.cs
index f69837f..26d06c2 100644
--- a/src/gui/chronopicRegister.cs
+++ b/src/gui/chronopicRegister.cs
@@ -127,7 +127,7 @@ public class ChronopicRegisterWindow
                unknownCol.PackStart (unknownCell, true);
 
                Gtk.TreeViewColumn contactsCol = new Gtk.TreeViewColumn ();
-               contactsCol.Title = "Contacts";
+               contactsCol.Title = "Jumps/Runs";
                Gtk.CellRendererToggle contactsCell = new Gtk.CellRendererToggle ();
                contactsCell.Activatable = true;
                contactsCell.Radio = true;      //draw as radiobutton


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