From 7469ff099e612e3d348b882a9fae37f5d5c280e4 Mon Sep 17 00:00:00 2001 From: Kristian Lauszus Date: Sun, 12 Jan 2014 16:31:47 +0100 Subject: [PATCH] Typos, whitespace and some other cleanup stuff --- BTD.cpp | 8 +++--- BTD.h | 34 ++++++++++++------------ PS4BT.cpp | 12 ++++----- examples/Bluetooth/BTHID/BTHID.ino | 10 +++---- examples/Bluetooth/PS3BT/PS3BT.ino | 4 +-- examples/Bluetooth/PS3Multi/PS3Multi.ino | 2 +- examples/Bluetooth/PS3SPP/PS3SPP.ino | 4 +-- examples/Bluetooth/PS4BT/PS4BT.ino | 1 + 8 files changed, 38 insertions(+), 37 deletions(-) diff --git a/BTD.cpp b/BTD.cpp index b646b160..9b0d8ab5 100755 --- a/BTD.cpp +++ b/BTD.cpp @@ -36,7 +36,7 @@ qNextPollTime(0), // Reset NextPollTime pollInterval(0), bPollEnable(false) // Don't start polling before dongle is connected { - for(uint8_t i = 0; i < BTD_NUMSERVICES; i++) + for(uint8_t i = 0; i < BTD_NUM_SERVICES; i++) btService[i] = NULL; Initialize(); // Set all variables, endpoint structs etc. to default values @@ -293,7 +293,7 @@ void BTD::Initialize() { epInfo[i].epAttribs = 0; epInfo[i].bmNakPower = (i) ? USB_NAK_NOWAIT : USB_NAK_MAX_POWER; } - for(i = 0; i < BTD_NUMSERVICES; i++) { + for(i = 0; i < BTD_NUM_SERVICES; i++) { if(btService[i]) btService[i]->Reset(); // Reset all Bluetooth services } @@ -898,7 +898,7 @@ void BTD::ACL_event_task() { if(!rcode) { // Check for errors if(length > 0) { // Check if any data was read - for(uint8_t i = 0; i < BTD_NUMSERVICES; i++) { + for(uint8_t i = 0; i < BTD_NUM_SERVICES; i++) { if(btService[i]) btService[i]->ACLData(l2capinbuf); } @@ -910,7 +910,7 @@ void BTD::ACL_event_task() { D_PrintHex (rcode, 0x80); } #endif - for(uint8_t i = 0; i < BTD_NUMSERVICES; i++) + for(uint8_t i = 0; i < BTD_NUM_SERVICES; i++) if(btService[i]) btService[i]->Run(); } diff --git a/BTD.h b/BTD.h index 0fa6de70..609b8c2a 100755 --- a/BTD.h +++ b/BTD.h @@ -187,7 +187,7 @@ #define WI_PROTOCOL_BT 0x01 // Bluetooth Programming Interface #define BTD_MAX_ENDPOINTS 4 -#define BTD_NUMSERVICES 4 // Max number of Bluetooth services - if you need more than 4 simply increase this number +#define BTD_NUM_SERVICES 4 // Max number of Bluetooth services - if you need more than 4 simply increase this number #define PAIR 1 @@ -237,7 +237,7 @@ public: /** @name USBDeviceConfig implementation */ /** - * Address assignment and basic initilization is done here. + * Address assignment and basic initialization is done here. * @param parent Hub number. * @param port Port number on the hub. * @param lowspeed Speed of the device. @@ -258,7 +258,7 @@ public: */ virtual uint8_t Release(); /** - * Poll the USB Input endpoins and run the state machines. + * Poll the USB Input endpoints and run the state machines. * @return 0 on success. */ virtual uint8_t Poll(); @@ -320,18 +320,18 @@ public: /** Disconnects both the L2CAP Channel and the HCI Connection for all Bluetooth services. */ void disconnect() { - for(uint8_t i = 0; i < BTD_NUMSERVICES; i++) + for(uint8_t i = 0; i < BTD_NUM_SERVICES; i++) if(btService[i]) btService[i]->disconnect(); }; /** - * Register bluetooth dongle members/services. + * Register Bluetooth dongle members/services. * @param pService Pointer to BluetoothService class instance. - * @return The serice ID on succes or -1 on fail. + * @return The service ID on success or -1 on fail. */ int8_t registerServiceClass(BluetoothService *pService) { - for(uint8_t i = 0; i < BTD_NUMSERVICES; i++) { + for(uint8_t i = 0; i < BTD_NUM_SERVICES; i++) { if(!btService[i]) { btService[i] = pService; return i; // Return ID @@ -501,7 +501,7 @@ public: pairWithWii = true; hci_state = HCI_CHECK_DEVICE_SERVICE; }; - /** Used to only send the ACL data to the wiimote. */ + /** Used to only send the ACL data to the Wiimote. */ bool connectToWii; /** True if a Wiimote is connecting. */ bool incomingWii; @@ -517,7 +517,7 @@ public: pairWithHIDDevice = true; hci_state = HCI_CHECK_DEVICE_SERVICE; }; - /** Used to only send the ACL data to the wiimote. */ + /** Used to only send the ACL data to the Wiimote. */ bool connectToHIDDevice; /** True if a Wiimote is connecting. */ bool incomingHIDDevice; @@ -564,7 +564,7 @@ protected: private: void Initialize(); // Set all variables, endpoint structs etc. to default values - BluetoothService* btService[BTD_NUMSERVICES]; + BluetoothService *btService[BTD_NUM_SERVICES]; uint16_t PID, VID; // PID and VID of device connected @@ -575,15 +575,15 @@ private: uint8_t classOfDevice[3]; // Class of device of last device /* Variables used by high level HCI task */ - uint8_t hci_state; //current state of bluetooth hci connection - uint16_t hci_counter; // counter used for bluetooth hci reset loops - uint16_t hci_num_reset_loops; // this value indicate how many times it should read before trying to reset - uint16_t hci_event_flag; // hci flags of received bluetooth events + uint8_t hci_state; // Current state of Bluetooth HCI connection + uint16_t hci_counter; // Counter used for Bluetooth HCI reset loops + uint16_t hci_num_reset_loops; // This value indicate how many times it should read before trying to reset + uint16_t hci_event_flag; // HCI flags of received Bluetooth events uint8_t inquiry_counter; - uint8_t hcibuf[BULK_MAXPKTSIZE]; //General purpose buffer for hci data - uint8_t l2capinbuf[BULK_MAXPKTSIZE]; //General purpose buffer for l2cap in data - uint8_t l2capoutbuf[14]; //General purpose buffer for l2cap out data + uint8_t hcibuf[BULK_MAXPKTSIZE]; // General purpose buffer for HCI data + uint8_t l2capinbuf[BULK_MAXPKTSIZE]; // General purpose buffer for L2CAP in data + uint8_t l2capoutbuf[14]; // General purpose buffer for L2CAP out data /* State machines */ void HCI_event_task(); // Poll the HCI event pipe diff --git a/PS4BT.cpp b/PS4BT.cpp index abab9cfc..1459761e 100644 --- a/PS4BT.cpp +++ b/PS4BT.cpp @@ -48,9 +48,9 @@ const uint8_t PS4_BUTTONS[] PROGMEM = { /** Analog buttons on the controller */ const uint8_t PS4_ANALOG_BUTTONS[] PROGMEM = { - 0, 0, 0, 0, 0, 0, 0, 0, // Skip UP_ANALOG, RIGHT_ANALOG, DOWN_ANALOG, LEFT_ANALOG, SELECT, L3, R3 and START - 0, // L2_ANALOG - 1, // R2_ANALOG + 0, 0, 0, 0, 0, 0, 0, 0, // Skip UP, RIGHT, DOWN, LEFT, SHARE, OPTIONS, L3, and R3 + 0, // L2 + 1, // R2 }; bool PS4BT::checkDpad(PS4Buttons ps4Buttons, DPADEnum b) { @@ -59,7 +59,7 @@ bool PS4BT::checkDpad(PS4Buttons ps4Buttons, DPADEnum b) { bool PS4BT::getButtonPress(ButtonEnum b) { uint8_t button = pgm_read_byte(&PS4_BUTTONS[(uint8_t)b]); - if (b < 4) // Dpad + if (b <= LEFT) // Dpad return checkDpad(ps4Data.btn, (DPADEnum)button); else { uint8_t index = button < 8 ? 0 : button < 16 ? 1 : 2; @@ -70,7 +70,7 @@ bool PS4BT::getButtonPress(ButtonEnum b) { bool PS4BT::getButtonClick(ButtonEnum b) { uint8_t button = pgm_read_byte(&PS4_BUTTONS[(uint8_t)b]); - if (b < 4) { // Dpad + if (b <= LEFT) { // Dpad if (checkDpad(buttonClickState, (DPADEnum)button)) { buttonClickState.dpad = DPAD_OFF; return true; @@ -87,7 +87,7 @@ bool PS4BT::getButtonClick(ButtonEnum b) { } uint8_t PS4BT::getAnalogButton(ButtonEnum a) { - return (uint8_t)(ps4Data.trigger[pgm_read_byte(&PS4_ANALOG_BUTTONS[(uint8_t)a])]); + return ps4Data.trigger[pgm_read_byte(&PS4_ANALOG_BUTTONS[(uint8_t)a])]; } uint8_t PS4BT::getAnalogHat(AnalogHatEnum a) { diff --git a/examples/Bluetooth/BTHID/BTHID.ino b/examples/Bluetooth/BTHID/BTHID.ino index a38411b5..fcfd686a 100644 --- a/examples/Bluetooth/BTHID/BTHID.ino +++ b/examples/Bluetooth/BTHID/BTHID.ino @@ -20,7 +20,7 @@ BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so /* You can create the instance of the class in two ways */ // This will start an inquiry and then pair with your device - you only have to do this once // If you are using a Bluetooth keyboard, then you should type in the password on the keypad and then press enter -BTHID hid(&Btd, PAIR, "0000"); +BTHID bthid(&Btd, PAIR, "0000"); // After that you can simply create the instance like so and then press any button on the device //BTHID hid(&Btd); @@ -36,13 +36,13 @@ void setup() { while (1); // Halt } - hid.SetReportParser(KEYBOARD_PARSER_ID, (HIDReportParser*)&keyboardPrs); - hid.SetReportParser(MOUSE_PARSER_ID, (HIDReportParser*)&mousePrs); + bthid.SetReportParser(KEYBOARD_PARSER_ID, (HIDReportParser*)&keyboardPrs); + bthid.SetReportParser(MOUSE_PARSER_ID, (HIDReportParser*)&mousePrs); // If "Boot Protocol Mode" does not work, then try "Report Protocol Mode" // If that does not work either, then uncomment PRINTREPORT in BTHID.cpp to see the raw report - hid.setProtocolMode(HID_BOOT_PROTOCOL); // Boot Protocol Mode - //hid.setProtocolMode(HID_RPT_PROTOCOL); // Report Protocol Mode + bthid.setProtocolMode(HID_BOOT_PROTOCOL); // Boot Protocol Mode + //bthid.setProtocolMode(HID_RPT_PROTOCOL); // Report Protocol Mode Serial.print(F("\r\nHID Bluetooth Library Started")); } diff --git a/examples/Bluetooth/PS3BT/PS3BT.ino b/examples/Bluetooth/PS3BT/PS3BT.ino index 3cb0ae7a..982eb384 100644 --- a/examples/Bluetooth/PS3BT/PS3BT.ino +++ b/examples/Bluetooth/PS3BT/PS3BT.ino @@ -17,7 +17,7 @@ USB Usb; BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so /* You can create the instance of the class in two ways */ PS3BT PS3(&Btd); // This will just create the instance -//PS3BT PS3(&Btd,0x00,0x15,0x83,0x3D,0x0A,0x57); // This will also store the bluetooth address - this can be obtained from the dongle when running the sketch +//PS3BT PS3(&Btd, 0x00, 0x15, 0x83, 0x3D, 0x0A, 0x57); // This will also store the bluetooth address - this can be obtained from the dongle when running the sketch boolean printTemperature; boolean printAngle; @@ -52,7 +52,7 @@ void loop() { if (PS3.getAnalogButton(L2) || PS3.getAnalogButton(R2)) { Serial.print(F("\r\nL2: ")); Serial.print(PS3.getAnalogButton(L2)); - if (!PS3.PS3NavigationConnected) { + if (PS3.PS3Connected) { Serial.print(F("\tR2: ")); Serial.print(PS3.getAnalogButton(R2)); } diff --git a/examples/Bluetooth/PS3Multi/PS3Multi.ino b/examples/Bluetooth/PS3Multi/PS3Multi.ino index 9ce39857..23e8cd9a 100644 --- a/examples/Bluetooth/PS3Multi/PS3Multi.ino +++ b/examples/Bluetooth/PS3Multi/PS3Multi.ino @@ -56,7 +56,7 @@ void loop() { if (PS3[i]->getAnalogButton(L2) || PS3[i]->getAnalogButton(R2)) { Serial.print(F("\r\nL2: ")); Serial.print(PS3[i]->getAnalogButton(L2)); - if (!PS3[i]->PS3NavigationConnected) { + if (PS3[i]->PS3Connected) { Serial.print(F("\tR2: ")); Serial.print(PS3[i]->getAnalogButton(R2)); } diff --git a/examples/Bluetooth/PS3SPP/PS3SPP.ino b/examples/Bluetooth/PS3SPP/PS3SPP.ino index 6bc7afc6..440ea79e 100644 --- a/examples/Bluetooth/PS3SPP/PS3SPP.ino +++ b/examples/Bluetooth/PS3SPP/PS3SPP.ino @@ -26,7 +26,7 @@ BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so SPP SerialBT(&Btd); // This will set the name to the defaults: "Arduino" and the pin to "0000" //SPP SerialBTBT(&Btd,"Lauszus's Arduino","0000"); // You can also set the name and pin like so PS3BT PS3(&Btd); // This will just create the instance -//PS3BT PS3(&Btd,0x00,0x15,0x83,0x3D,0x0A,0x57); // This will also store the bluetooth address - this can be obtained from the dongle when running the sketch +//PS3BT PS3(&Btd, 0x00, 0x15, 0x83, 0x3D, 0x0A, 0x57); // This will also store the bluetooth address - this can be obtained from the dongle when running the sketch boolean firstMessage = true; String output = ""; // We will store the data in this string @@ -77,7 +77,7 @@ void loop() { output += "\r\n"; output += "L2: "; output += PS3.getAnalogButton(L2); - if (!PS3.PS3NavigationConnected) { + if (PS3.PS3Connected) { output += "\tR2: "; output += PS3.getAnalogButton(R2); } diff --git a/examples/Bluetooth/PS4BT/PS4BT.ino b/examples/Bluetooth/PS4BT/PS4BT.ino index 220014e2..6715b904 100644 --- a/examples/Bluetooth/PS4BT/PS4BT.ino +++ b/examples/Bluetooth/PS4BT/PS4BT.ino @@ -18,6 +18,7 @@ BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so /* You can create the instance of the BTHID class in two ways */ // This will start an inquiry and then pair with the PS4 controller - you only have to do this once +// You will need to hold down the PS and Share button at the same time, the PS4 controller will then start to blink rapidly indicating that it is in paring mode BTHID bthid(&Btd, PAIR); // After that you can simply create the instance like so and then press the PS button on the device