Encode all barometer service data in a single function
parent
f15d264a68
commit
0fa290be68
|
|
@ -105,7 +105,7 @@ function transmitUpdatedSensorData() {
|
||||||
let data = [ APP_ADVERTISING_DATA ]; // Always advertise at least app name
|
let data = [ APP_ADVERTISING_DATA ]; // Always advertise at least app name
|
||||||
|
|
||||||
if(isNewBarData) {
|
if(isNewBarData) {
|
||||||
data.push({ 0x2a6e: encodeTemperature(bar.temperature) });
|
data.push(encodeBarServiceData());
|
||||||
isNewBarData = false;
|
isNewBarData = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -118,11 +118,12 @@ function transmitUpdatedSensorData() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Convert temperature to signed 16-bit integer byte array
|
// Encode the bar service data to fit in a Bluetooth PDU
|
||||||
// TODO: implement negative temperature as signed int
|
function encodeBarServiceData() {
|
||||||
function encodeTemperature(temperature) {
|
// TODO: implement negative temperature as signed int
|
||||||
return [ Math.round(bar.temperature * 100) & 0xff,
|
let encodedTemperature = [ Math.round(bar.temperature * 100) & 0xff,
|
||||||
(Math.round(bar.temperature * 100) >> 8) & 0xff ];
|
(Math.round(bar.temperature * 100) >> 8) & 0xff ];
|
||||||
|
return { 0x2a6e: encodedTemperature };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue