bthrm fixes for reading characteristics generally and displaying location

pull/1655/head
Salim Blume 2022-04-04 16:48:15 -05:00
parent d89db8f7d7
commit 75c4e5b54b
3 changed files with 23 additions and 13 deletions

View File

@ -168,14 +168,14 @@
//Body sensor location
handler: function(data){
if (!lastReceivedData["0x180d"]) lastReceivedData["0x180d"] = {};
if (!lastReceivedData["0x180d"]["0x2a38"]) lastReceivedData["0x180d"]["0x2a38"] = data.target.value;
lastReceivedData["0x180d"]["0x2a38"] = parseInt(data.buffer, 10);
}
},
"0x2a19": {
//Battery
handler: function (event){
if (!lastReceivedData["0x180f"]) lastReceivedData["0x180f"] = {};
if (!lastReceivedData["0x180f"]["0x2a19"]) lastReceivedData["0x180f"]["0x2a19"] = event.target.value.getUint8(0);
if (!lastReceivedData["0x180f"]) lastReceivedData["0x180f"] = { "0x2a19": null };
lastReceivedData["0x180f"]["0x2a19"] = event.target.value.getUint8(0);
}
}
@ -295,12 +295,13 @@
}
return startPromise;
});
} else if (newCharacteristic.read){
} else if (newCharacteristic.readValue){
result = result.then(()=>{
// readData(newCharacteristic);
log("Reading data for " + newCharacteristic);
return newCharacteristic.read().then((data)=>{
supportedCharacteristics[newCharacteristic.uuid].handler(data);
log("Reading data for " + JSON.stringify(newCharacteristic));
return newCharacteristic.readValue().then((data)=>{
if (supportedCharacteristics[newCharacteristic.uuid] && supportedCharacteristics[newCharacteristic.uuid].handler) {
supportedCharacteristics[newCharacteristic.uuid].handler(data);
}
});
});
}

View File

@ -1,7 +1,16 @@
var btm = g.getHeight()-1;
var intervalInt;
var intervalBt;
var BODY_LOCS = {
0: 'Other',
1: 'Chest',
2: 'Wrist',
3: 'Finger',
4: 'Hand',
5: 'Ear Lobe',
6: 'Foot',
}
function clear(y){
g.reset();
g.clearRect(0,y,g.getWidth(),y+75);
@ -25,7 +34,7 @@ function draw(y, type, event) {
if (event.battery) str += " Bat: " + (event.battery ? event.battery : "");
g.setFontVector(12).drawString(str,px,y+40);
str= "";
if (event.location) str += "Loc: " + event.location.toFixed(0) + "ms";
if (event.location) str += "Loc: " + BODY_LOCS[event.location];
if (event.rr && event.rr.length > 0) str += " RR: " + event.rr.join(",");
g.setFontVector(12).drawString(str,px,y+50);
str= "";

View File

@ -158,9 +158,9 @@ declare type Image = {
};
declare type GraphicsApi = {
reset: () => void;
reset: () => GraphicsApi;
flip: () => void;
setColor: (color: string) => void; // TODO we can most likely type color more usefully than this
setColor: (color: string) => GraphicsApi; // TODO we can most likely type color more usefully than this
drawImage: (
image: string | Image | ArrayBuffer,
xOffset: number,
@ -169,7 +169,7 @@ declare type GraphicsApi = {
rotate?: number;
scale?: number;
}
) => void;
) => GraphicsApi;
// TODO add more
};