From eaaf864b077c0400259db530c6a1f683460b5051 Mon Sep 17 00:00:00 2001 From: Heesub Shin Date: Fri, 28 Apr 2017 18:27:12 +0900 Subject: [PATCH] examples/sensorbd_demo: fix starterled test Since we reworked the entire GPIO layer, 'sensorbd ledst' command have been broken. This commit fixes it. Change-Id: I2ca80ac611155a68d86acefceea61bfbf5146afc Signed-off-by: Heesub Shin --- .../sensorbd_demo/examples/gpio_starterled.c | 27 ++++++++++------------ 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/apps/examples/sensorbd_demo/examples/gpio_starterled.c b/apps/examples/sensorbd_demo/examples/gpio_starterled.c index 5c8c439..aa2911a 100644 --- a/apps/examples/sensorbd_demo/examples/gpio_starterled.c +++ b/apps/examples/sensorbd_demo/examples/gpio_starterled.c @@ -55,30 +55,27 @@ static int gpio_read(int port) { - int value = -1; - static char buf[16]; - snprintf(buf, 16, "/dev/gpio%d", port); - int fd = open(buf, O_RDWR); + char buf[4]; + char devpath[16]; + snprintf(devpath, 16, "/dev/gpio%d", port); + int fd = open(devpath, O_RDWR); ioctl(fd, GPIOIOC_SET_DIRECTION, GPIO_DIRECTION_IN); - read(fd, (void *)&value, sizeof(int)); - + read(fd, buf, sizeof(buf)); close(fd); - return value; + + return buf[0] == '1'; } static void gpio_write(int port, int value) { - static char buf[16]; - snprintf(buf, 16, "/dev/gpio%d", port); - int fd = open(buf, O_RDWR); + char buf[4]; + char devpath[16]; + snprintf(devpath, 16, "/dev/gpio%d", port); + int fd = open(devpath, O_RDWR); - int mode = value ? GPIO_DRIVE_PULLUP : GPIO_DRIVE_PULLDOWN; - ioctl(fd, GPIOIOC_SET_DIRECTION, GPIO_DIRECTION_IN); - ioctl(fd, GPIOIOC_SET_DRIVE, mode); ioctl(fd, GPIOIOC_SET_DIRECTION, GPIO_DIRECTION_OUT); - write(fd, (void *)&value, sizeof(int)); - + write(fd, buf, snprintf(buf, sizeof(buf), "%d", !!value)); close(fd); } -- 2.7.4