Subversion Repositories HomeAutomation

Rev

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

Rev 1874 Rev 1875
Line 10... Line 10...
10
#include "protocols.h"
10
#include "protocols.h"
11
#include <bios.h>
11
#include <bios.h>
12
 
12
 
13
 
13
 
14
 
14
 
15
#include <drivers/mcu/gpio.h>
15
//#include <drivers/mcu/gpio.h>
16
 
16
 
17
 
17
 
18
 
18
 
19
int8_t parseProtocol(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto) {
19
int8_t parseProtocol(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto) {
20
    proto->protocol=IR_PROTO_UNKNOWN;
20
    proto->protocol=IR_PROTO_UNKNOWN;
21
    proto->data=0;
21
    proto->data=0;
22
    proto->timeout=100;
22
    proto->timeout=1;
23
    /* Try all protocols in order. */
23
    /* Try all protocols in order. */
24
#if (IR_PROTOCOLS_USE_SIRC)
24
#if (IR_PROTOCOLS_USE_SIRC)
25
    if (parseSIRC(buf, len, proto)==IR_OK) return IR_OK;
25
    if (parseSIRC(buf, len, proto)==IR_OK) return IR_OK;
26
#endif
26
#endif
27
#if (IR_PROTOCOLS_USE_RC5)
27
#if (IR_PROTOCOLS_USE_RC5)
Line 971... Line 971...
971
    /* check if we have correct amount of data */
971
    /* check if we have correct amount of data */
972
    if (len != 148 && len != 132) {
972
    if (len != 148 && len != 132) {
973
        return IR_NOT_CORRECT_DATA;
973
        return IR_NOT_CORRECT_DATA;
974
    }
974
    }
975
 
975
 
976
    uint32_t rawbits = 0;
-
 
977
    uint64_t rawbitsTemp = 0;
-
 
978
    if (buf[0] < IR_NEXA2_START1 - IR_NEXA2_START1/IR_NEXA2_TOL_DIV && buf[0] > IR_NEXA2_START1 + IR_NEXA2_START1/IR_NEXA2_TOL_DIV) { //check start bit
976
    if (buf[0] < IR_NEXA2_START1 - IR_NEXA2_START1/IR_NEXA2_TOL_DIV && buf[0] > IR_NEXA2_START1 + IR_NEXA2_START1/IR_NEXA2_TOL_DIV) { //check start bit
979
        return IR_NOT_CORRECT_DATA;
977
        return IR_NOT_CORRECT_DATA;
980
    }
978
    }
981
    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) { //check start bit
979
    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) { //check start bit
982
        return IR_NOT_CORRECT_DATA;
980
        return IR_NOT_CORRECT_DATA;
983
    }
981
    }
984
    if (buf[2] < IR_NEXA2_START2 - IR_NEXA2_START2/IR_NEXA2_TOL_DIV && buf[2] > IR_NEXA2_START2 + IR_NEXA2_START2/IR_NEXA2_TOL_DIV) { //check start bit
982
    if (buf[2] < IR_NEXA2_START2 - IR_NEXA2_START2/IR_NEXA2_TOL_DIV && buf[2] > IR_NEXA2_START2 + IR_NEXA2_START2/IR_NEXA2_TOL_DIV) { //check start bit
985
        return IR_NOT_CORRECT_DATA;
983
        return IR_NOT_CORRECT_DATA;
986
    }
984
    }
987
 
985
 
-
 
986
    /* Incoming data could actually be longer than 32bits when a dimming command is received */
988
gpio_set_pin(EXP_H);
987
    uint32_t rawbitsTemp = 0;
989
   
-
 
990
    uint8_t bitCounter = 0;
988
    uint8_t bitCounter = 0;
991
    for (uint8_t i = 3; i < len; i++) {
989
    for (uint8_t i = 3; i < len; i++) {
992
        if ((i&1) == 0) {       /* if even, transmit */
990
        if ((i&1) == 0) {       /* if even, data */
993
            /* check length of transmit pulse */
991
            /* check length of transmit pulse */
994
            if (buf[i] > IR_NEXA2_LOW_ONE - IR_NEXA2_LOW_ONE/IR_NEXA2_TOL_DIV && buf[i] < IR_NEXA2_LOW_ONE + IR_NEXA2_LOW_ONE/IR_NEXA2_TOL_DIV) {
992
            if (buf[i] > IR_NEXA2_LOW_ONE - IR_NEXA2_LOW_ONE/IR_NEXA2_TOL_DIV && buf[i] < IR_NEXA2_LOW_ONE + IR_NEXA2_LOW_ONE/IR_NEXA2_TOL_DIV) {
995
                /* write a one */
993
                /* write a one */
996
                rawbitsTemp |= 1<<(bitCounter++);
994
                rawbitsTemp |= (1UL)<<(bitCounter++);
997
            } else if (buf[i] > IR_NEXA2_LOW_ZERO - IR_NEXA2_LOW_ZERO/IR_NEXA2_TOL_DIV && buf[i] < IR_NEXA2_LOW_ZERO + IR_NEXA2_LOW_ZERO/IR_NEXA2_TOL_DIV) {
995
            } else if (buf[i] > IR_NEXA2_LOW_ZERO - IR_NEXA2_LOW_ZERO/IR_NEXA2_TOL_DIV && buf[i] < IR_NEXA2_LOW_ZERO + IR_NEXA2_LOW_ZERO/IR_NEXA2_TOL_DIV) {
998
                /* do nothing, a zero is already in rawbits */
996
                /* do nothing, a zero is already in rawbits */
999
                bitCounter++;
997
                bitCounter++;
1000
            } else {
998
            } else {
1001
                return IR_NOT_CORRECT_DATA;
999
                return IR_NOT_CORRECT_DATA;
1002
            }
1000
            }
1003
            i+=2;   // skip every other bit, implement check here in the future
1001
            i+=2;   // skip every other bit, implement check here in the future
1004
        } else {            /* if odd, no transmit */
1002
        } else {            /* if odd, no data */
1005
            if (buf[i] < IR_NEXA2_HIGH - IR_NEXA2_HIGH/IR_NEXA2_TOL_DIV && buf[i] > IR_NEXA2_HIGH + IR_NEXA2_HIGH/IR_NEXA2_TOL_DIV) {
1003
            if (buf[i] < IR_NEXA2_HIGH - IR_NEXA2_HIGH/IR_NEXA2_TOL_DIV && buf[i] > IR_NEXA2_HIGH + IR_NEXA2_HIGH/IR_NEXA2_TOL_DIV) {
1006
                return IR_NOT_CORRECT_DATA;
1004
                return IR_NOT_CORRECT_DATA;
1007
            }
1005
            }
1008
        }
1006
        }
1009
    }
1007
    }
1010
   
-
 
1011
   
1008
   
1012
    rawbits = (uint32_t) (0xffff & rawbitsTemp);
1009
//gpio_set_pin(EXP_H);
1013
   
1010
   
1014
    proto->protocol=IR_PROTO_NEXA2;
1011
    proto->protocol=IR_PROTO_NEXA2;
1015
    proto->timeout=IR_NEXA2_TIMEOUT;
1012
    proto->timeout=IR_NEXA2_TIMEOUT;
1016
    proto->data=rawbits;
1013
    proto->data=rawbitsTemp;
1017
    return IR_OK;
1014
    return IR_OK;
1018
}
1015
}
1019
#endif
1016
#endif
1020
 
1017