Hardware Reference
In-Depth Information
19 static void
context = 0; /
ZMQ context
/
20 static void
publisher = 0; /
Publishing socket
/
21 static void
console = 0; /
Pull socket
/
22
23 static int SW1 = 0; /
Switchstatus
/
24 static int LED = 0; /
LED status
/
25 static int stop = 0; /
Nonzero when shutting down
/
26
27 static int gp_SW1 = 22; /
GPIO 22 (input)
/
28 static int gp_LED = 27; /
GPIO 22 (output)
/
29 static int fd_SW1 = −1; /
Open fd for SW1
/
30
31 #include "mutex.c"
32
33 /
34
Publish the LED setting to the console(s)
35
/
36 static void
37 publish_LED(void) {
38 char buf [256];
39 size_tn;
40 int rc;
41
42 n = sprintf(buf,"led:%d",LED);
43 mutex_lock();
44 rc = zmq_send(publisher,buf,n,0);
45 assert(rc!=-1);
46 mutex_unlock();
47 }
48
49 /
50
Publish the switch setting to the console(s)
51
/
52 static void
53 publish_SW1(void) {
54 char buf[256];
55 size_t n;
56 int rc;
57
58 n = sprintf(buf,"sw1:%d",SW1);
59
60 mutex_lock();
61 rc = zmq_send(publisher,buf,n,0);
62 assert(rc!=-1);
63 mutex_unlock();
64 }
65
Search WWH ::




Custom Search