Xiaohai Li
/
AirBoxProto
Demo
AplicationLayer/DebugCommander.cpp@0:3dac4f477e98, 2015-07-08 (annotated)
- Committer:
- nightseas
- Date:
- Wed Jul 08 17:50:18 2015 +0000
- Revision:
- 0:3dac4f477e98
- Child:
- 1:0c1053275589
Basic Demo; Implement: Debug serial commander, Gas sensors, Temp&Rh sensor.
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 | 0:3dac4f477e98 | 29 | uart_db.printf("OK!\n\rCO2 Vol = %dppm.\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 | 0:3dac4f477e98 | 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 | 0:3dac4f477e98 | 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 | 0:3dac4f477e98 | 49 | cnt++; |
nightseas | 0:3dac4f477e98 | 50 | } |
nightseas | 0:3dac4f477e98 | 51 | } |
nightseas | 0:3dac4f477e98 | 52 | pm25VolAvg = pm25VolAvg / cnt_max; |
nightseas | 0:3dac4f477e98 | 53 | uart_db.printf("OK!\n\rPM2.5 Vol = %dug/m^3.\n\r", pm25VolAvg); |
nightseas | 0:3dac4f477e98 | 54 | } |
nightseas | 0:3dac4f477e98 | 55 | |
nightseas | 0:3dac4f477e98 | 56 | void DebugFunc_CH2O(void) |
nightseas | 0:3dac4f477e98 | 57 | { |
nightseas | 0:3dac4f477e98 | 58 | uart_db.printf("Reading ZE08..."); |
nightseas | 0:3dac4f477e98 | 59 | SerialMuxSel(SMUX_ZE08); |
nightseas | 0:3dac4f477e98 | 60 | int ch2oVol = ZE08_ReadCH2O(); |
nightseas | 0:3dac4f477e98 | 61 | if(ch2oVol < 0) |
nightseas | 0:3dac4f477e98 | 62 | uart_db.printf("CheckSum Error!\n\r"); |
nightseas | 0:3dac4f477e98 | 63 | else |
nightseas | 0:3dac4f477e98 | 64 | uart_db.printf("OK!\n\rCH2O Vol = %dug/m^3.\n\r", ch2oVol); |
nightseas | 0:3dac4f477e98 | 65 | } |
nightseas | 0:3dac4f477e98 | 66 | |
nightseas | 0:3dac4f477e98 | 67 | void DebugFunc_TempRh(void) |
nightseas | 0:3dac4f477e98 | 68 | { |
nightseas | 0:3dac4f477e98 | 69 | uart_db.printf("Reading SHT20..."); |
nightseas | 0:3dac4f477e98 | 70 | float temp = SHT20_ReadTemp(); |
nightseas | 0:3dac4f477e98 | 71 | float rh = SHT20_ReadRh(); |
nightseas | 0:3dac4f477e98 | 72 | uart_db.printf("OK!\n\rTemperature = %.2f, Humidity = %2.f\n\r", temp, rh); |
nightseas | 0:3dac4f477e98 | 73 | } |
nightseas | 0:3dac4f477e98 | 74 | |
nightseas | 0:3dac4f477e98 | 75 | void DebugFunc_AirPress(void) |
nightseas | 0:3dac4f477e98 | 76 | { |
nightseas | 0:3dac4f477e98 | 77 | uart_db.printf("Not implemented..."); |
nightseas | 0:3dac4f477e98 | 78 | } |
nightseas | 0:3dac4f477e98 | 79 | |
nightseas | 0:3dac4f477e98 | 80 | void DebugFunc_UvLevel(void) |
nightseas | 0:3dac4f477e98 | 81 | { |
nightseas | 0:3dac4f477e98 | 82 | uart_db.printf("Not implemented..."); |
nightseas | 0:3dac4f477e98 | 83 | } |
nightseas | 0:3dac4f477e98 | 84 | |
nightseas | 0:3dac4f477e98 | 85 | void DebugFunc_WiFi(void) |
nightseas | 0:3dac4f477e98 | 86 | { |
nightseas | 0:3dac4f477e98 | 87 | uart_db.printf("Not implemented..."); |
nightseas | 0:3dac4f477e98 | 88 | } |
nightseas | 0:3dac4f477e98 | 89 | |
nightseas | 0:3dac4f477e98 | 90 | void DebugFunc_SwitchSmux(void) |
nightseas | 0:3dac4f477e98 | 91 | { |
nightseas | 0:3dac4f477e98 | 92 | uart_db.printf("Please type SMUX channel(0~3) with ENTER.\n\r"); |
nightseas | 0:3dac4f477e98 | 93 | while(!uart_db.readable()); |
nightseas | 0:3dac4f477e98 | 94 | uint8_t ch = uart_db.getc(); |
nightseas | 0:3dac4f477e98 | 95 | SerialMuxSel(ch - '0'); |
nightseas | 0:3dac4f477e98 | 96 | uart_db.printf("Switched to ch %c.\n\r", ch); |
nightseas | 0:3dac4f477e98 | 97 | } |
nightseas | 0:3dac4f477e98 | 98 | |
nightseas | 0:3dac4f477e98 | 99 | void DebugCommander(void) |
nightseas | 0:3dac4f477e98 | 100 | { |
nightseas | 0:3dac4f477e98 | 101 | int quitFlag = 0, cmdPc; |
nightseas | 0:3dac4f477e98 | 102 | while(!quitFlag) |
nightseas | 0:3dac4f477e98 | 103 | { |
nightseas | 0:3dac4f477e98 | 104 | uart_db.printf("\n\r\n\r============ AirBox Nucleo Adaptor Demo ============\n\r\n\r"); |
nightseas | 0:3dac4f477e98 | 105 | uart_db.printf(" 0. All sensors auto Test.\n\r"); |
nightseas | 0:3dac4f477e98 | 106 | uart_db.printf(" 1. Test CO2 gas sensor.\n\r"); |
nightseas | 0:3dac4f477e98 | 107 | uart_db.printf(" 2. Test PM2.5 dust sensor.\n\r"); |
nightseas | 0:3dac4f477e98 | 108 | uart_db.printf(" 3. Test CH2O gas sensor.\n\r"); |
nightseas | 0:3dac4f477e98 | 109 | uart_db.printf(" 4. Test temperature & humidity sensor.\n\r"); |
nightseas | 0:3dac4f477e98 | 110 | uart_db.printf(" 5. Test air pressure sensor.\n\r"); |
nightseas | 0:3dac4f477e98 | 111 | uart_db.printf(" 6. Test UV light level.\n\r"); |
nightseas | 0:3dac4f477e98 | 112 | uart_db.printf(" w. Test WiFi module.\n\r"); |
nightseas | 0:3dac4f477e98 | 113 | uart_db.printf(" m. Manual switch SMUX channel.\n\r"); |
nightseas | 0:3dac4f477e98 | 114 | uart_db.printf(" q. Exit demo.\n\r\n\r"); |
nightseas | 0:3dac4f477e98 | 115 | |
nightseas | 0:3dac4f477e98 | 116 | while(!uart_db.readable()) |
nightseas | 0:3dac4f477e98 | 117 | { |
nightseas | 0:3dac4f477e98 | 118 | #if 0 |
nightseas | 0:3dac4f477e98 | 119 | if(uart_sen.readable()) |
nightseas | 0:3dac4f477e98 | 120 | uart_db.printf(" <0x%02X> ", uart_sen.getc()); |
nightseas | 0:3dac4f477e98 | 121 | #endif |
nightseas | 0:3dac4f477e98 | 122 | } |
nightseas | 0:3dac4f477e98 | 123 | cmdPc = uart_db.getc(); |
nightseas | 0:3dac4f477e98 | 124 | |
nightseas | 0:3dac4f477e98 | 125 | switch(cmdPc) |
nightseas | 0:3dac4f477e98 | 126 | { |
nightseas | 0:3dac4f477e98 | 127 | case 'q': |
nightseas | 0:3dac4f477e98 | 128 | quitFlag = 1; |
nightseas | 0:3dac4f477e98 | 129 | uart_db.printf("\n\rExiting demo...\n\r"); |
nightseas | 0:3dac4f477e98 | 130 | break; |
nightseas | 0:3dac4f477e98 | 131 | |
nightseas | 0:3dac4f477e98 | 132 | case 'm': |
nightseas | 0:3dac4f477e98 | 133 | DebugFunc_SwitchSmux(); |
nightseas | 0:3dac4f477e98 | 134 | break; |
nightseas | 0:3dac4f477e98 | 135 | |
nightseas | 0:3dac4f477e98 | 136 | case 'w': |
nightseas | 0:3dac4f477e98 | 137 | DebugFunc_WiFi(); |
nightseas | 0:3dac4f477e98 | 138 | break; |
nightseas | 0:3dac4f477e98 | 139 | |
nightseas | 0:3dac4f477e98 | 140 | case '1': |
nightseas | 0:3dac4f477e98 | 141 | DebugFunc_CO2(); |
nightseas | 0:3dac4f477e98 | 142 | break; |
nightseas | 0:3dac4f477e98 | 143 | |
nightseas | 0:3dac4f477e98 | 144 | case '2': |
nightseas | 0:3dac4f477e98 | 145 | DebugFunc_PM25(); |
nightseas | 0:3dac4f477e98 | 146 | break; |
nightseas | 0:3dac4f477e98 | 147 | |
nightseas | 0:3dac4f477e98 | 148 | case '3': |
nightseas | 0:3dac4f477e98 | 149 | DebugFunc_CH2O(); |
nightseas | 0:3dac4f477e98 | 150 | break; |
nightseas | 0:3dac4f477e98 | 151 | |
nightseas | 0:3dac4f477e98 | 152 | case '4': |
nightseas | 0:3dac4f477e98 | 153 | DebugFunc_TempRh(); |
nightseas | 0:3dac4f477e98 | 154 | break; |
nightseas | 0:3dac4f477e98 | 155 | |
nightseas | 0:3dac4f477e98 | 156 | case '5': |
nightseas | 0:3dac4f477e98 | 157 | DebugFunc_AirPress(); |
nightseas | 0:3dac4f477e98 | 158 | break; |
nightseas | 0:3dac4f477e98 | 159 | |
nightseas | 0:3dac4f477e98 | 160 | case '6': |
nightseas | 0:3dac4f477e98 | 161 | DebugFunc_UvLevel(); |
nightseas | 0:3dac4f477e98 | 162 | break; |
nightseas | 0:3dac4f477e98 | 163 | default: |
nightseas | 0:3dac4f477e98 | 164 | uart_db.printf("Incorrect input!\n\r"); |
nightseas | 0:3dac4f477e98 | 165 | break; |
nightseas | 0:3dac4f477e98 | 166 | } |
nightseas | 0:3dac4f477e98 | 167 | |
nightseas | 0:3dac4f477e98 | 168 | uart_db.printf("\n\rPress any key...\n\r"); |
nightseas | 0:3dac4f477e98 | 169 | |
nightseas | 0:3dac4f477e98 | 170 | while(!uart_db.readable()); |
nightseas | 0:3dac4f477e98 | 171 | cmdPc = uart_db.getc(); |
nightseas | 0:3dac4f477e98 | 172 | |
nightseas | 0:3dac4f477e98 | 173 | } |
nightseas | 0:3dac4f477e98 | 174 | |
nightseas | 0:3dac4f477e98 | 175 | } |
nightseas | 0:3dac4f477e98 | 176 |