[chronojump] on Compujump wake up screen on capture encoder and on rfid



commit bfe7c38d81db8999863dc90cfd3aa6623b4c805e
Author: Xavier de Blas <xaviblas gmail com>
Date:   Mon Jan 30 17:07:13 2017 +0100

    on Compujump wake up screen on capture encoder and on rfid

 src/gui/encoder.cs  |    4 ++++
 src/gui/networks.cs |    4 ++++
 src/networks.cs     |   46 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 54 insertions(+), 0 deletions(-)
---
diff --git a/src/gui/encoder.cs b/src/gui/encoder.cs
index 0a7e0ec..77833e8 100644
--- a/src/gui/encoder.cs
+++ b/src/gui/encoder.cs
@@ -647,6 +647,10 @@ public partial class ChronoJumpWindow
 //             if(eCaptureInertialBG != null)
 //                     eCaptureInertialBG.Finish();
 
+               //if compujump, wakeup screen if it's off
+               if(configChronojump.Compujump == true)
+                       Networks.WakeUpRaspberryIfNeeded();
+
                maxPowerIntersessionOnCapture = findMaxPowerIntersession();
                //LogB.Information("maxPower: " + maxPowerIntersessionOnCapture);
 
diff --git a/src/gui/networks.cs b/src/gui/networks.cs
index 095f0be..1ea0b20 100644
--- a/src/gui/networks.cs
+++ b/src/gui/networks.cs
@@ -296,6 +296,10 @@ public partial class ChronoJumpWindow
        private void rfid_watcher_changed(object source, FileSystemEventArgs e)
        {
                rfid_read();
+
+               //if compujump, wakeup screen if it's off
+               if(configChronojump.Compujump == true)
+                       Networks.WakeUpRaspberryIfNeeded();
        }
 
        private void rfid_read()
diff --git a/src/networks.cs b/src/networks.cs
index 69b5400..e8630eb 100644
--- a/src/networks.cs
+++ b/src/networks.cs
@@ -20,6 +20,7 @@
 
 using System;
 using System.Collections.Generic; //List<T>
+using System.IO; //StringReader
        
 public class Networks
 {
@@ -51,4 +52,49 @@ public class Networks
 
                return (total);
        }
+
+       public static void WakeUpRaspberryIfNeeded()
+       {
+               string executable = "xset";
+               List<string> parameters = new List<string>();
+
+               parameters.Insert (0, "-q");
+               ExecuteProcess.Result execute_result = ExecuteProcess.run (executable, parameters);
+
+               bool on = screenIsOn(execute_result.stdout);
+               LogB.Information("Screen is on?" + on.ToString());
+
+               if(! on) {
+                       //xset -display :0 dpms force on
+                       parameters = new List<string>();
+                       parameters.Insert (0, "-display");
+                       parameters.Insert (1, ":0");
+                       parameters.Insert (2, "dpms");
+                       parameters.Insert (3, "force");
+                       parameters.Insert (4, "on");
+               }
+
+               execute_result = ExecuteProcess.run (executable, parameters);
+               LogB.Information("Result = " + execute_result.stdout);
+       }
+
+       private static bool screenIsOn(string contents)
+       {
+               LogB.Information(contents);
+               string line;
+               using (StringReader reader = new StringReader (contents)) {
+                       do {
+                               line = reader.ReadLine ();
+
+                               if (line == null)
+                                       break;
+
+                               if(line.StartsWith("  Monitor is On"))
+                                       return true;
+                               else if(line.StartsWith("  Monitor is Off"))
+                                       return false;
+                       } while(true);
+               }
+               return true; //by default screen is on. If detection is wrong user can touch screen
+       }
 }


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