summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2021-12-13 21:54:01 +0100
committerDaniel Friesel <derf@finalrewind.org>2021-12-13 21:54:01 +0100
commit2baa0a1d8584b4fff1df548437882fa6c908350e (patch)
tree5dcdfb026774aeb3707d84443b4d94a617c27fb9
parent7f2e4f346d446acfd60ac2fc61dcae370f91e159 (diff)
mpu9250: Implement getMagnet function
TODO: Use ASA[XYZ] for sensitivity adjustment
-rw-r--r--include/driver/mpu9250.h2
-rw-r--r--src/driver/mpu9250.cc15
2 files changed, 16 insertions, 1 deletions
diff --git a/include/driver/mpu9250.h b/include/driver/mpu9250.h
index bc0a11f..5a12150 100644
--- a/include/driver/mpu9250.h
+++ b/include/driver/mpu9250.h
@@ -274,7 +274,7 @@ class MPU9250 {
bool getRawMagnet(int *x, int *y, int *z);
void getAccel(float *g_x, float *g_y, float *g_z);
void getGyro(float *dps_x, float *dps_y, float *dps_z);
- void getMagnet(int *x, int *y, int *z);
+ bool getMagnet(float *ut_x, float *ut_y, float *ut_z);
float getTemperature();
void setAccelEnable(bool x, bool y, bool z);
void setGyroEnable(bool x, bool y, bool z);
diff --git a/src/driver/mpu9250.cc b/src/driver/mpu9250.cc
index de47597..3ad91c7 100644
--- a/src/driver/mpu9250.cc
+++ b/src/driver/mpu9250.cc
@@ -222,6 +222,21 @@ bool MPU9250::getRawMagnet(int *x, int *y, int *z)
}
}
+bool MPU9250::getMagnet(float *ut_x, float *ut_y, float *ut_z)
+{
+ int x, y, z;
+ bool success = getRawMagnet(&x, &y, &z);
+
+ if (!success) {
+ return false;
+ }
+
+ *ut_x = x * 0.15;
+ *ut_y = y * 0.15;
+ *ut_z = z * 0.15;
+ return true;
+}
+
// mpu9250.dfa
void MPU9250::nineAxis()