2019-11-11 16:59:02 +00:00
|
|
|
// ble-scanner
|
|
|
|
// Scan the airwaves every three seconds (which seems safe for a large number of devices)
|
|
|
|
// Using the menu feature, display a scrollable list of BLE devices on the watch
|
|
|
|
|
|
|
|
// Dummy menu item to display until we find something
|
|
|
|
const NODEVICE = 'No devices found';
|
|
|
|
|
|
|
|
const SCAN_INTERVAL = 3000;
|
|
|
|
|
|
|
|
const menu = {
|
|
|
|
};
|
|
|
|
|
|
|
|
menu[NODEVICE] = {
|
|
|
|
value : "",
|
|
|
|
onchange : () => {}
|
|
|
|
};
|
|
|
|
|
2020-01-17 11:32:32 +00:00
|
|
|
|
2019-11-11 16:59:02 +00:00
|
|
|
function draw() {
|
2020-01-17 11:32:32 +00:00
|
|
|
E.showMenu(menu);
|
2019-11-11 16:59:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function scan() {
|
|
|
|
NRF.findDevices(devices => {
|
2020-05-23 21:32:33 +00:00
|
|
|
for (let device of devices) {
|
|
|
|
|
|
|
|
// Only display devices that advertise a name
|
|
|
|
|
|
|
|
if (device.name) {
|
|
|
|
// Remove no devices found message if it is present
|
|
|
|
if (menu[NODEVICE]) {
|
|
|
|
delete menu[NODEVICE];
|
2019-11-11 16:59:02 +00:00
|
|
|
}
|
2020-05-23 21:32:33 +00:00
|
|
|
menu[device.name] = {
|
|
|
|
value : device.rssi,
|
|
|
|
onchange : () => {}
|
|
|
|
};
|
2019-11-11 16:59:02 +00:00
|
|
|
}
|
2020-05-23 21:32:33 +00:00
|
|
|
}
|
|
|
|
draw();
|
2019-11-11 16:59:02 +00:00
|
|
|
}, { active: true });
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function waitMessage() {
|
|
|
|
E.showMessage('scanning');
|
|
|
|
}
|
|
|
|
|
|
|
|
scan();
|
|
|
|
waitMessage();
|
|
|
|
|
|
|
|
setInterval(scan, SCAN_INTERVAL);
|