mDot / Mbed OS Honneywell_Dust_Simple
Revision:
3:1ba96949e2fd
Parent:
2:65f09ca5b557
Child:
4:12dfd9a8ee76
--- a/Main.cpp	Tue Aug 01 14:01:02 2017 +0000
+++ b/Main.cpp	Sat Aug 05 06:59:15 2017 +0000
@@ -1,24 +1,22 @@
 /* Run Honeywell Dust Sensor in continous Sampling Mode on a mDot
-   Version 1.0
+   Version 1.1
    Steve Mylroie Roitronic August 1st 2017
    @C Copyright Global Quality Corp
 */
 
 #include "mbed.h"
-#include "mDot.h"
-#include "MTSLog.h"
 #include "stdlib.h"
-#include <Stream.h>
 
 #define TRACE_MODE
 
 //Turn on trace logging to the PC USB port
 #ifdef TRACE_MODE
 //Log level need to be set one level higher than the high level to be output
-#define LOG_LEVEL mts::MTSLog::TRACE_LEVEL + 1
+#define LOG_LEVEL 4
 #define DEBUG
 #endif
 
+
 const uint8_t* measureCommand = "68014057";
 const uint8_t* stopCommand    = "68012077";
 
@@ -29,22 +27,42 @@
 //sensor measurement cycle in millseconds
 #define MEASURE_DELAY 1500 
 
+Serial pc(USBTX, USBRX, 115200);
+
 //Use USB debug pott for the debug stream
 #ifdef DEBUG
-Serial pc(USBTX, USBRX, 115200);
+uint32_t debugLevel  = LOG_LEVEL;
+#else
+uint32_t debugLevel = 0;
 #endif
 
-//Use second UART to communicate witb the Honneywell sensor
+void logInfo(char* text) {
+     if ( debugLevel > 0 ) {
+          pc.printf("\n%s\n", text );
+     }
+     return;
+     }
+ 
+void logTrace(uint8_t data) {
+     if (debugLevel > 2 ){ pc.putc( data );
+      }
+      return;
+  } 
+
+
+//Use second UART   to communicate witb the Honneywell sensor
 //Default UART setting are 8,N,1
 Serial sensor(PA_2, PA_3 , 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
 void readBuffer(uint8_t* buffer, uint16_t count)
 {
+    logInfo( "Receiving Data from sensor");
     uint8_t* pointer = buffer;
     uint16_t counter = count;
     while(1)
@@ -52,6 +70,7 @@
         if(sensor.readable())
         {
             *pointer++ = sensor.getc();
+            logTrace(*pointer);
             counter--;
             }
         if(count == 0) {
@@ -62,12 +81,14 @@
     
 void writeBuffer(const uint8_t* buffer, uint16_t count)
 {
+    logInfo( "Sending Data to sensor");
     uint8_t* pointer = (uint8_t*)buffer;
     uint16_t counter = count;
     while(1)
     {
         if(sensor.writeable())
         {
+            logTrace(*pointer);
             sensor.putc(*pointer++);
             counter--;
             }