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