Skip to content

Commit

Permalink
refactor settings
Browse files Browse the repository at this point in the history
  • Loading branch information
cameron-goddard committed Oct 16, 2024
1 parent 60db22b commit 56d20a8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
13 changes: 7 additions & 6 deletions bmp388.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
pico_add_uf2_output(${PROJECT_NAME})
18 changes: 8 additions & 10 deletions examples/poll_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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;
Expand Down

0 comments on commit 56d20a8

Please sign in to comment.