Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

node_helper.js 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. var NodeHelper = require('node_helper');
  2. var exec = require("child_process").exec;
  3. var myPythonScriptPath = '/home/pi/Desktop/Git/smartMirror/modules/MMM-flick-gestures/monitor.py';
  4. const {PythonShell} = require("python-shell");
  5. const gestureLogMessage = 'Gesture detected:';
  6. let options = {
  7. mode: 'text',
  8. pythonPath: '/usr/bin/python',
  9. pythonOptions: ['-u'], // get print results in real-time
  10. args: []
  11. };
  12. /////////////////
  13. module.exports = NodeHelper.create({
  14. start: function () {
  15. console.log("[GESTURE] Starting...")
  16. this.config = {}
  17. this.gestureSequence = ""
  18. this.commandTimer = null
  19. this.shell = null
  20. },
  21. stop: function () {
  22. console.log("[GESTURE] Stopping...")
  23. if (this.shell) {
  24. this.shell.end()
  25. }
  26. },
  27. socketNotificationReceived: function (noti, payload) {
  28. this.process(payload)
  29. },
  30. powerOff: function() {
  31. console.log('Power off HDMI');
  32. exec("vcgencmd display_power 0", function (error, stdout, stderr) {
  33. if(error!=null)
  34. {
  35. console.log("vcgencmd display_power 0 failed "+JSON.stringify(error));
  36. }
  37. });
  38. },
  39. powerOn: function() {
  40. var me = this;
  41. console.log('Power on HDMI');
  42. exec("vcgencmd display_power 1", function (error, stdout, stderr) {
  43. if(error!=null)
  44. {
  45. console.log("vcgencmd display_power 1 failed "+JSON.stringify(error));
  46. }
  47. });
  48. },
  49. process: function (config) {
  50. var me = this;
  51. var pyshell = new PythonShell(myPythonScriptPath, options);
  52. pyshell.on('message', function (message) {
  53. // relay event to modules
  54. //console.log('checkGesture:', pyshell);
  55. if (message === 'west - east') {
  56. console.log(gestureLogMessage + JSON.stringify(message));
  57. me.sendSocketNotification("PAGE_DECREMENT");
  58. }
  59. else if (message === 'east - west') {
  60. console.log(gestureLogMessage + JSON.stringify(message));
  61. me.sendSocketNotification("PAGE_INCREMENT");
  62. }
  63. else if (message === 'south - north') {
  64. console.log(gestureLogMessage + JSON.stringify(message));
  65. me.powerOn()
  66. }
  67. else if (message === 'north - south') {
  68. console.log(gestureLogMessage + JSON.stringify(message));
  69. me.powerOff()
  70. }
  71. });
  72. pyshell.end(function (err) {
  73. if (err) {
  74. throw err;
  75. }
  76. console.log('pyShell finished with err ' + err);
  77. //console.log('try to restart MMM-Framework'); //reatart if error of pyShell is thrown
  78. //var exec = require('child_process').exec;
  79. //exec('pm2 restart mm',
  80. //function(error, stdout, stderr){
  81. //console.log('stdout: ', stdout);
  82. //console.log('stderr: ', stderr);
  83. //if(error !== null){
  84. //console.log('exec error: ', error);
  85. //}
  86. //}
  87. //)
  88. });
  89. }
  90. })