bmm150: split into new library, C port, FTI, C++ wraps C

Signed-off-by: Jon Trulson <jtrulson@ics.com>
This commit is contained in:
Jon Trulson
2017-03-29 13:15:45 -06:00
parent 7d789ec208
commit aeaf84ccc6
20 changed files with 2397 additions and 28 deletions

View File

@ -340,6 +340,8 @@ add_example (mma8x5x)
add_example (mag3110)
add_example (hdc1000)
add_example (bmg160)
add_example (bma250e)
add_example (bmm150)
# These are special cases where you specify example binary, source file and module(s)
include_directories (${PROJECT_SOURCE_DIR}/src)
@ -365,8 +367,6 @@ add_custom_example (adc-example-cxx adc-sensor.cxx "ads1x15")
add_custom_example (light-sensor-example-cxx light-sensor.cxx "si1132;max44009")
add_custom_example (light-controller-example-cxx light-controller.cxx "lp8860;ds1808lc;hlg150h")
add_custom_example (bme280-example-cxx bme280.cxx bmp280)
add_custom_example (bma250e-example-cxx bma250e.cxx bmx055)
add_custom_example (bmm150-example-cxx bmm150.cxx bmx055)
add_custom_example (bmc150-example-cxx bmc150.cxx bmx055)
add_custom_example (bmi055-example-cxx bmi055.cxx bmx055)
if (OPENZWAVE_FOUND)

View File

@ -155,6 +155,7 @@ add_example (abpdrrt005pg2a5)
add_example (lcdks)
add_example (bmg160)
add_example (bma250e)
add_example (bmm150)
# Custom examples
add_custom_example (nmea_gps_i2c-example-c nmea_gps_i2c.c nmea_gps)

96
examples/c/bmm150.c Normal file
View File

@ -0,0 +1,96 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2017 Intel Corporation.
*
* The MIT License
*
* 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 <stdio.h>
#include <signal.h>
#include "upm_utilities.h"
#include "bmm150.h"
bool shouldRun = true;
void sig_handler(int signo)
{
if (signo == SIGINT)
shouldRun = false;
}
int main(int argc, char **argv)
{
signal(SIGINT, sig_handler);
//! [Interesting]
#if defined(CONFIG_BOARD_ARDUINO_101_SSS)
// ARDUINO_101_SSS (ARC core) must use I2C
// Instantiate a BMM150 instance using default i2c bus and address
bmm150_context sensor = bmm150_init(BMM150_DEFAULT_I2C_BUS,
BMM150_DEFAULT_ADDR, -1);
#elif defined(CONFIG_BOARD_ARDUINO_101)
// ARDUINO_101 (Quark core) where you must use SPI
// Instantiate a BMM150 instance using default SPI bus and pin 10 as CS
bmm150_context sensor = bmm150_init(BMM150_DEFAULT_SPI_BUS,
-1, 10);
#else
// everything else use I2C by default
// Instantiate a BMM150 instance using default i2c bus and address
bmm150_context sensor = bmm150_init(BMM150_DEFAULT_I2C_BUS,
BMM150_DEFAULT_ADDR, -1);
#endif
if (!sensor)
{
printf("bmm150_init() failed.\n");
return 1;
}
// now output data every 250 milliseconds
while (shouldRun)
{
float x, y, z;
if (bmm150_update(sensor))
{
printf("bmm150_update() failed\n");
return 1;
}
bmm150_get_magnetometer(sensor, &x, &y, &z);
printf("Magnetometer x: %f y: %f z: %f g\n",
x, y, z);
upm_delay_ms(250);
}
printf("Exiting...\n");
bmm150_close(sensor);
//! [Interesting]
return 0;
}

View File

@ -2,6 +2,8 @@
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2016 Intel Corporation.
*
* The MIT License
*
* 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
@ -22,7 +24,7 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
import upm_bmx055.BMM150;
import upm_bmm150.BMM150;
public class BMM150_Example
{
@ -42,11 +44,11 @@ public class BMM150_Example
// update our values from the sensor
sensor.update();
float dataA[] = sensor.getMagnetometer();
upm_bmm150.floatVector data = sensor.getMagnetometer();
System.out.println("Magnetometer x: " + dataA[0]
+ " y: " + dataA[1]
+ " z: " + dataA[2]
System.out.println("Magnetometer x: " + data.get(0)
+ " y: " + data.get(1)
+ " z: " + data.get(2)
+ " uT");
System.out.println();

View File

@ -168,6 +168,7 @@ add_example(SensorTemplateSample sensortemplate)
add_example(P9813Sample p9813)
add_example(BMG160_Example bmg160)
add_example(BMA250E_Example bma250e)
add_example(BMM150_Example bmm150)
add_example_with_path(Jhd1313m1_lcdSample jhd1313m1 jhd1313m1)
add_example_with_path(Jhd1313m1Sample jhd1313m1 jhd1313m1)
@ -181,7 +182,6 @@ if(SWIG_VERSION VERSION_GREATER 3.0.8)
add_example_with_path(BME280_InterfaceExample bmp280 bmp280)
endif()
add_example_with_path(BMM150_Example bmx055 bmx055)
add_example_with_path(BMC150_Example bmx055 bmx055)
add_example_with_path(BMI055_Example bmx055 bmx055)
if (OPENZWAVE_FOUND)

View File

@ -2,6 +2,8 @@
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2016 Intel Corporation.
*
* The MIT License
*
* 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
@ -22,7 +24,7 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
var sensorObj = require('jsupm_bmx055');
var sensorObj = require('jsupm_bmm150');
// Instantiate a BMM150 instance using default i2c bus and address
var sensor = new sensorObj.BMM150();
@ -30,21 +32,17 @@ var sensor = new sensorObj.BMM150();
// For SPI, bus 0, you would pass -1 as the address, and a valid pin for CS:
// BMM150(0, -1, 10);
var x = new sensorObj.new_floatp();
var y = new sensorObj.new_floatp();
var z = new sensorObj.new_floatp();
// now output data every 250 milliseconds
setInterval(function()
{
// update our values from the sensor
sensor.update();
sensor.getMagnetometer(x, y, z);
var data = sensor.getMagnetometer();
console.log("Magnetometer x: "
+ sensorObj.floatp_value(x)
+ " y: " + sensorObj.floatp_value(y)
+ " z: " + sensorObj.floatp_value(z)
+ data.get(0)
+ " y: " + data.get(1)
+ " z: " + data.get(2)
+ " uT");
console.log();

View File

@ -1,6 +1,8 @@
#!/usr/bin/python
# Author: Jon Trulson <jtrulson@ics.com>
# Copyright (c) 2016 Intel Corporation.
# Copyright (c) 2016-2017 Intel Corporation.
#
# The MIT License
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
@ -23,7 +25,7 @@
from __future__ import print_function
import time, sys, signal, atexit
from upm import pyupm_bmx055 as sensorObj
from upm import pyupm_bmm150 as sensorObj
def main():
# Instantiate a BMP250E instance using default i2c bus and address
@ -46,18 +48,14 @@ def main():
atexit.register(exitHandler)
signal.signal(signal.SIGINT, SIGINTHandler)
x = sensorObj.new_floatp()
y = sensorObj.new_floatp()
z = sensorObj.new_floatp()
# now output data every 250 milliseconds
while (1):
sensor.update()
sensor.getMagnetometer(x, y, z)
print("Magnetometer x:", sensorObj.floatp_value(x), end=' ')
print(" y:", sensorObj.floatp_value(y), end=' ')
print(" z:", sensorObj.floatp_value(z), end=' ')
data = sensor.getMagnetometer()
print("Magnetometer x:", data[0], end=' ')
print(" y:", data[1], end=' ')
print(" z:", data[2], end=' ')
print(" uT")
print()