Hardware Reference
In-Depth Information
203 static void
204 gpio_write(int fd,int dbit) {
205 write(fd,dbit ? "1\n" : "0\n",2);
206 }
207
208 /
209
Monitor switch changes on GPIO
210
/
211 static void
212 SW1_monitor_thread(void
arg) {
213 int rc;
214
215 while ( !stop ) {
216 rc = gpio_poll(fd_SW1); /
Watch for SW1 changes
/
217 if ( rc < 0 )
218 break;
219 SW1 = rc;
220 publish_SW1();
221 }
222 return 0;
223 }
224
225 /
226
Periodic broadcast to consoles thread
227
/
228 static void
229 console_thread(void
arg) {
230
231 while ( !stop ) {
232 sleep(3);
233 publish_SW1();
234 publish_LED();
235 }
236 return 0;
237 }
238
239 /
∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗
240
Main thread : read switch changes and publish to console (s)
241
/
∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗
242 int
243 main(int argc,char
argv) {
∗∗
244 pthread_t tid;
245 int rc = 0;
246 char buf[256];
247 int fd_LED = −1; /
GPIO 27
/
248
 
Search WWH ::




Custom Search