mirror of
https://github.com/eclipse/upm.git
synced 2025-07-01 09:21:12 +03:00
bma250e: split into new library, C port, FTI, C++ wraps C
Signed-off-by: Jon Trulson <jtrulson@ics.com>
This commit is contained in:
@ -154,6 +154,7 @@ add_example (bmp280)
|
||||
add_example (abpdrrt005pg2a5)
|
||||
add_example (lcdks)
|
||||
add_example (bmg160)
|
||||
add_example (bma250e)
|
||||
|
||||
# Custom examples
|
||||
add_custom_example (nmea_gps_i2c-example-c nmea_gps_i2c.c nmea_gps)
|
||||
|
99
examples/c/bma250e.c
Normal file
99
examples/c/bma250e.c
Normal file
@ -0,0 +1,99 @@
|
||||
/*
|
||||
* 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 "bma250e.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 BMA250E instance using default i2c bus and address
|
||||
bma250e_context sensor = bma250e_init(BMA250E_DEFAULT_I2C_BUS,
|
||||
BMA250E_DEFAULT_ADDR, -1);
|
||||
#elif defined(CONFIG_BOARD_ARDUINO_101)
|
||||
// ARDUINO_101 (Quark core) where you must use SPI
|
||||
// Instantiate a BMA250E instance using default SPI bus and pin 10 as CS
|
||||
bma250e_context sensor = bma250e_init(BMA250E_DEFAULT_SPI_BUS,
|
||||
-1, 10);
|
||||
#else
|
||||
// everything else use I2C by default
|
||||
// Instantiate a BMA250E instance using default i2c bus and address
|
||||
bma250e_context sensor = bma250e_init(BMA250E_DEFAULT_I2C_BUS,
|
||||
BMA250E_DEFAULT_ADDR, -1);
|
||||
#endif
|
||||
|
||||
if (!sensor)
|
||||
{
|
||||
printf("bma250e_init() failed.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
// now output data every 250 milliseconds
|
||||
while (shouldRun)
|
||||
{
|
||||
float x, y, z;
|
||||
|
||||
if (bma250e_update(sensor))
|
||||
{
|
||||
printf("bma250e_update() failed\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
bma250e_get_accelerometer(sensor, &x, &y, &z);
|
||||
printf("Acceleration x: %f y: %f z: %f g\n",
|
||||
x, y, z);
|
||||
|
||||
printf("Compensation Temperature: %f C\n\n",
|
||||
bma250e_get_temperature(sensor));
|
||||
|
||||
upm_delay_ms(250);
|
||||
}
|
||||
|
||||
printf("Exiting...\n");
|
||||
|
||||
bma250e_close(sensor);
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2016 Intel Corporation.
|
||||
* Copyright (c) 2016-2017 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
@ -22,7 +22,7 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import upm_bmx055.BMA250E;
|
||||
import upm_bma250e.BMA250E;
|
||||
|
||||
public class BMA250E_Example
|
||||
{
|
||||
@ -42,11 +42,11 @@ public class BMA250E_Example
|
||||
// update our values from the sensor
|
||||
sensor.update();
|
||||
|
||||
float dataA[] = sensor.getAccelerometer();
|
||||
upm_bma250e.floatVector dataA = sensor.getAccelerometer();
|
||||
|
||||
System.out.println("Accelerometer x: " + dataA[0]
|
||||
+ " y: " + dataA[1]
|
||||
+ " z: " + dataA[2]
|
||||
System.out.println("Accelerometer x: " + dataA.get(0)
|
||||
+ " y: " + dataA.get(1)
|
||||
+ " z: " + dataA.get(2)
|
||||
+ " g");
|
||||
|
||||
System.out.println("Compensation Temperature: "
|
||||
|
@ -167,6 +167,7 @@ add_example(Ads1115Sample ads1x15)
|
||||
add_example(SensorTemplateSample sensortemplate)
|
||||
add_example(P9813Sample p9813)
|
||||
add_example(BMG160_Example bmg160)
|
||||
add_example(BMA250E_Example bma250e)
|
||||
|
||||
add_example_with_path(Jhd1313m1_lcdSample jhd1313m1 jhd1313m1)
|
||||
add_example_with_path(Jhd1313m1Sample jhd1313m1 jhd1313m1)
|
||||
@ -180,7 +181,6 @@ if(SWIG_VERSION VERSION_GREATER 3.0.8)
|
||||
add_example_with_path(BME280_InterfaceExample bmp280 bmp280)
|
||||
endif()
|
||||
|
||||
add_example_with_path(BMA250E_Example bmx055 bmx055)
|
||||
add_example_with_path(BMM150_Example bmx055 bmx055)
|
||||
add_example_with_path(BMC150_Example bmx055 bmx055)
|
||||
add_example_with_path(BMI055_Example bmx055 bmx055)
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2016 Intel Corporation.
|
||||
* Copyright (c) 2016-2017 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
@ -22,7 +22,7 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
var sensorObj = require('jsupm_bmx055');
|
||||
var sensorObj = require('jsupm_bma250e');
|
||||
|
||||
// Instantiate a BMA250E instance using default i2c bus and address
|
||||
var sensor = new sensorObj.BMA250E();
|
||||
@ -30,21 +30,17 @@ var sensor = new sensorObj.BMA250E();
|
||||
// For SPI, bus 0, you would pass -1 as the address, and a valid pin for CS:
|
||||
// BMA250E(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.getAccelerometer(x, y, z);
|
||||
var data = sensor.getAccelerometer();
|
||||
console.log("Accelerometer 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)
|
||||
+ " g");
|
||||
|
||||
// we show both C and F for temperature
|
||||
|
@ -1,6 +1,6 @@
|
||||
#!/usr/bin/python
|
||||
# Author: Jon Trulson <jtrulson@ics.com>
|
||||
# Copyright (c) 2016 Intel Corporation.
|
||||
# Copyright (c) 2016-2017 Intel Corporation.
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining
|
||||
# a copy of this software and associated documentation files (the
|
||||
@ -23,7 +23,7 @@
|
||||
|
||||
from __future__ import print_function
|
||||
import time, sys, signal, atexit
|
||||
from upm import pyupm_bmx055 as sensorObj
|
||||
from upm import pyupm_bma250e as sensorObj
|
||||
|
||||
def main():
|
||||
# Instantiate a BMP250E instance using default i2c bus and address
|
||||
@ -46,18 +46,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.getAccelerometer(x, y, z)
|
||||
print("Accelerometer x:", sensorObj.floatp_value(x), end=' ')
|
||||
print(" y:", sensorObj.floatp_value(y), end=' ')
|
||||
print(" z:", sensorObj.floatp_value(z), end=' ')
|
||||
data = sensor.getAccelerometer()
|
||||
print("Accelerometer x:", data[0], end=' ')
|
||||
print(" y:", data[1], end=' ')
|
||||
print(" z:", data[2], end=' ')
|
||||
print(" g")
|
||||
|
||||
# we show both C and F for temperature
|
||||
|
Reference in New Issue
Block a user