This sample reads the temperature of the chip five times, a second apart,
through DIE_TEMP: the board’s die temperature sensor, whatever drives it.
pbl_temp_read() gives millidegrees Celsius.
On a watch the reading follows the chip, a few degrees above the room and rising under load. The emulator’s simulated sensor reads a fixed 25 C.
pbl samples samples/drivers/temp
every board
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <pbl/drivers/temp.h>
#include <pbl/kernel/delay.h>
#define READS 5
int main(void) {
for (int i = 0; i < READS; i++) {
int32_t millicelsius;
int ret;
/* DIE_TEMP is the board's die temperature sensor, whatever drives it. */
ret = pbl_temp_read(DIE_TEMP, &millicelsius);
if (ret != 0) {
fprintf(stderr, "temp: read failed (%d)\n", ret);
return ret;
}
printf("temp: %s%d.%d C\n", millicelsius < 0 ? "-" : "", (int)(abs(millicelsius) / 1000),
(int)(abs(millicelsius) % 1000 / 100));
pbl_sleep_ms(1000);
}
printf("Sample done\n");
return 0;
}
temp: -?\d+\.\d+ C
temp: -?\d+\.\d+ C
temp: -?\d+\.\d+ C
temp: -?\d+\.\d+ C
temp: -?\d+\.\d+ C
Sample done
Generated from PebbleOS 9e782207f. This page is maintained in the pebbleos repository: docs/samples/drivers/temp.md.