Dust sensor
Fork of DustSenzor by
DustSenzor.cpp@0:513b42c738f3, 2017-03-17 (annotated)
- Committer:
- mpuric
- Date:
- Fri Mar 17 17:39:39 2017 +0000
- Revision:
- 0:513b42c738f3
- Child:
- 1:c0ccd10b5a2b
proba
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mpuric | 0:513b42c738f3 | 1 | #include"mbed.h" |
mpuric | 0:513b42c738f3 | 2 | #include"DustSenzor.h" |
mpuric | 0:513b42c738f3 | 3 | |
mpuric | 0:513b42c738f3 | 4 | DustSenzor::DustSenzor(PinName txPin, PinName rxPin) : tx(txPin), rx(rxPin), tipka(p5), set(p4){ |
mpuric | 0:513b42c738f3 | 5 | provjera=false; |
mpuric | 0:513b42c738f3 | 6 | br=0; |
mpuric | 0:513b42c738f3 | 7 | set=0; |
mpuric | 0:513b42c738f3 | 8 | PM1 =0; |
mpuric | 0:513b42c738f3 | 9 | PM2_5 =0; |
mpuric | 0:513b42c738f3 | 10 | PM10 =0; |
mpuric | 0:513b42c738f3 | 11 | pm1=0; |
mpuric | 0:513b42c738f3 | 12 | pm2_5=0; |
mpuric | 0:513b42c738f3 | 13 | pm10=0; |
mpuric | 0:513b42c738f3 | 14 | uart.baud(9600); |
mpuric | 0:513b42c738f3 | 15 | uart.format(8,SerialBase::None,1); |
mpuric | 0:513b42c738f3 | 16 | uart.attach(&DustSenzor::mbedTOSenzor,Serial::RxIrq); |
mpuric | 0:513b42c738f3 | 17 | debounce.start(); |
mpuric | 0:513b42c738f3 | 18 | while(1){ |
mpuric | 0:513b42c738f3 | 19 | if(br==32){ |
mpuric | 0:513b42c738f3 | 20 | DustSenzor::Racunanje(); |
mpuric | 0:513b42c738f3 | 21 | } |
mpuric | 0:513b42c738f3 | 22 | } |
mpuric | 0:513b42c738f3 | 23 | } |
mpuric | 0:513b42c738f3 | 24 | |
mpuric | 0:513b42c738f3 | 25 | void DustSenzor::mbedTOSenzor(){ |
mpuric | 0:513b42c738f3 | 26 | buff[br]=uart.getc(); |
mpuric | 0:513b42c738f3 | 27 | br++; |
mpuric | 0:513b42c738f3 | 28 | } |
mpuric | 0:513b42c738f3 | 29 | |
mpuric | 0:513b42c738f3 | 30 | // concentration unit μg/m3(CF=1,standard particle) |
mpuric | 0:513b42c738f3 | 31 | int DustSenzor::posalji_PM1(unsigned char *thebuff){ |
mpuric | 0:513b42c738f3 | 32 | int PM1Val; |
mpuric | 0:513b42c738f3 | 33 | PM1Val= thebuff[5]|thebuff[4]<<8; |
mpuric | 0:513b42c738f3 | 34 | return PM1Val; |
mpuric | 0:513b42c738f3 | 35 | } |
mpuric | 0:513b42c738f3 | 36 | |
mpuric | 0:513b42c738f3 | 37 | int DustSenzor::posalji_PM2_5(unsigned char *thebuff){ |
mpuric | 0:513b42c738f3 | 38 | int PM2_5Val; |
mpuric | 0:513b42c738f3 | 39 | PM2_5Val= thebuff[7]|thebuff[6]<<8; |
mpuric | 0:513b42c738f3 | 40 | return PM2_5Val; |
mpuric | 0:513b42c738f3 | 41 | } |
mpuric | 0:513b42c738f3 | 42 | |
mpuric | 0:513b42c738f3 | 43 | int DustSenzor::posalji_PM10(unsigned char *thebuff){ |
mpuric | 0:513b42c738f3 | 44 | int PM10Val; |
mpuric | 0:513b42c738f3 | 45 | PM10Val= thebuff[9]|thebuff[8]<<8; |
mpuric | 0:513b42c738f3 | 46 | return PM10Val; |
mpuric | 0:513b42c738f3 | 47 | } |
mpuric | 0:513b42c738f3 | 48 | |
mpuric | 0:513b42c738f3 | 49 | // Koliko ima čestica u 0.1 L zraka |
mpuric | 0:513b42c738f3 | 50 | float DustSenzor::posalji_pm1(unsigned char *thebuff){ |
mpuric | 0:513b42c738f3 | 51 | float pm1Val; |
mpuric | 0:513b42c738f3 | 52 | pm1Val= thebuff[17]|thebuff[16]<<8; |
mpuric | 0:513b42c738f3 | 53 | return pm1Val; |
mpuric | 0:513b42c738f3 | 54 | } |
mpuric | 0:513b42c738f3 | 55 | |
mpuric | 0:513b42c738f3 | 56 | float DustSenzor::posalji_pm2_5(unsigned char *thebuff){ |
mpuric | 0:513b42c738f3 | 57 | float pm2_5Val; |
mpuric | 0:513b42c738f3 | 58 | pm2_5Val= thebuff[19]|thebuff[18]<<8; |
mpuric | 0:513b42c738f3 | 59 | return pm2_5Val; |
mpuric | 0:513b42c738f3 | 60 | } |
mpuric | 0:513b42c738f3 | 61 | |
mpuric | 0:513b42c738f3 | 62 | float DustSenzor::posalji_pm10(unsigned char *thebuff){ |
mpuric | 0:513b42c738f3 | 63 | float pm10Val; |
mpuric | 0:513b42c738f3 | 64 | pm10Val= thebuff[21]|thebuff[20]<<8; |
mpuric | 0:513b42c738f3 | 65 | return pm10Val; |
mpuric | 0:513b42c738f3 | 66 | } |
mpuric | 0:513b42c738f3 | 67 | |
mpuric | 0:513b42c738f3 | 68 | void DustSenzor::ispis(){ |
mpuric | 0:513b42c738f3 | 69 | //pc.printf("\n PM1 = %d \n PM2_5 = %d \n PM10 = %d \n",PM1,PM2_5,PM10); |
mpuric | 0:513b42c738f3 | 70 | //pc.printf("\n PM1 = %d \n PM2_5 = %d \n PM10 = %d \n u metru kubnom ",pm1*10000,pm2_5*10000,pm10*10000); |
mpuric | 0:513b42c738f3 | 71 | //for( int i=0;i<32;i++) |
mpuric | 0:513b42c738f3 | 72 | //pc.printf("\n 0%x ", buff[i]); |
mpuric | 0:513b42c738f3 | 73 | } |
mpuric | 0:513b42c738f3 | 74 | |
mpuric | 0:513b42c738f3 | 75 | |
mpuric | 0:513b42c738f3 | 76 | void DustSenzor::Racunanje(){ |
mpuric | 0:513b42c738f3 | 77 | if(buff[0]==0x42){ |
mpuric | 0:513b42c738f3 | 78 | if(buff[1]==0x4d){ |
mpuric | 0:513b42c738f3 | 79 | PM1 =DustSenzor::posalji_PM1(&buff); |
mpuric | 0:513b42c738f3 | 80 | PM2_5=DustSenzor::posalji_PM2_5(buff); |
mpuric | 0:513b42c738f3 | 81 | PM10 =DustSenzor::posalji_PM10(buff); |
mpuric | 0:513b42c738f3 | 82 | |
mpuric | 0:513b42c738f3 | 83 | pm1=DustSenzor::posalji_pm1(buff); |
mpuric | 0:513b42c738f3 | 84 | pm2_5=DustSenzor::posalji_pm2_5(buff); |
mpuric | 0:513b42c738f3 | 85 | pm10=DustSenzor::posalji_pm10(buff); |
mpuric | 0:513b42c738f3 | 86 | br=0; |
mpuric | 0:513b42c738f3 | 87 | ispis(); |
mpuric | 0:513b42c738f3 | 88 | } |
mpuric | 0:513b42c738f3 | 89 | } |
mpuric | 0:513b42c738f3 | 90 | } |
mpuric | 0:513b42c738f3 | 91 |