|
|
|
|
@ -16,9 +16,14 @@ const isArray = (maybeArray) =>
|
|
|
|
|
const isEmptyArray = (maybeArray) =>
|
|
|
|
|
isArray(maybeArray) && maybeArray.length === 0;
|
|
|
|
|
|
|
|
|
|
const getClosestDevices = () => {
|
|
|
|
|
console.warn("getClosestDevices NOT IMPLEMENTED YET");
|
|
|
|
|
return [];
|
|
|
|
|
const getClosestDevices = (repo) => {
|
|
|
|
|
const sortByRssi = (d1, d2) => d1.rssi > d2.rssi;
|
|
|
|
|
|
|
|
|
|
const cadSensors = repo.cad_sensors.sort(sortByRssi);
|
|
|
|
|
const hrSensors = repo.hr_sensors.sort(sortByRssi);
|
|
|
|
|
const trainers = repo.trainers.sort(sortByRssi);
|
|
|
|
|
|
|
|
|
|
return [hrSensors[0], cadSensors[0], trainers[0]];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const isRepoEmpty = (repo) =>
|
|
|
|
|
@ -27,12 +32,13 @@ const isRepoEmpty = (repo) =>
|
|
|
|
|
(!repo.trainers || isEmptyArray(repo.trainers));
|
|
|
|
|
|
|
|
|
|
window.addEventListener("DOMContentLoaded", async () => {
|
|
|
|
|
console.log("hello from main js");
|
|
|
|
|
const [savedDevices, scannedDevices] = await Promise.all([
|
|
|
|
|
readRepo(),
|
|
|
|
|
scan(),
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
console.log(savedDevices);
|
|
|
|
|
console.log(savedDevices, scannedDevices);
|
|
|
|
|
|
|
|
|
|
if (isRepoEmpty(savedDevices)) {
|
|
|
|
|
const closest = getClosestDevices(scannedDevices);
|
|
|
|
|
|