[chronojump] watching rfid file actively



commit 647dcb48d9ba46195766befbe55bd918956bc561
Author: Xavier de Blas <xaviblas gmail com>
Date:   Fri Jan 20 18:04:38 2017 +0100

    watching rfid file actively

 glade/app1.glade    |   20 ++++++++++++++++++--
 src/constants.cs    |    1 +
 src/gui/networks.cs |   50 ++++++++++++++++++++++++++++++++++++++++++++++----
 3 files changed, 65 insertions(+), 6 deletions(-)
---
diff --git a/glade/app1.glade b/glade/app1.glade
index dd1c68a..8007e98 100644
--- a/glade/app1.glade
+++ b/glade/app1.glade
@@ -13684,7 +13684,6 @@ Concentric</property>
                                                             <child>
                                                             <widget class="GtkButton" id="button_rfid_read">
                                                             <property name="label">Read RFID</property>
-                                                            <property name="visible">True</property>
                                                             <property name="can_focus">True</property>
                                                             <property name="receives_default">True</property>
                                                             <signal name="clicked" 
handler="on_button_rfid_read_clicked" swapped="no"/>
@@ -13696,6 +13695,20 @@ Concentric</property>
                                                             </packing>
                                                             </child>
                                                             <child>
+                                                            <widget class="GtkButton" id="button_rfid_start">
+                                                            <property name="label">Start RFID</property>
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">True</property>
+                                                            <property name="receives_default">True</property>
+                                                            <signal name="clicked" 
handler="on_button_rfid_start_clicked" swapped="no"/>
+                                                            </widget>
+                                                            <packing>
+                                                            <property name="expand">True</property>
+                                                            <property name="fill">True</property>
+                                                            <property name="position">1</property>
+                                                            </packing>
+                                                            </child>
+                                                            <child>
                                                             <widget class="GtkLabel" id="label_rfid">
                                                             <property name="visible">True</property>
                                                             <property name="can_focus">False</property>
@@ -13703,7 +13716,7 @@ Concentric</property>
                                                             <packing>
                                                             <property name="expand">True</property>
                                                             <property name="fill">True</property>
-                                                            <property name="position">1</property>
+                                                            <property name="position">2</property>
                                                             </packing>
                                                             </child>
                                                           </widget>
@@ -18469,6 +18482,9 @@ Concentric</property>
                                                             <child>
                                                             <placeholder/>
                                                             </child>
+                                                            <child>
+                                                            <placeholder/>
+                                                            </child>
                                                             </widget>
                                                             <packing>
                                                             <property name="expand">False</property>
diff --git a/src/constants.cs b/src/constants.cs
index f750f8c..a1707b3 100644
--- a/src/constants.cs
+++ b/src/constants.cs
@@ -480,6 +480,7 @@ public class Constants
        public static string FileNameLogOld = "log_chronojump_old.txt";
        
        public static string FileNameConfig = "chronojump_config.txt";
+       public static string FilePathRfid = "/tmp/chronojump_rfid.txt";
        
        //30 colors defined
        //see als UtilGtk that's not used by the server
diff --git a/src/gui/networks.cs b/src/gui/networks.cs
index 3d786f6..ab8890d 100644
--- a/src/gui/networks.cs
+++ b/src/gui/networks.cs
@@ -34,6 +34,8 @@ public partial class ChronoJumpWindow
        [Widget] Gtk.HBox hbox_encoder_analyze_signal_or_curves;
                        
        //RFID
+       [Widget] Gtk.HBox hbox_rfid;
+       [Widget] Gtk.Button button_rfid_start;
        [Widget] Gtk.Label label_rfid;
        
        //better raspberry controls
@@ -183,6 +185,8 @@ public partial class ChronoJumpWindow
                        notebook_encoder_sup.Sensitive = false;
                }
                */
+
+               hbox_rfid.Visible = (UtilAll.GetOSEnum() == UtilAll.OperatingSystems.LINUX);
        }
 
        //rfid
@@ -190,12 +194,50 @@ public partial class ChronoJumpWindow
                Networks networks = new Networks();
                networks.Test();
        }
-       void on_button_rfid_read_clicked (object o, EventArgs args) {
-               string file = "/tmp/chronojump_rfid.txt";
+       void on_button_rfid_read_clicked (object o, EventArgs args)
+       {
+               string filePath = Constants.FilePathRfid;
+
+               if(Util.FileExists(filePath))
+                       label_rfid.Text = Util.ReadFile(filePath, true);
+       }
+
+       void on_button_rfid_start_clicked (object o, EventArgs args)
+       {
+               button_rfid_start.Sensitive = false;
+
+               string filePath = Constants.FilePathRfid;
+
+               //create a new FileSystemWatcher and set its properties.
+               FileSystemWatcher watcher = new FileSystemWatcher();
+               watcher.Path = Path.GetDirectoryName(filePath);
+               watcher.Filter = Path.GetFileName(filePath);
+
+               //add event handlers.
+               watcher.Changed += new FileSystemEventHandler(rfid_watcher_changed);
+
+               //start watching
+               watcher.EnableRaisingEvents = true;
 
-               if(Util.FileExists(file))
-                       label_rfid.Text = Util.ReadFile(file, true);
+               //also perform an initial search
+               rfid_read();
        }
 
+       private void rfid_watcher_changed(object source, FileSystemEventArgs e)
+       {
+               rfid_read();
+       }
+
+       private void rfid_read()
+       {
+               string filePath = Constants.FilePathRfid;
+
+               LogB.Information("Changed file: " +  filePath);
+
+               if(Util.FileExists(filePath))
+                       label_rfid.Text = Util.ReadFile(filePath, true);
+       }
+
+
 }
 


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