Denwis La / Mbed OS mDot_Send_Data

Dependencies:   libmDot-dev-mbed5-deprecated ISL29011

Fork of mdot-examples by 3mdeb

Revision:
24:88c7bebf0b05
Parent:
23:9c95ba021bdc
Child:
25:c92ef8ae7efb
diff -r 9c95ba021bdc -r 88c7bebf0b05 copy_main.cpp
--- a/copy_main.cpp	Wed Jan 10 17:05:29 2018 +0000
+++ b/copy_main.cpp	Wed Jan 10 17:13:12 2018 +0000
@@ -141,9 +141,9 @@
     takeAccelerometer = true;   // Take accelerometer because something happened
 }
 
-void takePeriodicReading(void){
-        pc.printf("Periodic Reading\n\r");
-        /*  
+void takePeriodicReading(std::vector<uint8_t> tx_data){
+        pc.printf("Regular periodic reading \n\r");
+        /*
          *  Taking accelerometer data
          */
         regAddress = 0x08;  // This is the register address for XData
@@ -170,13 +170,18 @@
         rawTempValues = ADT7410Read(regAddress);
         convertedTempValue = ((*(rawTempValues + 0) << 8) | *(rawTempValues + 1)) >> 3; // Combine the two bytes into 
                                                                                         // a short int variable(16 bits), remove last 3 bits
-        if(convertedTempValue & 0x8000){
-                
-        }
         pc.printf("Accelerometer::: ");
         pc.printf("X: 0x%x | Y: 0x%x | Z: 0x%x\n\r", XData, YData, ZData);
         pc.printf("Temperature::: ");
         pc.printf("Celsius: 0x%x\n\r", convertedTempValue);
+        
+        
+        
+        tx_data.push_back((convertedTempValue >> 8) & 0xFF);
+        tx_data.push_back(convertedTempValue & 0xFF);
+        logInfo("Temperautre: %lu [0x%04X]", convertedTempValue, convertedTempValue);
+        send_data(tx_data);
+        periodicReadingTrigger = false; // Flip back to no trigger
 }
 
 void takePeriodicReadingTicker(void){
@@ -327,46 +332,7 @@
         
         if(periodicReadingTrigger)
         {
-            pc.printf("Regular periodic reading ");
-            /*
-             *  Taking accelerometer data
-             */
-            regAddress = 0x08;  // This is the register address for XData
-            accelValues = accelerometerI2CRead(regAddress);
-            Xmsb = *(accelValues + 0);
-            Xlsb = *(accelValues + 1);
-            Ymsb = *(accelValues + 2);
-            Ylsb = *(accelValues + 3);
-            Zmsb = *(accelValues + 4);
-            Zlsb = *(accelValues + 5);
-            
-            XData = (Xmsb << 8 | Xlsb) >> 4;  // Combine two bytes into short int, remove last 4 flag bits
-            YData = (Ymsb << 8 | Ylsb) >> 4;
-            ZData = (Zmsb << 8 | Zlsb) >> 4;
-            
-            XData = twosComplementConversion(XData);
-            YData = twosComplementConversion(YData);
-            ZData = twosComplementConversion(ZData);
-            
-            /*
-             *  Taking temperature data
-             */
-            regAddress = 0x00;
-            rawTempValues = ADT7410Read(regAddress);
-            convertedTempValue = ((*(rawTempValues + 0) << 8) | *(rawTempValues + 1)) >> 3; // Combine the two bytes into 
-                                                                                            // a short int variable(16 bits), remove last 3 bits
-            pc.printf("Accelerometer::: ");
-            pc.printf("X: 0x%x | Y: 0x%x | Z: 0x%x\n\r", XData, YData, ZData);
-            pc.printf("Temperature::: ");
-            pc.printf("Celsius: 0x%x\n\r", convertedTempValue);
-            
-            
-            
-            tx_data.push_back((convertedTempValue >> 8) & 0xFF);
-            tx_data.push_back(convertedTempValue & 0xFF);
-            logInfo("Temperautre: %lu [0x%04X]", convertedTempValue, convertedTempValue);
-            send_data(tx_data);
-            periodicReadingTrigger = false; // Flip back to no trigger
+            takePeriodicReading(tx_data);
         }
         
         if(takeAccelerometer || takeAccelerometer){