Subversion Repositories HomeAutomation

Rev

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

Rev 1563 Rev 1588
Line 36... Line 36...
36
#if (IR_PROTOCOLS_USE_PANASONIC)
36
#if (IR_PROTOCOLS_USE_PANASONIC)
37
    if (parsePanasonic(buf, len, proto)==IR_OK) return IR_OK;
37
    if (parsePanasonic(buf, len, proto)==IR_OK) return IR_OK;
38
#endif
38
#endif
39
#if (IR_PROTOCOLS_USE_SKY)
39
#if (IR_PROTOCOLS_USE_SKY)
40
    if (parseSky(buf, len, proto)==IR_OK) return IR_OK;
40
    if (parseSky(buf, len, proto)==IR_OK) return IR_OK;
-
 
41
#endif
-
 
42
#if (IR_PROTOCOLS_USE_NEXA2)
-
 
43
    if (parseNexa2(buf, len, proto)==IR_OK) return IR_OK;
41
#endif
44
#endif
42
    /* No protocol matched. */
45
    /* No protocol matched. */
43
    proto->protocol = IR_PROTO_UNKNOWN;
46
    proto->protocol = IR_PROTO_UNKNOWN;
44
    return IR_NOT_CORRECT_DATA;
47
    return IR_NOT_CORRECT_DATA;
45
}
48
}
46
 
49
 
47
int8_t parseHash(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto) {
50
int8_t parseHash(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto) {
48
    //TODO: Transform the buffer in some clever way to a 32 bit word. */
51
    //TODO: Transform the buffer in some clever way to a 32 bit word. */
49
    proto->protocol = IR_PROTO_HASH;
52
    proto->protocol = IR_PROTO_HASH;
50
    proto->timeout = 200;
53
    proto->timeout = 200;
51
    proto->data = 0;
54
    proto->data = 0;
52
   
55
   
53
    return 0;
56
    return 0;
54
}
57
}
55
 
58
 
56
int8_t expandProtocol(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto) {
59
int8_t expandProtocol(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto) {
57
    /* Call the expand function for the specified protocol. */
60
    /* Call the expand function for the specified protocol. */
58
    switch (proto->protocol) {
61
    switch (proto->protocol) {
59
    case IR_PROTO_SIRC:
62
    case IR_PROTO_SIRC:
60
        return expandSIRC(buf, len, proto);
63
        return expandSIRC(buf, len, proto);
Line 78... Line 81...
78
}
81
}
79
 
82
 
80
#if (IR_PROTOCOLS_USE_SIRC)
83
#if (IR_PROTOCOLS_USE_SIRC)
81
/**
84
/**
82
 * Test data on SIRC protocol, 12-bit version
85
 * Test data on SIRC protocol, 12-bit version
83
 * http://www.sbprojects.com/knowledge/ir/sirc.htm
86
 * http://www.sbprojects.com/knowledge/ir/sirc.htm
84
 *
87
 *
85
 * @param buf
88
 * @param buf
86
 *      Pointer to buffer to where to data to parse is stored
89
 *      Pointer to buffer to where to data to parse is stored
87
 * @param len
90
 * @param len
88
 *      Length of the data
91
 *      Length of the data
Line 91... Line 94...
91
 * @return
94
 * @return
92
 *      IR_OK if data parsed successfully, one of several errormessages if not
95
 *      IR_OK if data parsed successfully, one of several errormessages if not
93
 */
96
 */
94
int8_t parseSIRC(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto) {
97
int8_t parseSIRC(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto) {
95
    /* parse buf[], max is len */
98
    /* parse buf[], max is len */
96
 
99
 
97
    /* check if we have correct amount of data */
100
    /* check if we have correct amount of data */
98
    if (len != 25) {
101
    if (len != 25) {
99
        return IR_NOT_CORRECT_DATA;
102
        return IR_NOT_CORRECT_DATA;
100
    }
103
    }
101
   
104
   
Line 120... Line 123...
120
                /* do nothing, a zero is already in rawbits */
123
                /* do nothing, a zero is already in rawbits */
121
            } else {
124
            } else {
122
                return IR_NOT_CORRECT_DATA;
125
                return IR_NOT_CORRECT_DATA;
123
            }
126
            }
124
        }
127
        }
125
    }
128
    }
126
   
129
   
127
    proto->protocol = IR_PROTO_SIRC;
130
    proto->protocol = IR_PROTO_SIRC;
128
    proto->timeout = IR_SIRC_TIMEOUT;
131
    proto->timeout = IR_SIRC_TIMEOUT;
129
    proto->data = rawbits;
132
    proto->data = rawbits;
130
   
133
   
Line 146... Line 149...
146
 *      IR_OK if data expanded successfully, one of several errormessages if not
149
 *      IR_OK if data expanded successfully, one of several errormessages if not
147
 */
150
 */
148
int8_t expandSIRC(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto) {
151
int8_t expandSIRC(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto) {
149
    //TODO: Implement this function.
152
    //TODO: Implement this function.
150
    buf[0] = IR_SIRC_ST_BIT;
153
    buf[0] = IR_SIRC_ST_BIT;
151
    buf[1] = IR_SIRC_LOW;//start pulse finished
154
    buf[1] = IR_SIRC_LOW;//start pulse finished
152
   
155
   
153
   
156
   
154
   
157
   
155
    return IR_NOT_CORRECT_DATA;
158
    return IR_NOT_CORRECT_DATA;
156
}
159
}
Line 471... Line 474...
471
 
474
 
472
 
475
 
473
#if (IR_PROTOCOLS_USE_SAMSUNG)
476
#if (IR_PROTOCOLS_USE_SAMSUNG)
474
/**
477
/**
475
 * Test data on Samsung protocol
478
 * Test data on Samsung protocol
476
 * Very much like NEC, different start bit/pause lengths etc.
479
 * Very much like NEC, different start bit/pause lengths etc.
477
 * http://www.sbprojects.com/knowledge/ir/nec.htm
480
 * http://www.sbprojects.com/knowledge/ir/nec.htm
478
 *
481
 *
479
 * @param buf
482
 * @param buf
480
 *      Pointer to buffer to where to data to parse is stored
483
 *      Pointer to buffer to where to data to parse is stored
481
 * @param len
484
 * @param len
482
 *      Length of the data
485
 *      Length of the data
483
 * @param proto
486
 * @param proto
484
 *      Pointer to protocol information
487
 *      Pointer to protocol information
485
 * @return
488
 * @return
Line 488... Line 491...
488
int8_t parseSamsung(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto) {
491
int8_t parseSamsung(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto) {
489
    /* parse buf[], max is len */
492
    /* parse buf[], max is len */
490
 
493
 
491
    /* check if we have correct amount of data */
494
    /* check if we have correct amount of data */
492
    if (len != 67) {
495
    if (len != 67) {
493
        return IR_NOT_CORRECT_DATA;
496
        return IR_NOT_CORRECT_DATA;
494
    }
497
    }
495
   
498
   
496
    /* check startbit */
499
    /* check startbit */
497
    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) {
500
    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) {
498
        return IR_NOT_CORRECT_DATA;
501
        return IR_NOT_CORRECT_DATA;
499
    }
502
    }
Line 519... Line 522...
519
        } else {            /* if even, ir-bit */
522
        } else {            /* if even, ir-bit */
520
            if (buf[i] > IR_SAMS_HIGH + IR_SAMS_HIGH/IR_SAMS_TOL_DIV || buf[i] < IR_SAMS_HIGH - IR_SAMS_HIGH/IR_SAMS_TOL_DIV) {
523
            if (buf[i] > IR_SAMS_HIGH + IR_SAMS_HIGH/IR_SAMS_TOL_DIV || buf[i] < IR_SAMS_HIGH - IR_SAMS_HIGH/IR_SAMS_TOL_DIV) {
521
                return IR_NOT_CORRECT_DATA;
524
                return IR_NOT_CORRECT_DATA;
522
            }
525
            }
523
        }
526
        }
524
    }
527
    }
525
   
528
   
526
    proto->protocol=IR_PROTO_SAMS;
529
    proto->protocol=IR_PROTO_SAMS;
527
    proto->timeout=IR_SAMS_TIMEOUT;
530
    proto->timeout=IR_SAMS_TIMEOUT;
528
    proto->data=rawbits;   
531
    proto->data=rawbits;   
529
    return IR_OK;
532
    return IR_OK;
Line 558... Line 561...
558
            }
561
            }
559
        } else {                /* if even, ir-bit */
562
        } else {                /* if even, ir-bit */
560
            buf[i+2] = IR_SAMS_HIGH;
563
            buf[i+2] = IR_SAMS_HIGH;
561
        }
564
        }
562
    }
565
    }
563
   
566
   
564
    *len = 67;
567
    *len = 67;
565
   
568
   
566
    proto->modfreq=(((F_CPU/2000)/IR_SAMS_F_MOD) -1);
569
    proto->modfreq=(((F_CPU/2000)/IR_SAMS_F_MOD) -1);
567
    proto->timeout=IR_SAMS_TIMEOUT;
570
    proto->timeout=IR_SAMS_TIMEOUT;
568
    proto->repeats=IR_SAMS_REPS;
571
    proto->repeats=IR_SAMS_REPS;
Line 585... Line 588...
585
 * @return
588
 * @return
586
 *      IR_OK if data parsed successfully, one of several errormessages if not
589
 *      IR_OK if data parsed successfully, one of several errormessages if not
587
 */
590
 */
588
int8_t parseMarantz(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto) {
591
int8_t parseMarantz(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto) {
589
    uint8_t halfbitscnt = 1;
592
    uint8_t halfbitscnt = 1;
590
    uint32_t rawbits = 0;
593
    uint32_t rawbits = 0;
591
   
594
   
592
    for (uint8_t i = 0; i<len; i++) {
595
    for (uint8_t i = 0; i<len; i++) {
593
        //halfbitscnt&1==1 in the middle of bits
596
        //halfbitscnt&1==1 in the middle of bits
594
        //i&1==0 positive flank
597
        //i&1==0 positive flank
595
 
598
 
Line 610... Line 613...
610
    }
613
    }
611
   
614
   
612
    proto->protocol=IR_PROTO_MARANTZ;
615
    proto->protocol=IR_PROTO_MARANTZ;
613
    proto->timeout=IR_MARANTZ_TIMEOUT;
616
    proto->timeout=IR_MARANTZ_TIMEOUT;
614
    proto->data = rawbits&0x0001ffff;
617
    proto->data = rawbits&0x0001ffff;
615
   
618
   
616
    return IR_OK;
619
    return IR_OK;
617
}
620
}
618
#endif
621
#endif
619
 
622
 
620
/**
623
/**
Line 622... Line 625...
622
 *
625
 *
623
 * @param buf
626
 * @param buf
624
 *      Pointer to buffer to store the expanded data
627
 *      Pointer to buffer to store the expanded data
625
 * @param len
628
 * @param len
626
 *      Pointer to length of the data
629
 *      Pointer to length of the data
627
 * @param proto
630
 * @param proto
628
 *      Pointer to protocol information
631
 *      Pointer to protocol information
629
 * @return
632
 * @return
630
 *      IR_OK if data expanded successfully, one of several errormessages if not
633
 *      IR_OK if data expanded successfully, one of several errormessages if not
631
 */
634
 */
632
int8_t expandMarantz(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto) {
635
int8_t expandMarantz(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto) {
633
    uint8_t previousBit;
636
    uint8_t previousBit;
Line 648... Line 651...
648
    for(uint8_t i = 0; i < 17; i++) {
651
    for(uint8_t i = 0; i < 17; i++) {
649
        tempdata = (uint32_t)tempdata<<1;
652
        tempdata = (uint32_t)tempdata<<1;
650
 
653
 
651
        if (((uint32_t)tempdata>>31)==1){
654
        if (((uint32_t)tempdata>>31)==1){
652
            if (previousBit == 1){//11
655
            if (previousBit == 1){//11
653
                buf[*len] = IR_MARANTZ_HALF_BIT;
656
                buf[*len] = IR_MARANTZ_HALF_BIT;
654
                buf[*len+1] = IR_MARANTZ_HALF_BIT;
657
                buf[*len+1] = IR_MARANTZ_HALF_BIT;
655
                *len = *len + 2;
658
                *len = *len + 2;
656
            } else {//01
659
            } else {//01
657
                buf[*len-1] = IR_MARANTZ_BIT;
660
                buf[*len-1] = IR_MARANTZ_BIT;
658
                buf[*len] = IR_MARANTZ_HALF_BIT;
661
                buf[*len] = IR_MARANTZ_HALF_BIT;
659
                *len = *len + 1;
662
                *len = *len + 1;
Line 689... Line 692...
689
}
692
}
690
 
693
 
691
#if (IR_PROTOCOLS_USE_PANASONIC)
694
#if (IR_PROTOCOLS_USE_PANASONIC)
692
/**
695
/**
693
 * Test data on Panasonic protocol
696
 * Test data on Panasonic protocol
694
 *
697
 *
695
 * @param buf
698
 * @param buf
696
 *      Pointer to buffer to where to data to parse is stored
699
 *      Pointer to buffer to where to data to parse is stored
697
 * @param len
700
 * @param len
698
 *      Length of the data
701
 *      Length of the data
699
 * @param proto
702
 * @param proto
700
 *      Pointer to protocol information
703
 *      Pointer to protocol information
701
 * @return
704
 * @return
702
 *      IR_OK if data parsed successfully, one of several errormessages if not
705
 *      IR_OK if data parsed successfully, one of several errormessages if not
703
 */
706
 */
704
int8_t parsePanasonic(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto) {
707
int8_t parsePanasonic(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto) {
705
    /* parse buf[], max is len */
708
    /* parse buf[], max is len */
706
 
709
 
707
    /* check if we have correct amount of data */
710
    /* check if we have correct amount of data */
708
    if (len != 99) {
711
    if (len != 99) {
709
        return IR_NOT_CORRECT_DATA;
712
        return IR_NOT_CORRECT_DATA;
710
    }
713
    }
711
   
714
   
712
    /* check startbit */
715
    /* check startbit */
713
    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) {
716
    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) {
714
        return IR_NOT_CORRECT_DATA;
717
        return IR_NOT_CORRECT_DATA;
715
    }
718
    }
716
 
719
 
717
    /* check pause after startbit */
720
    /* check pause after startbit */
718
    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) {
721
    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) {
719
        return IR_NOT_CORRECT_DATA;
722
        return IR_NOT_CORRECT_DATA;
Line 734... Line 737...
734
                return IR_NOT_CORRECT_DATA;
737
                return IR_NOT_CORRECT_DATA;
735
            }
738
            }
736
        } else {            /* if even, ir-bit */
739
        } else {            /* if even, ir-bit */
737
            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) {
740
            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) {
738
                return IR_NOT_CORRECT_DATA;
741
                return IR_NOT_CORRECT_DATA;
739
            }
742
            }
740
        }
743
        }
741
    }
744
    }
742
   
745
   
743
    proto->protocol=IR_PROTO_PANASONIC;
746
    proto->protocol=IR_PROTO_PANASONIC;
744
    proto->timeout=IR_PANA_TIMEOUT;
747
    proto->timeout=IR_PANA_TIMEOUT;
745
    proto->data=rawbits;   
748
    proto->data=rawbits;   
746
    return IR_OK;
749
    return IR_OK;
747
}
750
}
Line 800... Line 803...
800
}
803
}
801
 
804
 
802
#if (IR_PROTOCOLS_USE_SKY)
805
#if (IR_PROTOCOLS_USE_SKY)
803
/**
806
/**
804
 * Test data on Sky protocol
807
 * Test data on Sky protocol
805
 *
808
 *
806
 *
809
 *
807
 * @param buf
810
 * @param buf
808
 *      Pointer to buffer to where to data to parse is stored
811
 *      Pointer to buffer to where to data to parse is stored
809
 * @param len
812
 * @param len
810
 *      Length of the data
813
 *      Length of the data
811
 * @param proto
814
 * @param proto
812
 *      Pointer to protocol information
815
 *      Pointer to protocol information
813
 * @return
816
 * @return
814
 *      IR_OK if data parsed successfully, one of several errormessages if not
817
 *      IR_OK if data parsed successfully, one of several errormessages if not
815
 */
818
 */
816
int8_t parseSky(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto) {
819
int8_t parseSky(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto) {
817
    /* parse buf[], max is len */
820
    /* parse buf[], max is len */
818
 
821
 
819
    /* check startbit */
822
    /* check startbit */
820
    if (buf[0] > IR_SKY_ST_BIT + IR_SKY_ST_BIT/IR_SKY_TOL_DIV || buf[0] < IR_SKY_ST_BIT - IR_SKY_ST_BIT/IR_SKY_TOL_DIV) {
823
    if (buf[0] > IR_SKY_ST_BIT + IR_SKY_ST_BIT/IR_SKY_TOL_DIV || buf[0] < IR_SKY_ST_BIT - IR_SKY_ST_BIT/IR_SKY_TOL_DIV) {
821
        return IR_NOT_CORRECT_DATA;
824
        return IR_NOT_CORRECT_DATA;
822
    }
825
    }
823
   
826
   
824
    uint32_t rawbits=0;
827
    uint32_t rawbits=0;
825
    uint8_t current=0;
828
    uint8_t current=0;
826
    uint8_t previous=0;
829
    uint8_t previous=0;
827
    uint8_t cnt=0;
830
    uint8_t cnt=0;
828
#define SKYLONG 0
831
#define SKYLONG 0
829
#define SKYSHORT 1
832
#define SKYSHORT 1
Line 832... Line 835...
832
        if (buf[i] > IR_SKY_SHORT - IR_SKY_SHORT/IR_SKY_TOL_DIV && buf[i] < IR_SKY_SHORT + IR_SKY_SHORT/IR_SKY_TOL_DIV) {
835
        if (buf[i] > IR_SKY_SHORT - IR_SKY_SHORT/IR_SKY_TOL_DIV && buf[i] < IR_SKY_SHORT + IR_SKY_SHORT/IR_SKY_TOL_DIV) {
833
            current = SKYSHORT;
836
            current = SKYSHORT;
834
        }
837
        }
835
        else if (buf[i] > IR_SKY_LONG - IR_SKY_LONG/IR_SKY_TOL_DIV && buf[i] < IR_SKY_LONG + IR_SKY_LONG/IR_SKY_TOL_DIV) {
838
        else if (buf[i] > IR_SKY_LONG - IR_SKY_LONG/IR_SKY_TOL_DIV && buf[i] < IR_SKY_LONG + IR_SKY_LONG/IR_SKY_TOL_DIV) {
836
            current = SKYLONG;
839
            current = SKYLONG;
837
        }
840
        }
838
        else {
841
        else {
839
            return IR_NOT_CORRECT_DATA;
842
            return IR_NOT_CORRECT_DATA;
840
        }
843
        }
841
       
844
       
842
        /* if level is low */
845
        /* if level is low */
843
        if ((rawbits&1)==0) {
846
        if ((rawbits&1)==0) {
844
            /* and there is a long pulse */
847
            /* and there is a long pulse */
845
            if (current == SKYLONG) {
848
            if (current == SKYLONG) {
846
                /* push a one */
849
                /* push a one */
847
                rawbits = rawbits<<1;
850
                rawbits = rawbits<<1;
848
                rawbits |= 1;
851
                rawbits |= 1;
849
                cnt = 0;
852
                cnt = 0;
850
            }
853
            }
851
            else if (cnt == 0) {
854
            else if (cnt == 0) {
852
                cnt=1;
855
                cnt=1;
853
                /* push a zero */
856
                /* push a zero */
854
                rawbits = rawbits<<1;
857
                rawbits = rawbits<<1;
855
               
858
               
856
            }
859
            }
Line 915... Line 918...
915
    buf[1] = IR_SKY_LONG;   //
918
    buf[1] = IR_SKY_LONG;   //
916
   
919
   
917
   
920
   
918
    return IR_NOT_CORRECT_DATA;
921
    return IR_NOT_CORRECT_DATA;
919
}
922
}
-
 
923
 
-
 
924
#if (IR_PROTOCOLS_USE_NEXA2)
-
 
925
/**
-
 
926
 * Test data on NEXA protocol
-
 
927
 * http://elektronikforumet.com/wiki/index.php?title=RF_Protokoll_-_Nexa_sj%C3%A4lvl%C3%A4rande
-
 
928
 *
-
 
929
 * @param buf
-
 
930
 *      Pointer to buffer to where to data to parse is stored
-
 
931
 * @param len
-
 
932
 *      Length of the data
-
 
933
 * @param proto
-
 
934
 *      Pointer to protocol information
-
 
935
 * @return
-
 
936
 *      IR_OK if data parsed successfully, one of several errormessages if not
-
 
937
 */
-
 
938
int8_t parseNexa2(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto) {
-
 
939
    /* parse buf[], max is len */
-
 
940
 
-
 
941
    /* check if we have correct amount of data */
-
 
942
    if (len != 146 || len != 130) {
-
 
943
        return IR_NOT_CORRECT_DATA;
-
 
944
    }
-
 
945
   
-
 
946
    uint32_t rawbits = 0;
-
 
947
    uint64_t rawbitsTemp = 0;
-
 
948
    if (buf[1] < IR_NEXA2_START - IR_NEXA2_START/IR_NEXA2_TOL_DIV && buf[1] > IR_NEXA2_START + IR_NEXA2_START/IR_NEXA2_TOL_DIV) { //check start bit
-
 
949
        return IR_NOT_CORRECT_DATA;
-
 
950
    }
-
 
951
     
-
 
952
      uint8_t bitCounter = 0;
-
 
953
    for (uint8_t i = 2; i < len; i++) { //Skip first bit
-
 
954
        if ((i&1) == 1) {       /* if odd, ir-pause */
-
 
955
            /* check length of pause between bits */
-
 
956
            if (buf[1] > IR_NEXA2_LOW_ONE - IR_NEXA2_LOW_ONE/IR_NEXA2_TOL_DIV && buf[1] < IR_NEXA2_LOW_ONE + IR_NEXA2_LOW_ONE/IR_NEXA2_TOL_DIV) {
-
 
957
                /* write a one */
-
 
958
                rawbitsTemp |= 1<<(bitCounter++);
-
 
959
            } else if (buf[1] > IR_NEXA2_LOW_ZERO - IR_NEXA2_LOW_ZERO/IR_NEXA2_TOL_DIV && buf[1] < IR_NEXA2_LOW_ZERO + IR_NEXA2_LOW_ZERO/IR_NEXA2_TOL_DIV) {
-
 
960
                /* do nothing, a zero is already in rawbits */
-
 
961
                bitCounter++;
-
 
962
            } else {
-
 
963
                return IR_NOT_CORRECT_DATA;
-
 
964
            }
-
 
965
            i+=2;   // skip every other bit,implement check here in the future
-
 
966
        } else {            /* if even, ir-bit */
-
 
967
            if (buf[1] < IR_NEXA2_HIGH - IR_NEXA2_HIGH/IR_NEXA2_TOL_DIV && buf[1] > IR_NEXA2_HIGH + IR_NEXA2_HIGH/IR_NEXA2_TOL_DIV) {
-
 
968
                return IR_NOT_CORRECT_DATA;
-
 
969
            }
-
 
970
        }
-
 
971
    }
-
 
972
   
-
 
973
   
-
 
974
    rawbits = (uint32_t) (0xffff & rawbitsTemp);
-
 
975
   
-
 
976
    proto->protocol=IR_PROTO_NEXA2;
-
 
977
    proto->timeout=IR_NEXA2_TIMEOUT;
-
 
978
    proto->data=rawbits;
-
 
979
    return IR_OK;
-
 
980
}
-
 
981
#endif
920
 
982