-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotification.html
43 lines (38 loc) · 1.22 KB
/
notification.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
<!DOCTYPE html>
<html lang="en-us">
<head>
<meta charset="utf-8">
<title>Example 3: notifications</title>
<link rel="stylesheet" href="./common.css" type="text/css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.3/require.min.js"></script>
</head>
<body>
<div class="box">
<button>start experiment</button>
<progress style="display:none" max="100"></progress>
</div>
<script>
require(['../dist/jsgatt.js'], function(Device) {
var awos = new Device.default(window);
var battery = awos.register(
'battery_service',
'battery_level'
);
var button = document.querySelector('button');
var progress = document.querySelector('progress');
button.addEventListener('click', function() {
battery.getCharacteristic().then(function(ch) {
ch.startNotifications().then(function(){
ch.addEventListener('characteristicvaluechanged', printValue);
button.style.display = 'none';
progress.removeAttribute('style');
});
});
});
function printValue(event) {
progress.setAttribute('value', event.target.value.getUint8(0));
}
});
</script>
</body>
</html>