mirror of
https://github.com/vsergeev/c-periphery.git
synced 2026-02-06 23:42:24 +08:00
gpio: add dummy read before poll()
this fixes blocking polls on some platforms. resolves #5. Signed-off-by: Vanya A. Sergeev <v@sergeev.io>
This commit is contained in:
committed by
Vanya A. Sergeev
parent
e0871c09fc
commit
0643fe91eb
@@ -159,8 +159,13 @@ int gpio_write(gpio_t *gpio, bool value) {
|
||||
|
||||
int gpio_poll(gpio_t *gpio, int timeout_ms) {
|
||||
struct pollfd fds[1];
|
||||
char buf[1];
|
||||
int ret;
|
||||
|
||||
/* Dummy read before poll */
|
||||
if (read(gpio->fd, buf, 1) < 0)
|
||||
return _gpio_error(gpio, GPIO_ERROR_IO, errno, "Reading GPIO 'value'");
|
||||
|
||||
/* Seek to end */
|
||||
if (lseek(gpio->fd, 0, SEEK_END) < 0)
|
||||
return _gpio_error(gpio, GPIO_ERROR_IO, errno, "Seeking to end of GPIO 'value'");
|
||||
@@ -345,4 +350,3 @@ unsigned int gpio_pin(gpio_t *gpio) {
|
||||
int gpio_fd(gpio_t *gpio) {
|
||||
return gpio->fd;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user