Condensation Monitor Measure the current environment condition at outside and inside and make caution or warnings related to condensation. Support UART over BLE. It works with nRF Toolbox. 結露モニタ 屋内外の環境情報を計測し、結露に関する警告あるいは注意を出力します。 nRF Toolboxと一緒に動作し、UART機能でBLE経由でメッセージを出力します。 ドキュメント https://developer.mbed.org/users/takafuminaka/notebook/information-about-my-condensation-monitor-for-mbed/
Dependencies: AQM0802 BME280 HDC1000 VaporCondition mbed BLE_API nRF51822 BLE_Condensation_Monitor
Dependents: BLE_Condensation_Monitor
Fork of Condensation_Monitor by
Revision 6:3c2404870d39, committed 2015-05-31
- Comitter:
- takafuminaka
- Date:
- Sun May 31 11:11:48 2015 +0000
- Parent:
- 5:06d988a47721
- Child:
- 7:7cecec859fe1
- Commit message:
- Small Modifications
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Sun May 31 09:46:44 2015 +0000 +++ b/main.cpp Sun May 31 11:11:48 2015 +0000 @@ -35,17 +35,17 @@ #endif /* #if NEED_BLE_CONSOLE */ #if defined(TARGET_LPC1768) - I2C i2c(p28, p27); - // BME280 sensor(p28, p27, 0x76 << 1); +I2C i2c(p28, p27); +// BME280 sensor(p28, p27, 0x76 << 1); #else - I2C i2c(I2C_SDA0, I2C_SCL0); - // BME280 sensor(I2C_SDA0, I2C_SCL0, 0x76 << 1); +I2C i2c(I2C_SDA0, I2C_SCL0); +// BME280 sensor(I2C_SDA0, I2C_SCL0, 0x76 << 1); #endif BME280 bme280(I2C_SDA0, I2C_SCL0, 0x76 << 1); HDC1000 hdc1000(i2c); #if NEED_LCD_OUTPUT - AQM0802 lcd(i2c); +AQM0802 lcd(i2c); #endif DigitalOut led1(LED1); @@ -64,7 +64,8 @@ #endif /* #if NEED_BLE_CONSOLE */ -int main() { +int main() +{ float Tdp_o =0.; float Tdp_i =0.; int cautions = 0; @@ -76,7 +77,7 @@ char msg[4][2][9]; char bmsg[4][20]; int skipf[4]; - + float Tcur; float Tdp; char *sTcur; @@ -86,24 +87,26 @@ char *bsTcur; char *bsWin; + int skipped = 0; + VaporCondition Inside; VaporCondition Outside; - // LED Check + // LED Check led1 = 1; led2 = 1; wait(3); led1 = 0; led2 = 0; - + // i2c.frequency(100000); - + #if NEED_BLE_CONSOLE - // Setup BLE // + // Setup BLE // ble.init(); ble.onDisconnection(disconnectionCallback); - + uart = new UARTService(ble); /* setup advertising */ @@ -117,123 +120,125 @@ ble.setAdvertisingInterval(160); /* 100ms; in multiples of 0.625ms. */ ble.startAdvertising(); #endif /* #if NEED_BLE_CONSOLE */ - + while(1) { - // Get data + if ( skipped == 0 ) { + // Get data + + Outside.t = bme280.getTemperature(); + Outside.h = bme280.getHumidity(); + + Outside.p = bme280.getPressure(); + Inside.p = bme280.getPressure(); // Usually Pressures are same between inside and outside. - Outside.t = bme280.getTemperature(); - Outside.h = bme280.getHumidity(); + Inside.t = float(hdc1000.temperature())/0x10000*165-40; + Inside.h = float(hdc1000.humidity())/0x10000*100; + - Outside.p = bme280.getPressure(); - Inside.p = bme280.getPressure(); // Usually Pressures are same between inside and outside. + PC("In: %2.2f degC, %2.2f %% Out: %2.2f degC, %2.2f %%, %04.2f hPa\r\n", Inside.t, Inside.h, Outside.t, Outside.h, Outside.p); + PC("Humidity Ratio [g/kg] : In %2.2f Out %2.2f \r\n", Inside.Rh(), Outside.Rh()); + Tdp_o = Outside.Tdp(); + Tdp_i = Inside.Tdp(); + PC("Due Point Temperature [degC] : In %2.2f Out %2.2f \r\n", Tdp_o, Tdp_i); - Inside.t = float(hdc1000.temperature())/0x10000*165-40; - Inside.h = float(hdc1000.humidity())/0x10000*100; + // print catuions and warnings // + cautions = 0; + warnings = 0; - - PC("In: %2.2f degC, %2.2f %% Out: %2.2f degC, %2.2f %%, %04.2f hPa\r\n", Inside.t, Inside.h, Outside.t, Outside.h, Outside.p); - PC("Humidity Ratio [g/kg] : In %2.2f Out %2.2f \r\n", Inside.Rh(), Outside.Rh()); - Tdp_o = Outside.Tdp(); - Tdp_i = Inside.Tdp(); - PC("Due Point Temperature [degC] : In %2.2f Out %2.2f \r\n", Tdp_o, Tdp_i); + for(int ii=0; ii<4; ii++) { + if ( (ii % 2) == 1 ) { + Tcur = Outside.t; // 1 and 3 + sTcur = "Outside"; + ssTcur = "Out"; + bsTcur = "Out"; + } else { + Tcur = Inside.t; // 0 and 2 + sTcur = "Inside"; + ssTcur = "In"; + bsTcur = "In"; + } - // print catuions and warnings // - cautions = 0; - warnings = 0; + if ( ii / 2 ) { + sWin = " Window"; // 2 and 3 + ssWin = "@Win"; + bsWin = "Wind."; + } else { + sWin = ""; // 0 and 1 + ssWin = ""; + bsWin = ""; + } - for(int ii=0; ii<4; ii++) { - if ( (ii % 2) == 1 ) { - Tcur = Outside.t; // 1 and 3 - sTcur = "Outside"; - ssTcur = "Out"; - bsTcur = "Out"; - } else { - Tcur = Inside.t; // 0 and 2 - sTcur = "Inside"; - ssTcur = "In"; - bsTcur = "In"; + if ( ii / 2 == ii %2 ) { + Tdp = Tdp_i; // 0 and 3 + } else { + Tdp = Tdp_o; // 1 and 1 + } + + if ( Tdp >= Tcur - warn_wid ) { + skipf[ii] = 0; + if ( Tdp >= Tcur ) { + PC("Condensation at %s\r\n",sTcur); + sprintf(msg[ii][0],"Condns!!"); + sprintf(msg[ii][1],"%s%s",ssTcur,ssWin); + sprintf(bmsg[ii],"Cond. at %s",bsWin); + cautions ++; + } else { + PC("%4.1f degC to Condensation at %s%s\r\n", Tcur - Tdp, sTcur, sWin); + sprintf(msg[ii][0],"Cto%4.1fC",Tcur-Tdp); + sprintf(msg[ii][1],"%s%s\0",ssTcur,ssWin); + sprintf(bmsg[ii],"%4.1ftoC.at%s%s",Tcur - Tdp, bsTcur, bsWin); + warnings ++; + } + } else { + skipf[ii] = 1; + } } - if ( ii / 2 ) { - sWin = " Window"; // 2 and 3 - ssWin = "@Win"; - bsWin = "Wind."; + PC("\r\n"); + + if ( cautions > 0 ) { + led2 = 1; } else { - sWin = ""; // 0 and 1 - ssWin = ""; - bsWin = ""; - } - - if ( ii / 2 == ii %2 ) { - Tdp = Tdp_i; // 0 and 3 - } else { - Tdp = Tdp_o; // 1 and 1 + led2 = 0; } - if ( Tdp >= Tcur - warn_wid ) { - skipf[ii] = 0; - if ( Tdp >= Tcur ) { - PC("Condensation at %s\r\n",sTcur); - sprintf(msg[ii][0],"Condns!!"); - sprintf(msg[ii][1],"%s%s",ssTcur,ssWin); - sprintf(bmsg[ii],"Cond. at %s",bsWin); - cautions ++; - } else { - PC("%4.1f degC to Condensation at %s%s\r\n", Tcur - Tdp, sTcur, sWin); - sprintf(msg[ii][0],"Cto%4.1fC",Tcur-Tdp); - sprintf(msg[ii][1],"%s%s\0",ssTcur,ssWin); - sprintf(bmsg[ii],"%4.1ftoC.at%s%s",Tcur - Tdp, bsTcur, bsWin); - warnings ++; - } + if ( warnings > 0 ) { + led1 = 1; } else { - skipf[ii] = 1; + led1 = 0; } - } - PC("\r\n"); - - if ( cautions > 0 ) { - led2 = 1; - } else { - led2 = 0; } - - if ( warnings > 0 ) { - led1 = 1; - } else { - led1 = 0; - } - // LCD print switch(mode) { case (0): skip = 1; break; - + case (1): sprintf(msg1,"Ti %4.1fC",Inside.t); sprintf(msg2,"To %4.1fC",Outside.t); BLEC("Temp.In%4.1f Out%4.1f\n",Inside.t, Outside.t); break; - + case (2): sprintf(msg1,"Hi %4.1f%%",Inside.h); sprintf(msg2,"Ho %4.1f%%",Outside.h); BLEC("Hum.In%2.0f%% Out%2.0f%%\n",Inside.h, Outside.h); break; - + case (3): sprintf(msg1,"Po%6.2f",Outside.p); sprintf(msg2," [hPa]"); BLEC("Press. %6.2fhPa\n",Outside.p); break; - + case (4): sprintf(msg1,"Dpi%4.1fC",Tdp_i); sprintf(msg2,"Dpo%4.1fC",Tdp_o); BLEC("DP. In%4.1f Out%4.1f\n",Tdp_i, Tdp_o); break; - + case (5): case (6): case (7): @@ -247,20 +252,22 @@ } mode++; if ( mode > 8 ) { - mode = 0; - } - + mode = 0; + } + if ( skip == 0 ) { #if NEED_LCD_OUTPUT lcd.locate(0,0); lcd.print(msg1); lcd.locate(0,1); lcd.print(msg2); + #endif - + skipped = 0; wait(3); } else { skip = 0; + skipped = 1; } }