Last active
February 22, 2021 10:03
-
-
Save gfwilliams/e3ddbf81f1619c6fb8a5604d7a56c30b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require("Font8x12").add(Graphics); | |
// List of devices | |
var devices = []; | |
// For each device discovered | |
function onDevice(dev) { | |
// work out the temperature | |
var info = { | |
id : dev.id.substr(0,17), | |
temp : new DataView(dev.serviceData["1809"]).getInt16(0,true)/100 | |
}; | |
// save the info in 'devices' list | |
var idx = devices.findIndex(d=>d.id == info.id); | |
if (idx>=0) devices[idx] = info; | |
else { | |
devices.push(info); | |
// Crop to 5 devices here? | |
} | |
} | |
// Scan for devices | |
NRF.setScan(onDevice, { filters: [{ serviceData:{"1809":{}} }] }); | |
// Display on screen | |
function show() { | |
if (!devices.length) | |
E.showMessage("No devices found"); | |
g.clear(1); | |
devices.forEach(function(info, idx) { | |
var y = idx*12; | |
g.setFont("4x6"); | |
g.drawString(info.id, 0, y+4); | |
g.setFont("8x12"); | |
g.drawString(info.temp, 90, y); | |
}); | |
g.flip(); | |
} | |
show(); | |
setInterval(show, 1000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment