[chronojump] Discover works ok with RaceAnalyzer and multitest (event on jumps)



commit ef2d38085ad72712c4c6ebb720cdb9154c7e3412
Author: Xavier de Blas <xaviblas gmail com>
Date:   Wed May 18 18:52:30 2022 +0200

    Discover works ok with RaceAnalyzer and multitest (event on jumps)

 src/chronopicRegister.cs      |  2 +-
 src/execute/arduinoCapture.cs | 72 ++++++++++++++++++++++++++++++++++++++++---
 src/gui/app1/chronojump.cs    | 24 ++++++++++++---
 3 files changed, 87 insertions(+), 11 deletions(-)
---
diff --git a/src/chronopicRegister.cs b/src/chronopicRegister.cs
index dcd81c28a..d94584f0f 100644
--- a/src/chronopicRegister.cs
+++ b/src/chronopicRegister.cs
@@ -84,7 +84,7 @@ public class ChronopicRegisterPort
                else if(typeStatic == Types.ACCELEROMETER)
                        return "Accelerometer";
                else if(typeStatic == Types.RUN_WIRELESS)
-                       return "Races (wireless)";
+                       return "WICHRO";
 
                return Catalog.GetString("Unknown");
        }
diff --git a/src/execute/arduinoCapture.cs b/src/execute/arduinoCapture.cs
index ceec13adf..3b9d0d112 100644
--- a/src/execute/arduinoCapture.cs
+++ b/src/execute/arduinoCapture.cs
@@ -573,7 +573,7 @@ public class MicroDiscover : MicroComms
 
                foreach (ChronopicRegisterPort crp in toDiscover_l)
                {
-                       micro_l.Add (new Micro (crp.Port, 115200));
+                       micro_l.Add (new Micro (crp.Port, 115200)); //for multitest will be changed below
                        microDiscoverManage_l.Add (new MicroDiscoverManage (crp.Port));
                        progressBar_l.Add (Status.NotStarted);
                }
@@ -597,9 +597,45 @@ public class MicroDiscover : MicroComms
                                progressBar_l[i] = Status.Detecting;
 
                                flush(); //after connect
-                               if(mode == Constants.Modes.RUNSSIMPLE || mode == 
Constants.Modes.RUNSINTERVALLIC)
-                                       success = discoverWichro ();
-                               if(mode == Constants.Modes.FORCESENSOR)
+                               if(mode == Constants.Modes.JUMPSSIMPLE || mode == 
Constants.Modes.JUMPSREACTIVE)
+                               {
+                                       micro.Bauds = 9600;
+                                       if(connectAndSleep ())
+                                       {
+                                               flush(); //after connect
+                                               LogB.Information("calling discoverMultitest");
+                                               success = discoverMultitest ();
+                                               LogB.Information("ended discoverMultitest");
+                                       }
+                               }
+                               else if(mode == Constants.Modes.RUNSSIMPLE || mode == 
Constants.Modes.RUNSINTERVALLIC)
+                               {
+                                       //if we need to test low speed and high speed, better try first low
+                                       //a 9600 device can get saturated if 115200 connection is done, will 
need to remove usb
+                                       micro.Bauds = 9600;
+                                       if(connectAndSleep ())
+                                       {
+                                               flush(); //after connect
+                                               LogB.Information("calling discoverMultitest");
+                                               success = discoverMultitest ();
+                                               LogB.Information("ended discoverMultitest");
+                                       }
+                                       if (! success)
+                                       {
+                                               LogB.Information("closing port");
+                                               micro.ClosePort ();
+                                               micro.Bauds = 115200;
+                                               LogB.Information("connectAndSleep again");
+                                               if(connectAndSleep ())
+                                               {
+                                                       LogB.Information("calling discoverWichro");
+                                                       success = discoverWichro ();
+                                                       LogB.Information("ended discoverWichro");
+                                               }
+                                       }
+                                       LogB.Information("success: " + success.ToString());
+                               }
+                               else if(mode == Constants.Modes.FORCESENSOR)
                                        success = discoverForceSensor ();
                                else if(mode == Constants.Modes.RUNSENCODER)
                                        success = discoverRaceAnalyzer ();
@@ -785,7 +821,7 @@ public class MicroDiscover : MicroComms
                                LogB.Information("Discover found this device: " + micro.Response);
                                if(micro.Response.Contains(wichroStr))
                                {
-                                       micro.Discovered = ChronopicRegisterPort.Types.ARDUINO_RUN_ENCODER;
+                                       micro.Discovered = ChronopicRegisterPort.Types.RUN_WIRELESS;
                                        success = true;
                                        break;
                                }
@@ -796,6 +832,32 @@ public class MicroDiscover : MicroComms
                return success;
        }
 
+       private bool discoverMultitest ()
+       {
+               bool success = false;
+
+               LogB.Information("Going to write a J");
+               micro.Write("J");
+               LogB.Information("Going to read a J");
+
+               Stopwatch sw = new Stopwatch();
+               sw.Start();
+               do {
+                       Thread.Sleep(25);
+                       if (micro.BytesToRead () && (char) micro.ReadByte() == 'J')
+                       {
+                               micro.Discovered = ChronopicRegisterPort.Types.CONTACTS;
+                               success = true;
+                       }
+               }
+               while(! (success || cancel || sw.Elapsed.TotalMilliseconds > 1000) );
+
+               LogB.Information("done");
+
+               flush(); //empty the port for future use
+               return success;
+       }
+
        /*
           these methods Discover all the devices,
           just use methods above to discover devices of each mode
diff --git a/src/gui/app1/chronojump.cs b/src/gui/app1/chronojump.cs
index d83228634..04bfcc67a 100644
--- a/src/gui/app1/chronojump.cs
+++ b/src/gui/app1/chronojump.cs
@@ -4621,6 +4621,8 @@ public partial class ChronoJumpWindow
        private void on_button_contacts_detect_clicked (object o, EventArgs args)
        {
                if(
+                               current_mode != Constants.Modes.JUMPSSIMPLE &&
+                               current_mode != Constants.Modes.JUMPSREACTIVE &&
                                current_mode != Constants.Modes.RUNSSIMPLE &&
                                current_mode != Constants.Modes.RUNSINTERVALLIC &&
                                current_mode != Constants.Modes.FORCESENSOR &&
@@ -4762,10 +4764,22 @@ public partial class ChronoJumpWindow
 
        private bool discoverMatchCurrentMode (ChronopicRegisterPort.Types crpt)
        {
-               if (current_mode == Constants.Modes.FORCESENSOR && crpt == 
ChronopicRegisterPort.Types.ARDUINO_FORCE)
-                       return true;
+               LogB.Information(string.Format(
+                                       "at discoverMatchCurrentMode current_mode: {0}, crpt: {1}",
+                                       current_mode, crpt));
 
-               //TODO: add for other modes
+               if (
+                               (current_mode == Constants.Modes.JUMPSSIMPLE || current_mode == 
Constants.Modes.JUMPSREACTIVE) &&
+                               crpt == ChronopicRegisterPort.Types.CONTACTS )
+                       return true;
+               else if (
+                               (current_mode == Constants.Modes.RUNSSIMPLE || current_mode == 
Constants.Modes.RUNSINTERVALLIC) &&
+                               (crpt == ChronopicRegisterPort.Types.CONTACTS || crpt == 
ChronopicRegisterPort.Types.RUN_WIRELESS) )
+                       return true;
+               else if (current_mode == Constants.Modes.FORCESENSOR && crpt == 
ChronopicRegisterPort.Types.ARDUINO_FORCE)
+                       return true;
+               else if (current_mode == Constants.Modes.RUNSENCODER && crpt == 
ChronopicRegisterPort.Types.ARDUINO_RUN_ENCODER)
+                       return true;
 
                return false;
        }
@@ -4781,8 +4795,8 @@ public partial class ChronoJumpWindow
                                forceSensorPortName = microDiscover.ToDiscover_l[i].Port;
                                LogB.Information(forceSensorPortName);
 
-                               //SqliteChronopicRegister.Update(false,
-                               //              microDiscover.NotDiscovered_l[i], 
microDiscover.Discovered_l[i]);
+                               SqliteChronopicRegister.Update(false,
+                                               microDiscover.ToDiscover_l[i], microDiscover.Discovered_l[i]);
                                chronopicRegister.SetType (microDiscover.ToDiscover_l[i].SerialNumber,
                                                microDiscover.Discovered_l[i]);
 


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