#include "iotapi_evt_handler.h"
#define IOTAPI_QUEUE_SIZE 19
-#define IOTAPI_LOG printf
+#ifdef IOTAPI_DEBUG
+#define IOTAPI_LOG(format, ...) printf(format, ##__VA_ARGS__)
+#else
+#define IOTAPI_LOG(x...)
+#endif
+
struct _iotapi_msg_queue {
int type; // 1 is insert, 2 is remove, 0 is empty
}
if (g_ia_evtlist[0].revents & POLLIN) {
- int readed = read(g_ia_evtlist[0].fd, buf, 3);
+ int readed;
+ readed = read(g_ia_evtlist[0].fd, buf, 3);
IOTAPI_LOG("[iotcom] receive command(%d)\n", readed);
if (buf[0] == 's' && buf[1] == 't')
break;
{
struct _iotbus_gpio_s *dev = (struct _iotbus_gpio_s *)malloc(sizeof(struct _iotbus_gpio_s));
- char gpio_dev[32] = { 0, };
- snprintf(gpio_dev, 32, "/dev/gpio%d", gpiopin);
+ char gpio_dev[16] = { 0, };
+ snprintf(gpio_dev, 16, "/dev/gpio%d", gpiopin);
dev->fd = open(gpio_dev, O_RDWR);
if (dev->fd < 0) {
*/
int iotbus_gpio_read(iotbus_gpio_context_h dev)
{
- int state = 0;
+ char buf[4];
if (!dev)
return IOTBUS_ERROR_INVALID_PARAMETER;
- int ret = read(dev->fd, &state, sizeof(int));
+ int ret = read(dev->fd, buf, sizeof(buf));
if (ret < 0)
return IOTBUS_ERROR_UNKNOWN;
ret = lseek(dev->fd, 0, SEEK_SET);
if (ret < 0)
return IOTBUS_ERROR_UNKNOWN;
- return state;
+ return buf[0] == '1';
}
/**
int iotbus_gpio_write(iotbus_gpio_context_h dev, int value)
{
int ret;
+ char buf[4];
if (!dev)
return IOTBUS_ERROR_INVALID_PARAMETER;
if (value != 0 && value != 1)
return IOTBUS_ERROR_INVALID_PARAMETER;
- ret = write(dev->fd, &value, sizeof(int));
+ ret = write(dev->fd, buf, snprintf(buf, sizeof(buf), "%d", !!value));
if (ret < 0)
return IOTBUS_ERROR_UNKNOWN;