Once connected to a BLE device clicking on FAB will disconnect from device

This commit is contained in:
Peter Stockings
2023-01-26 22:27:03 +11:00
parent e9be507254
commit fa9af6a512

View File

@@ -37,8 +37,11 @@ async function disconnect() {
"characteristicvaluechanged",
handleNotifications
);
btn.classList.remove("bg-green-600");
btn.classList.add("bg-blue-600");
} catch (error) {
log("Argh! " + error);
console.log("Argh! " + error);
swal("Oops", error, "error");
}
}
}
@@ -71,7 +74,6 @@ function parseCSC(e) {
if (prevRes) {
let rpm = revsToRPM(prevRes, res);
if (rpm > 0)
//socket.emit("message", { rpm: parseFloat(rpm.toFixed(2)), id: 1 });
fetch("/cadence", {
method: "POST",
headers: {
@@ -103,10 +105,14 @@ function revsToRPM(prevRes, res) {
return rpm;
}
btn.addEventListener("click", () =>
connect({
onChange: parseCSC,
}).catch((err) => {
swal("Oops", err, "error");
})
);
btn.addEventListener("click", () => {
if (!characteristic) {
connect({
onChange: parseCSC,
}).catch((err) => {
swal("Oops", err, "error");
});
} else {
disconnect();
}
});