Hardware Reference
In-Depth Information
62 { IR_8, "8" } ,
63 { IR_9, "9" } ,
64 { IR_EXIT, "\n<EXIT>\n" } ,
65 { IR_RETURN, "\n<RETURN>\n" } ,
66 { IR_MUTE, "\n<MUTE>\n" } ,
67 { 0, 0 } /
End marker
/
68 } ;
69
70 /
71
Compute the time difference in milliseconds :
72
/
73 static double
74 msdiff(struct timeval
t1,struct timeval
t0) {
75 unsigned long ut;
76 double ms;
77
78 ms = ( t1−>tv_sec − t0−>tv_sec )
1000.0;
79 if ( t1−>tv_usec > t0−>tv_usec )
80 ms += ( t1−>tv_usec − t0−>tv_usec ) / 1000.0;
81 else {
82 ut = t1−>tv_usec + 1000000UL;
83 ut −= t0−>tv_usec;
84 ms += ut / 1000.0;
85 }
86 return ms;
87 }
88
89 /
90
Create a pathname fo r type in buf.
91
/
92 static const char
93 gpio_setpath(int pin,gpio_path_t type,char
buf,unsigned bufsiz) {
94 static const char
paths[] = {
95 "export", "unexport", "gpio%d/direction",
96 "gpio%d/edge", "gpio%d/value"};
97 int slen;
98
99 strncpy(buf,"/sys/class/gpio/",bufsiz);
100 bufsiz -= (slen = strlen(buf));
101 snprintf(buf+slen,bufsiz,paths[type],pin);
102 return buf;
103 }
104
105 /
106
Open /sys/class/gpio%d/value for edge detection :
107
/
Search WWH ::




Custom Search