From c5c761aec5e708cd1918d91eb634b8e0658aa0c6 Mon Sep 17 00:00:00 2001 From: Kristian Lauszus Date: Tue, 9 Sep 2014 16:39:57 -0700 Subject: [PATCH] Reduced code size in PS3BT by removing some unnecessary variables --- PS3BT.cpp | 19 +++++++++---------- PS3BT.h | 6 ++---- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/PS3BT.cpp b/PS3BT.cpp index fbd4e5f0..235092e0 100644 --- a/PS3BT.cpp +++ b/PS3BT.cpp @@ -229,8 +229,7 @@ void PS3BT::ACLData(uint8_t* ACLData) { activeConnection = true; hci_handle = pBtd->hci_handle; // Store the HCI Handle for the connection l2cap_state = L2CAP_WAIT; - for(uint8_t i = 0; i < 30; i++) - remote_name[i] = pBtd->remote_name[i]; // Store the remote name for the connection + remote_name_first = pBtd->remote_name[0]; // Store the first letter in remote name for the connection #ifdef DEBUG_USB_HOST if(pBtd->hci_version < 3) { // Check the HCI Version of the Bluetooth dongle Notify(PSTR("\r\nYour dongle may not support reading the analog buttons, sensors and status\r\nYour HCI Version is: "), 0x80); @@ -416,7 +415,7 @@ void PS3BT::L2CAP_task() { #ifdef DEBUG_USB_HOST Notify(PSTR("\r\nHID Interrupt Successfully Configured"), 0x80); #endif - if(remote_name[0] == 'M') { // First letter in Motion Controller ('M') + if(remote_name_first == 'M') { // First letter in Motion Controller ('M') memset(l2capinbuf, 0, BULK_MAXPKTSIZE); // Reset l2cap in buffer as it sometimes read it as a button has been pressed l2cap_state = TURN_ON_LED; } else @@ -467,18 +466,18 @@ void PS3BT::Run() { case TURN_ON_LED: if(millis() - timer > 1000) { // loop 1 second before sending the command - if(remote_name[0] == 'P') { // First letter in PLAYSTATION(R)3 Controller ('P') + if(remote_name_first == 'P') { // First letter in PLAYSTATION(R)3 Controller ('P') #ifdef DEBUG_USB_HOST Notify(PSTR("\r\nDualshock 3 Controller Enabled\r\n"), 0x80); #endif PS3Connected = true; - } else if(remote_name[0] == 'N') { // First letter in Navigation Controller ('N') + } else if(remote_name_first == 'N') { // First letter in Navigation Controller ('N') #ifdef DEBUG_USB_HOST Notify(PSTR("\r\nNavigation Controller Enabled\r\n"), 0x80); #endif PS3NavigationConnected = true; - } else if(remote_name[0] == 'M') { // First letter in Motion Controller ('M') - timerBulbRumble = millis(); + } else if(remote_name_first == 'M') { // First letter in Motion Controller ('M') + timer = millis(); #ifdef DEBUG_USB_HOST Notify(PSTR("\r\nMotion Controller Enabled\r\n"), 0x80); #endif @@ -494,10 +493,10 @@ void PS3BT::Run() { break; case L2CAP_DONE: - if(PS3MoveConnected) { // The Bulb and rumble values, has to be send at aproximatly every 5th second for it to stay on - if(millis() - timerBulbRumble > 4000) { // Send at least every 4th second + if(PS3MoveConnected) { // The Bulb and rumble values, has to be send at approximately every 5th second for it to stay on + if(millis() - timer > 4000) { // Send at least every 4th second HIDMove_Command(HIDMoveBuffer, HID_BUFFERSIZE); // The Bulb and rumble values, has to be written again and again, for it to stay turned on - timerBulbRumble = millis(); + timer = millis(); } } break; diff --git a/PS3BT.h b/PS3BT.h index 17b7b0c9..faec2ca1 100644 --- a/PS3BT.h +++ b/PS3BT.h @@ -207,7 +207,7 @@ private: void L2CAP_task(); // L2CAP state machine /* Variables filled from HCI event management */ - uint8_t remote_name[30]; // First 30 chars of remote name + char remote_name_first; // First letter in remote name bool activeConnection; // Used to indicate if it's already has established a connection /* Variables used by high level L2CAP task */ @@ -215,14 +215,12 @@ private: uint32_t lastMessageTime; // Variable used to store the millis value of the last message. - uint32_t timer; - uint32_t ButtonState; uint32_t OldButtonState; uint32_t ButtonClickState; + uint32_t timer; // Timer used to limit time between messages and also used to continuously set PS3 Move controller Bulb and rumble values uint32_t timerHID; // Timer used see if there has to be a delay before a new HID command - uint32_t timerBulbRumble; // used to continuously set PS3 Move controller Bulb and rumble values uint8_t l2capinbuf[BULK_MAXPKTSIZE]; // General purpose buffer for L2CAP in data uint8_t HIDBuffer[HID_BUFFERSIZE]; // Used to store HID commands