forked from yoyojacky/Pet-Camera
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
64 lines (49 loc) · 1.31 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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <pthread.h>
#include <mraa/gpio.h>
int ir_state = 0; //syroelectric sensor state
//take photo thread
void *take_photo_thread (void *args){
for(;;){
if(ir_state){ //check sensor state
//get system time
char str[25];
sprintf(str,"%d.jpg",(int) time((time_t*)NULL));
//take photo
take_photo(str);
sleep (1);
//upload photo
char command[120];
sprintf(command,"curl --form \"fileupload=@%s\" http://www.lisperli.org/upload/?upload=yes",str);
system(command);
}
sleep(1);
}
}
int main(int argc, char** argv)
{
mraa_gpio_context ir_gpio = NULL;
//set ir io as input
ir_gpio = mraa_gpio_init(7);
if (ir_gpio == NULL) {
fprintf(stdout, "Could not initilaize ir_gpio\n");
return 1;
}
mraa_gpio_dir(ir_gpio, MRAA_GPIO_IN);
//create take photo thread
pthread_t t;
pthread_create(&t,NULL,take_photo_thread,NULL);
//pthread_join(t,NULL);
//main loop
for (;;) {
if( ir_state != mraa_gpio_read(ir_gpio)) {
ir_state = !ir_state;
printf("%d\n",ir_state);
sleep(1);
}
}
return 0;
}