Subversion Repositories HomeAutomation

Rev

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

Rev 1320 Rev 1562
Line 791... Line 791...
791
    proto->modfreq=(((F_CPU/2000)/IR_PANA_F_MOD) -1);
791
    proto->modfreq=(((F_CPU/2000)/IR_PANA_F_MOD) -1);
792
    proto->timeout=IR_PANA_TIMEOUT;
792
    proto->timeout=IR_PANA_TIMEOUT;
793
    proto->repeats=IR_PANA_REPS;
793
    proto->repeats=IR_PANA_REPS;
794
    return IR_OK;
794
    return IR_OK;
795
}
795
}
-
 
796
 
-
 
797
#if (IR_PROTOCOLS_USE_SKY)
-
 
798
/**
-
 
799
 * Test data on Sky protocol
-
 
800
 *
-
 
801
 *
-
 
802
 * @param buf
-
 
803
 *      Pointer to buffer to where to data to parse is stored
-
 
804
 * @param len
-
 
805
 *      Length of the data
-
 
806
 * @param proto
-
 
807
 *      Pointer to protocol information
-
 
808
 * @return
-
 
809
 *      IR_OK if data parsed successfully, one of several errormessages if not
-
 
810
 */
-
 
811
int8_t parseSky(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto) {
-
 
812
    /* parse buf[], max is len */
-
 
813
 
-
 
814
    /* check startbit */
-
 
815
    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) {
-
 
816
        return IR_NOT_CORRECT_DATA;
-
 
817
    }
-
 
818
   
-
 
819
    uint32_t rawbits=0;
-
 
820
    uint8_t current=0;
-
 
821
    uint8_t previous=0;
-
 
822
    uint8_t cnt=0;
-
 
823
#define SKYLONG 0
-
 
824
#define SKYSHORT 1
-
 
825
    for (uint8_t i = 1; i < len; i++)
-
 
826
    {
-
 
827
        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) {
-
 
828
            current = SKYSHORT;
-
 
829
        }
-
 
830
        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) {
-
 
831
            current = SKYLONG;
-
 
832
        }
-
 
833
        else {
-
 
834
            return IR_NOT_CORRECT_DATA;
-
 
835
        }
-
 
836
       
-
 
837
        /* if level is low */
-
 
838
        if ((rawbits&1)==0) {
-
 
839
            /* and there is a long pulse */
-
 
840
            if (current == SKYLONG) {
-
 
841
                /* push a one */
-
 
842
                rawbits = rawbits<<1;
-
 
843
                rawbits |= 1;
-
 
844
                cnt = 0;
-
 
845
            }
-
 
846
            else if (cnt == 0) {
-
 
847
                cnt=1;
-
 
848
                /* push a zero */
-
 
849
                rawbits = rawbits<<1;
-
 
850
               
-
 
851
            }
-
 
852
            else {
-
 
853
                cnt = 0;
-
 
854
            }
-
 
855
        }
-
 
856
       
-
 
857
        /* if level is high */
-
 
858
        if ((rawbits&1)==1) {
-
 
859
            /* and there is a long pulse */
-
 
860
            if (current == SKYLONG) {
-
 
861
                /* push a zero */
-
 
862
                rawbits = rawbits<<1;
-
 
863
               
-
 
864
                if (previous == SKYLONG) {
-
 
865
                    cnt = 1;
-
 
866
                }
-
 
867
                else {
-
 
868
                    cnt = 0;
-
 
869
                }
-
 
870
            }
-
 
871
            else if (cnt == 0) {
-
 
872
                cnt=1;
-
 
873
                /* push a one */
-
 
874
                rawbits = rawbits<<1;
-
 
875
                rawbits |= 1;
-
 
876
            }
-
 
877
            else {
-
 
878
                cnt = 0;
-
 
879
            }
-
 
880
        }
-
 
881
       
-
 
882
        previous=current;
-
 
883
       
-
 
884
    }
-
 
885
   
-
 
886
    proto->protocol = IR_PROTO_SKY;
-
 
887
    proto->timeout = IR_SKY_TIMEOUT;
-
 
888
    proto->data = rawbits;
-
 
889
   
-
 
890
    return IR_OK;
-
 
891
}
-
 
892
#endif
-
 
893
 
-
 
894
/**
-
 
895
 * Expand data from Sky protocol
-
 
896
 *
-
 
897
 *
-
 
898
 * @param buf
-
 
899
 *      Pointer to buffer to store the expanded data
-
 
900
 * @param len
-
 
901
 *      Pointer to length of the data
-
 
902
 * @param proto
-
 
903
 *      Pointer to protocol information
-
 
904
 * @return
-
 
905
 *      IR_OK if data expanded successfully, one of several errormessages if not
-
 
906
 */
-
 
907
int8_t expandSky(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto) {
-
 
908
    //TODO: Implement this function.
-
 
909
    buf[0] = IR_SKY_ST_BIT;
-
 
910
    buf[1] = IR_SKY_LONG;   //
-
 
911
   
-
 
912
   
-
 
913
    return IR_NOT_CORRECT_DATA;
-
 
914
}
-
 
915