This sample reads the air pressure five times, a second apart, through
PRESSURE: the board’s pressure sensor, whatever drives it.
pbl_pressure_read() gives pascals; the sample prints hectopascals.
The reading is the pressure where the watch is, not corrected to sea level, so it is lower than a weather report’s by about 1.2 hPa for every 10 m of altitude. Only boards with a pressure sensor run it; the emulator has none.
pbl samples samples/drivers/pressure
every board
#include <stdint.h>
#include <stdio.h>
#include <pbl/drivers/pressure.h>
#include <pbl/kernel/delay.h>
#define READS 5
int main(void) {
for (int i = 0; i < READS; i++) {
uint32_t pa;
int ret;
/* Each read runs one conversion; the sensor sleeps in between. */
ret = pbl_pressure_read(PRESSURE, &pa);
if (ret != 0) {
fprintf(stderr, "pressure: read failed (%d)\n", ret);
return ret;
}
printf("pressure: %d.%02d hPa\n", (int)(pa / 100U), (int)(pa % 100U));
pbl_sleep_ms(1000);
}
printf("Sample done\n");
return 0;
}
pressure: \d+\.\d\d hPa
pressure: \d+\.\d\d hPa
pressure: \d+\.\d\d hPa
pressure: \d+\.\d\d hPa
pressure: \d+\.\d\d hPa
Sample done
Generated from PebbleOS 4bbc630fa. This page is maintained in the pebbleos repository: docs/samples/drivers/pressure.md.