X-Git-Url: http://cloudbase.mooo.com/gitweb/irmp.git/blobdiff_plain/6f153888f708dc80351c5048ca3f98125563df8a..8aaafe9d1b78f92e33e2791a8aa5e0aa877975b9:/irmp.c diff --git a/irmp.c b/irmp.c index 0753e0d..018bb7f 100644 --- a/irmp.c +++ b/irmp.c @@ -1,13 +1,11 @@ /*--------------------------------------------------------------------------------------------------------------------------------------------------- * irmp.c - infrared multi-protocol decoder, supports several remote control protocols * - * Copyright (c) 2009-2013 Frank Meyer - frank(at)fli4l.de + * Copyright (c) 2009-2014 Frank Meyer - frank(at)fli4l.de * - * $Id: irmp.c,v 1.155 2014/07/01 09:43:13 fm Exp $ + * $Id: irmp.c,v 1.164 2014/09/15 12:36:28 fm Exp $ * - * ATMEGA88 @ 8 MHz - * - * Supported mikrocontrollers: + * Supported AVR mikrocontrollers: * * ATtiny87, ATtiny167 * ATtiny45, ATtiny85 @@ -145,10 +143,10 @@ #define MATSUSHITA_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * MATSUSHITA_0_PAUSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1) #define MATSUSHITA_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * MATSUSHITA_0_PAUSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1) -#define KASEIKYO_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * KASEIKYO_START_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) -#define KASEIKYO_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * KASEIKYO_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) -#define KASEIKYO_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * KASEIKYO_START_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) -#define KASEIKYO_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * KASEIKYO_START_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) +#define KASEIKYO_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * KASEIKYO_START_BIT_PULSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1) +#define KASEIKYO_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * KASEIKYO_START_BIT_PULSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1) +#define KASEIKYO_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * KASEIKYO_START_BIT_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1) +#define KASEIKYO_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * KASEIKYO_START_BIT_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1) #define KASEIKYO_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * KASEIKYO_PULSE_TIME * MIN_TOLERANCE_50 + 0.5) - 1) #define KASEIKYO_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * KASEIKYO_PULSE_TIME * MAX_TOLERANCE_50 + 0.5) + 1) #define KASEIKYO_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * KASEIKYO_1_PAUSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1) @@ -498,51 +496,98 @@ static void (*irmp_callback_ptr) (uint8_t); *--------------------------------------------------------------------------------------------------------------------------------------------------- */ #if defined(UNIX_OR_WINDOWS) || IRMP_PROTOCOL_NAMES == 1 -char * -irmp_protocol_names[IRMP_N_PROTOCOLS + 1] = +static const char proto_unknown[] PROGMEM = "UNKNOWN"; +static const char proto_sircs[] PROGMEM = "SIRCS"; +static const char proto_nec[] PROGMEM = "NEC"; +static const char proto_samsung[] PROGMEM = "SAMSUNG"; +static const char proto_matsushita[] PROGMEM = "MATSUSH"; +static const char proto_kaseikyo[] PROGMEM = "KASEIKYO"; +static const char proto_recs80[] PROGMEM = "RECS80"; +static const char proto_rc5[] PROGMEM = "RC5"; +static const char proto_denon[] PROGMEM = "DENON"; +static const char proto_rc6[] PROGMEM = "RC6"; +static const char proto_samsung32[] PROGMEM = "SAMSG32"; +static const char proto_apple[] PROGMEM = "APPLE"; +static const char proto_recs80ext[] PROGMEM = "RECS80EX"; +static const char proto_nubert[] PROGMEM = "NUBERT"; +static const char proto_bang_olufsen[] PROGMEM = "BANG OLU"; +static const char proto_grundig[] PROGMEM = "GRUNDIG"; +static const char proto_nokia[] PROGMEM = "NOKIA"; +static const char proto_siemens[] PROGMEM = "SIEMENS"; +static const char proto_fdc[] PROGMEM = "FDC"; +static const char proto_rccar[] PROGMEM = "RCCAR"; +static const char proto_jvc[] PROGMEM = "JVC"; +static const char proto_rc6a[] PROGMEM = "RC6A"; +static const char proto_nikon[] PROGMEM = "NIKON"; +static const char proto_ruwido[] PROGMEM = "RUWIDO"; +static const char proto_ir60[] PROGMEM = "IR60"; +static const char proto_kathrein[] PROGMEM = "KATHREIN"; +static const char proto_netbox[] PROGMEM = "NETBOX"; +static const char proto_nec16[] PROGMEM = "NEC16"; +static const char proto_nec42[] PROGMEM = "NEC42"; +static const char proto_lego[] PROGMEM = "LEGO"; +static const char proto_thomson[] PROGMEM = "THOMSON"; +static const char proto_bose[] PROGMEM = "BOSE"; +static const char proto_a1tvbox[] PROGMEM = "A1TVBOX"; +static const char proto_ortek[] PROGMEM = "ORTEK"; +static const char proto_telefunken[] PROGMEM = "TELEFUNKEN"; +static const char proto_roomba[] PROGMEM = "ROOMBA"; +static const char proto_rcmm32[] PROGMEM = "RCMM32"; +static const char proto_rcmm24[] PROGMEM = "RCMM24"; +static const char proto_rcmm12[] PROGMEM = "RCMM12"; +static const char proto_speaker[] PROGMEM = "SPEAKER"; +static const char proto_lgair[] PROGMEM = "LGAIR"; +static const char proto_samsung48[] PROGMEM = "SAMSG48"; + +static const char proto_radio1[] PROGMEM = "RADIO1"; + +const char * const +irmp_protocol_names[IRMP_N_PROTOCOLS + 1] PROGMEM = { - "UNKNOWN", - "SIRCS", - "NEC", - "SAMSUNG", - "MATSUSH", - "KASEIKYO", - "RECS80", - "RC5", - "DENON", - "RC6", - "SAMSG32", - "APPLE", - "RECS80EX", - "NUBERT", - "BANG OLU", - "GRUNDIG", - "NOKIA", - "SIEMENS", - "FDC", - "RCCAR", - "JVC", - "RC6A", - "NIKON", - "RUWIDO", - "IR60", - "KATHREIN", - "NETBOX", - "NEC16", - "NEC42", - "LEGO", - "THOMSON", - "BOSE", - "A1TVBOX", - "ORTEK", - "TELEFUNKEN", - "ROOMBA", - "RCMM32", - "RCMM24", - "RCMM12", - "SPEAKER", - "LGAIR", - "RADIO1" + proto_unknown, + proto_sircs, + proto_nec, + proto_samsung, + proto_matsushita, + proto_kaseikyo, + proto_recs80, + proto_rc5, + proto_denon, + proto_rc6, + proto_samsung32, + proto_apple, + proto_recs80ext, + proto_nubert, + proto_bang_olufsen, + proto_grundig, + proto_nokia, + proto_siemens, + proto_fdc, + proto_rccar, + proto_jvc, + proto_rc6a, + proto_nikon, + proto_ruwido, + proto_ir60, + proto_kathrein, + proto_netbox, + proto_nec16, + proto_nec42, + proto_lego, + proto_thomson, + proto_bose, + proto_a1tvbox, + proto_ortek, + proto_telefunken, + proto_roomba, + proto_rcmm32, + proto_rcmm24, + proto_rcmm12, + proto_speaker, + proto_lgair, + proto_samsung48, + + proto_radio1 }; #endif @@ -736,79 +781,6 @@ irmp_uart_putc (unsigned char ch) #define ENDBITS 1000 // number of sequenced highbits to detect end #define DATALEN 700 // log buffer size -#if 0 // old log routine - -static void -irmp_log (uint8_t val) -{ - static uint8_t buf[DATALEN]; // logging buffer - static uint16_t buf_idx; // number of written bits - static uint8_t startcycles; // current number of start-zeros - static uint16_t cnt; // counts sequenced highbits - to detect end - - if (! val && (startcycles < STARTCYCLES) && !buf_idx) // prevent that single random zeros init logging - { - startcycles++; - } - else - { - startcycles = 0; - - if (! val || (val && buf_idx != 0)) // start or continue logging on "0", "1" cannot init logging - { - if (buf_idx < DATALEN * 8) // index in range? - { // yes - if (val) - { - buf[(buf_idx / 8)] |= (1<<(buf_idx % 8)); // set bit - } - else - { - buf[(buf_idx / 8)] &= ~(1<<(buf_idx % 8)); // reset bit - } - - buf_idx++; - } - - if (val) - { // if high received then look at log-stop condition - cnt++; - - if (cnt > ENDBITS) - { // if stop condition is true, output on uart - uint16_t i; - - for (i = 0; i < STARTCYCLES; i++) - { - irmp_uart_putc ('0'); // the ignored starting zeros - } - - for (i = 0; i < (buf_idx - ENDBITS + 20) / 8; i++) // transform bitset into uart chars - { - uint8_t d = buf[i]; - uint8_t j; - - for (j = 0; j < 8; j++) - { - irmp_uart_putc ((d & 1) + '0'); - d >>= 1; - } - } - - irmp_uart_putc ('\n'); - buf_idx = 0; - } - } - else - { - cnt = 0; - } - } - } -} - -#else // new log routine - static void irmp_log (uint8_t val) { @@ -897,8 +869,6 @@ irmp_log (uint8_t val) } } -#endif - #else #define irmp_log(val) #endif //IRMP_LOGGING @@ -1735,7 +1705,7 @@ static IRMP_PARAMETER irmp_param; static IRMP_PARAMETER irmp_param2; #endif -static volatile uint8_t irmp_ir_detected; +static volatile uint8_t irmp_ir_detected = FALSE; static volatile uint8_t irmp_protocol; static volatile uint16_t irmp_address; static volatile uint16_t irmp_command; @@ -1827,7 +1797,15 @@ irmp_get_data (IRMP_DATA * irmp_data_p) rtc = TRUE; } break; + +#if IRMP_SUPPORT_SAMSUNG48_PROTOCOL == 1 + case IRMP_SAMSUNG48_PROTOCOL: + irmp_command = (irmp_command & 0x00FF) | ((irmp_id & 0x00FF) << 8); + rtc = TRUE; + break; #endif +#endif + #if IRMP_SUPPORT_NEC_PROTOCOL == 1 case IRMP_NEC_PROTOCOL: if ((irmp_command >> 8) == (~irmp_command & 0x00FF)) @@ -2001,7 +1979,7 @@ irmp_set_callback_ptr (void (*cb)(uint8_t)) static uint16_t irmp_tmp_address; // ir address static uint16_t irmp_tmp_command; // ir command -#if IRMP_SUPPORT_RC5_PROTOCOL == 1 && (IRMP_SUPPORT_FDC_PROTOCOL == 1 || IRMP_SUPPORT_RCCAR_PROTOCOL == 1) || IRMP_SUPPORT_NEC42_PROTOCOL == 1 +#if (IRMP_SUPPORT_RC5_PROTOCOL == 1 && (IRMP_SUPPORT_FDC_PROTOCOL == 1 || IRMP_SUPPORT_RCCAR_PROTOCOL == 1)) || IRMP_SUPPORT_NEC42_PROTOCOL == 1 static uint16_t irmp_tmp_address2; // ir address static uint16_t irmp_tmp_command2; // ir command #endif @@ -2097,7 +2075,16 @@ irmp_store_bit (uint8_t value) { if (irmp_param.lsb_first) { - irmp_tmp_command |= (((uint16_t) (value)) << (irmp_bit - irmp_param.command_offset)); // CV wants cast +#if IRMP_SUPPORT_SAMSUNG48_PROTOCOL == 1 + if (irmp_param.protocol == IRMP_SAMSUNG48_PROTOCOL && irmp_bit >= 32) + { + irmp_tmp_id |= (((uint16_t) (value)) << (irmp_bit - 32)); // CV wants cast + } + else +#endif + { + irmp_tmp_command |= (((uint16_t) (value)) << (irmp_bit - irmp_param.command_offset)); // CV wants cast + } } else { @@ -2284,6 +2271,9 @@ irmp_ISR (void) #if IRMP_SUPPORT_KASEIKYO_PROTOCOL == 1 genre2 = 0; #endif +#if IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1 + irmp_tmp_id = 0; +#endif #if IRMP_SUPPORT_RC5_PROTOCOL == 1 && (IRMP_SUPPORT_FDC_PROTOCOL == 1 || IRMP_SUPPORT_RCCAR_PROTOCOL == 1) || IRMP_SUPPORT_NEC42_PROTOCOL == 1 irmp_tmp_command2 = 0; @@ -2314,8 +2304,8 @@ irmp_ISR (void) { #ifdef ANALYZE ANALYZE_PRINTF ("%8.3fms warning: did not receive inverted command repetition\n", -#endif // ANALYZE (double) (time_counter * 1000) / F_INTERRUPTS); +#endif // ANALYZE last_irmp_denon_command = 0; denon_repetition_len = 0xFFFF; } @@ -2361,7 +2351,8 @@ irmp_ISR (void) } else { // receiving first data pulse! - IRMP_PARAMETER * irmp_param_p = (IRMP_PARAMETER *) 0; + IRMP_PARAMETER * irmp_param_p; + irmp_param_p = (IRMP_PARAMETER *) 0; #if IRMP_SUPPORT_RC5_PROTOCOL == 1 && (IRMP_SUPPORT_FDC_PROTOCOL == 1 || IRMP_SUPPORT_RCCAR_PROTOCOL == 1) irmp_param2.protocol = 0; @@ -3358,6 +3349,20 @@ irmp_ISR (void) } #endif // IRMP_SUPPORT_JVC_PROTOCOL == 1 #endif // IRMP_SUPPORT_NEC42_PROTOCOL == 1 + +#if IRMP_SUPPORT_SAMSUNG48_PROTOCOL == 1 + else if (irmp_param.protocol == IRMP_SAMSUNG48_PROTOCOL && irmp_bit == 32) // it was a SAMSUNG32 stop bit + { +#ifdef ANALYZE + ANALYZE_PRINTF ("Switching to SAMSUNG32 protocol\n"); +#endif // ANALYZE + irmp_param.protocol = IRMP_SAMSUNG32_PROTOCOL; + irmp_param.command_offset = SAMSUNG32_COMMAND_OFFSET; + irmp_param.command_end = SAMSUNG32_COMMAND_OFFSET + SAMSUNG32_COMMAND_LEN; + irmp_param.complete_len = SAMSUNG32_COMPLETE_DATA_LEN; + } +#endif // IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1 + #if IRMP_SUPPORT_RCMM_PROTOCOL == 1 else if (irmp_param.protocol == IRMP_RCMM32_PROTOCOL && (irmp_bit == 12 || irmp_bit == 24)) // it was a RCMM stop bit { @@ -3689,16 +3694,27 @@ irmp_ISR (void) ANALYZE_PRINTF ("SYNC\n"); #endif // ANALYZE wait_for_space = 0; - irmp_tmp_id = 0; irmp_bit++; } else if (irmp_pulse_time >= SAMSUNG_PULSE_LEN_MIN && irmp_pulse_time <= SAMSUNG_PULSE_LEN_MAX) { +#if IRMP_SUPPORT_SAMSUNG48_PROTOCOL == 1 +#ifdef ANALYZE + ANALYZE_PRINTF ("Switching to SAMSUNG48 protocol "); +#endif // ANALYZE + irmp_param.protocol = IRMP_SAMSUNG48_PROTOCOL; + irmp_param.command_offset = SAMSUNG48_COMMAND_OFFSET; + irmp_param.command_end = SAMSUNG48_COMMAND_OFFSET + SAMSUNG48_COMMAND_LEN; + irmp_param.complete_len = SAMSUNG48_COMPLETE_DATA_LEN; +#else +#ifdef ANALYZE + ANALYZE_PRINTF ("Switching to SAMSUNG32 protocol "); +#endif // ANALYZE irmp_param.protocol = IRMP_SAMSUNG32_PROTOCOL; irmp_param.command_offset = SAMSUNG32_COMMAND_OFFSET; irmp_param.command_end = SAMSUNG32_COMMAND_OFFSET + SAMSUNG32_COMMAND_LEN; irmp_param.complete_len = SAMSUNG32_COMPLETE_DATA_LEN; - +#endif if (irmp_pause_time >= SAMSUNG_1_PAUSE_LEN_MIN && irmp_pause_time <= SAMSUNG_1_PAUSE_LEN_MAX) { #ifdef ANALYZE @@ -3717,10 +3733,6 @@ irmp_ISR (void) irmp_store_bit (0); wait_for_space = 0; } - -#ifdef ANALYZE - ANALYZE_PRINTF ("Switching to SAMSUNG32 protocol\n"); -#endif // ANALYZE } else { // timing incorrect! @@ -4032,11 +4044,11 @@ irmp_ISR (void) #endif #if IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1 - // if SAMSUNG32 protocol and the code will be repeated within 50 ms, we will ignore every 2nd frame - if (irmp_param.protocol == IRMP_SAMSUNG32_PROTOCOL && (repetition_frame_number & 0x01)) + // if SAMSUNG32 or SAMSUNG48 protocol and the code will be repeated within 50 ms, we will ignore every 2nd frame + if ((irmp_param.protocol == IRMP_SAMSUNG32_PROTOCOL || irmp_param.protocol == IRMP_SAMSUNG48_PROTOCOL) && (repetition_frame_number & 0x01)) { #ifdef ANALYZE - ANALYZE_PRINTF ("code skipped: SAMSUNG32 auto repetition frame #%d, counter = %d, auto repetition len = %d\n", + ANALYZE_PRINTF ("code skipped: SAMSUNG32/SAMSUNG48 auto repetition frame #%d, counter = %d, auto repetition len = %d\n", repetition_frame_number + 1, key_repetition_len, AUTO_FRAME_REPETITION_LEN); #endif // ANALYZE key_repetition_len = 0;