2015-04-24 18:53:54 -06:00
|
|
|
/*
|
|
|
|
* Author: Jon Trulson <jtrulson@ics.com>
|
|
|
|
* Copyright (c) 2015 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.
|
2015-04-24 18:53:54 -06:00
|
|
|
*
|
2019-07-30 19:41:32 -07:00
|
|
|
* SPDX-License-Identifier: MIT
|
2015-04-24 18:53:54 -06:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <iostream>
|
2017-08-30 15:00:29 -07:00
|
|
|
#include <signal.h>
|
|
|
|
|
2016-04-25 14:27:51 -07:00
|
|
|
#include "h3lis331dl.hpp"
|
2017-08-30 15:00:29 -07:00
|
|
|
#include "upm_utilities.h"
|
2015-04-24 18:53:54 -06:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace upm;
|
|
|
|
|
|
|
|
int shouldRun = true;
|
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
void
|
|
|
|
sig_handler(int signo)
|
2015-04-24 18:53:54 -06:00
|
|
|
{
|
2017-08-30 15:00:29 -07:00
|
|
|
if (signo == SIGINT)
|
|
|
|
shouldRun = false;
|
2015-04-24 18:53:54 -06:00
|
|
|
}
|
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
int
|
|
|
|
main(int argc, char** argv)
|
2015-04-24 18:53:54 -06:00
|
|
|
{
|
2017-08-30 15:00:29 -07:00
|
|
|
signal(SIGINT, sig_handler);
|
|
|
|
|
|
|
|
//! [Interesting]
|
|
|
|
// Instantiate an H3LIS331DL on I2C bus 0
|
2015-04-24 18:53:54 -06:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
upm::H3LIS331DL accel(H3LIS331DL_I2C_BUS, H3LIS331DL_DEFAULT_I2C_ADDR);
|
2015-04-24 18:53:54 -06:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
// Initialize the device with default values
|
|
|
|
accel.init();
|
2015-04-24 18:53:54 -06:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
while (shouldRun) {
|
|
|
|
int x, y, z;
|
|
|
|
float ax, ay, az;
|
2015-04-24 18:53:54 -06:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
accel.update();
|
2015-04-24 18:53:54 -06:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
accel.getRawXYZ(&x, &y, &z);
|
|
|
|
accel.getAcceleration(&ax, &ay, &az);
|
2015-04-24 18:53:54 -06:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
cout << "Raw: X = " << x << " Y = " << y << " Z = " << z << endl;
|
2015-04-24 18:53:54 -06:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
cout << "Acceleration: AX = " << ax << " AY = " << ay << " AZ = " << az << endl;
|
2015-04-24 18:53:54 -06:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
cout << endl;
|
2015-04-24 18:53:54 -06:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
upm_delay_us(500000);
|
2015-04-24 18:53:54 -06:00
|
|
|
}
|
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
//! [Interesting]
|
2015-04-24 18:53:54 -06:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
cout << "Exiting..." << endl;
|
2015-04-24 18:53:54 -06:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
return 0;
|
2015-04-24 18:53:54 -06:00
|
|
|
}
|