-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIndex.html
executable file
·300 lines (260 loc) · 10.9 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
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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="description" content="Sample illustrating the use of Web Bluetooth / Notifications.">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="visualize.js" type="text/javascript"></script>
<script src="https://cdn.jsdelivr.net/npm/p5@0.7.2/lib/p5.min.js" type="text/javascript"></script>
<title>Web Bluetooth / Notifications Sample</title>
<script>
// Add a global error event listener early on in the page load, to help ensure that browsers
// which don't support specific functionality still end up displaying a meaningful message.
window.addEventListener('error', function (error) {
if (ChromeSamples && ChromeSamples.setStatus) {
console.error(error);
ChromeSamples.setStatus(error.message + ' (Your browser may not support this feature.)');
error.preventDefault();
}
});
</script>
<link rel="icon" href="icon.png">
<link rel="stylesheet" href="../styles/main.css">
</head>
<body>
<script>
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('service-worker.js');
}
</script>
<script>
window.addEventListener('DOMContentLoaded', function () {
const searchParams = new URL(location).searchParams;
const inputs = Array.from(document.querySelectorAll('input[id]'));
inputs.forEach(input => {
if (searchParams.has(input.id)) {
if (input.type == 'checkbox') {
input.checked = searchParams.get(input.id);
} else {
input.value = searchParams.get(input.id);
input.blur();
}
}
if (input.type == 'checkbox') {
input.addEventListener('change', function (event) {
const newSearchParams = new URL(location).searchParams;
if (event.target.checked) {
newSearchParams.set(input.id, event.target.checked);
} else {
newSearchParams.delete(input.id);
}
history.replaceState({}, '', Array.from(newSearchParams).length ?
location.pathname + '?' + newSearchParams : location.pathname);
});
} else {
input.addEventListener('input', function (event) {
const newSearchParams = new URL(location).searchParams;
if (event.target.value) {
newSearchParams.set(input.id, event.target.value);
} else {
newSearchParams.delete(input.id);
}
history.replaceState({}, '', Array.from(newSearchParams).length ?
location.pathname + '?' + newSearchParams : location.pathname);
});
}
});
});
</script>
<form>
<button id="startNotifications">Start notifications</button>
<button id="stopNotifications">Stop notifications</button>
</form>
<script>
var ChromeSamples = {
log: function () {
var line = Array.prototype.slice.call(arguments).map(function (argument) {
return typeof argument === 'string' ? argument : JSON.stringify(argument);
}).join(' ');
document.querySelector('#log').textContent += line + '\n';
},
clearLog: function () {
document.querySelector('#log').textContent = '';
},
setStatus: function (status) {
document.querySelector('#status').textContent = status;
},
setContent: function (newContent) {
var content = document.querySelector('#content');
while (content.hasChildNodes()) {
content.removeChild(content.lastChild);
}
content.appendChild(newContent);
}
};
</script>
<h3>Live Output</h3>
<div id="output" class="output">
<div id="content"></div>
<div id="status"></div>
<pre id="log"></pre>
</div>
<script>
if (/Chrome\/(\d+\.\d+.\d+.\d+)/.test(navigator.userAgent)) {
// Let's log a warning if the sample is not supposed to execute on this
// version of Chrome.
if (48 > parseInt(RegExp.$1)) {
ChromeSamples.setStatus('Warning! Keep in mind this sample has been tested with Chrome ' + 48 + '.');
}
}
</script>
<!--
<script>
var myCharacteristic;
function onStartButtonClick() {
let serviceUuid = '0xffb0';
if (serviceUuid.startsWith('0x')) {
serviceUuid = parseInt(serviceUuid);
}
let characteristicUuid = '0xffb3';
if (characteristicUuid.startsWith('0x')) {
characteristicUuid = parseInt(characteristicUuid);
}
log('Requesting Bluetooth Device...');
navigator.bluetooth.requestDevice({ filters: [{ services: [serviceUuid] }] })
.then(device => {
log('Connecting to GATT Server...');
return device.gatt.connect();
})
.then(server => {
log('Getting Service...');
return server.getPrimaryService(serviceUuid);
})
.then(service => {
log('Getting Characteristic...');
return service.getCharacteristic(characteristicUuid);
})
.then(characteristic => {
myCharacteristic = characteristic;
return myCharacteristic.startNotifications().then(_ => {
log('> Notifications started');
myCharacteristic.addEventListener('characteristicvaluechanged',
handleNotifications);
});
})
.catch(error => {
log('Argh! ' + error);
});
}
function onStopButtonClick() {
if (myCharacteristic) {
myCharacteristic.stopNotifications()
.then(_ => {
log('> Notifications stopped');
myCharacteristic.removeEventListener('characteristicvaluechanged',
handleNotifications);
})
.catch(error => {
log('Argh! ' + error);
});
}
}
function handleNotifications(event) {
let value = event.target.value;
let a = [];
// Convert raw data bytes to hex values just for the sake of showing something.
// In the "real" world, you'd use data.getUint8, data.getUint16 or even
// TextDecoder to process raw data bytes.
for (let i = 0; i < 1; i++) {
a.push(value.getUint8(i).toString());
}
log('> ' + a.join(' '));
}
var w;
function setup() {
createCanvas(windowWidth, windowHeight);
w1 = new Wave(width / 2, height / 2, 1, 200, width);
}
function draw() {
background(0, 0, 0, 10);
w1.barwid = map(mouseX, 0, width, 5, 1);
w1.maxhei = map(mouseY, 0, height, height, 1);
w1.display();
}
//Wave Object
function Wave(x, y, barwid, maxhei, amount) {
//Initial Variables
//Coords
this.x = x;
this.y = y;
//Bar Properties
this.maxhei = maxhei;
this.amount = amount;
this.barwid = barwid;
//noStroke();
rectMode(CENTER);
//Display
this.display = function () {
for (this.i = 0; this.i < this.amount; this.i++) {
//Time in milliseconds/600 for smoothe transitions
this.time = millis() / 600;
//Cycling colors depending on time
this.r = map(sin(this.time + this.i / 90), -1, 1, 0, 255);
this.g = map(sin(this.time + 22.5 + this.i / 90), -1, 1, 0, 255);
this.b = map(sin(this.time + 45 + this.i / 90), -1, 1, 0, 255);
fill(this.r, this.g, this.b);
//Hight depending on time and i
this.hei = map(sin(this.i / 90 + this.time), -1, 1, 0, this.maxhei);
//Actual Draw
strokeWeight(1);
stroke(this.g, this.b, this.r);
rect(this.x + this.i * this.barwid - this.amount * this.barwid / 2, this.y, this.barwid + 2, this.hei);
}
}
}
</script>
-->
<script>
document.querySelector('#startNotifications').addEventListener('click', function (event) {
event.stopPropagation();
event.preventDefault();
if (isWebBluetoothEnabled()) {
ChromeSamples.clearLog();
onStartButtonClick();
}
});
document.querySelector('#stopNotifications').addEventListener('click', function (event) {
event.stopPropagation();
event.preventDefault();
if (isWebBluetoothEnabled()) {
onStopButtonClick();
}
});
</script>
<script>
log = ChromeSamples.log;
function isWebBluetoothEnabled() {
if (navigator.bluetooth) {
return true;
} else {
ChromeSamples.setStatus('Web Bluetooth API is not available.\n' +
'Please make sure the "Experimental Web Platform features" flag is enabled.');
return false;
}
}
</script>
<!-- <script>
/* jshint ignore:start */
(function (i, s, o, g, r, a, m) {
i['GoogleAnalyticsObject'] = r; i[r] = i[r] || function () {
(i[r].q = i[r].q || []).push(arguments)
}, i[r].l = 1 * new Date(); a = s.createElement(o),
m = s.getElementsByTagName(o)[0]; a.async = 1; a.src = g; m.parentNode.insertBefore(a, m)
})(window, document, 'script', 'https://www.google-analytics.com/analytics.js', 'ga');
ga('create', 'UA-53563471-1', 'auto');
ga('send', 'pageview');
/* jshint ignore:end */
</script> -->
</body>
</html>