Subversion Repositories HomeAutomation

Rev

Rev 922 | Rev 1562 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 922 Rev 1320
Line 1... Line 1...
1
/**
1
/**
2
 * IR receiver and transmitter protocols.
2
 * IR receiver and transmitter protocols.
3
 *
3
 *
4
 * @date    2006-12-10
4
 * @date    2006-12-10
5
 *
5
 *
6
 * @author  Anders Runeson, Andreas Fritiofson, Martin Nordn
6
 * @author  Anders Runeson, Andreas Fritiofson, Martin Nordin
7
 *  
7
 *  
8
 */
8
 */
9
 
9
 
10
#include "protocols.h"
10
#include "protocols.h"
11
#include <bios.h>
11
#include <bios.h>
Line 30... Line 30...
30
#if (IR_PROTOCOLS_USE_SAMSUNG)
30
#if (IR_PROTOCOLS_USE_SAMSUNG)
31
    if (parseSamsung(buf, len, proto)==IR_OK) return IR_OK;
31
    if (parseSamsung(buf, len, proto)==IR_OK) return IR_OK;
32
#endif
32
#endif
33
#if (IR_PROTOCOLS_USE_MARANTZ)
33
#if (IR_PROTOCOLS_USE_MARANTZ)
34
    if (parseMarantz(buf, len, proto)==IR_OK) return IR_OK;
34
    if (parseMarantz(buf, len, proto)==IR_OK) return IR_OK;
-
 
35
#endif
-
 
36
#if (IR_PROTOCOLS_USE_PANASONIC)
-
 
37
    if (parsePanasonic(buf, len, proto)==IR_OK) return IR_OK;
35
#endif
38
#endif
36
    /* No protocol matched. */
39
    /* No protocol matched. */
37
    proto->protocol = IR_PROTO_UNKNOWN;
40
    proto->protocol = IR_PROTO_UNKNOWN;
38
    return IR_NOT_CORRECT_DATA;
41
    return IR_NOT_CORRECT_DATA;
39
}
42
}
Line 60... Line 63...
60
        return expandNEC(buf, len, proto);
63
        return expandNEC(buf, len, proto);
61
    case IR_PROTO_SAMS:
64
    case IR_PROTO_SAMS:
62
        return expandSamsung(buf, len, proto);
65
        return expandSamsung(buf, len, proto);
63
    case IR_PROTO_MARANTZ:
66
    case IR_PROTO_MARANTZ:
64
        return expandMarantz(buf, len, proto);
67
        return expandMarantz(buf, len, proto);
-
 
68
    case IR_PROTO_PANASONIC:
-
 
69
        return expandPanasonic(buf, len, proto);
65
    }
70
    }
66
    /* Invalid protocol specified. */
71
    /* Invalid protocol specified. */
67
    return IR_NOT_CORRECT_DATA;
72
    return IR_NOT_CORRECT_DATA;
68
}
73
}
69
 
74
 
Line 84... Line 89...
84
int8_t parseSIRC(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto) {
89
int8_t parseSIRC(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto) {
85
    /* parse buf[], max is len */
90
    /* parse buf[], max is len */
86
 
91
 
87
    /* check if we have correct amount of data */
92
    /* check if we have correct amount of data */
88
    if (len != 25) {
93
    if (len != 25) {
89
        return IR_NOT_CORRECT_DATA;
94
        return IR_NOT_CORRECT_DATA;
90
    }
95
    }
91
   
96
   
92
    /* check startbit */
97
    /* check startbit */
93
    if (buf[0] > IR_SIRC_ST_BIT + IR_SIRC_ST_BIT/IR_SIRC_TOL_DIV || buf[0] < IR_SIRC_ST_BIT - IR_SIRC_ST_BIT/IR_SIRC_TOL_DIV) {
98
    if (buf[0] > IR_SIRC_ST_BIT + IR_SIRC_ST_BIT/IR_SIRC_TOL_DIV || buf[0] < IR_SIRC_ST_BIT - IR_SIRC_ST_BIT/IR_SIRC_TOL_DIV) {
94
        return IR_NOT_CORRECT_DATA;
99
        return IR_NOT_CORRECT_DATA;
95
    }
100
    }
96
   
101
   
Line 105... Line 110...
105
        } else {            /* if even, ir-bit */
110
        } else {            /* if even, ir-bit */
106
            if (buf[i] > IR_SIRC_HIGH_ONE - IR_SIRC_HIGH_ONE/IR_SIRC_TOL_DIV && buf[i] < IR_SIRC_HIGH_ONE + IR_SIRC_HIGH_ONE/IR_SIRC_TOL_DIV) {
111
            if (buf[i] > IR_SIRC_HIGH_ONE - IR_SIRC_HIGH_ONE/IR_SIRC_TOL_DIV && buf[i] < IR_SIRC_HIGH_ONE + IR_SIRC_HIGH_ONE/IR_SIRC_TOL_DIV) {
107
                /* write a one */
112
                /* write a one */
108
                rawbits |= 1<<((i-2)>>1);
113
                rawbits |= 1<<((i-2)>>1);
109
            } else if (buf[i] > IR_SIRC_HIGH_ZERO - IR_SIRC_HIGH_ZERO/IR_SIRC_TOL_DIV && buf[i] < IR_SIRC_HIGH_ZERO + IR_SIRC_HIGH_ZERO/IR_SIRC_TOL_DIV) {
114
            } else if (buf[i] > IR_SIRC_HIGH_ZERO - IR_SIRC_HIGH_ZERO/IR_SIRC_TOL_DIV && buf[i] < IR_SIRC_HIGH_ZERO + IR_SIRC_HIGH_ZERO/IR_SIRC_TOL_DIV) {
110
                /* do nothing, a zero is already in rawbits */
115
                /* do nothing, a zero is already in rawbits */
111
            } else {
116
            } else {
112
                return IR_NOT_CORRECT_DATA;
117
                return IR_NOT_CORRECT_DATA;
113
            }
118
            }
114
        }
119
        }
115
    }
120
    }
116
   
121
   
117
    proto->protocol = IR_PROTO_SIRC;
122
    proto->protocol = IR_PROTO_SIRC;
118
    proto->timeout = IR_SIRC_TIMEOUT;
123
    proto->timeout = IR_SIRC_TIMEOUT;
119
    proto->data = rawbits;
124
    proto->data = rawbits;
120
   
125
   
121
    return IR_OK;
126
    return IR_OK;
122
}
127
}
123
#endif
128
#endif
124
 
129
 
125
/**
130
/**
126
 * Expand data from SIRC protocol
131
 * Expand data from SIRC protocol
127
 * http://www.sbprojects.com/knowledge/ir/sirc.htm
132
 * http://www.sbprojects.com/knowledge/ir/sirc.htm
128
 *
133
 *
129
 * @param buf
134
 * @param buf
130
 *      Pointer to buffer to store the expanded data
135
 *      Pointer to buffer to store the expanded data
131
 * @param len
136
 * @param len
132
 *      Pointer to length of the data
137
 *      Pointer to length of the data
133
 * @param proto
138
 * @param proto
134
 *      Pointer to protocol information
139
 *      Pointer to protocol information
Line 185... Line 190...
185
    proto->protocol=IR_PROTO_RC5;
190
    proto->protocol=IR_PROTO_RC5;
186
    proto->timeout=IR_RC5_TIMEOUT;
191
    proto->timeout=IR_RC5_TIMEOUT;
187
    //support RC5-extended keeping second startbit 
192
    //support RC5-extended keeping second startbit 
188
    //remove togglebit
193
    //remove togglebit
189
    proto->data = rawbits&0x37ff; //This seems to be wrong? Does not invert second start bit and keeps first start bit
194
    proto->data = rawbits&0x37ff; //This seems to be wrong? Does not invert second start bit and keeps first start bit
190
    //proto->data = (rawbits&0x07ff) | ((~rawbits)&0x0100);
195
    //proto->data = (rawbits&0x07ff) | ((~rawbits)&0x0100);
191
 
196
 
192
   
197
   
193
    return IR_OK;
198
    return IR_OK;
194
}
199
}
195
#endif
200
#endif
196
 
201
 
197
/**
202
/**
198
 * Used by the expandRC5 to ensure that we toggle the signal with each button press.
203
 * Used by the expandRC5 to ensure that we toggle the signal with each button press.
199
 */
204
 */
200
int8_t rc5_toggle=0;
205
int8_t rc5_toggle=0;
201
 
206
 
202
/**
207
/**
Line 350... Line 355...
350
 * @return
355
 * @return
351
 *      IR_OK if data expanded successfully, one of several errormessages if not
356
 *      IR_OK if data expanded successfully, one of several errormessages if not
352
 */
357
 */
353
int8_t expandSharp(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto) {
358
int8_t expandSharp(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto) {
354
    //TODO: Implement this function.
359
    //TODO: Implement this function.
355
    return IR_NOT_CORRECT_DATA;
360
    return IR_NOT_CORRECT_DATA;
356
}
361
}
357
 
362
 
358
 
363
 
359
#if (IR_PROTOCOLS_USE_NEC)
364
#if (IR_PROTOCOLS_USE_NEC)
360
/**
365
/**
361
 * Test data on NEC protocol
366
 * Test data on NEC protocol
362
 * http://www.sbprojects.com/knowledge/ir/nec.htm
367
 * http://www.sbprojects.com/knowledge/ir/nec.htm
363
 *
368
 *
364
 * @param buf
369
 * @param buf
365
 *      Pointer to buffer to where to data to parse is stored
370
 *      Pointer to buffer to where to data to parse is stored
366
 * @param len
371
 * @param len
367
 *      Length of the data
372
 *      Length of the data
368
 * @param proto
373
 * @param proto
369
 *      Pointer to protocol information
374
 *      Pointer to protocol information
370
 * @return
375
 * @return
371
 *      IR_OK if data parsed successfully, one of several errormessages if not
376
 *      IR_OK if data parsed successfully, one of several errormessages if not
372
 */
377
 */
373
int8_t parseNEC(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto) {
378
int8_t parseNEC(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto) {
374
    /* parse buf[], max is len */
379
    /* parse buf[], max is len */
375
 
380
 
376
    /* check if we have correct amount of data */
381
    /* check if we have correct amount of data */
377
    if (len != 67) {
382
    if (len != 67) {
378
        return IR_NOT_CORRECT_DATA;
383
        return IR_NOT_CORRECT_DATA;
379
    }
384
    }
380
   
385
   
381
    /* check startbit */
386
    /* check startbit */
382
    if (buf[0] > IR_NEC_ST_BIT + IR_NEC_ST_BIT/IR_NEC_TOL_DIV || buf[0] < IR_NEC_ST_BIT - IR_NEC_ST_BIT/IR_NEC_TOL_DIV) {
387
    if (buf[0] > IR_NEC_ST_BIT + IR_NEC_ST_BIT/IR_NEC_TOL_DIV || buf[0] < IR_NEC_ST_BIT - IR_NEC_ST_BIT/IR_NEC_TOL_DIV) {
383
        return IR_NOT_CORRECT_DATA;
388
        return IR_NOT_CORRECT_DATA;
384
    }
389
    }
385
 
390
 
386
    /* check pause after startbit */
391
    /* check pause after startbit */
387
    if (buf[1] > IR_NEC_ST_PAUSE + IR_NEC_ST_PAUSE/IR_NEC_TOL_DIV || buf[1] < IR_NEC_ST_PAUSE - IR_NEC_ST_PAUSE/IR_NEC_TOL_DIV) {
392
    if (buf[1] > IR_NEC_ST_PAUSE + IR_NEC_ST_PAUSE/IR_NEC_TOL_DIV || buf[1] < IR_NEC_ST_PAUSE - IR_NEC_ST_PAUSE/IR_NEC_TOL_DIV) {
388
        return IR_NOT_CORRECT_DATA;
393
        return IR_NOT_CORRECT_DATA;
389
    }
394
    }
390
 
395
 
391
    uint32_t rawbits = 0;
396
    uint32_t rawbits = 0;
392
 
397
 
393
    for (uint8_t i = 3; i < len; i++) {
398
    for (uint8_t i = 3; i < len; i++) {
394
        if ((i&1) == 1) {       /* if odd, ir-pause */
399
        if ((i&1) == 1) {       /* if odd, ir-pause */
Line 431... Line 436...
431
int8_t expandNEC(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto) {
436
int8_t expandNEC(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto) {
432
    /* Set up startbit */
437
    /* Set up startbit */
433
    buf[0] = IR_NEC_ST_BIT;
438
    buf[0] = IR_NEC_ST_BIT;
434
   
439
   
435
    if (proto->framecnt == 0) {
440
    if (proto->framecnt == 0) {
436
        buf[1] = IR_NEC_ST_PAUSE;
441
        buf[1] = IR_NEC_ST_PAUSE;
437
   
442
   
438
        *len = 67;
443
        *len = 67;
439
        for (uint8_t i = 0; i < 65; i++) {
444
        for (uint8_t i = 0; i < 65; i++) {
440
            if ((i&1) == 1) {       /* if odd, ir-pause */
445
            if ((i&1) == 1) {       /* if odd, ir-pause */
441
                if ((proto->data>>(i>>1))&1) {
446
                if ((proto->data>>(i>>1))&1) {
442
                    buf[i+2] = IR_NEC_LOW_ONE;
447
                    buf[i+2] = IR_NEC_LOW_ONE;
443
                } else {
448
                } else {
444
                    buf[i+2] = IR_NEC_LOW_ZERO;
449
                    buf[i+2] = IR_NEC_LOW_ZERO;
445
                }
450
                }
446
            } else {            /* if even, ir-bit */
451
            } else {            /* if even, ir-bit */
447
                buf[i+2] = IR_NEC_HIGH;
452
                buf[i+2] = IR_NEC_HIGH;
448
            }
453
            }
449
        }
454
        }
450
        proto->timeout=IR_NEC_TIMEOUT;
455
        proto->timeout=IR_NEC_TIMEOUT;
451
    } else {
456
    } else {
452
        buf[1] = IR_NEC_ST_PAUSE/2;
457
        buf[1] = IR_NEC_ST_PAUSE/2;
453
        buf[2] = IR_NEC_HIGH;
458
        buf[2] = IR_NEC_HIGH;
454
        proto->timeout=IR_NEC_ST_TIMEOUT;
459
        proto->timeout=IR_NEC_ST_TIMEOUT;
Line 483... Line 488...
483
        return IR_NOT_CORRECT_DATA;
488
        return IR_NOT_CORRECT_DATA;
484
    }
489
    }
485
   
490
   
486
    /* check startbit */
491
    /* check startbit */
487
    if (buf[0] > IR_SAMS_ST_BIT + IR_SAMS_ST_BIT/IR_SAMS_TOL_DIV || buf[0] < IR_SAMS_ST_BIT - IR_SAMS_ST_BIT/IR_SAMS_TOL_DIV) {
492
    if (buf[0] > IR_SAMS_ST_BIT + IR_SAMS_ST_BIT/IR_SAMS_TOL_DIV || buf[0] < IR_SAMS_ST_BIT - IR_SAMS_ST_BIT/IR_SAMS_TOL_DIV) {
488
        return IR_NOT_CORRECT_DATA;
493
        return IR_NOT_CORRECT_DATA;
489
    }
494
    }
490
 
495
 
491
    /* check pause after startbit */
496
    /* check pause after startbit */
492
    if (buf[1] > IR_SAMS_ST_PAUSE + IR_SAMS_ST_PAUSE/IR_SAMS_TOL_DIV || buf[1] < IR_SAMS_ST_PAUSE - IR_SAMS_ST_PAUSE/IR_SAMS_TOL_DIV) {
497
    if (buf[1] > IR_SAMS_ST_PAUSE + IR_SAMS_ST_PAUSE/IR_SAMS_TOL_DIV || buf[1] < IR_SAMS_ST_PAUSE - IR_SAMS_ST_PAUSE/IR_SAMS_TOL_DIV) {
493
        return IR_NOT_CORRECT_DATA;
498
        return IR_NOT_CORRECT_DATA;
494
    }
499
    }
Line 512... Line 517...
512
            }
517
            }
513
        }
518
        }
514
    }
519
    }
515
   
520
   
516
    proto->protocol=IR_PROTO_SAMS;
521
    proto->protocol=IR_PROTO_SAMS;
517
    proto->timeout=IR_SAMS_TIMEOUT;
522
    proto->timeout=IR_SAMS_TIMEOUT;
518
    proto->data=rawbits;   
523
    proto->data=rawbits;   
519
    return IR_OK;
524
    return IR_OK;
520
}
525
}
521
#endif
526
#endif
522
 
527
 
523
/**
528
/**
524
 * Expand data from Samsung protocol
529
 * Expand data from Samsung protocol
Line 531... Line 536...
531
 *      Pointer to length of the data
536
 *      Pointer to length of the data
532
 * @param proto
537
 * @param proto
533
 *      Pointer to protocol information
538
 *      Pointer to protocol information
534
 * @return
539
 * @return
535
 *      IR_OK if data expanded successfully, one of several errormessages if not
540
 *      IR_OK if data expanded successfully, one of several errormessages if not
536
 */
541
 */
537
int8_t expandSamsung(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto) {
542
int8_t expandSamsung(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto) {
538
    /* Set up startbit */
543
    /* Set up startbit */
539
    buf[0] = IR_SAMS_ST_BIT;
544
    buf[0] = IR_SAMS_ST_BIT;
540
    buf[1] = IR_SAMS_ST_PAUSE;
545
    buf[1] = IR_SAMS_ST_PAUSE;
541
   
546
   
542
    for (uint8_t i = 0; i < 65; i++) {
547
    for (uint8_t i = 0; i < 65; i++) {
543
        if ((i&1) == 1) {       /* if odd, ir-pause */
548
        if ((i&1) == 1) {       /* if odd, ir-pause */
544
            if ((proto->data>>(i>>1))&1) {
549
            if ((proto->data>>(i>>1))&1) {
545
                buf[i+2] = IR_SAMS_LOW_ONE;
550
                buf[i+2] = IR_SAMS_LOW_ONE;
546
            } else {
551
            } else {
547
                buf[i+2] = IR_SAMS_LOW_ZERO;
552
                buf[i+2] = IR_SAMS_LOW_ZERO;
548
            }
553
            }
549
        } else {                /* if even, ir-bit */
554
        } else {                /* if even, ir-bit */
550
            buf[i+2] = IR_SAMS_HIGH;
555
            buf[i+2] = IR_SAMS_HIGH;
551
        }
556
        }
Line 591... Line 596...
591
            halfbitscnt += 1;
596
            halfbitscnt += 1;
592
        } else if (buf[i] > IR_MARANTZ_BIT - IR_MARANTZ_BIT/IR_MARANTZ_TOL_DIV && buf[i] < IR_MARANTZ_BIT + IR_MARANTZ_BIT/IR_MARANTZ_TOL_DIV) {
597
        } else if (buf[i] > IR_MARANTZ_BIT - IR_MARANTZ_BIT/IR_MARANTZ_TOL_DIV && buf[i] < IR_MARANTZ_BIT + IR_MARANTZ_BIT/IR_MARANTZ_TOL_DIV) {
593
            halfbitscnt += 2;
598
            halfbitscnt += 2;
594
        } else if (buf[i] > IR_MARANTZ_BIT - IR_MARANTZ_BIT/IR_MARANTZ_TOL_DIV && buf[i] < 5*IR_MARANTZ_HALF_BIT + IR_MARANTZ_BIT/IR_MARANTZ_TOL_DIV) {
599
        } else if (buf[i] > IR_MARANTZ_BIT - IR_MARANTZ_BIT/IR_MARANTZ_TOL_DIV && buf[i] < 5*IR_MARANTZ_HALF_BIT + IR_MARANTZ_BIT/IR_MARANTZ_TOL_DIV) {
595
            halfbitscnt += 1; //It seems to work, not entirely sure of the purpose of this long zero though.
600
            halfbitscnt += 1; //It seems to work, not entirely sure of the purpose of this long zero though.
596
        } else {
601
        } else {
597
            return IR_NOT_CORRECT_DATA;
602
            return IR_NOT_CORRECT_DATA;
598
        }
603
        }
599
       
604
       
600
    }
605
    }
601
   
606
   
602
    proto->protocol=IR_PROTO_MARANTZ;
607
    proto->protocol=IR_PROTO_MARANTZ;
603
    proto->timeout=IR_MARANTZ_TIMEOUT;
608
    proto->timeout=IR_MARANTZ_TIMEOUT;
604
    proto->data = rawbits&0x0001ffff;
609
    proto->data = rawbits&0x0001ffff;
605
   
610
   
606
    return IR_OK;
611
    return IR_OK;
607
}
612
}
-
 
613
#endif
608
 
614
 
609
/**
615
/**
610
 * Expand data from Marantz. Written by Martin Nordn
616
 * Expand data from Marantz. Written by Martin Nordin
611
 *
617
 *
612
 * @param buf
618
 * @param buf
613
 *      Pointer to buffer to store the expanded data
619
 *      Pointer to buffer to store the expanded data
614
 * @param len
620
 * @param len
615
 *      Pointer to length of the data
621
 *      Pointer to length of the data
616
 * @param proto
622
 * @param proto
Line 646... Line 652...
646
                buf[*len-1] = IR_MARANTZ_BIT;
652
                buf[*len-1] = IR_MARANTZ_BIT;
647
                buf[*len] = IR_MARANTZ_HALF_BIT;
653
                buf[*len] = IR_MARANTZ_HALF_BIT;
648
                *len = *len + 1;
654
                *len = *len + 1;
649
            }
655
            }
650
            previousBit = 1;
656
            previousBit = 1;
651
        } else {
657
        } else {
652
            if (previousBit == 1){//10
658
            if (previousBit == 1){//10
653
                buf[*len-1] = IR_MARANTZ_BIT;
659
                buf[*len-1] = IR_MARANTZ_BIT;
654
                buf[*len] = IR_MARANTZ_HALF_BIT;
660
                buf[*len] = IR_MARANTZ_HALF_BIT;
655
                *len = *len + 1;
661
                *len = *len + 1;
656
            } else {//00
662
            } else {//00
Line 675... Line 681...
675
    proto->timeout=IR_MARANTZ_TIMEOUT;
681
    proto->timeout=IR_MARANTZ_TIMEOUT;
676
    proto->repeats=IR_MARANTZ_REPS;
682
    proto->repeats=IR_MARANTZ_REPS;
677
    return IR_OK;
683
    return IR_OK;
678
}
684
}
679
 
685
 
-
 
686
#if (IR_PROTOCOLS_USE_PANASONIC)
-
 
687
/**
-
 
688
 * Test data on Panasonic protocol
-
 
689
 *
-
 
690
 * @param buf
-
 
691
 *      Pointer to buffer to where to data to parse is stored
-
 
692
 * @param len
-
 
693
 *      Length of the data
-
 
694
 * @param proto
-
 
695
 *      Pointer to protocol information
-
 
696
 * @return
-
 
697
 *      IR_OK if data parsed successfully, one of several errormessages if not
-
 
698
 */
-
 
699
int8_t parsePanasonic(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto) {
-
 
700
    /* parse buf[], max is len */
680
 
701
 
-
 
702
    /* check if we have correct amount of data */
-
 
703
    if (len != 99) {
-
 
704
        return IR_NOT_CORRECT_DATA;
-
 
705
    }
-
 
706
   
-
 
707
    /* check startbit */
-
 
708
    if (buf[0] > IR_PANA_ST_BIT + IR_PANA_ST_BIT/IR_PANA_TOL_DIV || buf[0] < IR_PANA_ST_BIT - IR_PANA_ST_BIT/IR_PANA_TOL_DIV) {
-
 
709
        return IR_NOT_CORRECT_DATA;
-
 
710
    }
-
 
711
 
-
 
712
    /* check pause after startbit */
-
 
713
    if (buf[1] > IR_PANA_ST_PAUSE + IR_PANA_ST_PAUSE/IR_PANA_TOL_DIV || buf[1] < IR_PANA_ST_PAUSE - IR_PANA_ST_PAUSE/IR_PANA_TOL_DIV) {
-
 
714
        return IR_NOT_CORRECT_DATA;
-
 
715
    }
-
 
716
 
-
 
717
    uint32_t rawbits = 0;
-
 
718
   
-
 
719
    /* skip start bit, start bit pause and first 16 bits (32 values) */
-
 
720
    for (uint8_t i = (3+16*2); i < len; i++) {
-
 
721
        if ((i&1) == 1) {       /* if odd, ir-pause */
-
 
722
            /* check length of pause between bits */
-
 
723
            if (buf[i] > IR_PANA_LOW_ONE - IR_PANA_LOW_ONE/IR_PANA_TOL_DIV && buf[i] < IR_PANA_LOW_ONE + IR_PANA_LOW_ONE/IR_PANA_TOL_DIV) {
-
 
724
                /* write a one */
-
 
725
                rawbits |= 1UL<<((i-(3+16*2))>>1);
-
 
726
            } else if (buf[i] > IR_PANA_LOW_ZERO - IR_PANA_LOW_ZERO/IR_PANA_TOL_DIV && buf[i] < IR_PANA_LOW_ZERO + IR_PANA_LOW_ZERO/IR_PANA_TOL_DIV) {
-
 
727
                /* do nothing, a zero is already in rawbits */
-
 
728
            } else {
-
 
729
                return IR_NOT_CORRECT_DATA;
-
 
730
            }
-
 
731
        } else {            /* if even, ir-bit */
-
 
732
            if (buf[i] > IR_PANA_HIGH + IR_PANA_HIGH/IR_PANA_TOL_DIV || buf[i] < IR_PANA_HIGH - IR_PANA_HIGH/IR_PANA_TOL_DIV) {
-
 
733
                return IR_NOT_CORRECT_DATA;
-
 
734
            }
-
 
735
        }
-
 
736
    }
-
 
737
   
-
 
738
    proto->protocol=IR_PROTO_PANASONIC;
-
 
739
    proto->timeout=IR_PANA_TIMEOUT;
-
 
740
    proto->data=rawbits;   
-
 
741
    return IR_OK;
-
 
742
}
681
#endif
743
#endif
-
 
744
 
-
 
745
/**
-
 
746
 * Expand data from Panasonic protocol
-
 
747
 *
-
 
748
 * @param buf
-
 
749
 *      Pointer to buffer to store the expanded data
-
 
750
 * @param len
-
 
751
 *      Pointer to length of the data
-
 
752
 * @param proto
-
 
753
 *      Pointer to protocol information
-
 
754
 * @return
-
 
755
 *      IR_OK if data expanded successfully, one of several errormessages if not
-
 
756
 */
-
 
757
int8_t expandPanasonic(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto) {
-
 
758
    /* Set up startbit */
-
 
759
    buf[0] = IR_PANA_ST_BIT;
-
 
760
    buf[1] = IR_PANA_ST_PAUSE;
-
 
761
   
-
 
762
    /* add the first 16 static bits */
-
 
763
    uint16_t staticBits = 0x2002;
-
 
764
    for (uint8_t i = 0; i < 32; i++) {
-
 
765
        if ((i&1) == 1) {       /* if odd, ir-pause */
-
 
766
            if ((staticBits>>(i>>1))&1) {
-
 
767
                buf[i+2] = IR_PANA_LOW_ONE;
-
 
768
            } else {
-
 
769
                buf[i+2] = IR_PANA_LOW_ZERO;
-
 
770
            }
-
 
771
        } else {                /* if even, ir-bit */
-
 
772
            buf[i+2] = IR_PANA_HIGH;
-
 
773
        }
-
 
774
    }
-
 
775
   
-
 
776
    /* then add the value bits */
-
 
777
    for (uint8_t i = 0; i < 65; i++) {
-
 
778
        if ((i&1) == 1) {       /* if odd, ir-pause */
-
 
779
            if ((proto->data>>(i>>1))&1) {
-
 
780
                buf[i+2+32] = IR_PANA_LOW_ONE;
-
 
781
            } else {
-
 
782
                buf[i+2+32] = IR_PANA_LOW_ZERO;
-
 
783
            }
-
 
784
        } else {                /* if even, ir-bit */
-
 
785
            buf[i+2+32] = IR_PANA_HIGH;
-
 
786
        }
-
 
787
    }
-
 
788
   
-
 
789
    *len = 99;
-
 
790
   
-
 
791
    proto->modfreq=(((F_CPU/2000)/IR_PANA_F_MOD) -1);
-
 
792
    proto->timeout=IR_PANA_TIMEOUT;
-
 
793
    proto->repeats=IR_PANA_REPS;
-
 
794
    return IR_OK;
-
 
795
}