From d50b646c35fde0d3b21f335bc5af3eadec496f6b Mon Sep 17 00:00:00 2001 From: Sanrio Alvares Date: Fri, 18 Aug 2017 11:44:21 -0700 Subject: [PATCH] peripheralman: fix uart data available api Signed-off-by: Sanrio Alvares Signed-off-by: Brendan Le Foll --- src/peripheralman/peripheralman.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/peripheralman/peripheralman.c b/src/peripheralman/peripheralman.c index f0bc818..339d3a3 100644 --- a/src/peripheralman/peripheralman.c +++ b/src/peripheralman/peripheralman.c @@ -247,8 +247,26 @@ mraa_pman_uart_set_timeout_replace(mraa_uart_context dev, int read, int write, i static mraa_boolean_t mraa_pman_uart_data_available_replace(mraa_uart_context dev, unsigned int millis) { - // FIXME! We probably should say yes sometimes ;-) - return 0; + int fd = -1; + + if (AUartDevice_getPollingFd(dev->buart, &fd)) { + syslog(LOG_ERR, "peripheralman: failed to get the fd"); + return 0; + } + + struct pollfd poller = { + .fd = fd, + .events = POLLIN | POLLERR, + .revents = 0, + }; + + if (poll(&poller, 1, millis) > 0) { + syslog(LOG_INFO, "peripheralman: received an event"); + AUartDevice_ackInputEvent(fd); + return 1; + } else { + return 0; + } } static mraa_result_t