[chronojump] chronopicRegister updates port



commit 16cd5e820263a3ca841782b2624f11c564751a55
Author: Xavier de Blas <xaviblas gmail com>
Date:   Mon Oct 3 21:19:57 2016 +0200

    chronopicRegister updates port

 src/chronopicRegister.cs |   47 ++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 41 insertions(+), 6 deletions(-)
---
diff --git a/src/chronopicRegister.cs b/src/chronopicRegister.cs
index dff4bbb..69e3e5b 100644
--- a/src/chronopicRegister.cs
+++ b/src/chronopicRegister.cs
@@ -97,7 +97,22 @@ public class ChronopicRegisterPortList
                L.Add(crp);
        }
 
-       public void Update (ChronopicRegisterPort crp, ChronopicRegisterPort.Types newType)
+       //only call this if Exists
+       public bool PortChanged(ChronopicRegisterPort crp)
+       {
+               foreach(ChronopicRegisterPort c in L) {
+                       if(c.SerialNumber == crp.SerialNumber) {
+                               if(c.Port == crp.Port)
+                                       return false;
+
+                               return true;
+                       }
+               }
+
+               return true;
+       }
+
+       public void UpdateType (ChronopicRegisterPort crp, ChronopicRegisterPort.Types newType)
        {
                //Update SQL
                SqliteChronopicRegister.Update(false, crp, newType);
@@ -110,6 +125,15 @@ public class ChronopicRegisterPortList
                        }
                }
        }
+       public void UpdatePort (ChronopicRegisterPort crp, string newPort)
+       {
+               foreach(ChronopicRegisterPort c in L) {
+                       if(c.SerialNumber == crp.SerialNumber) {
+                               c.Port = newPort;
+                               break;
+                       }
+               }
+       }
 
        public void Delete (ChronopicRegisterPort crp)
        {
@@ -152,7 +176,6 @@ public abstract class ChronopicRegister
                createList();
 
                //3 print the registered ports on SQL (debug)
-               crpl = new ChronopicRegisterPortList();
                crpl.Print();
        }
 
@@ -169,9 +192,8 @@ public abstract class ChronopicRegister
 
                        LogB.Information(crp.ToString());
 
-                       //2 add to registered list (add also on database)
-                       if(crp.FTDI && ! crpl.Exists(crp))
-                               crpl.Add(crp);
+                       //2 add/update registered list
+                       registerAddOrUpdate(crp);
                }
        }
 
@@ -187,6 +209,17 @@ public abstract class ChronopicRegister
 
                return l;
        }
+       
+       protected void registerAddOrUpdate(ChronopicRegisterPort crp)
+       {
+               if(! crp.FTDI)
+                       return;
+
+               if (! crpl.Exists(crp))
+                       crpl.Add(crp);
+               else if(crpl.PortChanged(crp))
+                       crpl.UpdatePort(crp, crp.Port);
+       }
 
        //unused
        protected virtual ChronopicRegisterPort readFTDI(ChronopicRegisterPort crp)
@@ -364,8 +397,10 @@ public class ChronopicRegisterWindows : ChronopicRegister
                                crp.FTDI = true;
                                crp.SerialNumber = ftdiDeviceList[i].SerialNumber.ToString();
                                crp.Type = ChronopicRegisterPort.Types.UNKNOWN;
+                               
+                               LogB.Information(string.Format("crp: " + crp.ToString()));
 
-                               crpl.Add(crp);
+                               registerAddOrUpdate(crp);
                        }
                }
        }


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