[chronojump] Multichronopic working again



commit d8e42d018ac8c80d6d21cb1d44160963b308f71c
Author: Xavier de Blas <xaviblas gmail com>
Date:   Mon Jan 2 16:04:10 2017 +0100

    Multichronopic working again

 src/chronopic.cs      |   22 +---------
 src/chronopic2016.cs  |    2 +
 src/gui/chronojump.cs |   77 ++--------------------------------
 src/gui/chronopic.cs  |  112 +++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 119 insertions(+), 94 deletions(-)
---
diff --git a/src/chronopic.cs b/src/chronopic.cs
index b385bec..8195a81 100644
--- a/src/chronopic.cs
+++ b/src/chronopic.cs
@@ -523,28 +523,8 @@ public class ChronopicInit
                        myCp = new Chronopic(); //fake constructor
                }
                
-               bool connected = false;
                returnString = "";
-               if(success) {
-                       if(currentCp == 1)
-                               connected = true;
-                       returnString = string.Format(Catalog.GetString("<b>Connected</b> to Chronopic on 
port: {0}"), myPort);
-               }
-               else {
-                       returnString = Catalog.GetString("Problems communicating to chronopic.");
-                       if(currentCp == 1) {
-                               returnString += " " + Catalog.GetString("Changed platform to 'Simulated'");
-                               returnString += Catalog.GetString("\n\nWe recommend to remove and connect USB 
cable.");
-                       }
-
-                       //this will raise on_radiobutton_simulated_ativate and 
-                       //will put cpRunning to false, and simulated to true and cp.Close()
-                       if(currentCp == 1) {
-                               connected = false;
-                       }
-               }
-
-               return connected;
+               return success;
        }
        
 }
diff --git a/src/chronopic2016.cs b/src/chronopic2016.cs
index 22ec435..41380fb 100644
--- a/src/chronopic2016.cs
+++ b/src/chronopic2016.cs
@@ -139,12 +139,14 @@ public class Chronopic2016
 
                if(cpDoing == 1)
                {
+                       LogB.Information("connectContactsRealDo() 1");
                        sp = new SerialPort(crp.Port);
                        chronopicInit = new ChronopicInit();
                        connected = chronopicInit.Do(1, out cp, out sp,
                                        platformState, crp.Port, out message, out success);
                } else //(cpDoing == 2)
                {
+                       LogB.Information("connectContactsRealDo() 2");
                        sp2 = new SerialPort(crp.Port);
                        chronopicInit = new ChronopicInit();
                        connected = chronopicInit.Do(2, out cp2, out sp2,
diff --git a/src/gui/chronojump.cs b/src/gui/chronojump.cs
index ac6aa0c..a3c23b6 100644
--- a/src/gui/chronojump.cs
+++ b/src/gui/chronojump.cs
@@ -3856,7 +3856,8 @@ public partial class ChronoJumpWindow
                                threshold.ChronopicFirmwareUpdated();
                }
 
-               button_activate_chronopics.Show();
+               connectingSequence = connectingSequenceEnum.END;
+               chronopicConnectionSequenceDo();
        }
 
        void on_button_execute_test_clicked (object o, EventArgs args) 
@@ -3869,64 +3870,11 @@ public partial class ChronoJumpWindow
                //check if chronopics have changed
                if(numContacts >= 2 && radio_mode_multi_chronopic_small.Active)
                {
-                       //will get two or null
-                       List<ChronopicRegisterPort> crpMultiList = 
chronopicRegister.GetTwoContactsConnected();
-                       //store a boolean in order to read info faster
-                       cp2016.StoredCanCaptureContacts = (crpMultiList.Count == 2);
-
-                       foreach(ChronopicRegisterPort crp in crpMultiList)
-                       {
-                               //TODO: Note this code can be BUGGY in the foreach because two iteration can 
happen while waiting user interaction
-                               int count = 1;
-                               if(cp2016.IsLastConnectedReal(crp))
-                               {
-                                       LogB.Information("Already Connected real! cp = " + count.ToString());
-                                       changeMultitestFirmwareIfNeeded(count);
-                                       //on_button_execute_test_accepted();
-                               } else {
-                                       cp2016.FakeButtonContactsRealDone.Clicked +=
-                                               new EventHandler(on_connection_contacts_real_done);
-
-                                       cp2016.ConnectContactsReal(app1, crp, count,
-                                                       "Press TEST button on Chronopic to stablish initial 
communication"); //TODO: translate this
-
-                                       /* this will start a thread and if succeeds, then will call:
-                                        * changeMultitestFirmwareIfNeeded();
-                                        * on_button_execute_test_accepted();
-                                        */
-                               }
-                               count ++;
-                       }
-
-                       return;
+                       chronopicConnectionSequenceInit(2);
                }
                else if(numContacts >= 1) //will get first
                {
-                       ChronopicRegisterPort crp = 
chronopicRegister.ConnectedOfType(ChronopicRegisterPort.Types.CONTACTS);
-                       //store a boolean in order to read info faster
-                       cp2016.StoredCanCaptureContacts = true;
-
-                       LogB.Information("Checking if Connected real!");
-                       if(cp2016.IsLastConnectedReal(crp))
-                       {
-                               LogB.Information("Already Connected real!");
-                               changeMultitestFirmwareIfNeeded(1);
-                               on_button_execute_test_accepted();
-                       } else
-                       {
-                               cp2016.FakeButtonContactsRealDone.Clicked +=
-                                       new EventHandler(on_connection_contacts_real_done);
-
-                               cp2016.ConnectContactsReal(app1, crp, 1,
-                                               "Press TEST button on Chronopic to stablish initial 
communication"); //TODO: translate this
-
-                               /* this will start a thread and if succeeds, then will call:
-                                * changeMultitestFirmwareIfNeeded();
-                                * on_button_execute_test_accepted();
-                                */
-                       }
-
-                       return;
+                       chronopicConnectionSequenceInit(1);
                }
                else //(numContacts == 0)
                {
@@ -3949,23 +3897,6 @@ public partial class ChronoJumpWindow
                }
        }
 
-       private void on_connection_contacts_real_done (object o, EventArgs args)
-       {
-               cp2016.FakeButtonContactsRealDone.Clicked -=
-                       new EventHandler(on_connection_contacts_real_done);
-
-               if(cp2016.SuccededConnectContactsRealThread) {
-                       LogB.Information("Success at Connecting real! (main GUI)");
-                       if(testsActive)
-                               chronojumpWindowTestsNext();
-                       else {
-                               changeMultitestFirmwareIfNeeded(cp2016.CpDoing);
-                               on_button_execute_test_accepted();
-                       }
-               } else
-                       LogB.Warning("Failure at Connecting real! (main GUI)");
-       }
-
        void on_button_execute_test_accepted ()
        {
                bool canCaptureC = cp2016.StoredCanCaptureContacts;
diff --git a/src/gui/chronopic.cs b/src/gui/chronopic.cs
index 55c0e6c..2fd4404 100644
--- a/src/gui/chronopic.cs
+++ b/src/gui/chronopic.cs
@@ -28,6 +28,118 @@ using Mono.Unix;
 using System.Threading;
 using System.IO; //"File" things
 using System.Collections; //ArrayList
+using System.Collections.Generic; //List
+
+//gui stuff for the connection of one or two chronopics
+public partial class ChronoJumpWindow
+{
+       //multi chronopic stuff
+       List<ChronopicRegisterPort> crpMultiList;
+
+       ChronopicRegisterPort crpDoing;
+       bool connectAnother;
+       int connectNum;
+       enum connectingSequenceEnum { START, CONNECTINGREAL, FIRMWAREIFNEEDED, END }
+       private static connectingSequenceEnum connectingSequence;
+
+       private void chronopicConnectionSequenceInit(int numCPs)
+       {
+               connectNum = 1;
+               if(numCPs == 1)
+               {
+                       connectAnother = false;
+                       crpDoing = chronopicRegister.ConnectedOfType(ChronopicRegisterPort.Types.CONTACTS);
+                       //store a boolean in order to read info faster
+                       cp2016.StoredCanCaptureContacts = true;
+               }
+               else
+               { //2
+                       connectAnother = true;
+                       //will get two crps or null
+                       crpMultiList = chronopicRegister.GetTwoContactsConnected();
+                       //store a boolean in order to read info faster
+                       if(crpMultiList == null)
+                               return;
+
+                       crpDoing = crpMultiList[0];
+
+                       cp2016.StoredCanCaptureContacts = (crpMultiList.Count == 2);
+               }
+               connectingSequence = connectingSequenceEnum.START;
+               chronopicConnectionSequenceDo();
+       }
+
+       private void chronopicConnectionSequenceDo()
+       {
+               //0 print sequence
+               LogB.Information("SEQUENCE: " + connectingSequence.ToString());
+
+               //1 check if need to end sequence or go to second chronopic
+               if (connectingSequence == connectingSequenceEnum.END)
+               {
+                       if(connectAnother)
+                       {
+                               System.Threading.Thread.Sleep(250);
+                               crpDoing = crpMultiList[1];
+                               connectingSequence = connectingSequenceEnum.START;
+                               connectAnother = false;
+                               connectNum = 2;
+                               chronopicConnectionSequenceDo();
+                               return;
+                       } else {
+                               button_activate_chronopics.Show();
+                               on_button_execute_test_accepted();
+                               return;
+                       }
+               }
+
+               //2 update sequence
+               if(connectingSequence == connectingSequenceEnum.START)
+               {
+                       if(cp2016.IsLastConnectedReal(crpDoing)) {
+                               connectingSequence = connectingSequenceEnum.FIRMWAREIFNEEDED;
+                       } else {
+                               connectingSequence = connectingSequenceEnum.CONNECTINGREAL;
+                       }
+                       chronopicConnectionSequenceDo();
+               }
+               else if (connectingSequence == connectingSequenceEnum.CONNECTINGREAL)
+               {
+                       callConnectContactsReal(crpDoing, connectNum);
+                       //this opens a thread and when end goes to chronopicConnectionSequenceDo again
+               }
+               else if (connectingSequence == connectingSequenceEnum.FIRMWAREIFNEEDED)
+               {
+                       changeMultitestFirmwareIfNeeded(connectNum);
+                       //this will call chronopicConnectionSequenceDo if success
+               }
+       }
+
+       private void callConnectContactsReal(ChronopicRegisterPort crp, int numCP)
+       {
+               cp2016.FakeButtonContactsRealDone.Clicked +=
+                       new EventHandler(on_connection_contacts_real_done);
+
+               cp2016.ConnectContactsReal(app1, crp, numCP,
+                               "Press TEST button on Chronopic to stablish initial communication"); //TODO: 
translate this
+       }
+
+       private void on_connection_contacts_real_done (object o, EventArgs args)
+       {
+               cp2016.FakeButtonContactsRealDone.Clicked -=
+                       new EventHandler(on_connection_contacts_real_done);
+
+               if(cp2016.SuccededConnectContactsRealThread)
+               {
+                       LogB.Information("Success at Connecting real! (main GUI)");
+
+                       connectingSequence = connectingSequenceEnum.FIRMWAREIFNEEDED;
+                       chronopicConnectionSequenceDo();
+               } else
+                       LogB.Warning("Failure at Connecting real! (main GUI)");
+       }
+
+}
 
 public class ChronopicPortData
 {


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