mirror of
https://github.com/servo/servo.git
synced 2025-07-10 00:43:39 +01:00
57 lines
2.2 KiB
HTML
57 lines
2.2 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<title>Descriptor info</title>
|
|
<body>
|
|
<input id="service" type="text" autofocus placeholder="Bluetooth Service">
|
|
<input id="characteristic" type="text" autofocus placeholder="Bluetooth Characteristic">
|
|
<input id="descriptor" type="text" autofocus placeholder="Bluetooth Descriptor">
|
|
<button type="button" onclick="onButtonClick()">Get Descriptor 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;
|
|
var descriptorUuid = document.getElementById('descriptor').value;
|
|
|
|
if (!serviceUuid || !characteristicUuid || !descriptorUuid) {
|
|
return log('All input field must be filled!');
|
|
}
|
|
if (serviceUuid.startsWith('0x'))
|
|
serviceUuid = parseInt(serviceUuid, 16);
|
|
|
|
if (characteristicUuid.startsWith('0x'))
|
|
characteristicUuid = parseInt(characteristicUuid, 16);
|
|
|
|
if (descriptorUuid.startsWith('0x'))
|
|
descriptorUuid = parseInt(descriptorUuid, 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('Getting Descriptor...');
|
|
var descriptor = characteristic.getDescriptor(descriptorUuid);
|
|
|
|
log('Descriptor found!');
|
|
log('> Descriptor characteristic: ' + descriptor.characteristic.uuid);
|
|
log('> Descriptor UUID: ' + descriptor.uuid);
|
|
descriptor.readValue();
|
|
log('> Descriptor value: ' + asciiToDecimal(descriptor.value));
|
|
} catch(err) {
|
|
log(err);
|
|
}
|
|
}
|
|
</script>
|
|
</body>
|
|
</html>
|