Rev 533 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 533 | Rev 548 | ||
|---|---|---|---|
| Line 50... | Line 50... | ||
| 50 | * The number of stored ir-times in the array |
50 | * The number of stored ir-times in the array |
| 51 | */ |
51 | */ |
| 52 | uint8_t getRawDataCnt(void) { |
52 | uint8_t getRawDataCnt(void) { |
| 53 | return timesCounter; |
53 | return timesCounter; |
| 54 | } |
54 | } |
| 55 | - | ||
| 56 | #if 1 |
- | |
| 57 | 55 | ||
| 58 | /** |
56 | /** |
| 59 | * Test data on SIRC protocol, 12-bit version |
57 | * Test data on SIRC protocol, 12-bit version |
| 60 | * http://www.sbprojects.com/knowledge/ir/sirc.htm |
58 | * http://www.sbprojects.com/knowledge/ir/sirc.htm |
| 61 | * |
59 | * |
| Line 72... | Line 70... | ||
| 72 | /* check if we have correct amount of data */ |
70 | /* check if we have correct amount of data */ |
| 73 | if (timesCounter != 25) { |
71 | if (timesCounter != 25) { |
| 74 | return IR_NOT_CORRECT_DATA; |
72 | return IR_NOT_CORRECT_DATA; |
| 75 | } |
73 | } |
| 76 | 74 | ||
| 77 | /* check startbit */ |
75 | /* check startbit */ |
| 78 | if (times[0] > IR_SIRC_ST_BIT + IR_SIRC_ST_BIT/IR_SIRC_TOL_DIV || times[0] < IR_SIRC_ST_BIT - IR_SIRC_ST_BIT/IR_SIRC_TOL_DIV) { |
76 | if (times[0] > IR_SIRC_ST_BIT + IR_SIRC_ST_BIT/IR_SIRC_TOL_DIV || times[0] < IR_SIRC_ST_BIT - IR_SIRC_ST_BIT/IR_SIRC_TOL_DIV) { |
| 79 | return IR_NOT_CORRECT_DATA; |
77 | return IR_NOT_CORRECT_DATA; |
| 80 | } |
78 | } |
| 81 | 79 | ||
| 82 | uint16_t rawbits=0; |
80 | uint16_t rawbits=0; |
| 83 | 81 | ||
| 84 | for (uint8_t i = 1; i < timesCounter; i++) { |
82 | for (uint8_t i = 1; i < timesCounter; i++) { |
| 85 | if ((i&1) == 1) { /* if odd, ir-pause */ |
83 | if ((i&1) == 1) { /* if odd, ir-pause */ |
| 86 | /* check length of pause between bits */ |
84 | /* check length of pause between bits */ |
| 87 | if (times[i] > IR_SIRC_LOW + IR_SIRC_LOW/IR_SIRC_TOL_DIV || times[i] < IR_SIRC_LOW - IR_SIRC_LOW/IR_SIRC_TOL_DIV) { |
85 | if (times[i] > IR_SIRC_LOW + IR_SIRC_LOW/IR_SIRC_TOL_DIV || times[i] < IR_SIRC_LOW - IR_SIRC_LOW/IR_SIRC_TOL_DIV) { |
| 88 | return IR_NOT_CORRECT_DATA; |
86 | return IR_NOT_CORRECT_DATA; |
| 89 | } |
87 | } |
| 90 | } else { /* if even, ir-bit */ |
88 | } else { /* if even, ir-bit */ |
| 91 | if (times[i] > IR_SIRC_HIGH_ONE - IR_SIRC_HIGH_ONE/IR_SIRC_TOL_DIV && times[i] < IR_SIRC_HIGH_ONE + IR_SIRC_HIGH_ONE/IR_SIRC_TOL_DIV) { |
89 | if (times[i] > IR_SIRC_HIGH_ONE - IR_SIRC_HIGH_ONE/IR_SIRC_TOL_DIV && times[i] < IR_SIRC_HIGH_ONE + IR_SIRC_HIGH_ONE/IR_SIRC_TOL_DIV) { |
| Line 96... | Line 94... | ||
| 96 | } else { |
94 | } else { |
| 97 | return IR_NOT_CORRECT_DATA; |
95 | return IR_NOT_CORRECT_DATA; |
| 98 | } |
96 | } |
| 99 | } |
97 | } |
| 100 | } |
98 | } |
| 101 | 99 | ||
| 102 | *command = ((uint8_t)rawbits&0x7f); |
100 | *command = ((uint8_t)rawbits&0x7f); |
| 103 | *address = ((uint8_t)(rawbits>>7)&0x1f); |
101 | *address = ((uint8_t)(rawbits>>7)&0x1f); |
| 104 | 102 | ||
| 105 | return IR_OK; |
103 | return IR_OK; |
| 106 | } |
104 | } |
| 107 | 105 | ||
| 108 | /** |
106 | /** |
| 109 | * Test data on RC5 protocol |
107 | * Test data on RC5 protocol |
| 110 | * http://www.sbprojects.com/knowledge/ir/rc5.htm |
108 | * http://www.sbprojects.com/knowledge/ir/rc5.htm |
| 111 | * |
109 | * |
| 112 | * @param address |
110 | * @param address |
| 113 | * Pointer to store the address of the received data |
111 | * Pointer to store the address of the received data |
| 114 | * @param command |
112 | * @param command |
| 115 | * Pointer to store the command of the received data |
113 | * Pointer to store the command of the received data |
| 116 | * @return |
114 | * @return |
| 117 | * IR_OK if data parsed successfully, one of several errormessages if not |
115 | * IR_OK if data parsed successfully, one of several errormessages if not |
| 118 | */ |
116 | */ |
| 119 | uint8_t testRC5(uint8_t *address, uint8_t *command) { |
117 | uint8_t testRC5(uint8_t *address, uint8_t *command) { |
| 120 | uint8_t halfbitscnt = 1; |
118 | uint8_t halfbitscnt = 1; |
| Line 168... | Line 166... | ||
| 168 | } |
166 | } |
| 169 | 167 | ||
| 170 | uint16_t rawbits=0; |
168 | uint16_t rawbits=0; |
| 171 | 169 | ||
| 172 | for (uint8_t i = 1; i < timesCounter; i++) { |
170 | for (uint8_t i = 1; i < timesCounter; i++) { |
| 173 | if ((i&1) == 1) { /* if odd, ir-pause */ |
171 | if ((i&1) == 1) { /* if odd, ir-pause */ |
| 174 | /* check length of pause between bits */ |
172 | /* check length of pause between bits */ |
| 175 | if (times[i] > IR_SHARP_LOW_ONE - IR_SHARP_LOW_ONE/IR_SHARP_TOL_DIV && times[i] < IR_SHARP_LOW_ONE + IR_SHARP_LOW_ONE/IR_SHARP_TOL_DIV) { |
173 | if (times[i] > IR_SHARP_LOW_ONE - IR_SHARP_LOW_ONE/IR_SHARP_TOL_DIV && times[i] < IR_SHARP_LOW_ONE + IR_SHARP_LOW_ONE/IR_SHARP_TOL_DIV) { |
| 176 | /* write a one */ |
174 | /* write a one */ |
| 177 | rawbits |= 1<<((i-1)>>1); |
175 | rawbits |= 1<<((i-1)>>1); |
| 178 | } else if (times[i] > IR_SHARP_LOW_ZERO - IR_SHARP_LOW_ZERO/IR_SHARP_TOL_DIV && times[i] < IR_SHARP_LOW_ZERO + IR_SHARP_LOW_ZERO/IR_SHARP_TOL_DIV) { |
176 | } else if (times[i] > IR_SHARP_LOW_ZERO - IR_SHARP_LOW_ZERO/IR_SHARP_TOL_DIV && times[i] < IR_SHARP_LOW_ZERO + IR_SHARP_LOW_ZERO/IR_SHARP_TOL_DIV) { |
| 179 | /* do nothing, a zero is already in rawbits */ |
177 | /* do nothing, a zero is already in rawbits */ |
| 180 | } else { |
178 | } else { |
| 181 | return IR_NOT_CORRECT_DATA; |
179 | return IR_NOT_CORRECT_DATA; |
| 182 | } |
180 | } |
| 183 | } else { /* if even, ir-bit */ |
181 | } else { /* if even, ir-bit */ |
| 184 | if (times[i] > IR_SHARP_HIGH + IR_SHARP_HIGH/IR_SHARP_TOL_DIV || times[i] < IR_SHARP_HIGH - IR_SHARP_HIGH/IR_SHARP_TOL_DIV) { |
182 | if (times[i] > IR_SHARP_HIGH + IR_SHARP_HIGH/IR_SHARP_TOL_DIV || times[i] < IR_SHARP_HIGH - IR_SHARP_HIGH/IR_SHARP_TOL_DIV) { |
| 185 | return IR_NOT_CORRECT_DATA; |
183 | return IR_NOT_CORRECT_DATA; |
| 186 | } |
184 | } |
| 187 | } |
185 | } |
| Line 193... | Line 191... | ||
| 193 | return IR_OK; |
191 | return IR_OK; |
| 194 | } |
192 | } |
| 195 | 193 | ||
| 196 | /** |
194 | /** |
| 197 | * Test data on NEC protocol |
195 | * Test data on NEC protocol |
| 198 | * http://www.sbprojects.com/knowledge/ir/nec.htm |
196 | * http://www.sbprojects.com/knowledge/ir/nec.htm |
| 199 | * |
197 | * |
| 200 | * @param address |
198 | * @param address |
| 201 | * Pointer to store the address of the received data |
199 | * Pointer to store the address of the received data |
| 202 | * @param command |
200 | * @param command |
| 203 | * Pointer to store the command of the received data |
201 | * Pointer to store the command of the received data |
| 204 | * @return |
202 | * @return |
| 205 | * IR_OK if data parsed successfully, one of several errormessages if not |
203 | * IR_OK if data parsed successfully, one of several errormessages if not |
| 206 | */ |
204 | */ |
| 207 | uint8_t testNEC(uint8_t *address, uint8_t *command) { |
205 | uint8_t testNEC(uint8_t *address, uint8_t *command) { |
| Line 284... | Line 282... | ||
| 284 | } |
282 | } |
| 285 | 283 | ||
| 286 | *command = 0; |
284 | *command = 0; |
| 287 | *address = 0; |
285 | *address = 0; |
| 288 | 286 | ||
| 289 | for (uint8_t i = |
287 | for (uint8_t i = 2; i < timesCounter; i++) { |
| 290 | if ((i&1) == 1) { /* if odd, ir-pause */ |
288 | if ((i&1) == 1) { /* if odd, ir-pause */ |
| 291 | /* check length of pause between bits */ |
289 | /* check length of pause between bits */ |
| 292 | if (times[i] > IR_SAMS_LOW_ONE - IR_SAMS_LOW_ONE/IR_SAMS_TOL_DIV && times[i] < IR_SAMS_LOW_ONE + IR_SAMS_LOW_ONE/IR_SAMS_TOL_DIV) { |
290 | if (times[i] > IR_SAMS_LOW_ONE - IR_SAMS_LOW_ONE/IR_SAMS_TOL_DIV && times[i] < IR_SAMS_LOW_ONE + IR_SAMS_LOW_ONE/IR_SAMS_TOL_DIV) { |
| 293 | if (i>2 && i<18) { |
291 | if (i>2 && i<18) { |
| 294 | /* write a one */ |
292 | /* write a one */ |
| Line 319... | Line 317... | ||
| 319 | initTimer(); |
317 | initTimer(); |
| 320 | 318 | ||
| 321 | //this routine should sample the timings for received irdata |
319 | //this routine should sample the timings for received irdata |
| 322 | timesCounter = 0; |
320 | timesCounter = 0; |
| 323 | 321 | ||
| 324 | uint8_t gotTimout = 0; // a timeout is a very long break in irdata (such as occurs between ir |
322 | uint8_t gotTimout = 0; // a timeout is a very long break in irdata (such as occurs between ir frames) |
| 325 | while (!gotTimout && timesCounter < MAX_NR_TIMES-1) { //loop as long as no timeout occured and not to many pulses received |
323 | while (!gotTimout && timesCounter < MAX_NR_TIMES-1) { //loop as long as no timeout occured and not to many pulses received |
| 326 | setTimerVal(TIM_OVFL_RELOAD_VAL); |
324 | setTimerVal(TIM_OVFL_RELOAD_VAL); |
| 327 | //wait for positiv slope, while checking timer overflow |
325 | //wait for positiv slope, while checking timer overflow |
| 328 | while (!(IRPIN & (1<<IRBIT))) { |
326 | while (!(IRPIN & (1<<IRBIT))) { |
| 329 | //if timeout (if timer-ovflow-flaggan is set) |
327 | //if timeout (if timer-ovflow-flaggan is set) |
| Line 375... | Line 373... | ||
| 375 | } |
373 | } |
| 376 | 374 | ||
| 377 | return IR_NO_PROTOCOL; |
375 | return IR_NO_PROTOCOL; |
| 378 | 376 | ||
| 379 | } |
377 | } |
| 380 | #endif |
- | |
| 381 | 378 | ||
| 382 | //TODO: skriv doxygen-header som för de andra funktionerna |
379 | //TODO: skriv doxygen-header som för de andra funktionerna |
| 383 | /** |
380 | /** |
| 384 | * |
381 | * |
| 385 | * |
382 | * |
| Line 388... | Line 385... | ||
| 388 | */ |
385 | */ |
| 389 | void IrReceive_Init(void) { |
386 | void IrReceive_Init(void) { |
| 390 | IRDDR &= ~(1<<IRBIT); |
387 | IRDDR &= ~(1<<IRBIT); |
| 391 | } |
388 | } |
| 392 | 389 | ||
| 393 | //varför är denna funktion så komplex? jo den filtrerar bort korta ir-pulser |
390 | //varför är denna funktion så komplex? jo den filtrerar bort för korta ir-pulser |
| 394 | //TODO: skriv doxygen-header som för de andra funktionerna |
391 | //TODO: skriv doxygen-header som för de andra funktionerna |
| 395 | uint8_t IrReceive_CheckIdle(void) { |
392 | uint8_t IrReceive_CheckIdle(void) { |
| 396 | if (IRPIN & (1<<IRBIT)) return IR_NO_DATA; //om irmodulen ger en etta så återgå |
393 | if (IRPIN & (1<<IRBIT)) return IR_NO_DATA; //om irmodulen ger en etta så återgå |
| 397 | 394 | ||
| 398 | //nu lägger irmodulen ut en nolla, "startbiten" alltså |
395 | //nu lägger irmodulen ut en nolla, "startbiten" alltså |