Textile sensor

Dependents:   MjTextileSensor_Hello

Files at this revision

API Documentation at this revision

Comitter:
matsujirushi
Date:
Wed Jul 01 13:58:31 2015 +0000
Commit message:
created.

Changed in this revision

MjTextileSensor.cpp Show annotated file Show diff for this revision Revisions of this file
MjTextileSensor.h Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 9f5d5e904cb9 MjTextileSensor.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MjTextileSensor.cpp	Wed Jul 01 13:58:31 2015 +0000
@@ -0,0 +1,39 @@
+#include "MjTextileSensor.h"
+#include <string.h>
+
+MjTextileSensor::MjTextileSensor(I2C* i2c, uint8_t address)
+{
+    this->i2c = i2c;
+    this->address = address;
+}
+
+bool MjTextileSensor::GetVersion(uint8_t* majorVersion, uint8_t* minorVersion)
+{
+    char command = 0x00;
+    i2c->write(address, &command, 1);
+
+    char response[3];
+    i2c->read(address, response, sizeof (response));
+    if (response[0] != 0x80) {
+        return false;
+    }
+
+    *minorVersion = response[1];
+    *majorVersion = response[2];
+
+    return true;
+}
+int MjTextileSensor::GetSensorValues(uint8_t* sensorValues, size_t sensorValuesSize)
+{
+    char response[11];
+    i2c->read(address, response, sizeof (response));
+    if (response[0] != 0xff) {
+        memset(response, 0, sizeof (response));
+        return 0;
+    }
+
+    int sensorValuesSizeActual = sensorValuesSize < 10 ? sensorValuesSize : 10;
+    memcpy(sensorValues, &response[1], sensorValuesSizeActual);
+
+    return sensorValuesSizeActual;
+}
diff -r 000000000000 -r 9f5d5e904cb9 MjTextileSensor.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MjTextileSensor.h	Wed Jul 01 13:58:31 2015 +0000
@@ -0,0 +1,19 @@
+#ifndef MJ_TEXTILESENSOR_H
+#define MJ_TEXTILESENSOR_H
+
+#include "mbed.h"
+
+class MjTextileSensor
+{
+public:
+    MjTextileSensor(I2C* i2c, uint8_t address);
+    bool GetVersion(uint8_t* majorVersion, uint8_t* minorVersion);
+    int GetSensorValues(uint8_t* sensorValues, size_t sensorValuesSize);
+
+private:
+    I2C *i2c;
+    uint8_t address;
+
+};
+
+#endif