Merge pull request #21 from TKJElectronics/master

Improved getAngle() and added getTemperature()
This commit is contained in:
Oleg Mazurov 2012-06-01 13:52:02 -07:00
commit 0a02474628
5 changed files with 24 additions and 35 deletions

View file

@ -465,7 +465,7 @@ uint8_t PS3BT::getAnalogHat(AnalogHat a)
return 0;
return (uint8_t)(l2capinbuf[(uint16_t)a]);
}
int32_t PS3BT::getSensor(Sensor a)
int16_t PS3BT::getSensor(Sensor a)
{
if (l2capinbuf == NULL)
return 0;
@ -505,22 +505,9 @@ double PS3BT::getAngle(Angle a) {
} else if(PS3MoveConnected) {
// It's a Kionix KXSC4 inside the Motion controller
const uint16_t zeroG = 0x8000;
accXval = getSensor(aXmove);
accYval = getSensor(aYmove);
accZval = getSensor(aZmove);
if(accXval < 0)
accXval += zeroG;
else
accXval -= zeroG;
if(accYval < 0)
accYval += zeroG;
else
accYval -= zeroG;
if(accZval < 0)
accZval += zeroG;
else
accZval -= zeroG;
accXval = -(int16_t)(getSensor(aXmove)-zeroG);
accYval = (int16_t)(getSensor(aYmove)-zeroG);
accZval = (int16_t)(getSensor(aZmove)-zeroG);
}
// Convert to 360 degrees resolution
@ -534,6 +521,19 @@ double PS3BT::getAngle(Angle a) {
return angle;
}
}
String PS3BT::getTemperature() {
if(PS3MoveConnected) {
int16_t input = getSensor(tempMove);
String output = String(input/100);
output += ".";
if(input%100 < 10)
output += "0";
output += String(input%100);
return output;
}
}
bool PS3BT::getStatus(Status c)
{
if (l2capinbuf == NULL)

View file

@ -349,10 +349,11 @@ public:
bool getButton(Button b);
uint8_t getAnalogButton(AnalogButton a);
uint8_t getAnalogHat(AnalogHat a);
int32_t getSensor(Sensor a);
int16_t getSensor(Sensor a);
double getAngle(Angle a);
bool getStatus(Status c);
String getStatusString();
String getTemperature();
void disconnect(); // use this void to disconnect any of the controllers
/* HID Commands */

View file

@ -313,8 +313,8 @@ void PS3USB::readReport()
{
if (readBuf == NULL)
return;
if(PS3Connected || PS3NavigationConnected)
ButtonState = (uint32_t)(readBuf[2] | ((uint16_t)readBuf[3] << 8) | ((uint32_t)readBuf[4] << 16));
ButtonState = (uint32_t)(readBuf[2] | ((uint16_t)readBuf[3] << 8) | ((uint32_t)readBuf[4] << 16));
//Notify(PSTR("\r\nButtonState");
//PrintHex<uint32_t>(ButtonState);

View file

@ -189,21 +189,8 @@ void loop()
Serial.println(PS3.getAngle(Roll));
}
else if(printTemperature) {
String templow;
String temphigh;
String input = String(PS3.getSensor(tempMove));
if (input.length() > 3) {
temphigh = input.substring(0, 2);
templow = input.substring(2);
} else {
temphigh = input.substring(0, 1);
templow = input.substring(1);
}
Serial.print(F("Temperature: "));
Serial.print(temphigh);
Serial.print(F("."));
Serial.println(templow);
Serial.print(F("Temperature: "));
Serial.println(PS3.getTemperature());
}
}
delay(1);

View file

@ -22,6 +22,7 @@ getSensor KEYWORD2
getAngle KEYWORD2
getStatus KEYWORD2
getStatusString KEYWORD2
getTemperature KEYWORD2
disconnect KEYWORD2
setAllOff KEYWORD2