tests: adapt driver_mpl3115a2
This commit is contained in:
parent
c7375529e3
commit
9bed191b4f
@ -56,6 +56,7 @@ extern "C" {
|
|||||||
*/
|
*/
|
||||||
static const mpl3115a2_params_t mpl3115a2_params[] =
|
static const mpl3115a2_params_t mpl3115a2_params[] =
|
||||||
{
|
{
|
||||||
|
|
||||||
#ifdef MPL3115A2_PARAMS_CUSTOM
|
#ifdef MPL3115A2_PARAMS_CUSTOM
|
||||||
MPL3115A2_PARAMS_CUSTOM
|
MPL3115A2_PARAMS_CUSTOM
|
||||||
#else
|
#else
|
||||||
@ -63,6 +64,16 @@ static const mpl3115a2_params_t mpl3115a2_params[] =
|
|||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Additional meta information to keep in the SAUL registry
|
||||||
|
*/
|
||||||
|
static const saul_reg_info_t mpl3115a2_saul_info[] =
|
||||||
|
{
|
||||||
|
{
|
||||||
|
.name = "mpl3115a2"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -6,12 +6,4 @@ FEATURES_REQUIRED = periph_i2c
|
|||||||
USEMODULE += mpl3115a2
|
USEMODULE += mpl3115a2
|
||||||
USEMODULE += xtimer
|
USEMODULE += xtimer
|
||||||
|
|
||||||
# set default device parameters in case they are undefined
|
|
||||||
TEST_MPL3115A2_I2C ?= I2C_DEV\(0\)
|
|
||||||
TEST_MPL3115A2_ADDR ?= 0x60
|
|
||||||
|
|
||||||
# export parameters
|
|
||||||
CFLAGS += -DTEST_MPL3115A2_I2C=$(TEST_MPL3115A2_I2C)
|
|
||||||
CFLAGS += -DTEST_MPL3115A2_ADDR=$(TEST_MPL3115A2_ADDR)
|
|
||||||
|
|
||||||
include $(RIOTBASE)/Makefile.include
|
include $(RIOTBASE)/Makefile.include
|
||||||
|
|||||||
@ -2,8 +2,8 @@
|
|||||||
This is a manual test application for the MPL3115A2 driver.
|
This is a manual test application for the MPL3115A2 driver.
|
||||||
|
|
||||||
# Usage
|
# Usage
|
||||||
This test application will initialize the MPL3115A2 sensor with the following parameters:
|
This test application will initialize the MPL3115A2 sensor with parameter
|
||||||
- oversample ratio 128
|
oversample ratio 128
|
||||||
|
|
||||||
After initialization, the sensor reads the pressure and temperature values every 1s
|
After initialization, the sensor reads pressure, temperature values and device
|
||||||
and prints them to STDOUT.
|
state every 1s and prints them to STDOUT.
|
||||||
|
|||||||
@ -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 <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "xtimer.h"
|
#include "xtimer.h"
|
||||||
#include "mpl3115a2.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)
|
int main(void)
|
||||||
{
|
{
|
||||||
mpl3115a2_t dev;
|
|
||||||
uint32_t pressure;
|
|
||||||
int16_t temp;
|
|
||||||
uint8_t status;
|
|
||||||
|
|
||||||
puts("MPL3115A2 pressure sensor driver test application\n");
|
puts("MPL3115A2 pressure sensor driver test application\n");
|
||||||
printf("Initializing MPL3115A2 sensor at I2C_%i... ", TEST_MPL3115A2_I2C);
|
printf("Initializing MPL3115A2 sensor at I2C_%i... ", mpl3115a2_params[0].i2c);
|
||||||
if (mpl3115a2_init(&dev, TEST_MPL3115A2_I2C, TEST_MPL3115A2_ADDR,
|
|
||||||
MPL3115A2_OS_RATIO_DEFAULT) == 0) {
|
if (mpl3115a2_init(&dev, &mpl3115a2_params[0]) != MPL3115A2_OK) {
|
||||||
puts("[OK]\n");
|
puts("[FAILED] init device!");
|
||||||
}
|
return 1;
|
||||||
else {
|
|
||||||
puts("[Failed]");
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mpl3115a2_set_active(&dev)) {
|
if (mpl3115a2_set_active(&dev) != MPL3115A2_OK) {
|
||||||
puts("Measurement start failed.");
|
puts("[FAILED] activate measurement!");
|
||||||
return -1;
|
return 2;
|
||||||
}
|
}
|
||||||
|
puts("[SUCCESS]");
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
|
uint32_t pressure;
|
||||||
|
int16_t temp;
|
||||||
|
uint8_t status;
|
||||||
xtimer_usleep(SLEEP);
|
xtimer_usleep(SLEEP);
|
||||||
mpl3115a2_read_pressure(&dev, &pressure, &status);
|
if ((mpl3115a2_read_pressure(&dev, &pressure, &status) |
|
||||||
printf("Pressure: %u Status: %#02x\n", (unsigned int)pressure, status);
|
mpl3115a2_read_temp(&dev, &temp)) != MPL3115A2_OK) {
|
||||||
mpl3115a2_read_temp(&dev, &temp);
|
puts("[FAILED] read values!");
|
||||||
printf("Temperature: %d\n", temp/10);
|
}
|
||||||
|
else {
|
||||||
|
printf("Pressure: %u Pa, Temperature: %3d.%d C, State: %#02x\n",
|
||||||
|
(unsigned int)pressure, temp/10, abs(temp%10), status);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user