Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
framboise-pi authored Jun 8, 2020
1 parent 8ec7be5 commit 7f61d96
Show file tree
Hide file tree
Showing 4 changed files with 196 additions and 31 deletions.
42 changes: 33 additions & 9 deletions MMM-MySenseHat.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -30,15 +34,35 @@ Module.register("MMM-MySenseHat",{
compy: "<sup>-N/A-</sup>",
compz: "<sup>-N/A-</sup>"
},
//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 () {
Expand All @@ -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) {
Expand All @@ -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 = "<div class='container'>"
ihtml += "<div class='line'><sup> humidité </sup> <i class=\"fa fa-tint\" style=\"color:#50FCFF\"></i> " + this.SensorsData.humi + " %</div>"
ihtml += "<div class='line'><sup> température </sup> <i class=\"fa fa-thermometer-empty\" style=\"color:#FF8A50\"></i> " + this.SensorsData.temp + " °C</div>"
ihtml += "<div class='line'><sup> pression </sup> <i class=\"fa fa-cloud\" style=\"color:#EFEFEF\"></i> " + this.SensorsData.press + " mbar</div>"
if (this.config.show_all_sensors) {
ihtml += "<div class='line'><sup> compas </sup> <i class=\"fa fa-compass\" style=\"color:#CD1C00\"></i> " + this.SensorsData.compx + "<sup>X</sup> | " + this.SensorsData.compy + "<sup>Y</sup> | " + this.SensorsData.compz + "<sup>Z</sup> µT</div>"
//ihtml += "<div class='line'><sup> fusion </sup> <i class=\"fa fa-compass\" style=\"color:#CD1C00\"></i> " + this.SensorsData.fusix + "<sup>X</sup> | " + this.SensorsData.fusiy + "<sup>Y</sup> | " + this.SensorsData.fusiz + "<sup>Z</sup></div>"
ihtml += "<div class='line'><sup> gyroscope </sup> <i class=\"fa fa-arrows-alt\" style=\"color:#FAFF8E\"></i> " + this.SensorsData.gyrox + "<sup>X</sup> | " + this.SensorsData.gyroy + "<sup>Y</sup> | " + this.SensorsData.gyroz + "<sup>Z</sup> rad/sec</div>"
ihtml += "<div class='line'><sup> accélération </sup> <i class=\"fa fa-dashboard\" style=\"color:#A6FF8E\"></i> " + this.SensorsData.accex + "<sup>X</sup> | " + this.SensorsData.accey + "<sup>Y</sup> | " + this.SensorsData.accez + "<sup>Z</sup> G</div>"
}
ihtml += "</div>"
wrapper.innerHTML = ihtml
return wrapper
Expand Down
177 changes: 156 additions & 21 deletions node_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 7f61d96

Please sign in to comment.