Added get9DOFValues

Thanks to Manfred Piendl for finding the values needed to convert the
Move sensor data into units
This commit is contained in:
Kristian Lauszus 2012-10-02 02:05:07 +02:00
parent 75a84c5e80
commit 81c7f22417
3 changed files with 35 additions and 18 deletions

View file

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

View file

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

View file

@ -21,6 +21,7 @@ getAnalogButton KEYWORD2
getAnalogHat KEYWORD2
getSensor KEYWORD2
getAngle KEYWORD2
get9DOFValues KEYWORD2
getStatus KEYWORD2
getStatusString KEYWORD2
getTemperature KEYWORD2