teste de publish
Dependencies: DS1820 HighSpeedAnalogIn devices mbed
IRPack.cpp@0:1c0a769988ee, 2017-03-24 (annotated)
- Committer:
- brunofgc
- Date:
- Fri Mar 24 15:54:41 2017 +0000
- Revision:
- 0:1c0a769988ee
- Child:
- 2:55b7b466e742
Saidas digitais com pwm ok, entradas analogicas ok
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
brunofgc | 0:1c0a769988ee | 1 | #include "IRPack.h" |
brunofgc | 0:1c0a769988ee | 2 | //bool dataIn[maxBytesMsg*8]; |
brunofgc | 0:1c0a769988ee | 3 | uint16_t bits[maxBitsMsg*2][2]; |
brunofgc | 0:1c0a769988ee | 4 | int index=0,botao; |
brunofgc | 0:1c0a769988ee | 5 | int startBitAlto=0, startBitBaixo=0, bitBaixo[maxBitsMsg], bitAlto[maxBitsMsg], i; |
brunofgc | 0:1c0a769988ee | 6 | //unsigned char byte=0,msg[maxBytesMsg],msgBytes=0; |
brunofgc | 0:1c0a769988ee | 7 | |
brunofgc | 0:1c0a769988ee | 8 | Timer IrTmr; |
brunofgc | 0:1c0a769988ee | 9 | Timer IrDetect; |
brunofgc | 0:1c0a769988ee | 10 | bool irInAntes=1; |
brunofgc | 0:1c0a769988ee | 11 | CircularBuffer bufIROut(maxBitsMsg*2*4); |
brunofgc | 0:1c0a769988ee | 12 | |
brunofgc | 0:1c0a769988ee | 13 | //PwmOut IrOut(P1_18); |
brunofgc | 0:1c0a769988ee | 14 | DigitalIn IrIn(P1_24); //Não utilizado na placa |
brunofgc | 0:1c0a769988ee | 15 | |
brunofgc | 0:1c0a769988ee | 16 | int round(float in){ |
brunofgc | 0:1c0a769988ee | 17 | int x = floor(in); |
brunofgc | 0:1c0a769988ee | 18 | float y = in-x; |
brunofgc | 0:1c0a769988ee | 19 | if(y>=0.5){ |
brunofgc | 0:1c0a769988ee | 20 | x++; |
brunofgc | 0:1c0a769988ee | 21 | } |
brunofgc | 0:1c0a769988ee | 22 | return x; |
brunofgc | 0:1c0a769988ee | 23 | } |
brunofgc | 0:1c0a769988ee | 24 | |
brunofgc | 0:1c0a769988ee | 25 | uint16_t pulseDuration_us(bool high,DigitalIn pin,unsigned long int timeout){ |
brunofgc | 0:1c0a769988ee | 26 | unsigned long int duration; |
brunofgc | 0:1c0a769988ee | 27 | IrTmr.reset(); |
brunofgc | 0:1c0a769988ee | 28 | IrTmr.start(); |
brunofgc | 0:1c0a769988ee | 29 | |
brunofgc | 0:1c0a769988ee | 30 | do{ |
brunofgc | 0:1c0a769988ee | 31 | duration = IrTmr.read_us(); |
brunofgc | 0:1c0a769988ee | 32 | }while((duration < timeout) && (pin==high)); |
brunofgc | 0:1c0a769988ee | 33 | |
brunofgc | 0:1c0a769988ee | 34 | |
brunofgc | 0:1c0a769988ee | 35 | IrTmr.stop(); |
brunofgc | 0:1c0a769988ee | 36 | if(duration < timeout){ |
brunofgc | 0:1c0a769988ee | 37 | return duration; |
brunofgc | 0:1c0a769988ee | 38 | } |
brunofgc | 0:1c0a769988ee | 39 | else{ |
brunofgc | 0:1c0a769988ee | 40 | return 65535; |
brunofgc | 0:1c0a769988ee | 41 | } |
brunofgc | 0:1c0a769988ee | 42 | } |
brunofgc | 0:1c0a769988ee | 43 | |
brunofgc | 0:1c0a769988ee | 44 | |
brunofgc | 0:1c0a769988ee | 45 | |
brunofgc | 0:1c0a769988ee | 46 | void enviaComandoIR(uint8_t freq,uint8_t port){ |
brunofgc | 0:1c0a769988ee | 47 | float sd1Duty = SD1.read(); |
brunofgc | 0:1c0a769988ee | 48 | float sd2Duty = SD2.read(); |
brunofgc | 0:1c0a769988ee | 49 | float sd3Duty = SD3.read(); |
brunofgc | 0:1c0a769988ee | 50 | float sd4Duty = SD4.read(); |
brunofgc | 0:1c0a769988ee | 51 | float sd5Duty = SD5.read(); |
brunofgc | 0:1c0a769988ee | 52 | float sd6Duty = SD6.read(); |
brunofgc | 0:1c0a769988ee | 53 | |
brunofgc | 0:1c0a769988ee | 54 | PwmOut *SD; |
brunofgc | 0:1c0a769988ee | 55 | |
brunofgc | 0:1c0a769988ee | 56 | switch(port){ |
brunofgc | 0:1c0a769988ee | 57 | case 0: |
brunofgc | 0:1c0a769988ee | 58 | SD = &SD1; |
brunofgc | 0:1c0a769988ee | 59 | break; |
brunofgc | 0:1c0a769988ee | 60 | case 1: |
brunofgc | 0:1c0a769988ee | 61 | SD = &SD2; |
brunofgc | 0:1c0a769988ee | 62 | break; |
brunofgc | 0:1c0a769988ee | 63 | case 2: |
brunofgc | 0:1c0a769988ee | 64 | SD = &SD3; |
brunofgc | 0:1c0a769988ee | 65 | break; |
brunofgc | 0:1c0a769988ee | 66 | case 3: |
brunofgc | 0:1c0a769988ee | 67 | SD = &SD4; |
brunofgc | 0:1c0a769988ee | 68 | break; |
brunofgc | 0:1c0a769988ee | 69 | case 4: |
brunofgc | 0:1c0a769988ee | 70 | SD = &SD5; |
brunofgc | 0:1c0a769988ee | 71 | break; |
brunofgc | 0:1c0a769988ee | 72 | case 5: |
brunofgc | 0:1c0a769988ee | 73 | SD = &SD6; |
brunofgc | 0:1c0a769988ee | 74 | break; |
brunofgc | 0:1c0a769988ee | 75 | } |
brunofgc | 0:1c0a769988ee | 76 | |
brunofgc | 0:1c0a769988ee | 77 | SD1.write(0.0f); |
brunofgc | 0:1c0a769988ee | 78 | SD2.write(0.0f); |
brunofgc | 0:1c0a769988ee | 79 | SD3.write(0.0f); |
brunofgc | 0:1c0a769988ee | 80 | SD4.write(0.0f); |
brunofgc | 0:1c0a769988ee | 81 | SD5.write(0.0f); |
brunofgc | 0:1c0a769988ee | 82 | SD6.write(0.0f); |
brunofgc | 0:1c0a769988ee | 83 | |
brunofgc | 0:1c0a769988ee | 84 | SD->period(1.0/(freq*1000.0)); |
brunofgc | 0:1c0a769988ee | 85 | SD->write(0.5); |
brunofgc | 0:1c0a769988ee | 86 | if(startBitAlto!=65535){wait_us(startBitAlto);} |
brunofgc | 0:1c0a769988ee | 87 | SD->write(0.0); |
brunofgc | 0:1c0a769988ee | 88 | if(startBitBaixo!=65535){wait_us(startBitBaixo);} |
brunofgc | 0:1c0a769988ee | 89 | for(i=0;i<index;i++){ |
brunofgc | 0:1c0a769988ee | 90 | SD->write(0.5); |
brunofgc | 0:1c0a769988ee | 91 | if(bitAlto[i]!=65535){wait_us(bits[i][0]);} |
brunofgc | 0:1c0a769988ee | 92 | SD->write(0.0); |
brunofgc | 0:1c0a769988ee | 93 | if(bitBaixo[i]!=65535){wait_us(bits[i][1]);} |
brunofgc | 0:1c0a769988ee | 94 | } |
brunofgc | 0:1c0a769988ee | 95 | |
brunofgc | 0:1c0a769988ee | 96 | SD1.period_us(pwmPeriod); |
brunofgc | 0:1c0a769988ee | 97 | SD1.write(sd1Duty); |
brunofgc | 0:1c0a769988ee | 98 | SD2.write(sd2Duty); |
brunofgc | 0:1c0a769988ee | 99 | SD3.write(sd3Duty); |
brunofgc | 0:1c0a769988ee | 100 | SD4.write(sd4Duty); |
brunofgc | 0:1c0a769988ee | 101 | SD5.write(sd5Duty); |
brunofgc | 0:1c0a769988ee | 102 | SD6.write(sd6Duty); |
brunofgc | 0:1c0a769988ee | 103 | } |
brunofgc | 0:1c0a769988ee | 104 | |
brunofgc | 0:1c0a769988ee | 105 | |
brunofgc | 0:1c0a769988ee | 106 | static const long hextable[] = { |
brunofgc | 0:1c0a769988ee | 107 | [0 ... 255] = -1, // bit aligned access into this table is considerably |
brunofgc | 0:1c0a769988ee | 108 | ['0'] = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, // faster for most modern processors, |
brunofgc | 0:1c0a769988ee | 109 | ['A'] = 10, 11, 12, 13, 14, 15, // for the space conscious, reduce to |
brunofgc | 0:1c0a769988ee | 110 | ['a'] = 10, 11, 12, 13, 14, 15 // signed char. |
brunofgc | 0:1c0a769988ee | 111 | }; |
brunofgc | 0:1c0a769988ee | 112 | |
brunofgc | 0:1c0a769988ee | 113 | uint16_t hexdec(char *hex,uint16_t tam) { |
brunofgc | 0:1c0a769988ee | 114 | uint16_t ret = 0; |
brunofgc | 0:1c0a769988ee | 115 | uint16_t i; |
brunofgc | 0:1c0a769988ee | 116 | for(i=0;i<tam;i++){ |
brunofgc | 0:1c0a769988ee | 117 | ret += hextable[hex[i]] << (i*4); |
brunofgc | 0:1c0a769988ee | 118 | } |
brunofgc | 0:1c0a769988ee | 119 | return ret; |
brunofgc | 0:1c0a769988ee | 120 | } |
brunofgc | 0:1c0a769988ee | 121 | |
brunofgc | 0:1c0a769988ee | 122 | |
brunofgc | 0:1c0a769988ee | 123 | void deserializaPacoteIR(char *str){ |
brunofgc | 0:1c0a769988ee | 124 | uint16_t len; |
brunofgc | 0:1c0a769988ee | 125 | uint16_t i; |
brunofgc | 0:1c0a769988ee | 126 | len = strlen(str); |
brunofgc | 0:1c0a769988ee | 127 | len = len/4; //Separando de quatro em quatro pra formar um uint16_t |
brunofgc | 0:1c0a769988ee | 128 | //printf("%lu bits\n",len/2); |
brunofgc | 0:1c0a769988ee | 129 | for(i=0;i<len;i++){ |
brunofgc | 0:1c0a769988ee | 130 | bits[i/2][(i%2)]=hexdec(&str[i*4],4); |
brunofgc | 0:1c0a769988ee | 131 | } |
brunofgc | 0:1c0a769988ee | 132 | /*for(i=0;i<len;i++){ |
brunofgc | 0:1c0a769988ee | 133 | printf("bits[%u][%u]=%lu\n",i/2,(i%2),bits[i/2][(i%2)]); |
brunofgc | 0:1c0a769988ee | 134 | }*/ |
brunofgc | 0:1c0a769988ee | 135 | index = len/2; |
brunofgc | 0:1c0a769988ee | 136 | } |
brunofgc | 0:1c0a769988ee | 137 | |
brunofgc | 0:1c0a769988ee | 138 | void serializaPacoteIR(uint8_t connectionID){ |
brunofgc | 0:1c0a769988ee | 139 | char aux[20]; |
brunofgc | 0:1c0a769988ee | 140 | uint32_t length; |
brunofgc | 0:1c0a769988ee | 141 | char *ptr; |
brunofgc | 0:1c0a769988ee | 142 | uint16_t i; |
brunofgc | 0:1c0a769988ee | 143 | union{ |
brunofgc | 0:1c0a769988ee | 144 | char c[2]; |
brunofgc | 0:1c0a769988ee | 145 | uint16_t v; |
brunofgc | 0:1c0a769988ee | 146 | }u; |
brunofgc | 0:1c0a769988ee | 147 | sdCardBuf.del(); |
brunofgc | 0:1c0a769988ee | 148 | sprintf(aux,"callback({\"response\":\""); |
brunofgc | 0:1c0a769988ee | 149 | sdCardBuf.fill(aux,strlen(aux)); |
brunofgc | 0:1c0a769988ee | 150 | for(i=0;i<index;i++){ |
brunofgc | 0:1c0a769988ee | 151 | u.v = bits[i][0]; |
brunofgc | 0:1c0a769988ee | 152 | sprintf(aux,"%01X%01X%01X%01X" |
brunofgc | 0:1c0a769988ee | 153 | ,u.c[0]&0xF |
brunofgc | 0:1c0a769988ee | 154 | ,u.c[0]>>4 |
brunofgc | 0:1c0a769988ee | 155 | ,u.c[1]&0xF |
brunofgc | 0:1c0a769988ee | 156 | ,u.c[1]>>4 |
brunofgc | 0:1c0a769988ee | 157 | ); |
brunofgc | 0:1c0a769988ee | 158 | sdCardBuf.fill(aux,strlen(aux)); |
brunofgc | 0:1c0a769988ee | 159 | |
brunofgc | 0:1c0a769988ee | 160 | u.v = bits[i][1]; |
brunofgc | 0:1c0a769988ee | 161 | sprintf(aux,"%01X%01X%01X%01X" |
brunofgc | 0:1c0a769988ee | 162 | ,u.c[0]&0xF |
brunofgc | 0:1c0a769988ee | 163 | ,u.c[0]>>4 |
brunofgc | 0:1c0a769988ee | 164 | ,u.c[1]&0xF |
brunofgc | 0:1c0a769988ee | 165 | ,u.c[1]>>4 |
brunofgc | 0:1c0a769988ee | 166 | ); |
brunofgc | 0:1c0a769988ee | 167 | sdCardBuf.fill(aux,strlen(aux)); |
brunofgc | 0:1c0a769988ee | 168 | } |
brunofgc | 0:1c0a769988ee | 169 | sprintf(aux,"\"})"); |
brunofgc | 0:1c0a769988ee | 170 | sdCardBuf.fill(aux,strlen(aux)); |
brunofgc | 0:1c0a769988ee | 171 | length = sdCardBuf.getLength(); |
brunofgc | 0:1c0a769988ee | 172 | ptr = sdCardBuf.get(); |
brunofgc | 0:1c0a769988ee | 173 | modemCom::cipSend(connID,ptr,length); |
brunofgc | 0:1c0a769988ee | 174 | } |
brunofgc | 0:1c0a769988ee | 175 | |
brunofgc | 0:1c0a769988ee | 176 | bool detectaIRIn(){ |
brunofgc | 0:1c0a769988ee | 177 | bool detectado=0; |
brunofgc | 0:1c0a769988ee | 178 | if((irInAntes!=IrIn) && (!IrIn)){ |
brunofgc | 0:1c0a769988ee | 179 | bits[0][0] = pulseDuration_us(0,IrIn,10000); |
brunofgc | 0:1c0a769988ee | 180 | bits[0][1] = pulseDuration_us(1,IrIn,10000); |
brunofgc | 0:1c0a769988ee | 181 | if((bits[0][0]>1000)&&(bits[0][1]>1000)){ |
brunofgc | 0:1c0a769988ee | 182 | index = 1; |
brunofgc | 0:1c0a769988ee | 183 | do{ |
brunofgc | 0:1c0a769988ee | 184 | bits[index][0] = pulseDuration_us(0,IrIn,10000); |
brunofgc | 0:1c0a769988ee | 185 | bits[index][1] = pulseDuration_us(1,IrIn,10000); |
brunofgc | 0:1c0a769988ee | 186 | index++; |
brunofgc | 0:1c0a769988ee | 187 | |
brunofgc | 0:1c0a769988ee | 188 | }while((bits[index-1][0]!=65535)&&(bits[index-1][1]!=65535)); |
brunofgc | 0:1c0a769988ee | 189 | detectado=1; |
brunofgc | 0:1c0a769988ee | 190 | } |
brunofgc | 0:1c0a769988ee | 191 | } |
brunofgc | 0:1c0a769988ee | 192 | irInAntes = IrIn; |
brunofgc | 0:1c0a769988ee | 193 | led2 = !IrIn; |
brunofgc | 0:1c0a769988ee | 194 | return detectado; |
brunofgc | 0:1c0a769988ee | 195 | } |
brunofgc | 0:1c0a769988ee | 196 | |
brunofgc | 0:1c0a769988ee | 197 | void pesquisaIRIn(){ |
brunofgc | 0:1c0a769988ee | 198 | if((irInAntes!=IrIn) && (!IrIn)){ |
brunofgc | 0:1c0a769988ee | 199 | startBitAlto = pulseDuration_us(0,IrIn,10000); |
brunofgc | 0:1c0a769988ee | 200 | startBitBaixo = pulseDuration_us(1,IrIn,10000); |
brunofgc | 0:1c0a769988ee | 201 | if((startBitAlto>1000)&&(startBitBaixo>1000)){ |
brunofgc | 0:1c0a769988ee | 202 | index = 0; |
brunofgc | 0:1c0a769988ee | 203 | do{ |
brunofgc | 0:1c0a769988ee | 204 | bitAlto[index] = pulseDuration_us(0,IrIn,10000); |
brunofgc | 0:1c0a769988ee | 205 | bitBaixo[index] = pulseDuration_us(1,IrIn,10000); |
brunofgc | 0:1c0a769988ee | 206 | //dataIn[index] = (bitBaixo[index] > 1000); |
brunofgc | 0:1c0a769988ee | 207 | index++; |
brunofgc | 0:1c0a769988ee | 208 | |
brunofgc | 0:1c0a769988ee | 209 | }while((bitAlto[index-1]!=(-1))&&(bitBaixo[index-1]!=(-1))); |
brunofgc | 0:1c0a769988ee | 210 | |
brunofgc | 0:1c0a769988ee | 211 | pc.printf("Capturado um quadro com %lu bits. sbH %ld, sbL %ld <",index,startBitAlto, startBitBaixo); |
brunofgc | 0:1c0a769988ee | 212 | for(i=0;i<(index);i++){ |
brunofgc | 0:1c0a769988ee | 213 | pc.printf("[H%ld L%ld] ",bitAlto[i],bitBaixo[i]); |
brunofgc | 0:1c0a769988ee | 214 | } |
brunofgc | 0:1c0a769988ee | 215 | pc.printf(">.\n\n"); |
brunofgc | 0:1c0a769988ee | 216 | |
brunofgc | 0:1c0a769988ee | 217 | /*pc.printf("%lu bits 0b",index); |
brunofgc | 0:1c0a769988ee | 218 | for(i=0;i<index;i++){ |
brunofgc | 0:1c0a769988ee | 219 | pc.printf("%u",dataIn[i]); |
brunofgc | 0:1c0a769988ee | 220 | } |
brunofgc | 0:1c0a769988ee | 221 | pc.printf("\n\n");*/ |
brunofgc | 0:1c0a769988ee | 222 | |
brunofgc | 0:1c0a769988ee | 223 | /*//Montando os bytes; |
brunofgc | 0:1c0a769988ee | 224 | byte=0; |
brunofgc | 0:1c0a769988ee | 225 | msgBytes=0; |
brunofgc | 0:1c0a769988ee | 226 | for(i=0;i<=index;i++){ |
brunofgc | 0:1c0a769988ee | 227 | if((i!=0)&&((i%8) == 0)){ |
brunofgc | 0:1c0a769988ee | 228 | msg[msgBytes]=byte; |
brunofgc | 0:1c0a769988ee | 229 | msgBytes++; |
brunofgc | 0:1c0a769988ee | 230 | byte=0; |
brunofgc | 0:1c0a769988ee | 231 | } |
brunofgc | 0:1c0a769988ee | 232 | byte+= dataIn[i]<<(i%8); |
brunofgc | 0:1c0a769988ee | 233 | |
brunofgc | 0:1c0a769988ee | 234 | } |
brunofgc | 0:1c0a769988ee | 235 | |
brunofgc | 0:1c0a769988ee | 236 | //Exibindo pacote |
brunofgc | 0:1c0a769988ee | 237 | pc.printf("Resultado 0x"); |
brunofgc | 0:1c0a769988ee | 238 | for(i=0;i<msgBytes;i++){ |
brunofgc | 0:1c0a769988ee | 239 | pc.printf("%02X",msg[i]); |
brunofgc | 0:1c0a769988ee | 240 | } |
brunofgc | 0:1c0a769988ee | 241 | pc.printf("\n\n"); |
brunofgc | 0:1c0a769988ee | 242 | |
brunofgc | 0:1c0a769988ee | 243 | //Atuando nos leds |
brunofgc | 0:1c0a769988ee | 244 | botao=0; |
brunofgc | 0:1c0a769988ee | 245 | for(i=0;i<msgBytes;i++){ |
brunofgc | 0:1c0a769988ee | 246 | botao+=msg[i]<<(8*i); |
brunofgc | 0:1c0a769988ee | 247 | |
brunofgc | 0:1c0a769988ee | 248 | } |
brunofgc | 0:1c0a769988ee | 249 | //pc.printf("Botao pressionado %X\n",botao); |
brunofgc | 0:1c0a769988ee | 250 | switch(botao){ |
brunofgc | 0:1c0a769988ee | 251 | case 0xfb040707: //1 |
brunofgc | 0:1c0a769988ee | 252 | led2=1; |
brunofgc | 0:1c0a769988ee | 253 | break; |
brunofgc | 0:1c0a769988ee | 254 | case 0xfa050707: //2 |
brunofgc | 0:1c0a769988ee | 255 | led3=1; |
brunofgc | 0:1c0a769988ee | 256 | break; |
brunofgc | 0:1c0a769988ee | 257 | case 0xf9060707: //3 |
brunofgc | 0:1c0a769988ee | 258 | led4=1; |
brunofgc | 0:1c0a769988ee | 259 | break; |
brunofgc | 0:1c0a769988ee | 260 | case 0xf7080707: //4 |
brunofgc | 0:1c0a769988ee | 261 | led2=0; |
brunofgc | 0:1c0a769988ee | 262 | break; |
brunofgc | 0:1c0a769988ee | 263 | case 0xf6090707: //5 |
brunofgc | 0:1c0a769988ee | 264 | led3=0; |
brunofgc | 0:1c0a769988ee | 265 | break; |
brunofgc | 0:1c0a769988ee | 266 | case 0xf50a0707: //6 |
brunofgc | 0:1c0a769988ee | 267 | led4=0; |
brunofgc | 0:1c0a769988ee | 268 | break; |
brunofgc | 0:1c0a769988ee | 269 | }*/ |
brunofgc | 0:1c0a769988ee | 270 | //descritorPacoteIR(int startBitAlto, int startBitBaixo, int *bitAlto, int *bitBaixo, int numBits) |
brunofgc | 0:1c0a769988ee | 271 | //descritorPacoteIR(startBitAlto,startBitBaixo,bitAlto,bitBaixo,index); |
brunofgc | 0:1c0a769988ee | 272 | } |
brunofgc | 0:1c0a769988ee | 273 | } |
brunofgc | 0:1c0a769988ee | 274 | irInAntes = IrIn; |
brunofgc | 0:1c0a769988ee | 275 | led2 = !IrIn; |
brunofgc | 0:1c0a769988ee | 276 | } |
brunofgc | 0:1c0a769988ee | 277 | |
brunofgc | 0:1c0a769988ee | 278 | /* |
brunofgc | 0:1c0a769988ee | 279 | |
brunofgc | 0:1c0a769988ee | 280 | float razaoBit(int iH, int iL){ |
brunofgc | 0:1c0a769988ee | 281 | float H=(float)iH,L=(float)iL; |
brunofgc | 0:1c0a769988ee | 282 | float razao = L/H; |
brunofgc | 0:1c0a769988ee | 283 | |
brunofgc | 0:1c0a769988ee | 284 | if(razao>=1){ |
brunofgc | 0:1c0a769988ee | 285 | return (float) round(razao); |
brunofgc | 0:1c0a769988ee | 286 | }else if(razao>=0.5){ |
brunofgc | 0:1c0a769988ee | 287 | return 0.5; |
brunofgc | 0:1c0a769988ee | 288 | }else if(razao>=0.25){ |
brunofgc | 0:1c0a769988ee | 289 | return 0.25; |
brunofgc | 0:1c0a769988ee | 290 | }else if(razao>=0.125){ |
brunofgc | 0:1c0a769988ee | 291 | return 0.125; |
brunofgc | 0:1c0a769988ee | 292 | }else{ |
brunofgc | 0:1c0a769988ee | 293 | return -1; |
brunofgc | 0:1c0a769988ee | 294 | } |
brunofgc | 0:1c0a769988ee | 295 | |
brunofgc | 0:1c0a769988ee | 296 | } |
brunofgc | 0:1c0a769988ee | 297 | |
brunofgc | 0:1c0a769988ee | 298 | void descritorPacoteIR(int startBitAlto, int startBitBaixo, int *bitAlto, int *bitBaixo, int numBits){ |
brunofgc | 0:1c0a769988ee | 299 | unsigned int razao_maiorQue4=0; |
brunofgc | 0:1c0a769988ee | 300 | unsigned int razao_4=0; |
brunofgc | 0:1c0a769988ee | 301 | unsigned int razao_3=0; |
brunofgc | 0:1c0a769988ee | 302 | unsigned int razao_2=0; |
brunofgc | 0:1c0a769988ee | 303 | unsigned int razao_1=0; |
brunofgc | 0:1c0a769988ee | 304 | unsigned int razao_0_5=0; |
brunofgc | 0:1c0a769988ee | 305 | unsigned int razao_0_25=0; |
brunofgc | 0:1c0a769988ee | 306 | unsigned int razao_0_125=0; |
brunofgc | 0:1c0a769988ee | 307 | unsigned int razao_menorQue_0_125=0; |
brunofgc | 0:1c0a769988ee | 308 | |
brunofgc | 0:1c0a769988ee | 309 | //Indice 0 ALto, 1 Baixo; |
brunofgc | 0:1c0a769988ee | 310 | unsigned long int bitRazao_maiorQue4[2]= {0,0}; |
brunofgc | 0:1c0a769988ee | 311 | unsigned long int bitRazao_4[2]= {0,0}; |
brunofgc | 0:1c0a769988ee | 312 | unsigned long int bitRazao_3[2]= {0,0}; |
brunofgc | 0:1c0a769988ee | 313 | unsigned long int bitRazao_2[2]= {0,0}; |
brunofgc | 0:1c0a769988ee | 314 | unsigned long int bitRazao_1[2]= {0,0}; |
brunofgc | 0:1c0a769988ee | 315 | unsigned long int bitRazao_0_5[2]= {0,0}; |
brunofgc | 0:1c0a769988ee | 316 | unsigned long int bitRazao_0_25[2]= {0,0}; |
brunofgc | 0:1c0a769988ee | 317 | unsigned long int bitRazao_0_125[2]= {0,0}; |
brunofgc | 0:1c0a769988ee | 318 | unsigned long int bitRazao_menorQue_0_125[2]= {0,0}; |
brunofgc | 0:1c0a769988ee | 319 | |
brunofgc | 0:1c0a769988ee | 320 | unsigned long int indiceMaiorNEventos[2] = {0,0}; |
brunofgc | 0:1c0a769988ee | 321 | unsigned long int indiceSegundoMaiorNEventos[2] = {0,0}; |
brunofgc | 0:1c0a769988ee | 322 | |
brunofgc | 0:1c0a769988ee | 323 | |
brunofgc | 0:1c0a769988ee | 324 | |
brunofgc | 0:1c0a769988ee | 325 | unsigned int bitAlto_H=0; |
brunofgc | 0:1c0a769988ee | 326 | unsigned int bitAlto_L=0; |
brunofgc | 0:1c0a769988ee | 327 | unsigned int bitBaixo_H=0; |
brunofgc | 0:1c0a769988ee | 328 | unsigned int bitBaixo_L=0; |
brunofgc | 0:1c0a769988ee | 329 | |
brunofgc | 0:1c0a769988ee | 330 | unsigned int stopBitAlto = bitAlto[numBits-1]; |
brunofgc | 0:1c0a769988ee | 331 | |
brunofgc | 0:1c0a769988ee | 332 | int i; |
brunofgc | 0:1c0a769988ee | 333 | |
brunofgc | 0:1c0a769988ee | 334 | //printf("startBitAlto %d, startBitBaixo %d, stopBitAlto %d, stopBitBaixo %d numBits %d\n",startBitAlto,startBitBaixo,bitAlto[numBits-1],bitBaixo[numBits-1],numBits); |
brunofgc | 0:1c0a769988ee | 335 | |
brunofgc | 0:1c0a769988ee | 336 | //Despresando o stopBit pois esse já sabemos como faz |
brunofgc | 0:1c0a769988ee | 337 | for(i=0;i<numBits-1;i++){ |
brunofgc | 0:1c0a769988ee | 338 | //printf("Razao entre [L %05d e H %05d]=%1.2f\n",bitBaixo[i],bitAlto[i],razaoBit(bitAlto[i],bitBaixo[i])); |
brunofgc | 0:1c0a769988ee | 339 | //Detecção de padroes |
brunofgc | 0:1c0a769988ee | 340 | if(razaoBit(bitAlto[i],bitBaixo[i])>=4){ |
brunofgc | 0:1c0a769988ee | 341 | razao_maiorQue4++; |
brunofgc | 0:1c0a769988ee | 342 | bitRazao_maiorQue4[0]+= bitAlto[i]; |
brunofgc | 0:1c0a769988ee | 343 | bitRazao_maiorQue4[1]+=bitBaixo[i]; |
brunofgc | 0:1c0a769988ee | 344 | |
brunofgc | 0:1c0a769988ee | 345 | }else if(razaoBit(bitAlto[i],bitBaixo[i])==4){ |
brunofgc | 0:1c0a769988ee | 346 | razao_4++; |
brunofgc | 0:1c0a769988ee | 347 | bitRazao_4[0]+= bitAlto[i]; |
brunofgc | 0:1c0a769988ee | 348 | bitRazao_4[1]+=bitBaixo[i]; |
brunofgc | 0:1c0a769988ee | 349 | }else if(razaoBit(bitAlto[i],bitBaixo[i])==3){ |
brunofgc | 0:1c0a769988ee | 350 | razao_3++; |
brunofgc | 0:1c0a769988ee | 351 | bitRazao_3[0]+= bitAlto[i]; |
brunofgc | 0:1c0a769988ee | 352 | bitRazao_3[1]+=bitBaixo[i]; |
brunofgc | 0:1c0a769988ee | 353 | }else if(razaoBit(bitAlto[i],bitBaixo[i])==2){ |
brunofgc | 0:1c0a769988ee | 354 | razao_2++; |
brunofgc | 0:1c0a769988ee | 355 | bitRazao_2[0]+= bitAlto[i]; |
brunofgc | 0:1c0a769988ee | 356 | bitRazao_2[1]+=bitBaixo[i]; |
brunofgc | 0:1c0a769988ee | 357 | }else if(razaoBit(bitAlto[i],bitBaixo[i])==1){ |
brunofgc | 0:1c0a769988ee | 358 | razao_1++; |
brunofgc | 0:1c0a769988ee | 359 | bitRazao_1[0]+= bitAlto[i]; |
brunofgc | 0:1c0a769988ee | 360 | bitRazao_1[1]+=bitBaixo[i]; |
brunofgc | 0:1c0a769988ee | 361 | }else if(razaoBit(bitAlto[i],bitBaixo[i])==0.5){ |
brunofgc | 0:1c0a769988ee | 362 | razao_0_5++; |
brunofgc | 0:1c0a769988ee | 363 | bitRazao_0_5[0]+= bitAlto[i]; |
brunofgc | 0:1c0a769988ee | 364 | bitRazao_0_5[1]+=bitBaixo[i]; |
brunofgc | 0:1c0a769988ee | 365 | }else if(razaoBit(bitAlto[i],bitBaixo[i])==0.25){ |
brunofgc | 0:1c0a769988ee | 366 | razao_0_25++; |
brunofgc | 0:1c0a769988ee | 367 | bitRazao_0_25[0]+= bitAlto[i]; |
brunofgc | 0:1c0a769988ee | 368 | bitRazao_0_25[1]+=bitBaixo[i]; |
brunofgc | 0:1c0a769988ee | 369 | }else if(razaoBit(bitAlto[i],bitBaixo[i])==0.125){ |
brunofgc | 0:1c0a769988ee | 370 | razao_0_125++; |
brunofgc | 0:1c0a769988ee | 371 | bitRazao_0_125[0]+= bitAlto[i]; |
brunofgc | 0:1c0a769988ee | 372 | bitRazao_0_125[1]+=bitBaixo[i]; |
brunofgc | 0:1c0a769988ee | 373 | }else { |
brunofgc | 0:1c0a769988ee | 374 | razao_menorQue_0_125++; |
brunofgc | 0:1c0a769988ee | 375 | bitRazao_menorQue_0_125[0]+= bitAlto[i]; |
brunofgc | 0:1c0a769988ee | 376 | bitRazao_menorQue_0_125[1]+=bitBaixo[i]; |
brunofgc | 0:1c0a769988ee | 377 | } |
brunofgc | 0:1c0a769988ee | 378 | |
brunofgc | 0:1c0a769988ee | 379 | } |
brunofgc | 0:1c0a769988ee | 380 | printf("Razoes <0.125 = %d\n 0.125 = %d\n 0.25 = %d\n 0.5 = %d\n 1 = %d\n 2 = %d\n 3 = %d\n 4 = %d\n maior que 4 = %d\n" |
brunofgc | 0:1c0a769988ee | 381 | ,razao_menorQue_0_125 |
brunofgc | 0:1c0a769988ee | 382 | ,razao_0_125 |
brunofgc | 0:1c0a769988ee | 383 | ,razao_0_25 |
brunofgc | 0:1c0a769988ee | 384 | ,razao_0_5 |
brunofgc | 0:1c0a769988ee | 385 | ,razao_1 |
brunofgc | 0:1c0a769988ee | 386 | ,razao_2 |
brunofgc | 0:1c0a769988ee | 387 | ,razao_3 |
brunofgc | 0:1c0a769988ee | 388 | ,razao_4 |
brunofgc | 0:1c0a769988ee | 389 | ,razao_maiorQue4 |
brunofgc | 0:1c0a769988ee | 390 | ); |
brunofgc | 0:1c0a769988ee | 391 | |
brunofgc | 0:1c0a769988ee | 392 | //Buscando os dois maiores em numero de eventos por Indice; |
brunofgc | 0:1c0a769988ee | 393 | //Buscando o primeiro |
brunofgc | 0:1c0a769988ee | 394 | for(i=0;i<9;i++){ |
brunofgc | 0:1c0a769988ee | 395 | //Buscando nos indices maior numero eventos |
brunofgc | 0:1c0a769988ee | 396 | switch(i){ |
brunofgc | 0:1c0a769988ee | 397 | case 0: |
brunofgc | 0:1c0a769988ee | 398 | if(razao_maiorQue4>indiceMaiorNEventos[0]){ |
brunofgc | 0:1c0a769988ee | 399 | indiceMaiorNEventos[0] = razao_maiorQue4; |
brunofgc | 0:1c0a769988ee | 400 | indiceMaiorNEventos[1] = i; |
brunofgc | 0:1c0a769988ee | 401 | } |
brunofgc | 0:1c0a769988ee | 402 | break; |
brunofgc | 0:1c0a769988ee | 403 | |
brunofgc | 0:1c0a769988ee | 404 | case 1: |
brunofgc | 0:1c0a769988ee | 405 | if(razao_4>indiceMaiorNEventos[0]){ |
brunofgc | 0:1c0a769988ee | 406 | indiceMaiorNEventos[0] = razao_4; |
brunofgc | 0:1c0a769988ee | 407 | indiceMaiorNEventos[1] = i; |
brunofgc | 0:1c0a769988ee | 408 | } |
brunofgc | 0:1c0a769988ee | 409 | break; |
brunofgc | 0:1c0a769988ee | 410 | case 2: |
brunofgc | 0:1c0a769988ee | 411 | if(razao_3>indiceMaiorNEventos[0]){ |
brunofgc | 0:1c0a769988ee | 412 | indiceMaiorNEventos[0] = razao_3; |
brunofgc | 0:1c0a769988ee | 413 | indiceMaiorNEventos[1] = i; |
brunofgc | 0:1c0a769988ee | 414 | } |
brunofgc | 0:1c0a769988ee | 415 | break; |
brunofgc | 0:1c0a769988ee | 416 | case 3: |
brunofgc | 0:1c0a769988ee | 417 | if(razao_2>indiceMaiorNEventos[0]){ |
brunofgc | 0:1c0a769988ee | 418 | indiceMaiorNEventos[0] = razao_2; |
brunofgc | 0:1c0a769988ee | 419 | indiceMaiorNEventos[1] = i; |
brunofgc | 0:1c0a769988ee | 420 | } |
brunofgc | 0:1c0a769988ee | 421 | break; |
brunofgc | 0:1c0a769988ee | 422 | case 4: |
brunofgc | 0:1c0a769988ee | 423 | if(razao_1>indiceMaiorNEventos[0]){ |
brunofgc | 0:1c0a769988ee | 424 | indiceMaiorNEventos[0] = razao_1; |
brunofgc | 0:1c0a769988ee | 425 | indiceMaiorNEventos[1] = i; |
brunofgc | 0:1c0a769988ee | 426 | } |
brunofgc | 0:1c0a769988ee | 427 | break; |
brunofgc | 0:1c0a769988ee | 428 | case 5: |
brunofgc | 0:1c0a769988ee | 429 | if(razao_0_5>indiceMaiorNEventos[0]){ |
brunofgc | 0:1c0a769988ee | 430 | indiceMaiorNEventos[0] = razao_0_5; |
brunofgc | 0:1c0a769988ee | 431 | indiceMaiorNEventos[1] = i; |
brunofgc | 0:1c0a769988ee | 432 | } |
brunofgc | 0:1c0a769988ee | 433 | break; |
brunofgc | 0:1c0a769988ee | 434 | case 6: |
brunofgc | 0:1c0a769988ee | 435 | if(razao_0_25>indiceMaiorNEventos[0]){ |
brunofgc | 0:1c0a769988ee | 436 | indiceMaiorNEventos[0] = razao_0_25; |
brunofgc | 0:1c0a769988ee | 437 | indiceMaiorNEventos[1] = i; |
brunofgc | 0:1c0a769988ee | 438 | } |
brunofgc | 0:1c0a769988ee | 439 | break; |
brunofgc | 0:1c0a769988ee | 440 | case 7: |
brunofgc | 0:1c0a769988ee | 441 | if(razao_0_125>indiceMaiorNEventos[0]){ |
brunofgc | 0:1c0a769988ee | 442 | indiceMaiorNEventos[0] = razao_0_125; |
brunofgc | 0:1c0a769988ee | 443 | indiceMaiorNEventos[1] = i; |
brunofgc | 0:1c0a769988ee | 444 | } |
brunofgc | 0:1c0a769988ee | 445 | break; |
brunofgc | 0:1c0a769988ee | 446 | case 8: |
brunofgc | 0:1c0a769988ee | 447 | if(razao_menorQue_0_125>indiceMaiorNEventos[0]){ |
brunofgc | 0:1c0a769988ee | 448 | indiceMaiorNEventos[0] = razao_menorQue_0_125; |
brunofgc | 0:1c0a769988ee | 449 | indiceMaiorNEventos[1] = i; |
brunofgc | 0:1c0a769988ee | 450 | } |
brunofgc | 0:1c0a769988ee | 451 | break; |
brunofgc | 0:1c0a769988ee | 452 | |
brunofgc | 0:1c0a769988ee | 453 | } |
brunofgc | 0:1c0a769988ee | 454 | } |
brunofgc | 0:1c0a769988ee | 455 | |
brunofgc | 0:1c0a769988ee | 456 | //Buscando o segundo |
brunofgc | 0:1c0a769988ee | 457 | //Buscando o primeiro |
brunofgc | 0:1c0a769988ee | 458 | for(i=0;i<9;i++){ |
brunofgc | 0:1c0a769988ee | 459 | //Buscando nos indices maior numero eventos |
brunofgc | 0:1c0a769988ee | 460 | if(i!=indiceMaiorNEventos[1]){ |
brunofgc | 0:1c0a769988ee | 461 | switch(i){ |
brunofgc | 0:1c0a769988ee | 462 | case 0: |
brunofgc | 0:1c0a769988ee | 463 | if(razao_maiorQue4>indiceSegundoMaiorNEventos[0]){ |
brunofgc | 0:1c0a769988ee | 464 | indiceSegundoMaiorNEventos[0] = razao_maiorQue4; |
brunofgc | 0:1c0a769988ee | 465 | indiceSegundoMaiorNEventos[1] = i; |
brunofgc | 0:1c0a769988ee | 466 | } |
brunofgc | 0:1c0a769988ee | 467 | break; |
brunofgc | 0:1c0a769988ee | 468 | |
brunofgc | 0:1c0a769988ee | 469 | case 1: |
brunofgc | 0:1c0a769988ee | 470 | if(razao_4>indiceSegundoMaiorNEventos[0]){ |
brunofgc | 0:1c0a769988ee | 471 | indiceSegundoMaiorNEventos[0] = razao_4; |
brunofgc | 0:1c0a769988ee | 472 | indiceSegundoMaiorNEventos[1] = i; |
brunofgc | 0:1c0a769988ee | 473 | } |
brunofgc | 0:1c0a769988ee | 474 | break; |
brunofgc | 0:1c0a769988ee | 475 | case 2: |
brunofgc | 0:1c0a769988ee | 476 | if(razao_3>indiceSegundoMaiorNEventos[0]){ |
brunofgc | 0:1c0a769988ee | 477 | indiceSegundoMaiorNEventos[0] = razao_3; |
brunofgc | 0:1c0a769988ee | 478 | indiceSegundoMaiorNEventos[1] = i; |
brunofgc | 0:1c0a769988ee | 479 | } |
brunofgc | 0:1c0a769988ee | 480 | break; |
brunofgc | 0:1c0a769988ee | 481 | case 3: |
brunofgc | 0:1c0a769988ee | 482 | if(razao_2>indiceSegundoMaiorNEventos[0]){ |
brunofgc | 0:1c0a769988ee | 483 | indiceSegundoMaiorNEventos[0] = razao_2; |
brunofgc | 0:1c0a769988ee | 484 | indiceSegundoMaiorNEventos[1] = i; |
brunofgc | 0:1c0a769988ee | 485 | } |
brunofgc | 0:1c0a769988ee | 486 | break; |
brunofgc | 0:1c0a769988ee | 487 | case 4: |
brunofgc | 0:1c0a769988ee | 488 | if(razao_1>indiceSegundoMaiorNEventos[0]){ |
brunofgc | 0:1c0a769988ee | 489 | indiceSegundoMaiorNEventos[0] = razao_1; |
brunofgc | 0:1c0a769988ee | 490 | indiceSegundoMaiorNEventos[1] = i; |
brunofgc | 0:1c0a769988ee | 491 | } |
brunofgc | 0:1c0a769988ee | 492 | break; |
brunofgc | 0:1c0a769988ee | 493 | case 5: |
brunofgc | 0:1c0a769988ee | 494 | if(razao_0_5>indiceSegundoMaiorNEventos[0]){ |
brunofgc | 0:1c0a769988ee | 495 | indiceSegundoMaiorNEventos[0] = razao_0_5; |
brunofgc | 0:1c0a769988ee | 496 | indiceSegundoMaiorNEventos[1] = i; |
brunofgc | 0:1c0a769988ee | 497 | } |
brunofgc | 0:1c0a769988ee | 498 | break; |
brunofgc | 0:1c0a769988ee | 499 | case 6: |
brunofgc | 0:1c0a769988ee | 500 | if(razao_0_25>indiceSegundoMaiorNEventos[0]){ |
brunofgc | 0:1c0a769988ee | 501 | indiceSegundoMaiorNEventos[0] = razao_0_25; |
brunofgc | 0:1c0a769988ee | 502 | indiceSegundoMaiorNEventos[1] = i; |
brunofgc | 0:1c0a769988ee | 503 | } |
brunofgc | 0:1c0a769988ee | 504 | break; |
brunofgc | 0:1c0a769988ee | 505 | case 7: |
brunofgc | 0:1c0a769988ee | 506 | if(razao_0_125>indiceSegundoMaiorNEventos[0]){ |
brunofgc | 0:1c0a769988ee | 507 | indiceSegundoMaiorNEventos[0] = razao_0_125; |
brunofgc | 0:1c0a769988ee | 508 | indiceSegundoMaiorNEventos[1] = i; |
brunofgc | 0:1c0a769988ee | 509 | } |
brunofgc | 0:1c0a769988ee | 510 | break; |
brunofgc | 0:1c0a769988ee | 511 | case 8: |
brunofgc | 0:1c0a769988ee | 512 | if(razao_menorQue_0_125>indiceSegundoMaiorNEventos[0]){ |
brunofgc | 0:1c0a769988ee | 513 | indiceSegundoMaiorNEventos[0] = razao_menorQue_0_125; |
brunofgc | 0:1c0a769988ee | 514 | indiceSegundoMaiorNEventos[1] = i; |
brunofgc | 0:1c0a769988ee | 515 | } |
brunofgc | 0:1c0a769988ee | 516 | break; |
brunofgc | 0:1c0a769988ee | 517 | |
brunofgc | 0:1c0a769988ee | 518 | } |
brunofgc | 0:1c0a769988ee | 519 | } |
brunofgc | 0:1c0a769988ee | 520 | } |
brunofgc | 0:1c0a769988ee | 521 | |
brunofgc | 0:1c0a769988ee | 522 | |
brunofgc | 0:1c0a769988ee | 523 | //printf("Indice de maior aparecimento foi o de %d.\nIndice de segundo maior aparecimento foi o de %d.\n",indiceMaiorNEventos[1],indiceSegundoMaiorNEventos[1]); |
brunofgc | 0:1c0a769988ee | 524 | |
brunofgc | 0:1c0a769988ee | 525 | //Calculando bitAlto |
brunofgc | 0:1c0a769988ee | 526 | switch(indiceMaiorNEventos[1]){ |
brunofgc | 0:1c0a769988ee | 527 | case 0: |
brunofgc | 0:1c0a769988ee | 528 | bitAlto_H = round(bitRazao_maiorQue4[0]/indiceMaiorNEventos[0]); |
brunofgc | 0:1c0a769988ee | 529 | bitAlto_L = round(bitRazao_maiorQue4[1]/indiceMaiorNEventos[0]); |
brunofgc | 0:1c0a769988ee | 530 | break; |
brunofgc | 0:1c0a769988ee | 531 | case 1: |
brunofgc | 0:1c0a769988ee | 532 | bitAlto_H = round(bitRazao_4[0]/indiceMaiorNEventos[0]); |
brunofgc | 0:1c0a769988ee | 533 | bitAlto_L = round(bitRazao_4[1]/indiceMaiorNEventos[0]); |
brunofgc | 0:1c0a769988ee | 534 | break; |
brunofgc | 0:1c0a769988ee | 535 | case 2: |
brunofgc | 0:1c0a769988ee | 536 | bitAlto_H = round(bitRazao_3[0]/indiceMaiorNEventos[0]); |
brunofgc | 0:1c0a769988ee | 537 | bitAlto_L = round(bitRazao_3[1]/indiceMaiorNEventos[0]); |
brunofgc | 0:1c0a769988ee | 538 | break; |
brunofgc | 0:1c0a769988ee | 539 | case 3: |
brunofgc | 0:1c0a769988ee | 540 | bitAlto_H = round(bitRazao_2[0]/indiceMaiorNEventos[0]); |
brunofgc | 0:1c0a769988ee | 541 | bitAlto_L = round(bitRazao_2[1]/indiceMaiorNEventos[0]); |
brunofgc | 0:1c0a769988ee | 542 | break; |
brunofgc | 0:1c0a769988ee | 543 | case 4: |
brunofgc | 0:1c0a769988ee | 544 | bitAlto_H = round(bitRazao_1[0]/indiceMaiorNEventos[0]); |
brunofgc | 0:1c0a769988ee | 545 | bitAlto_L = round(bitRazao_1[1]/indiceMaiorNEventos[0]); |
brunofgc | 0:1c0a769988ee | 546 | break; |
brunofgc | 0:1c0a769988ee | 547 | case 5: |
brunofgc | 0:1c0a769988ee | 548 | bitAlto_H = round(bitRazao_0_5[0]/indiceMaiorNEventos[0]); |
brunofgc | 0:1c0a769988ee | 549 | bitAlto_L = round(bitRazao_0_5[1]/indiceMaiorNEventos[0]); |
brunofgc | 0:1c0a769988ee | 550 | break; |
brunofgc | 0:1c0a769988ee | 551 | case 6: |
brunofgc | 0:1c0a769988ee | 552 | bitAlto_H = round(bitRazao_0_25[0]/indiceMaiorNEventos[0]); |
brunofgc | 0:1c0a769988ee | 553 | bitAlto_L = round(bitRazao_0_25[1]/indiceMaiorNEventos[0]); |
brunofgc | 0:1c0a769988ee | 554 | break; |
brunofgc | 0:1c0a769988ee | 555 | case 7: |
brunofgc | 0:1c0a769988ee | 556 | bitAlto_H = round(bitRazao_0_125[0]/indiceMaiorNEventos[0]); |
brunofgc | 0:1c0a769988ee | 557 | bitAlto_L = round(bitRazao_0_125[1]/indiceMaiorNEventos[0]); |
brunofgc | 0:1c0a769988ee | 558 | break; |
brunofgc | 0:1c0a769988ee | 559 | case 8: |
brunofgc | 0:1c0a769988ee | 560 | bitAlto_H = round(bitRazao_menorQue_0_125[0]/indiceMaiorNEventos[0]); |
brunofgc | 0:1c0a769988ee | 561 | bitAlto_L = round(bitRazao_menorQue_0_125[1]/indiceMaiorNEventos[0]); |
brunofgc | 0:1c0a769988ee | 562 | break; |
brunofgc | 0:1c0a769988ee | 563 | } |
brunofgc | 0:1c0a769988ee | 564 | |
brunofgc | 0:1c0a769988ee | 565 | //Calculando bitBaixo |
brunofgc | 0:1c0a769988ee | 566 | switch(indiceSegundoMaiorNEventos[1]){ |
brunofgc | 0:1c0a769988ee | 567 | case 0: |
brunofgc | 0:1c0a769988ee | 568 | bitBaixo_H = round(bitRazao_maiorQue4[0]/indiceSegundoMaiorNEventos[0]); |
brunofgc | 0:1c0a769988ee | 569 | bitBaixo_L = round(bitRazao_maiorQue4[1]/indiceSegundoMaiorNEventos[0]); |
brunofgc | 0:1c0a769988ee | 570 | break; |
brunofgc | 0:1c0a769988ee | 571 | case 1: |
brunofgc | 0:1c0a769988ee | 572 | bitBaixo_H = round(bitRazao_4[0]/indiceSegundoMaiorNEventos[0]); |
brunofgc | 0:1c0a769988ee | 573 | bitBaixo_L = round(bitRazao_4[1]/indiceSegundoMaiorNEventos[0]); |
brunofgc | 0:1c0a769988ee | 574 | break; |
brunofgc | 0:1c0a769988ee | 575 | case 2: |
brunofgc | 0:1c0a769988ee | 576 | bitBaixo_H = round(bitRazao_3[0]/indiceSegundoMaiorNEventos[0]); |
brunofgc | 0:1c0a769988ee | 577 | bitBaixo_L = round(bitRazao_3[1]/indiceSegundoMaiorNEventos[0]); |
brunofgc | 0:1c0a769988ee | 578 | break; |
brunofgc | 0:1c0a769988ee | 579 | case 3: |
brunofgc | 0:1c0a769988ee | 580 | bitBaixo_H = round(bitRazao_2[0]/indiceSegundoMaiorNEventos[0]); |
brunofgc | 0:1c0a769988ee | 581 | bitBaixo_L = round(bitRazao_2[1]/indiceSegundoMaiorNEventos[0]); |
brunofgc | 0:1c0a769988ee | 582 | break; |
brunofgc | 0:1c0a769988ee | 583 | case 4: |
brunofgc | 0:1c0a769988ee | 584 | bitBaixo_H = round(bitRazao_1[0]/indiceSegundoMaiorNEventos[0]); |
brunofgc | 0:1c0a769988ee | 585 | bitBaixo_L = round(bitRazao_1[1]/indiceSegundoMaiorNEventos[0]); |
brunofgc | 0:1c0a769988ee | 586 | break; |
brunofgc | 0:1c0a769988ee | 587 | case 5: |
brunofgc | 0:1c0a769988ee | 588 | bitBaixo_H = round(bitRazao_0_5[0]/indiceSegundoMaiorNEventos[0]); |
brunofgc | 0:1c0a769988ee | 589 | bitBaixo_L = round(bitRazao_0_5[1]/indiceSegundoMaiorNEventos[0]); |
brunofgc | 0:1c0a769988ee | 590 | break; |
brunofgc | 0:1c0a769988ee | 591 | case 6: |
brunofgc | 0:1c0a769988ee | 592 | bitBaixo_H = round(bitRazao_0_25[0]/indiceSegundoMaiorNEventos[0]); |
brunofgc | 0:1c0a769988ee | 593 | bitBaixo_L = round(bitRazao_0_25[1]/indiceSegundoMaiorNEventos[0]); |
brunofgc | 0:1c0a769988ee | 594 | break; |
brunofgc | 0:1c0a769988ee | 595 | case 7: |
brunofgc | 0:1c0a769988ee | 596 | bitBaixo_H = round(bitRazao_0_125[0]/indiceSegundoMaiorNEventos[0]); |
brunofgc | 0:1c0a769988ee | 597 | bitBaixo_L = round(bitRazao_0_125[1]/indiceSegundoMaiorNEventos[0]); |
brunofgc | 0:1c0a769988ee | 598 | break; |
brunofgc | 0:1c0a769988ee | 599 | case 8: |
brunofgc | 0:1c0a769988ee | 600 | bitBaixo_H = round(bitRazao_menorQue_0_125[0]/indiceSegundoMaiorNEventos[0]); |
brunofgc | 0:1c0a769988ee | 601 | bitBaixo_L = round(bitRazao_menorQue_0_125[1]/indiceSegundoMaiorNEventos[0]); |
brunofgc | 0:1c0a769988ee | 602 | break; |
brunofgc | 0:1c0a769988ee | 603 | } |
brunofgc | 0:1c0a769988ee | 604 | |
brunofgc | 0:1c0a769988ee | 605 | printf("\n\nFinalmente.\n"); |
brunofgc | 0:1c0a769988ee | 606 | printf("startBitAlto = %ld, startBitBaixo = %ld\n", startBitAlto,startBitBaixo); |
brunofgc | 0:1c0a769988ee | 607 | printf("bitAlto_H = %ld bitAlto_l = %ld\n",bitAlto_H,bitAlto_L); |
brunofgc | 0:1c0a769988ee | 608 | printf("bitBaixo_H = %ld bitBaixo_l = %ld\n",bitBaixo_H,bitBaixo_L); |
brunofgc | 0:1c0a769988ee | 609 | printf("stopBitAlto = %ld\n",stopBitAlto); |
brunofgc | 0:1c0a769988ee | 610 | |
brunofgc | 0:1c0a769988ee | 611 | return; |
brunofgc | 0:1c0a769988ee | 612 | }*/ |