-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest1.html
49 lines (47 loc) · 1.82 KB
/
test1.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
<html>
<head>
<title>Dashboard</title>
<meta name="viewport" content="width=620, initial-scale=1">
</head>
<body style="width:620px;height:450px">
<link href="https://espruino.github.io/TinyDash/tinydash.css" rel="stylesheet">
<script src="https://espruino.github.io/TinyDash/tinydash.js"></script>
<script src="https://www.puck-js.com/puck.js"></script>
<script>
// https://www.espruino.com/Web+Bluetooth
function connectDevice() {
// connect, and ask for the battery percentage
Puck.eval("{bat:Puck.getBatteryPercentage()}", function(d,err) {
if (!d) {
alert("Web Bluetooth connection failed!\n"+(err||""));
return;
}
// remove the 'connect' window
elements.modal.remove();
// update the controls with the values we received
elements.bat.setValue(d.bat);
// now get the history - these could take a while
// so we do it separately.
Puck.eval("history", function(d) {
elements.temp.setData(d);
});
});
}
// Set up the controls we see on the screen
var elements = {
heading : TD.label({x:10,y:10,width:190,height:50,label:"My Dashboard"}),
bat : TD.gauge({x:10,y:70,width:190,height:220,label:"Battery Level",value:0,min:0,max:100}),
temp : TD.graph({x:210,y:10,width:400,height:180,label:"Temperature"}),
redled : TD.toggle({x:210,y:200,width:200,height:90,label:"Red LED",value:0,onchange:function(el,v) {
Puck.write("LED1.write("+v+");\n");
}}),
flash : TD.button({x:420,y:200,width:190,height:90,label:"Flash!",onchange:function(){
Puck.write("digitalPulse(LED3,1,500);\n");
}}),
modal: TD.modal({x:10,y:10,width:600,height:430,label:"Click to connect",onchange:connectDevice})
}
for (var i in elements)
document.body.appendChild(elements[i]);
</script>
</body>
</html>