tests/driver_bmx280: adapted to driver rework
functional changes: - enable test to test the driver in SPI mode style changes and code simplification: - enable SPI mode - fixed typos in doxygen - fixed line length issues - simplified code - use fmt for formatting numbers - use US_PER_SEC instead of magic value - use named return values provided by driver - use puts where ever applicable
This commit is contained in:
parent
b7f33bd84f
commit
c83e197676
@ -1,8 +1,8 @@
|
|||||||
include ../Makefile.tests_common
|
include ../Makefile.tests_common
|
||||||
|
|
||||||
DRIVER ?= bme280
|
DRIVER ?= bme280_i2c
|
||||||
|
|
||||||
|
USEMODULE += fmt
|
||||||
USEMODULE += $(DRIVER)
|
USEMODULE += $(DRIVER)
|
||||||
USEMODULE += xtimer
|
|
||||||
|
|
||||||
include $(RIOTBASE)/Makefile.include
|
include $(RIOTBASE)/Makefile.include
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2016 Kees Bakker, SODAQ
|
* Copyright (C) 2016 Kees Bakker, SODAQ
|
||||||
|
* 2018 Freie Universität Berlin
|
||||||
*
|
*
|
||||||
* This file is subject to the terms and conditions of the GNU Lesser
|
* This file is subject to the terms and conditions of the GNU Lesser
|
||||||
* General Public License v2.1. See the file LICENSE in the top level
|
* General Public License v2.1. See the file LICENSE in the top level
|
||||||
@ -7,50 +8,51 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ingroup tests
|
* @ingroup tests
|
||||||
* @{
|
* @{
|
||||||
*
|
*
|
||||||
* @file
|
* @file
|
||||||
* @brief Test application for the BME280 temperature, pressure
|
* @brief Test application for the BMX280 temperature, pressure, and
|
||||||
* and humidity sensor.
|
* humidity sensor driver
|
||||||
*
|
*
|
||||||
* @author Kees Bakker <kees@sodaq.com>
|
* @author Kees Bakker <kees@sodaq.com>
|
||||||
|
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
|
||||||
*
|
*
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <inttypes.h>
|
|
||||||
|
|
||||||
#include "bmx280_params.h"
|
#include "bmx280_params.h"
|
||||||
#include "bmx280.h"
|
#include "bmx280.h"
|
||||||
#include "xtimer.h"
|
#include "xtimer.h"
|
||||||
|
#include "fmt.h"
|
||||||
|
|
||||||
#define MAINLOOP_DELAY (2 * 1000 * 1000u) /* 2 seconds delay between printf's */
|
#define MAINLOOP_DELAY (2) /* read sensor every 2 seconds */
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
bmx280_t dev;
|
bmx280_t dev;
|
||||||
int result;
|
|
||||||
|
|
||||||
puts("BMX280 test application\n");
|
puts("BMX280 test application\n");
|
||||||
|
|
||||||
printf("+------------Initializing------------+\n");
|
puts("+------------Initializing------------+");
|
||||||
result = bmx280_init(&dev, &bmx280_params[0]);
|
switch (bmx280_init(&dev, &bmx280_params[0])) {
|
||||||
if (result == -1) {
|
case BMX280_ERR_BUS:
|
||||||
puts("[Error] The given i2c is not enabled");
|
puts("[Error] Something went wrong when using the I2C bus");
|
||||||
return 1;
|
return 1;
|
||||||
|
case BMX280_ERR_NODEV:
|
||||||
|
puts("[Error] Unable to communicate with any BMX280 device");
|
||||||
|
return 1;
|
||||||
|
default:
|
||||||
|
/* all good -> do nothing */
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result == -2) {
|
puts("Initialization successful\n");
|
||||||
printf("[Error] The sensor did not answer correctly at address 0x%02X\n", bmx280_params[0].i2c_addr);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("Initialization successful\n\n");
|
puts("+------------Calibration Data------------+");
|
||||||
|
|
||||||
printf("+------------Calibration Data------------+\n");
|
|
||||||
printf("dig_T1: %u\n", dev.calibration.dig_T1);
|
printf("dig_T1: %u\n", dev.calibration.dig_T1);
|
||||||
printf("dig_T2: %i\n", dev.calibration.dig_T2);
|
printf("dig_T2: %i\n", dev.calibration.dig_T2);
|
||||||
printf("dig_T3: %i\n", dev.calibration.dig_T3);
|
printf("dig_T3: %i\n", dev.calibration.dig_T3);
|
||||||
@ -65,7 +67,7 @@ int main(void)
|
|||||||
printf("dig_P8: %i\n", dev.calibration.dig_P8);
|
printf("dig_P8: %i\n", dev.calibration.dig_P8);
|
||||||
printf("dig_P9: %i\n", dev.calibration.dig_P9);
|
printf("dig_P9: %i\n", dev.calibration.dig_P9);
|
||||||
|
|
||||||
#if defined(MODULE_BME280)
|
#if defined(MODULE_BME280_SPI) || defined(MODULE_BME280_I2C)
|
||||||
printf("dig_H1: %u\n", dev.calibration.dig_H1);
|
printf("dig_H1: %u\n", dev.calibration.dig_H1);
|
||||||
printf("dig_H2: %i\n", dev.calibration.dig_H2);
|
printf("dig_H2: %i\n", dev.calibration.dig_H2);
|
||||||
printf("dig_H3: %i\n", dev.calibration.dig_H3);
|
printf("dig_H3: %i\n", dev.calibration.dig_H3);
|
||||||
@ -74,41 +76,34 @@ int main(void)
|
|||||||
printf("dig_H6: %i\n", dev.calibration.dig_H6);
|
printf("dig_H6: %i\n", dev.calibration.dig_H6);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
printf("\n+--------Starting Measurements--------+\n");
|
puts("\n+--------Starting Measurements--------+");
|
||||||
while (1) {
|
while (1) {
|
||||||
int16_t temperature;
|
/* read temperature, pressure [and humidity] values */
|
||||||
uint32_t pressure;
|
int16_t temperature = bmx280_read_temperature(&dev);
|
||||||
#if defined(MODULE_BME280)
|
uint32_t pressure = bmx280_read_pressure(&dev);
|
||||||
uint16_t humidity;
|
#if defined(MODULE_BME280_SPI) || defined(MODULE_BME280_I2C)
|
||||||
|
uint16_t humidity = bme280_read_humidity(&dev);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Get temperature in centi degrees Celsius */
|
/* format values for printing */
|
||||||
temperature = bmx280_read_temperature(&dev);
|
char str_temp[8];
|
||||||
|
size_t len = fmt_s16_dfp(str_temp, temperature, -2);
|
||||||
/* Get pressure in Pa */
|
str_temp[len] = '\0';
|
||||||
pressure = bmx280_read_pressure(&dev);
|
#if defined(MODULE_BME280_SPI) || defined(MODULE_BME280_I2C)
|
||||||
|
char str_hum[8];
|
||||||
#if defined(MODULE_BME280)
|
len = fmt_s16_dfp(str_hum, humidity, -2);
|
||||||
/* Get pressure in %rH */
|
str_hum[len] = '\0';
|
||||||
humidity = bme280_read_humidity(&dev);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
printf("Temperature [°C]: %d.%d\n"
|
/* print values to STDIO */
|
||||||
"Pressure [Pa]: %lu\n"
|
printf("Temperature [°C]: %s\n", str_temp);
|
||||||
#if defined(MODULE_BME280)
|
printf(" Pressure [Pa]: %" PRIu32 "\n", pressure);
|
||||||
"Humidity [%%rH]: %u.%02u\n"
|
#if defined(MODULE_BME280_SPI) || defined(MODULE_BME280_I2C)
|
||||||
|
printf(" Humidity [%%rH]: %s\n", str_hum);
|
||||||
#endif
|
#endif
|
||||||
"\n+-------------------------------------+\n",
|
puts("\n+-------------------------------------+\n");
|
||||||
temperature / 100, abs(temperature % 100) / 10,
|
|
||||||
#if defined(MODULE_BME280)
|
|
||||||
(unsigned long)pressure,
|
|
||||||
(unsigned int)(humidity / 100), (unsigned int)(humidity % 100)
|
|
||||||
#else
|
|
||||||
(unsigned long)pressure
|
|
||||||
#endif
|
|
||||||
);
|
|
||||||
|
|
||||||
xtimer_usleep(MAINLOOP_DELAY);
|
xtimer_sleep(MAINLOOP_DELAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user