Skip to content

Commit 983a7d6

Browse files
committed
Added getLastMessageTime() - this is useful if you want to detect if the connection is lost with the PS3 controller
Credit: Thomas Frederick
1 parent 37d59a6 commit 983a7d6

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

PS3BT.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,8 @@ void PS3BT::ACLData(uint8_t* ACLData) {
343343
if(PS3Connected || PS3MoveConnected || PS3NavigationConnected) {
344344
/* Read Report */
345345
if(l2capinbuf[8] == 0xA1) { // HID_THDR_DATA_INPUT
346+
lastMessageTime = millis(); // Store the last message time
347+
346348
if(PS3Connected || PS3NavigationConnected)
347349
ButtonState = (uint32_t)(l2capinbuf[11] | ((uint16_t)l2capinbuf[12] << 8) | ((uint32_t)l2capinbuf[13] << 16));
348350
else if(PS3MoveConnected)

PS3BT.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,11 @@ class PS3BT : public BluetoothService {
179179
*/
180180
void moveSetRumble(uint8_t rumble);
181181

182+
/** Used to get the millis() of the last message */
183+
uint32_t getLastMessageTime() {
184+
return lastMessageTime;
185+
};
186+
182187
/**
183188
* Used to call your own function when the controller is successfully initialized.
184189
* @param funcOnInit Function to call.
@@ -214,10 +219,12 @@ class PS3BT : public BluetoothService {
214219
uint8_t remote_name[30]; // First 30 chars of remote name
215220
bool activeConnection; // Used to indicate if it's already has established a connection
216221

217-
/* variables used by high level L2CAP task */
222+
/* Variables used by high level L2CAP task */
218223
uint8_t l2cap_state;
219224
uint32_t l2cap_event_flag; // L2CAP flags of received Bluetooth events
220225

226+
uint32_t lastMessageTime; // Variable used to store the millis value of the last message.
227+
221228
unsigned long timer;
222229

223230
uint32_t ButtonState;

0 commit comments

Comments
 (0)