From 7f61d96d603d4c6c243779fb00d5260f01324394 Mon Sep 17 00:00:00 2001 From: framboise-pi <55726262+framboise-pi@users.noreply.github.com> Date: Mon, 8 Jun 2020 06:32:44 +0200 Subject: [PATCH] Add files via upload --- MMM-MySenseHat.js | 42 ++++++++--- node_helper.js | 177 ++++++++++++++++++++++++++++++++++++++++------ package-lock.json | 5 ++ package.json | 3 +- 4 files changed, 196 insertions(+), 31 deletions(-) diff --git a/MMM-MySenseHat.js b/MMM-MySenseHat.js index 6095ff2..f00b271 100644 --- a/MMM-MySenseHat.js +++ b/MMM-MySenseHat.js @@ -10,9 +10,13 @@ Module.register("MMM-MySenseHat",{ // CONFIG defaults: { - read_interval: 500,//ms - slide_interval: 10000,//ms - slide_display: 5000,//ms + read_interval: 500,//ms interval on magicmirror module + slide_interval: 20000,//ms as it refreshes clock/time : try keep <30 seconds) + display_start_LED: true, + use_SenseHat_LED: true, + random_mode: true,// for future - on false, change mode with sensehatjoystick + show_all_sensors: true, + fontsize: "normal",//small | normal | large | xlarge }, // DATA DISPLAY STARTUP VALUE @@ -30,15 +34,35 @@ Module.register("MMM-MySenseHat",{ compy: "-N/A-", compz: "-N/A-" }, + //VARIABLES USED + round: 0,//pixelart|clock|temp value|weather|... // CSS getStyles: function () { return ["MMM-MySenseHat.css", "font-awesome.css"]; }, // start: function() { - this.sendSocketNotification("MMM_MySenseHat_LoadingTxt"); + var self = this; + if (this.config.display_start_LED == true) this.sendSocketNotification("MMM_MySenseHat_LoadingTxt"); this.askdata(); - this.pixelslide(); + if (this.config.use_SenseHat_LED == true && this.config.random_mode == true) self.autochangemode(); + }, + //AUTO CHANGE MODE + autochangemode: function () { + var self = this; + setInterval(function() { + self.round = self.round + 1; + if (self.round == 1 ) + { + self.pixelslide(); + } + if (self.round == 2 ) + { + self.sendSocketNotification("MMM_MySenseHat_Clock"); + self.round = 0; + } + }, self.config.slide_interval); + }, //ASK FOR SENSORS DATA askdata: function () { @@ -50,10 +74,7 @@ Module.register("MMM-MySenseHat",{ }, //SLIDESHOW LED pixelslide: function () { - var self = this; - setInterval(function() { - self.sendSocketNotification("MMM_MySenseHat_PixelSlide"); - }, self.config.slide_interval); + this.sendSocketNotification("MMM_MySenseHat_PixelSlide"); }, // socketNotificationReceived: function (notification, payload) { @@ -79,14 +100,17 @@ Module.register("MMM-MySenseHat",{ //#end socketNotif SensorsData getDom: function() { var wrapper = document.createElement("div"); + wrapper.className = this.config.classes ? this.config.classes : "thin " + this.config.fontsize + " bright pre-line"; ihtml = "
" ihtml += "
humidité " + this.SensorsData.humi + " %
" ihtml += "
température " + this.SensorsData.temp + " °C
" ihtml += "
pression " + this.SensorsData.press + " mbar
" + if (this.config.show_all_sensors) { ihtml += "
compas " + this.SensorsData.compx + "X | " + this.SensorsData.compy + "Y | " + this.SensorsData.compz + "Z µT
" //ihtml += "
fusion " + this.SensorsData.fusix + "X | " + this.SensorsData.fusiy + "Y | " + this.SensorsData.fusiz + "Z
" ihtml += "
gyroscope " + this.SensorsData.gyrox + "X | " + this.SensorsData.gyroy + "Y | " + this.SensorsData.gyroz + "Z rad/sec
" ihtml += "
accélération " + this.SensorsData.accex + "X | " + this.SensorsData.accey + "Y | " + this.SensorsData.accez + "Z G
" + } ihtml += "
" wrapper.innerHTML = ihtml return wrapper diff --git a/node_helper.js b/node_helper.js index 2f6905f..2c0608a 100644 --- a/node_helper.js +++ b/node_helper.js @@ -10,31 +10,141 @@ const request = require('request'); const sense = require('sense-hat-led').sync; const imu = require('node-sense-hat').Imu; const IMU = new imu.IMU(); -// ROTATION +var Random = require('java-random'); +//var fs = require('fs'); +// ORIENTATION sense.clear(); sense.setRotation(270); sense.lowLight = true; -//COLORS -const RR = [255, 0, 0]; -const GG = [0, 255, 0]; -const BB = [0, 0, 255]; -const OO = [0, 0, 0]; + +color1 = [255,0,0]; +color2 = [0,255,0,0]; +// + // module.exports = NodeHelper.create({ start: function() { }, +// + clockclock: function(payload){ + var self = this; + + num_a = parseInt(payload[0]); + num_b = parseInt(payload[1]); + num_c = parseInt(payload[2]); + num_d = parseInt(payload[3]); + + if (!num_b) { num_b = num_a; num_a = 0; } + if (!num_d) { num_d = num_c; num_c = 0; } + + num_1 = this.getdigit(num_a,1); + num_2 = this.getdigit(num_b,2); + num_3 = this.getdigit(num_c,3); + num_4 = this.getdigit(num_d,4); + + rowz_1a = num_1[0]; + rowz_1b = num_1[1]; + rowz_1c = num_1[2]; + rowz_1d = num_1[3]; + + rowz_2a = num_2[0]; + rowz_2b = num_2[1]; + rowz_2c = num_2[2]; + rowz_2d = num_2[3]; + + rowz_3a = num_3[0]; + rowz_3b = num_3[1]; + rowz_3c = num_3[2]; + rowz_3d = num_3[3]; + + rowz_4a = num_4[0]; + rowz_4b = num_4[1]; + rowz_4c = num_4[2]; + rowz_4d = num_4[3]; + + zeclock = [ + rowz_1a[0],rowz_1a[1],rowz_1a[2],rowz_1a[3],rowz_2a[0],rowz_2a[1],rowz_2a[2],rowz_2a[3], + rowz_1b[0],rowz_1b[1],rowz_1b[2],rowz_1b[3],rowz_2b[0],rowz_2b[1],rowz_2b[2],rowz_2b[3], + rowz_1c[0],rowz_1c[1],rowz_1c[2],rowz_1c[3],rowz_2c[0],rowz_2c[1],rowz_2c[2],rowz_2c[3], + rowz_1d[0],rowz_1d[1],rowz_1d[2],rowz_1d[3],rowz_2d[0],rowz_2d[1],rowz_2d[2],rowz_2d[3], + rowz_3a[0],rowz_3a[1],rowz_3a[2],rowz_3a[3],rowz_4a[0],rowz_4a[1],rowz_4a[2],rowz_4a[3], + rowz_3b[0],rowz_3b[1],rowz_3b[2],rowz_3b[3],rowz_4b[0],rowz_4b[1],rowz_4b[2],rowz_4b[3], + rowz_3c[0],rowz_3c[1],rowz_3c[2],rowz_3c[3],rowz_4c[0],rowz_4c[1],rowz_4c[2],rowz_4c[3], + rowz_3d[0],rowz_3d[1],rowz_3d[2],rowz_3d[3],rowz_4d[0],rowz_4d[1],rowz_4d[2],rowz_4d[3], + ] + + sense.setPixels(zeclock); + + }, +// + getdigit: function(num, place){ + + var self = this; + if (place <= 2) { o = self.color1;} + if (place >= 3) { o = self.color2;} + x = [0, 0, 0];//light off + digits = [ + [[x,x,x,x],[x,o,o,o],[x,o,x,o],[x,o,o,o],], + [[x,o,o,x],[x,x,o,x],[x,x,o,x],[x,x,o,x],], + [[x,o,o,x],[x,x,x,o],[x,x,o,x],[x,o,o,o],], + [[x,o,o,o],[x,x,x,o],[x,x,o,o],[x,o,o,o],], + [[x,x,x,o],[x,o,x,o],[x,o,o,o],[x,x,x,o],], + [[x,o,o,o],[x,o,o,x],[x,x,x,o],[x,o,o,x],], + [[x,o,x,x],[x,o,o,x],[x,o,x,o],[x,x,o,x],], + [[x,o,o,o],[x,x,x,o],[x,x,o,x],[x,x,o,x],], + [[x,x,o,x],[x,o,o,o],[x,o,o,o],[x,x,o,x],], + [[x,x,o,x],[x,o,x,o],[x,x,o,o],[x,x,x,o],] + ] + return digits[num]; + }, +// + clock: function(){ + let time_now = Date.now(); + date_now = new Date(time_now); + now_minutes = date_now.getMinutes(); + now_hours = date_now.getHours(); + this.color1 = this.ColorRandom(); + this.color2 = this.ColorRandom(); + ab = "" + now_hours; + cd = "" + now_minutes; + if (now_hours.length == 1) ab = "0" + now_hours; + if (now_minutes.length == 1) cd = "0" + now_minutes; + now_array = [ + ab.slice(0,1), + ab.slice(1,2), + cd.slice(0,1), + cd.slice(1,2), + ] + this.clockclock(now_array); + }, +// + ColorRandom: function(payload){ + ra = new Random(); + randomeda = ra.nextInt(256); + rb = new Random(); + randomedb = rb.nextInt(256); + rc = new Random(); + randomedc = rc.nextInt(256); + randomed = [randomeda,randomedb,randomedc]; + return randomed; + }, // socketNotificationReceived: function (notification, payload) { // - if (notification == "MMM_MySenseHat_LoadingTxt"){ + var self = this; + if (notification === "MMM_MySenseHat_LoadingTxt"){ sense.flashMessage("MAGIC", 0.5); sense.sleep(0.7); sense.clear(); } // - if (notification == "MMM_MySenseHat_ReadSensors"){ + if (notification === "MMM_MySenseHat_Clock"){ + self.clock(); + } + // + if (notification === "MMM_MySenseHat_ReadSensors"){ IMU.getValue((err, data) => { if (err !== null) { return; @@ -87,19 +197,44 @@ module.exports = NodeHelper.create({ }//#end if SensorsData // if (notification == "MMM_MySenseHat_PixelSlide"){ - const monster_01 = [ - OO, OO, RR, RR, RR, RR, OO, OO, - OO, RR, RR, RR, RR, RR, RR, OO, - RR, RR, OO, RR, RR, OO, RR, RR, - RR, RR, RR, RR, RR, RR, RR, RR, - RR, RR, RR, RR, RR, RR, RR, RR, - OO, RR, RR, OO, OO, RR, RR, OO, - OO, RR, RR, OO, OO, RR, RR, OO, - OO, RR, OO, OO, OO, OO, RR, OO - ]; - sense.setPixels(monster_01); - sense.sleep(5); - sense.clear(); + RR = this.ColorRandom(); + OO = [0, 0, 0];//light off, + const monsters = [ + [ + OO, OO, RR, RR, RR, RR, OO, OO, + OO, RR, RR, RR, RR, RR, RR, OO, + RR, RR, OO, RR, RR, OO, RR, RR, + RR, RR, RR, RR, RR, RR, RR, RR, + RR, RR, RR, RR, RR, RR, RR, RR, + OO, RR, RR, OO, OO, RR, RR, OO, + OO, RR, RR, OO, OO, RR, RR, OO, + OO, RR, OO, OO, OO, OO, RR, OO + ], + [ + OO, OO, OO, OO, OO, OO, OO, OO, + OO, RR, RR, RR, RR, RR, RR, OO, + OO, RR, OO, OO, OO, OO, RR, OO, + OO, RR, RR, OO, OO, RR, RR, OO, + OO, RR, OO, OO, OO, OO, RR, OO, + OO, RR, RR, RR, RR, RR, RR, OO, + RR, RR, OO, OO, OO, OO, RR, RR, + OO, RR, OO, OO, OO, OO, RR, OO + ], + [ + OO, OO, RR, OO, OO, OO, RR, OO, + OO, OO, RR, RR, RR, RR, RR, OO, + OO, OO, RR, OO, RR, OO, RR, OO, + OO, OO, RR, RR, RR, RR, RR, OO, + OO, OO, RR, RR, RR, RR, RR, OO, + OO, OO, RR, RR, RR, RR, RR, OO, + OO, RR, OO, RR, OO, RR, OO, OO, + RR, OO, RR, OO, RR, OO, RR, OO + ] + ] + + r = new Random(); + randomed = r.nextInt(monsters.length); + sense.setPixels(monsters[randomed]); }//#end if SlidePixel }//#end socketNotificationReceived diff --git a/package-lock.json b/package-lock.json index 7e368ce..5c6a6e5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -555,6 +555,11 @@ "resolved": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz", "integrity": "sha1-R+Y/evVa+m+S4VAOaQ64uFKcCZo=" }, + "java-random": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/java-random/-/java-random-0.4.0.tgz", + "integrity": "sha512-l2IZbnB877+oTytU15ac1Mp90fDrKSDpZfpDqqgCAxVjxN/HdVdM7S7YScqQ4SoBMCyjMJz+nj5h8YOereOn9Q==" + }, "jsbn": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz", diff --git a/package.json b/package.json index ff32f69..a467b26 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,8 @@ }, "homepage": "https://github.com/framboise-pi/MMM-MysenseHat#readme", "dependencies": { - "node-sense-hat": "^0.0.2" + "node-sense-hat": "^0.0.2", + "java-random": "^0.4.0" }, "devDependencies": { "electron-rebuild": "^1.11.0"