-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
84 lines (64 loc) · 2.01 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
#include <wiringPi.h>
#include <stdlib.h>
#include "umidade.h"
#include "mqtt.h"
#include "debug.h"
#include "temperatura.h"
#include "pressao.h"
#include "vento.h"
#include "config.h"
volatile int terminate = 0;
static int pronto = 0;
volatile int sensor_umidade = 0;
volatile int sensor_temperatura = 0;
volatile int sensor_pressao = 0;
volatile int sensor_vento = 0;
volatile int conexao_mqtt = 0;
void esta_pronto(void);
void *thread_status(void *pVoid);
int main() {
pthread_t status, s1, s2, s3, s4;
status = s1 = s2 = s3 = s4 = 0;
TRACE("Configurando wiringPi\n");
if (wiringPiSetup()) {
exit(1);
}
pthread_create(&status, NULL, thread_status, NULL);
pthread_detach(status);
mqtt();
TRACE("Inicializando sensores...\n");
pthread_create(&s1, NULL, umidade, NULL);
pthread_create(&s2, NULL, temperatura, NULL);
pthread_create(&s3, NULL, pressao, NULL);
pthread_create(&s4, NULL, vento, NULL);
pthread_join(s1, NULL);
pthread_join(s2, NULL);
pthread_join(s3, NULL);
pthread_join(s4, NULL);
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
while (1);
#pragma clang diagnostic pop
}
void *thread_status(void *pVoid) {
TRACE("Setando pino %d como %d\n", LED_STATUS, OUTPUT);
pinMode(LED_STATUS, OUTPUT);
while (!terminate) {
while (!pronto) {
delay(500);
digitalWrite(LED_STATUS, LOW);
delay(500);
digitalWrite(LED_STATUS, HIGH);
esta_pronto();
TRACE("pronto: [%d]\n", pronto);
}
digitalWrite(LED_STATUS, LOW);
}
digitalWrite(LED_STATUS, HIGH);
return NULL;
}
void esta_pronto(void) {
TRACE("sensor_umidade [%d], sensor_temperatura [%d], sensor_pressao [%d], sensor_vento [%d], conexao_mqtt [%d]\n",
sensor_umidade, sensor_temperatura, sensor_pressao, sensor_vento, conexao_mqtt);
pronto = sensor_umidade && sensor_temperatura && sensor_pressao && sensor_vento && conexao_mqtt;
}