From 5b793db3e3123753c4f691ad8efeb97252b87287 Mon Sep 17 00:00:00 2001 From: Kristian Lauszus Date: Fri, 15 Nov 2013 23:19:10 +0100 Subject: [PATCH] Can now call setLedOff without any argument, to turn all LEDs off --- PS3BT.cpp | 23 +++++++++++-------- PS3BT.h | 4 ++++ PS3USB.h | 4 ++++ Wii.h | 6 +++-- examples/Bluetooth/PS3BT/PS3BT.ino | 8 +++---- examples/Bluetooth/PS3Multi/PS3Multi.ino | 8 +++---- examples/Bluetooth/PS3SPP/PS3SPP.ino | 8 +++---- examples/Bluetooth/Wii/Wii.ino | 8 +++---- examples/Bluetooth/WiiMulti/WiiMulti.ino | 8 +++---- .../WiiUProController/WiiUProController.ino | 8 +++---- examples/PS3USB/PS3USB.ino | 8 +++---- 11 files changed, 54 insertions(+), 39 deletions(-) diff --git a/PS3BT.cpp b/PS3BT.cpp index 7fb6b8b4..72c257d0 100644 --- a/PS3BT.cpp +++ b/PS3BT.cpp @@ -36,7 +36,7 @@ pBtd(p) // pointer to USB class instance - mandatory HIDBuffer[0] = 0x52; // HID BT Set_report (0x50) | Report Type (Output 0x02) HIDBuffer[1] = 0x01; // Report ID - //Needed for PS3 Move Controller commands to work via bluetooth + // Needed for PS3 Move Controller commands to work via bluetooth HIDMoveBuffer[0] = 0xA2; // HID BT DATA_request (0xA0) | Report Type (Output 0x02) HIDMoveBuffer[1] = 0x02; // Report ID @@ -529,16 +529,16 @@ void PS3BT::Run() { ButtonState = 0; // Clear all values OldButtonState = 0; ButtonClickState = 0; - + onInit(); // Turn on the LED on the controller l2cap_state = L2CAP_DONE; } 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 - HIDMove_Command(HIDMoveBuffer, HID_BUFFERSIZE); //The Bulb and rumble values, has to be written again and again, for it to stay turned on + 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 + 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(); } } @@ -560,8 +560,12 @@ void PS3BT::HID_Command(uint8_t* data, uint8_t nbytes) { } void PS3BT::setAllOff() { - for (uint8_t i = 0; i < PS3_REPORT_BUFFER_SIZE; i++) - HIDBuffer[i + 2] = pgm_read_byte(&PS3_REPORT_BUFFER[i]); // First two bytes reserved for report type and ID + HIDBuffer[3] = 0x00; // Rumble bytes + HIDBuffer[4] = 0x00; + HIDBuffer[5] = 0x00; + HIDBuffer[6] = 0x00; + + HIDBuffer[11] = 0x00; // LED byte HID_Command(HIDBuffer, HID_BUFFERSIZE); } @@ -596,6 +600,7 @@ void PS3BT::setLedRaw(uint8_t value) { HIDBuffer[11] = value << 1; HID_Command(HIDBuffer, HID_BUFFERSIZE); } + void PS3BT::setLedOff(LED a) { HIDBuffer[11] &= ~((uint8_t)((pgm_read_byte(&LEDS[(uint8_t)a]) & 0x0f) << 1)); HID_Command(HIDBuffer, HID_BUFFERSIZE); @@ -633,7 +638,7 @@ void PS3BT::HIDMove_Command(uint8_t* data, uint8_t nbytes) { } void PS3BT::moveSetBulb(uint8_t r, uint8_t g, uint8_t b) { //Use this to set the Color using RGB values - //set the Bulb's values into the write buffer + // Set the Bulb's values into the write buffer HIDMoveBuffer[3] = r; HIDMoveBuffer[4] = g; HIDMoveBuffer[5] = b; @@ -650,7 +655,7 @@ void PS3BT::moveSetRumble(uint8_t rumble) { if (rumble < 64 && rumble != 0) // The rumble value has to at least 64, or approximately 25% (64/255*100) Notify(PSTR("\r\nThe rumble value has to at least 64, or approximately 25%"), 0x80); #endif - //set the rumble value into the write buffer + // Set the rumble value into the write buffer HIDMoveBuffer[7] = rumble; HIDMove_Command(HIDMoveBuffer, HID_BUFFERSIZE); diff --git a/PS3BT.h b/PS3BT.h index 5b00232f..6b901402 100644 --- a/PS3BT.h +++ b/PS3BT.h @@ -176,6 +176,10 @@ public: * @param value See: ::LED enum. */ void setLedRaw(uint8_t value); + /** Turn all LEDs off. */ + void setLedOff() { + setLedRaw(0); + } /** * Turn the specific ::LED off. * @param a The ::LED to turn off. diff --git a/PS3USB.h b/PS3USB.h index 2fac0fbe..ae5314f4 100644 --- a/PS3USB.h +++ b/PS3USB.h @@ -220,6 +220,10 @@ public: * @param value See: ::LED enum. */ void setLedRaw(uint8_t value); + /** Turn all LEDs off. */ + void setLedOff() { + setLedRaw(0); + } /** * Turn the specific ::LED off. * @param a The ::LED to turn off. diff --git a/Wii.h b/Wii.h index f1ba6a90..f8d206ef 100755 --- a/Wii.h +++ b/Wii.h @@ -191,6 +191,10 @@ public: * @param value See: ::LED enum. */ void setLedRaw(uint8_t value); + /** Turn all LEDs off. */ + void setLedOff() { + setLedRaw(0); + } /** * Turn the specific ::LED off. * @param a The ::LED to turn off. @@ -210,9 +214,7 @@ public: * This will set the LEDs, so the user can see which connections are active. * * The first ::LED indicate that the Wiimote is connected, - * * the second ::LED indicate indicate that a Motion Plus is also connected - * * the third ::LED will indicate that a Nunchuck controller is also connected. */ void setLedStatus(); diff --git a/examples/Bluetooth/PS3BT/PS3BT.ino b/examples/Bluetooth/PS3BT/PS3BT.ino index 253f17b9..e98d5b73 100644 --- a/examples/Bluetooth/PS3BT/PS3BT.ino +++ b/examples/Bluetooth/PS3BT/PS3BT.ino @@ -69,28 +69,28 @@ void loop() { if (PS3.getButtonClick(UP)) { Serial.print(F("\r\nUp")); if (PS3.PS3Connected) { - PS3.setAllOff(); + PS3.setLedOff(); PS3.setLedOn(LED4); } } if (PS3.getButtonClick(RIGHT)) { Serial.print(F("\r\nRight")); if (PS3.PS3Connected) { - PS3.setAllOff(); + PS3.setLedOff(); PS3.setLedOn(LED1); } } if (PS3.getButtonClick(DOWN)) { Serial.print(F("\r\nDown")); if (PS3.PS3Connected) { - PS3.setAllOff(); + PS3.setLedOff(); PS3.setLedOn(LED2); } } if (PS3.getButtonClick(LEFT)) { Serial.print(F("\r\nLeft")); if (PS3.PS3Connected) { - PS3.setAllOff(); + PS3.setLedOff(); PS3.setLedOn(LED3); } } diff --git a/examples/Bluetooth/PS3Multi/PS3Multi.ino b/examples/Bluetooth/PS3Multi/PS3Multi.ino index 56f8da94..2471cfcc 100644 --- a/examples/Bluetooth/PS3Multi/PS3Multi.ino +++ b/examples/Bluetooth/PS3Multi/PS3Multi.ino @@ -74,28 +74,28 @@ void loop() { if (PS3[i]->getButtonClick(UP)) { Serial.print(F("\r\nUp")); if (PS3[i]->PS3Connected) { - PS3[i]->setAllOff(); + PS3[i]->setLedOff(); PS3[i]->setLedOn(LED4); } } if (PS3[i]->getButtonClick(RIGHT)) { Serial.print(F("\r\nRight")); if (PS3[i]->PS3Connected) { - PS3[i]->setAllOff(); + PS3[i]->setLedOff(); PS3[i]->setLedOn(LED1); } } if (PS3[i]->getButtonClick(DOWN)) { Serial.print(F("\r\nDown")); if (PS3[i]->PS3Connected) { - PS3[i]->setAllOff(); + PS3[i]->setLedOff(); PS3[i]->setLedOn(LED2); } } if (PS3[i]->getButtonClick(LEFT)) { Serial.print(F("\r\nLeft")); if (PS3[i]->PS3Connected) { - PS3[i]->setAllOff(); + PS3[i]->setLedOff(); PS3[i]->setLedOn(LED3); } } diff --git a/examples/Bluetooth/PS3SPP/PS3SPP.ino b/examples/Bluetooth/PS3SPP/PS3SPP.ino index 734de065..0263c10a 100644 --- a/examples/Bluetooth/PS3SPP/PS3SPP.ino +++ b/examples/Bluetooth/PS3SPP/PS3SPP.ino @@ -100,28 +100,28 @@ void loop() { if (PS3.getButtonClick(UP)) { output += " - Up"; if (PS3.PS3Connected) { - PS3.setAllOff(); + PS3.setLedOff(); PS3.setLedOn(LED4); } } if (PS3.getButtonClick(RIGHT)) { output += " - Right"; if (PS3.PS3Connected) { - PS3.setAllOff(); + PS3.setLedOff(); PS3.setLedOn(LED1); } } if (PS3.getButtonClick(DOWN)) { output += " - Down"; if (PS3.PS3Connected) { - PS3.setAllOff(); + PS3.setLedOff(); PS3.setLedOn(LED2); } } if (PS3.getButtonClick(LEFT)) { output += " - Left"; if (PS3.PS3Connected) { - PS3.setAllOff(); + PS3.setLedOff(); PS3.setLedOn(LED3); } } diff --git a/examples/Bluetooth/Wii/Wii.ino b/examples/Bluetooth/Wii/Wii.ino index e377ad24..d56b4252 100644 --- a/examples/Bluetooth/Wii/Wii.ino +++ b/examples/Bluetooth/Wii/Wii.ino @@ -34,22 +34,22 @@ void loop() { } else { if (Wii.getButtonClick(LEFT)) { - Wii.setAllOff(); + Wii.setLedOff(); Wii.setLedOn(LED1); Serial.print(F("\r\nLeft")); } if (Wii.getButtonClick(RIGHT)) { - Wii.setAllOff(); + Wii.setLedOff(); Wii.setLedOn(LED3); Serial.print(F("\r\nRight")); } if (Wii.getButtonClick(DOWN)) { - Wii.setAllOff(); + Wii.setLedOff(); Wii.setLedOn(LED4); Serial.print(F("\r\nDown")); } if (Wii.getButtonClick(UP)) { - Wii.setAllOff(); + Wii.setLedOff(); Wii.setLedOn(LED2); Serial.print(F("\r\nUp")); } diff --git a/examples/Bluetooth/WiiMulti/WiiMulti.ino b/examples/Bluetooth/WiiMulti/WiiMulti.ino index 518d9859..3036b908 100644 --- a/examples/Bluetooth/WiiMulti/WiiMulti.ino +++ b/examples/Bluetooth/WiiMulti/WiiMulti.ino @@ -42,22 +42,22 @@ void loop() { } else { if (Wii[i]->getButtonClick(LEFT)) { - Wii[i]->setAllOff(); + Wii[i]->setLedOff(); Wii[i]->setLedOn(LED1); Serial.print(F("\r\nLeft")); } if (Wii[i]->getButtonClick(RIGHT)) { - Wii[i]->setAllOff(); + Wii[i]->setLedOff(); Wii[i]->setLedOn(LED3); Serial.print(F("\r\nRight")); } if (Wii[i]->getButtonClick(DOWN)) { - Wii[i]->setAllOff(); + Wii[i]->setLedOff(); Wii[i]->setLedOn(LED4); Serial.print(F("\r\nDown")); } if (Wii[i]->getButtonClick(UP)) { - Wii[i]->setAllOff(); + Wii[i]->setLedOff(); Wii[i]->setLedOn(LED2); Serial.print(F("\r\nUp")); } diff --git a/examples/Bluetooth/WiiUProController/WiiUProController.ino b/examples/Bluetooth/WiiUProController/WiiUProController.ino index 608a7688..582eeae3 100644 --- a/examples/Bluetooth/WiiUProController/WiiUProController.ino +++ b/examples/Bluetooth/WiiUProController/WiiUProController.ino @@ -32,22 +32,22 @@ void loop() { } else { if (Wii.getButtonClick(LEFT)) { - Wii.setAllOff(); + Wii.setLedOff(); Wii.setLedOn(LED1); Serial.print(F("\r\nLeft")); } if (Wii.getButtonClick(RIGHT)) { - Wii.setAllOff(); + Wii.setLedOff(); Wii.setLedOn(LED3); Serial.print(F("\r\nRight")); } if (Wii.getButtonClick(DOWN)) { - Wii.setAllOff(); + Wii.setLedOff(); Wii.setLedOn(LED4); Serial.print(F("\r\nDown")); } if (Wii.getButtonClick(UP)) { - Wii.setAllOff(); + Wii.setLedOff(); Wii.setLedOn(LED2); Serial.print(F("\r\nUp")); } diff --git a/examples/PS3USB/PS3USB.ino b/examples/PS3USB/PS3USB.ino index 6e6943a9..50a020c0 100644 --- a/examples/PS3USB/PS3USB.ino +++ b/examples/PS3USB/PS3USB.ino @@ -62,22 +62,22 @@ void loop() { if (PS3.getButtonClick(UP)) { Serial.print(F("\r\nUp")); - PS3.setAllOff(); + PS3.setLedOff(); PS3.setLedOn(LED4); } if (PS3.getButtonClick(RIGHT)) { Serial.print(F("\r\nRight")); - PS3.setAllOff(); + PS3.setLedOff(); PS3.setLedOn(LED1); } if (PS3.getButtonClick(DOWN)) { Serial.print(F("\r\nDown")); - PS3.setAllOff(); + PS3.setLedOff(); PS3.setLedOn(LED2); } if (PS3.getButtonClick(LEFT)) { Serial.print(F("\r\nLeft")); - PS3.setAllOff(); + PS3.setLedOff(); PS3.setLedOn(LED3); }