mirror of
https://github.com/usatiuk/door-thing.git
synced 2025-10-26 19:17:49 +01:00
prettify a bit
This commit is contained in:
@@ -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 () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user