X-Git-Url: http://cloudbase.mooo.com/gitweb/irmp.git/blobdiff_plain/acf7fb44f0428a5f1434045f02615a7ebcb17ebd..476267f4e9854c75c890799df29225e61623c3cc:/irmp.c diff --git a/irmp.c b/irmp.c index 7e95818..208e22d 100644 --- a/irmp.c +++ b/irmp.c @@ -3,11 +3,20 @@ * * Copyright (c) 2009-2011 Frank Meyer - frank(at)fli4l.de * - * $Id: irmp.c,v 1.104 2011/05/22 21:40:52 fm Exp $ + * $Id: irmp.c,v 1.108 2011/09/09 11:59:39 fm Exp $ * * ATMEGA88 @ 8 MHz * - * Typical manufacturers: + * Supported mikrocontrollers: + * + * ATtiny45, ATtiny85 + * ATtiny84 + * ATmega8, ATmega16, ATmega32 + * ATmega162 + * ATmega164, ATmega324, ATmega644, ATmega644P, ATmega1284 + * ATmega88, ATmega88P, ATmega168, ATmega168P, ATmega328P + * + * Typical manufacturers of remote controls: * * SIRCS - Sony * NEC - NEC, Yamaha, Canon, Tevion, Harman/Kardon, Hitachi, JVC, Pioneer, Toshiba, Xoro, Orion, and many other Japanese manufacturers @@ -316,8 +325,6 @@ typedef unsigned short uint16_t; #else -#ifndef CODEVISION - #ifdef PIC_CCS_COMPILER #include @@ -336,7 +343,6 @@ typedef unsigned int16 uint16_t; #include #endif // PIC_CCS_COMPILER -#endif // CODEVISION #endif // windows #endif // unix @@ -368,9 +374,7 @@ typedef unsigned int16 uint16_t; #define IRMP_SUPPORT_MANCHESTER 0 #endif -#if IRMP_SUPPORT_NETBOX_PROTOCOL == 1 || \ - IRMP_SUPPORT_MERLIN_PROTOCOL == 1 || \ - IRMP_SUPPORT_IMON_PROTOCOL == 1 +#if IRMP_SUPPORT_NETBOX_PROTOCOL == 1 #define IRMP_SUPPORT_SERIAL 1 #else #define IRMP_SUPPORT_SERIAL 0 @@ -678,34 +682,16 @@ typedef unsigned int16 uint16_t; #define LEGO_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * LEGO_0_PAUSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1) #define LEGO_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * LEGO_0_PAUSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1) -#define MERLIN_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * MERLIN_START_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) -#define MERLIN_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * MERLIN_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) -#define MERLIN_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * MERLIN_START_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) -#define MERLIN_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * MERLIN_START_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) -#define MERLIN_PULSE_LEN ((uint8_t)(F_INTERRUPTS * MERLIN_PULSE_TIME)) -#define MERLIN_PAUSE_LEN ((uint8_t)(F_INTERRUPTS * MERLIN_PAUSE_TIME)) -#define MERLIN_PULSE_REST_LEN ((uint8_t)(F_INTERRUPTS * MERLIN_PULSE_TIME / 4)) -#define MERLIN_PAUSE_REST_LEN ((uint8_t)(F_INTERRUPTS * MERLIN_PAUSE_TIME / 4)) - -#define IMON_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * IMON_START_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) -#define IMON_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * IMON_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) -#define IMON_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * IMON_START_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) -#define IMON_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * IMON_START_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) -#define IMON_PULSE_LEN ((uint8_t)(F_INTERRUPTS * IMON_PULSE_TIME)) -#define IMON_PAUSE_LEN ((uint8_t)(F_INTERRUPTS * IMON_PAUSE_TIME)) -#define IMON_PULSE_REST_LEN ((uint8_t)(F_INTERRUPTS * IMON_PULSE_TIME / 4)) -#define IMON_PAUSE_REST_LEN ((uint8_t)(F_INTERRUPTS * IMON_PAUSE_TIME / 4)) - #define AUTO_FRAME_REPETITION_LEN (uint16_t)(F_INTERRUPTS * AUTO_FRAME_REPETITION_TIME + 0.5) // use uint16_t! #ifdef ANALYZE -#define ANALYZE_PUTCHAR(a) { if (! silent) { putchar (a); } } -#define ANALYZE_ONLY_NORMAL_PUTCHAR(a) { if (! silent && !verbose) { putchar (a); } } -#define ANALYZE_PRINTF(...) { if (verbose) { printf (__VA_ARGS__); } } -#define ANALYZE_NEWLINE() { if (verbose) { putchar ('\n'); } } -static int silent; -static int time_counter; -static int verbose; +#define ANALYZE_PUTCHAR(a) { if (! silent) { putchar (a); } } +#define ANALYZE_ONLY_NORMAL_PUTCHAR(a) { if (! silent && !verbose) { putchar (a); } } +#define ANALYZE_PRINTF(...) { if (verbose) { printf (__VA_ARGS__); } } +#define ANALYZE_NEWLINE() { if (verbose) { putchar ('\n'); } } +static int silent; +static int time_counter; +static int verbose; #else #define ANALYZE_PUTCHAR(a) #define ANALYZE_ONLY_NORMAL_PUTCHAR(a) @@ -713,6 +699,56 @@ static int verbose; #define ANALYZE_NEWLINE() #endif +#if IRMP_USE_CALLBACK == 1 +static void (*irmp_callback_ptr) (uint8_t); +#endif // IRMP_USE_CALLBACK == 1 + +/*--------------------------------------------------------------------------------------------------------------------------------------------------- + * Protocol names + *--------------------------------------------------------------------------------------------------------------------------------------------------- + */ +#if IRMP_PROTOCOL_NAMES == 1 +char * +irmp_protocol_names[IRMP_N_PROTOCOLS + 1] = +{ + "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" +}; +#endif + +/*--------------------------------------------------------------------------------------------------------------------------------------------------- + * Logging + *--------------------------------------------------------------------------------------------------------------------------------------------------- + */ #if IRMP_LOGGING == 1 #define BAUD 9600L #include @@ -900,7 +936,7 @@ typedef struct #if IRMP_SUPPORT_SIRCS_PROTOCOL == 1 -static PROGMEM IRMP_PARAMETER sircs_param = +static const PROGMEM IRMP_PARAMETER sircs_param = { IRMP_SIRCS_PROTOCOL, // protocol: ir protocol SIRCS_1_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1 @@ -925,7 +961,7 @@ static PROGMEM IRMP_PARAMETER sircs_param = #if IRMP_SUPPORT_NEC_PROTOCOL == 1 -static PROGMEM IRMP_PARAMETER nec_param = +static const PROGMEM IRMP_PARAMETER nec_param = { IRMP_NEC_PROTOCOL, // protocol: ir protocol NEC_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1 @@ -946,7 +982,7 @@ static PROGMEM IRMP_PARAMETER nec_param = NEC_FLAGS // flags: some flags }; -static PROGMEM IRMP_PARAMETER nec_rep_param = +static const PROGMEM IRMP_PARAMETER nec_rep_param = { IRMP_NEC_PROTOCOL, // protocol: ir protocol NEC_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1 @@ -971,7 +1007,7 @@ static PROGMEM IRMP_PARAMETER nec_rep_param = #if IRMP_SUPPORT_NEC42_PROTOCOL == 1 -static PROGMEM IRMP_PARAMETER nec42_param = +static const PROGMEM IRMP_PARAMETER nec42_param = { IRMP_NEC42_PROTOCOL, // protocol: ir protocol NEC_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1 @@ -983,9 +1019,9 @@ static PROGMEM IRMP_PARAMETER nec42_param = NEC_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0 NEC_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0 NEC42_ADDRESS_OFFSET, // address_offset: address offset - NEC42_ADDRESS_OFFSET + NEC_ADDRESS_LEN, // address_end: end of address + NEC42_ADDRESS_OFFSET + NEC42_ADDRESS_LEN, // address_end: end of address NEC42_COMMAND_OFFSET, // command_offset: command offset - NEC42_COMMAND_OFFSET + NEC_COMMAND_LEN, // command_end: end of command + NEC42_COMMAND_OFFSET + NEC42_COMMAND_LEN, // command_end: end of command NEC42_COMPLETE_DATA_LEN, // complete_len: complete length of frame NEC_STOP_BIT, // stop_bit: flag: frame has stop bit NEC_LSB, // lsb_first: flag: LSB first @@ -996,7 +1032,7 @@ static PROGMEM IRMP_PARAMETER nec42_param = #if IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1 -static PROGMEM IRMP_PARAMETER samsung_param = +static const PROGMEM IRMP_PARAMETER samsung_param = { IRMP_SAMSUNG_PROTOCOL, // protocol: ir protocol SAMSUNG_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1 @@ -1021,7 +1057,7 @@ static PROGMEM IRMP_PARAMETER samsung_param = #if IRMP_SUPPORT_MATSUSHITA_PROTOCOL == 1 -static PROGMEM IRMP_PARAMETER matsushita_param = +static const PROGMEM IRMP_PARAMETER matsushita_param = { IRMP_MATSUSHITA_PROTOCOL, // protocol: ir protocol MATSUSHITA_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1 @@ -1046,7 +1082,7 @@ static PROGMEM IRMP_PARAMETER matsushita_param = #if IRMP_SUPPORT_KASEIKYO_PROTOCOL == 1 -static PROGMEM IRMP_PARAMETER kaseikyo_param = +static const PROGMEM IRMP_PARAMETER kaseikyo_param = { IRMP_KASEIKYO_PROTOCOL, // protocol: ir protocol KASEIKYO_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1 @@ -1071,7 +1107,7 @@ static PROGMEM IRMP_PARAMETER kaseikyo_param = #if IRMP_SUPPORT_RECS80_PROTOCOL == 1 -static PROGMEM IRMP_PARAMETER recs80_param = +static const PROGMEM IRMP_PARAMETER recs80_param = { IRMP_RECS80_PROTOCOL, // protocol: ir protocol RECS80_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1 @@ -1096,7 +1132,7 @@ static PROGMEM IRMP_PARAMETER recs80_param = #if IRMP_SUPPORT_RC5_PROTOCOL == 1 -static PROGMEM IRMP_PARAMETER rc5_param = +static const PROGMEM IRMP_PARAMETER rc5_param = { IRMP_RC5_PROTOCOL, // protocol: ir protocol RC5_BIT_LEN_MIN, // pulse_1_len_min: here: minimum length of short pulse @@ -1121,7 +1157,7 @@ static PROGMEM IRMP_PARAMETER rc5_param = #if IRMP_SUPPORT_DENON_PROTOCOL == 1 -static PROGMEM IRMP_PARAMETER denon_param = +static const PROGMEM IRMP_PARAMETER denon_param = { IRMP_DENON_PROTOCOL, // protocol: ir protocol DENON_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1 @@ -1146,7 +1182,7 @@ static PROGMEM IRMP_PARAMETER denon_param = #if IRMP_SUPPORT_RC6_PROTOCOL == 1 -static PROGMEM IRMP_PARAMETER rc6_param = +static const PROGMEM IRMP_PARAMETER rc6_param = { IRMP_RC6_PROTOCOL, // protocol: ir protocol @@ -1172,7 +1208,7 @@ static PROGMEM IRMP_PARAMETER rc6_param = #if IRMP_SUPPORT_RECS80EXT_PROTOCOL == 1 -static PROGMEM IRMP_PARAMETER recs80ext_param = +static const PROGMEM IRMP_PARAMETER recs80ext_param = { IRMP_RECS80EXT_PROTOCOL, // protocol: ir protocol RECS80EXT_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1 @@ -1197,7 +1233,7 @@ static PROGMEM IRMP_PARAMETER recs80ext_param = #if IRMP_SUPPORT_NUBERT_PROTOCOL == 1 -static PROGMEM IRMP_PARAMETER nubert_param = +static const PROGMEM IRMP_PARAMETER nubert_param = { IRMP_NUBERT_PROTOCOL, // protocol: ir protocol NUBERT_1_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1 @@ -1222,7 +1258,7 @@ static PROGMEM IRMP_PARAMETER nubert_param = #if IRMP_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1 -static PROGMEM IRMP_PARAMETER bang_olufsen_param = +static const PROGMEM IRMP_PARAMETER bang_olufsen_param = { IRMP_BANG_OLUFSEN_PROTOCOL, // protocol: ir protocol BANG_OLUFSEN_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1 @@ -1249,7 +1285,7 @@ static PROGMEM IRMP_PARAMETER bang_olufsen_param = static uint8_t first_bit; -static PROGMEM IRMP_PARAMETER grundig_param = +static const PROGMEM IRMP_PARAMETER grundig_param = { IRMP_GRUNDIG_PROTOCOL, // protocol: ir protocol @@ -1275,7 +1311,7 @@ static PROGMEM IRMP_PARAMETER grundig_param = #if IRMP_SUPPORT_SIEMENS_OR_RUWIDO_PROTOCOL == 1 -static PROGMEM IRMP_PARAMETER ruwido_param = +static const PROGMEM IRMP_PARAMETER ruwido_param = { IRMP_RUWIDO_PROTOCOL, // protocol: ir protocol SIEMENS_OR_RUWIDO_BIT_PULSE_LEN_MIN, // pulse_1_len_min: here: minimum length of short pulse @@ -1300,7 +1336,7 @@ static PROGMEM IRMP_PARAMETER ruwido_param = #if IRMP_SUPPORT_FDC_PROTOCOL == 1 -static PROGMEM IRMP_PARAMETER fdc_param = +static const PROGMEM IRMP_PARAMETER fdc_param = { IRMP_FDC_PROTOCOL, // protocol: ir protocol FDC_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1 @@ -1325,7 +1361,7 @@ static PROGMEM IRMP_PARAMETER fdc_param = #if IRMP_SUPPORT_RCCAR_PROTOCOL == 1 -static PROGMEM IRMP_PARAMETER rccar_param = +static const PROGMEM IRMP_PARAMETER rccar_param = { IRMP_RCCAR_PROTOCOL, // protocol: ir protocol RCCAR_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1 @@ -1350,7 +1386,7 @@ static PROGMEM IRMP_PARAMETER rccar_param = #if IRMP_SUPPORT_NIKON_PROTOCOL == 1 -static PROGMEM IRMP_PARAMETER nikon_param = +static const PROGMEM IRMP_PARAMETER nikon_param = { IRMP_NIKON_PROTOCOL, // protocol: ir protocol NIKON_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1 @@ -1375,7 +1411,7 @@ static PROGMEM IRMP_PARAMETER nikon_param = #if IRMP_SUPPORT_KATHREIN_PROTOCOL == 1 -static PROGMEM IRMP_PARAMETER kathrein_param = +static const PROGMEM IRMP_PARAMETER kathrein_param = { IRMP_KATHREIN_PROTOCOL, // protocol: ir protocol KATHREIN_1_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1 @@ -1400,7 +1436,7 @@ static PROGMEM IRMP_PARAMETER kathrein_param = #if IRMP_SUPPORT_NETBOX_PROTOCOL == 1 -static PROGMEM IRMP_PARAMETER netbox_param = +static const PROGMEM IRMP_PARAMETER netbox_param = { IRMP_NETBOX_PROTOCOL, // protocol: ir protocol NETBOX_PULSE_LEN, // pulse_1_len_min: minimum length of pulse with bit value 1, here: exact value @@ -1425,7 +1461,7 @@ static PROGMEM IRMP_PARAMETER netbox_param = #if IRMP_SUPPORT_LEGO_PROTOCOL == 1 -static PROGMEM IRMP_PARAMETER lego_param = +static const PROGMEM IRMP_PARAMETER lego_param = { IRMP_LEGO_PROTOCOL, // protocol: ir protocol LEGO_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1 @@ -1448,34 +1484,9 @@ static PROGMEM IRMP_PARAMETER lego_param = #endif -#if IRMP_SUPPORT_MERLIN_PROTOCOL == 1 - -static PROGMEM IRMP_PARAMETER merlin_param = -{ - IRMP_MERLIN_PROTOCOL, // protocol: ir protocol - MERLIN_PULSE_LEN, // pulse_1_len_min: minimum length of pulse with bit value 1, here: exact value - MERLIN_PULSE_REST_LEN, // pulse_1_len_max: maximum length of pulse with bit value 1, here: rest value - MERLIN_PAUSE_LEN, // pause_1_len_min: minimum length of pause with bit value 1, here: exact value - MERLIN_PAUSE_REST_LEN, // pause_1_len_max: maximum length of pause with bit value 1, here: rest value - MERLIN_PULSE_LEN, // pulse_0_len_min: minimum length of pulse with bit value 0, here: exact value - MERLIN_PULSE_REST_LEN, // pulse_0_len_max: maximum length of pulse with bit value 0, here: rest value - MERLIN_PAUSE_LEN, // pause_0_len_min: minimum length of pause with bit value 0, here: exact value - MERLIN_PAUSE_REST_LEN, // pause_0_len_max: maximum length of pause with bit value 0, here: rest value - MERLIN_ADDRESS_OFFSET, // address_offset: address offset - MERLIN_ADDRESS_OFFSET + MERLIN_ADDRESS_LEN, // address_end: end of address - MERLIN_COMMAND_OFFSET, // command_offset: command offset - MERLIN_COMMAND_OFFSET + MERLIN_COMMAND_LEN, // command_end: end of command - MERLIN_COMPLETE_DATA_LEN, // complete_len: complete length of frame - MERLIN_STOP_BIT, // stop_bit: flag: frame has stop bit - MERLIN_LSB, // lsb_first: flag: LSB first - MERLIN_FLAGS // flags: some flags -}; - -#endif - #if IRMP_SUPPORT_THOMSON_PROTOCOL == 1 -static PROGMEM IRMP_PARAMETER thomson_param = +static const PROGMEM IRMP_PARAMETER thomson_param = { IRMP_THOMSON_PROTOCOL, // protocol: ir protocol THOMSON_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1 @@ -1498,31 +1509,6 @@ static PROGMEM IRMP_PARAMETER thomson_param = #endif -#if IRMP_SUPPORT_IMON_PROTOCOL == 1 - -static PROGMEM IRMP_PARAMETER imon_param = -{ - IRMP_IMON_PROTOCOL, // protocol: ir protocol - IMON_PULSE_LEN, // pulse_1_len_min: minimum length of pulse with bit value 1 - IMON_PULSE_REST_LEN, // pulse_1_len_max: maximum length of pulse with bit value 1 - IMON_PAUSE_LEN, // pause_1_len_min: minimum length of pause with bit value 1 - IMON_PAUSE_REST_LEN, // pause_1_len_max: maximum length of pause with bit value 1 - IMON_PULSE_LEN, // pulse_0_len_min: minimum length of pulse with bit value 0 - IMON_PULSE_REST_LEN, // pulse_0_len_max: maximum length of pulse with bit value 0 - IMON_PAUSE_LEN, // pause_0_len_min: minimum length of pause with bit value 0 - IMON_PAUSE_REST_LEN, // pause_0_len_max: maximum length of pause with bit value 0 - IMON_ADDRESS_OFFSET, // address_offset: address offset - IMON_ADDRESS_OFFSET + IMON_ADDRESS_LEN, // address_end: end of address - IMON_COMMAND_OFFSET, // command_offset: command offset - IMON_COMMAND_OFFSET + IMON_COMMAND_LEN, // command_end: end of command - IMON_COMPLETE_DATA_LEN, // complete_len: complete length of frame - IMON_STOP_BIT, // stop_bit: flag: frame has stop bit - IMON_LSB, // lsb_first: flag: LSB first - IMON_FLAGS // flags: some flags -}; - -#endif - static uint8_t irmp_bit; // current bit position static IRMP_PARAMETER irmp_param; @@ -1536,6 +1522,7 @@ static volatile uint16_t irmp_address; static volatile uint16_t irmp_command; static volatile uint16_t irmp_id; // only used for SAMSUNG protocol static volatile uint8_t irmp_flags; +// static volatile uint8_t irmp_busy_flag; #ifdef ANALYZE static uint8_t IRMP_PIN; @@ -1621,6 +1608,12 @@ irmp_get_data (IRMP_DATA * irmp_data_p) } break; #endif +#if IRMP_SUPPORT_RC5_PROTOCOL == 1 + case IRMP_RC5_PROTOCOL: + irmp_address &= ~0x20; // clear toggle bit + rtc = TRUE; + break; +#endif #if IRMP_SUPPORT_IR60_PROTOCOL == 1 case IRMP_IR60_PROTOCOL: if (irmp_command != 0x007d) // 0x007d (== 62<<1 + 1) is start instruction frame @@ -1708,6 +1701,20 @@ irmp_get_data (IRMP_DATA * irmp_data_p) return rtc; } +// uint8_t +// irmp_is_busy (void) +// { +// return irmp_busy_flag; +// } + +#if IRMP_USE_CALLBACK == 1 +void +irmp_set_callback_ptr (void (*cb)(uint8_t)) +{ + irmp_callback_ptr = cb; +} +#endif // IRMP_USE_CALLBACK == 1 + // these statics must not be volatile, because they are only used by irmp_store_bit(), which is called by irmp_ISR() static uint16_t irmp_tmp_address; // ir address static uint16_t irmp_tmp_command; // ir command @@ -1875,6 +1882,19 @@ irmp_ISR (void) irmp_input = input(IRMP_PIN); +#if IRMP_USE_CALLBACK == 1 + if (irmp_callback_ptr) + { + static uint8_t last_inverted_input; + + if (last_inverted_input != !irmp_input) + { + (*irmp_callback_ptr) (! irmp_input); + last_inverted_input = !irmp_input; + } + } +#endif // IRMP_USE_CALLBACK == 1 + irmp_log(irmp_input); // log ir signal, if IRMP_LOGGING defined if (! irmp_ir_detected) // ir code already detected? @@ -1883,6 +1903,7 @@ irmp_ISR (void) { // no... if (! irmp_input) // receiving burst? { // yes... +// irmp_busy_flag = TRUE; #ifdef ANALYZE if (! irmp_pulse_time) { @@ -1947,6 +1968,7 @@ irmp_ISR (void) ANALYZE_PRINTF ("%8d error 1: pause after start bit pulse %d too long: %d\n", time_counter, irmp_pulse_time, irmp_pause_time); ANALYZE_ONLY_NORMAL_PUTCHAR ('\n'); } +// irmp_busy_flag = FALSE; irmp_start_bit_detected = 0; // reset flags, let's wait for another start bit irmp_pulse_time = 0; irmp_pause_time = 0; @@ -2307,18 +2329,6 @@ irmp_ISR (void) else #endif // IRMP_SUPPORT_NETBOX_PROTOCOL == 1 -#if IRMP_SUPPORT_MERLIN_PROTOCOL == 1 - if (irmp_pulse_time >= MERLIN_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= MERLIN_START_BIT_PULSE_LEN_MAX && - irmp_pause_time >= MERLIN_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= MERLIN_START_BIT_PAUSE_LEN_MAX) - { // it's MERLIN - ANALYZE_PRINTF ("protocol = MERLIN, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n", - MERLIN_START_BIT_PULSE_LEN_MIN, MERLIN_START_BIT_PULSE_LEN_MAX, - MERLIN_START_BIT_PAUSE_LEN_MIN, MERLIN_START_BIT_PAUSE_LEN_MAX); - irmp_param_p = (IRMP_PARAMETER *) &merlin_param; - } - else -#endif // IRMP_SUPPORT_MERLIN_PROTOCOL == 1 - #if IRMP_SUPPORT_LEGO_PROTOCOL == 1 if (irmp_pulse_time >= LEGO_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= LEGO_START_BIT_PULSE_LEN_MAX && irmp_pause_time >= LEGO_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= LEGO_START_BIT_PAUSE_LEN_MAX) @@ -2331,20 +2341,9 @@ irmp_ISR (void) else #endif // IRMP_SUPPORT_NEC_PROTOCOL == 1 -#if IRMP_SUPPORT_IMON_PROTOCOL == 1 - if (irmp_pulse_time >= IMON_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= IMON_START_BIT_PULSE_LEN_MAX && - irmp_pause_time >= IMON_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= IMON_START_BIT_PAUSE_LEN_MAX) - { // it's IMON - ANALYZE_PRINTF ("protocol = IMON, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n", - IMON_START_BIT_PULSE_LEN_MIN, IMON_START_BIT_PULSE_LEN_MAX, - IMON_START_BIT_PAUSE_LEN_MIN, IMON_START_BIT_PAUSE_LEN_MAX); - irmp_param_p = (IRMP_PARAMETER *) &imon_param; - } - else -#endif // IRMP_SUPPORT_IMON_PROTOCOL == 1 - { ANALYZE_PRINTF ("protocol = UNKNOWN\n"); +// irmp_busy_flag = FALSE; irmp_start_bit_detected = 0; // wait for another start bit... } @@ -2518,6 +2517,7 @@ irmp_ISR (void) { ANALYZE_PRINTF ("error: stop bit timing wrong\n"); +// irmp_busy_flag = FALSE; irmp_start_bit_detected = 0; // wait for another start bit... irmp_pulse_time = 0; irmp_pause_time = 0; @@ -2548,15 +2548,6 @@ irmp_ISR (void) got_light = TRUE; // this is a lie, but helps (generates stop bit) } else -#if 1 - // MERLIN generates no stop bit, here is the timeout condition: - if ((irmp_param.flags & IRMP_PARAM_FLAG_IS_SERIAL) && irmp_param.protocol == IRMP_MERLIN_PROTOCOL && - irmp_pause_time >= MERLIN_PULSE_LEN * (MERLIN_COMPLETE_DATA_LEN - irmp_bit)) - { - got_light = TRUE; // this is a lie, but helps (generates stop bit) - } - else -#endif #endif #if IRMP_SUPPORT_GRUNDIG_NOKIA_IR60_PROTOCOL == 1 if (irmp_param.protocol == IRMP_GRUNDIG_PROTOCOL && !irmp_param.stop_bit) @@ -2696,6 +2687,7 @@ irmp_ISR (void) ANALYZE_PRINTF ("error 2: pause %d after data bit %d too long\n", irmp_pause_time, irmp_bit); ANALYZE_ONLY_NORMAL_PUTCHAR ('\n'); +// irmp_busy_flag = FALSE; irmp_start_bit_detected = 0; // wait for another start bit... irmp_pulse_time = 0; irmp_pause_time = 0; @@ -2843,6 +2835,7 @@ irmp_ISR (void) ANALYZE_NEWLINE (); ANALYZE_PRINTF ("error 3 manchester: timing not correct: data bit %d, pulse: %d, pause: %d\n", irmp_bit, irmp_pulse_time, irmp_pause_time); ANALYZE_ONLY_NORMAL_PUTCHAR ('\n'); +// irmp_busy_flag = FALSE; irmp_start_bit_detected = 0; // reset flags and wait for next start bit irmp_pause_time = 0; } @@ -2980,6 +2973,7 @@ irmp_ISR (void) { // timing incorrect! ANALYZE_PRINTF ("error 3 Samsung: timing not correct: data bit %d, pulse: %d, pause: %d\n", irmp_bit, irmp_pulse_time, irmp_pause_time); ANALYZE_ONLY_NORMAL_PUTCHAR ('\n'); +// irmp_busy_flag = FALSE; irmp_start_bit_detected = 0; // reset flags and wait for next start bit irmp_pause_time = 0; } @@ -2995,9 +2989,8 @@ irmp_ISR (void) #endif // IRMP_SUPPORT_NEC42_PROTOCOL == 1 irmp_bit == 8 && irmp_pause_time >= NEC_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= NEC_START_BIT_PAUSE_LEN_MAX) { -printf ("! %d %d !\n", irmp_pause_time, NEC_START_BIT_PAUSE_LEN_MAX); ANALYZE_PRINTF ("Switching to NEC16 protocol\n"); - irmp_param.protocol = IRMP_NEC16_PROTOCOL; + irmp_param.protocol = IRMP_NEC16_PROTOCOL; irmp_param.address_offset = NEC16_ADDRESS_OFFSET; irmp_param.address_end = NEC16_ADDRESS_OFFSET + NEC16_ADDRESS_LEN; irmp_param.command_offset = NEC16_COMMAND_OFFSET; @@ -3025,6 +3018,7 @@ printf ("! %d %d !\n", irmp_pause_time, NEC_START_BIT_PAUSE_LEN_MAX); { // timing incorrect! ANALYZE_PRINTF ("error 3a B&O: timing not correct: data bit %d, pulse: %d, pause: %d\n", irmp_bit, irmp_pulse_time, irmp_pause_time); ANALYZE_ONLY_NORMAL_PUTCHAR ('\n'); +// irmp_busy_flag = FALSE; irmp_start_bit_detected = 0; // reset flags and wait for next start bit irmp_pause_time = 0; } @@ -3041,6 +3035,7 @@ printf ("! %d %d !\n", irmp_pause_time, NEC_START_BIT_PAUSE_LEN_MAX); { // timing incorrect! ANALYZE_PRINTF ("error 3b B&O: timing not correct: data bit %d, pulse: %d, pause: %d\n", irmp_bit, irmp_pulse_time, irmp_pause_time); ANALYZE_ONLY_NORMAL_PUTCHAR ('\n'); +// irmp_busy_flag = FALSE; irmp_start_bit_detected = 0; // reset flags and wait for next start bit irmp_pause_time = 0; } @@ -3074,6 +3069,7 @@ printf ("! %d %d !\n", irmp_pause_time, NEC_START_BIT_PAUSE_LEN_MAX); { // timing incorrect! ANALYZE_PRINTF ("error 3c B&O: timing not correct: data bit %d, pulse: %d, pause: %d\n", irmp_bit, irmp_pulse_time, irmp_pause_time); ANALYZE_ONLY_NORMAL_PUTCHAR ('\n'); +// irmp_busy_flag = FALSE; irmp_start_bit_detected = 0; // reset flags and wait for next start bit irmp_pause_time = 0; } @@ -3083,6 +3079,7 @@ printf ("! %d %d !\n", irmp_pause_time, NEC_START_BIT_PAUSE_LEN_MAX); { // timing incorrect! ANALYZE_PRINTF ("error 3d B&O: timing not correct: data bit %d, pulse: %d, pause: %d\n", irmp_bit, irmp_pulse_time, irmp_pause_time); ANALYZE_ONLY_NORMAL_PUTCHAR ('\n'); +// irmp_busy_flag = FALSE; irmp_start_bit_detected = 0; // reset flags and wait for next start bit irmp_pause_time = 0; } @@ -3137,6 +3134,7 @@ printf ("! %d %d !\n", irmp_pause_time, NEC_START_BIT_PAUSE_LEN_MAX); { // timing incorrect! ANALYZE_PRINTF ("error 3: timing not correct: data bit %d, pulse: %d, pause: %d\n", irmp_bit, irmp_pulse_time, irmp_pause_time); ANALYZE_ONLY_NORMAL_PUTCHAR ('\n'); +// irmp_busy_flag = FALSE; irmp_start_bit_detected = 0; // reset flags and wait for next start bit irmp_pause_time = 0; } @@ -3328,7 +3326,10 @@ printf ("! %d %d !\n", irmp_pause_time, NEC_START_BIT_PAUSE_LEN_MAX); irmp_address = irmp_tmp_address; // store address #if IRMP_SUPPORT_NEC_PROTOCOL == 1 - last_irmp_address = irmp_tmp_address; // store as last address, too + if (irmp_param.protocol == IRMP_NEC_PROTOCOL) + { + last_irmp_address = irmp_tmp_address; // store as last address, too + } #endif #if IRMP_SUPPORT_RC5_PROTOCOL == 1 @@ -3347,8 +3348,8 @@ printf ("! %d %d !\n", irmp_pause_time, NEC_START_BIT_PAUSE_LEN_MAX); if (irmp_ir_detected) { - if (last_irmp_command == irmp_command && - last_irmp_address == irmp_address && + if (last_irmp_command == irmp_tmp_command && + last_irmp_address == irmp_tmp_address && repetition_len < IRMP_KEY_REPETITION_LEN) { irmp_flags |= IRMP_FLAG_REPETITION; @@ -3364,6 +3365,7 @@ printf ("! %d %d !\n", irmp_pause_time, NEC_START_BIT_PAUSE_LEN_MAX); ANALYZE_ONLY_NORMAL_PUTCHAR ('\n'); } +// irmp_busy_flag = FALSE; irmp_start_bit_detected = 0; // and wait for next start bit irmp_tmp_command = 0; irmp_pulse_time = 0;