mDot / Mbed OS Honneywell_Dust_Simple
Revision:
6:6aa9d16e27bc
Parent:
5:7cabc36d4352
Child:
7:5f612ed18852
--- a/Main.cpp	Wed Aug 09 07:29:26 2017 +0000
+++ b/Main.cpp	Wed Aug 09 18:57:37 2017 +0000
@@ -7,7 +7,7 @@
 #include "mbed.h"
 #include "stdlib.h"
 
-#define VERSION  "1.2"
+#define VERSION  "1.3"
 
 #define TRACE_MODE
 
@@ -74,9 +74,6 @@
 //Default UART setting are 8,N,1
 Serial sensor( SENSOR_XMT, SENSOR_RCV, 9600);
 
-Timer t;
-
-
 //synchrnous serial read and writes
 //Mbed 5 Serial class only supports single character read and writes or
 // async buffer reads abd wrutes
@@ -125,7 +122,8 @@
   bool receiveflag = false;
   uint16_t receiveSum=0;
 
-  for(int i=0; i<(leng-1); i++){
+  //Don't include the checksum bytes in the sum
+  for(int i=0; i<(leng-3); i++){
   receiveSum=receiveSum+thebuf[i];
   }
   receiveSum=receiveSum + 0x42;
@@ -193,7 +191,6 @@
         return -2;
     }
 */    
-    t.start();
 
     //Start continous loop 
     while(1)
@@ -202,11 +199,15 @@
             readBuffer(dataBuffer,MESSAGE_LEN -1);
         
             if(dataBuffer[0] == 0x4d){
-              if(checkValue(dataBuffer,MESSAGE_LEN-1)){
+              if(checkValue(dataBuffer, MESSAGE_LEN-1)){
                 PM01Value=transmitPM01(dataBuffer); //count PM1.0 value of the air detector module
                 PM2_5Value=transmitPM2_5(dataBuffer);//count PM2.5 value of the air detector module
                 PM10Value=transmitPM10(dataBuffer); //count PM10 value of the air detector module 
               }
+              else {
+                  pc.printf("Message checksum error\n");
+              }
+              
           }           
         }
         //Check for exit request
@@ -214,33 +215,21 @@
             char input = pc.getc();
             if(input == 'Q' || input == 'q')
             { 
-                t.stop();
                 writeBuffer(stopCommand, 4);
                 pc.printf("Exit request received\n");
                 return 0;
             }
         }
-/* Use MBed wait function instead of Arduino delay loop
-        static unsigned long OledTimer= t.read_ms();  
-        if (t.read_ms() - OledTimer >=1000) 
-        {
-          OledTimer= t.read_ms(); 
-*/
+// Use MBed wait function instead of Arduino delay loop
       wait_ms(1000);          
           
       pc.printf("PM1.0: %d ug/m3", PM01Value);  
-//          debug.print(PM01Value);
-//          debug.println("  ug/m3");            
         
       pc.printf("PM2.5: %d ug/m3", PM2_5Value);  
-//          debug.print(PM2_5Value);
-//          debug.println("  ug/m3");     
           
-    pc.printf("PM10: %d ug/m3", PM10Value);  
-//          debug.print(PM10Value);
-//          debug.println("  ug/m3");   
+      pc.printf("PM10: %d ug/m3", PM10Value);  
+
       pc.printf("\n");
             
- //       }
     }
  }
\ No newline at end of file