Dave H's version of the EVB Demo. Sends to specific conduit, and sends with a comma separated text string
Dependencies: DOGS102 ISL29011 MMA845x MPL3115A2 NCP5623B libmDot mbed-rtos mbed-src
Fork of MTDOT-EVBDemo by
Diff: main.cpp
- Revision:
- 6:b62e5106b5bc
- Parent:
- 5:5a794cedd728
- Child:
- 7:74c027d0353b
--- a/main.cpp Thu Aug 20 21:28:45 2015 +0000 +++ b/main.cpp Mon Aug 24 16:38:59 2015 +0000 @@ -148,6 +148,17 @@ void config_pkt_xmit (void const *args); int32_t sendString(const std::string text); +bool writeValueOrError(); + +char sensor_text[54]; +char lora_temp_string[7]; +char lora_alt_string[8]; +char lora_press_string[9]; + +char lora_light_string[6]; +const int FAIL_MAX=15; +int failtime=FAIL_MAX; + int main() { @@ -155,7 +166,7 @@ std::vector<uint8_t> mdot_EUI; uint16_t i = 0; - debugUART.baud(921600); + debugUART.baud(115200); // mDotUART.baud(9600); // mdot UART unused but available on external connector Thread thread_1(pb1_debounce); // threads for de-bouncing pushbutton switches @@ -164,7 +175,7 @@ thread_3 = new Thread(config_pkt_xmit); // start thread that sends LoRa packet when SW2 pressed evbAccel = new MMA845x(mDoti2c,MMA845x::SA0_VSS); // setup Accelerometer - evbBaro = new MPL3115A2(mDoti2c); // setup Barometric sensor + evbBaro = new MPL3115A2(mDoti2c); // setup0 Barometric sensor evbAmbLight = new ISL29011(mDoti2c); // Setup Ambient Light Sensor evbBackLight = new NCP5623B(mDoti2c); // setup backlight and LED 2 driver chip evbLCD = new DOGS102(mDotspi, mDot17, mDot13); // setup LCD @@ -399,12 +410,6 @@ */ pckt_time = 10; i = 0; - char sensor_text[54]; - char lora_temp_string[7]; - char lora_alt_string[8]; - char lora_press_string[9]; - char lora_light_string[6]; - do { evbLCD->startUpdate(); evbLCD->clearBuffer(); @@ -412,10 +417,13 @@ /* * Test Accelerometer XYZ data ready bit to see if acquisition complete */ + failtime = FAIL_MAX; do { osDelay(100); // allows other threads to process result = evbAccel->getStatus(); - } while ((result & MMA845x::XYZDR) == 0 ); + failtime--; + } while ((result & MMA845x::XYZDR) == 0 && failtime > 0); + if (failtime==0) {continue; } /* * Retrieve and print out accelerometer data @@ -441,26 +449,28 @@ /* * Test barometer device status to see if acquisition is complete */ + failtime=FAIL_MAX; do { osDelay(100); // allows other threads to process result = evbBaro->getStatus(); - } while ((result & MPL3115A2::PTDR) == 0 ); - + failtime--; + } while ((result & MPL3115A2::PTDR) == 0 && failtime > 0 ); + if (failtime==0) {continue; } /* * Retrieve and print out barometric pressure */ pressure = evbBaro->getBaroData() >> 12; // convert 32 bit signed to 20 bit unsigned value num_whole = pressure >> 2; // 18 bit integer significant num_frac = (pressure & 0x3) * 25; // 2 bit fractional 0.25 per bit + // if failtime reached 0 , indicates that the result might be junk. sprintf(txtstr,"Press=%ld.%02d Pa", num_whole, num_frac); pressure = evbBaro->getBaroData() >> 12; // convert 32 bit signed to 20 bit unsigned value num_whole = pressure >> 2; // 18 bit integer significant num_frac = (pressure & 0x3) * 25; // 2 bit fractional 0.25 per bit - sprintf(lora_press_string, "%ld.%02d", num_whole, num_frac); + writeValueOrError(); // will write to lorapresstring and txtstr - evbLCD->writeText(0,4,font_6x8,txtstr,strlen(txtstr)); /* * Trigger a Altitude reading @@ -472,10 +482,13 @@ /* * Test barometer device status to see if acquisition is complete */ + failtime=FAIL_MAX; do { osDelay(100); // allows other threads to process result = evbBaro->getStatus(); - } while ((result & MPL3115A2::PTDR) == 0 ); + failtime--; + } while ((result & MPL3115A2::PTDR) == 0 && failtime > 0 ); + if (failtime==0) {continue; } /* * Retrieve and print out altitude and temperature @@ -696,4 +709,21 @@ printf("Data sent!\r\n"); } return ret; -} \ No newline at end of file +} + +bool writeValueOrError() +{ + bool res; + if (failtime==0){ + sprintf(lora_press_string, "%s", "--.--"); + sprintf(txtstr, "%s", "--.--"); + evbLCD->writeText(0,4,font_6x8,txtstr, strlen(txtstr)); + res=false; + }else{ + sprintf(lora_press_string, "%ld.%02d", num_whole, num_frac); + evbLCD->writeText(0,4,font_6x8,txtstr,strlen(txtstr)); + res=true; + } + return res; +} +