-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
102 lines (75 loc) · 2.14 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include "architecture.h"
#include "thread.h"
#include "xtimer.h"
#include "ztimer.h"
#include "uuid.h"
#include "clk.h"
#include <stdio.h>
#include <string.h>
#include "shell.h"
#include "cpu.h"
#include "periph_conf.h"
#include "ds18.h"
#include "ds18_params.h"
#define SAMPLING_PERIOD 1
int test(int argc, char **argv)
{
ds18_t dev;
int result;
puts("DS18B20 test application\n");
const ds18_params_t params = {
.pin = GPIO_PIN(PORT_A, 8),
.out_mode = DS18_PARAM_PULL
};
printf("+------------Initializing------------+\n");
result = ds18_init(&dev, ¶ms);
/*
#define LED0_PIN GPIO_PIN(PORT_B, 0)
#define LED0_MASK (1 << 0)
#define LED0_ON (GPIOB->PCOR = LED0_MASK)
#define LED0_OFF (GPIOB->PSOR = LED0_MASK)
#define LED0_TOGGLE (GPIOB->PTOR = LED0_MASK)
*/
// LED0_TOGGLE;
printf("RES: %d", result);
if (result == DS18_ERROR) {
puts("[Error] The sensor pin could not be initialized");
return 1;
}
printf("\n+--------Starting Measurements--------+\n");
while (1) {
int16_t temperature;
if (ds18_get_temperature(&dev, &temperature) == DS18_OK) {
temperature *= 0.8; // without this shows not correct temp.
bool negative = (temperature < 0);
if (negative) {
temperature = -temperature;
}
printf(
"Temperature [ºC]: %c%d.%02d"
"\n+-------------------------------------+\n",
negative ? '-': ' ',
temperature / 100,
temperature % 100
);
LED0_TOGGLE;
}
else {
puts("[Error] Could not read temperature. Exit proc");
break;
}
xtimer_sleep(SAMPLING_PERIOD);
}
return 0;
}
const shell_command_t commands[] = {
{ "t", "test", test },
{ NULL, NULL, NULL }
};
int main(void)
{
puts("Welcome to RIOT!");
char line_buf[SHELL_DEFAULT_BUFSIZE];
shell_run(commands, line_buf, SHELL_DEFAULT_BUFSIZE);
return 0;
}