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

@ -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);

View file

@ -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.

View file

@ -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.

6
Wii.h
View file

@ -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();

View file

@ -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);
}
}

View file

@ -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);
}
}

View file

@ -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);
}
}

View file

@ -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"));
}

View file

@ -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"));
}

View file

@ -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"));
}

View file

@ -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);
}