-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.html
226 lines (216 loc) · 8.36 KB
/
index.html
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
<!DOCTYPE html>
<html>
<meta charset="utf-8" />
<title>balenaBLE</title>
<link rel="stylesheet" href="style.css" />
<script src="ble-client.js"></script>
<body>
<h1>balenaBLE</h1>
<div class="lamp">
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- Generator: Adobe Illustrator 19.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg
version="1.1"
id="Layer_1"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
x="0px"
y="0px"
viewBox="0 0 512 512"
style="enable-background:new 0 0 512 512;"
xml:space="preserve"
>
<path
d="M255.962,132.741c-5.234,0-9.481-4.248-9.481-9.481V9.481c0-5.234,4.248-9.481,9.481-9.481s9.481,4.248,9.481,9.481v113.778
C265.443,128.493,261.196,132.741,255.962,132.741z"
/>
<path
style="fill:#AD1457;"
d="M471.476,341.333H40.448c-6.334,0.275-11.681-4.636-11.956-10.97
c-0.161-3.859,1.621-7.538,4.75-9.794l191.621-138.145c2.076-1.47,4.561-2.266,7.111-2.276h47.976
c2.551,0.009,5.035,0.806,7.111,2.276l191.621,138.145c5.139,3.707,6.296,10.875,2.588,16.014
C479.014,339.712,475.335,341.495,471.476,341.333z"
/>
<path
style="fill:#E91E63;"
d="M424.069,341.333H40.448c-6.334,0.275-11.681-4.636-11.956-10.97
c-0.161-3.859,1.621-7.538,4.75-9.794l191.621-138.145c2.076-1.47,4.561-2.266,7.111-2.276h0.569
c2.551,0.009,5.035,0.806,7.111,2.276l191.621,138.145c5.139,3.707,6.296,10.875,2.588,16.014
C431.606,339.712,427.927,341.495,424.069,341.333z"
/>
<path
style="fill:#AD1457;"
d="M284.406,151.704v28.444h-56.889v-28.444c0-15.711,12.734-28.444,28.444-28.444
S284.406,135.993,284.406,151.704z"
/>
<path
style="fill:#E91E63;"
d="M255.962,151.704v28.444h-28.444v-28.444c-0.009-10.164,5.414-19.57,14.222-24.652
C250.548,132.134,255.971,141.54,255.962,151.704z"
/>
<path
d="M471.476,350.815H40.448c-9.33,0.18-17.664-5.803-20.48-14.696c-2.854-8.59,0.265-18.034,7.68-23.23l191.621-138.145
c3.698-2.655,8.145-4.087,12.705-4.077h47.881c4.561-0.009,9.007,1.422,12.705,4.077l191.716,138.145
c7.443,5.167,10.61,14.62,7.775,23.23C489.225,345.05,480.844,351.042,471.476,350.815z M231.974,189.63
c-0.569-0.009-1.138,0.161-1.612,0.474L38.741,328.344c-0.721,0.379-1.043,1.233-0.759,1.991c0.341,0.996,1.327,1.621,2.37,1.517
h431.123c1.043,0.104,2.029-0.521,2.37-1.517c0.284-0.759-0.038-1.612-0.759-1.991l-191.526-138.24
c-0.474-0.313-1.043-0.484-1.612-0.474L231.974,189.63L231.974,189.63z"
/>
<path
class="rays"
style="fill:#FDD834;"
d="M284.406,341.333v28.444c0,15.711-12.734,28.444-28.444,28.444s-28.444-12.734-28.444-28.444v-28.444
H284.406z"
/>
<path
class="rays"
style="fill:#FFEB3A;"
d="M255.962,341.333v28.444c0.009,10.164-5.414,19.57-14.222,24.652
c-8.808-5.082-14.232-14.488-14.222-24.652v-28.444H255.962z"
/>
<path
d="M255.962,407.704c-20.945,0-37.926-16.981-37.926-37.926v-28.444c0-5.234,4.248-9.481,9.481-9.481h56.889
c5.234,0,9.481,4.248,9.481,9.481v28.444C293.888,390.722,276.906,407.704,255.962,407.704z M236.999,350.815v18.963
c0,10.477,8.486,18.963,18.963,18.963s18.963-8.486,18.963-18.963v-18.963H236.999z"
/>
<path
class="rays"
d="M123.221,502.519c-5.234,0.028-9.51-4.191-9.538-9.425c-0.019-2.551,0.996-4.997,2.807-6.789l75.852-75.852
c3.973-3.404,9.965-2.939,13.369,1.034c3.044,3.546,3.044,8.789,0,12.335l-75.852,75.852
C128.104,501.457,125.724,502.481,123.221,502.519z"
/>
<path
class="rays"
d="M388.703,502.519c-2.522,0.019-4.94-0.977-6.732-2.75l-75.852-75.852c-3.404-3.973-2.939-9.965,1.033-13.369
c3.546-3.044,8.789-3.044,12.335,0L395.34,486.4c3.669,3.736,3.603,9.737-0.133,13.407
C393.472,501.513,391.139,502.481,388.703,502.519z"
/>
<path
class="rays"
d="M189.591,388.741h-66.37c-5.234,0-9.481-4.248-9.481-9.481c0-5.234,4.248-9.482,9.481-9.482h66.37
c5.234,0,9.481,4.248,9.481,9.482C199.073,384.493,194.825,388.741,189.591,388.741z"
/>
<path
class="rays"
d="M379.221,388.741h-66.37c-5.234,0-9.481-4.248-9.481-9.481c0-5.234,4.248-9.482,9.481-9.482h66.37
c5.234,0,9.481,4.248,9.481,9.482C388.703,384.493,384.455,388.741,379.221,388.741z"
/>
<path
class="rays"
d="M255.962,512c-5.234,0-9.481-4.248-9.481-9.481v-66.37c0-5.234,4.248-9.482,9.481-9.482s9.481,4.248,9.481,9.482v66.37
C265.443,507.752,261.196,512,255.962,512z"
/>
<path
d="M284.406,189.63h-56.889c-5.234,0-9.481-4.248-9.481-9.481v-28.444c0-20.945,16.981-37.926,37.926-37.926
s37.926,16.981,37.926,37.926v28.444C293.888,185.382,289.64,189.63,284.406,189.63z M236.999,170.667h37.926v-18.963
c0-10.477-8.486-18.963-18.963-18.963s-18.963,8.486-18.963,18.963V170.667z"
/>
<path
d="M274.925,227.556h-37.926c-5.234,0-9.481-4.248-9.481-9.481s4.248-9.481,9.481-9.481h37.926
c5.234,0,9.481,4.248,9.481,9.481S280.159,227.556,274.925,227.556z"
/>
</svg>
</div>
<!-- svg ends -->
<div id="stats">
<div id="not-connected">
<p>Connect to a balenaBLE device to get started</p>
<button id="btn-connect" class="btn">Connect</button>
</div>
<div id="container" class="hidden">
<label class="btn-light"
><input type="checkbox" id="toggle" />
<div></div>
</label>
<div id="device-info">
<p>CPU: <span id="vendor"></span>@<span id="speed"></span>GHz</p>
<button id="btn-disconnect" onclick="disconnect()" class="btn">
Disconnect
</button>
</div>
</div>
</div>
<footer>
<div>
Icons made by
<a
href="https://www.flaticon.com/authors/creaticca-creative-agency"
title="Creaticca Creative Agency"
>Creaticca Creative Agency</a
>
from
<a href="https://www.flaticon.com/" title="Flaticon"
>www.flaticon.com</a
>
</div>
</footer>
</body>
</html>
<script>
/* updates UI when LED is turned on/off */
function handleLedStatusChanged(event) {
let status = event.target.value.getUint8(0);
rays = document.getElementsByClassName("rays");
if (status) {
for (let ray of rays) {
ray.style.setProperty("display", "block");
let toggle = document.getElementById("toggle");
}
toggle.checked = true;
} else {
for (let ray of rays) {
ray.style.setProperty("display", "none");
}
toggle.checked = false;
}
}
/* helper function to decode message sent from peripheral */
function decode(buf) {
let dec = new TextDecoder("utf-8");
return dec.decode(buf);
}
/* Disconnect from peripheral and update UI */
function disconnect() {
balenaBLE.disconnect();
document.getElementById("not-connected").classList.remove("hidden");
document.getElementById("container").classList.add("hidden");
}
var balenaBLE = new BalenaBLE();
var toggle = document.getElementById("toggle");
/* connect to peripheral, load data and add event listeners */
document
.getElementById("btn-connect")
.addEventListener("click", async event => {
try {
await balenaBLE.request();
await balenaBLE.connect();
await balenaBLE.setLedCharacteristic();
await balenaBLE.setDeviceCharacteristic();
document.getElementById("not-connected").classList.add("hidden");
document.getElementById(
"vendor"
).textContent = await balenaBLE.readCPUVendor();
document.getElementById(
"speed"
).textContent = await balenaBLE.readCPUSpeed();
toggle.addEventListener("change", e => {
if (e.target.checked) {
balenaBLE.writeLed(1);
toggle.disabled = true;
setTimeout(() => {
toggle.disabled = false;
}, 1000);
} else {
balenaBLE.writeLed(0);
toggle.disabled = true;
setTimeout(() => {
toggle.disabled = false;
}, 1000);
}
});
document.getElementById("container").classList.remove("hidden");
} catch (error) {
console.log(error.message);
}
});
</script>