Xiaohai Li
/
AirBoxProto
Demo
PeripheralLayer/PeMod_UV370.cpp@2:0ee90da44162, 2016-05-19 (annotated)
- Committer:
- nightseas
- Date:
- Thu May 19 15:52:24 2016 +0000
- Revision:
- 2:0ee90da44162
AirBoxProtoDemo
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nightseas | 2:0ee90da44162 | 1 | #include "SysConfig.h" |
nightseas | 2:0ee90da44162 | 2 | |
nightseas | 2:0ee90da44162 | 3 | #define UV_LV_MAX 11 |
nightseas | 2:0ee90da44162 | 4 | #define UV_SMP_AVG 5 |
nightseas | 2:0ee90da44162 | 5 | const int UvLvTable[] = {50, 227, 318, 408, 503, 606, 696, 795, 881, 976, 1079, 1170}; |
nightseas | 2:0ee90da44162 | 6 | |
nightseas | 2:0ee90da44162 | 7 | #define i2c_uv i2c_sen |
nightseas | 2:0ee90da44162 | 8 | //#define uart_db uart_pc |
nightseas | 2:0ee90da44162 | 9 | |
nightseas | 2:0ee90da44162 | 10 | int UV_Init(void) |
nightseas | 2:0ee90da44162 | 11 | { |
nightseas | 2:0ee90da44162 | 12 | return 0; |
nightseas | 2:0ee90da44162 | 13 | } |
nightseas | 2:0ee90da44162 | 14 | |
nightseas | 2:0ee90da44162 | 15 | float UV_ReadVolt(void) |
nightseas | 2:0ee90da44162 | 16 | { |
nightseas | 2:0ee90da44162 | 17 | return(adc_ch10.read() * 3300); |
nightseas | 2:0ee90da44162 | 18 | } |
nightseas | 2:0ee90da44162 | 19 | |
nightseas | 2:0ee90da44162 | 20 | float UV_ReadLv(void) |
nightseas | 2:0ee90da44162 | 21 | { |
nightseas | 2:0ee90da44162 | 22 | int i; |
nightseas | 2:0ee90da44162 | 23 | float volt = 0, level; |
nightseas | 2:0ee90da44162 | 24 | for(i=0; i<UV_SMP_AVG; i++) |
nightseas | 2:0ee90da44162 | 25 | volt += UV_ReadVolt(); |
nightseas | 2:0ee90da44162 | 26 | volt = volt / UV_SMP_AVG ; |
nightseas | 2:0ee90da44162 | 27 | |
nightseas | 2:0ee90da44162 | 28 | if(volt < (float)UvLvTable[0]) |
nightseas | 2:0ee90da44162 | 29 | { |
nightseas | 2:0ee90da44162 | 30 | level = 0; |
nightseas | 2:0ee90da44162 | 31 | return level; |
nightseas | 2:0ee90da44162 | 32 | } |
nightseas | 2:0ee90da44162 | 33 | |
nightseas | 2:0ee90da44162 | 34 | if(volt > (float)UvLvTable[UV_LV_MAX]) |
nightseas | 2:0ee90da44162 | 35 | { |
nightseas | 2:0ee90da44162 | 36 | level = 11; |
nightseas | 2:0ee90da44162 | 37 | return level; |
nightseas | 2:0ee90da44162 | 38 | } |
nightseas | 2:0ee90da44162 | 39 | |
nightseas | 2:0ee90da44162 | 40 | for(i=0; i<UV_LV_MAX; i++) |
nightseas | 2:0ee90da44162 | 41 | { |
nightseas | 2:0ee90da44162 | 42 | if(volt > (float)UvLvTable[i] && volt < (float)UvLvTable[i+1]) |
nightseas | 2:0ee90da44162 | 43 | { |
nightseas | 2:0ee90da44162 | 44 | level = i + (volt - UvLvTable[i]) / (UvLvTable[i+1] - UvLvTable[i]); |
nightseas | 2:0ee90da44162 | 45 | return level; |
nightseas | 2:0ee90da44162 | 46 | } |
nightseas | 2:0ee90da44162 | 47 | } |
nightseas | 2:0ee90da44162 | 48 | |
nightseas | 2:0ee90da44162 | 49 | return -1; |
nightseas | 2:0ee90da44162 | 50 | } |