mirror of
https://github.com/felis/USB_Host_Shield_2.0.git
synced 2024-03-22 11:31:26 +01:00
Added get9DOFValues
Thanks to Manfred Piendl for finding the values needed to convert the Move sensor data into units
This commit is contained in:
parent
75a84c5e80
commit
81c7f22417
3 changed files with 35 additions and 18 deletions
37
PS3BT.cpp
37
PS3BT.cpp
|
@ -83,20 +83,11 @@ int16_t PS3BT::getSensor(Sensor a) {
|
|||
return 0;
|
||||
if (a == aX || a == aY || a == aZ || a == gZ)
|
||||
return ((l2capinbuf[(uint16_t)a] << 8) | l2capinbuf[(uint16_t)a + 1]);
|
||||
else if (a == mXmove || a == mYmove || a == mZmove) // These are all 12-bits long
|
||||
{
|
||||
// Might not be correct, haven't tested it yet
|
||||
/*if (a == mXmove)
|
||||
return ((l2capinbuf[(uint16_t)a + 1] << 0x04) | (l2capinbuf[(uint16_t)a] << 0x0C));
|
||||
else if (a == mYmove)
|
||||
return ((l2capinbuf[(uint16_t)a + 1] & 0xF0) | (l2capinbuf[(uint16_t)a] << 0x08));
|
||||
else if (a == mZmove)
|
||||
return ((l2capinbuf[(uint16_t)a + 1] << 0x0F) | (l2capinbuf[(uint16_t)a] << 0x0C));
|
||||
*/
|
||||
else if (a == mXmove || a == mYmove || a == mZmove) { // These are all 12-bits long
|
||||
if (a == mXmove || a == mYmove)
|
||||
return (((l2capinbuf[(uint16_t)a] & 0x0F) << 8) | (l2capinbuf[(uint16_t)a + 1]));
|
||||
else // mZmove
|
||||
return ((l2capinbuf[(uint16_t)a] << 4) | (l2capinbuf[(uint16_t)a + 1] >> 4));
|
||||
return ((l2capinbuf[(uint16_t)a] << 4) | (l2capinbuf[(uint16_t)a + 1] & 0xF0 ) >> 4);
|
||||
}
|
||||
else if (a == tempMove) // The tempearature is 12 bits long too
|
||||
return ((l2capinbuf[(uint16_t)a] << 4) | ((l2capinbuf[(uint16_t)a + 1] & 0xF0) >> 4));
|
||||
|
@ -133,6 +124,30 @@ double PS3BT::getAngle(Angle a) {
|
|||
return angle;
|
||||
}
|
||||
}
|
||||
double PS3BT::get9DOFValues(Sensor a) { // Thanks to Manfred Piendl
|
||||
int16_t value = getSensor(a);
|
||||
if (a == mXmove || a == mYmove || a == mZmove) {
|
||||
if (value > 2047)
|
||||
value -= 0x1000;
|
||||
return (double)value/3.2; // unit: muT = 10^(-6) Tesla
|
||||
}
|
||||
else if (a == aXmove || a == aYmove || a == aZmove) {
|
||||
if (value < 0)
|
||||
value += 0x8000;
|
||||
else
|
||||
value -= 0x8000;
|
||||
return (double)value/442.0; // unit: m/(s^2)
|
||||
}
|
||||
else if (a == gXmove || a == gYmove || a == gZmove) {
|
||||
if (value < 0)
|
||||
value += 0x8000;
|
||||
else
|
||||
value -= 0x8000;
|
||||
return (double)value/9.6; // unit: deg/s
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
String PS3BT::getTemperature() {
|
||||
if(PS3MoveConnected) {
|
||||
int16_t input = getSensor(tempMove);
|
||||
|
|
1
PS3BT.h
1
PS3BT.h
|
@ -74,6 +74,7 @@ public:
|
|||
uint8_t getAnalogHat(AnalogHat a);
|
||||
int16_t getSensor(Sensor a);
|
||||
double getAngle(Angle a);
|
||||
double get9DOFValues(Sensor a);
|
||||
bool getStatus(Status c);
|
||||
String getStatusString();
|
||||
String getTemperature();
|
||||
|
|
|
@ -21,6 +21,7 @@ getAnalogButton KEYWORD2
|
|||
getAnalogHat KEYWORD2
|
||||
getSensor KEYWORD2
|
||||
getAngle KEYWORD2
|
||||
get9DOFValues KEYWORD2
|
||||
getStatus KEYWORD2
|
||||
getStatusString KEYWORD2
|
||||
getTemperature KEYWORD2
|
||||
|
|
Loading…
Reference in a new issue