prettify a bit

This commit is contained in:
2022-04-18 16:39:29 +02:00
parent bbeb1eb420
commit d96af87629

View File

@@ -25,13 +25,13 @@ export function App() {
}); });
console.log("Found device:"); console.log("Found device:");
console.log(foundDevice); console.log(foundDevice);
await foundDevice.gatt.connect(); await foundDevice.gatt.connect();
foundDevice.ongattserverdisconnected = onDisconnect; foundDevice.ongattserverdisconnected = onDisconnect;
const doorService = await foundDevice.gatt.getPrimaryService( const doorService = await foundDevice.gatt.getPrimaryService(
doorServiceUUID, doorServiceUUID,
); );
const doorSwitch = await doorService.getCharacteristic(doorSwitchUUID); const doorSwitch = await doorService.getCharacteristic(doorSwitchUUID);
setDevice({ setDevice({
device: foundDevice, device: foundDevice,
@@ -40,11 +40,10 @@ export function App() {
}); });
const data = await (await doorSwitch.readValue()).getUint8(0); const data = await (await doorSwitch.readValue()).getUint8(0);
setDoorOpen(Boolean(data));
doorSwitch.oncharacteristicvaluechanged = onDoorUpdate; doorSwitch.oncharacteristicvaluechanged = onDoorUpdate;
doorSwitch.startNotifications(); doorSwitch.startNotifications();
setDoorOpen(Boolean(data));
} catch (error) { } catch (error) {
console.log("Error connecting:"); console.log("Error connecting:");
console.log(error); console.log(error);
@@ -62,6 +61,7 @@ export function App() {
const onDisconnect = async () => { const onDisconnect = async () => {
setDevice(null); setDevice(null);
setDoorOpen(null);
}; };
const onDisconnectClick = async () => { const onDisconnectClick = async () => {