lsm303: rename to lsm303dlh

There are a variety of LSM303 devices out there with various
incompatibilities and differing capabilities.  The current lsm303
driver in UPM only supports the LSM303DLH variant, so it has been
renamed to lsm303dlh to avoid confusion and to make it clear which
variant is actually supported.

All examples and source files have been renamed, including header
files.  In addition, the class name, LSM303, has been renamed to
LSM303DLH.  No other functionality or behavior has been changed.

Signed-off-by: Jon Trulson <jtrulson@ics.com>
This commit is contained in:
Jon Trulson 2017-04-12 11:49:20 -06:00
parent d9fd1af272
commit 19c58ebba2
13 changed files with 95 additions and 82 deletions

View File

@ -4,11 +4,23 @@ API Changes {#apichanges}
Here's a list of other API changes made to the library that break source/binary Here's a list of other API changes made to the library that break source/binary
compatibility between releases: compatibility between releases:
# current UPM master
* **The lsm303 driver has been renamed** There are a variety of
LSM303 devices out there with various incompatibilities and differing
capabilities. The current lsm303 driver in UPM only supports the
LSM303DLH variant, so it has been renamed to lsm303dlh to avoid
confusion and to make it clear which variant is actually supported.
All examples and source files have been renamed, including header
files. In addition, the class name, LSM303, has been renamed to
LSM303DLH. No other functionality or behavior has been changed.
# v1.2.0 # v1.2.0
* **Note for all drivers ported to C** As a general note concerning * **Note for all drivers ported to C** As a general note concerning
all of the drivers that have been ported to C: **external constants all of the drivers that have been ported to C: **external constants
have likely been renamed**. Previously in C++, most these constants have likely been renamed**. Previously in C++, most of these constants
were defined as enums in the *upm::classname* namespace. were defined as enums in the *upm::classname* namespace.
For drivers written in C, all of these constants are no longer in For drivers written in C, all of these constants are no longer in

View File

Before

Width:  |  Height:  |  Size: 29 KiB

After

Width:  |  Height:  |  Size: 29 KiB

View File

@ -25,19 +25,19 @@
#include <iostream> #include <iostream>
//! [Interesting] //! [Interesting]
#include "lsm303.hpp" #include "lsm303dlh.hpp"
int int
main(int argc, char **argv) main(int argc, char **argv)
{ {
// Instantiate LSM303 compass on I2C // Instantiate LSM303DLH compass on I2C
upm::LSM303 *sensor = new upm::LSM303(0); upm::LSM303DLH *sensor = new upm::LSM303DLH(0);
// Get the coordinate data // Get the coordinate data
sensor->getCoordinates(); sensor->getCoordinates();
int16_t* coor = sensor->getRawCoorData(); // in XYZ order. int16_t* coor = sensor->getRawCoorData(); // in XYZ order.
// The sensor returns XZY, but the driver compensates and makes it XYZ // The sensor returns XZY, but the driver compensates and makes it XYZ
// Print out the X, Y, and Z coordinate data using two different methods // Print out the X, Y, and Z coordinate data using two different methods
std::cout << "coor: rX " << (int)coor[0] std::cout << "coor: rX " << (int)coor[0]
<< " - rY " << (int)coor[1] << " - rY " << (int)coor[1]

View File

@ -86,7 +86,7 @@ add_example(Itg3200Sample itg3200)
add_example(Joystick12Sample joystick12) add_example(Joystick12Sample joystick12)
add_example(LDT0028Sample ldt0028) add_example(LDT0028Sample ldt0028)
add_example(LoLSample lol) add_example(LoLSample lol)
add_example(LSM303Sample lsm303) add_example(LSM303DLHSample lsm303dlh)
add_example(M24LR64ESample m24lr64e) add_example(M24LR64ESample m24lr64e)
add_example(MAX44000Sample max44000) add_example(MAX44000Sample max44000)
add_example(MHZ16Sample mhz16) add_example(MHZ16Sample mhz16)

View File

@ -23,12 +23,12 @@
*/ */
//NOT TESTED!!! //NOT TESTED!!!
public class LSM303Sample { public class LSM303DLHSample {
public static void main(String[] args) throws InterruptedException { public static void main(String[] args) throws InterruptedException {
// ! [Interesting] // ! [Interesting]
// Instantiate LSM303 compass on I2C // Instantiate LSM303DLH compass on I2C
upm_lsm303.LSM303 sensor = new upm_lsm303.LSM303(0); upm_lsm303dlh.LSM303DLH sensor = new upm_lsm303dlh.LSM303DLH(0);
// Get the coordinate data // Get the coordinate data
sensor.getCoordinates(); sensor.getCoordinates();
@ -56,4 +56,4 @@ public class LSM303Sample {
// ! [Interesting] // ! [Interesting]
} }
} }

View File

@ -22,15 +22,15 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
var accelrCompassSensor = require('jsupm_lsm303'); var accelrCompassSensor = require('jsupm_lsm303dlh');
// Instantiate LSM303 compass on I2C // Instantiate LSM303DLH compass on I2C
var myAccelrCompass = new accelrCompassSensor.LSM303(0); var myAccelrCompass = new accelrCompassSensor.LSM303DLH(0);
var successFail, coords, outputStr, accel; var successFail, coords, outputStr, accel;
var myInterval = setInterval(function() var myInterval = setInterval(function()
{ {
// Load coordinates into LSM303 object // Load coordinates into LSM303DLH object
successFail = myAccelrCompass.getCoordinates(); successFail = myAccelrCompass.getCoordinates();
// in XYZ order. The sensor returns XZY, // in XYZ order. The sensor returns XZY,
// but the driver compensates and makes it XYZ // but the driver compensates and makes it XYZ

View File

@ -25,11 +25,11 @@
from __future__ import print_function from __future__ import print_function
import time, sys, signal, atexit import time, sys, signal, atexit
from upm import pyupm_lsm303 as lsm303 from upm import pyupm_lsm303dlh as lsm303dlh
def main(): def main():
# Instantiate LSM303 compass on I2C # Instantiate LSM303DLH compass on I2C
myAccelrCompass = lsm303.LSM303(0) myAccelrCompass = lsm303dlh.LSM303DLH(0)
## Exit handlers ## ## Exit handlers ##
# This stops python from printing a stacktrace when you hit control-C # This stops python from printing a stacktrace when you hit control-C
@ -47,7 +47,7 @@ def main():
signal.signal(signal.SIGINT, SIGINTHandler) signal.signal(signal.SIGINT, SIGINTHandler)
while(1): while(1):
# Load coordinates into LSM303 object # Load coordinates into LSM303DLH object
successFail = myAccelrCompass.getCoordinates() successFail = myAccelrCompass.getCoordinates()
# in XYZ order. The sensor returns XZY, # in XYZ order. The sensor returns XZY,
# but the driver compensates and makes it XYZ # but the driver compensates and makes it XYZ

View File

@ -1,4 +1,4 @@
set (libname "lsm303") set (libname "lsm303dlh")
set (libdescription "Triaxial Accelerometer/magnetometer") set (libdescription "Triaxial Accelerometer/magnetometer")
set (module_src ${libname}.cxx) set (module_src ${libname}.cxx)
set (module_hpp ${libname}.hpp) set (module_hpp ${libname}.hpp)

View File

@ -1,8 +1,8 @@
%module javaupm_lsm303 %module javaupm_lsm303dlh
%include "../upm.i" %include "../upm.i"
%{ %{
#include "lsm303.hpp" #include "lsm303dlh.hpp"
%} %}
%typemap(jni) int16_t* "jshortArray" %typemap(jni) int16_t* "jshortArray"
@ -18,15 +18,15 @@
JCALL4(SetShortArrayRegion, jenv, $result, 0, 3, (jshort*)$1); JCALL4(SetShortArrayRegion, jenv, $result, 0, 3, (jshort*)$1);
} }
%include "lsm303.hpp" %include "lsm303dlh.hpp"
%pragma(java) jniclasscode=%{ %pragma(java) jniclasscode=%{
static { static {
try { try {
System.loadLibrary("javaupm_lsm303"); System.loadLibrary("javaupm_lsm303dlh");
} catch (UnsatisfiedLinkError e) { } catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load. \n" + e); System.err.println("Native code library failed to load. \n" + e);
System.exit(1); System.exit(1);
} }
} }
%} %}

View File

@ -1,4 +1,4 @@
%module jsupm_lsm303 %module jsupm_lsm303dlh
%include "../upm.i" %include "../upm.i"
%include "../carrays_int16_t.i" %include "../carrays_int16_t.i"
@ -9,7 +9,7 @@
} }
%{ %{
#include "lsm303.hpp" #include "lsm303dlh.hpp"
%} %}
%include "lsm303.hpp" %include "lsm303dlh.hpp"

View File

@ -31,11 +31,12 @@
#include <unistd.h> #include <unistd.h>
#include <stdlib.h> #include <stdlib.h>
#include "lsm303.hpp" #include "lsm303dlh.hpp"
using namespace upm; using namespace upm;
LSM303::LSM303(int bus, int addrMag, int addrAcc, int accScale) : m_i2c(bus) LSM303DLH::LSM303DLH(int bus, int addrMag, int addrAcc, int accScale) :
m_i2c(bus)
{ {
m_addrMag = addrMag; m_addrMag = addrMag;
m_addrAcc = addrAcc; m_addrAcc = addrAcc;
@ -45,11 +46,11 @@ LSM303::LSM303(int bus, int addrMag, int addrAcc, int accScale) : m_i2c(bus)
// scale can be 2, 4 or 8 // scale can be 2, 4 or 8
if (2 == accScale) { if (2 == accScale) {
setRegisterSafe(m_addrAcc, CTRL_REG4_A, 0x00); setRegisterSafe(m_addrAcc, CTRL_REG4_A, 0x00);
} else if (4 == accScale) { } else if (4 == accScale) {
setRegisterSafe(m_addrAcc, CTRL_REG4_A, 0x10); setRegisterSafe(m_addrAcc, CTRL_REG4_A, 0x10);
} else { // default; equivalent to 8g } else { // default; equivalent to 8g
setRegisterSafe(m_addrAcc, CTRL_REG4_A, 0x30); setRegisterSafe(m_addrAcc, CTRL_REG4_A, 0x30);
} }
// 0x10 = minimum datarate ~15Hz output rate // 0x10 = minimum datarate ~15Hz output rate
@ -65,7 +66,7 @@ LSM303::LSM303(int bus, int addrMag, int addrAcc, int accScale) : m_i2c(bus)
} }
float float
LSM303::getHeading() LSM303DLH::getHeading()
{ {
if (getCoordinates() != mraa::SUCCESS) { if (getCoordinates() != mraa::SUCCESS) {
return -1; return -1;
@ -80,37 +81,37 @@ LSM303::getHeading()
} }
int16_t* int16_t*
LSM303::getRawAccelData() LSM303DLH::getRawAccelData()
{ {
return &accel[0]; return &accel[0];
} }
int16_t* int16_t*
LSM303::getRawCoorData() LSM303DLH::getRawCoorData()
{ {
return &coor[0]; return &coor[0];
} }
int16_t int16_t
LSM303::getAccelX() LSM303DLH::getAccelX()
{ {
return accel[X]; return accel[X];
} }
int16_t int16_t
LSM303::getAccelY() LSM303DLH::getAccelY()
{ {
return accel[Y]; return accel[Y];
} }
int16_t int16_t
LSM303::getAccelZ() LSM303DLH::getAccelZ()
{ {
return accel[Z]; return accel[Z];
} }
mraa::Result mraa::Result
LSM303::getCoordinates() LSM303DLH::getCoordinates()
{ {
mraa::Result ret = mraa::SUCCESS; mraa::Result ret = mraa::SUCCESS;
@ -125,7 +126,7 @@ LSM303::getCoordinates()
// convert to coordinates // convert to coordinates
for (int i=0; i<3; i++) { for (int i=0; i<3; i++) {
coor[i] = (int16_t(buf[2*i] << 8)) coor[i] = (int16_t(buf[2*i] << 8))
| int16_t(buf[(2*i)+1]); | int16_t(buf[(2*i)+1]);
} }
// swap elements 1 and 2 to get things in natural XYZ order // swap elements 1 and 2 to get things in natural XYZ order
int16_t t = coor[2]; int16_t t = coor[2];
@ -137,24 +138,24 @@ LSM303::getCoordinates()
} }
int16_t int16_t
LSM303::getCoorX() { LSM303DLH::getCoorX() {
return coor[X]; return coor[X];
} }
int16_t int16_t
LSM303::getCoorY() { LSM303DLH::getCoorY() {
return coor[Y]; return coor[Y];
} }
int16_t int16_t
LSM303::getCoorZ() { LSM303DLH::getCoorZ() {
return coor[Z]; return coor[Z];
} }
// helper function that writes a value to the acc and then reads // helper function that writes a value to the acc and then reads
// FIX: shouldn't this be write-then-read? // FIX: shouldn't this be write-then-read?
int int
LSM303::readThenWrite(uint8_t reg) LSM303DLH::readThenWrite(uint8_t reg)
{ {
m_i2c.address(m_addrAcc); m_i2c.address(m_addrAcc);
m_i2c.writeByte(reg); m_i2c.writeByte(reg);
@ -163,16 +164,16 @@ LSM303::readThenWrite(uint8_t reg)
} }
mraa::Result mraa::Result
LSM303::getAcceleration() LSM303DLH::getAcceleration()
{ {
mraa::Result ret = mraa::SUCCESS; mraa::Result ret = mraa::SUCCESS;
accel[X] = (int16_t(readThenWrite(OUT_X_H_A)) << 8) accel[X] = (int16_t(readThenWrite(OUT_X_H_A)) << 8)
| int16_t(readThenWrite(OUT_X_L_A)); | int16_t(readThenWrite(OUT_X_L_A));
accel[Y] = (int16_t(readThenWrite(OUT_Y_H_A)) << 8) accel[Y] = (int16_t(readThenWrite(OUT_Y_H_A)) << 8)
| int16_t(readThenWrite(OUT_Y_L_A)); | int16_t(readThenWrite(OUT_Y_L_A));
accel[Z] = (int16_t(readThenWrite(OUT_Z_H_A)) << 8) accel[Z] = (int16_t(readThenWrite(OUT_Z_H_A)) << 8)
| int16_t(readThenWrite(OUT_Z_L_A)); | int16_t(readThenWrite(OUT_Z_L_A));
//printf("X=%x, Y=%x, Z=%x\n", accel[X], accel[Y], accel[Z]); //printf("X=%x, Y=%x, Z=%x\n", accel[X], accel[Y], accel[Z]);
return ret; return ret;
@ -180,7 +181,7 @@ LSM303::getAcceleration()
// helper function that sets a register and then checks the set was succesful // helper function that sets a register and then checks the set was succesful
mraa::Result mraa::Result
LSM303::setRegisterSafe(uint8_t slave, uint8_t sregister, uint8_t data) LSM303DLH::setRegisterSafe(uint8_t slave, uint8_t sregister, uint8_t data)
{ {
buf[0] = sregister; buf[0] = sregister;
buf[1] = data; buf[1] = data;

View File

@ -32,11 +32,11 @@
namespace upm { namespace upm {
/* LSM303 Address definitions */ /* LSM303DLH Address definitions */
#define LSM303_MAG 0x1E #define LSM303DLH_MAG 0x1E
#define LSM303_ACC 0x19 #define LSM303DLH_ACC 0x19
/* LSM303 Register definitions */ /* LSM303DLH Register definitions */
#define CTRL_REG1_A 0x20 #define CTRL_REG1_A 0x20
#define CTRL_REG2_A 0x21 #define CTRL_REG2_A 0x21
#define CTRL_REG3_A 0x22 #define CTRL_REG3_A 0x22
@ -61,14 +61,14 @@ namespace upm {
#define Z 2 #define Z 2
/** /**
* @brief LSM303 Accelerometer/Compass library * @brief LSM303DLH Accelerometer/Compass library
* @defgroup lsm303 libupm-lsm303 * @defgroup lsm303dlh libupm-lsm303dlh
* @ingroup seeed adafruit stmicro i2c accelerometer compass * @ingroup seeed adafruit stmicro i2c accelerometer compass
*/ */
/** /**
* @library lsm303 * @library lsm303dlh
* @sensor lsm303 * @sensor lsm303dlh
* @comname Triaxial Accelerometer/magnetometer * @comname Triaxial Accelerometer/magnetometer
* @altname Grove 6-Axis Accelerometer & Compass * @altname Grove 6-Axis Accelerometer & Compass
* @type accelerometer compass * @type accelerometer compass
@ -76,36 +76,36 @@ namespace upm {
* @web http://www.seeedstudio.com/wiki/Grove_-_6-Axis_Accelerometer%26Compass * @web http://www.seeedstudio.com/wiki/Grove_-_6-Axis_Accelerometer%26Compass
* @con i2c * @con i2c
* *
* @brief API for the LSM303 Accelerometer & Compass * @brief API for the LSM303DLH Accelerometer & Compass
* *
* This module defines the LSM303DLH 3-axis magnetometer/3-axis accelerometer. * This module defines the LSM303DLHDLH 3-axis magnetometer/3-axis accelerometer.
* This module was tested with the Seeed Studio* Grove 6-Axis Accelerometer & Compass * This module was tested with the Seeed Studio* Grove 6-Axis Accelerometer & Compass
* module used over I2C. The magnetometer and acceleromter are accessed * module used over I2C. The magnetometer and acceleromter are accessed
* at two seperate I2C addresses. * at two seperate I2C addresses.
* *
* @image html lsm303.jpeg * @image html lsm303dlh.jpeg
* @snippet lsm303.cxx Interesting * @snippet lsm303dlh.cxx Interesting
*/ */
class LSM303 { class LSM303DLH {
public: public:
/** /**
* Instantiates an LSM303 object * Instantiates an LSM303DLH object
* *
* @param bus I2C bus to use * @param bus I2C bus to use
* @param addrMag I2C address of the Magnetometer (default 0x1E) * @param addrMag I2C address of the Magnetometer (default 0x1E)
* @param addrAcc I2C address of the Accelerometer (default 0x19) * @param addrAcc I2C address of the Accelerometer (default 0x19)
* @param accScale Accelerometer scale, can be 2, 4 or 8 (default 8) * @param accScale Accelerometer scale, can be 2, 4 or 8 (default 8)
*/ */
LSM303 (int bus, LSM303DLH (int bus,
int addrMag=LSM303_MAG, int addrMag=LSM303DLH_MAG,
int addrAcc=LSM303_ACC, int addrAcc=LSM303DLH_ACC,
int accScale=8); int accScale=8);
/** /**
* LSM303 object destructor * LSM303DLH object destructor
* where is no more need for this here - I2c connection will be stopped * where is no more need for this here - I2c connection will be stopped
* automatically when m_i2c variable will go out of scope * automatically when m_i2c variable will go out of scope
* ~LSM303 (); * ~LSM303DLH ();
**/ **/
/** /**
@ -172,10 +172,10 @@ class LSM303 {
mraa::I2c m_i2c; mraa::I2c m_i2c;
int m_addrMag; int m_addrMag;
int m_addrAcc; int m_addrAcc;
uint8_t buf[6]; uint8_t buf[6];
int16_t coor[3]; int16_t coor[3];
int16_t accel[3]; int16_t accel[3];
}; };
} }

View File

@ -1,6 +1,6 @@
// Include doxygen-generated documentation // Include doxygen-generated documentation
%include "pyupm_doxy2swig.i" %include "pyupm_doxy2swig.i"
%module pyupm_lsm303 %module pyupm_lsm303dlh
%include "../upm.i" %include "../upm.i"
%include "../carrays_int16_t.i" %include "../carrays_int16_t.i"
@ -12,7 +12,7 @@
resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_int16Array, 0 | 0 ); resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_int16Array, 0 | 0 );
} }
%include "lsm303.hpp" %include "lsm303dlh.hpp"
%{ %{
#include "lsm303.hpp" #include "lsm303dlh.hpp"
%} %}