Store the timestamp of the last Bluetooth DATA input report received on the interrupt channel

This can be used detect if the connection to a Bluetooth device is lost fx if the battery runs out or it gets out of range
This commit is contained in:
Kristian Sloth Lauszus 2021-01-26 23:41:05 +01:00
parent 8758b2fc25
commit b4bbfecd09
2 changed files with 13 additions and 0 deletions

View file

@ -337,6 +337,8 @@ void BTHID::ACLData(uint8_t* l2capinbuf) {
}
#endif
if(l2capinbuf[8] == 0xA1) { // HID BT DATA (0xA0) | Report Type (Input 0x01)
lastBtDataInputIntMillis = (uint32_t)millis(); // Store the timestamp of the report
uint16_t length = ((uint16_t)l2capinbuf[5] << 8 | l2capinbuf[4]);
ParseBTHIDData((uint8_t)(length - 1), &l2capinbuf[9]); // First byte will be the report ID

11
BTHID.h
View file

@ -93,6 +93,15 @@ public:
pBtd->pairWithHID();
};
/**
* Used to get the millis() of the last Bluetooth DATA input report received on the interrupt channel.
* This can be used detect if the connection to a Bluetooth device is lost fx if the battery runs out or if it gets out of range.
* @return Timestamp in milliseconds of the last Bluetooth DATA input report received on the interrupt channel.
*/
uint32_t getLastMessageTime() {
return lastBtDataInputIntMillis;
};
protected:
/** @name BluetoothService implementation */
/**
@ -173,5 +182,7 @@ private:
uint8_t interrupt_dcid[2]; // L2CAP device CID for HID_Interrupt - Always 0x0071
uint8_t sdp_dcid[2];
uint8_t l2cap_state;
uint32_t lastBtDataInputIntMillis; // Variable used to store the millis value of the last Bluetooth DATA input report received on the interrupt channel
};
#endif