Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test/bmx280: New integration to generic BMX280 sensors tests #327

Merged
merged 1 commit into from
Jul 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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