-
Notifications
You must be signed in to change notification settings - Fork 1
/
MMM-MySenseHat.js
209 lines (199 loc) · 7.3 KB
/
MMM-MySenseHat.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/* global Module */
/* Magic Mirror
* Module: MMM-MySenseHat
* https://github.com/framboise-pi/MMM-MySenseHat
* Copyright(C) 2021 Cedric Camille Lafontaine http://www.framboise-pi.fr,
* version 0.0.4
*/
Module.register("MMM-MySenseHat",{
// CONFIG
defaults: {
slide_interval: 30000,//ms as it refreshes clock/time : try keep <30 seconds)
/*config: {
read_interval : 20000,
display_start_LED: false,
use_SenseHat_LED: true,
show_all_sensors: false,
mode_monster: true,
mode_clock: true,
mode_pixel1: false,
mode_pixelv: true,
mode_temp: true,
cpu_load: true,
ram_used: true,
fontsize: "normal"//small | normal | large | xlarge
}*/
},
// DATA DISPLAY STARTUP VALUE
SensorsData: {
temp: "<sup>-N/A-</sup>",
humi: "<sup>-N/A-</sup>",
press: "<sup>-N/A-</sup>",
accex: "<sup>-N/A-</sup>",
accey: "<sup>-N/A-</sup>",
accez: "<sup>-N/A-</sup>",
gyrox: "<sup>-N/A-</sup>",
gyroy: "<sup>-N/A-</sup>",
gyroz: "<sup>-N/A-</sup>",
compx: "<sup>-N/A-</sup>",
compy: "<sup>-N/A-</sup>",
compz: "<sup>-N/A-</sup>"
},
//VARIABLES USED
round: 0,//pixelart|clock|temp value|weather|...
last_version: null,
installed: null,
versiontimer: true,
versionreturn: null,
// CSS
getStyles: function () {
return ["MMM-MySenseHat.css", "font-awesome.css"];
},
//
start: function() {
var self = this;
if (this.config.display_start_LED == true) this.sendSocketNotification("MMM_MySenseHat_LoadingTxt");
this.askdata();
if (this.config.use_SenseHat_LED == true) self.autochangemode();
this.checkversion();
},
//
checkversion: function(){
var self = this;
setTimeout(function() {
self.sendSocketNotification("MMM_MySenseHat_Version");
}, 5000);
/* OPTION to hide versions tags after 2min timeout
setTimeout(function(){
self.versiontimer = false;
}, 120 * 1000);*/
},
//AUTO CHANGE MODE
autochangemode: function () {
var self = this;
setInterval(function() {
self.zeloop();
}, self.config.slide_interval);
},
// LOOP WITHIN MODES
zeloop: function (){
var self = this;
self.round = self.round + 1;
if (self.round == 1)
{
if (self.config.mode_monster) { self.pixelslide(); }
else self.round = 2;
}
if (self.round == 2 )
{
if (self.config.mode_clock) {
self.sendSocketNotification("MMM_MySenseHat_Clock"); }
else self.round = 3;
}
if (self.round == 3 )
{
if (self.config.mode_pixel1) {
self.sendSocketNotification("MMM_MySenseHat_Random1x1"); }
else self.round = 4;
}
if (self.round == 4 )
{
if (self.config.mode_pixelv) {
self.sendSocketNotification("MMM_MySenseHat_RandomV"); }
else self.round = 5;
}
if (self.round == 5 )
{
if (self.config.mode_temp) {
self.sendSocketNotification("MMM_MySenseHat_PixelTemp", self.SensorsData.temp); }
else self.round = 6;
}
if (self.round == 6 )
{
if (self.config.cpu_load) {
self.sendSocketNotification("MMM_MySenseHat_PixelCpu"); }
else self.round = 7;
}
if (self.round == 7 )
{
if (self.config.ram_used) {
self.sendSocketNotification("MMM_MySenseHat_PixelRam"); }
else {
self.round = 0;
self.zeloop();
}
}
},
//ASK FOR SENSORS DATA
askdata: function () {
var self = this;
setInterval(function() {
self.sendSocketNotification("MMM_MySenseHat_ReadSensors");
self.updateDom();
}, self.config.read_interval);
},
//SLIDESHOW LED
pixelslide: function () {
this.sendSocketNotification("MMM_MySenseHat_PixelSlide");
},
//
socketNotificationReceived: function (notification, payload) {
if (notification === "MMM_MySenseHat_Latest_Version"){
//var self = this;
this.last_version = payload.last_version
this.installed = payload.installed
this.versionreturn = payload.versionreturn
}
if (notification === "MMM_MySenseHat_SensorsData"){
//TEMP-HUMIDITY-PRESSION
this.SensorsData.temp = Math.round(payload.temp*100)/100
this.SensorsData.humi = Math.round(payload.humi*100)/100
this.SensorsData.press = Math.round(payload.press*100)/100
//ACCELERATOR XYZ
this.SensorsData.accex = Math.round(payload.accex*100)/100
this.SensorsData.accey = Math.round(payload.accey*100)/100
this.SensorsData.accez = Math.round(payload.accez*100)/100
//GYYROSCOPE XYZ
this.SensorsData.gyrox = Math.round(payload.gyrox*100)/100
this.SensorsData.gyroy = Math.round(payload.gyroy*100)/100
this.SensorsData.gyroz = Math.round(payload.gyroz*100)/100
//COMPASS XYZ
this.SensorsData.compx = Math.round(payload.compx*100)/100
this.SensorsData.compy = Math.round(payload.compy*100)/100
this.SensorsData.compz = Math.round(payload.compz*100)/100
}
},
//#end socketNotif SensorsData
getDom: function() {
var self = this;
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>"
}
if (this.versiontimer && this.last_version != null)
{
ihtml += "<div class='leftline'><sup> <i class=\"fa fa-github\" style=\"color:#A6FF8E\"></i> " + self.last_version + "</sup></div>"
ihtml += "<div class='leftline'><sup> <i class=\"fa fa-files-o\" style=\"color:#A6FF8E\"></i> " + self.installed + "</sup></div>"
if (self.versionreturn == 0){
ihtml += "<div class='leftline'><sup> <i class=\"fa fa-check-circle\" style=\"color:#A6FF8E\"></i> UP TO DATE </sup> </div>"
}
if (self.versionreturn == 1){
ihtml += "<div class='leftline'><sup> <i class=\"fa fa-plus-circle\" style=\"color:#A6FF8E\"></i> NEW version available </sup> </div>"
}
if (self.versionreturn == -1){
ihtml += "<div class='leftline'><sup> <i class=\"fa fa-user-secret\" style=\"color:#A6FF8E\"></i> DEV version ! </sup> </div>"
}
}
ihtml += "</div>"
wrapper.innerHTML = ihtml
return wrapper
},
});