-
Notifications
You must be signed in to change notification settings - Fork 1
/
example.html
105 lines (87 loc) · 2.73 KB
/
example.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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
Status: <span id="status"></span>
<br /><br />
<script type="module" src="../dist/BluetoothLedStrip.js"></script>
<script type="module">
import { BluetoothLedStrip } from '../dist/BluetoothLedStrip.js';
var device;
// connect callback
function onConnect(device)
{
document.getElementById('status').innerHTML = 'Device ' + device.name + ' connected';
}
// disconnect callback
function onDisconnect(device)
{
document.getElementById('status').innerHTML = 'Device ' + device.name + ' disconnected';
}
// error callback
function onError(exception)
{
document.getElementById('status').innerHTML = 'Error ' + exception + ' occured';
}
// 'Connect' button
window.connect = function()
{
device = new BluetoothLedStrip.Device();
device.connect(onConnect, onDisconnect, onError);
}
// 'setRGB' button
window.setRGB = function()
{
const red = document.getElementById('red').value;
const green = document.getElementById('green').value;
const blue = document.getElementById('blue').value;
device.setRGB(red, green, blue);
}
// 'setBrightness' button
window.setBrightness = function()
{
const brightness = document.getElementById('brightness').value;
device.setBrightness(brightness);
}
// 'setSwitch' button
window.setSwitch = function()
{
const value = document.getElementById('switch').value;
device.setSwitch(value);
}
// 'setMode' button
window.setMode = function()
{
const mode = document.getElementById('mode').value;
device.setMode(mode);
}
// 'setSpeed' button
window.setSpeed = function()
{
const speed = document.getElementById('speed').value;
device.setSpeed(speed);
}
</script>
<button onclick="connect();">Connect</button>
<br /><br />
R <input type="text" id="red" size="3" value="255">
G <input type="text" id="green" size="3" value="0">
B <input type="text" id="blue" size="3" value="0">
<button onclick="setRGB();">setRGB</button>
<br /><br />
Brightness <input type="text" id="brightness" size="3" value="0">
<button onclick="setBrightness();">setBrightness</button>
<br /><br />
Switch <input type="text" id="switch" size="3" value="0">
<button onclick="setSwitch();">setSwitch</button>
<br /><br />
Mode <input type="text" id="mode" size="3" value="0">
<button onclick="setMode();">setMode</button>
<br /><br />
Speed <input type="text" id="speed" size="3" value="0">
<button onclick="setSpeed();">setSpeed</button>
</body>
</html>