Skip to content

Commit

Permalink
Merge pull request #327 from eduazocar/feature/test_bmx280
Browse files Browse the repository at this point in the history
test/bmx280: New integration to generic BMX280 sensors tests
  • Loading branch information
CW-75 authored Jul 26, 2022
2 parents 0c29af9 + b62d261 commit 320cf06
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 12 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
33 changes: 21 additions & 12 deletions tests/driver_bme280/main.c → tests/driver_bmx280/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,17 @@
#include "embUnit.h"

bmx280_t bme280;
#if (MODULE_BME280_I2C) || (MODULE_BME_280_SPI)
char sensor_id = 'E';
#else
char sensor_id = 'P';
#endif

static const bmx280_params_t default_bme280_params[] = {
{.i2c_dev = I2C_DEV(0), .i2c_addr = 0x76, BMX280_PARAM_MISC},
};

void bme280_init(void) {
void bmx280_init_test(void) {
// It should be initialized
int error = bmx280_init(&bme280, &default_bme280_params[0]);

Expand All @@ -44,10 +49,10 @@ void bme280_init(void) {
printf("[Error] Something went wrong when using the I2C bus\n");
break;
case BMX280_ERR_NODEV:
printf("[Error] Unable to communicate with the BME280 device\n");
printf("[Error] Unable to communicate with the BM%c280 device\n", sensor_id);
break;
case BMX280_OK:
printf("BME280 - Initialized\n");
printf("BM%c280 - Initialized\n", sensor_id);
break;
default:
printf("[Error] This should never happen\n");
Expand All @@ -56,29 +61,30 @@ void bme280_init(void) {
TEST_ASSERT_EQUAL_INT(0, error);
}

void bme280_get_temperature(void) {
void bmx280_get_temperature(void) {
// It should be able to read temperature
int16_t temperature = bmx280_read_temperature(&bme280);

char str_temperature[8];
size_t len = fmt_s16_dfp(str_temperature, temperature, -2);
str_temperature[len] = '\0';
printf("BME280 - Temperature: %s ºC\n", str_temperature);
printf("BM%c280 - Temperature: %s ºC\n", sensor_id, str_temperature);

// It should be greater than -32768
TEST_ASSERT(temperature > -32768);
}

void bme280_get_pressure(void) {
void bmx280_get_pressure(void) {
// It should be able to read pressure in Pascal [Pa]
uint32_t pressure = bmx280_read_pressure(&bme280);

printf("BME280 - Pressure: %" PRIu32 " Pa\n", pressure);
printf("BM%c280 - Pressure: %" PRIu32 " Pa\n", sensor_id, pressure);

// It should be less than 4294967295 or 0xFFFFFFFF
TEST_ASSERT(pressure < 4294967295);
}

#if (MODULE_BME280_I2C) || (MODULE_BME_280_SPI)
void bme280_get_humiditty(void) {
// It should be able to read humidity
uint16_t humidity = bme280_read_humidity(&bme280);
Expand All @@ -91,14 +97,17 @@ void bme280_get_humiditty(void) {
// It should be greater than zero
TEST_ASSERT(humidity > 0);
}
#endif

Test *test_bme280_driver(void) {

EMB_UNIT_TESTFIXTURES(fixtures){
new_TestFixture(bme280_init),
new_TestFixture(bme280_get_temperature),
new_TestFixture(bme280_get_pressure),
EMB_UNIT_TESTFIXTURES(fixtures) {
new_TestFixture(bmx280_init_test),
new_TestFixture(bmx280_get_temperature),
new_TestFixture(bmx280_get_pressure),
#if (MODULE_BME280_I2C) || (MODULE_BME_280_SPI)
new_TestFixture(bme280_get_humiditty),
#endif
};

EMB_UNIT_TESTCALLER(test_bme280_driver, NULL, NULL, fixtures);
Expand All @@ -108,7 +117,7 @@ Test *test_bme280_driver(void) {

int main(void) {
printf("\n");
printf("Test BME280 driver\n");
printf("Test BM%c280 driver\n", sensor_id);

TESTS_START();
TESTS_RUN(test_bme280_driver());
Expand Down
File renamed without changes.

0 comments on commit 320cf06

Please sign in to comment.