examples/sensorbd_demo: fix starterled test
authorHeesub Shin <heesub.shin@samsung.com>
Fri, 28 Apr 2017 09:27:12 +0000 (18:27 +0900)
committerHeesub Shin <heesub.shin@samsung.com>
Sat, 6 May 2017 14:00:41 +0000 (23:00 +0900)
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 <heesub.shin@samsung.com>
apps/examples/sensorbd_demo/examples/gpio_starterled.c

index 5c8c439..aa2911a 100644 (file)
 
 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);
 }