Hardware Reference
In-Depth Information
152 assert(f);
153 fprintf(f,"%d\n",pin);
154 fclose(f);
155 }
156
157 /
158
This routine will block until the open GPIO pin has changed
159
value .
160
/
161 static int
162 gpio_poll(int fd,double
ms) {
163 static char needs_init = 1;
164 static struct timeval t0;
165 static struct timeval t1;
166 struct pollfd polls;
167 char buf[32];
168 int rc, n;
169
170 if ( needs_init ) {
171 rc = gettimeofday(&t0,0);
172 assert(!rc);
173 needs_init = 0;
174 }
175
176 polls.fd = fd; /
/sys/class/gpio17/value
/
177 polls.events = POLLPRI; /
Exceptions
/
178
179 do {
180 rc = poll(&polls,1,−1); /
Block
/
181 if ( is_signaled )
182 longjmp(jmp_exit,1);
183 } while ( rc < 0 && errno == EINTR );
184
185 assert(rc > 0);
186
187 rc = gettimeofday(&t1,0);
188 assert(!rc);
189
190
ms = msdiff(&t1,&t0);
191
192 lseek(fd,0,SEEK_SET);
193 n = read(fd,buf,sizeof buf); /
Read value
/
194 assert(n>0);
195 buf[n] = 0;
196
197 rc = sscanf(buf,"%d",&n) ;
198 assert(rc==1);
199
Search WWH ::




Custom Search