From: Heesub Shin Date: Fri, 28 Apr 2017 09:27:12 +0000 (+0900) Subject: examples/sensorbd_demo: fix starterled test X-Git-Tag: 1.1_Public_Release~597^2~48 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=eaaf864b077c0400259db530c6a1f683460b5051;p=rtos%2Ftinyara.git 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 --- 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); }