[chronojump] RFID class can manage WaitingAdmin event



commit d4439f1a7a8609aa1a56523176a85d8ad9fcc6e5
Author: Xavier de Blas <xaviblas gmail com>
Date:   Fri Jul 19 11:47:51 2019 +0200

    RFID class can manage WaitingAdmin event

 src/RFID.cs | 74 +++++++++++++++++++++++++++++++++++++++++++++++++------------
 1 file changed, 60 insertions(+), 14 deletions(-)
---
diff --git a/src/RFID.cs b/src/RFID.cs
index f2bc00a6..e737f16c 100644
--- a/src/RFID.cs
+++ b/src/RFID.cs
@@ -18,6 +18,7 @@
 
 using System;
 using System.Collections.Generic; //List<T>
+using System.Diagnostics;  //Stopwatch
 using System.IO.Ports;
 using System.Threading;
 using Gtk;
@@ -26,11 +27,17 @@ using Gtk;
 public class RFID
 {
        public string Captured;
+
+       private bool waitingAdmin;
+       private string adminRFID;
+       private Stopwatch swWaitingAdminDetected; //count when detected 3 seconds to not detect again
+
        private bool stop;
        //public event EventHandler ChangedEvent; //raised when change RFID vaues
        private SerialPort port;
        private string portName;
        private Gtk.Button fakeButtonChange;
+       private Gtk.Button fakeButtonAdminDetected;
        private Gtk.Button fakeButtonReopenDialog;
        private Gtk.Button fakeButtonDisconnected;
 
@@ -39,8 +46,13 @@ public class RFID
                this.portName = portName;
                stop = false;
                fakeButtonChange = new Button();
+               fakeButtonAdminDetected = new Button();
                fakeButtonReopenDialog = new Button();
                fakeButtonDisconnected = new Button();
+
+               waitingAdmin = false;
+               adminRFID = "";
+               swWaitingAdminDetected = new Stopwatch();
        }
        
        public void Start()
@@ -91,21 +103,44 @@ public class RFID
                                {
                                        str = str.Substring(1, str.Length -2);
 
-                                       if(str != lastRFID)
+                                       if(waitingAdmin && adminRFID != "")
                                        {
-                                               Captured = str;
-
-                                               //Firing the event
-                                               fakeButtonChange.Click();
-                                               /*
-                                                  EventHandler handler = ChangedEvent;
-                                                  if (handler != null)
-                                                  handler(this, new EventArgs());
-                                                  */
-                                               lastRFID = str;
-                                       } else {
-                                               //Firing the event
-                                               fakeButtonReopenDialog.Click();
+                                               if(str == adminRFID)
+                                               {
+                                                       if(! swWaitingAdminDetected.IsRunning)
+                                                       {
+                                                               //start stopwatch
+                                                               swWaitingAdminDetected.Start();
+
+                                                               //fire special signal
+                                                               fakeButtonAdminDetected.Click();
+                                                       } else {
+                                                               //do not allow any other rfid in 2 seconds
+                                                               if(swWaitingAdminDetected.ElapsedMilliseconds 
2000)
+                                                               {
+                                                                       swWaitingAdminDetected.Stop();
+                                                                       waitingAdmin = false;
+                                                               }
+                                                       }
+                                               }
+                                       }
+                                       else {
+                                               if(str != lastRFID)
+                                               {
+                                                       Captured = str;
+
+                                                       //Firing the event
+                                                       fakeButtonChange.Click();
+                                                       /*
+                                                          EventHandler handler = ChangedEvent;
+                                                          if (handler != null)
+                                                          handler(this, new EventArgs());
+                                                          */
+                                                       lastRFID = str;
+                                               } else {
+                                                       //Firing the event
+                                                       fakeButtonReopenDialog.Click();
+                                               }
                                        }
                                }
                        }
@@ -120,6 +155,12 @@ public class RFID
                stop = true;
        }
 
+       public void WaitingAdminStart(string adminRFID)
+       {
+               waitingAdmin = true;
+               this.adminRFID = adminRFID;
+       }
+
        private bool findRFIDPort(List<string> l)
        {
                foreach(string p in l)
@@ -167,6 +208,11 @@ public class RFID
                get { return fakeButtonChange; }
        }
 
+       public Gtk.Button FakeButtonAdminDetected
+       {
+               get { return fakeButtonAdminDetected; }
+       }
+
        public Gtk.Button FakeButtonReopenDialog
        {
                get { return fakeButtonReopenDialog; }


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