[chronojump/michrolab] At mode change (also at start), if ! device selected, will select any compatible (using NumConnected



commit 05c455a04f1d4635fc8bc687276680079abf83e4
Author: Xavier de Blas <xaviblas gmail com>
Date:   Mon Jul 18 11:59:14 2022 +0200

    At mode change (also at start), if ! device selected, will select any compatible (using 
NumConnectedOfType)

 src/chronopicRegister.cs   | 48 ++++++++++++++++++++++++++++++++++++++++++++++
 src/gui/app1/chronojump.cs |  6 +++++-
 2 files changed, 53 insertions(+), 1 deletion(-)
---
diff --git a/src/chronopicRegister.cs b/src/chronopicRegister.cs
index d9838d835..a54df497c 100644
--- a/src/chronopicRegister.cs
+++ b/src/chronopicRegister.cs
@@ -338,6 +338,54 @@ public abstract class ChronopicRegister
                selectedForMode_l.Add (new selectedForMode (crp, mode));
        }
 
+       // in order to the device available without needing to click to device button
+       public bool SetAnyCompatibleConnectedAsSelected (Constants.Modes mode)
+       {
+               if (mode == Constants.Modes.JUMPSSIMPLE || mode == Constants.Modes.JUMPSREACTIVE)
+               {
+                       if (setAnyCompatibleConnectedAsSelectedDo (mode, 
ChronopicRegisterPort.Types.CONTACTS))
+                               return true;
+               }
+               else if (mode == Constants.Modes.RUNSSIMPLE || mode == Constants.Modes.RUNSINTERVALLIC)
+               {
+                       if (setAnyCompatibleConnectedAsSelectedDo (mode, 
ChronopicRegisterPort.Types.CONTACTS))
+                               return true;
+                       //with the repeated FTDI number it will not work until selected at each Chronojump 
boot
+                       else if (setAnyCompatibleConnectedAsSelectedDo (mode, 
ChronopicRegisterPort.Types.RUN_WIRELESS))
+                               return true;
+               }
+               else if (Constants.ModeIsENCODER (mode))
+               {
+                       if (setAnyCompatibleConnectedAsSelectedDo (mode, ChronopicRegisterPort.Types.ENCODER))
+                               return true;
+               }
+               //with the repeated FTDI number it will not work until selected at each Chronojump boot
+               else if (Constants.ModeIsFORCESENSOR (mode))
+               {
+                       if (setAnyCompatibleConnectedAsSelectedDo (mode, 
ChronopicRegisterPort.Types.ARDUINO_FORCE))
+                               return true;
+               }
+               //with the repeated FTDI number it will not work until selected at each Chronojump boot
+               else if (mode == Constants.Modes.RUNSENCODER)
+               {
+                       if (setAnyCompatibleConnectedAsSelectedDo (mode, 
ChronopicRegisterPort.Types.ARDUINO_RUN_ENCODER))
+                               return true;
+               }
+
+               return false;
+       }
+       private bool setAnyCompatibleConnectedAsSelectedDo (Constants.Modes mode, ChronopicRegisterPort.Types 
type)
+       {
+               foreach(ChronopicRegisterPort crp in crpl.L)
+                       if(crp.Type == type && crp.Port != "")
+                       {
+                               SetSelectedForMode (crp, mode);
+                               return true;
+                       }
+
+               return false;
+       }
+
        public ChronopicRegisterPort GetSelectedForMode (Constants.Modes mode)
        {
                if (selectedForMode_l == null)
diff --git a/src/gui/app1/chronojump.cs b/src/gui/app1/chronojump.cs
index 21a0b1f6c..1076c5d37 100644
--- a/src/gui/app1/chronojump.cs
+++ b/src/gui/app1/chronojump.cs
@@ -3632,8 +3632,13 @@ public partial class ChronoJumpWindow
                if(chronopicRegister == null)
                        chronopicRegisterUpdate(false);
                chronopicRegister.ListSelectedForAllModes (); //debug
+               //if not selected, assign (auto-select) any compatible (using NumConnectedOfType)
+               if (chronopicRegister.GetSelectedForMode (m).Port == "")
+                       chronopicRegister.SetAnyCompatibleConnectedAsSelected (m);
+               //show button_detect depending on selected or not
                button_detect_show_hide (chronopicRegister.GetSelectedForMode (m).Port == "");
 
+
                //blank exercise options: useful for changing from jumps or runs to forceSensor, runEncoder, 
reaction time, other
                label_contacts_exercise_selected_name.Visible = true; //will not be visible when all the 
contacts_top combo is implemented
                label_contacts_exercise_selected_options.Text = "";
@@ -4626,7 +4631,6 @@ public partial class ChronoJumpWindow
           */
 
        //also manages if networks or not, on networks do not show
-       //TODO: add the encoder controls
        private void button_detect_show_hide (bool show)
        {
                //compujump will continue with the top right device button, far from the capture button


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