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.
DebugCommander.cpp
00001 #include "SysConfig.h" 00002 00003 #define SMUX_MHZ19 0 00004 #define SMUX_ZPH01 1 00005 #define SMUX_ESP01 2 00006 #define SMUX_ZE08 3 00007 00008 #define uart_db uart_pc 00009 00010 void LedFlasher(void) 00011 { 00012 int ledNumOn; 00013 for(ledNumOn = 1; ledNumOn < LED_NUM_MAX; ledNumOn++) 00014 { 00015 LedOffAll(); 00016 LedOn(ledNumOn); 00017 wait_ms(300); 00018 } 00019 } 00020 00021 void DebugFunc_CO2(void) 00022 { 00023 uart_db.printf("Reading MHZ19..."); 00024 SerialMuxSel(SMUX_MHZ19); 00025 int co2Vol = MHZ19_ReadCO2(); 00026 if(co2Vol < 0) 00027 uart_db.printf("CheckSum Error!\n\r"); 00028 else 00029 uart_db.printf("OK!\n\rCO2 Vol = %dppm.\n\r\n\r", co2Vol); 00030 } 00031 00032 void DebugFunc_PM25(void) 00033 { 00034 float pm25Vol = 0, pm25VolAvg = 0; 00035 int cnt = 0, cnt_max = 30; 00036 uart_db.printf("Reading ZPH01 (need %dsec)", cnt_max); 00037 SerialMuxSel(SMUX_ZPH01); 00038 00039 while(cnt < cnt_max) 00040 { 00041 pm25Vol = ZPH01_ReadPM25(); 00042 if(pm25Vol < 0) 00043 { 00044 uart_db.printf("CheckSum Error!\n\rRepeat reading"); 00045 } 00046 else 00047 { 00048 pm25VolAvg += pm25Vol; 00049 uart_db.printf("."); 00050 //uart_db.printf("Single sample = %fug/m^3.\n\r", pm25Vol); 00051 cnt++; 00052 } 00053 } 00054 pm25VolAvg = pm25VolAvg / cnt_max; 00055 uart_db.printf("OK!\n\rPM2.5 Vol = %fug/m^3.\n\r\n\r", pm25VolAvg); 00056 } 00057 00058 void DebugFunc_CH2O(void) 00059 { 00060 uart_db.printf("Reading ZE08..."); 00061 SerialMuxSel(SMUX_ZE08); 00062 int ch2oVol = ZE08_ReadCH2O(); 00063 if(ch2oVol < 0) 00064 uart_db.printf("CheckSum Error!\n\r"); 00065 else 00066 uart_db.printf("OK!\n\rCH2O Vol = %dug/m^3.\n\r\n\r", ch2oVol); 00067 } 00068 00069 void DebugFunc_TempRh(void) 00070 { 00071 uart_db.printf("Reading SHT20..."); 00072 float temp = SHT20_ReadTemp(); 00073 float rh = SHT20_ReadRh(); 00074 uart_db.printf("OK!\n\rTemperature = %.2f, Humidity = %2.f\n\r\n\r", temp, rh); 00075 } 00076 00077 void DebugFunc_AirPress(void) 00078 { 00079 uart_db.printf("Air pressure test not implemented...\n\r"); 00080 } 00081 00082 void DebugFunc_UvLevel(void) 00083 { 00084 uart_db.printf("UV level test not implemented...\n\r"); 00085 } 00086 00087 void DebugFunc_WiFi(void) 00088 { 00089 uart_db.printf("WiFi test not implemented...\n\r"); 00090 } 00091 00092 void DebugFunc_SwitchSmux(void) 00093 { 00094 uart_db.printf("Please type SMUX channel(0~3) with ENTER.\n\r"); 00095 while(!uart_db.readable()); 00096 uint8_t ch = uart_db.getc(); 00097 SerialMuxSel(ch - '0'); 00098 uart_db.printf("Switched to ch %c.\n\r", ch); 00099 } 00100 00101 void DebugCommander(void) 00102 { 00103 int quitFlag = 0, cmdPc; 00104 while(!quitFlag) 00105 { 00106 uart_db.printf("\n\r\n\r============ AirBox Nucleo Adaptor Demo ============\n\r\n\r"); 00107 uart_db.printf(" 0. All sensors auto Test.\n\r"); 00108 uart_db.printf(" 1. Test CO2 gas sensor.\n\r"); 00109 uart_db.printf(" 2. Test PM2.5 dust sensor.\n\r"); 00110 uart_db.printf(" 3. Test CH2O gas sensor.\n\r"); 00111 uart_db.printf(" 4. Test temperature & humidity sensor.\n\r"); 00112 uart_db.printf(" 5. Test air pressure sensor.\n\r"); 00113 uart_db.printf(" 6. Test UV light level.\n\r"); 00114 uart_db.printf(" w. Test WiFi module.\n\r"); 00115 uart_db.printf(" m. Manual switch SMUX channel.\n\r"); 00116 uart_db.printf(" q. Exit demo.\n\r\n\r"); 00117 uart_db.printf(" Input:\n\r\n\r"); 00118 00119 while(!uart_db.readable()) 00120 { 00121 #if 0 00122 if(uart_sen.readable()) 00123 uart_db.printf(" <0x%02X> ", uart_sen.getc()); 00124 #endif 00125 } 00126 cmdPc = uart_db.getc(); 00127 00128 switch(cmdPc) 00129 { 00130 case 'q': 00131 quitFlag = 1; 00132 uart_db.printf("\n\rExiting demo...\n\r"); 00133 break; 00134 00135 case 'm': 00136 DebugFunc_SwitchSmux(); 00137 break; 00138 00139 case 'w': 00140 DebugFunc_WiFi(); 00141 break; 00142 00143 case '0': 00144 DebugFunc_CO2(); 00145 DebugFunc_CH2O(); 00146 DebugFunc_PM25(); 00147 DebugFunc_TempRh(); 00148 DebugFunc_AirPress(); 00149 DebugFunc_UvLevel(); 00150 break; 00151 00152 case '1': 00153 DebugFunc_CO2(); 00154 break; 00155 00156 case '2': 00157 DebugFunc_PM25(); 00158 break; 00159 00160 case '3': 00161 DebugFunc_CH2O(); 00162 break; 00163 00164 case '4': 00165 DebugFunc_TempRh(); 00166 break; 00167 00168 case '5': 00169 DebugFunc_AirPress(); 00170 break; 00171 00172 case '6': 00173 DebugFunc_UvLevel(); 00174 break; 00175 00176 case 'z': 00177 MHZ19_CalZero(); 00178 break; 00179 00180 00181 case 'f': 00182 MHZ19_CalFull(); 00183 break; 00184 00185 default: 00186 uart_db.printf("Incorrect input!\n\r"); 00187 break; 00188 } 00189 00190 uart_db.printf("\n\rPress any key...\n\r"); 00191 00192 while(!uart_db.readable()); 00193 cmdPc = uart_db.getc(); 00194 00195 } 00196 00197 } 00198
Generated on Fri Jul 15 2022 14:37:21 by
1.7.2