From 1f33f2bd087c1eee4ca528da5e3ca0e656088785 Mon Sep 17 00:00:00 2001 From: Kristian Lauszus Date: Sat, 4 Jan 2014 14:14:22 +0100 Subject: [PATCH] Renamed getStatusString() to printStatusString() --- PS3BT.cpp | 18 +++------ PS3BT.h | 7 +--- PS3USB.cpp | 50 ++++++++++++------------ PS3USB.h | 7 +--- examples/Bluetooth/PS3BT/PS3BT.ino | 4 +- examples/Bluetooth/PS3Multi/PS3Multi.ino | 2 +- examples/Bluetooth/PS3SPP/PS3SPP.ino | 3 +- examples/PS3USB/PS3USB.ino | 2 +- keywords.txt | 2 +- 9 files changed, 40 insertions(+), 55 deletions(-) diff --git a/PS3BT.cpp b/PS3BT.cpp index ba8e043b..ba531c26 100644 --- a/PS3BT.cpp +++ b/PS3BT.cpp @@ -160,18 +160,17 @@ bool PS3BT::getStatus(StatusEnum c) { return (l2capinbuf[(uint16_t)c >> 8] == ((uint8_t)c & 0xff)); } -String PS3BT::getStatusString() { +void PS3BT::printStatusString() { + char statusOutput[100]; // Max string length plus null character if(PS3Connected || PS3NavigationConnected) { - char statusOutput[100]; // Max string length plus null character - strcpy_P(statusOutput, PSTR("ConnectionStatus: ")); if(getStatus(Plugged)) strcat_P(statusOutput, PSTR("Plugged")); else if(getStatus(Unplugged)) strcat_P(statusOutput, PSTR("Unplugged")); else strcat_P(statusOutput, PSTR("Error")); - strcat_P(statusOutput, PSTR(" - PowerRating: ")); + if(getStatus(Charging)) strcat_P(statusOutput, PSTR("Charging")); else if(getStatus(NotCharging)) strcat_P(statusOutput, PSTR("Not Charging")); else if(getStatus(Shutdown)) strcat_P(statusOutput, PSTR("Shutdown")); @@ -188,12 +187,7 @@ String PS3BT::getStatusString() { else if(getStatus(BluetoothRumble)) strcat_P(statusOutput, PSTR("Bluetooth - Rumble is on")); else if(getStatus(Bluetooth)) strcat_P(statusOutput, PSTR("Bluetooth - Rumble is off")); else strcat_P(statusOutput, PSTR("Error")); - - return statusOutput; - } else if(PS3MoveConnected) { - char statusOutput[26]; // Max string length plus null character - strcpy_P(statusOutput, PSTR("PowerRating: ")); if(getStatus(MoveCharging)) strcat_P(statusOutput, PSTR("Charging")); @@ -204,10 +198,10 @@ String PS3BT::getStatusString() { else if(getStatus(MoveHigh)) strcat_P(statusOutput, PSTR("High")); else if(getStatus(MoveFull)) strcat_P(statusOutput, PSTR("Full")); else strcat_P(statusOutput, PSTR("Error")); - - return statusOutput; } else - return "Error"; + strcpy_P(statusOutput, PSTR("Error")); + + USB_HOST_SERIAL.write((uint8_t*)statusOutput, strlen(statusOutput)); } void PS3BT::Reset() { diff --git a/PS3BT.h b/PS3BT.h index bd14f4e4..7291c092 100644 --- a/PS3BT.h +++ b/PS3BT.h @@ -111,11 +111,8 @@ public: * @return True if correct and false if not. */ bool getStatus(StatusEnum c); - /** - * Read all the available ::StatusEnum from the controller. - * @return One large string with all the information. - */ - String getStatusString(); + /** Read all the available statuses from the controller and prints it as a nice formated string. */ + void printStatusString(); /** * Read the temperature from the Move controller. * @return The temperature in degrees Celsius. diff --git a/PS3USB.cpp b/PS3USB.cpp index 7a15bb37..fa865495 100644 --- a/PS3USB.cpp +++ b/PS3USB.cpp @@ -362,39 +362,37 @@ bool PS3USB::getStatus(StatusEnum c) { return (readBuf[((uint16_t)c >> 8) - 9] == ((uint8_t)c & 0xff)); } -String PS3USB::getStatusString() { +void PS3USB::printStatusString() { + char statusOutput[100]; // Max string length plus null character if(PS3Connected || PS3NavigationConnected) { - char statusOutput[100]; + strcpy_P(statusOutput, PSTR("ConnectionStatus: ")); - strcpy(statusOutput, "ConnectionStatus: "); + if(getStatus(Plugged)) strcat_P(statusOutput, PSTR("Plugged")); + else if(getStatus(Unplugged)) strcat_P(statusOutput, PSTR("Unplugged")); + else strcat_P(statusOutput, PSTR("Error")); - if(getStatus(Plugged)) strcat(statusOutput, "Plugged"); - else if(getStatus(Unplugged)) strcat(statusOutput, "Unplugged"); - else strcat(statusOutput, "Error"); + strcat_P(statusOutput, PSTR(" - PowerRating: ")); + if(getStatus(Charging)) strcat_P(statusOutput, PSTR("Charging")); + else if(getStatus(NotCharging)) strcat_P(statusOutput, PSTR("Not Charging")); + else if(getStatus(Shutdown)) strcat_P(statusOutput, PSTR("Shutdown")); + else if(getStatus(Dying)) strcat_P(statusOutput, PSTR("Dying")); + else if(getStatus(Low)) strcat_P(statusOutput, PSTR("Low")); + else if(getStatus(High)) strcat_P(statusOutput, PSTR("High")); + else if(getStatus(Full)) strcat_P(statusOutput, PSTR("Full")); + else strcat_P(statusOutput, PSTR("Error")); - strcat(statusOutput, " - PowerRating: "); + strcat_P(statusOutput, PSTR(" - WirelessStatus: ")); - if(getStatus(Charging)) strcat(statusOutput, "Charging"); - else if(getStatus(NotCharging)) strcat(statusOutput, "Not Charging"); - else if(getStatus(Shutdown)) strcat(statusOutput, "Shutdown"); - else if(getStatus(Dying)) strcat(statusOutput, "Dying"); - else if(getStatus(Low)) strcat(statusOutput, "Low"); - else if(getStatus(High)) strcat(statusOutput, "High"); - else if(getStatus(Full)) strcat(statusOutput, "Full"); - else strcat(statusOutput, "Error"); - - strcat(statusOutput, " - WirelessStatus: "); - - if(getStatus(CableRumble)) strcat(statusOutput, "Cable - Rumble is on"); - else if(getStatus(Cable)) strcat(statusOutput, "Cable - Rumble is off"); - else if(getStatus(BluetoothRumble)) strcat(statusOutput, "Bluetooth - Rumble is on"); - else if(getStatus(Bluetooth)) strcat(statusOutput, "Bluetooth - Rumble is off"); - else strcat(statusOutput, "Error"); - - return statusOutput; + if(getStatus(CableRumble)) strcat_P(statusOutput, PSTR("Cable - Rumble is on")); + else if(getStatus(Cable)) strcat_P(statusOutput, PSTR("Cable - Rumble is off")); + else if(getStatus(BluetoothRumble)) strcat_P(statusOutput, PSTR("Bluetooth - Rumble is on")); + else if(getStatus(Bluetooth)) strcat_P(statusOutput, PSTR("Bluetooth - Rumble is off")); + else strcat_P(statusOutput, PSTR("Error")); } else - return "Error"; + strcpy_P(statusOutput, PSTR("Error")); + + USB_HOST_SERIAL.write((uint8_t*)statusOutput, strlen(statusOutput)); } /* Playstation Sixaxis Dualshock and Navigation Controller commands */ diff --git a/PS3USB.h b/PS3USB.h index dde40d5c..5bbbdf2e 100644 --- a/PS3USB.h +++ b/PS3USB.h @@ -193,11 +193,8 @@ public: * @return True if correct and false if not. */ bool getStatus(StatusEnum c); - /** - * Read all the available ::StatusEnum from the controller. - * @return One large string with all the information. - */ - String getStatusString(); + /** Read all the available statuses from the controller and prints it as a nice formated string. */ + void printStatusString(); /** Used to set all LEDs and rumble off. */ void setAllOff(); diff --git a/examples/Bluetooth/PS3BT/PS3BT.ino b/examples/Bluetooth/PS3BT/PS3BT.ino index 87cc9939..3cb0ae7a 100644 --- a/examples/Bluetooth/PS3BT/PS3BT.ino +++ b/examples/Bluetooth/PS3BT/PS3BT.ino @@ -111,7 +111,7 @@ void loop() { if (PS3.getButtonClick(SELECT)) { Serial.print(F("\r\nSelect - ")); - Serial.print(PS3.getStatusString()); + PS3.printStatusString(); } if (PS3.getButtonClick(START)) { Serial.print(F("\r\nStart")); @@ -163,7 +163,7 @@ void loop() { PS3.moveSetBulb(Off); Serial.print(F("\r\nMove")); Serial.print(F(" - ")); - Serial.print(PS3.getStatusString()); + PS3.printStatusString(); } } if (printAngle) { diff --git a/examples/Bluetooth/PS3Multi/PS3Multi.ino b/examples/Bluetooth/PS3Multi/PS3Multi.ino index 20f0da8d..9ce39857 100644 --- a/examples/Bluetooth/PS3Multi/PS3Multi.ino +++ b/examples/Bluetooth/PS3Multi/PS3Multi.ino @@ -116,7 +116,7 @@ void loop() { if (PS3[i]->getButtonClick(SELECT)) { Serial.print(F("\r\nSelect - ")); - Serial.print(PS3[i]->getStatusString()); + PS3[i]->printStatusString(); } if (PS3[i]->getButtonClick(START)) { Serial.print(F("\r\nStart")); diff --git a/examples/Bluetooth/PS3SPP/PS3SPP.ino b/examples/Bluetooth/PS3SPP/PS3SPP.ino index ed346d90..6bc7afc6 100644 --- a/examples/Bluetooth/PS3SPP/PS3SPP.ino +++ b/examples/Bluetooth/PS3SPP/PS3SPP.ino @@ -141,8 +141,7 @@ void loop() { output += " - R3"; if (PS3.getButtonClick(SELECT)) { - output += " - Select - "; - output += PS3.getStatusString(); + output += " - Select"; } if (PS3.getButtonClick(START)) output += " - Start"; diff --git a/examples/PS3USB/PS3USB.ino b/examples/PS3USB/PS3USB.ino index e05f55b5..2db3afd5 100644 --- a/examples/PS3USB/PS3USB.ino +++ b/examples/PS3USB/PS3USB.ino @@ -96,7 +96,7 @@ void loop() { if (PS3.getButtonClick(SELECT)) { Serial.print(F("\r\nSelect - ")); - Serial.print(PS3.getStatusString()); + PS3.printStatusString(); } if (PS3.getButtonClick(START)) { Serial.print(F("\r\nStart")); diff --git a/keywords.txt b/keywords.txt index c04041ab..1c987a4e 100644 --- a/keywords.txt +++ b/keywords.txt @@ -52,7 +52,7 @@ getSensor KEYWORD2 getAngle KEYWORD2 get9DOFValues KEYWORD2 getStatus KEYWORD2 -getStatusString KEYWORD2 +printStatusString KEYWORD2 getTemperature KEYWORD2 disconnect KEYWORD2