Once connected to a BLE device clicking on FAB will disconnect from device
This commit is contained in:
@@ -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", () =>
|
||||
btn.addEventListener("click", () => {
|
||||
if (!characteristic) {
|
||||
connect({
|
||||
onChange: parseCSC,
|
||||
}).catch((err) => {
|
||||
swal("Oops", err, "error");
|
||||
})
|
||||
);
|
||||
});
|
||||
} else {
|
||||
disconnect();
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user