int mraa_gpio_read(mraa_gpio_context dev) { if (dev == NULL) return -1; if (dev->mmap_read != NULL) return dev->mmap_read(dev); if (dev->value_fp == -1) { if (mraa_gpio_get_valfp(dev) != MRAA_SUCCESS) { syslog(LOG_ERR, "gpio: Failed to get value file pointer"); return -1; } } else { // if value_fp is new this is pointless lseek(dev->value_fp, 0, SEEK_SET); } char bu[2]; if (read(dev->value_fp, bu, 2*sizeof(char)) != 2) { syslog(LOG_ERR, "gpio: Failed to read a sensible value from sysfs"); return -1; } lseek(dev->value_fp, 0, SEEK_SET); return (int) strtol(bu, NULL, 10); }
int mraa_gpio_read(mraa_gpio_context dev) { if (dev == NULL) { syslog(LOG_ERR, "gpio: read: context is invalid"); return -1; } if (IS_FUNC_DEFINED(dev, gpio_read_replace)) return dev->advance_func->gpio_read_replace(dev); if (dev->mmap_read != NULL) return dev->mmap_read(dev); if (dev->value_fp == -1) { if (mraa_gpio_get_valfp(dev) != MRAA_SUCCESS) { return -1; } } else { // if value_fp is new this is pointless lseek(dev->value_fp, 0, SEEK_SET); } char bu[2]; if (read(dev->value_fp, bu, 2 * sizeof(char)) != 2) { syslog(LOG_ERR, "gpio%i: read: Failed to read a sensible value from sysfs: %s", dev->pin, strerror(errno)); return -1; } lseek(dev->value_fp, 0, SEEK_SET); return (int) strtol(bu, NULL, 10); }