i2c.cxx: add functionality to write to i2c
authorBrendan Le Foll <brendan.le.foll@intel.com>
Fri, 11 Apr 2014 10:51:40 +0000 (11:51 +0100)
committerBrendan Le Foll <brendan.le.foll@intel.com>
Fri, 11 Apr 2014 10:51:40 +0000 (11:51 +0100)
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
src/i2c/i2c.cxx

index 39ea2f0..2c591ad 100644 (file)
@@ -64,12 +64,21 @@ I2C::read(int ack)
 int
 I2C::write(int address, const char *data, int length, bool repeated)
 {
 int
 I2C::write(int address, const char *data, int length, bool repeated)
 {
+    if (i2c_smbus_write_i2c_block_data(i2c_handle, data[0], length, (uint8_t*) data) < 0) {
+        fprintf(stderr, "Failed to write to I2C slave\n");
+       return -1;
+    }
     return 0;
 }
 
 int
 I2C::write(int data)
 {
     return 0;
 }
 
 int
 I2C::write(int data)
 {
+    if (i2c_smbus_write_byte(i2c_handle, data) < 0) {
+        fprintf(stderr, "Failed to write to I2C slave\n");
+       return -1;
+    }
+    return 0;
 }
 
 void
 }
 
 void