mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
Refactoring the WebBluetooth html tests.
This commit is contained in:
parent
9c0e7b1cf2
commit
5d3556a99d
23 changed files with 1112 additions and 119 deletions
58
tests/html/bluetooth/bluetooth_characteristic_info.html
Normal file
58
tests/html/bluetooth/bluetooth_characteristic_info.html
Normal file
|
@ -0,0 +1,58 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<title>Characteristic info</title>
|
||||
<body>
|
||||
<input id="service" type="text" autofocus placeholder="Bluetooth Service">
|
||||
<input id="characteristic" type="text" autofocus placeholder="Bluetooth Characteristic">
|
||||
<button type="button" onclick="onButtonClick()">Get Characteristic Info</button>
|
||||
<pre id="log"></pre>
|
||||
<script src="bluetooth_functions.js"></script>
|
||||
<script>
|
||||
function onButtonClick() {
|
||||
clear();
|
||||
var serviceUuid = document.getElementById('service').value;
|
||||
var characteristicUuid = document.getElementById('characteristic').value;
|
||||
|
||||
if (!serviceUuid || !characteristicUuid) {
|
||||
return log('All input field must be filled!');
|
||||
}
|
||||
if (serviceUuid.startsWith('0x'))
|
||||
serviceUuid = parseInt(serviceUuid, 16);
|
||||
|
||||
if (characteristicUuid.startsWith('0x'))
|
||||
characteristicUuid = parseInt(characteristicUuid, 16);
|
||||
|
||||
try {
|
||||
log('Requesting Bluetooth Device...');
|
||||
var device = window.navigator.bluetooth.requestDevice({filters: [{services: [serviceUuid]}]});
|
||||
|
||||
log('Connecting to GATTserver on device...');
|
||||
var server = device.gatt.connect();
|
||||
|
||||
log('Getting Primary Service...');
|
||||
var primaryService = server.getPrimaryService(serviceUuid);
|
||||
|
||||
log('Getting Characteristic...');
|
||||
var characteristic = primaryService.getCharacteristic(characteristicUuid);
|
||||
|
||||
log('Characteristic found!');
|
||||
log('> Characteristic service: ' + characteristic.service.uuid);
|
||||
log('> Characteristic UUID: ' + characteristic.uuid);
|
||||
log('> Broadcast: ' + characteristic.properties.broadcast);
|
||||
log('> Read: ' + characteristic.properties.read);
|
||||
log('> Write w/o response: ' + characteristic.properties.writeWithoutResponse);
|
||||
log('> Write: ' + characteristic.properties.write);
|
||||
log('> Notify: ' + characteristic.properties.notify);
|
||||
log('> Indicate: ' + characteristic.properties.indicate);
|
||||
log('> Signed Write: ' + characteristic.properties.authenticatedSignedWrites);
|
||||
log('> Queued Write: ' + characteristic.properties.reliableWrite);
|
||||
log('> Writable Auxiliaries: ' + characteristic.properties.writableAuxiliaries);
|
||||
characteristic.readValue();
|
||||
log('> Characteristic value: ' + asciiToDecimal(characteristic.value));
|
||||
} catch(err) {
|
||||
log(err);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Loading…
Add table
Add a link
Reference in a new issue