|
|
|
@ -20,49 +20,45 @@
|
|
|
|
|
* @} |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
#ifndef TEST_MPL3115A2_I2C |
|
|
|
|
#error "TEST_MPL3115A2_I2C not defined" |
|
|
|
|
#endif |
|
|
|
|
#ifndef TEST_MPL3115A2_ADDR |
|
|
|
|
#error "TEST_MPL3115A2_ADDR not defined" |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
#include <stdio.h> |
|
|
|
|
#include <stdlib.h> |
|
|
|
|
|
|
|
|
|
#include "xtimer.h" |
|
|
|
|
#include "mpl3115a2.h" |
|
|
|
|
#include "mpl3115a2_params.h" |
|
|
|
|
|
|
|
|
|
#define SLEEP (1000 * 1000U) |
|
|
|
|
#define SLEEP (1UL * US_PER_SEC) |
|
|
|
|
static mpl3115a2_t dev; |
|
|
|
|
|
|
|
|
|
int main(void) |
|
|
|
|
{ |
|
|
|
|
mpl3115a2_t dev; |
|
|
|
|
uint32_t pressure; |
|
|
|
|
int16_t temp; |
|
|
|
|
uint8_t status; |
|
|
|
|
|
|
|
|
|
puts("MPL3115A2 pressure sensor driver test application\n"); |
|
|
|
|
printf("Initializing MPL3115A2 sensor at I2C_%i... ", TEST_MPL3115A2_I2C); |
|
|
|
|
if (mpl3115a2_init(&dev, TEST_MPL3115A2_I2C, TEST_MPL3115A2_ADDR, |
|
|
|
|
MPL3115A2_OS_RATIO_DEFAULT) == 0) { |
|
|
|
|
puts("[OK]\n"); |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
puts("[Failed]"); |
|
|
|
|
return -1; |
|
|
|
|
printf("Initializing MPL3115A2 sensor at I2C_%i... ", mpl3115a2_params[0].i2c); |
|
|
|
|
|
|
|
|
|
if (mpl3115a2_init(&dev, &mpl3115a2_params[0]) != MPL3115A2_OK) { |
|
|
|
|
puts("[FAILED] init device!"); |
|
|
|
|
return 1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (mpl3115a2_set_active(&dev)) { |
|
|
|
|
puts("Measurement start failed."); |
|
|
|
|
return -1; |
|
|
|
|
if (mpl3115a2_set_active(&dev) != MPL3115A2_OK) { |
|
|
|
|
puts("[FAILED] activate measurement!"); |
|
|
|
|
return 2; |
|
|
|
|
} |
|
|
|
|
puts("[SUCCESS]"); |
|
|
|
|
|
|
|
|
|
while (1) { |
|
|
|
|
uint32_t pressure; |
|
|
|
|
int16_t temp; |
|
|
|
|
uint8_t status; |
|
|
|
|
xtimer_usleep(SLEEP); |
|
|
|
|
mpl3115a2_read_pressure(&dev, &pressure, &status); |
|
|
|
|
printf("Pressure: %u Status: %#02x\n", (unsigned int)pressure, status); |
|
|
|
|
mpl3115a2_read_temp(&dev, &temp); |
|
|
|
|
printf("Temperature: %d\n", temp/10); |
|
|
|
|
if ((mpl3115a2_read_pressure(&dev, &pressure, &status) | |
|
|
|
|
mpl3115a2_read_temp(&dev, &temp)) != MPL3115A2_OK) { |
|
|
|
|
puts("[FAILED] read values!"); |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
printf("Pressure: %u Pa, Temperature: %3d.%d C, State: %#02x\n", |
|
|
|
|
(unsigned int)pressure, temp/10, abs(temp%10), status); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
|