Xiaohai Li
/
AirBoxProto
Demo
AplicationLayer/DebugCommander.cpp@1:0c1053275589, 2015-07-09 (annotated)
- Committer:
- nightseas
- Date:
- Thu Jul 09 05:14:58 2015 +0000
- Revision:
- 1:0c1053275589
- Parent:
- 0:3dac4f477e98
- Child:
- 2:0ee90da44162
Update commander and fix sensor bugs.
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 | 0:3dac4f477e98 | 117 | |
nightseas | 0:3dac4f477e98 | 118 | while(!uart_db.readable()) |
nightseas | 0:3dac4f477e98 | 119 | { |
nightseas | 0:3dac4f477e98 | 120 | #if 0 |
nightseas | 0:3dac4f477e98 | 121 | if(uart_sen.readable()) |
nightseas | 0:3dac4f477e98 | 122 | uart_db.printf(" <0x%02X> ", uart_sen.getc()); |
nightseas | 0:3dac4f477e98 | 123 | #endif |
nightseas | 0:3dac4f477e98 | 124 | } |
nightseas | 0:3dac4f477e98 | 125 | cmdPc = uart_db.getc(); |
nightseas | 0:3dac4f477e98 | 126 | |
nightseas | 0:3dac4f477e98 | 127 | switch(cmdPc) |
nightseas | 0:3dac4f477e98 | 128 | { |
nightseas | 0:3dac4f477e98 | 129 | case 'q': |
nightseas | 0:3dac4f477e98 | 130 | quitFlag = 1; |
nightseas | 0:3dac4f477e98 | 131 | uart_db.printf("\n\rExiting demo...\n\r"); |
nightseas | 0:3dac4f477e98 | 132 | break; |
nightseas | 0:3dac4f477e98 | 133 | |
nightseas | 0:3dac4f477e98 | 134 | case 'm': |
nightseas | 0:3dac4f477e98 | 135 | DebugFunc_SwitchSmux(); |
nightseas | 0:3dac4f477e98 | 136 | break; |
nightseas | 0:3dac4f477e98 | 137 | |
nightseas | 0:3dac4f477e98 | 138 | case 'w': |
nightseas | 0:3dac4f477e98 | 139 | DebugFunc_WiFi(); |
nightseas | 1:0c1053275589 | 140 | break; |
nightseas | 1:0c1053275589 | 141 | |
nightseas | 1:0c1053275589 | 142 | case '0': |
nightseas | 1:0c1053275589 | 143 | DebugFunc_CO2(); |
nightseas | 1:0c1053275589 | 144 | DebugFunc_CH2O(); |
nightseas | 1:0c1053275589 | 145 | DebugFunc_PM25(); |
nightseas | 1:0c1053275589 | 146 | DebugFunc_TempRh(); |
nightseas | 1:0c1053275589 | 147 | DebugFunc_AirPress(); |
nightseas | 1:0c1053275589 | 148 | DebugFunc_UvLevel(); |
nightseas | 1:0c1053275589 | 149 | break; |
nightseas | 0:3dac4f477e98 | 150 | |
nightseas | 0:3dac4f477e98 | 151 | case '1': |
nightseas | 0:3dac4f477e98 | 152 | DebugFunc_CO2(); |
nightseas | 0:3dac4f477e98 | 153 | break; |
nightseas | 0:3dac4f477e98 | 154 | |
nightseas | 0:3dac4f477e98 | 155 | case '2': |
nightseas | 0:3dac4f477e98 | 156 | DebugFunc_PM25(); |
nightseas | 0:3dac4f477e98 | 157 | break; |
nightseas | 0:3dac4f477e98 | 158 | |
nightseas | 0:3dac4f477e98 | 159 | case '3': |
nightseas | 0:3dac4f477e98 | 160 | DebugFunc_CH2O(); |
nightseas | 0:3dac4f477e98 | 161 | break; |
nightseas | 0:3dac4f477e98 | 162 | |
nightseas | 0:3dac4f477e98 | 163 | case '4': |
nightseas | 0:3dac4f477e98 | 164 | DebugFunc_TempRh(); |
nightseas | 0:3dac4f477e98 | 165 | break; |
nightseas | 0:3dac4f477e98 | 166 | |
nightseas | 0:3dac4f477e98 | 167 | case '5': |
nightseas | 0:3dac4f477e98 | 168 | DebugFunc_AirPress(); |
nightseas | 0:3dac4f477e98 | 169 | break; |
nightseas | 0:3dac4f477e98 | 170 | |
nightseas | 0:3dac4f477e98 | 171 | case '6': |
nightseas | 0:3dac4f477e98 | 172 | DebugFunc_UvLevel(); |
nightseas | 0:3dac4f477e98 | 173 | break; |
nightseas | 0:3dac4f477e98 | 174 | default: |
nightseas | 0:3dac4f477e98 | 175 | uart_db.printf("Incorrect input!\n\r"); |
nightseas | 0:3dac4f477e98 | 176 | break; |
nightseas | 0:3dac4f477e98 | 177 | } |
nightseas | 0:3dac4f477e98 | 178 | |
nightseas | 0:3dac4f477e98 | 179 | uart_db.printf("\n\rPress any key...\n\r"); |
nightseas | 0:3dac4f477e98 | 180 | |
nightseas | 0:3dac4f477e98 | 181 | while(!uart_db.readable()); |
nightseas | 0:3dac4f477e98 | 182 | cmdPc = uart_db.getc(); |
nightseas | 0:3dac4f477e98 | 183 | |
nightseas | 0:3dac4f477e98 | 184 | } |
nightseas | 0:3dac4f477e98 | 185 | |
nightseas | 0:3dac4f477e98 | 186 | } |
nightseas | 0:3dac4f477e98 | 187 |