Skip to content

Commit

Permalink
Merge pull request #2 from gizero/fix-return-values-attribute-writes
Browse files Browse the repository at this point in the history
Fix return values attribute writes
  • Loading branch information
lclausen-adi committed Jul 30, 2014
2 parents 3f9e458 + a08465c commit f6c0ba5
Showing 1 changed file with 37 additions and 9 deletions.
46 changes: 37 additions & 9 deletions device.c
Original file line number Diff line number Diff line change
Expand Up @@ -499,26 +499,38 @@ int iio_device_attr_read_double(const struct iio_device *dev,
int iio_device_attr_write_longlong(const struct iio_device *dev,
const char *attr, long long val)
{
ssize_t ret;
char buf[1024];

snprintf(buf, sizeof(buf), "%lld", val);
return iio_device_attr_write(dev, attr, buf);
ret = iio_device_attr_write(dev, attr, buf);

return ret < 0 ? ret : 0;
}

int iio_device_attr_write_double(const struct iio_device *dev,
const char *attr, double val)
{
ssize_t ret;
char buf[1024];

snprintf(buf, sizeof(buf), "%lf", val);
return iio_device_attr_write(dev, attr, buf);
ret = iio_device_attr_write(dev, attr, buf);

return ret < 0 ? ret : 0;
}

int iio_device_attr_write_bool(const struct iio_device *dev,
const char *attr, bool val)
{
ssize_t ret;

if (val)
return iio_device_attr_write(dev, attr, "1");
ret = iio_device_attr_write(dev, attr, "1");
else
return iio_device_attr_write(dev, attr, "0");
ret = iio_device_attr_write(dev, attr, "0");

return ret < 0 ? ret : 0;
}

ssize_t iio_device_debug_attr_read(const struct iio_device *dev,
Expand Down Expand Up @@ -608,26 +620,38 @@ int iio_device_debug_attr_read_double(const struct iio_device *dev,
int iio_device_debug_attr_write_longlong(const struct iio_device *dev,
const char *attr, long long val)
{
ssize_t ret;

char buf[1024];
snprintf(buf, sizeof(buf), "%lld", val);
return iio_device_debug_attr_write(dev, attr, buf);
ret = iio_device_debug_attr_write(dev, attr, buf);

return ret < 0 ? ret : 0;
}

int iio_device_debug_attr_write_double(const struct iio_device *dev,
const char *attr, double val)
{
ssize_t ret;

char buf[1024];
snprintf(buf, sizeof(buf), "%lf", val);
return iio_device_debug_attr_write(dev, attr, buf);
ret = iio_device_debug_attr_write(dev, attr, buf);

return ret < 0 ? ret : 0;
}

int iio_device_debug_attr_write_bool(const struct iio_device *dev,
const char *attr, bool val)
{
ssize_t ret;

if (val)
return iio_device_debug_attr_write_raw(dev, attr, "1", 2);
ret = iio_device_debug_attr_write_raw(dev, attr, "1", 2);
else
return iio_device_debug_attr_write_raw(dev, attr, "0", 2);
ret = iio_device_debug_attr_write_raw(dev, attr, "0", 2);

return ret < 0 ? ret : 0;
}

int iio_device_identify_filename(const struct iio_device *dev,
Expand Down Expand Up @@ -672,9 +696,13 @@ int iio_device_identify_filename(const struct iio_device *dev,
int iio_device_reg_write(struct iio_device *dev,
uint32_t address, uint32_t value)
{
ssize_t ret;

char buf[1024];
snprintf(buf, sizeof(buf), "0x%x 0x%x", address, value);
return iio_device_debug_attr_write(dev, "direct_reg_access", buf);
ret = iio_device_debug_attr_write(dev, "direct_reg_access", buf);

return ret < 0 ? ret : 0;
}

int iio_device_reg_read(struct iio_device *dev,
Expand Down

0 comments on commit f6c0ba5

Please sign in to comment.