-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpage.html
More file actions
267 lines (235 loc) · 7.63 KB
/
Copy pathpage.html
File metadata and controls
267 lines (235 loc) · 7.63 KB
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
let x = [];
let v = val=>val.pressureAltitude;
let d = id => document.getElementById(id);
let p = (url, number) => fetch(url, { method: "PUT", body: number });
let g = url => fetch(url, { method: "GET" });
let led = n => {
d('led').style.top = n + '00%';
p("/led", n);
};
let sound = n => {
d('sound').style.top = n +'00%';
p("/sound", n);
};
let c = () => {
let g = d('chart').getContext('2d');
g.save();
g.clearRect(0, 0, 1000, 1000);
g.lineWidth = 2;
g.lineCap = 'round';
g.strokeStyle = '#222';
g.beginPath();
g.moveTo(800, 800);
g.lineTo(200, 800);
g.lineTo(200, 200);
g.stroke();
if (x.length < 2) {
return;
}
let mostRecent = x[x.length-1];
let minmax = {
min: Infinity,
max: -Infinity
};
let data = x.filter(v => mostRecent.millis - v.millis <= 60000);
if (Array.isArray(v(mostRecent))) {
for (let i = 0; i < v(mostRecent).length; i++) {
minmax = data.reduce((prev, current) => ({
min: Math.min(prev.min, v(current)[i]),
max: Math.max(prev.max, v(current)[i])
}), minmax);
}
} else {
minmax = data.reduce((prev, current) => ({
min: Math.min(prev.min, v(current)),
max: Math.max(prev.max, v(current))
}), minmax);
}
if (minmax.min == minmax.max) {
minmax.min -= 1;
minmax.max += 1;
}
let scale = { x: 600.0 / 60000.0, y: 600.0 / (minmax.min - minmax.max) };
let offset = { x: 800 - mostRecent.millis * scale.x, y: 800 - minmax.min * scale.y };
g.lineJoin='round';
g.strokeStyle='#e33';
let colours = ['#3e3', '#e33', '#33e'];
if (Array.isArray(v(mostRecent))) {
for (let j = 0; j < v(mostRecent).length; j++) {
g.strokeStyle = colours[j];
g.beginPath();
data.forEach((val, i) => g[i ? 'lineTo' : 'moveTo'](offset.x + scale.x * val.millis, offset.y + scale.y * v(val)[j]));
g.stroke();
}
} else {
g.beginPath();
data.forEach((val, i) => g[i ? 'lineTo' : 'moveTo'](offset.x + scale.x * val.millis, offset.y + scale.y * v(val)));
g.stroke();
}
[0,0.2,0.4,0.6,0.8,1.0].forEach(v => {
g.fillText('-' + ((1 - v) * 60).toFixed() + 's', 200 + v * 600, 900);
g.fillText((v * minmax.max + (1 - v) * minmax.min).toFixed(2), 100, 800 - v * 600);
});
g.restore();
};
setInterval(()=>{
g("/data")
.then(r=>r.json())
.then(t=>{
x.push(t);
d('rssi').innerText=t.rssi;
d('acceleration').innerText=t.acc.join(', ');
d('gyro').innerText=t.gyro.join(', ');
d('mag').innerText=t.mag.join(', ');
d('temp').innerText=t.temp;
d('pressure').innerText=t.pressure;
d('altitude-pressure').innerText=t.pressureAltitude;
d('gps').innerText=t.gps.fix?t.gps.satellites:'No lock';
d('lat').innerText=t.gps.latitude
d('lon').innerText=t.gps.longitude;
d('altitude-gps').innerText=t.gps.altitude;
d('photos').innerText=t.photoNumber;
});
c();
},1000);
</script>
<style>
* {
box-sizing: border-box;
}
.sidepanel {
background-color:#d1e8e2;
flex: 0 1 25%;
padding: 2%;
}
.control {
display: grid;
grid: auto-flow / 1fr 25%;
align-content: start;
}
.control > span + div {
grid-column-start: 2;
background-color: #c5ceca;
border-radius: 50%;
padding-bottom: 20%;
margin: 40%;
cursor: pointer;
}
.control > span {
place-self: center auto;
}
.control > h2 {
grid-column-end: span 2;
}
#led + div {
grid-area: 2 / -2 / span 3 / span 1;
border-left: 5px solid#c5ceca;
justify-self: center;
}
#led {
grid-area: 2 / 2;
}
#sound + div {
grid-area: 6 / -2 / span 4 / span 1;
border-left: 5px solid#c5ceca;
justify-self: center;
}
#sound {
grid-area: 6 / 2;
}
#led, #sound {
top: 0;
background-color: #116466;
border-radius: 50%;
padding-bottom: 30%;
margin: 35%;
z-index: 1;
position: relative;
transition: top 0.5s;
}
#data {
background-color:#c5ceca;
border-radius: 20px;
display: grid;
grid: auto-flow / 1fr 1fr 1fr;
align-content: start;
gap: 20px;
padding: 40px;
}
#data > div {
border-radius: 20px;
background-color: #d1e8e2;
padding: 20px;
}
#chart {
background-color: #c5ceca;
border-radius: 20px;
place-self: stretch;
}
.suck {
display: flow;
flex-direction: column;
padding: 2%;
}
.suck > div {
background-color: #116466;
border-radius: 20px;
padding: 20px;
text-align: center;
color: white;
font-weight: bold;
cursor: pointer;
margin-bottom: 20px;
}
</style>
</head>
<body style="display: flex; align-items: stretch; height: 100vh; margin: 0; background-color: #2c3531; font-family: sans-serif;">
<div class="sidepanel control">
<div id="led"></div>
<div></div>
<h2>LED Modes</h2>
<span style="grid-row-start: 2">The Inside of My Soul</span><div style="grid-row-start: 2" onclick="led(0)"></div>
<span style="grid-row-start: 3">This Month</span><div style="grid-row-start: 3" onclick="led(1)"></div>
<span style="grid-row-start: 4">Artsy</span><div style="grid-row-start: 4" onclick="led(2)"></div>
<div id="sound"></div>
<div></div>
<h2>Sound Modes</h2>
<span style="grid-row-start: 6">Blissful Silence</span><div style="grid-row-start: 6" onclick="sound(0)"></div>
<span style="grid-row-start: 7">Ol' Reliable</span><div style="grid-row-start: 7" onclick="sound(1)"></div>
<span style="grid-row-start: 8">Imperial</span><div style="grid-row-start: 8" onclick="sound(2)"></div>
<span style="grid-row-start: 9">Just Give Up</span><div style="grid-row-start: 9" onclick="sound(3)"></div>
</div>
<div style="overflow: auto; flex: auto; display: grid; row-gap: 50px; margin: 50px;">
<div id="data">
<div onclick="v=x=>x.rssi">WiFi Strength (RSSI): <span id="rssi"></span></div>
<div onclick="v=x=>x.acc">Acceleration (m s-2): <span id="acceleration"></span></div>
<div onclick="v=x=>x.gyro">Gyro (rad s-1): <span id="gyro"></span></div>
<div onclick="v=x=>x.mag">Magnetic Field (uT): <span id="mag"></span></div>
<div>GPS Lock: <span id="gps"></span></div>
<div onclick="v=x=>x.temp">Temperature (C):<span id="temp"></span></div>
<div onclick="v=x=>x.pressure">Pressure (Pa): <span id="pressure"></span></div>
<div onclick="v=x=>x.gps.latitude">Latitude (deg): <span id="lat"></span></div>
<div onclick="v=x=>x.gps.longitude">Longitude (deg): <span id="lon"></span></div>
<div onclick="v=x=>x.pressureAltitude">Altitude - Pressure (m): <span id="altitude-pressure"></span></div>
<div onclick="v=x=>x.gps.altitude">Altitude - GPS (m): <span id="altitude-gps"></span></div>
<div onclick="v=x=>x.photoNumber">Photos Taken: <span id="photos"></span> / 999</div>
</div>
<canvas id="chart" width=1000 height=1000>
</div>
<div class="sidepanel suck">
<h2>Command Module</h2>
<div onclick="p('/camera',0)">Take single picture</div>
<div onclick="p('/camera',1)">Enable continuous pictures</div>
<div onclick="p('/camera',2)">Take video</div>
<div onclick="p('/altitude',+prompt('Altitude (mm above sealevel)', '0'))">Set altitude</div>
<div onclick="p('/time',+prompt('Time (unix)', '0'))">Set rtc time</div>
<div onclick="p('/gps',+prompt('Ms to wait', '30000'))">Turn off chip until Gps lock is found</div>
<div onclick="p('/arm',0)">Arm the psat to detect launch</div>
<div onclick="p('/arm',1)">Disarm the psat to detect launch</div>
</div>
</body>
</html>