h3lis331dl: Initial implementation

The driver implements support for the Grove 3-Axis Digital
Accelerometer(±400g), using the h3lis331dl chip.

Signed-off-by: Jon Trulson <jtrulson@ics.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
This commit is contained in:
Jon Trulson
2015-04-24 18:53:54 -06:00
committed by Mihai Tudor Panu
parent 5547d99609
commit c8d0aee873
9 changed files with 1468 additions and 0 deletions

View File

@ -119,6 +119,7 @@ add_executable (si114x-example si114x.cxx)
add_executable (maxsonarez-example maxsonarez.cxx)
add_executable (hm11-example hm11.cxx)
add_executable (ht9170-example ht9170.cxx)
add_executable (h3lis331dl-example h3lis331dl.cxx)
include_directories (${PROJECT_SOURCE_DIR}/src/hmc5883l)
include_directories (${PROJECT_SOURCE_DIR}/src/grove)
@ -216,6 +217,7 @@ include_directories (${PROJECT_SOURCE_DIR}/src/si114x)
include_directories (${PROJECT_SOURCE_DIR}/src/maxsonarez)
include_directories (${PROJECT_SOURCE_DIR}/src/hm11)
include_directories (${PROJECT_SOURCE_DIR}/src/ht9170)
include_directories (${PROJECT_SOURCE_DIR}/src/h3lis331dl)
target_link_libraries (hmc5883l-example hmc5883l ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (groveled-example grove ${CMAKE_THREAD_LIBS_INIT})
@ -336,3 +338,4 @@ target_link_libraries (si114x-example si114x ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (maxsonarez-example maxsonarez ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (hm11-example hm11 ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (ht9170-example ht9170 ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (h3lis331dl-example h3lis331dl ${CMAKE_THREAD_LIBS_INIT})

View File

@ -0,0 +1,80 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2015 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <unistd.h>
#include <signal.h>
#include <iostream>
#include "h3lis331dl.h"
using namespace std;
using namespace upm;
int shouldRun = true;
void sig_handler(int signo)
{
if (signo == SIGINT)
shouldRun = false;
}
int main(int argc, char **argv)
{
signal(SIGINT, sig_handler);
//! [Interesting]
// Instantiate an H3LIS331DL on I2C bus 0
upm::H3LIS331DL *accel = new upm::H3LIS331DL(H3LIS331DL_I2C_BUS,
H3LIS331DL_DEFAULT_I2C_ADDR);
// Initialize the device with default values
accel->init();
while (shouldRun)
{
int x, y, z;
float ax, ay, az;
accel->update();
accel->getRawXYZ(&x, &y, &z);
accel->getAcceleration(&ax, &ay, &az);
cout << "Raw: X = " << x << " Y = " << y << " Z = " << z << endl;
cout << "Acceleration: AX = " << ax << " AY = " << ay << " AZ = " << az
<< endl;
cout << endl;
usleep(500000);
}
//! [Interesting]
cout << "Exiting..." << endl;
delete accel;
return 0;
}