mDot / Mbed OS Honneywell_Dust_Simple
Revision:
15:5ba877be4304
Parent:
13:e5f9b5ec30e1
Child:
16:6550040fbdf4
--- a/Main.cpp	Wed Nov 29 22:55:34 2017 +0000
+++ b/Main.cpp	Sun Dec 03 00:05:11 2017 +0000
@@ -1,14 +1,14 @@
 /* Run Honeywell Dust Sensor in continous Sampling Mode on a mDot or 
    Freedom K64 board
-   Version 2.1
-   Steve Mylroie Roitronic November 29 2017
-   @C Copyright Global Quality Corp
+   Version 2.2
+   Steve Mylroie Roitronic December 2 2017
+   @C Copyright 2017 Global Quality Corp
 */
 
 #include "mbed.h"
 #include "stdlib.h"
 
-#define VERSION  "2.1"
+#define VERSION  "2.2"
 
 #define TRACE_MODE
 
@@ -27,7 +27,7 @@
 #define OK   0xA5A5
 #define BAD  0x9696
 
-//Auto Mode measurement response lenght
+//Maximum response message lenght
 #define MESSAGE_LEN 32
 
 //sensor measurement cycle in millseconds
@@ -71,11 +71,12 @@
 
 #endif
 
+//Number of character following the 
 #define RESPONSE_MSG_LEN 2
-#define AUTO_MSG_LEN 8
+#define AUTO_MSG_LEN 32
 
 //Time required to receive one character at 9600 baud
-#define CHAR_TIME 1000/9600 & 10
+#define CHAR_TIME (1000 * 10)/9600
 
 enum MSG_TYPE{  UNKNOWN,
                 ACK_MSG,
@@ -101,7 +102,7 @@
         data = sensor.getc();
         if(msgType == UNKNOWN) {  //Start of a new message
             bufferPtr = dataBuffer;
-            switch(data) {
+            switch(data) { //Switch on message type character
                 case 0x42:
                     msgType = AUTO_MSG;
                     msgLen = AUTO_MSG_LEN;
@@ -157,7 +158,7 @@
        return READ_ERROR;
          }
     else {
-        //Copy the message to the requesters buffer 
+        //Copy the message minus type flag to the requesters buffer 
         inPointer = &dataBuffer[1];
         outPointer = buffer;
         for(int i = 0; i < count; i++) {
@@ -244,6 +245,10 @@
     uint16_t PM10Value=0;         //define PM10 value of the air detector module
     
     pc.printf("Starting Honeywell Dust Sesor App version %\n", VERSION);
+
+    #ifdef DEBIG
+        pc.printf("Character wait time is %d millseconds", CHAR_TIME);
+    #endif
     //Attach a receive interrupt handler
     sensor.attach(receiveInterrupt, Serial::RxIrq);
     msgType = UNKNOWN;
@@ -283,7 +288,7 @@
                 }
               }
             else {
-              pc.printf("Second Character was %x\n", dataBuffer[0]);
+              pc.printf("Error Second Character not 0x4d but #x\n", dataBuffer[0]);
               }
              //Check for exit request
             if(pc.readable()) {
@@ -328,7 +333,7 @@
                         }
                     break;
                     case READ_ERROR:
-                        pc.puts("Data Reading Error");
+                        pc.puts("Data Reading Error\n");
                     break;
                     }
                 }