[chronojump] Change multitest firmware only when needed



commit 301492d6ed4dfa70cd5c97a459060e10e3eabf1c
Author: Xavier de Blas <xaviblas gmail com>
Date:   Thu Sep 8 17:33:32 2016 +0200

    Change multitest firmware only when needed

 src/constants.cs      |   20 +++++++++++++++++++-
 src/gui/chronojump.cs |   26 ++++++++++++++++++++------
 2 files changed, 39 insertions(+), 7 deletions(-)
---
diff --git a/src/constants.cs b/src/constants.cs
index 42ff536..1afb15c 100644
--- a/src/constants.cs
+++ b/src/constants.cs
@@ -692,12 +692,30 @@ public class Constants
        }
 
        public enum Menuitem_modes { JUMPSSIMPLE, JUMPSREACTIVE, RUNSSIMPLE, RUNSINTERVALLIC, 
POWERGRAVITATORY, POWERINERTIAL, OTHER }
-       public static bool Menuitem_mode_IsContacts (Menuitem_modes m) {
+       public static bool Menuitem_mode_IsContacts (Menuitem_modes m) 
+       {
                if(m == Menuitem_modes.POWERGRAVITATORY || m == Menuitem_modes.POWERINERTIAL)
                        return false;
                return true;
        }
 
+       //unused on power
+       private static int menuitem_mode_multitest_debounce (Menuitem_modes m) 
+       {
+               if(m == Menuitem_modes.RUNSSIMPLE || m == Menuitem_modes.RUNSINTERVALLIC)
+                       return 10;
+               
+               return 50;
+       }
+       //know if multitest firmware has to be changed, eg jumps(50) <-> runs(10)
+       public static bool Menuitem_mode_multitest_should_change (Menuitem_modes mPre, Menuitem_modes m) 
+       {
+               if(menuitem_mode_multitest_debounce(mPre) != menuitem_mode_multitest_debounce(m))
+                       return true;
+
+               return false;
+       }
+
        public static string All = "All";
        public static string None = "None";
        public static string Invert = "Invert";
diff --git a/src/gui/chronojump.cs b/src/gui/chronojump.cs
index ce6374c..74f7379 100644
--- a/src/gui/chronojump.cs
+++ b/src/gui/chronojump.cs
@@ -3379,20 +3379,31 @@ public partial class ChronoJumpWindow
        {
                main_menu.Sensitive = true;
        }
-                       
+               
+       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");
+
+               //---- 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 = "";
                
-
-               //---- 1 if is not connected, return
+               //---- 2 if is not connected, return
                
                if(! chronopicWin.Connected)
                        return;
 
-               //---- 2 if port does not exists, show cp window and 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
@@ -3439,7 +3450,7 @@ public partial class ChronoJumpWindow
                }
                */
 
-               //---- 3 try to communicate with multitest firmware (return if cannot connect)
+               //---- 4 try to communicate with multitest firmware (return if cannot connect)
                
                LogB.Information("Trying method 2");
                bool isChronopicAuto = false;
@@ -3451,7 +3462,7 @@ public partial class ChronoJumpWindow
                        return;
                }
                
-               //---- 4 change 10 <-> 50 ms
+               //---- 5 change 10 <-> 50 ms
 
                LogB.Information("change_multitest_firmware 3");
                if(isChronopicAuto) {
@@ -3470,6 +3481,9 @@ public partial class ChronoJumpWindow
                        } else
                                label_chronopics_multitest.Text = "";
                }
+       
+               previousMultitestFirmwareDefined = true;
+               previousMultitestFirmware = m;
        }
 
        private Constants.Menuitem_modes getMenuItemMode() 


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