-
Notifications
You must be signed in to change notification settings - Fork 0
/
thread_time.c
166 lines (97 loc) · 2.13 KB
/
thread_time.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#include <stdio.h>
#include <pthread.h>
#include <stdlib.h>
#include <time.h>
#include <bcm2835.h>
#include "pmedex.h"
/*
*
* Basic thread simple via pe2a.h
* You can see how to create Digital Output and Analog Output functions as using thread functions
* 2017 | [email protected]
* Compile : gcc -o thread_time thread_time.c pmedex.c -lbcm2835 -lpthread -std=gnu11
* Run : ./thread
*
*/
void *fTimePicker_1(); //thread1
void *fTimePicker_2(); //thread2
void *fTimePicker_3(); //thread3
void fDOSet();
void fAOSet();
void fGrassSetHigh();
void fGrassSetLow();
void fFlowerSetHigh();
void fFlowerSetLow();
int main(){
pthread_t thread1,thread2,thread3;
pthread_create(&thread1,NULL,&fTimePicker_1,NULL);
pthread_create(&thread2,NULL,&fTimePicker_2,NULL);
pthread_create(&thread3,NULL,&fTimePicker_3,NULL);
pthread_join(thread1,NULL);
pthread_join(thread2,NULL);
pthread_join(thread3,NULL);
exit(EXIT_SUCCESS);
return 0;
}
void fGrassSetHigh(){
pe2a_DO_setHigh(pe2a_GPIO_J4_1);
pe2a_DO_setHigh(pe2a_GPIO_J4_2);
}
void fGrassSetLow(){
pe2a_DO_setLow(pe2a_GPIO_J4_1);
pe2a_DO_setLow(pe2a_GPIO_J4_2);
}
void fFlowerSetHigh(){
pe2a_DO_setHigh(pe2a_GPIO_J5_5);
pe2a_DO_setHigh(pe2a_GPIO_J5_6);
}
void fFlowerSetLow(){
pe2a_DO_setLow(pe2a_GPIO_J5_5);
pe2a_DO_setLow(pe2a_GPIO_J5_6);
}
void *fTimePicker_1(){
int state = 0;
pe2a_DO_DI_init();
while(1){
switch (state){
case 0:
;
case 1:
fGrassSetHigh();
sleep(1);
case 2:
fGrassSetLow();
sleep(1);
}
}
}
void *fTimePicker_2(){
int state = 0;
pe2a_DO_DI_init();
while(1){
switch (state){
case 0:
case 1:
fFlowerSetHigh();
sleep(2);
case 2:
fFlowerSetLow();
sleep(2);
}
}
}
void *fTimePicker_3(){
int state = 0;
pe2a_AO_init();
while(1){
switch (state){
case 0:
case 1:
pe2a_AO_writeVal(pe2a_GPIO_J1_1,4095); //means 10V as Analog Output Voltage reference
sleep(2);
case 2:
pe2a_AO_writeVal(pe2a_GPIO_J1_1,2048); //means 5V as Analog Output Voltage reference
sleep(2);
}
}
}