Can now call setLedOff without any argument, to turn all LEDs off

This commit is contained in:
Kristian Lauszus 2013-11-15 23:19:10 +01:00
parent 87cb83276b
commit 5b793db3e3
11 changed files with 54 additions and 39 deletions

View file

@ -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[0] = 0x52; // HID BT Set_report (0x50) | Report Type (Output 0x02)
HIDBuffer[1] = 0x01; // Report ID 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[0] = 0xA2; // HID BT DATA_request (0xA0) | Report Type (Output 0x02)
HIDMoveBuffer[1] = 0x02; // Report ID HIDMoveBuffer[1] = 0x02; // Report ID
@ -529,16 +529,16 @@ void PS3BT::Run() {
ButtonState = 0; // Clear all values ButtonState = 0; // Clear all values
OldButtonState = 0; OldButtonState = 0;
ButtonClickState = 0; ButtonClickState = 0;
onInit(); // Turn on the LED on the controller onInit(); // Turn on the LED on the controller
l2cap_state = L2CAP_DONE; l2cap_state = L2CAP_DONE;
} }
break; break;
case L2CAP_DONE: 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 (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 (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 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(); timerBulbRumble = millis();
} }
} }
@ -560,8 +560,12 @@ void PS3BT::HID_Command(uint8_t* data, uint8_t nbytes) {
} }
void PS3BT::setAllOff() { void PS3BT::setAllOff() {
for (uint8_t i = 0; i < PS3_REPORT_BUFFER_SIZE; i++) HIDBuffer[3] = 0x00; // Rumble bytes
HIDBuffer[i + 2] = pgm_read_byte(&PS3_REPORT_BUFFER[i]); // First two bytes reserved for report type and ID HIDBuffer[4] = 0x00;
HIDBuffer[5] = 0x00;
HIDBuffer[6] = 0x00;
HIDBuffer[11] = 0x00; // LED byte
HID_Command(HIDBuffer, HID_BUFFERSIZE); HID_Command(HIDBuffer, HID_BUFFERSIZE);
} }
@ -596,6 +600,7 @@ void PS3BT::setLedRaw(uint8_t value) {
HIDBuffer[11] = value << 1; HIDBuffer[11] = value << 1;
HID_Command(HIDBuffer, HID_BUFFERSIZE); HID_Command(HIDBuffer, HID_BUFFERSIZE);
} }
void PS3BT::setLedOff(LED a) { void PS3BT::setLedOff(LED a) {
HIDBuffer[11] &= ~((uint8_t)((pgm_read_byte(&LEDS[(uint8_t)a]) & 0x0f) << 1)); HIDBuffer[11] &= ~((uint8_t)((pgm_read_byte(&LEDS[(uint8_t)a]) & 0x0f) << 1));
HID_Command(HIDBuffer, HID_BUFFERSIZE); 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 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[3] = r;
HIDMoveBuffer[4] = g; HIDMoveBuffer[4] = g;
HIDMoveBuffer[5] = b; 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) 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); Notify(PSTR("\r\nThe rumble value has to at least 64, or approximately 25%"), 0x80);
#endif #endif
//set the rumble value into the write buffer // Set the rumble value into the write buffer
HIDMoveBuffer[7] = rumble; HIDMoveBuffer[7] = rumble;
HIDMove_Command(HIDMoveBuffer, HID_BUFFERSIZE); HIDMove_Command(HIDMoveBuffer, HID_BUFFERSIZE);

View file

@ -176,6 +176,10 @@ public:
* @param value See: ::LED enum. * @param value See: ::LED enum.
*/ */
void setLedRaw(uint8_t value); void setLedRaw(uint8_t value);
/** Turn all LEDs off. */
void setLedOff() {
setLedRaw(0);
}
/** /**
* Turn the specific ::LED off. * Turn the specific ::LED off.
* @param a The ::LED to turn off. * @param a The ::LED to turn off.

View file

@ -220,6 +220,10 @@ public:
* @param value See: ::LED enum. * @param value See: ::LED enum.
*/ */
void setLedRaw(uint8_t value); void setLedRaw(uint8_t value);
/** Turn all LEDs off. */
void setLedOff() {
setLedRaw(0);
}
/** /**
* Turn the specific ::LED off. * Turn the specific ::LED off.
* @param a The ::LED to turn off. * @param a The ::LED to turn off.

6
Wii.h
View file

@ -191,6 +191,10 @@ public:
* @param value See: ::LED enum. * @param value See: ::LED enum.
*/ */
void setLedRaw(uint8_t value); void setLedRaw(uint8_t value);
/** Turn all LEDs off. */
void setLedOff() {
setLedRaw(0);
}
/** /**
* Turn the specific ::LED off. * Turn the specific ::LED off.
* @param a The ::LED to turn 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. * This will set the LEDs, so the user can see which connections are active.
* *
* The first ::LED indicate that the Wiimote is connected, * The first ::LED indicate that the Wiimote is connected,
*
* the second ::LED indicate indicate that a Motion Plus is also 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. * the third ::LED will indicate that a Nunchuck controller is also connected.
*/ */
void setLedStatus(); void setLedStatus();

View file

@ -69,28 +69,28 @@ void loop() {
if (PS3.getButtonClick(UP)) { if (PS3.getButtonClick(UP)) {
Serial.print(F("\r\nUp")); Serial.print(F("\r\nUp"));
if (PS3.PS3Connected) { if (PS3.PS3Connected) {
PS3.setAllOff(); PS3.setLedOff();
PS3.setLedOn(LED4); PS3.setLedOn(LED4);
} }
} }
if (PS3.getButtonClick(RIGHT)) { if (PS3.getButtonClick(RIGHT)) {
Serial.print(F("\r\nRight")); Serial.print(F("\r\nRight"));
if (PS3.PS3Connected) { if (PS3.PS3Connected) {
PS3.setAllOff(); PS3.setLedOff();
PS3.setLedOn(LED1); PS3.setLedOn(LED1);
} }
} }
if (PS3.getButtonClick(DOWN)) { if (PS3.getButtonClick(DOWN)) {
Serial.print(F("\r\nDown")); Serial.print(F("\r\nDown"));
if (PS3.PS3Connected) { if (PS3.PS3Connected) {
PS3.setAllOff(); PS3.setLedOff();
PS3.setLedOn(LED2); PS3.setLedOn(LED2);
} }
} }
if (PS3.getButtonClick(LEFT)) { if (PS3.getButtonClick(LEFT)) {
Serial.print(F("\r\nLeft")); Serial.print(F("\r\nLeft"));
if (PS3.PS3Connected) { if (PS3.PS3Connected) {
PS3.setAllOff(); PS3.setLedOff();
PS3.setLedOn(LED3); PS3.setLedOn(LED3);
} }
} }

View file

@ -74,28 +74,28 @@ void loop() {
if (PS3[i]->getButtonClick(UP)) { if (PS3[i]->getButtonClick(UP)) {
Serial.print(F("\r\nUp")); Serial.print(F("\r\nUp"));
if (PS3[i]->PS3Connected) { if (PS3[i]->PS3Connected) {
PS3[i]->setAllOff(); PS3[i]->setLedOff();
PS3[i]->setLedOn(LED4); PS3[i]->setLedOn(LED4);
} }
} }
if (PS3[i]->getButtonClick(RIGHT)) { if (PS3[i]->getButtonClick(RIGHT)) {
Serial.print(F("\r\nRight")); Serial.print(F("\r\nRight"));
if (PS3[i]->PS3Connected) { if (PS3[i]->PS3Connected) {
PS3[i]->setAllOff(); PS3[i]->setLedOff();
PS3[i]->setLedOn(LED1); PS3[i]->setLedOn(LED1);
} }
} }
if (PS3[i]->getButtonClick(DOWN)) { if (PS3[i]->getButtonClick(DOWN)) {
Serial.print(F("\r\nDown")); Serial.print(F("\r\nDown"));
if (PS3[i]->PS3Connected) { if (PS3[i]->PS3Connected) {
PS3[i]->setAllOff(); PS3[i]->setLedOff();
PS3[i]->setLedOn(LED2); PS3[i]->setLedOn(LED2);
} }
} }
if (PS3[i]->getButtonClick(LEFT)) { if (PS3[i]->getButtonClick(LEFT)) {
Serial.print(F("\r\nLeft")); Serial.print(F("\r\nLeft"));
if (PS3[i]->PS3Connected) { if (PS3[i]->PS3Connected) {
PS3[i]->setAllOff(); PS3[i]->setLedOff();
PS3[i]->setLedOn(LED3); PS3[i]->setLedOn(LED3);
} }
} }

View file

@ -100,28 +100,28 @@ void loop() {
if (PS3.getButtonClick(UP)) { if (PS3.getButtonClick(UP)) {
output += " - Up"; output += " - Up";
if (PS3.PS3Connected) { if (PS3.PS3Connected) {
PS3.setAllOff(); PS3.setLedOff();
PS3.setLedOn(LED4); PS3.setLedOn(LED4);
} }
} }
if (PS3.getButtonClick(RIGHT)) { if (PS3.getButtonClick(RIGHT)) {
output += " - Right"; output += " - Right";
if (PS3.PS3Connected) { if (PS3.PS3Connected) {
PS3.setAllOff(); PS3.setLedOff();
PS3.setLedOn(LED1); PS3.setLedOn(LED1);
} }
} }
if (PS3.getButtonClick(DOWN)) { if (PS3.getButtonClick(DOWN)) {
output += " - Down"; output += " - Down";
if (PS3.PS3Connected) { if (PS3.PS3Connected) {
PS3.setAllOff(); PS3.setLedOff();
PS3.setLedOn(LED2); PS3.setLedOn(LED2);
} }
} }
if (PS3.getButtonClick(LEFT)) { if (PS3.getButtonClick(LEFT)) {
output += " - Left"; output += " - Left";
if (PS3.PS3Connected) { if (PS3.PS3Connected) {
PS3.setAllOff(); PS3.setLedOff();
PS3.setLedOn(LED3); PS3.setLedOn(LED3);
} }
} }

View file

@ -34,22 +34,22 @@ void loop() {
} }
else { else {
if (Wii.getButtonClick(LEFT)) { if (Wii.getButtonClick(LEFT)) {
Wii.setAllOff(); Wii.setLedOff();
Wii.setLedOn(LED1); Wii.setLedOn(LED1);
Serial.print(F("\r\nLeft")); Serial.print(F("\r\nLeft"));
} }
if (Wii.getButtonClick(RIGHT)) { if (Wii.getButtonClick(RIGHT)) {
Wii.setAllOff(); Wii.setLedOff();
Wii.setLedOn(LED3); Wii.setLedOn(LED3);
Serial.print(F("\r\nRight")); Serial.print(F("\r\nRight"));
} }
if (Wii.getButtonClick(DOWN)) { if (Wii.getButtonClick(DOWN)) {
Wii.setAllOff(); Wii.setLedOff();
Wii.setLedOn(LED4); Wii.setLedOn(LED4);
Serial.print(F("\r\nDown")); Serial.print(F("\r\nDown"));
} }
if (Wii.getButtonClick(UP)) { if (Wii.getButtonClick(UP)) {
Wii.setAllOff(); Wii.setLedOff();
Wii.setLedOn(LED2); Wii.setLedOn(LED2);
Serial.print(F("\r\nUp")); Serial.print(F("\r\nUp"));
} }

View file

@ -42,22 +42,22 @@ void loop() {
} }
else { else {
if (Wii[i]->getButtonClick(LEFT)) { if (Wii[i]->getButtonClick(LEFT)) {
Wii[i]->setAllOff(); Wii[i]->setLedOff();
Wii[i]->setLedOn(LED1); Wii[i]->setLedOn(LED1);
Serial.print(F("\r\nLeft")); Serial.print(F("\r\nLeft"));
} }
if (Wii[i]->getButtonClick(RIGHT)) { if (Wii[i]->getButtonClick(RIGHT)) {
Wii[i]->setAllOff(); Wii[i]->setLedOff();
Wii[i]->setLedOn(LED3); Wii[i]->setLedOn(LED3);
Serial.print(F("\r\nRight")); Serial.print(F("\r\nRight"));
} }
if (Wii[i]->getButtonClick(DOWN)) { if (Wii[i]->getButtonClick(DOWN)) {
Wii[i]->setAllOff(); Wii[i]->setLedOff();
Wii[i]->setLedOn(LED4); Wii[i]->setLedOn(LED4);
Serial.print(F("\r\nDown")); Serial.print(F("\r\nDown"));
} }
if (Wii[i]->getButtonClick(UP)) { if (Wii[i]->getButtonClick(UP)) {
Wii[i]->setAllOff(); Wii[i]->setLedOff();
Wii[i]->setLedOn(LED2); Wii[i]->setLedOn(LED2);
Serial.print(F("\r\nUp")); Serial.print(F("\r\nUp"));
} }

View file

@ -32,22 +32,22 @@ void loop() {
} }
else { else {
if (Wii.getButtonClick(LEFT)) { if (Wii.getButtonClick(LEFT)) {
Wii.setAllOff(); Wii.setLedOff();
Wii.setLedOn(LED1); Wii.setLedOn(LED1);
Serial.print(F("\r\nLeft")); Serial.print(F("\r\nLeft"));
} }
if (Wii.getButtonClick(RIGHT)) { if (Wii.getButtonClick(RIGHT)) {
Wii.setAllOff(); Wii.setLedOff();
Wii.setLedOn(LED3); Wii.setLedOn(LED3);
Serial.print(F("\r\nRight")); Serial.print(F("\r\nRight"));
} }
if (Wii.getButtonClick(DOWN)) { if (Wii.getButtonClick(DOWN)) {
Wii.setAllOff(); Wii.setLedOff();
Wii.setLedOn(LED4); Wii.setLedOn(LED4);
Serial.print(F("\r\nDown")); Serial.print(F("\r\nDown"));
} }
if (Wii.getButtonClick(UP)) { if (Wii.getButtonClick(UP)) {
Wii.setAllOff(); Wii.setLedOff();
Wii.setLedOn(LED2); Wii.setLedOn(LED2);
Serial.print(F("\r\nUp")); Serial.print(F("\r\nUp"));
} }

View file

@ -62,22 +62,22 @@ void loop() {
if (PS3.getButtonClick(UP)) { if (PS3.getButtonClick(UP)) {
Serial.print(F("\r\nUp")); Serial.print(F("\r\nUp"));
PS3.setAllOff(); PS3.setLedOff();
PS3.setLedOn(LED4); PS3.setLedOn(LED4);
} }
if (PS3.getButtonClick(RIGHT)) { if (PS3.getButtonClick(RIGHT)) {
Serial.print(F("\r\nRight")); Serial.print(F("\r\nRight"));
PS3.setAllOff(); PS3.setLedOff();
PS3.setLedOn(LED1); PS3.setLedOn(LED1);
} }
if (PS3.getButtonClick(DOWN)) { if (PS3.getButtonClick(DOWN)) {
Serial.print(F("\r\nDown")); Serial.print(F("\r\nDown"));
PS3.setAllOff(); PS3.setLedOff();
PS3.setLedOn(LED2); PS3.setLedOn(LED2);
} }
if (PS3.getButtonClick(LEFT)) { if (PS3.getButtonClick(LEFT)) {
Serial.print(F("\r\nLeft")); Serial.print(F("\r\nLeft"));
PS3.setAllOff(); PS3.setLedOff();
PS3.setLedOn(LED3); PS3.setLedOn(LED3);
} }