From 56d20a8f44753da1d0776b55fb36485c89332e18 Mon Sep 17 00:00:00 2001 From: Cameron Goddard Date: Wed, 16 Oct 2024 18:23:17 -0400 Subject: [PATCH] refactor settings --- bmp388.cpp | 13 +++++++------ examples/CMakeLists.txt | 2 +- examples/poll_data.cpp | 18 ++++++++---------- 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/bmp388.cpp b/bmp388.cpp index 3b9b8cd..8210b34 100644 --- a/bmp388.cpp +++ b/bmp388.cpp @@ -23,14 +23,8 @@ bool BMP388::begin() { return false; } - return true; -} - -bool BMP388::read_pressure(float *pressure) { uint16_t settings_sel = 0; struct bmp3_settings settings = {0}; - struct bmp3_status status = {{0}}; - struct bmp3_data data; settings.int_settings.drdy_en = BMP3_ENABLE; settings.press_en = BMP3_ENABLE; @@ -56,6 +50,13 @@ bool BMP388::read_pressure(float *pressure) { return false; } + return true; +} + +bool BMP388::read_pressure(float *pressure) { + struct bmp3_status status = {{0}}; + struct bmp3_data data; + ret = bmp3_get_status(&status, &device); if (ret != BMP3_OK) { return false; diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 38fa989..a59fd75 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -28,4 +28,4 @@ pico_enable_stdio_usb(${PROJECT_NAME} 1) pico_enable_stdio_uart(${PROJECT_NAME} 0) # Create map/bin/hex file etc. -pico_add_extra_outputs(${PROJECT_NAME}) \ No newline at end of file +pico_add_uf2_output(${PROJECT_NAME}) \ No newline at end of file diff --git a/examples/poll_data.cpp b/examples/poll_data.cpp index 3cf3ea6..94efb18 100644 --- a/examples/poll_data.cpp +++ b/examples/poll_data.cpp @@ -13,7 +13,7 @@ BMP388 altimeter(I2C_PORT); int main() { stdio_init_all(); - i2c_init(I2C_PORT, 100 * 1000); + i2c_init(I2C_PORT, 400 * 1000); gpio_set_function(I2C_SDA, GPIO_FUNC_I2C); gpio_set_function(I2C_SCL, GPIO_FUNC_I2C); @@ -30,23 +30,21 @@ int main() { sleep_ms(1000); } - float pressure, altitude; + float ref_pressure, altitude; bool ret; - while (true) { - ret = altimeter.read_pressure(&pressure); - if (!ret) { - printf("Altimeter failed to read pressure\n"); - } + altimeter.read_pressure(&ref_pressure); + sleep_ms(100); + altimeter.read_pressure(&ref_pressure); - ret = altimeter.read_altitude(&altitude, SEA_LEVEL_PRESSURE_HPA); + while (true) { + ret = altimeter.read_altitude(&altitude, ref_pressure); if (!ret) { printf("Altimeter failed to read altitude\n"); } - printf("Pressure: %.3f\n", pressure); printf("Altitude: %.3f\n", altitude); - sleep_ms(1000); + sleep_ms(40); } return 0;