2016-03-10 12:18:56 -07:00
|
|
|
/*
|
|
|
|
* Author: Jon Trulson <jtrulson@ics.com>
|
|
|
|
* Copyright (c) 2016 Intel Corporation.
|
|
|
|
*
|
2019-07-30 19:41:32 -07:00
|
|
|
* This program and the accompanying materials are made available under the
|
|
|
|
* terms of the The MIT License which is available at
|
|
|
|
* https://opensource.org/licenses/MIT.
|
2016-03-10 12:18:56 -07:00
|
|
|
*
|
2019-07-30 19:41:32 -07:00
|
|
|
* SPDX-License-Identifier: MIT
|
2016-03-10 12:18:56 -07:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <signal.h>
|
2017-08-30 15:00:29 -07:00
|
|
|
|
2016-04-25 14:27:51 -07:00
|
|
|
#include "bmi160.hpp"
|
2017-08-30 15:00:29 -07:00
|
|
|
#include "upm_utilities.h"
|
2016-03-10 12:18:56 -07:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
int shouldRun = true;
|
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
void
|
|
|
|
sig_handler(int signo)
|
2016-03-10 12:18:56 -07:00
|
|
|
{
|
2017-08-30 15:00:29 -07:00
|
|
|
if (signo == SIGINT)
|
|
|
|
shouldRun = false;
|
2016-03-10 12:18:56 -07:00
|
|
|
}
|
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
int
|
|
|
|
main(int argc, char** argv)
|
2016-03-10 12:18:56 -07:00
|
|
|
{
|
2017-08-30 15:00:29 -07:00
|
|
|
signal(SIGINT, sig_handler);
|
|
|
|
//! [Interesting]
|
2016-03-10 12:18:56 -07:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
// Instantiate a BMI160 instance using default i2c bus and address
|
|
|
|
upm::BMI160 sensor;
|
2016-03-10 12:18:56 -07:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
while (shouldRun) {
|
|
|
|
// update our values from the sensor
|
|
|
|
sensor.update();
|
2016-03-10 12:18:56 -07:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
float dataX, dataY, dataZ;
|
2016-03-10 12:18:56 -07:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
sensor.getAccelerometer(&dataX, &dataY, &dataZ);
|
|
|
|
cout << "Accelerometer: ";
|
|
|
|
cout << "AX: " << dataX << " AY: " << dataY << " AZ: " << dataZ << endl;
|
2016-03-10 12:18:56 -07:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
sensor.getGyroscope(&dataX, &dataY, &dataZ);
|
|
|
|
cout << "Gryoscope: ";
|
|
|
|
cout << "GX: " << dataX << " GY: " << dataY << " GZ: " << dataZ << endl;
|
2016-03-10 12:18:56 -07:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
sensor.getMagnetometer(&dataX, &dataY, &dataZ);
|
|
|
|
cout << "Magnetometer: ";
|
|
|
|
cout << "MX: " << dataX << " MY: " << dataY << " MZ: " << dataZ << endl;
|
2016-03-10 12:18:56 -07:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
cout << endl;
|
2016-03-10 12:18:56 -07:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
upm_delay_us(500000);
|
2016-03-10 12:18:56 -07:00
|
|
|
}
|
2017-08-30 15:00:29 -07:00
|
|
|
//! [Interesting]
|
2016-03-10 12:18:56 -07:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
cout << "Exiting..." << endl;
|
2016-03-10 12:18:56 -07:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
return 0;
|
2016-03-10 12:18:56 -07:00
|
|
|
}
|