i2c.hpp: add read(size_t length) function useful in scripting languages
authorBrendan Le Foll <brendan.le.foll@intel.com>
Thu, 31 Jul 2014 08:14:57 +0000 (10:14 +0200)
committerBrendan Le Foll <brendan.le.foll@intel.com>
Thu, 31 Jul 2014 08:14:57 +0000 (10:14 +0200)
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
api/mraa/i2c.hpp

index 8a49be3..8e5d7ce 100644 (file)
@@ -98,6 +98,18 @@ class I2c {
         int read(char * data, size_t length) {
             return mraa_i2c_read(m_i2c, (uint8_t*) data, (int) length);
         }
+       /**
+        * Read length bytes from the bus, this function will allocate memory
+        * and will require you to free the returned pointer
+        *
+        * @param length Size of read to make
+        * @return pointer to read data which must be freed
+        */
+        uint8_t* read(size_t length) {
+            uint8_t* data = (uint8_t*) malloc(sizeof(uint8_t) * length);
+            mraa_i2c_read(m_i2c, data, (int) length);
+            return data;
+        }
         /**
          * Write one byte to the bus
          *