Xiaohai Li
/
AirBoxProto
Demo
AplicationLayer/DebugCommander.cpp@2:0ee90da44162, 2016-05-19 (annotated)
- Committer:
- nightseas
- Date:
- Thu May 19 15:52:24 2016 +0000
- Revision:
- 2:0ee90da44162
- Parent:
- 1:0c1053275589
AirBoxProtoDemo
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nightseas | 0:3dac4f477e98 | 1 | #include "SysConfig.h" |
nightseas | 0:3dac4f477e98 | 2 | |
nightseas | 0:3dac4f477e98 | 3 | #define SMUX_MHZ19 0 |
nightseas | 0:3dac4f477e98 | 4 | #define SMUX_ZPH01 1 |
nightseas | 0:3dac4f477e98 | 5 | #define SMUX_ESP01 2 |
nightseas | 0:3dac4f477e98 | 6 | #define SMUX_ZE08 3 |
nightseas | 0:3dac4f477e98 | 7 | |
nightseas | 0:3dac4f477e98 | 8 | #define uart_db uart_pc |
nightseas | 0:3dac4f477e98 | 9 | |
nightseas | 0:3dac4f477e98 | 10 | void LedFlasher(void) |
nightseas | 0:3dac4f477e98 | 11 | { |
nightseas | 0:3dac4f477e98 | 12 | int ledNumOn; |
nightseas | 0:3dac4f477e98 | 13 | for(ledNumOn = 1; ledNumOn < LED_NUM_MAX; ledNumOn++) |
nightseas | 0:3dac4f477e98 | 14 | { |
nightseas | 0:3dac4f477e98 | 15 | LedOffAll(); |
nightseas | 0:3dac4f477e98 | 16 | LedOn(ledNumOn); |
nightseas | 0:3dac4f477e98 | 17 | wait_ms(300); |
nightseas | 0:3dac4f477e98 | 18 | } |
nightseas | 0:3dac4f477e98 | 19 | } |
nightseas | 0:3dac4f477e98 | 20 | |
nightseas | 0:3dac4f477e98 | 21 | void DebugFunc_CO2(void) |
nightseas | 0:3dac4f477e98 | 22 | { |
nightseas | 0:3dac4f477e98 | 23 | uart_db.printf("Reading MHZ19..."); |
nightseas | 0:3dac4f477e98 | 24 | SerialMuxSel(SMUX_MHZ19); |
nightseas | 0:3dac4f477e98 | 25 | int co2Vol = MHZ19_ReadCO2(); |
nightseas | 0:3dac4f477e98 | 26 | if(co2Vol < 0) |
nightseas | 0:3dac4f477e98 | 27 | uart_db.printf("CheckSum Error!\n\r"); |
nightseas | 0:3dac4f477e98 | 28 | else |
nightseas | 1:0c1053275589 | 29 | uart_db.printf("OK!\n\rCO2 Vol = %dppm.\n\r\n\r", co2Vol); |
nightseas | 0:3dac4f477e98 | 30 | } |
nightseas | 0:3dac4f477e98 | 31 | |
nightseas | 0:3dac4f477e98 | 32 | void DebugFunc_PM25(void) |
nightseas | 0:3dac4f477e98 | 33 | { |
nightseas | 0:3dac4f477e98 | 34 | float pm25Vol = 0, pm25VolAvg = 0; |
nightseas | 0:3dac4f477e98 | 35 | int cnt = 0, cnt_max = 30; |
nightseas | 1:0c1053275589 | 36 | uart_db.printf("Reading ZPH01 (need %dsec)", cnt_max); |
nightseas | 0:3dac4f477e98 | 37 | SerialMuxSel(SMUX_ZPH01); |
nightseas | 0:3dac4f477e98 | 38 | |
nightseas | 0:3dac4f477e98 | 39 | while(cnt < cnt_max) |
nightseas | 0:3dac4f477e98 | 40 | { |
nightseas | 0:3dac4f477e98 | 41 | pm25Vol = ZPH01_ReadPM25(); |
nightseas | 0:3dac4f477e98 | 42 | if(pm25Vol < 0) |
nightseas | 0:3dac4f477e98 | 43 | { |
nightseas | 1:0c1053275589 | 44 | uart_db.printf("CheckSum Error!\n\rRepeat reading"); |
nightseas | 0:3dac4f477e98 | 45 | } |
nightseas | 0:3dac4f477e98 | 46 | else |
nightseas | 0:3dac4f477e98 | 47 | { |
nightseas | 0:3dac4f477e98 | 48 | pm25VolAvg += pm25Vol; |
nightseas | 1:0c1053275589 | 49 | uart_db.printf("."); |
nightseas | 1:0c1053275589 | 50 | //uart_db.printf("Single sample = %fug/m^3.\n\r", pm25Vol); |
nightseas | 0:3dac4f477e98 | 51 | cnt++; |
nightseas | 0:3dac4f477e98 | 52 | } |
nightseas | 0:3dac4f477e98 | 53 | } |
nightseas | 0:3dac4f477e98 | 54 | pm25VolAvg = pm25VolAvg / cnt_max; |
nightseas | 1:0c1053275589 | 55 | uart_db.printf("OK!\n\rPM2.5 Vol = %fug/m^3.\n\r\n\r", pm25VolAvg); |
nightseas | 0:3dac4f477e98 | 56 | } |
nightseas | 0:3dac4f477e98 | 57 | |
nightseas | 0:3dac4f477e98 | 58 | void DebugFunc_CH2O(void) |
nightseas | 0:3dac4f477e98 | 59 | { |
nightseas | 0:3dac4f477e98 | 60 | uart_db.printf("Reading ZE08..."); |
nightseas | 0:3dac4f477e98 | 61 | SerialMuxSel(SMUX_ZE08); |
nightseas | 0:3dac4f477e98 | 62 | int ch2oVol = ZE08_ReadCH2O(); |
nightseas | 0:3dac4f477e98 | 63 | if(ch2oVol < 0) |
nightseas | 0:3dac4f477e98 | 64 | uart_db.printf("CheckSum Error!\n\r"); |
nightseas | 0:3dac4f477e98 | 65 | else |
nightseas | 1:0c1053275589 | 66 | uart_db.printf("OK!\n\rCH2O Vol = %dug/m^3.\n\r\n\r", ch2oVol); |
nightseas | 0:3dac4f477e98 | 67 | } |
nightseas | 0:3dac4f477e98 | 68 | |
nightseas | 0:3dac4f477e98 | 69 | void DebugFunc_TempRh(void) |
nightseas | 0:3dac4f477e98 | 70 | { |
nightseas | 0:3dac4f477e98 | 71 | uart_db.printf("Reading SHT20..."); |
nightseas | 0:3dac4f477e98 | 72 | float temp = SHT20_ReadTemp(); |
nightseas | 0:3dac4f477e98 | 73 | float rh = SHT20_ReadRh(); |
nightseas | 1:0c1053275589 | 74 | uart_db.printf("OK!\n\rTemperature = %.2f, Humidity = %2.f\n\r\n\r", temp, rh); |
nightseas | 0:3dac4f477e98 | 75 | } |
nightseas | 0:3dac4f477e98 | 76 | |
nightseas | 0:3dac4f477e98 | 77 | void DebugFunc_AirPress(void) |
nightseas | 0:3dac4f477e98 | 78 | { |
nightseas | 1:0c1053275589 | 79 | uart_db.printf("Air pressure test not implemented...\n\r"); |
nightseas | 0:3dac4f477e98 | 80 | } |
nightseas | 0:3dac4f477e98 | 81 | |
nightseas | 0:3dac4f477e98 | 82 | void DebugFunc_UvLevel(void) |
nightseas | 0:3dac4f477e98 | 83 | { |
nightseas | 1:0c1053275589 | 84 | uart_db.printf("UV level test not implemented...\n\r"); |
nightseas | 0:3dac4f477e98 | 85 | } |
nightseas | 0:3dac4f477e98 | 86 | |
nightseas | 0:3dac4f477e98 | 87 | void DebugFunc_WiFi(void) |
nightseas | 0:3dac4f477e98 | 88 | { |
nightseas | 1:0c1053275589 | 89 | uart_db.printf("WiFi test not implemented...\n\r"); |
nightseas | 0:3dac4f477e98 | 90 | } |
nightseas | 0:3dac4f477e98 | 91 | |
nightseas | 0:3dac4f477e98 | 92 | void DebugFunc_SwitchSmux(void) |
nightseas | 0:3dac4f477e98 | 93 | { |
nightseas | 0:3dac4f477e98 | 94 | uart_db.printf("Please type SMUX channel(0~3) with ENTER.\n\r"); |
nightseas | 0:3dac4f477e98 | 95 | while(!uart_db.readable()); |
nightseas | 0:3dac4f477e98 | 96 | uint8_t ch = uart_db.getc(); |
nightseas | 0:3dac4f477e98 | 97 | SerialMuxSel(ch - '0'); |
nightseas | 0:3dac4f477e98 | 98 | uart_db.printf("Switched to ch %c.\n\r", ch); |
nightseas | 0:3dac4f477e98 | 99 | } |
nightseas | 0:3dac4f477e98 | 100 | |
nightseas | 0:3dac4f477e98 | 101 | void DebugCommander(void) |
nightseas | 0:3dac4f477e98 | 102 | { |
nightseas | 0:3dac4f477e98 | 103 | int quitFlag = 0, cmdPc; |
nightseas | 0:3dac4f477e98 | 104 | while(!quitFlag) |
nightseas | 0:3dac4f477e98 | 105 | { |
nightseas | 0:3dac4f477e98 | 106 | uart_db.printf("\n\r\n\r============ AirBox Nucleo Adaptor Demo ============\n\r\n\r"); |
nightseas | 0:3dac4f477e98 | 107 | uart_db.printf(" 0. All sensors auto Test.\n\r"); |
nightseas | 0:3dac4f477e98 | 108 | uart_db.printf(" 1. Test CO2 gas sensor.\n\r"); |
nightseas | 0:3dac4f477e98 | 109 | uart_db.printf(" 2. Test PM2.5 dust sensor.\n\r"); |
nightseas | 0:3dac4f477e98 | 110 | uart_db.printf(" 3. Test CH2O gas sensor.\n\r"); |
nightseas | 0:3dac4f477e98 | 111 | uart_db.printf(" 4. Test temperature & humidity sensor.\n\r"); |
nightseas | 0:3dac4f477e98 | 112 | uart_db.printf(" 5. Test air pressure sensor.\n\r"); |
nightseas | 0:3dac4f477e98 | 113 | uart_db.printf(" 6. Test UV light level.\n\r"); |
nightseas | 0:3dac4f477e98 | 114 | uart_db.printf(" w. Test WiFi module.\n\r"); |
nightseas | 0:3dac4f477e98 | 115 | uart_db.printf(" m. Manual switch SMUX channel.\n\r"); |
nightseas | 0:3dac4f477e98 | 116 | uart_db.printf(" q. Exit demo.\n\r\n\r"); |
nightseas | 2:0ee90da44162 | 117 | uart_db.printf(" Input:\n\r\n\r"); |
nightseas | 0:3dac4f477e98 | 118 | |
nightseas | 0:3dac4f477e98 | 119 | while(!uart_db.readable()) |
nightseas | 0:3dac4f477e98 | 120 | { |
nightseas | 0:3dac4f477e98 | 121 | #if 0 |
nightseas | 0:3dac4f477e98 | 122 | if(uart_sen.readable()) |
nightseas | 0:3dac4f477e98 | 123 | uart_db.printf(" <0x%02X> ", uart_sen.getc()); |
nightseas | 0:3dac4f477e98 | 124 | #endif |
nightseas | 0:3dac4f477e98 | 125 | } |
nightseas | 0:3dac4f477e98 | 126 | cmdPc = uart_db.getc(); |
nightseas | 0:3dac4f477e98 | 127 | |
nightseas | 0:3dac4f477e98 | 128 | switch(cmdPc) |
nightseas | 0:3dac4f477e98 | 129 | { |
nightseas | 0:3dac4f477e98 | 130 | case 'q': |
nightseas | 0:3dac4f477e98 | 131 | quitFlag = 1; |
nightseas | 0:3dac4f477e98 | 132 | uart_db.printf("\n\rExiting demo...\n\r"); |
nightseas | 0:3dac4f477e98 | 133 | break; |
nightseas | 0:3dac4f477e98 | 134 | |
nightseas | 0:3dac4f477e98 | 135 | case 'm': |
nightseas | 0:3dac4f477e98 | 136 | DebugFunc_SwitchSmux(); |
nightseas | 0:3dac4f477e98 | 137 | break; |
nightseas | 0:3dac4f477e98 | 138 | |
nightseas | 0:3dac4f477e98 | 139 | case 'w': |
nightseas | 0:3dac4f477e98 | 140 | DebugFunc_WiFi(); |
nightseas | 1:0c1053275589 | 141 | break; |
nightseas | 1:0c1053275589 | 142 | |
nightseas | 1:0c1053275589 | 143 | case '0': |
nightseas | 1:0c1053275589 | 144 | DebugFunc_CO2(); |
nightseas | 1:0c1053275589 | 145 | DebugFunc_CH2O(); |
nightseas | 1:0c1053275589 | 146 | DebugFunc_PM25(); |
nightseas | 1:0c1053275589 | 147 | DebugFunc_TempRh(); |
nightseas | 1:0c1053275589 | 148 | DebugFunc_AirPress(); |
nightseas | 1:0c1053275589 | 149 | DebugFunc_UvLevel(); |
nightseas | 1:0c1053275589 | 150 | break; |
nightseas | 0:3dac4f477e98 | 151 | |
nightseas | 0:3dac4f477e98 | 152 | case '1': |
nightseas | 0:3dac4f477e98 | 153 | DebugFunc_CO2(); |
nightseas | 0:3dac4f477e98 | 154 | break; |
nightseas | 0:3dac4f477e98 | 155 | |
nightseas | 0:3dac4f477e98 | 156 | case '2': |
nightseas | 0:3dac4f477e98 | 157 | DebugFunc_PM25(); |
nightseas | 0:3dac4f477e98 | 158 | break; |
nightseas | 0:3dac4f477e98 | 159 | |
nightseas | 0:3dac4f477e98 | 160 | case '3': |
nightseas | 0:3dac4f477e98 | 161 | DebugFunc_CH2O(); |
nightseas | 0:3dac4f477e98 | 162 | break; |
nightseas | 0:3dac4f477e98 | 163 | |
nightseas | 0:3dac4f477e98 | 164 | case '4': |
nightseas | 0:3dac4f477e98 | 165 | DebugFunc_TempRh(); |
nightseas | 0:3dac4f477e98 | 166 | break; |
nightseas | 0:3dac4f477e98 | 167 | |
nightseas | 0:3dac4f477e98 | 168 | case '5': |
nightseas | 0:3dac4f477e98 | 169 | DebugFunc_AirPress(); |
nightseas | 0:3dac4f477e98 | 170 | break; |
nightseas | 0:3dac4f477e98 | 171 | |
nightseas | 0:3dac4f477e98 | 172 | case '6': |
nightseas | 0:3dac4f477e98 | 173 | DebugFunc_UvLevel(); |
nightseas | 0:3dac4f477e98 | 174 | break; |
nightseas | 2:0ee90da44162 | 175 | |
nightseas | 2:0ee90da44162 | 176 | case 'z': |
nightseas | 2:0ee90da44162 | 177 | MHZ19_CalZero(); |
nightseas | 2:0ee90da44162 | 178 | break; |
nightseas | 2:0ee90da44162 | 179 | |
nightseas | 2:0ee90da44162 | 180 | |
nightseas | 2:0ee90da44162 | 181 | case 'f': |
nightseas | 2:0ee90da44162 | 182 | MHZ19_CalFull(); |
nightseas | 2:0ee90da44162 | 183 | break; |
nightseas | 2:0ee90da44162 | 184 | |
nightseas | 0:3dac4f477e98 | 185 | default: |
nightseas | 0:3dac4f477e98 | 186 | uart_db.printf("Incorrect input!\n\r"); |
nightseas | 0:3dac4f477e98 | 187 | break; |
nightseas | 0:3dac4f477e98 | 188 | } |
nightseas | 0:3dac4f477e98 | 189 | |
nightseas | 0:3dac4f477e98 | 190 | uart_db.printf("\n\rPress any key...\n\r"); |
nightseas | 0:3dac4f477e98 | 191 | |
nightseas | 0:3dac4f477e98 | 192 | while(!uart_db.readable()); |
nightseas | 0:3dac4f477e98 | 193 | cmdPc = uart_db.getc(); |
nightseas | 0:3dac4f477e98 | 194 | |
nightseas | 0:3dac4f477e98 | 195 | } |
nightseas | 0:3dac4f477e98 | 196 | |
nightseas | 0:3dac4f477e98 | 197 | } |
nightseas | 0:3dac4f477e98 | 198 |