|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- var NodeHelper = require('node_helper');
- var exec = require("child_process").exec;
-
- var myPythonScriptPath = '/home/pi/Desktop/Git/smartMirror/modules/MMM-flick-gestures/monitor.py';
- const {PythonShell} = require("python-shell");
- const gestureLogMessage = 'Gesture detected:';
-
- let options = {
- mode: 'text',
- pythonPath: '/usr/bin/python',
- pythonOptions: ['-u'], // get print results in real-time
- args: []
- };
-
- /////////////////
-
- module.exports = NodeHelper.create({
-
- start: function () {
- console.log("[GESTURE] Starting...")
- this.config = {}
- this.gestureSequence = ""
- this.commandTimer = null
- this.shell = null
- },
-
- stop: function () {
- console.log("[GESTURE] Stopping...")
- if (this.shell) {
- this.shell.end()
- }
- },
-
- socketNotificationReceived: function (noti, payload) {
- this.process(payload)
- },
-
- powerOff: function() {
- console.log('Power off HDMI');
- exec("vcgencmd display_power 0", function (error, stdout, stderr) {
- if(error!=null)
- {
- console.log("vcgencmd display_power 0 failed "+JSON.stringify(error));
- }
- });
- },
- powerOn: function() {
- var me = this;
- console.log('Power on HDMI');
- exec("vcgencmd display_power 1", function (error, stdout, stderr) {
- if(error!=null)
- {
- console.log("vcgencmd display_power 1 failed "+JSON.stringify(error));
- }
- });
- },
-
- process: function (config) {
- var me = this;
- var pyshell = new PythonShell(myPythonScriptPath, options);
- pyshell.on('message', function (message) {
- // relay event to modules
- //console.log('checkGesture:', pyshell);
-
- if (message === 'west - east') {
- console.log(gestureLogMessage + JSON.stringify(message));
-
- me.sendSocketNotification("PAGE_DECREMENT");
- }
- else if (message === 'east - west') {
- console.log(gestureLogMessage + JSON.stringify(message));
-
- me.sendSocketNotification("PAGE_INCREMENT");
- }
- else if (message === 'south - north') {
- console.log(gestureLogMessage + JSON.stringify(message));
- me.powerOn()
- }
- else if (message === 'north - south') {
-
- console.log(gestureLogMessage + JSON.stringify(message));
- me.powerOff()
- }
- });
-
- pyshell.end(function (err) {
- if (err) {
- throw err;
- }
- console.log('pyShell finished with err ' + err);
-
- //console.log('try to restart MMM-Framework'); //reatart if error of pyShell is thrown
- //var exec = require('child_process').exec;
- //exec('pm2 restart mm',
- //function(error, stdout, stderr){
- //console.log('stdout: ', stdout);
- //console.log('stderr: ', stderr);
- //if(error !== null){
- //console.log('exec error: ', error);
- //}
- //}
- //)
-
-
-
-
- });
-
- }
- })
|