GDP group 24 node core

Dependencies:   EthernetInterface SDFileSystem mbed-rtos mbed snail MbedJSONValue

Revision:
14:bc0e2fa25f94
Parent:
11:190d07f37ec0
Child:
16:3ac37613f849
Child:
18:e68c8551d12c
diff -r 344f559bf5ec -r bc0e2fa25f94 sensorinterface.cpp
--- a/sensorinterface.cpp	Tue Jan 13 21:34:08 2015 +0000
+++ b/sensorinterface.cpp	Tue Jan 13 22:48:25 2015 +0000
@@ -1,8 +1,9 @@
 #include "sensorinterface.h"
  
 sensorinterface::sensorinterface() : i2c(p28,p27), readyLine(p29)
-{
-    readyLine.fall(this, &sensorinterface::readyTrigger);
+{ 
+    readyLine.fall(this, &sensorinterface::readySet);
+    readyLine.rise(this, &sensorinterface::readyUnset);
     
     this->ready = false;
     
@@ -53,11 +54,16 @@
     }
 }
 
-void sensorinterface::readyTrigger()
+void sensorinterface::readySet()
 {
     this->ready = true;
 }
 
+void sensorinterface::readyUnset()
+{
+    this->ready = false;
+}
+
 #ifdef DEBUG
 void sensorinterface::error(int e_num)
 {
@@ -108,14 +114,14 @@
  
 sensor& sensorinterface::findType(sensor& s, int address)
 {
-    char response[3];
-    char cmd[1] = {'T'};
+    char response[I2C_TYPE_PACKET_SIZE];
+    char cmd[1] = {I2C_TYPE_HEADER};
  
     this->i2c.write(address, cmd, 1);
     int type_timeout = 10;
     i2c.stop();
     i2c.start();
-    while( (this->i2c.read(address, response, 3)) && (type_timeout) )
+    while( (this->i2c.read(address, response, I2C_TYPE_PACKET_SIZE)) && (type_timeout) )
     {
         --type_timeout;
         if (type_timeout == 2)
@@ -127,25 +133,16 @@
         }
     }
 
-    if (response[0] != 'T')
+    if (response[0] != I2C_TYPE_HEADER)
     {
         #ifdef DEBUG
             error(1);
         #endif
     }
-    else
-    {
-        //seperate the incoming bits
-        if ((response[1] != 0x00) && (response[1] != 0x01) && (response[1] != 0x02))
-        {
-            //if its not a recognised type
-            #ifdef DEBUG
-                error(2);
-            #endif
-        }
-    }
+
     s.type = response[1];
-    s.readingSize = response[2]; 
+    s.packetSize = response[2];
+    s.readingSize = response[3]; 
     return s;
 }
  
@@ -165,7 +162,7 @@
     #endif
     char address = currentSensor->first;
     char cmd[1] = {'D'};
-    char bufSize = currentSensor->second.readingSize + 2;
+    char bufSize = currentSensor->second.packetSize + 2;
     char buffer[bufSize];
     this->i2c.write(address, cmd, 1);
     wait(0.01);
@@ -188,9 +185,6 @@
         #endif
     }
     
-    // TODO sync ready property to ready line - don't manually
-    this->ready = false;
-    
     if (currentSensor != sensors.end() && sensors.size() > 1 )
     {
         #ifdef DEBUG