diff options
author | Daniel Friesel <derf@finalrewind.org> | 2019-11-01 21:19:25 +0100 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2019-11-01 21:19:25 +0100 |
commit | 1082a82fabd84fb2f23f182fa7f9ed76db9071d6 (patch) | |
tree | b85c24d29f1a8a612fec9e0325db8d0ddb6b788d /src/app/mpu9250_motionlog | |
parent | 2d62ccb5bb0f8cea5d6a75e6fd74a7d3cdbd0c69 (diff) |
MPU9250: Add SparkFun constants and non-raw readout of Accel and Gyro
Diffstat (limited to 'src/app/mpu9250_motionlog')
-rw-r--r-- | src/app/mpu9250_motionlog/Makefile.inc | 2 | ||||
-rw-r--r-- | src/app/mpu9250_motionlog/main.cc | 66 |
2 files changed, 68 insertions, 0 deletions
diff --git a/src/app/mpu9250_motionlog/Makefile.inc b/src/app/mpu9250_motionlog/Makefile.inc new file mode 100644 index 0000000..e273aaa --- /dev/null +++ b/src/app/mpu9250_motionlog/Makefile.inc @@ -0,0 +1,2 @@ +arch_drivers += ,i2c +drivers += ,mpu9250 diff --git a/src/app/mpu9250_motionlog/main.cc b/src/app/mpu9250_motionlog/main.cc new file mode 100644 index 0000000..fc9ac1d --- /dev/null +++ b/src/app/mpu9250_motionlog/main.cc @@ -0,0 +1,66 @@ +#include "arch.h" +#include "driver/gpio.h" +#include "driver/stdout.h" +#if defined(MULTIPASS_ARCH_HAS_I2C) && !defined(DRIVER_SOFTI2C) +#include "driver/i2c.h" +#else +#include "driver/soft_i2c.h" +#endif +#include "driver/mpu9250.h" + +#define UPDATE_MIN(min_val, val) if ((val) < (min_val)) { (min_val) = (val); } +#define UPDATE_MAX(max_val, val) if ((val) > (max_val)) { (max_val) = (val); } + +int main(void) +{ + int ax, ay, az, gx, gy, gz; + int max_ax, max_ay, max_az, max_gx, max_gy, max_gz; + int min_ax, min_ay, min_az, min_gx, min_gy, min_gz; + unsigned char i = 0; + + arch.setup(); + gpio.setup(); + kout.setup(); + + if (i2c.setup() != 0) { + kout << "I2C setup failed" << endl; + return 1; + } + + kout << "I2C setup OK" << endl; + + mpu9250.init(); + + while (1) { + mpu9250.getRawAccel(&ax, &ay, &az); + mpu9250.getRawGyro(&gx, &gy, &gz); + + UPDATE_MIN(min_ax, ax); + UPDATE_MIN(min_ay, ay); + UPDATE_MIN(min_az, az); + UPDATE_MIN(min_gx, gx); + UPDATE_MIN(min_gy, gy); + UPDATE_MIN(min_gz, gz); + UPDATE_MAX(max_ax, ax); + UPDATE_MAX(max_ay, ay); + UPDATE_MAX(max_az, az); + UPDATE_MAX(max_gx, gx); + UPDATE_MAX(max_gy, gy); + UPDATE_MAX(max_gz, gz); + + if (i++ == 200) { + kout << "Temp: " << mpu9250.getTemperature() << endl; + kout << "Min Accel: " << min_ax << " / " << min_ay << " / " << min_az << endl; + kout << "Max Accel: " << max_ax << " / " << max_ay << " / " << max_az << endl; + kout << "Min Gyro: " << min_gx << " / " << min_gy << " / " << min_gz << endl; + kout << "Max Gyro: " << max_gx << " / " << max_gy << " / " << max_gz << endl; + min_ax = min_ay = min_az = 0; + min_gx = min_gy = min_gz = 0; + max_ax = max_ay = max_az = 0; + max_gx = max_gy = max_gz = 0; + i = 0; + } + } + + return 0; +} |