Skip to content

Commit b062f21

Browse files
bradjcalevy
authored andcommitted
examples: add temperature test
1 parent 8763a8c commit b062f21

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Makefile for user application
2+
3+
# Specify this directory relative to the current application.
4+
TOCK_USERLAND_BASE_DIR = ../../..
5+
6+
# Which files to compile.
7+
C_SRCS := $(wildcard *.c)
8+
9+
# Include userland master makefile. Contains rules and flags for actually
10+
# building the application.
11+
include $(TOCK_USERLAND_BASE_DIR)/AppMakefile.mk
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Simple Temperature Test
2+
=======================
3+
4+
Uses libtock-sync to read the temperature sensor.

examples/tests/temperature/main.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
#include <string.h>
4+
5+
#include <libtock-sync/sensors/temperature.h>
6+
7+
int main(void) {
8+
returncode_t ret;
9+
10+
if (!libtock_temperature_exists()) {
11+
printf("[Temperature] No temperature sensor found.\n");
12+
exit(-1);
13+
}
14+
15+
int temp;
16+
ret = libtocksync_temperature_read(&temp);
17+
if (ret != RETURNCODE_SUCCESS) {
18+
printf("[Temperature] Error reading temperature sensor.\n");
19+
printf("[Temperature] %s\n", tock_strrcode(ret));
20+
exit(-2);
21+
}
22+
23+
int temp_ones = temp / 100;
24+
int temp_hundredths = temp - (temp_ones * 100);
25+
printf("[Temperature] %d.%d deg C\n", temp_ones, temp_hundredths);
26+
27+
return 0;
28+
}

0 commit comments

Comments
 (0)