mirror of
https://github.com/felis/USB_Host_Shield_2.0.git
synced 2024-03-22 11:31:26 +01:00
Merge pull request #21 from TKJElectronics/master
Improved getAngle() and added getTemperature()
This commit is contained in:
commit
0a02474628
5 changed files with 24 additions and 35 deletions
34
PS3BT.cpp
34
PS3BT.cpp
|
@ -465,7 +465,7 @@ uint8_t PS3BT::getAnalogHat(AnalogHat a)
|
||||||
return 0;
|
return 0;
|
||||||
return (uint8_t)(l2capinbuf[(uint16_t)a]);
|
return (uint8_t)(l2capinbuf[(uint16_t)a]);
|
||||||
}
|
}
|
||||||
int32_t PS3BT::getSensor(Sensor a)
|
int16_t PS3BT::getSensor(Sensor a)
|
||||||
{
|
{
|
||||||
if (l2capinbuf == NULL)
|
if (l2capinbuf == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -505,22 +505,9 @@ double PS3BT::getAngle(Angle a) {
|
||||||
} else if(PS3MoveConnected) {
|
} else if(PS3MoveConnected) {
|
||||||
// It's a Kionix KXSC4 inside the Motion controller
|
// It's a Kionix KXSC4 inside the Motion controller
|
||||||
const uint16_t zeroG = 0x8000;
|
const uint16_t zeroG = 0x8000;
|
||||||
accXval = getSensor(aXmove);
|
accXval = -(int16_t)(getSensor(aXmove)-zeroG);
|
||||||
accYval = getSensor(aYmove);
|
accYval = (int16_t)(getSensor(aYmove)-zeroG);
|
||||||
accZval = getSensor(aZmove);
|
accZval = (int16_t)(getSensor(aZmove)-zeroG);
|
||||||
|
|
||||||
if(accXval < 0)
|
|
||||||
accXval += zeroG;
|
|
||||||
else
|
|
||||||
accXval -= zeroG;
|
|
||||||
if(accYval < 0)
|
|
||||||
accYval += zeroG;
|
|
||||||
else
|
|
||||||
accYval -= zeroG;
|
|
||||||
if(accZval < 0)
|
|
||||||
accZval += zeroG;
|
|
||||||
else
|
|
||||||
accZval -= zeroG;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert to 360 degrees resolution
|
// Convert to 360 degrees resolution
|
||||||
|
@ -534,6 +521,19 @@ double PS3BT::getAngle(Angle a) {
|
||||||
return angle;
|
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)
|
bool PS3BT::getStatus(Status c)
|
||||||
{
|
{
|
||||||
if (l2capinbuf == NULL)
|
if (l2capinbuf == NULL)
|
||||||
|
|
3
PS3BT.h
3
PS3BT.h
|
@ -349,10 +349,11 @@ public:
|
||||||
bool getButton(Button b);
|
bool getButton(Button b);
|
||||||
uint8_t getAnalogButton(AnalogButton a);
|
uint8_t getAnalogButton(AnalogButton a);
|
||||||
uint8_t getAnalogHat(AnalogHat a);
|
uint8_t getAnalogHat(AnalogHat a);
|
||||||
int32_t getSensor(Sensor a);
|
int16_t getSensor(Sensor a);
|
||||||
double getAngle(Angle a);
|
double getAngle(Angle a);
|
||||||
bool getStatus(Status c);
|
bool getStatus(Status c);
|
||||||
String getStatusString();
|
String getStatusString();
|
||||||
|
String getTemperature();
|
||||||
void disconnect(); // use this void to disconnect any of the controllers
|
void disconnect(); // use this void to disconnect any of the controllers
|
||||||
|
|
||||||
/* HID Commands */
|
/* HID Commands */
|
||||||
|
|
|
@ -313,7 +313,7 @@ void PS3USB::readReport()
|
||||||
{
|
{
|
||||||
if (readBuf == NULL)
|
if (readBuf == NULL)
|
||||||
return;
|
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");
|
//Notify(PSTR("\r\nButtonState");
|
||||||
|
|
|
@ -189,21 +189,8 @@ void loop()
|
||||||
Serial.println(PS3.getAngle(Roll));
|
Serial.println(PS3.getAngle(Roll));
|
||||||
}
|
}
|
||||||
else if(printTemperature) {
|
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(F("Temperature: "));
|
||||||
Serial.print(temphigh);
|
Serial.println(PS3.getTemperature());
|
||||||
Serial.print(F("."));
|
|
||||||
Serial.println(templow);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
delay(1);
|
delay(1);
|
||||||
|
|
|
@ -22,6 +22,7 @@ getSensor KEYWORD2
|
||||||
getAngle KEYWORD2
|
getAngle KEYWORD2
|
||||||
getStatus KEYWORD2
|
getStatus KEYWORD2
|
||||||
getStatusString KEYWORD2
|
getStatusString KEYWORD2
|
||||||
|
getTemperature KEYWORD2
|
||||||
disconnect KEYWORD2
|
disconnect KEYWORD2
|
||||||
|
|
||||||
setAllOff KEYWORD2
|
setAllOff KEYWORD2
|
||||||
|
|
Loading…
Reference in a new issue