Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: Main.cpp
- Revision:
- 7:5f612ed18852
- Parent:
- 6:6aa9d16e27bc
- Child:
- 8:494f6fcecfbc
- Child:
- 9:1e63726fff9c
--- a/Main.cpp Wed Aug 09 18:57:37 2017 +0000
+++ b/Main.cpp Sat Aug 12 00:28:20 2017 +0000
@@ -7,7 +7,7 @@
#include "mbed.h"
#include "stdlib.h"
-#define VERSION "1.3"
+#define VERSION "1.4"
#define TRACE_MODE
@@ -72,7 +72,7 @@
//Use a boards second UART to communicate witb the Honneywell sensor
//Default UART setting are 8,N,1
-Serial sensor( SENSOR_XMT, SENSOR_RCV, 9600);
+Serial sensor( SENSOR_XMT, SENSOR_RCV);
//synchrnous serial read and writes
//Mbed 5 Serial class only supports single character read and writes or
@@ -82,11 +82,18 @@
logInfo( "Receiving Data from sensor\n");
uint8_t* pointer = buffer;
uint16_t counter = count;
+ bool firstchar = true;
+ uint8_t foo;
while(1)
{
if(sensor.readable())
{
- *pointer++ = sensor.getc();
+ foo = sensor.getc();
+ if(firstchar) {
+ pc.putc(foo);
+ firstchar = false;
+ }
+ *pointer++ = foo;
logTrace(*pointer);
counter--;
}
@@ -120,7 +127,7 @@
bool checkValue(uint8_t *thebuf, uint8_t leng)
{
bool receiveflag = false;
- uint16_t receiveSum=0;
+ uint16_t receiveSum = 0;
//Don't include the checksum bytes in the sum
for(int i=0; i<(leng-3); i++){
@@ -168,7 +175,7 @@
uint16_t PM2_5Value=0; //define PM2.5 value of the air detector module
uint16_t PM10Value=0; //define PM10 value of the air detector module
- pc.printf("Starting Honeywell Dust Sesor App version %s/n", VERSION);
+ pc.printf("Starting Honeywell Dust Sesor App version %\n", VERSION);
//Send start command to the sensor
writeBuffer(measureCommand, 4);
@@ -197,39 +204,39 @@
{
if(sensor.getc() == 0x42){ //start to read when detect 0x42
readBuffer(dataBuffer,MESSAGE_LEN -1);
-
if(dataBuffer[0] == 0x4d){
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
+ 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
- if(pc.readable()) {
- char input = pc.getc();
- if(input == 'Q' || input == 'q')
- {
- writeBuffer(stopCommand, 4);
- pc.printf("Exit request received\n");
- return 0;
+ else {
+ pc.printf("Second Character was %x\n", dataBuffer[0]);
+ }
+ //Check for exit request
+ if(pc.readable()) {
+ char input = pc.getc();
+ if(input == 'Q' || input == 'q')
+ {
+ writeBuffer(stopCommand, 4);
+ pc.printf("Exit request received\n");
+ return 0;
+ }
}
- }
-// Use MBed wait function instead of Arduino delay loop
- wait_ms(1000);
-
- pc.printf("PM1.0: %d ug/m3", PM01Value);
-
- pc.printf("PM2.5: %d ug/m3", PM2_5Value);
-
- pc.printf("PM10: %d ug/m3", PM10Value);
-
- pc.printf("\n");
+ // Use MBed wait function instead of Arduino delay loop
+ wait_ms(1000);
+
+ pc.printf("PM1.0: %d ug/m3\n", PM01Value);
+ pc.printf("PM2.5: %d ug/m3\n", PM2_5Value);
+
+ pc.printf("PM10: %d ug/m3\n", PM10Value);
+
+ pc.printf("\n");
+ }
}
}
\ No newline at end of file