[chronojump] chronojump_config AutodetectPort done



commit af4949666a2026ce3061f0f828d27b78a2c18ca3
Author: Xavier de Blas <xaviblas gmail com>
Date:   Tue Jun 9 16:33:33 2015 +0200

    chronojump_config AutodetectPort done

 src/Makefile.am        |    1 +
 src/chronopic.cs       |  339 --------------------------------------------
 src/chronopicDetect.cs |  364 +++++++++++++++++++++++++++++++++++++++++++++++-
 src/config.cs          |   90 ++++++++++++
 src/gui/chronojump.cs  |    6 +-
 src/gui/networks.cs    |   70 +---------
 6 files changed, 460 insertions(+), 410 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 21e65ee..c7456b2 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -117,6 +117,7 @@ SOURCES = \
        ../chronojump_server/ChronojumpServer.cs\
        AssemblyInfo.cs\
        chronojump.cs\
+       config.cs\
        encoder.cs\
        encoderRProc.cs\
        executeAuto.cs\
diff --git a/src/chronopic.cs b/src/chronopic.cs
index 8b3dbdc..8588b31 100644
--- a/src/chronopic.cs
+++ b/src/chronopic.cs
@@ -400,262 +400,6 @@ public class Chronopic {
 }
 
 
-//methods specific of the Automatic firmware
-//for "automatic" firmware 1.1: debounce can change, get version, port scanning
-public abstract class ChronopicAuto 
-{
-       protected SerialPort sp;
-       protected int sendNum;
-       public bool IsChronopicAuto;
-       protected internal abstract string Communicate();
-       private string str;
-       public string CharToSend = "";
-       public bool IsEncoder = false;
-       public ChronopicAutoDetect.ChronopicType Found;
-
-       private bool make(SerialPort sp) 
-       {
-               this.sp = sp;
-
-               if (sp == null) 
-                       return false;
-               
-               if (sp != null) 
-                       if (sp.IsOpen)
-                               sp.Close(); //close to ensure no bytes are comming
-
-               sp.Open();
-                       
-               if(IsEncoder)
-                       setEncoderBauds();
-
-               str = "";
-               return true;
-       }
-       private void close(SerialPort sp) {
-               sp.Close();
-       }       
-
-
-       //'template method'
-       public string Read(SerialPort sp) 
-       {
-               if ( ! make(sp) )
-                       return "Error sp == null";
-               
-               //bool needToFlush = false;
-               try {
-                       str = Communicate();
-               } catch {
-                       //this.error=ErrorType.Timeout;
-                       LogB.Warning("Error or Timeout. This is not Chronopic-Automatic-Firmware");
-                       str = "Error / not Multitest firmware";
-                       
-                       //needToFlush = true;
-               }
-               
-               /*      
-               if(needToFlush)
-                       flush();
-                       */
-
-               close(sp);
-               
-               return str;
-       }
-       
-       //'template method'
-       public string Write(SerialPort sp, int num) 
-       {
-               if ( ! make(sp) )
-                       return "Error sp == null";
-               
-               sendNum = num;
-               
-               //bool needToFlush = false;
-               try {
-                       str = Communicate();
-               } catch {
-                       //this.error=ErrorType.Timeout;
-                       LogB.Warning("Error or Timeout. This is not Chronopic-Automatic-Firmware");
-                       str = "Error / not Multitest firmware";
-
-                       //needToFlush = true;
-               }
-       
-               /*      
-               if(needToFlush)
-                       flush();
-                       */
-               
-               close(sp);
-               
-               return str;
-       }
-
-       private void setEncoderBauds()
-       {
-               sp.BaudRate = 115200; //encoder, 20MHz
-               LogB.Information("sp.BaudRate = 115200 bauds");
-       }
-
-       /*
-       protected void flush() 
-       {
-               LogB.Information("Flushing");
-               
-               //-- Esperar un tiempo y vaciar buffer
-               Thread.Sleep(500); //ErrorTimeout);
-               
-               byte[] buffer = new byte[256];
-               sp.Read(buffer,0,256); //flush
-               
-               bool success = false;
-               try {
-                       do{
-                               sp.Read(buffer,0,256);
-                               success = true;
-                               LogB.Debug(" spReaded ");
-                       } while(! success);
-               } catch {
-                       LogB.Information("Cannot flush");
-                       return;
-               }
-
-               LogB.Information("Flushed");
-       }
-       */
-}
-
-public class ChronopicAutoCheck : ChronopicAuto
-{
-       protected internal override string Communicate() 
-       {
-               Found = ChronopicAutoDetect.ChronopicType.UNDETECTED;
-               sp.Write("J");
-               IsChronopicAuto = ( (char) sp.ReadByte() == 'J');
-               if (IsChronopicAuto) 
-               {
-                       sp.Write("V");
-                       int major = (char) sp.ReadByte() - '0'; 
-                       sp.ReadByte();          //.
-                       int minor = (char) sp.ReadByte() - '0'; 
-
-                       Found = ChronopicAutoDetect.ChronopicType.NORMAL;
-                       return "Yes! v" + major.ToString() + "." + minor.ToString();
-               }
-
-               return "Please update it\nwith Chronopic-firmwarecord";
-       }
-}
-//only for encoder
-public class ChronopicAutoCheckEncoder : ChronopicAuto
-{
-       protected internal override string Communicate() 
-       {
-               LogB.Information("Communicate start ...");
-               
-               Found = ChronopicAutoDetect.ChronopicType.UNDETECTED;
-       
-               char myByte;
-               for(int i = 0; i < 100; i ++) //try 100 times (usually works on Linux 3-5 try, Mac 8-10, 
Windows don't work < 20... trying bigger numbers)
-               {
-                       LogB.Debug("writting ...");
-       
-                       sp.Write("J");
-                       
-                       LogB.Debug("reading ...");
-
-                       myByte = (char) sp.ReadByte();
-                       
-                       LogB.Debug("readed");
-                       if(myByte != null && myByte.ToString() != "")
-                               LogB.Information(myByte.ToString());
-                       
-                       if(myByte == 'J') {
-                               LogB.Information("Encoder found!");
-
-                               Found = ChronopicAutoDetect.ChronopicType.ENCODER;
-                               return "1";
-                       }
-               }
-               
-               return "0";
-       }
-}
-
-
-public class ChronopicAutoCheckDebounce : ChronopicAuto
-{
-       protected internal override string Communicate() 
-       {
-               sp.Write("a");
-               int debounce = ( sp.ReadByte() - '0' ) * 10;
-               return debounce.ToString() + " ms";
-       }
-}
-
-public class ChronopicAutoChangeDebounce : ChronopicAuto
-{
-       protected internal override string Communicate() 
-       {
-               int debounce = sendNum / 10;            //50 -> 5
-               
-               //byte[] bytesToSend = new byte[2] { 0x62, 0x05 }; //b, 05 //this works
-               byte[] bytesToSend = new byte[2] { 0x62, BitConverter.GetBytes(debounce)[0] }; //b, 05
-               sp.Write(bytesToSend,0,2);
-               
-               return "Changed to " + sendNum.ToString() + " ms";
-       }
-}
-
-public class ChronopicStartReactionTime : ChronopicAuto
-{
-       protected internal override string Communicate() 
-       {
-               try {
-                       sp.Write(CharToSend);
-                       LogB.Information("sending",CharToSend);
-               } catch {
-                       return "ERROR";
-               }
-               return "SUCCESS";
-       }
-}
-
-//like above method but sending the waiting time between each light
-public class ChronopicStartReactionTimeAnimation : ChronopicAuto
-{
-       protected internal override string Communicate() 
-       {
-               try {
-                       byte b;
-                       if(CharToSend == "l")
-                               b = 0x6c;
-                       else if(CharToSend == "f")
-                               b = 0x66;
-                       else if(CharToSend == "d")
-                               b = 0x64;
-                       else if(CharToSend == "D")
-                               b = 0x44;
-                       else if(CharToSend == "i")
-                               b = 0x69;
-                       else if(CharToSend == "I")
-                               b = 0x49;
-                       else
-                               return "ERROR";
-
-                       //values go from 0 to 7
-                       byte[] bytesToSend = new byte[2] { b, BitConverter.GetBytes(sendNum)[0] }; //eg. l, 
05; of f, 05
-                       sp.Write(bytesToSend,0,2);
-
-               } catch {
-                       return "ERROR";
-               }
-               return "SUCCESS";
-       }
-}
-
 public static class ChronopicPorts
 {
        public static string [] GetPorts() {
@@ -668,89 +412,6 @@ public static class ChronopicPorts
        }
 }
 
-public class ChronopicAutoDetect
-{
-       public enum ChronopicType { UNDETECTED, NORMAL, ENCODER }
-       private ChronopicType searched;
-
-       public string Detected; // portname if detected, if not will be ""
-
-       public ChronopicAutoDetect(ChronopicType type)
-       {
-               /*
-                * Try to detect a normal 4MHz Chronopic on a 20MHz encoder fails
-                * but encoder can be used normally
-                * In the other hand, try to detect an encoder on a 4MHz Chronopic fails
-                * but encoder cannot be used until 'reset' or disconnect cable (and can be problems with 
Chronojump GUI)
-                *
-                * So the solution is:
-                * if we are searching encoder, on every port first check if 4MHz connection can be 
stablished, if it's Found, then normal Chronopic is found
-                * if is not Fount, then search for the encoder.
-                *
-                * The only problem is in normal Chronopics with old firmware (without the 'J' read/write
-                * they will not work after trying to be recognised as an encoder, until reset or disconnect 
cable
-                *
-                */
-               this.searched = type;
-
-               //no matter if we are searching for 4MHz or 20MHz (encoder)
-               //first see if 4MHz is connected
-               ChronopicAuto caNormal = new ChronopicAutoCheck();
-               caNormal.IsEncoder = false;    //for the bauds.
-
-               autoDetect(caNormal);
-       }
-
-       private void autoDetect(ChronopicAuto caNormal)
-       {
-               LogB.Information("starting port detection");
-
-               string [] usbSerial = ChronopicPorts.GetPorts();
-
-               foreach(string port in usbSerial) 
-               {
-                       SerialPort sp = new SerialPort(port);
-                       
-                       LogB.Information("searching normal Chronopic at port: ", port);
-                       string readed = caNormal.Read(sp);
-
-                       if(caNormal.Found == ChronopicType.NORMAL) //We found a normal Chronopic
-                       {
-                               if(searched == ChronopicType.NORMAL) //normal Chronopic is what we are 
searching
-                               {
-                                       Detected = port;
-                                       return;
-                               } else {
-                                       /*
-                                        * else: 
-                                        * means that we are searching for an encoder chronopic and found a 
normal
-                                        * so don't try to search for an encoder on that port, because 115200 
bauds will saturate it
-                                        */
-                                       LogB.Information("our goal is to search encoder but found normal 
Chronopic at port: ", port);
-                               }
-                       } else if(searched == ChronopicType.ENCODER) 
-                       {
-                               /*
-                                * we are searching an encoder
-                                * if we arrived here, we know is not a normal chronopic
-                                * then wecan search safely for an encoder here
-                                */
-                               ChronopicAuto caEncoder = new ChronopicAutoCheckEncoder();
-                               caEncoder.IsEncoder = true;    //for the bauds.
-                       
-                               LogB.Information("searching encoder Chronopic at port: ", port);
-                               readed = caEncoder.Read(sp);
-                               if(caEncoder.Found == ChronopicType.ENCODER) 
-                               {
-                                       Detected = port;
-                                       return;
-                               }
-                       }
-               }
-               Detected = "";
-       }
-}
-
 public class ChronopicInit 
 {
        public bool CancelledByUser;
diff --git a/src/chronopicDetect.cs b/src/chronopicDetect.cs
index 1749341..dab574e 100644
--- a/src/chronopicDetect.cs
+++ b/src/chronopicDetect.cs
@@ -35,6 +35,7 @@ public class ChronopicDetect
        private static bool cancel;
        private static bool needToChangeProgressbarText;
        private SerialPort sp;
+       private Config.AutodetectPortEnum configAutoDetect;
 
        public bool Detecting; //used to block closing chronojump window if true
        public string Detected; //readed from chronojump window
@@ -43,12 +44,15 @@ public class ChronopicDetect
        
        public Gtk.Button FakeButtonDone;
        
-       public ChronopicDetect (SerialPort sp, Gtk.ProgressBar progressbar, Gtk.Button button_cancel, 
Gtk.Button button_info)
+       public ChronopicDetect (SerialPort sp, Gtk.ProgressBar progressbar, Gtk.Button button_cancel, 
Gtk.Button button_info,
+                       Config.AutodetectPortEnum configAutoDetect )
        {
                this.sp = sp;
                this.progressbar = progressbar;
                this.button_cancel = button_cancel;
                this.button_info = button_info;
+               this.configAutoDetect = configAutoDetect;
+
                button_cancel.Clicked += new EventHandler(on_button_cancel_clicked);
                button_info.Clicked += new EventHandler(on_button_info_clicked);
 
@@ -87,7 +91,7 @@ public class ChronopicDetect
                //simulateDriverProblem(); //uncomment to check cancel, info buttons behaviour
 
                ChronopicAutoDetect cad = 
-                       new ChronopicAutoDetect(ChronopicAutoDetect.ChronopicType.ENCODER);
+                       new ChronopicAutoDetect(ChronopicAutoDetect.ChronopicType.ENCODER, configAutoDetect);
 
                Detected = cad.Detected;
        }
@@ -97,7 +101,7 @@ public class ChronopicDetect
                //simulateDriverProblem(); //uncomment to check cancel, info buttons behaviour
 
                ChronopicAutoDetect cad = 
-                       new ChronopicAutoDetect(ChronopicAutoDetect.ChronopicType.NORMAL);
+                       new ChronopicAutoDetect(ChronopicAutoDetect.ChronopicType.NORMAL, configAutoDetect);
 
                Detected = cad.Detected;
                
@@ -197,3 +201,357 @@ public class ChronopicDetect
 
        ~ChronopicDetect() {}
 }
+
+public class ChronopicAutoDetect
+{
+       public enum ChronopicType { UNDETECTED, NORMAL, ENCODER }
+       private ChronopicType searched;
+
+       public string Detected; // portname if detected, if not will be ""
+       private Config.AutodetectPortEnum configAutoDetect;
+
+       public ChronopicAutoDetect(ChronopicType type, Config.AutodetectPortEnum configAutoDetect)
+       {
+               /*
+                * Try to detect a normal 4MHz Chronopic on a 20MHz encoder fails
+                * but encoder can be used normally
+                * In the other hand, try to detect an encoder on a 4MHz Chronopic fails
+                * but encoder cannot be used until 'reset' or disconnect cable (and can be problems with 
Chronojump GUI)
+                *
+                * So the solution is:
+                * if we are searching encoder, on every port first check if 4MHz connection can be 
stablished, if it's Found, then normal Chronopic is found
+                * if is not Fount, then search for the encoder.
+                *
+                * The only problem is in normal Chronopics with old firmware (without the 'J' read/write
+                * they will not work after trying to be recognised as an encoder, until reset or disconnect 
cable
+                *
+                */
+               this.searched = type;
+               this.configAutoDetect = configAutoDetect;
+               
+               if(configAutoDetect == Config.AutodetectPortEnum.INACTIVE) {
+                       return;
+                       Detected = "";
+               }
+
+               //no matter if we are searching for 4MHz or 20MHz (encoder)
+               //first see if 4MHz is connected
+               ChronopicAuto caNormal = new ChronopicAutoCheck();
+               caNormal.IsEncoder = false;    //for the bauds.
+
+               autoDetect(caNormal);
+       }
+
+       private void autoDetect(ChronopicAuto caNormal)
+       {
+               LogB.Information("starting port detection");
+
+               string [] usbSerial = ChronopicPorts.GetPorts();
+
+               bool first = true;
+               foreach(string port in usbSerial) 
+               {
+                       if(configAutoDetect == Config.AutodetectPortEnum.DISCARDFIRST && first) {
+                               first = false;
+                               LogB.Warning("Discarded port = ", port);
+                               continue;
+                       }
+
+                       SerialPort sp = new SerialPort(port);
+                       
+                       LogB.Information("searching normal Chronopic at port: ", port);
+                       string readed = caNormal.Read(sp);
+
+                       if(caNormal.Found == ChronopicType.NORMAL) //We found a normal Chronopic
+                       {
+                               if(searched == ChronopicType.NORMAL) //normal Chronopic is what we are 
searching
+                               {
+                                       Detected = port;
+                                       return;
+                               } else {
+                                       /*
+                                        * else: 
+                                        * means that we are searching for an encoder chronopic and found a 
normal
+                                        * so don't try to search for an encoder on that port, because 115200 
bauds will saturate it
+                                        */
+                                       LogB.Information("our goal is to search encoder but found normal 
Chronopic at port: ", port);
+                               }
+                       } else if(searched == ChronopicType.ENCODER) 
+                       {
+                               /*
+                                * we are searching an encoder
+                                * if we arrived here, we know is not a normal chronopic
+                                * then wecan search safely for an encoder here
+                                */
+                               ChronopicAuto caEncoder = new ChronopicAutoCheckEncoder();
+                               caEncoder.IsEncoder = true;    //for the bauds.
+                       
+                               LogB.Information("searching encoder Chronopic at port: ", port);
+                               readed = caEncoder.Read(sp);
+                               if(caEncoder.Found == ChronopicType.ENCODER) 
+                               {
+                                       Detected = port;
+                                       return;
+                               }
+                       }
+               }
+               Detected = "";
+       }
+}
+
+//methods specific of the Automatic firmware
+//for "automatic" firmware 1.1: debounce can change, get version, port scanning
+public abstract class ChronopicAuto 
+{
+       protected SerialPort sp;
+       protected int sendNum;
+       public bool IsChronopicAuto;
+       protected internal abstract string Communicate();
+       private string str;
+       public string CharToSend = "";
+       public bool IsEncoder = false;
+       public ChronopicAutoDetect.ChronopicType Found;
+
+       private bool make(SerialPort sp) 
+       {
+               this.sp = sp;
+
+               if (sp == null) 
+                       return false;
+               
+               if (sp != null) 
+                       if (sp.IsOpen)
+                               sp.Close(); //close to ensure no bytes are comming
+
+               sp.Open();
+                       
+               if(IsEncoder)
+                       setEncoderBauds();
+
+               str = "";
+               return true;
+       }
+       private void close(SerialPort sp) {
+               sp.Close();
+       }       
+
+
+       //'template method'
+       public string Read(SerialPort sp) 
+       {
+               if ( ! make(sp) )
+                       return "Error sp == null";
+               
+               //bool needToFlush = false;
+               try {
+                       str = Communicate();
+               } catch {
+                       //this.error=ErrorType.Timeout;
+                       LogB.Warning("Error or Timeout. This is not Chronopic-Automatic-Firmware");
+                       str = "Error / not Multitest firmware";
+                       
+                       //needToFlush = true;
+               }
+               
+               /*      
+               if(needToFlush)
+                       flush();
+                       */
+
+               close(sp);
+               
+               return str;
+       }
+       
+       //'template method'
+       public string Write(SerialPort sp, int num) 
+       {
+               if ( ! make(sp) )
+                       return "Error sp == null";
+               
+               sendNum = num;
+               
+               //bool needToFlush = false;
+               try {
+                       str = Communicate();
+               } catch {
+                       //this.error=ErrorType.Timeout;
+                       LogB.Warning("Error or Timeout. This is not Chronopic-Automatic-Firmware");
+                       str = "Error / not Multitest firmware";
+
+                       //needToFlush = true;
+               }
+       
+               /*      
+               if(needToFlush)
+                       flush();
+                       */
+               
+               close(sp);
+               
+               return str;
+       }
+
+       private void setEncoderBauds()
+       {
+               sp.BaudRate = 115200; //encoder, 20MHz
+               LogB.Information("sp.BaudRate = 115200 bauds");
+       }
+
+       /*
+       protected void flush() 
+       {
+               LogB.Information("Flushing");
+               
+               //-- Esperar un tiempo y vaciar buffer
+               Thread.Sleep(500); //ErrorTimeout);
+               
+               byte[] buffer = new byte[256];
+               sp.Read(buffer,0,256); //flush
+               
+               bool success = false;
+               try {
+                       do{
+                               sp.Read(buffer,0,256);
+                               success = true;
+                               LogB.Debug(" spReaded ");
+                       } while(! success);
+               } catch {
+                       LogB.Information("Cannot flush");
+                       return;
+               }
+
+               LogB.Information("Flushed");
+       }
+       */
+}
+
+public class ChronopicAutoCheck : ChronopicAuto
+{
+       protected internal override string Communicate() 
+       {
+               Found = ChronopicAutoDetect.ChronopicType.UNDETECTED;
+               sp.Write("J");
+               IsChronopicAuto = ( (char) sp.ReadByte() == 'J');
+               if (IsChronopicAuto) 
+               {
+                       sp.Write("V");
+                       int major = (char) sp.ReadByte() - '0'; 
+                       sp.ReadByte();          //.
+                       int minor = (char) sp.ReadByte() - '0'; 
+
+                       Found = ChronopicAutoDetect.ChronopicType.NORMAL;
+                       return "Yes! v" + major.ToString() + "." + minor.ToString();
+               }
+
+               return "Please update it\nwith Chronopic-firmwarecord";
+       }
+}
+//only for encoder
+public class ChronopicAutoCheckEncoder : ChronopicAuto
+{
+       protected internal override string Communicate() 
+       {
+               LogB.Information("Communicate start ...");
+               
+               Found = ChronopicAutoDetect.ChronopicType.UNDETECTED;
+       
+               char myByte;
+               for(int i = 0; i < 100; i ++) //try 100 times (usually works on Linux 3-5 try, Mac 8-10, 
Windows don't work < 20... trying bigger numbers)
+               {
+                       LogB.Debug("writting ...");
+       
+                       sp.Write("J");
+                       
+                       LogB.Debug("reading ...");
+
+                       myByte = (char) sp.ReadByte();
+                       
+                       LogB.Debug("readed");
+                       if(myByte != null && myByte.ToString() != "")
+                               LogB.Information(myByte.ToString());
+                       
+                       if(myByte == 'J') {
+                               LogB.Information("Encoder found!");
+
+                               Found = ChronopicAutoDetect.ChronopicType.ENCODER;
+                               return "1";
+                       }
+               }
+               
+               return "0";
+       }
+}
+
+
+public class ChronopicAutoCheckDebounce : ChronopicAuto
+{
+       protected internal override string Communicate() 
+       {
+               sp.Write("a");
+               int debounce = ( sp.ReadByte() - '0' ) * 10;
+               return debounce.ToString() + " ms";
+       }
+}
+
+public class ChronopicAutoChangeDebounce : ChronopicAuto
+{
+       protected internal override string Communicate() 
+       {
+               int debounce = sendNum / 10;            //50 -> 5
+               
+               //byte[] bytesToSend = new byte[2] { 0x62, 0x05 }; //b, 05 //this works
+               byte[] bytesToSend = new byte[2] { 0x62, BitConverter.GetBytes(debounce)[0] }; //b, 05
+               sp.Write(bytesToSend,0,2);
+               
+               return "Changed to " + sendNum.ToString() + " ms";
+       }
+}
+
+public class ChronopicStartReactionTime : ChronopicAuto
+{
+       protected internal override string Communicate() 
+       {
+               try {
+                       sp.Write(CharToSend);
+                       LogB.Information("sending",CharToSend);
+               } catch {
+                       return "ERROR";
+               }
+               return "SUCCESS";
+       }
+}
+
+//like above method but sending the waiting time between each light
+public class ChronopicStartReactionTimeAnimation : ChronopicAuto
+{
+       protected internal override string Communicate() 
+       {
+               try {
+                       byte b;
+                       if(CharToSend == "l")
+                               b = 0x6c;
+                       else if(CharToSend == "f")
+                               b = 0x66;
+                       else if(CharToSend == "d")
+                               b = 0x64;
+                       else if(CharToSend == "D")
+                               b = 0x44;
+                       else if(CharToSend == "i")
+                               b = 0x69;
+                       else if(CharToSend == "I")
+                               b = 0x49;
+                       else
+                               return "ERROR";
+
+                       //values go from 0 to 7
+                       byte[] bytesToSend = new byte[2] { b, BitConverter.GetBytes(sendNum)[0] }; //eg. l, 
05; of f, 05
+                       sp.Write(bytesToSend,0,2);
+
+               } catch {
+                       return "ERROR";
+               }
+               return "SUCCESS";
+       }
+}
+
diff --git a/src/config.cs b/src/config.cs
new file mode 100644
index 0000000..2bd7d35
--- /dev/null
+++ b/src/config.cs
@@ -0,0 +1,90 @@
+/*
+ * This file is part of ChronoJump
+ *
+ * Chronojump is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or   
+ *    (at your option) any later version.
+ *    
+ * Chronojump is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
+ *    GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Copyright (C) 2004-2015   Xavier de Blas <xaviblas gmail com> 
+ */
+
+using System;
+using System.IO;
+
+
+public class Config
+{
+       public enum AutodetectPortEnum { ACTIVE, DISCARDFIRST, INACTIVE }
+
+       public bool Maximized;
+       public bool CustomButtons;
+       public bool UseVideo;
+       public AutodetectPortEnum AutodetectPort;
+       public string RunScriptOnExit;
+
+       public Config()
+       {
+               Maximized = false;
+               CustomButtons = false;
+               UseVideo = true;
+               AutodetectPort = AutodetectPortEnum.ACTIVE;
+               RunScriptOnExit = "";
+       }
+
+       public void Read()
+       {
+               string contents = Util.ReadFile(UtilAll.GetConfigFileName(), false);
+               if (contents != null && contents != "") 
+               {
+                       string line;
+                       using (StringReader reader = new StringReader (contents)) {
+                               do {
+                                       line = reader.ReadLine ();
+
+                                       if (line == null)
+                                               break;
+                                       if (line == "" || line[0] == '#')
+                                               continue;
+
+                                       string [] parts = line.Split(new char[] {'='});
+                                       if(parts.Length != 2)
+                                               continue;
+
+                                       if(parts[0] == "Maximized" && Util.StringToBool(parts[1]))
+                                               Maximized = true;
+                                       else if(parts[0] == "CustomButtons" && Util.StringToBool(parts[1]))
+                                               CustomButtons = true;
+                                       else if(parts[0] == "UseVideo" && ! Util.StringToBool(parts[1]))
+                                               UseVideo = false;
+                                       else if(parts[0] == "AutodetectPort" && 
Enum.IsDefined(typeof(AutodetectPortEnum), parts[1]))
+                                               AutodetectPort = (AutodetectPortEnum) 
+                                                       Enum.Parse(typeof(AutodetectPortEnum), parts[1]);
+                                       else if(parts[0] == "RunScriptOnExit" && parts[1] != "")
+                                               RunScriptOnExit = parts[1];
+                               } while(true);
+                       }
+               }
+       }
+
+       public override string ToString() {
+               return(
+                               "Maximized = " + Maximized.ToString() + "\n" +
+                               "CustomButtons = " + CustomButtons.ToString() + "\n" +
+                               "UseVideo = " + UseVideo.ToString() + "\n" +
+                               "AutodetectPort = " + AutodetectPort.ToString() + "\n" +
+                               "RunScriptOnExit = " + RunScriptOnExit.ToString() + "\n"
+                     );
+       }
+
+       ~Config() {}
+}
diff --git a/src/gui/chronojump.cs b/src/gui/chronojump.cs
index bf05009..727ad1d 100644
--- a/src/gui/chronojump.cs
+++ b/src/gui/chronojump.cs
@@ -2931,7 +2931,8 @@ public partial class ChronoJumpWindow
                                        chronopicWin.SP,
                                        progressbar_chronopic_encoder_detecting, 
                                        button_chronopic_encoder_detecting_cancel,
-                                       button_chronopic_encoder_detecting_info
+                                       button_chronopic_encoder_detecting_info,
+                                       configAutodetectPort
                                        );
                        
                        cpDetect.Detect("ENCODER");
@@ -2952,7 +2953,8 @@ public partial class ChronoJumpWindow
                                        chronopicWin.SP,
                                        progressbar_chronopic_detecting, 
                                        button_chronopic_detecting_cancel,
-                                       button_chronopic_detecting_info
+                                       button_chronopic_detecting_info,
+                                       configAutodetectPort
                                        );
                        
                        cpDetect.Detect("NORMAL");
diff --git a/src/gui/networks.cs b/src/gui/networks.cs
index 43d963c..22aea28 100644
--- a/src/gui/networks.cs
+++ b/src/gui/networks.cs
@@ -40,6 +40,8 @@ public partial class ChronoJumpWindow
        [Widget] Gtk.Box hbox_encoder_capture_extra_mass_raspberry;
 
        private bool useVideo = true;
+       private Config.AutodetectPortEnum configAutodetectPort = Config.AutodetectPortEnum.ACTIVE;
+
        private enum linuxTypeEnum { NOTLINUX, LINUX, RASPBERRY, NETWORKS }
        private linuxTypeEnum linuxType;
 
@@ -62,6 +64,8 @@ public partial class ChronoJumpWindow
                        alignment_video_encoder.Visible = false;
                }
 
+               configAutodetectPort = config.AutodetectPort;
+
                //TODO
                //AutodetectPort
                //RunScriptOnExit
@@ -104,69 +108,3 @@ public partial class ChronoJumpWindow
 
 }
 
-public class Config
-{
-       public enum AutodetectPortEnum { ACTIVE, DISCARDFIRST, INACTIVE }
-
-       public bool Maximized;
-       public bool CustomButtons;
-       public bool UseVideo;
-       public AutodetectPortEnum AutodetectPort;
-       public string RunScriptOnExit;
-
-       public Config()
-       {
-               Maximized = false;
-               CustomButtons = false;
-               UseVideo = true;
-               AutodetectPort = AutodetectPortEnum.ACTIVE;
-               RunScriptOnExit = "";
-       }
-
-       public void Read()
-       {
-               string contents = Util.ReadFile(UtilAll.GetConfigFileName(), false);
-               if (contents != null && contents != "") 
-               {
-                       string line;
-                       using (StringReader reader = new StringReader (contents)) {
-                               do {
-                                       line = reader.ReadLine ();
-
-                                       if (line == null)
-                                               break;
-                                       if (line == "" || line[0] == '#')
-                                               continue;
-
-                                       string [] parts = line.Split(new char[] {'='});
-                                       if(parts.Length != 2)
-                                               continue;
-
-                                       if(parts[0] == "Maximized" && Util.StringToBool(parts[1]))
-                                               Maximized = true;
-                                       else if(parts[0] == "CustomButtons" && Util.StringToBool(parts[1]))
-                                               CustomButtons = true;
-                                       else if(parts[0] == "UseVideo" && ! Util.StringToBool(parts[1]))
-                                               UseVideo = false;
-                                       else if(parts[0] == "AutodetectPort" && 
Enum.IsDefined(typeof(AutodetectPortEnum), parts[1]))
-                                               AutodetectPort = (AutodetectPortEnum) 
-                                                       Enum.Parse(typeof(AutodetectPortEnum), parts[1]);
-                                       else if(parts[0] == "RunScriptOnExit" && parts[1] != "")
-                                               RunScriptOnExit = parts[1];
-                               } while(true);
-                       }
-               }
-       }
-
-       public override string ToString() {
-               return(
-                               "Maximized = " + Maximized.ToString() + "\n" +
-                               "CustomButtons = " + CustomButtons.ToString() + "\n" +
-                               "UseVideo = " + UseVideo.ToString() + "\n" +
-                               "AutodetectPort = " + AutodetectPort.ToString() + "\n" +
-                               "RunScriptOnExit = " + RunScriptOnExit.ToString() + "\n"
-                     );
-       }
-
-       ~Config() {}
-}


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