-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathMMM-ISS.js
164 lines (124 loc) · 4.97 KB
/
MMM-ISS.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
/* Magic Mirror
* Module: MMM-ISS
*
* By Mykle1 - MIT Licensed
*
*/
Module.register("MMM-ISS", {
// Module config defaults.
defaults: {
country: "France",
regionState: "", // Outside USA may not need regionState. If so, leave blank "".
city: "Toulon",
lat: "43.1242", // latitude
lng: "5.9280", // longitude
units: "km", // mi = miles,mph, km = kilometers,
useHeader: false, // true if you want a header
header: "Spot The Station", // Any text you want. useHeader must be true
animationSpeed: 0,
initialLoadDelay: 4250,
retryDelay: 2500,
updateInterval: 5 * 60 * 1000,
},
getStyles: function() {
return ["MMM-ISS.css"];
},
getScripts: function() {
return ["moment.js"];
},
start: function() {
Log.info("Starting module: " + this.name);
// Set locale.
this.url = "http://api.open-notify.org/iss-pass.json?lat=" + this.config.lat + "&lon=" + this.config.lng + "&n=5";
this.ISS = {};
this.VELALT = {};
this.scheduleUpdate();
},
getDom: function() {
var wrapper = document.createElement("div");
wrapper.className = "wrapper";
wrapper.style.maxWidth = this.config.maxWidth;
if (!this.loaded) {
wrapper.innerHTML = "Is that the ISS?";
wrapper.classList.add("bright", "light", "small");
return wrapper;
}
if (this.config.useHeader != false) {
var header = document.createElement("header");
header.classList.add("xsmall", "bright", "header");
header.innerHTML = this.config.header;
wrapper.appendChild(header);
}
// replaces spaces with underscores so url doesn't fail
if (this.config.country != "") {
this.config.country = (this.config.country).replace(/ /g,"_");
}
// replaces spaces with underscores so url doesn't fail
if (this.config.regionState != "") {
this.config.regionState = (this.config.regionState).replace(/ /g,"_");
}
// replaces spaces with underscores so url doesn't fail
if (this.config.city != "") {
this.config.city = (this.config.city).replace(/ /g,"_");
}
// When specific countries do not require regionState, replace empty regionState with "None"
if (this.config.regionState === "") {
this.config.regionState = "None";
}
var iframe = document.createElement("IFRAME");
iframe.style = "border:0";
iframe.width = "310px";
iframe.height = "450px";
iframe.src = 'https://spotthestation.nasa.gov/widget/widget.cfm?country=' + this.config.country + '®ion=' + this.config.regionState + '&city=' + this.config.city + '&theme=2';
wrapper.appendChild(iframe);
var ISS = this.ISS;
var VELALT = this.VELALT;
var velocity = document.createElement("div");
velocity.classList.add("xsmall", "velocity");
if (this.config.units != "km"){
velocity.innerHTML = "Velocity: " + Math.round(VELALT.velocity * 0.621371) + " mph       " + " Altitude: " + Math.round(VELALT.altitude * 0.621371) + " miles";
} else {
velocity.innerHTML = "Velocity: " + Math.round(VELALT.velocity) + " km/h       " + " Altitude: " + Math.round(VELALT.altitude) + " km";
}
wrapper.appendChild(velocity);
return wrapper;
},
///// Add this function to the modules you want to control with voice //////
notificationReceived: function(notification, payload) {
if (notification === 'HIDE_STATION') {
this.hide(1000);
} else if (notification === 'SHOW_STATION') {
this.show(1000);
}
},
processISS: function(data) {
this.ISS = data;
// console.log(this.ISS); // for checking in dev console
this.loaded = true;
},
processVELALT: function(data) {
this.VELALT = data;
// console.log(this.VELALT); // for checking in dev console
this.loaded = true;
},
scheduleUpdate: function() {
setInterval(() => {
this.getISS();
}, this.config.updateInterval);
this.getISS(this.config.initialLoadDelay);
},
getISS: function() {
this.sendSocketNotification('GET_ISS', this.url);
},
socketNotificationReceived: function(notification, payload) {
if (notification === "ISS_RESULT") {
this.processISS(payload);
this.updateDom(this.config.animationSpeed);
}
if (notification === "VELALT_RESULT") {
this.processVELALT(payload);
this.updateDom(this.config.fadeSpeed);
}
this.updateDom(this.config.initialLoadDelay);
},
});