upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
Data Structures | Functions | Typedefs
Include dependency graph for bmpx8x.h:

API Description

/*
* 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 "bmpx8x.h"
bool shouldRun = true;
void sig_handler(int signo)
{
if (signo == SIGINT)
shouldRun = false;
}
int main(int argc, char **argv)
{
signal(SIGINT, sig_handler);
// Instantiate a BMPX8X instance using default i2c bus and address
bmpx8x_context sensor = bmpx8x_init(BMPX8X_DEFAULT_I2C_BUS,
BMPX8X_DEFAULT_I2C_ADDR);
if (!sensor)
{
printf("bmpx8x_init() failed.\n");
return 1;
}
// Print the pressure, altitude, sea level, and
// temperature values every 0.5 seconds
while (shouldRun)
{
if (bmpx8x_update(sensor))
{
printf("bmpx8x_update() failed\n");
bmpx8x_close(sensor);
return 1;
}
// assume sea level pressure is 101325 Pa.
float altitude = bmpx8x_get_altitude(sensor, 101325);
int sealevel = bmpx8x_get_sealevel_pressure(sensor, altitude);
printf("Pressure: %d Pa, Temperature: %f C, "
"Altitude %f m, Sea level %d Pa\n",
altitude,
sealevel);
upm_delay_ms(500);
}
printf("Exiting...\n");
bmpx8x_close(sensor);
return 0;
}

Go to the source code of this file.

Data Structures

struct  _bmpx8x_context
 

Functions

bmpx8x_context bmpx8x_init (int bus, int addr)
 
void bmpx8x_close (bmpx8x_context dev)
 
uint8_t bmpx8x_get_chip_id (const bmpx8x_context dev)
 
upm_result_t bmpx8x_devinit (const bmpx8x_context dev, BMPX8X_OSS_T oss)
 
upm_result_t bmpx8x_reset (const bmpx8x_context dev)
 
upm_result_t bmpx8x_update (const bmpx8x_context dev)
 
void bmpx8x_set_oversampling (const bmpx8x_context dev, BMPX8X_OSS_T oss)
 
int bmpx8x_get_pressure (const bmpx8x_context dev)
 
float bmpx8x_get_temperature (const bmpx8x_context dev)
 
int bmpx8x_get_sealevel_pressure (const bmpx8x_context dev, float altitude)
 
float bmpx8x_get_altitude (const bmpx8x_context dev, int sealevel)
 
uint8_t bmpx8x_read_reg (const bmpx8x_context dev, uint8_t reg)
 
int bmpx8x_read_regs (const bmpx8x_context dev, uint8_t reg, uint8_t *buffer, int len)
 
upm_result_t bmpx8x_write_reg (const bmpx8x_context dev, uint8_t reg, uint8_t val)
 

Typedefs

typedef struct _bmpx8x_contextbmpx8x_context
 

Function Documentation

bmpx8x_context bmpx8x_init ( int  bus,
int  addr 
)

BMPX8X initialization.

By default, the device is initialized to it's highest accuracy (BMP085_OSS_ULTRAHIGHRES).

Parameters
busI2C bus number.
addrI2C address of the device.
Returns
Device context, or NULL if an error occurred.

Here is the call graph for this function:

void bmpx8x_close ( bmpx8x_context  dev)

BMPX8X close function.

Parameters
devDevice context.

Here is the caller graph for this function:

uint8_t bmpx8x_get_chip_id ( const bmpx8x_context  dev)

Return the chip ID.

Parameters
devThe device context.
Returns
The chip ID.

Here is the call graph for this function:

Here is the caller graph for this function:

upm_result_t bmpx8x_devinit ( const bmpx8x_context  dev,
BMPX8X_OSS_T  oss 
)

Initialize the device, read calibration data, and start operation. This function is called from bmpx8x_init() so it will not typically need to be called by a user unless the device is reset. This method will call bmpx8x_set_oversampling() with the passed parameter.

Parameters
devThe device context.
ossOne of the BMPX8X_OSS_T values. The default set at bmpx8x_init() time is BMP085_OSS_ULTRAHIGHRES.
Returns
UPM result.

Here is the call graph for this function:

Here is the caller graph for this function:

upm_result_t bmpx8x_reset ( const bmpx8x_context  dev)

Perform a device reset. The device will be reset as if it was just powered on. All compensation values will be lost. You should call bmpx8x_devinit() afterward, or perform the same steps that bmpx8x_devinit() performs before attempting to use the device.

Parameters
devThe device context.
Returns
UPM result.

Here is the call graph for this function:

Here is the caller graph for this function:

upm_result_t bmpx8x_update ( const bmpx8x_context  dev)

Update the internal stored values from sensor data.

Parameters
devThe device context.
Returns
UPM result.

Here is the call graph for this function:

Here is the caller graph for this function:

void bmpx8x_set_oversampling ( const bmpx8x_context  dev,
BMPX8X_OSS_T  oss 
)

Set the oversampling (precision mode) of the device. Higher precision requires more time to complete.

Parameters
devThe device context.
ossThe desired oversampling mode, one of the BMPX8X_OSS_T values.

Here is the caller graph for this function:

int bmpx8x_get_pressure ( const bmpx8x_context  dev)

Returns the pressure in Pascals. bmpx8x_update() must have been called prior to calling this function.

Parameters
devDevice context.
Returns
The pressure in Pascals.

Here is the caller graph for this function:

float bmpx8x_get_temperature ( const bmpx8x_context  dev)

Returns the temperature in degrees Celsius. bmpx8x_update() must have been called prior to calling this function.

Parameters
devDevice context.
Returns
The temperature in degrees Celsius.

Here is the caller graph for this function:

int bmpx8x_get_sealevel_pressure ( const bmpx8x_context  dev,
float  altitude 
)

With a given current altitude, calculate pressure at sea level. bmpx8x_update() must have been called prior to calling this function.

Parameters
devDevice context.
altitudeCurrent altitude in Meters.
Returns
The pressure in Pascals at sea level.

Here is the caller graph for this function:

float bmpx8x_get_altitude ( const bmpx8x_context  dev,
int  sealevel 
)

With a given sea level, calculate altitude in meters. bmpx8x_update() must have been called prior to calling this function.

Parameters
devDevice context.
sealevelSea level pressure in Pascals. If a negative number, or zero is supplied, a default sealevel of 101325 Pa will be used instead.
Returns
The current altitude in Meters.

Here is the caller graph for this function:

uint8_t bmpx8x_read_reg ( const bmpx8x_context  dev,
uint8_t  reg 
)

Read a register.

Parameters
devThe device context.
regThe register to read.
Returns
The value of the register.

Here is the caller graph for this function:

int bmpx8x_read_regs ( const bmpx8x_context  dev,
uint8_t  reg,
uint8_t *  buffer,
int  len 
)

Read contiguous registers into a buffer.

Parameters
devThe device context.
bufferThe buffer to store the results.
lenThe number of registers to read.
Returns
The number of bytes read, or -1 on error.

Here is the caller graph for this function:

upm_result_t bmpx8x_write_reg ( const bmpx8x_context  dev,
uint8_t  reg,
uint8_t  val 
)

Write to a register.

Parameters
devThe device context.
regThe register to write to.
valThe value to write.
Returns
UPM result.

Here is the caller graph for this function:

Typedef Documentation

typedef struct _bmpx8x_context * bmpx8x_context

Device context