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;
}

View File

@ -0,0 +1,91 @@
/*jslint node:true, vars:true, bitwise:true, unparam:true */
/*jshint unused:true */
/*
* 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.
*/
var digitalAccelerometer = require('jsupm_h3lis331dl');
// Instantiate an H3LIS331DL on I2C bus 0
var myDigitalAccelerometer = new digitalAccelerometer.H3LIS331DL(
digitalAccelerometer.H3LIS331DL_I2C_BUS,
digitalAccelerometer.H3LIS331DL_DEFAULT_I2C_ADDR);
// Initialize the device with default values
myDigitalAccelerometer.init();
var x, y, z;
x = digitalAccelerometer.new_intp();
y = digitalAccelerometer.new_intp();
z = digitalAccelerometer.new_intp();
var ax, ay, az;
ax = digitalAccelerometer.new_floatp();
ay = digitalAccelerometer.new_floatp();
az = digitalAccelerometer.new_floatp();
var outputStr;
var myInterval = setInterval(function()
{
myDigitalAccelerometer.update();
myDigitalAccelerometer.getRawXYZ(x, y, z);
outputStr = "Raw: X = " + digitalAccelerometer.intp_value(x) +
" Y = " + digitalAccelerometer.intp_value(y) +
" Z = " + digitalAccelerometer.intp_value(z);
console.log(outputStr);
myDigitalAccelerometer.getAcceleration(ax, ay, az);
outputStr = "Acceleration: AX = "
+ roundNum(digitalAccelerometer.floatp_value(ax), 6)
+ " AY = " + roundNum(digitalAccelerometer.floatp_value(ay), 6)
+ " AZ = " + roundNum(digitalAccelerometer.floatp_value(az), 6);
console.log(outputStr);
}, 500);
// round off output to match C example, which has 6 decimal places
function roundNum(num, decimalPlaces)
{
var extraNum = (1 / (Math.pow(10, decimalPlaces) * 1000));
return (Math.round((num + extraNum)
* (Math.pow(10, decimalPlaces))) / Math.pow(10, decimalPlaces));
}
// When exiting: clear interval and print message
process.on('SIGINT', function()
{
clearInterval(myInterval);
// clean up memory
digitalAccelerometer.delete_intp(x);
digitalAccelerometer.delete_intp(y);
digitalAccelerometer.delete_intp(z);
digitalAccelerometer.delete_floatp(ax);
digitalAccelerometer.delete_floatp(ay);
digitalAccelerometer.delete_floatp(az);
console.log("Exiting...");
process.exit(0);
});

View File

@ -0,0 +1,76 @@
#!/usr/bin/python
# 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.
import time, sys, signal, atexit
import pyupm_h3lis331dl as upmH3LIS331DL
# Instantiate an H3LIS331DL on I2C bus 0
myDigitalAccelerometer = upmH3LIS331DL.H3LIS331DL(
upmH3LIS331DL.H3LIS331DL_I2C_BUS,
upmH3LIS331DL.H3LIS331DL_DEFAULT_I2C_ADDR);
## Exit handlers ##
# This function stops python from printing a stacktrace when you hit control-C
def SIGINTHandler(signum, frame):
raise SystemExit
# This function lets you run code on exit, including functions from myDigitalAccelerometer
def exitHandler():
print "Exiting"
sys.exit(0)
# Register exit handlers
atexit.register(exitHandler)
signal.signal(signal.SIGINT, SIGINTHandler)
# Initialize the device with default values
myDigitalAccelerometer.init()
x = upmH3LIS331DL.new_intp()
y = upmH3LIS331DL.new_intp()
z = upmH3LIS331DL.new_intp()
ax = upmH3LIS331DL.new_floatp()
ay = upmH3LIS331DL.new_floatp()
az = upmH3LIS331DL.new_floatp()
while (1):
myDigitalAccelerometer.update()
myDigitalAccelerometer.getRawXYZ(x, y, z)
outputStr = ("Raw: X = {0}"
" Y = {1}"
" Z = {2}").format(upmH3LIS331DL.intp_value(x),
upmH3LIS331DL.intp_value(y),
upmH3LIS331DL.intp_value(z))
print outputStr
myDigitalAccelerometer.getAcceleration(ax, ay, az)
outputStr = ("Acceleration: AX = {0}"
" AY = {1}"
" AZ = {2}").format(upmH3LIS331DL.floatp_value(ax),
upmH3LIS331DL.floatp_value(ay),
upmH3LIS331DL.floatp_value(az))
print outputStr
time.sleep(.5)