]> cloudbase.mooo.com Git - irmp.git/blob - irmp.c
Version 2.3.1: corrected OC0A for ATmega48/88/168/328
[irmp.git] / irmp.c
1 /*---------------------------------------------------------------------------------------------------------------------------------------------------
2 * irmp.c - infrared multi-protocol decoder, supports several remote control protocols
3 *
4 * Copyright (c) 2009-2012 Frank Meyer - frank(at)fli4l.de
5 *
6 * $Id: irmp.c,v 1.129 2012/10/26 08:09:37 fm Exp $
7 *
8 * ATMEGA88 @ 8 MHz
9 *
10 * Supported mikrocontrollers:
11 *
12 * ATtiny87, ATtiny167
13 * ATtiny45, ATtiny85
14 * ATtiny84
15 * ATmega8, ATmega16, ATmega32
16 * ATmega162
17 * ATmega164, ATmega324, ATmega644, ATmega644P, ATmega1284
18 * ATmega88, ATmega88P, ATmega168, ATmega168P, ATmega328P
19 *
20 * This program is free software; you can redistribute it and/or modify
21 * it under the terms of the GNU General Public License as published by
22 * the Free Software Foundation; either version 2 of the License, or
23 * (at your option) any later version.
24 *---------------------------------------------------------------------------------------------------------------------------------------------------
25 */
26
27 #include "irmp.h"
28
29 #if IRMP_SUPPORT_GRUNDIG_PROTOCOL == 1 || IRMP_SUPPORT_NOKIA_PROTOCOL == 1 || IRMP_SUPPORT_IR60_PROTOCOL == 1
30 # define IRMP_SUPPORT_GRUNDIG_NOKIA_IR60_PROTOCOL 1
31 #else
32 # define IRMP_SUPPORT_GRUNDIG_NOKIA_IR60_PROTOCOL 0
33 #endif
34
35 #if IRMP_SUPPORT_SIEMENS_PROTOCOL == 1 || IRMP_SUPPORT_RUWIDO_PROTOCOL == 1
36 # define IRMP_SUPPORT_SIEMENS_OR_RUWIDO_PROTOCOL 1
37 #else
38 # define IRMP_SUPPORT_SIEMENS_OR_RUWIDO_PROTOCOL 0
39 #endif
40
41 #if IRMP_SUPPORT_RC5_PROTOCOL == 1 || \
42 IRMP_SUPPORT_RC6_PROTOCOL == 1 || \
43 IRMP_SUPPORT_GRUNDIG_NOKIA_IR60_PROTOCOL == 1 || \
44 IRMP_SUPPORT_SIEMENS_OR_RUWIDO_PROTOCOL == 1 || \
45 IRMP_SUPPORT_IR60_PROTOCOL
46 # define IRMP_SUPPORT_MANCHESTER 1
47 #else
48 # define IRMP_SUPPORT_MANCHESTER 0
49 #endif
50
51 #if IRMP_SUPPORT_NETBOX_PROTOCOL == 1
52 # define IRMP_SUPPORT_SERIAL 1
53 #else
54 # define IRMP_SUPPORT_SERIAL 0
55 #endif
56
57 #define IRMP_KEY_REPETITION_LEN (uint16_t)(F_INTERRUPTS * 150.0e-3 + 0.5) // autodetect key repetition within 150 msec
58
59 #define MIN_TOLERANCE_00 1.0 // -0%
60 #define MAX_TOLERANCE_00 1.0 // +0%
61
62 #define MIN_TOLERANCE_05 0.95 // -5%
63 #define MAX_TOLERANCE_05 1.05 // +5%
64
65 #define MIN_TOLERANCE_10 0.9 // -10%
66 #define MAX_TOLERANCE_10 1.1 // +10%
67
68 #define MIN_TOLERANCE_15 0.85 // -15%
69 #define MAX_TOLERANCE_15 1.15 // +15%
70
71 #define MIN_TOLERANCE_20 0.8 // -20%
72 #define MAX_TOLERANCE_20 1.2 // +20%
73
74 #define MIN_TOLERANCE_30 0.7 // -30%
75 #define MAX_TOLERANCE_30 1.3 // +30%
76
77 #define MIN_TOLERANCE_40 0.6 // -40%
78 #define MAX_TOLERANCE_40 1.4 // +40%
79
80 #define MIN_TOLERANCE_50 0.5 // -50%
81 #define MAX_TOLERANCE_50 1.5 // +50%
82
83 #define MIN_TOLERANCE_60 0.4 // -60%
84 #define MAX_TOLERANCE_60 1.6 // +60%
85
86 #define MIN_TOLERANCE_70 0.3 // -70%
87 #define MAX_TOLERANCE_70 1.7 // +70%
88
89 #define SIRCS_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SIRCS_START_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
90 #define SIRCS_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SIRCS_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
91 #define SIRCS_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SIRCS_START_BIT_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
92 #if IRMP_SUPPORT_NETBOX_PROTOCOL // only 5% to avoid conflict with NETBOX:
93 # define SIRCS_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SIRCS_START_BIT_PAUSE_TIME * MAX_TOLERANCE_05 + 0.5))
94 #else // only 5% + 1 to avoid conflict with RC6:
95 # define SIRCS_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SIRCS_START_BIT_PAUSE_TIME * MAX_TOLERANCE_05 + 0.5) + 1)
96 #endif
97 #define SIRCS_1_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SIRCS_1_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
98 #define SIRCS_1_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SIRCS_1_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
99 #define SIRCS_0_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SIRCS_0_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
100 #define SIRCS_0_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SIRCS_0_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
101 #define SIRCS_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SIRCS_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
102 #define SIRCS_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SIRCS_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
103
104 #define NEC_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NEC_START_BIT_PULSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1)
105 #define NEC_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NEC_START_BIT_PULSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1)
106 #define NEC_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NEC_START_BIT_PAUSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1)
107 #define NEC_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NEC_START_BIT_PAUSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1)
108 #define NEC_REPEAT_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NEC_REPEAT_START_BIT_PAUSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1)
109 #define NEC_REPEAT_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NEC_REPEAT_START_BIT_PAUSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1)
110 #define NEC_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NEC_PULSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1)
111 #define NEC_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NEC_PULSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1)
112 #define NEC_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NEC_1_PAUSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1)
113 #define NEC_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NEC_1_PAUSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1)
114 #define NEC_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NEC_0_PAUSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1)
115 #define NEC_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NEC_0_PAUSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1)
116 // autodetect nec repetition frame within 50 msec:
117 // NEC seems to send the first repetition frame after 40ms, further repetition frames after 100 ms
118 #if 0
119 #define NEC_FRAME_REPEAT_PAUSE_LEN_MAX (uint16_t)(F_INTERRUPTS * NEC_FRAME_REPEAT_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5)
120 #else
121 #define NEC_FRAME_REPEAT_PAUSE_LEN_MAX (uint16_t)(F_INTERRUPTS * 100.0e-3 * MAX_TOLERANCE_20 + 0.5)
122 #endif
123
124 #define SAMSUNG_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SAMSUNG_START_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
125 #define SAMSUNG_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SAMSUNG_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
126 #define SAMSUNG_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SAMSUNG_START_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
127 #define SAMSUNG_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SAMSUNG_START_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
128 #define SAMSUNG_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SAMSUNG_PULSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1)
129 #define SAMSUNG_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SAMSUNG_PULSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1)
130 #define SAMSUNG_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SAMSUNG_1_PAUSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1)
131 #define SAMSUNG_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SAMSUNG_1_PAUSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1)
132 #define SAMSUNG_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SAMSUNG_0_PAUSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1)
133 #define SAMSUNG_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SAMSUNG_0_PAUSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1)
134
135 #define MATSUSHITA_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * MATSUSHITA_START_BIT_PULSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
136 #define MATSUSHITA_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * MATSUSHITA_START_BIT_PULSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
137 #define MATSUSHITA_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * MATSUSHITA_START_BIT_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
138 #define MATSUSHITA_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * MATSUSHITA_START_BIT_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
139 #define MATSUSHITA_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * MATSUSHITA_PULSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1)
140 #define MATSUSHITA_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * MATSUSHITA_PULSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1)
141 #define MATSUSHITA_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * MATSUSHITA_1_PAUSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1)
142 #define MATSUSHITA_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * MATSUSHITA_1_PAUSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1)
143 #define MATSUSHITA_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * MATSUSHITA_0_PAUSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1)
144 #define MATSUSHITA_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * MATSUSHITA_0_PAUSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1)
145
146 #define KASEIKYO_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * KASEIKYO_START_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
147 #define KASEIKYO_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * KASEIKYO_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
148 #define KASEIKYO_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * KASEIKYO_START_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
149 #define KASEIKYO_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * KASEIKYO_START_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
150 #define KASEIKYO_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * KASEIKYO_PULSE_TIME * MIN_TOLERANCE_50 + 0.5) - 1)
151 #define KASEIKYO_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * KASEIKYO_PULSE_TIME * MAX_TOLERANCE_50 + 0.5) + 1)
152 #define KASEIKYO_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * KASEIKYO_1_PAUSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1)
153 #define KASEIKYO_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * KASEIKYO_1_PAUSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1)
154 #define KASEIKYO_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * KASEIKYO_0_PAUSE_TIME * MIN_TOLERANCE_50 + 0.5) - 1)
155 #define KASEIKYO_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * KASEIKYO_0_PAUSE_TIME * MAX_TOLERANCE_50 + 0.5) + 1)
156
157 #define RECS80_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RECS80_START_BIT_PULSE_TIME * MIN_TOLERANCE_00 + 0.5) - 1)
158 #define RECS80_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RECS80_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
159 #define RECS80_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RECS80_START_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
160 #define RECS80_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RECS80_START_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
161 #define RECS80_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RECS80_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
162 #define RECS80_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RECS80_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
163 #define RECS80_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RECS80_1_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
164 #define RECS80_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RECS80_1_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
165 #define RECS80_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RECS80_0_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
166 #define RECS80_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RECS80_0_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
167
168
169 #if IRMP_SUPPORT_BOSE_PROTOCOL == 1 // BOSE conflicts with RC5, so keep tolerance for RC5 minimal here:
170 #define RC5_START_BIT_LEN_MIN ((uint8_t)(F_INTERRUPTS * RC5_BIT_TIME * MIN_TOLERANCE_05 + 0.5) - 1)
171 #define RC5_START_BIT_LEN_MAX ((uint8_t)(F_INTERRUPTS * RC5_BIT_TIME * MAX_TOLERANCE_05 + 0.5) + 1)
172 #else
173 #define RC5_START_BIT_LEN_MIN ((uint8_t)(F_INTERRUPTS * RC5_BIT_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
174 #define RC5_START_BIT_LEN_MAX ((uint8_t)(F_INTERRUPTS * RC5_BIT_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
175 #endif
176
177 #define RC5_BIT_LEN_MIN ((uint8_t)(F_INTERRUPTS * RC5_BIT_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
178 #define RC5_BIT_LEN_MAX ((uint8_t)(F_INTERRUPTS * RC5_BIT_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
179
180 #define DENON_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * DENON_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
181 #define DENON_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * DENON_PULSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
182 #define DENON_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * DENON_1_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
183 #define DENON_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * DENON_1_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
184 // RUWIDO (see t-home-mediareceiver-15kHz.txt) conflicts here with DENON
185 #define DENON_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * DENON_0_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
186 #define DENON_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * DENON_0_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
187 #define DENON_AUTO_REPETITION_PAUSE_LEN ((uint16_t)(F_INTERRUPTS * DENON_AUTO_REPETITION_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
188
189 #define THOMSON_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * THOMSON_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
190 #define THOMSON_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * THOMSON_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
191 #define THOMSON_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * THOMSON_1_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
192 #define THOMSON_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * THOMSON_1_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
193 #define THOMSON_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * THOMSON_0_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
194 #define THOMSON_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * THOMSON_0_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
195
196 #define RC6_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RC6_START_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
197 #define RC6_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RC6_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
198 #define RC6_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RC6_START_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
199 #define RC6_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RC6_START_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
200 #define RC6_TOGGLE_BIT_LEN_MIN ((uint8_t)(F_INTERRUPTS * RC6_TOGGLE_BIT_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
201 #define RC6_TOGGLE_BIT_LEN_MAX ((uint8_t)(F_INTERRUPTS * RC6_TOGGLE_BIT_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
202 #define RC6_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RC6_BIT_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
203 #define RC6_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RC6_BIT_TIME * MAX_TOLERANCE_60 + 0.5) + 1) // pulses: 300 - 800
204 #define RC6_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RC6_BIT_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
205 #define RC6_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RC6_BIT_TIME * MAX_TOLERANCE_20 + 0.5) + 1) // pauses: 300 - 600
206
207 #define RECS80EXT_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RECS80EXT_START_BIT_PULSE_TIME * MIN_TOLERANCE_00 + 0.5) - 1)
208 #define RECS80EXT_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RECS80EXT_START_BIT_PULSE_TIME * MAX_TOLERANCE_00 + 0.5) + 1)
209 #define RECS80EXT_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RECS80EXT_START_BIT_PAUSE_TIME * MIN_TOLERANCE_05 + 0.5) - 1)
210 #define RECS80EXT_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RECS80EXT_START_BIT_PAUSE_TIME * MAX_TOLERANCE_05 + 0.5) + 1)
211 #define RECS80EXT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RECS80EXT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
212 #define RECS80EXT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RECS80EXT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
213 #define RECS80EXT_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RECS80EXT_1_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
214 #define RECS80EXT_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RECS80EXT_1_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
215 #define RECS80EXT_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RECS80EXT_0_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
216 #define RECS80EXT_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RECS80EXT_0_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
217
218 #define NUBERT_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NUBERT_START_BIT_PULSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
219 #define NUBERT_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NUBERT_START_BIT_PULSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
220 #define NUBERT_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NUBERT_START_BIT_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
221 #define NUBERT_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NUBERT_START_BIT_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
222 #define NUBERT_1_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NUBERT_1_PULSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
223 #define NUBERT_1_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NUBERT_1_PULSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
224 #define NUBERT_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NUBERT_1_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
225 #define NUBERT_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NUBERT_1_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
226 #define NUBERT_0_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NUBERT_0_PULSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
227 #define NUBERT_0_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NUBERT_0_PULSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
228 #define NUBERT_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NUBERT_0_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
229 #define NUBERT_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NUBERT_0_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
230
231 #define BANG_OLUFSEN_START_BIT1_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT1_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
232 #define BANG_OLUFSEN_START_BIT1_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT1_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
233 #define BANG_OLUFSEN_START_BIT1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT1_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
234 #define BANG_OLUFSEN_START_BIT1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT1_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
235 #define BANG_OLUFSEN_START_BIT2_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT2_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
236 #define BANG_OLUFSEN_START_BIT2_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT2_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
237 #define BANG_OLUFSEN_START_BIT2_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT2_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
238 #define BANG_OLUFSEN_START_BIT2_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT2_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
239 #define BANG_OLUFSEN_START_BIT3_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT3_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
240 #define BANG_OLUFSEN_START_BIT3_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT3_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
241 #define BANG_OLUFSEN_START_BIT3_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT3_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
242 #define BANG_OLUFSEN_START_BIT3_PAUSE_LEN_MAX ((PAUSE_LEN)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT3_PAUSE_TIME * MAX_TOLERANCE_05 + 0.5) + 1) // value must be below IRMP_TIMEOUT
243 #define BANG_OLUFSEN_START_BIT4_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT4_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
244 #define BANG_OLUFSEN_START_BIT4_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT4_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
245 #define BANG_OLUFSEN_START_BIT4_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT4_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
246 #define BANG_OLUFSEN_START_BIT4_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT4_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
247 #define BANG_OLUFSEN_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
248 #define BANG_OLUFSEN_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
249 #define BANG_OLUFSEN_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_1_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
250 #define BANG_OLUFSEN_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_1_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
251 #define BANG_OLUFSEN_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_0_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
252 #define BANG_OLUFSEN_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_0_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
253 #define BANG_OLUFSEN_R_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_R_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
254 #define BANG_OLUFSEN_R_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_R_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
255 #define BANG_OLUFSEN_TRAILER_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_TRAILER_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
256 #define BANG_OLUFSEN_TRAILER_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_TRAILER_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
257
258 #define IR60_TIMEOUT_LEN ((uint8_t)(F_INTERRUPTS * IR60_TIMEOUT_TIME * 0.5))
259 #define GRUNDIG_NOKIA_IR60_START_BIT_LEN_MIN ((uint8_t)(F_INTERRUPTS * GRUNDIG_NOKIA_IR60_BIT_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
260 #define GRUNDIG_NOKIA_IR60_START_BIT_LEN_MAX ((uint8_t)(F_INTERRUPTS * GRUNDIG_NOKIA_IR60_BIT_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
261 #define GRUNDIG_NOKIA_IR60_BIT_LEN_MIN ((uint8_t)(F_INTERRUPTS * GRUNDIG_NOKIA_IR60_BIT_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
262 #define GRUNDIG_NOKIA_IR60_BIT_LEN_MAX ((uint8_t)(F_INTERRUPTS * GRUNDIG_NOKIA_IR60_BIT_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
263 #define GRUNDIG_NOKIA_IR60_PRE_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * GRUNDIG_NOKIA_IR60_PRE_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) + 1)
264 #define GRUNDIG_NOKIA_IR60_PRE_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * GRUNDIG_NOKIA_IR60_PRE_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
265
266 #define SIEMENS_OR_RUWIDO_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SIEMENS_OR_RUWIDO_START_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
267 #define SIEMENS_OR_RUWIDO_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SIEMENS_OR_RUWIDO_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
268 #define SIEMENS_OR_RUWIDO_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SIEMENS_OR_RUWIDO_START_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
269 #define SIEMENS_OR_RUWIDO_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SIEMENS_OR_RUWIDO_START_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
270 #define SIEMENS_OR_RUWIDO_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SIEMENS_OR_RUWIDO_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
271 #define SIEMENS_OR_RUWIDO_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SIEMENS_OR_RUWIDO_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
272 #define SIEMENS_OR_RUWIDO_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SIEMENS_OR_RUWIDO_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
273 #define SIEMENS_OR_RUWIDO_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SIEMENS_OR_RUWIDO_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
274
275 #define FDC_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * FDC_START_BIT_PULSE_TIME * MIN_TOLERANCE_05 + 0.5) - 1) // 5%: avoid conflict with NETBOX
276 #define FDC_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * FDC_START_BIT_PULSE_TIME * MAX_TOLERANCE_05 + 0.5))
277 #define FDC_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * FDC_START_BIT_PAUSE_TIME * MIN_TOLERANCE_05 + 0.5) - 1)
278 #define FDC_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * FDC_START_BIT_PAUSE_TIME * MAX_TOLERANCE_05 + 0.5))
279 #define FDC_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * FDC_PULSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1)
280 #define FDC_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * FDC_PULSE_TIME * MAX_TOLERANCE_50 + 0.5) + 1)
281 #define FDC_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * FDC_1_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
282 #define FDC_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * FDC_1_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
283 #if 0
284 #define FDC_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * FDC_0_PAUSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1) // could be negative: 255
285 #else
286 #define FDC_0_PAUSE_LEN_MIN (1) // simply use 1
287 #endif
288 #define FDC_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * FDC_0_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
289
290 #define RCCAR_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RCCAR_START_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
291 #define RCCAR_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RCCAR_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
292 #define RCCAR_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RCCAR_START_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
293 #define RCCAR_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RCCAR_START_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
294 #define RCCAR_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RCCAR_PULSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
295 #define RCCAR_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RCCAR_PULSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
296 #define RCCAR_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RCCAR_1_PAUSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1)
297 #define RCCAR_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RCCAR_1_PAUSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1)
298 #define RCCAR_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RCCAR_0_PAUSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1)
299 #define RCCAR_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RCCAR_0_PAUSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1)
300
301 #define JVC_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * JVC_START_BIT_PULSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1)
302 #define JVC_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * JVC_START_BIT_PULSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1)
303 #define JVC_REPEAT_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * (JVC_FRAME_REPEAT_PAUSE_TIME - IRMP_TIMEOUT_TIME) * MIN_TOLERANCE_40 + 0.5) - 1) // HACK!
304 #define JVC_REPEAT_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * (JVC_FRAME_REPEAT_PAUSE_TIME - IRMP_TIMEOUT_TIME) * MAX_TOLERANCE_70 + 0.5) - 1) // HACK!
305 #define JVC_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * JVC_PULSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1)
306 #define JVC_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * JVC_PULSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1)
307 #define JVC_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * JVC_1_PAUSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1)
308 #define JVC_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * JVC_1_PAUSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1)
309 #define JVC_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * JVC_0_PAUSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1)
310 #define JVC_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * JVC_0_PAUSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1)
311 // autodetect JVC repetition frame within 50 msec:
312 #define JVC_FRAME_REPEAT_PAUSE_LEN_MAX (uint16_t)(F_INTERRUPTS * JVC_FRAME_REPEAT_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5)
313
314 #define NIKON_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NIKON_START_BIT_PULSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
315 #define NIKON_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NIKON_START_BIT_PULSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
316 #define NIKON_START_BIT_PAUSE_LEN_MIN ((uint16_t)(F_INTERRUPTS * NIKON_START_BIT_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
317 #define NIKON_START_BIT_PAUSE_LEN_MAX ((uint16_t)(F_INTERRUPTS * NIKON_START_BIT_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
318 #define NIKON_REPEAT_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NIKON_REPEAT_START_BIT_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
319 #define NIKON_REPEAT_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NIKON_REPEAT_START_BIT_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
320 #define NIKON_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NIKON_PULSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
321 #define NIKON_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NIKON_PULSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
322 #define NIKON_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NIKON_1_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
323 #define NIKON_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NIKON_1_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
324 #define NIKON_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NIKON_0_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
325 #define NIKON_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NIKON_0_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
326 #define NIKON_FRAME_REPEAT_PAUSE_LEN_MAX (uint16_t)(F_INTERRUPTS * NIKON_FRAME_REPEAT_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5)
327
328 #define KATHREIN_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * KATHREIN_START_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
329 #define KATHREIN_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * KATHREIN_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
330 #define KATHREIN_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * KATHREIN_START_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
331 #define KATHREIN_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * KATHREIN_START_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
332 #define KATHREIN_1_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * KATHREIN_1_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
333 #define KATHREIN_1_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * KATHREIN_1_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
334 #define KATHREIN_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * KATHREIN_1_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
335 #define KATHREIN_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * KATHREIN_1_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
336 #define KATHREIN_0_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * KATHREIN_0_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
337 #define KATHREIN_0_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * KATHREIN_0_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
338 #define KATHREIN_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * KATHREIN_0_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
339 #define KATHREIN_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * KATHREIN_0_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
340 #define KATHREIN_SYNC_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * KATHREIN_SYNC_BIT_PAUSE_LEN_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
341 #define KATHREIN_SYNC_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * KATHREIN_SYNC_BIT_PAUSE_LEN_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
342
343 #define NETBOX_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NETBOX_START_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
344 #define NETBOX_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NETBOX_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
345 #define NETBOX_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NETBOX_START_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
346 #define NETBOX_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NETBOX_START_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
347 #define NETBOX_PULSE_LEN ((uint8_t)(F_INTERRUPTS * NETBOX_PULSE_TIME))
348 #define NETBOX_PAUSE_LEN ((uint8_t)(F_INTERRUPTS * NETBOX_PAUSE_TIME))
349 #define NETBOX_PULSE_REST_LEN ((uint8_t)(F_INTERRUPTS * NETBOX_PULSE_TIME / 4))
350 #define NETBOX_PAUSE_REST_LEN ((uint8_t)(F_INTERRUPTS * NETBOX_PAUSE_TIME / 4))
351
352 #define LEGO_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * LEGO_START_BIT_PULSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1)
353 #define LEGO_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * LEGO_START_BIT_PULSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1)
354 #define LEGO_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * LEGO_START_BIT_PAUSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1)
355 #define LEGO_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * LEGO_START_BIT_PAUSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1)
356 #define LEGO_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * LEGO_PULSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1)
357 #define LEGO_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * LEGO_PULSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1)
358 #define LEGO_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * LEGO_1_PAUSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1)
359 #define LEGO_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * LEGO_1_PAUSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1)
360 #define LEGO_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * LEGO_0_PAUSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1)
361 #define LEGO_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * LEGO_0_PAUSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1)
362
363 #define BOSE_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BOSE_START_BIT_PULSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1)
364 #define BOSE_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BOSE_START_BIT_PULSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1)
365 #define BOSE_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BOSE_START_BIT_PAUSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1)
366 #define BOSE_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BOSE_START_BIT_PAUSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1)
367 #define BOSE_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BOSE_PULSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1)
368 #define BOSE_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BOSE_PULSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1)
369 #define BOSE_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BOSE_1_PAUSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1)
370 #define BOSE_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BOSE_1_PAUSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1)
371 #define BOSE_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BOSE_0_PAUSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1)
372 #define BOSE_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BOSE_0_PAUSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1)
373 #define BOSE_FRAME_REPEAT_PAUSE_LEN_MAX (uint16_t)(F_INTERRUPTS * 100.0e-3 * MAX_TOLERANCE_20 + 0.5)
374
375 #define AUTO_FRAME_REPETITION_LEN (uint16_t)(F_INTERRUPTS * AUTO_FRAME_REPETITION_TIME + 0.5) // use uint16_t!
376
377 #ifdef ANALYZE
378 # define ANALYZE_PUTCHAR(a) { if (! silent) { putchar (a); } }
379 # define ANALYZE_ONLY_NORMAL_PUTCHAR(a) { if (! silent && !verbose) { putchar (a); } }
380 # define ANALYZE_PRINTF(...) { if (verbose) { printf (__VA_ARGS__); } }
381 # define ANALYZE_NEWLINE() { if (verbose) { putchar ('\n'); } }
382 static int silent;
383 static int time_counter;
384 static int verbose;
385 #else
386 # define ANALYZE_PUTCHAR(a)
387 # define ANALYZE_ONLY_NORMAL_PUTCHAR(a)
388 # define ANALYZE_PRINTF(...)
389 # define ANALYZE_NEWLINE()
390 #endif
391
392 #if IRMP_USE_CALLBACK == 1
393 static void (*irmp_callback_ptr) (uint8_t);
394 #endif // IRMP_USE_CALLBACK == 1
395
396 /*---------------------------------------------------------------------------------------------------------------------------------------------------
397 * Protocol names
398 *---------------------------------------------------------------------------------------------------------------------------------------------------
399 */
400 #if IRMP_PROTOCOL_NAMES == 1
401 char *
402 irmp_protocol_names[IRMP_N_PROTOCOLS + 1] =
403 {
404 "UNKNOWN",
405 "SIRCS",
406 "NEC",
407 "SAMSUNG",
408 "MATSUSH",
409 "KASEIKYO",
410 "RECS80",
411 "RC5",
412 "DENON",
413 "RC6",
414 "SAMSG32",
415 "APPLE",
416 "RECS80EX",
417 "NUBERT",
418 "BANG OLU",
419 "GRUNDIG",
420 "NOKIA",
421 "SIEMENS",
422 "FDC",
423 "RCCAR",
424 "JVC",
425 "RC6A",
426 "NIKON",
427 "RUWIDO",
428 "IR60",
429 "KATHREIN",
430 "NETBOX",
431 "NEC16",
432 "NEC42",
433 "LEGO",
434 "THOMSON",
435 "BOSE"
436 };
437 #endif
438
439 /*---------------------------------------------------------------------------------------------------------------------------------------------------
440 * Logging
441 *---------------------------------------------------------------------------------------------------------------------------------------------------
442 */
443 #if IRMP_LOGGING == 1 // logging via UART
444
445 #if IRMP_EXT_LOGGING == 1 // use external logging
446 #include "irmpextlog.h"
447 #else // normal UART log (IRMP_EXT_LOGGING == 0)
448 #define BAUD 9600L
449 #include <util/setbaud.h>
450
451 #ifdef UBRR0H
452
453 #define UART0_UBRRH UBRR0H
454 #define UART0_UBRRL UBRR0L
455 #define UART0_UCSRA UCSR0A
456 #define UART0_UCSRB UCSR0B
457 #define UART0_UCSRC UCSR0C
458 #define UART0_UDRE_BIT_VALUE (1<<UDRE0)
459 #define UART0_UCSZ1_BIT_VALUE (1<<UCSZ01)
460 #define UART0_UCSZ0_BIT_VALUE (1<<UCSZ00)
461 #ifdef URSEL0
462 #define UART0_URSEL_BIT_VALUE (1<<URSEL0)
463 #else
464 #define UART0_URSEL_BIT_VALUE (0)
465 #endif
466 #define UART0_TXEN_BIT_VALUE (1<<TXEN0)
467 #define UART0_UDR UDR0
468 #define UART0_U2X U2X0
469
470 #else
471
472 #define UART0_UBRRH UBRRH
473 #define UART0_UBRRL UBRRL
474 #define UART0_UCSRA UCSRA
475 #define UART0_UCSRB UCSRB
476 #define UART0_UCSRC UCSRC
477 #define UART0_UDRE_BIT_VALUE (1<<UDRE)
478 #define UART0_UCSZ1_BIT_VALUE (1<<UCSZ1)
479 #define UART0_UCSZ0_BIT_VALUE (1<<UCSZ0)
480 #ifdef URSEL
481 #define UART0_URSEL_BIT_VALUE (1<<URSEL)
482 #else
483 #define UART0_URSEL_BIT_VALUE (0)
484 #endif
485 #define UART0_TXEN_BIT_VALUE (1<<TXEN)
486 #define UART0_UDR UDR
487 #define UART0_U2X U2X
488
489 #endif //UBRR0H
490 #endif //IRMP_EXT_LOGGING
491
492 /*---------------------------------------------------------------------------------------------------------------------------------------------------
493 * Initialize UART
494 * @details Initializes UART
495 *---------------------------------------------------------------------------------------------------------------------------------------------------
496 */
497 void
498 irmp_uart_init (void)
499 {
500 #if (IRMP_EXT_LOGGING == 0) // use UART
501 UART0_UBRRH = UBRRH_VALUE; // set baud rate
502 UART0_UBRRL = UBRRL_VALUE;
503
504 #if USE_2X
505 UART0_UCSRA |= (1<<UART0_U2X);
506 #else
507 UART0_UCSRA &= ~(1<<UART0_U2X);
508 #endif
509
510 UART0_UCSRC = UART0_UCSZ1_BIT_VALUE | UART0_UCSZ0_BIT_VALUE | UART0_URSEL_BIT_VALUE;
511 UART0_UCSRB |= UART0_TXEN_BIT_VALUE; // enable UART TX
512 #else // other log method
513 initextlog();
514 #endif //IRMP_EXT_LOGGING
515 }
516
517 /*---------------------------------------------------------------------------------------------------------------------------------------------------
518 * Send character
519 * @details Sends character
520 * @param ch character to be transmitted
521 *---------------------------------------------------------------------------------------------------------------------------------------------------
522 */
523 void
524 irmp_uart_putc (unsigned char ch)
525 {
526 #if (IRMP_EXT_LOGGING == 0)
527 while (!(UART0_UCSRA & UART0_UDRE_BIT_VALUE))
528 {
529 ;
530 }
531
532 UART0_UDR = ch;
533 #else
534 sendextlog(ch); //Use external log
535 #endif
536 }
537
538 /*---------------------------------------------------------------------------------------------------------------------------------------------------
539 * Log IR signal
540 *---------------------------------------------------------------------------------------------------------------------------------------------------
541 */
542
543 #define STARTCYCLES 2 // min count of zeros before start of logging
544 #define ENDBITS 1000 // number of sequenced highbits to detect end
545 #define DATALEN 700 // log buffer size
546
547 static void
548 irmp_log (uint8_t val)
549 {
550 static uint8_t buf[DATALEN]; // logging buffer
551 static uint16_t buf_idx; // number of written bits
552 static uint8_t startcycles; // current number of start-zeros
553 static uint16_t cnt; // counts sequenced highbits - to detect end
554
555 if (! val && (startcycles < STARTCYCLES) && !buf_idx) // prevent that single random zeros init logging
556 {
557 startcycles++;
558 }
559 else
560 {
561 startcycles = 0;
562
563 if (! val || (val && buf_idx != 0)) // start or continue logging on "0", "1" cannot init logging
564 {
565 if (buf_idx < DATALEN * 8) // index in range?
566 { // yes
567 if (val)
568 {
569 buf[(buf_idx / 8)] |= (1<<(buf_idx % 8)); // set bit
570 }
571 else
572 {
573 buf[(buf_idx / 8)] &= ~(1<<(buf_idx % 8)); // reset bit
574 }
575
576 buf_idx++;
577 }
578
579 if (val)
580 { // if high received then look at log-stop condition
581 cnt++;
582
583 if (cnt > ENDBITS)
584 { // if stop condition is true, output on uart
585 uint16_t i;
586
587 for (i = 0; i < STARTCYCLES; i++)
588 {
589 irmp_uart_putc ('0'); // the ignored starting zeros
590 }
591
592 for (i = 0; i < (buf_idx - ENDBITS + 20) / 8; i++) // transform bitset into uart chars
593 {
594 uint8_t d = buf[i];
595 uint8_t j;
596
597 for (j = 0; j < 8; j++)
598 {
599 irmp_uart_putc ((d & 1) + '0');
600 d >>= 1;
601 }
602 }
603
604 irmp_uart_putc ('\n');
605 buf_idx = 0;
606 }
607 }
608 else
609 {
610 cnt = 0;
611 }
612 }
613 }
614 }
615
616 #else
617 #define irmp_log(val)
618 #endif //IRMP_LOGGING
619
620 typedef struct
621 {
622 uint8_t protocol; // ir protocol
623 uint8_t pulse_1_len_min; // minimum length of pulse with bit value 1
624 uint8_t pulse_1_len_max; // maximum length of pulse with bit value 1
625 uint8_t pause_1_len_min; // minimum length of pause with bit value 1
626 uint8_t pause_1_len_max; // maximum length of pause with bit value 1
627 uint8_t pulse_0_len_min; // minimum length of pulse with bit value 0
628 uint8_t pulse_0_len_max; // maximum length of pulse with bit value 0
629 uint8_t pause_0_len_min; // minimum length of pause with bit value 0
630 uint8_t pause_0_len_max; // maximum length of pause with bit value 0
631 uint8_t address_offset; // address offset
632 uint8_t address_end; // end of address
633 uint8_t command_offset; // command offset
634 uint8_t command_end; // end of command
635 uint8_t complete_len; // complete length of frame
636 uint8_t stop_bit; // flag: frame has stop bit
637 uint8_t lsb_first; // flag: LSB first
638 uint8_t flags; // some flags
639 } IRMP_PARAMETER;
640
641 #if IRMP_SUPPORT_SIRCS_PROTOCOL == 1
642
643 static const PROGMEM IRMP_PARAMETER sircs_param =
644 {
645 IRMP_SIRCS_PROTOCOL, // protocol: ir protocol
646 SIRCS_1_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1
647 SIRCS_1_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1
648 SIRCS_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1
649 SIRCS_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1
650 SIRCS_0_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0
651 SIRCS_0_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0
652 SIRCS_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0
653 SIRCS_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0
654 SIRCS_ADDRESS_OFFSET, // address_offset: address offset
655 SIRCS_ADDRESS_OFFSET + SIRCS_ADDRESS_LEN, // address_end: end of address
656 SIRCS_COMMAND_OFFSET, // command_offset: command offset
657 SIRCS_COMMAND_OFFSET + SIRCS_COMMAND_LEN, // command_end: end of command
658 SIRCS_COMPLETE_DATA_LEN, // complete_len: complete length of frame
659 SIRCS_STOP_BIT, // stop_bit: flag: frame has stop bit
660 SIRCS_LSB, // lsb_first: flag: LSB first
661 SIRCS_FLAGS // flags: some flags
662 };
663
664 #endif
665
666 #if IRMP_SUPPORT_NEC_PROTOCOL == 1
667
668 static const PROGMEM IRMP_PARAMETER nec_param =
669 {
670 IRMP_NEC_PROTOCOL, // protocol: ir protocol
671 NEC_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1
672 NEC_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1
673 NEC_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1
674 NEC_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1
675 NEC_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0
676 NEC_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0
677 NEC_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0
678 NEC_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0
679 NEC_ADDRESS_OFFSET, // address_offset: address offset
680 NEC_ADDRESS_OFFSET + NEC_ADDRESS_LEN, // address_end: end of address
681 NEC_COMMAND_OFFSET, // command_offset: command offset
682 NEC_COMMAND_OFFSET + NEC_COMMAND_LEN, // command_end: end of command
683 NEC_COMPLETE_DATA_LEN, // complete_len: complete length of frame
684 NEC_STOP_BIT, // stop_bit: flag: frame has stop bit
685 NEC_LSB, // lsb_first: flag: LSB first
686 NEC_FLAGS // flags: some flags
687 };
688
689 static const PROGMEM IRMP_PARAMETER nec_rep_param =
690 {
691 IRMP_NEC_PROTOCOL, // protocol: ir protocol
692 NEC_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1
693 NEC_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1
694 NEC_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1
695 NEC_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1
696 NEC_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0
697 NEC_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0
698 NEC_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0
699 NEC_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0
700 0, // address_offset: address offset
701 0, // address_end: end of address
702 0, // command_offset: command offset
703 0, // command_end: end of command
704 0, // complete_len: complete length of frame
705 NEC_STOP_BIT, // stop_bit: flag: frame has stop bit
706 NEC_LSB, // lsb_first: flag: LSB first
707 NEC_FLAGS // flags: some flags
708 };
709
710 #endif
711
712 #if IRMP_SUPPORT_NEC42_PROTOCOL == 1
713
714 static const PROGMEM IRMP_PARAMETER nec42_param =
715 {
716 IRMP_NEC42_PROTOCOL, // protocol: ir protocol
717 NEC_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1
718 NEC_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1
719 NEC_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1
720 NEC_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1
721 NEC_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0
722 NEC_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0
723 NEC_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0
724 NEC_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0
725 NEC42_ADDRESS_OFFSET, // address_offset: address offset
726 NEC42_ADDRESS_OFFSET + NEC42_ADDRESS_LEN, // address_end: end of address
727 NEC42_COMMAND_OFFSET, // command_offset: command offset
728 NEC42_COMMAND_OFFSET + NEC42_COMMAND_LEN, // command_end: end of command
729 NEC42_COMPLETE_DATA_LEN, // complete_len: complete length of frame
730 NEC_STOP_BIT, // stop_bit: flag: frame has stop bit
731 NEC_LSB, // lsb_first: flag: LSB first
732 NEC_FLAGS // flags: some flags
733 };
734
735 #endif
736
737 #if IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1
738
739 static const PROGMEM IRMP_PARAMETER samsung_param =
740 {
741 IRMP_SAMSUNG_PROTOCOL, // protocol: ir protocol
742 SAMSUNG_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1
743 SAMSUNG_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1
744 SAMSUNG_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1
745 SAMSUNG_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1
746 SAMSUNG_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0
747 SAMSUNG_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0
748 SAMSUNG_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0
749 SAMSUNG_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0
750 SAMSUNG_ADDRESS_OFFSET, // address_offset: address offset
751 SAMSUNG_ADDRESS_OFFSET + SAMSUNG_ADDRESS_LEN, // address_end: end of address
752 SAMSUNG_COMMAND_OFFSET, // command_offset: command offset
753 SAMSUNG_COMMAND_OFFSET + SAMSUNG_COMMAND_LEN, // command_end: end of command
754 SAMSUNG_COMPLETE_DATA_LEN, // complete_len: complete length of frame
755 SAMSUNG_STOP_BIT, // stop_bit: flag: frame has stop bit
756 SAMSUNG_LSB, // lsb_first: flag: LSB first
757 SAMSUNG_FLAGS // flags: some flags
758 };
759
760 #endif
761
762 #if IRMP_SUPPORT_MATSUSHITA_PROTOCOL == 1
763
764 static const PROGMEM IRMP_PARAMETER matsushita_param =
765 {
766 IRMP_MATSUSHITA_PROTOCOL, // protocol: ir protocol
767 MATSUSHITA_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1
768 MATSUSHITA_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1
769 MATSUSHITA_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1
770 MATSUSHITA_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1
771 MATSUSHITA_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0
772 MATSUSHITA_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0
773 MATSUSHITA_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0
774 MATSUSHITA_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0
775 MATSUSHITA_ADDRESS_OFFSET, // address_offset: address offset
776 MATSUSHITA_ADDRESS_OFFSET + MATSUSHITA_ADDRESS_LEN, // address_end: end of address
777 MATSUSHITA_COMMAND_OFFSET, // command_offset: command offset
778 MATSUSHITA_COMMAND_OFFSET + MATSUSHITA_COMMAND_LEN, // command_end: end of command
779 MATSUSHITA_COMPLETE_DATA_LEN, // complete_len: complete length of frame
780 MATSUSHITA_STOP_BIT, // stop_bit: flag: frame has stop bit
781 MATSUSHITA_LSB, // lsb_first: flag: LSB first
782 MATSUSHITA_FLAGS // flags: some flags
783 };
784
785 #endif
786
787 #if IRMP_SUPPORT_KASEIKYO_PROTOCOL == 1
788
789 static const PROGMEM IRMP_PARAMETER kaseikyo_param =
790 {
791 IRMP_KASEIKYO_PROTOCOL, // protocol: ir protocol
792 KASEIKYO_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1
793 KASEIKYO_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1
794 KASEIKYO_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1
795 KASEIKYO_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1
796 KASEIKYO_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0
797 KASEIKYO_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0
798 KASEIKYO_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0
799 KASEIKYO_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0
800 KASEIKYO_ADDRESS_OFFSET, // address_offset: address offset
801 KASEIKYO_ADDRESS_OFFSET + KASEIKYO_ADDRESS_LEN, // address_end: end of address
802 KASEIKYO_COMMAND_OFFSET, // command_offset: command offset
803 KASEIKYO_COMMAND_OFFSET + KASEIKYO_COMMAND_LEN, // command_end: end of command
804 KASEIKYO_COMPLETE_DATA_LEN, // complete_len: complete length of frame
805 KASEIKYO_STOP_BIT, // stop_bit: flag: frame has stop bit
806 KASEIKYO_LSB, // lsb_first: flag: LSB first
807 KASEIKYO_FLAGS // flags: some flags
808 };
809
810 #endif
811
812 #if IRMP_SUPPORT_RECS80_PROTOCOL == 1
813
814 static const PROGMEM IRMP_PARAMETER recs80_param =
815 {
816 IRMP_RECS80_PROTOCOL, // protocol: ir protocol
817 RECS80_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1
818 RECS80_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1
819 RECS80_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1
820 RECS80_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1
821 RECS80_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0
822 RECS80_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0
823 RECS80_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0
824 RECS80_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0
825 RECS80_ADDRESS_OFFSET, // address_offset: address offset
826 RECS80_ADDRESS_OFFSET + RECS80_ADDRESS_LEN, // address_end: end of address
827 RECS80_COMMAND_OFFSET, // command_offset: command offset
828 RECS80_COMMAND_OFFSET + RECS80_COMMAND_LEN, // command_end: end of command
829 RECS80_COMPLETE_DATA_LEN, // complete_len: complete length of frame
830 RECS80_STOP_BIT, // stop_bit: flag: frame has stop bit
831 RECS80_LSB, // lsb_first: flag: LSB first
832 RECS80_FLAGS // flags: some flags
833 };
834
835 #endif
836
837 #if IRMP_SUPPORT_RC5_PROTOCOL == 1
838
839 static const PROGMEM IRMP_PARAMETER rc5_param =
840 {
841 IRMP_RC5_PROTOCOL, // protocol: ir protocol
842 RC5_BIT_LEN_MIN, // pulse_1_len_min: here: minimum length of short pulse
843 RC5_BIT_LEN_MAX, // pulse_1_len_max: here: maximum length of short pulse
844 RC5_BIT_LEN_MIN, // pause_1_len_min: here: minimum length of short pause
845 RC5_BIT_LEN_MAX, // pause_1_len_max: here: maximum length of short pause
846 0, // pulse_0_len_min: here: not used
847 0, // pulse_0_len_max: here: not used
848 0, // pause_0_len_min: here: not used
849 0, // pause_0_len_max: here: not used
850 RC5_ADDRESS_OFFSET, // address_offset: address offset
851 RC5_ADDRESS_OFFSET + RC5_ADDRESS_LEN, // address_end: end of address
852 RC5_COMMAND_OFFSET, // command_offset: command offset
853 RC5_COMMAND_OFFSET + RC5_COMMAND_LEN, // command_end: end of command
854 RC5_COMPLETE_DATA_LEN, // complete_len: complete length of frame
855 RC5_STOP_BIT, // stop_bit: flag: frame has stop bit
856 RC5_LSB, // lsb_first: flag: LSB first
857 RC5_FLAGS // flags: some flags
858 };
859
860 #endif
861
862 #if IRMP_SUPPORT_DENON_PROTOCOL == 1
863
864 static const PROGMEM IRMP_PARAMETER denon_param =
865 {
866 IRMP_DENON_PROTOCOL, // protocol: ir protocol
867 DENON_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1
868 DENON_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1
869 DENON_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1
870 DENON_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1
871 DENON_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0
872 DENON_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0
873 DENON_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0
874 DENON_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0
875 DENON_ADDRESS_OFFSET, // address_offset: address offset
876 DENON_ADDRESS_OFFSET + DENON_ADDRESS_LEN, // address_end: end of address
877 DENON_COMMAND_OFFSET, // command_offset: command offset
878 DENON_COMMAND_OFFSET + DENON_COMMAND_LEN, // command_end: end of command
879 DENON_COMPLETE_DATA_LEN, // complete_len: complete length of frame
880 DENON_STOP_BIT, // stop_bit: flag: frame has stop bit
881 DENON_LSB, // lsb_first: flag: LSB first
882 DENON_FLAGS // flags: some flags
883 };
884
885 #endif
886
887 #if IRMP_SUPPORT_RC6_PROTOCOL == 1
888
889 static const PROGMEM IRMP_PARAMETER rc6_param =
890 {
891 IRMP_RC6_PROTOCOL, // protocol: ir protocol
892
893 RC6_BIT_PULSE_LEN_MIN, // pulse_1_len_min: here: minimum length of short pulse
894 RC6_BIT_PULSE_LEN_MAX, // pulse_1_len_max: here: maximum length of short pulse
895 RC6_BIT_PAUSE_LEN_MIN, // pause_1_len_min: here: minimum length of short pause
896 RC6_BIT_PAUSE_LEN_MAX, // pause_1_len_max: here: maximum length of short pause
897 0, // pulse_0_len_min: here: not used
898 0, // pulse_0_len_max: here: not used
899 0, // pause_0_len_min: here: not used
900 0, // pause_0_len_max: here: not used
901 RC6_ADDRESS_OFFSET, // address_offset: address offset
902 RC6_ADDRESS_OFFSET + RC6_ADDRESS_LEN, // address_end: end of address
903 RC6_COMMAND_OFFSET, // command_offset: command offset
904 RC6_COMMAND_OFFSET + RC6_COMMAND_LEN, // command_end: end of command
905 RC6_COMPLETE_DATA_LEN_SHORT, // complete_len: complete length of frame
906 RC6_STOP_BIT, // stop_bit: flag: frame has stop bit
907 RC6_LSB, // lsb_first: flag: LSB first
908 RC6_FLAGS // flags: some flags
909 };
910
911 #endif
912
913 #if IRMP_SUPPORT_RECS80EXT_PROTOCOL == 1
914
915 static const PROGMEM IRMP_PARAMETER recs80ext_param =
916 {
917 IRMP_RECS80EXT_PROTOCOL, // protocol: ir protocol
918 RECS80EXT_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1
919 RECS80EXT_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1
920 RECS80EXT_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1
921 RECS80EXT_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1
922 RECS80EXT_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0
923 RECS80EXT_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0
924 RECS80EXT_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0
925 RECS80EXT_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0
926 RECS80EXT_ADDRESS_OFFSET, // address_offset: address offset
927 RECS80EXT_ADDRESS_OFFSET + RECS80EXT_ADDRESS_LEN, // address_end: end of address
928 RECS80EXT_COMMAND_OFFSET, // command_offset: command offset
929 RECS80EXT_COMMAND_OFFSET + RECS80EXT_COMMAND_LEN, // command_end: end of command
930 RECS80EXT_COMPLETE_DATA_LEN, // complete_len: complete length of frame
931 RECS80EXT_STOP_BIT, // stop_bit: flag: frame has stop bit
932 RECS80EXT_LSB, // lsb_first: flag: LSB first
933 RECS80EXT_FLAGS // flags: some flags
934 };
935
936 #endif
937
938 #if IRMP_SUPPORT_NUBERT_PROTOCOL == 1
939
940 static const PROGMEM IRMP_PARAMETER nubert_param =
941 {
942 IRMP_NUBERT_PROTOCOL, // protocol: ir protocol
943 NUBERT_1_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1
944 NUBERT_1_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1
945 NUBERT_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1
946 NUBERT_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1
947 NUBERT_0_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0
948 NUBERT_0_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0
949 NUBERT_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0
950 NUBERT_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0
951 NUBERT_ADDRESS_OFFSET, // address_offset: address offset
952 NUBERT_ADDRESS_OFFSET + NUBERT_ADDRESS_LEN, // address_end: end of address
953 NUBERT_COMMAND_OFFSET, // command_offset: command offset
954 NUBERT_COMMAND_OFFSET + NUBERT_COMMAND_LEN, // command_end: end of command
955 NUBERT_COMPLETE_DATA_LEN, // complete_len: complete length of frame
956 NUBERT_STOP_BIT, // stop_bit: flag: frame has stop bit
957 NUBERT_LSB, // lsb_first: flag: LSB first
958 NUBERT_FLAGS // flags: some flags
959 };
960
961 #endif
962
963 #if IRMP_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1
964
965 static const PROGMEM IRMP_PARAMETER bang_olufsen_param =
966 {
967 IRMP_BANG_OLUFSEN_PROTOCOL, // protocol: ir protocol
968 BANG_OLUFSEN_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1
969 BANG_OLUFSEN_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1
970 BANG_OLUFSEN_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1
971 BANG_OLUFSEN_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1
972 BANG_OLUFSEN_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0
973 BANG_OLUFSEN_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0
974 BANG_OLUFSEN_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0
975 BANG_OLUFSEN_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0
976 BANG_OLUFSEN_ADDRESS_OFFSET, // address_offset: address offset
977 BANG_OLUFSEN_ADDRESS_OFFSET + BANG_OLUFSEN_ADDRESS_LEN, // address_end: end of address
978 BANG_OLUFSEN_COMMAND_OFFSET, // command_offset: command offset
979 BANG_OLUFSEN_COMMAND_OFFSET + BANG_OLUFSEN_COMMAND_LEN, // command_end: end of command
980 BANG_OLUFSEN_COMPLETE_DATA_LEN, // complete_len: complete length of frame
981 BANG_OLUFSEN_STOP_BIT, // stop_bit: flag: frame has stop bit
982 BANG_OLUFSEN_LSB, // lsb_first: flag: LSB first
983 BANG_OLUFSEN_FLAGS // flags: some flags
984 };
985
986 #endif
987
988 #if IRMP_SUPPORT_GRUNDIG_NOKIA_IR60_PROTOCOL == 1
989
990 static uint8_t first_bit;
991
992 static const PROGMEM IRMP_PARAMETER grundig_param =
993 {
994 IRMP_GRUNDIG_PROTOCOL, // protocol: ir protocol
995
996 GRUNDIG_NOKIA_IR60_BIT_LEN_MIN, // pulse_1_len_min: here: minimum length of short pulse
997 GRUNDIG_NOKIA_IR60_BIT_LEN_MAX, // pulse_1_len_max: here: maximum length of short pulse
998 GRUNDIG_NOKIA_IR60_BIT_LEN_MIN, // pause_1_len_min: here: minimum length of short pause
999 GRUNDIG_NOKIA_IR60_BIT_LEN_MAX, // pause_1_len_max: here: maximum length of short pause
1000 0, // pulse_0_len_min: here: not used
1001 0, // pulse_0_len_max: here: not used
1002 0, // pause_0_len_min: here: not used
1003 0, // pause_0_len_max: here: not used
1004 GRUNDIG_ADDRESS_OFFSET, // address_offset: address offset
1005 GRUNDIG_ADDRESS_OFFSET + GRUNDIG_ADDRESS_LEN, // address_end: end of address
1006 GRUNDIG_COMMAND_OFFSET, // command_offset: command offset
1007 GRUNDIG_COMMAND_OFFSET + GRUNDIG_COMMAND_LEN + 1, // command_end: end of command (USE 1 bit MORE to STORE NOKIA DATA!)
1008 NOKIA_COMPLETE_DATA_LEN, // complete_len: complete length of frame, here: NOKIA instead of GRUNDIG!
1009 GRUNDIG_NOKIA_IR60_STOP_BIT, // stop_bit: flag: frame has stop bit
1010 GRUNDIG_NOKIA_IR60_LSB, // lsb_first: flag: LSB first
1011 GRUNDIG_NOKIA_IR60_FLAGS // flags: some flags
1012 };
1013
1014 #endif
1015
1016 #if IRMP_SUPPORT_SIEMENS_OR_RUWIDO_PROTOCOL == 1
1017
1018 static const PROGMEM IRMP_PARAMETER ruwido_param =
1019 {
1020 IRMP_RUWIDO_PROTOCOL, // protocol: ir protocol
1021 SIEMENS_OR_RUWIDO_BIT_PULSE_LEN_MIN, // pulse_1_len_min: here: minimum length of short pulse
1022 SIEMENS_OR_RUWIDO_BIT_PULSE_LEN_MAX, // pulse_1_len_max: here: maximum length of short pulse
1023 SIEMENS_OR_RUWIDO_BIT_PAUSE_LEN_MIN, // pause_1_len_min: here: minimum length of short pause
1024 SIEMENS_OR_RUWIDO_BIT_PAUSE_LEN_MAX, // pause_1_len_max: here: maximum length of short pause
1025 0, // pulse_0_len_min: here: not used
1026 0, // pulse_0_len_max: here: not used
1027 0, // pause_0_len_min: here: not used
1028 0, // pause_0_len_max: here: not used
1029 RUWIDO_ADDRESS_OFFSET, // address_offset: address offset
1030 RUWIDO_ADDRESS_OFFSET + RUWIDO_ADDRESS_LEN, // address_end: end of address
1031 RUWIDO_COMMAND_OFFSET, // command_offset: command offset
1032 RUWIDO_COMMAND_OFFSET + RUWIDO_COMMAND_LEN, // command_end: end of command
1033 SIEMENS_COMPLETE_DATA_LEN, // complete_len: complete length of frame, here: SIEMENS instead of RUWIDO!
1034 SIEMENS_OR_RUWIDO_STOP_BIT, // stop_bit: flag: frame has stop bit
1035 SIEMENS_OR_RUWIDO_LSB, // lsb_first: flag: LSB first
1036 SIEMENS_OR_RUWIDO_FLAGS // flags: some flags
1037 };
1038
1039 #endif
1040
1041 #if IRMP_SUPPORT_FDC_PROTOCOL == 1
1042
1043 static const PROGMEM IRMP_PARAMETER fdc_param =
1044 {
1045 IRMP_FDC_PROTOCOL, // protocol: ir protocol
1046 FDC_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1
1047 FDC_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1
1048 FDC_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1
1049 FDC_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1
1050 FDC_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0
1051 FDC_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0
1052 FDC_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0
1053 FDC_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0
1054 FDC_ADDRESS_OFFSET, // address_offset: address offset
1055 FDC_ADDRESS_OFFSET + FDC_ADDRESS_LEN, // address_end: end of address
1056 FDC_COMMAND_OFFSET, // command_offset: command offset
1057 FDC_COMMAND_OFFSET + FDC_COMMAND_LEN, // command_end: end of command
1058 FDC_COMPLETE_DATA_LEN, // complete_len: complete length of frame
1059 FDC_STOP_BIT, // stop_bit: flag: frame has stop bit
1060 FDC_LSB, // lsb_first: flag: LSB first
1061 FDC_FLAGS // flags: some flags
1062 };
1063
1064 #endif
1065
1066 #if IRMP_SUPPORT_RCCAR_PROTOCOL == 1
1067
1068 static const PROGMEM IRMP_PARAMETER rccar_param =
1069 {
1070 IRMP_RCCAR_PROTOCOL, // protocol: ir protocol
1071 RCCAR_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1
1072 RCCAR_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1
1073 RCCAR_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1
1074 RCCAR_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1
1075 RCCAR_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0
1076 RCCAR_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0
1077 RCCAR_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0
1078 RCCAR_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0
1079 RCCAR_ADDRESS_OFFSET, // address_offset: address offset
1080 RCCAR_ADDRESS_OFFSET + RCCAR_ADDRESS_LEN, // address_end: end of address
1081 RCCAR_COMMAND_OFFSET, // command_offset: command offset
1082 RCCAR_COMMAND_OFFSET + RCCAR_COMMAND_LEN, // command_end: end of command
1083 RCCAR_COMPLETE_DATA_LEN, // complete_len: complete length of frame
1084 RCCAR_STOP_BIT, // stop_bit: flag: frame has stop bit
1085 RCCAR_LSB, // lsb_first: flag: LSB first
1086 RCCAR_FLAGS // flags: some flags
1087 };
1088
1089 #endif
1090
1091 #if IRMP_SUPPORT_NIKON_PROTOCOL == 1
1092
1093 static const PROGMEM IRMP_PARAMETER nikon_param =
1094 {
1095 IRMP_NIKON_PROTOCOL, // protocol: ir protocol
1096 NIKON_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1
1097 NIKON_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1
1098 NIKON_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1
1099 NIKON_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1
1100 NIKON_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0
1101 NIKON_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0
1102 NIKON_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0
1103 NIKON_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0
1104 NIKON_ADDRESS_OFFSET, // address_offset: address offset
1105 NIKON_ADDRESS_OFFSET + NIKON_ADDRESS_LEN, // address_end: end of address
1106 NIKON_COMMAND_OFFSET, // command_offset: command offset
1107 NIKON_COMMAND_OFFSET + NIKON_COMMAND_LEN, // command_end: end of command
1108 NIKON_COMPLETE_DATA_LEN, // complete_len: complete length of frame
1109 NIKON_STOP_BIT, // stop_bit: flag: frame has stop bit
1110 NIKON_LSB, // lsb_first: flag: LSB first
1111 NIKON_FLAGS // flags: some flags
1112 };
1113
1114 #endif
1115
1116 #if IRMP_SUPPORT_KATHREIN_PROTOCOL == 1
1117
1118 static const PROGMEM IRMP_PARAMETER kathrein_param =
1119 {
1120 IRMP_KATHREIN_PROTOCOL, // protocol: ir protocol
1121 KATHREIN_1_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1
1122 KATHREIN_1_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1
1123 KATHREIN_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1
1124 KATHREIN_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1
1125 KATHREIN_0_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0
1126 KATHREIN_0_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0
1127 KATHREIN_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0
1128 KATHREIN_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0
1129 KATHREIN_ADDRESS_OFFSET, // address_offset: address offset
1130 KATHREIN_ADDRESS_OFFSET + KATHREIN_ADDRESS_LEN, // address_end: end of address
1131 KATHREIN_COMMAND_OFFSET, // command_offset: command offset
1132 KATHREIN_COMMAND_OFFSET + KATHREIN_COMMAND_LEN, // command_end: end of command
1133 KATHREIN_COMPLETE_DATA_LEN, // complete_len: complete length of frame
1134 KATHREIN_STOP_BIT, // stop_bit: flag: frame has stop bit
1135 KATHREIN_LSB, // lsb_first: flag: LSB first
1136 KATHREIN_FLAGS // flags: some flags
1137 };
1138
1139 #endif
1140
1141 #if IRMP_SUPPORT_NETBOX_PROTOCOL == 1
1142
1143 static const PROGMEM IRMP_PARAMETER netbox_param =
1144 {
1145 IRMP_NETBOX_PROTOCOL, // protocol: ir protocol
1146 NETBOX_PULSE_LEN, // pulse_1_len_min: minimum length of pulse with bit value 1, here: exact value
1147 NETBOX_PULSE_REST_LEN, // pulse_1_len_max: maximum length of pulse with bit value 1, here: rest value
1148 NETBOX_PAUSE_LEN, // pause_1_len_min: minimum length of pause with bit value 1, here: exact value
1149 NETBOX_PAUSE_REST_LEN, // pause_1_len_max: maximum length of pause with bit value 1, here: rest value
1150 NETBOX_PULSE_LEN, // pulse_0_len_min: minimum length of pulse with bit value 0, here: exact value
1151 NETBOX_PULSE_REST_LEN, // pulse_0_len_max: maximum length of pulse with bit value 0, here: rest value
1152 NETBOX_PAUSE_LEN, // pause_0_len_min: minimum length of pause with bit value 0, here: exact value
1153 NETBOX_PAUSE_REST_LEN, // pause_0_len_max: maximum length of pause with bit value 0, here: rest value
1154 NETBOX_ADDRESS_OFFSET, // address_offset: address offset
1155 NETBOX_ADDRESS_OFFSET + NETBOX_ADDRESS_LEN, // address_end: end of address
1156 NETBOX_COMMAND_OFFSET, // command_offset: command offset
1157 NETBOX_COMMAND_OFFSET + NETBOX_COMMAND_LEN, // command_end: end of command
1158 NETBOX_COMPLETE_DATA_LEN, // complete_len: complete length of frame
1159 NETBOX_STOP_BIT, // stop_bit: flag: frame has stop bit
1160 NETBOX_LSB, // lsb_first: flag: LSB first
1161 NETBOX_FLAGS // flags: some flags
1162 };
1163
1164 #endif
1165
1166 #if IRMP_SUPPORT_LEGO_PROTOCOL == 1
1167
1168 static const PROGMEM IRMP_PARAMETER lego_param =
1169 {
1170 IRMP_LEGO_PROTOCOL, // protocol: ir protocol
1171 LEGO_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1
1172 LEGO_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1
1173 LEGO_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1
1174 LEGO_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1
1175 LEGO_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0
1176 LEGO_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0
1177 LEGO_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0
1178 LEGO_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0
1179 LEGO_ADDRESS_OFFSET, // address_offset: address offset
1180 LEGO_ADDRESS_OFFSET + LEGO_ADDRESS_LEN, // address_end: end of address
1181 LEGO_COMMAND_OFFSET, // command_offset: command offset
1182 LEGO_COMMAND_OFFSET + LEGO_COMMAND_LEN, // command_end: end of command
1183 LEGO_COMPLETE_DATA_LEN, // complete_len: complete length of frame
1184 LEGO_STOP_BIT, // stop_bit: flag: frame has stop bit
1185 LEGO_LSB, // lsb_first: flag: LSB first
1186 LEGO_FLAGS // flags: some flags
1187 };
1188
1189 #endif
1190
1191 #if IRMP_SUPPORT_THOMSON_PROTOCOL == 1
1192
1193 static const PROGMEM IRMP_PARAMETER thomson_param =
1194 {
1195 IRMP_THOMSON_PROTOCOL, // protocol: ir protocol
1196 THOMSON_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1
1197 THOMSON_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1
1198 THOMSON_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1
1199 THOMSON_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1
1200 THOMSON_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0
1201 THOMSON_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0
1202 THOMSON_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0
1203 THOMSON_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0
1204 THOMSON_ADDRESS_OFFSET, // address_offset: address offset
1205 THOMSON_ADDRESS_OFFSET + THOMSON_ADDRESS_LEN, // address_end: end of address
1206 THOMSON_COMMAND_OFFSET, // command_offset: command offset
1207 THOMSON_COMMAND_OFFSET + THOMSON_COMMAND_LEN, // command_end: end of command
1208 THOMSON_COMPLETE_DATA_LEN, // complete_len: complete length of frame
1209 THOMSON_STOP_BIT, // stop_bit: flag: frame has stop bit
1210 THOMSON_LSB, // lsb_first: flag: LSB first
1211 THOMSON_FLAGS // flags: some flags
1212 };
1213
1214 #endif
1215
1216 #if IRMP_SUPPORT_BOSE_PROTOCOL == 1
1217
1218 static const PROGMEM IRMP_PARAMETER bose_param =
1219 {
1220 IRMP_BOSE_PROTOCOL, // protocol: ir protocol
1221 BOSE_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1
1222 BOSE_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1
1223 BOSE_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1
1224 BOSE_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1
1225 BOSE_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0
1226 BOSE_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0
1227 BOSE_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0
1228 BOSE_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0
1229 BOSE_ADDRESS_OFFSET, // address_offset: address offset
1230 BOSE_ADDRESS_OFFSET + BOSE_ADDRESS_LEN, // address_end: end of address
1231 BOSE_COMMAND_OFFSET, // command_offset: command offset
1232 BOSE_COMMAND_OFFSET + BOSE_COMMAND_LEN, // command_end: end of command
1233 BOSE_COMPLETE_DATA_LEN, // complete_len: complete length of frame
1234 BOSE_STOP_BIT, // stop_bit: flag: frame has stop bit
1235 BOSE_LSB, // lsb_first: flag: LSB first
1236 BOSE_FLAGS // flags: some flags
1237 };
1238
1239 #endif
1240
1241 static uint8_t irmp_bit; // current bit position
1242 static IRMP_PARAMETER irmp_param;
1243
1244 #if IRMP_SUPPORT_RC5_PROTOCOL == 1 && (IRMP_SUPPORT_FDC_PROTOCOL == 1 || IRMP_SUPPORT_RCCAR_PROTOCOL == 1)
1245 static IRMP_PARAMETER irmp_param2;
1246 #endif
1247
1248 static volatile uint8_t irmp_ir_detected;
1249 static volatile uint8_t irmp_protocol;
1250 static volatile uint16_t irmp_address;
1251 static volatile uint16_t irmp_command;
1252 static volatile uint16_t irmp_id; // only used for SAMSUNG protocol
1253 static volatile uint8_t irmp_flags;
1254 // static volatile uint8_t irmp_busy_flag;
1255
1256 #ifdef ANALYZE
1257 #define input(x) (x)
1258 static uint8_t IRMP_PIN;
1259 #endif
1260
1261 /*---------------------------------------------------------------------------------------------------------------------------------------------------
1262 * Initialize IRMP decoder
1263 * @details Configures IRMP input pin
1264 *---------------------------------------------------------------------------------------------------------------------------------------------------
1265 */
1266 #ifndef ANALYZE
1267 void
1268 irmp_init (void)
1269 {
1270 #if defined(PIC_CCS) || defined(PIC_C18) // PIC: do nothing
1271 #elif defined (ARM_STM32) // STM32
1272 GPIO_InitTypeDef GPIO_InitStructure;
1273
1274 /* GPIOx clock enable */
1275 #if defined (ARM_STM32L1XX)
1276 RCC_AHBPeriphClockCmd(IRMP_PORT_RCC, ENABLE);
1277 #elif defined (ARM_STM32F10X)
1278 RCC_APB2PeriphClockCmd(IRMP_PORT_RCC, ENABLE);
1279 #elif defined (ARM_STM32F4XX)
1280 RCC_AHB1PeriphClockCmd(IRMP_PORT_RCC, ENABLE);
1281 #endif
1282
1283 /* GPIO Configuration */
1284 GPIO_InitStructure.GPIO_Pin = IRMP_BIT;
1285 #if defined (ARM_STM32L1XX) || defined (ARM_STM32F4XX)
1286 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
1287 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
1288 GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
1289 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
1290 #elif defined (ARM_STM32F10X)
1291 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
1292 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
1293 #endif
1294 GPIO_Init(IRMP_PORT, &GPIO_InitStructure);
1295 #else // AVR
1296 IRMP_PORT &= ~(1<<IRMP_BIT); // deactivate pullup
1297 IRMP_DDR &= ~(1<<IRMP_BIT); // set pin to input
1298 #endif
1299
1300 #if IRMP_LOGGING == 1
1301 irmp_uart_init ();
1302 #endif
1303 }
1304 #endif
1305 /*---------------------------------------------------------------------------------------------------------------------------------------------------
1306 * Get IRMP data
1307 * @details gets decoded IRMP data
1308 * @param pointer in order to store IRMP data
1309 * @return TRUE: successful, FALSE: failed
1310 *---------------------------------------------------------------------------------------------------------------------------------------------------
1311 */
1312 uint8_t
1313 irmp_get_data (IRMP_DATA * irmp_data_p)
1314 {
1315 uint8_t rtc = FALSE;
1316
1317 if (irmp_ir_detected)
1318 {
1319 switch (irmp_protocol)
1320 {
1321 #if IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1
1322 case IRMP_SAMSUNG_PROTOCOL:
1323 if ((irmp_command >> 8) == (~irmp_command & 0x00FF))
1324 {
1325 irmp_command &= 0xff;
1326 irmp_command |= irmp_id << 8;
1327 rtc = TRUE;
1328 }
1329 break;
1330 #endif
1331 #if IRMP_SUPPORT_NEC_PROTOCOL == 1
1332 case IRMP_NEC_PROTOCOL:
1333 if ((irmp_command >> 8) == (~irmp_command & 0x00FF))
1334 {
1335 irmp_command &= 0xff;
1336 rtc = TRUE;
1337 }
1338 else if (irmp_address == 0x87EE)
1339 {
1340 ANALYZE_PRINTF ("Switching to APPLE protocol\n");
1341 irmp_protocol = IRMP_APPLE_PROTOCOL;
1342 irmp_address = (irmp_command & 0xFF00) >> 8;
1343 irmp_command &= 0x00FF;
1344 rtc = TRUE;
1345 }
1346 break;
1347 #endif
1348 #if IRMP_SUPPORT_BOSE_PROTOCOL == 1
1349 case IRMP_BOSE_PROTOCOL:
1350 if ((irmp_command >> 8) == (~irmp_command & 0x00FF))
1351 {
1352 irmp_command &= 0xff;
1353 rtc = TRUE;
1354 }
1355 break;
1356 #endif
1357 #if IRMP_SUPPORT_SIEMENS_OR_RUWIDO_PROTOCOL == 1
1358 case IRMP_SIEMENS_PROTOCOL:
1359 case IRMP_RUWIDO_PROTOCOL:
1360 if (((irmp_command >> 1) & 0x0001) == (~irmp_command & 0x0001))
1361 {
1362 irmp_command >>= 1;
1363 rtc = TRUE;
1364 }
1365 break;
1366 #endif
1367 #if IRMP_SUPPORT_KATHREIN_PROTOCOL == 1
1368 case IRMP_KATHREIN_PROTOCOL:
1369 if (irmp_command != 0x0000)
1370 {
1371 rtc = TRUE;
1372 }
1373 break;
1374 #endif
1375 #if IRMP_SUPPORT_RC5_PROTOCOL == 1
1376 case IRMP_RC5_PROTOCOL:
1377 irmp_address &= ~0x20; // clear toggle bit
1378 rtc = TRUE;
1379 break;
1380 #endif
1381 #if IRMP_SUPPORT_IR60_PROTOCOL == 1
1382 case IRMP_IR60_PROTOCOL:
1383 if (irmp_command != 0x007d) // 0x007d (== 62<<1 + 1) is start instruction frame
1384 {
1385 rtc = TRUE;
1386 }
1387 else
1388 {
1389 ANALYZE_PRINTF("Info IR60: got start instruction frame\n");
1390 }
1391 break;
1392 #endif
1393 #if IRMP_SUPPORT_RCCAR_PROTOCOL == 1
1394 case IRMP_RCCAR_PROTOCOL:
1395 // frame in irmp_data:
1396 // Bit 12 11 10 9 8 7 6 5 4 3 2 1 0
1397 // V D7 D6 D5 D4 D3 D2 D1 D0 A1 A0 C1 C0 // 10 9 8 7 6 5 4 3 2 1 0
1398 irmp_address = (irmp_command & 0x000C) >> 2; // addr: 0 0 0 0 0 0 0 0 0 A1 A0
1399 irmp_command = ((irmp_command & 0x1000) >> 2) | // V-Bit: V 0 0 0 0 0 0 0 0 0 0
1400 ((irmp_command & 0x0003) << 8) | // C-Bits: 0 C1 C0 0 0 0 0 0 0 0 0
1401 ((irmp_command & 0x0FF0) >> 4); // D-Bits: D7 D6 D5 D4 D3 D2 D1 D0
1402 rtc = TRUE; // Summe: V C1 C0 D7 D6 D5 D4 D3 D2 D1 D0
1403 break;
1404 #endif
1405
1406 #if IRMP_SUPPORT_NETBOX_PROTOCOL == 1 // squeeze code to 8 bit, upper bit indicates release-key
1407 case IRMP_NETBOX_PROTOCOL:
1408 if (irmp_command & 0x1000) // last bit set?
1409 {
1410 if ((irmp_command & 0x1f) == 0x15) // key pressed: 101 01 (LSB)
1411 {
1412 irmp_command >>= 5;
1413 irmp_command &= 0x7F;
1414 rtc = TRUE;
1415 }
1416 else if ((irmp_command & 0x1f) == 0x10) // key released: 000 01 (LSB)
1417 {
1418 irmp_command >>= 5;
1419 irmp_command |= 0x80;
1420 rtc = TRUE;
1421 }
1422 else
1423 {
1424 ANALYZE_PRINTF("error NETBOX: bit6/7 must be 0/1\n");
1425 }
1426 }
1427 else
1428 {
1429 ANALYZE_PRINTF("error NETBOX: last bit not set\n");
1430 }
1431 break;
1432 #endif
1433 #if IRMP_SUPPORT_LEGO_PROTOCOL == 1
1434 case IRMP_LEGO_PROTOCOL:
1435 {
1436 uint8_t crc = 0x0F ^ ((irmp_command & 0xF000) >> 12) ^ ((irmp_command & 0x0F00) >> 8) ^ ((irmp_command & 0x00F0) >> 4);
1437
1438 if ((irmp_command & 0x000F) == crc)
1439 {
1440 irmp_command >>= 4;
1441 rtc = TRUE;
1442 }
1443 else
1444 {
1445 ANALYZE_PRINTF ("CRC error in LEGO protocol\n");
1446 // rtc = TRUE; // don't accept codes with CRC errors
1447 }
1448 break;
1449 }
1450 #endif
1451 default:
1452 {
1453 rtc = TRUE;
1454 break;
1455 }
1456 }
1457
1458 if (rtc)
1459 {
1460 irmp_data_p->protocol = irmp_protocol;
1461 irmp_data_p->address = irmp_address;
1462 irmp_data_p->command = irmp_command;
1463 irmp_data_p->flags = irmp_flags;
1464 irmp_command = 0;
1465 irmp_address = 0;
1466 irmp_flags = 0;
1467 }
1468
1469 irmp_ir_detected = FALSE;
1470 }
1471
1472 return rtc;
1473 }
1474
1475 // uint8_t
1476 // irmp_is_busy (void)
1477 // {
1478 // return irmp_busy_flag;
1479 // }
1480
1481 #if IRMP_USE_CALLBACK == 1
1482 void
1483 irmp_set_callback_ptr (void (*cb)(uint8_t))
1484 {
1485 irmp_callback_ptr = cb;
1486 }
1487 #endif // IRMP_USE_CALLBACK == 1
1488
1489 // these statics must not be volatile, because they are only used by irmp_store_bit(), which is called by irmp_ISR()
1490 static uint16_t irmp_tmp_address; // ir address
1491 static uint16_t irmp_tmp_command; // ir command
1492
1493 #if IRMP_SUPPORT_RC5_PROTOCOL == 1 && (IRMP_SUPPORT_FDC_PROTOCOL == 1 || IRMP_SUPPORT_RCCAR_PROTOCOL == 1) || IRMP_SUPPORT_NEC42_PROTOCOL == 1
1494 static uint16_t irmp_tmp_address2; // ir address
1495 static uint16_t irmp_tmp_command2; // ir command
1496 #endif
1497
1498 #if IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1
1499 static uint16_t irmp_tmp_id; // ir id (only SAMSUNG)
1500 #endif
1501 #if IRMP_SUPPORT_KASEIKYO_PROTOCOL == 1
1502 static uint8_t xor_check[6]; // check kaseikyo "parity" bits
1503 static uint8_t genre2; // save genre2 bits here, later copied to MSB in flags
1504 #endif
1505
1506 /*---------------------------------------------------------------------------------------------------------------------------------------------------
1507 * store bit
1508 * @details store bit in temp address or temp command
1509 * @param value to store: 0 or 1
1510 *---------------------------------------------------------------------------------------------------------------------------------------------------
1511 */
1512 // verhindert, dass irmp_store_bit() inline compiliert wird:
1513 // static void irmp_store_bit (uint8_t) __attribute__ ((noinline));
1514
1515 static void
1516 irmp_store_bit (uint8_t value)
1517 {
1518 #if IRMP_SUPPORT_GRUNDIG_NOKIA_IR60_PROTOCOL == 1
1519 if (irmp_bit == 0 && irmp_param.protocol == IRMP_GRUNDIG_PROTOCOL)
1520 {
1521 first_bit = value;
1522 }
1523 else
1524 #endif
1525
1526 if (irmp_bit >= irmp_param.address_offset && irmp_bit < irmp_param.address_end)
1527 {
1528 if (irmp_param.lsb_first)
1529 {
1530 irmp_tmp_address |= (((uint16_t) (value)) << (irmp_bit - irmp_param.address_offset)); // CV wants cast
1531 }
1532 else
1533 {
1534 irmp_tmp_address <<= 1;
1535 irmp_tmp_address |= value;
1536 }
1537 }
1538 else if (irmp_bit >= irmp_param.command_offset && irmp_bit < irmp_param.command_end)
1539 {
1540 if (irmp_param.lsb_first)
1541 {
1542 irmp_tmp_command |= (((uint16_t) (value)) << (irmp_bit - irmp_param.command_offset)); // CV wants cast
1543 }
1544 else
1545 {
1546 irmp_tmp_command <<= 1;
1547 irmp_tmp_command |= value;
1548 }
1549 }
1550
1551 #if IRMP_SUPPORT_NEC42_PROTOCOL == 1
1552 if (irmp_param.protocol == IRMP_NEC42_PROTOCOL && irmp_bit >= 13 && irmp_bit < 26)
1553 {
1554 irmp_tmp_address2 |= (((uint16_t) (value)) << (irmp_bit - 13)); // CV wants cast
1555 }
1556 else
1557 #endif
1558
1559 #if IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1
1560 if (irmp_param.protocol == IRMP_SAMSUNG_PROTOCOL && irmp_bit >= SAMSUNG_ID_OFFSET && irmp_bit < SAMSUNG_ID_OFFSET + SAMSUNG_ID_LEN)
1561 {
1562 irmp_tmp_id |= (((uint16_t) (value)) << (irmp_bit - SAMSUNG_ID_OFFSET)); // store with LSB first
1563 }
1564 else
1565 #endif
1566
1567 #if IRMP_SUPPORT_KASEIKYO_PROTOCOL == 1
1568 if (irmp_param.protocol == IRMP_KASEIKYO_PROTOCOL)
1569 {
1570 if (irmp_bit >= 20 && irmp_bit < 24)
1571 {
1572 irmp_tmp_command |= (((uint16_t) (value)) << (irmp_bit - 8)); // store 4 system bits (genre 1) in upper nibble with LSB first
1573 }
1574 else if (irmp_bit >= 24 && irmp_bit < 28)
1575 {
1576 genre2 |= (((uint8_t) (value)) << (irmp_bit - 20)); // store 4 system bits (genre 2) in upper nibble with LSB first
1577 }
1578
1579 if (irmp_bit < KASEIKYO_COMPLETE_DATA_LEN)
1580 {
1581 if (value)
1582 {
1583 xor_check[irmp_bit / 8] |= 1 << (irmp_bit % 8);
1584 }
1585 else
1586 {
1587 xor_check[irmp_bit / 8] &= ~(1 << (irmp_bit % 8));
1588 }
1589 }
1590 }
1591 else
1592 #endif
1593 {
1594 ;
1595 }
1596
1597 irmp_bit++;
1598 }
1599
1600 /*---------------------------------------------------------------------------------------------------------------------------------------------------
1601 * store bit
1602 * @details store bit in temp address or temp command
1603 * @param value to store: 0 or 1
1604 *---------------------------------------------------------------------------------------------------------------------------------------------------
1605 */
1606 #if IRMP_SUPPORT_RC5_PROTOCOL == 1 && (IRMP_SUPPORT_FDC_PROTOCOL == 1 || IRMP_SUPPORT_RCCAR_PROTOCOL == 1)
1607 static void
1608 irmp_store_bit2 (uint8_t value)
1609 {
1610 uint8_t irmp_bit2;
1611
1612 if (irmp_param.protocol)
1613 {
1614 irmp_bit2 = irmp_bit - 2;
1615 }
1616 else
1617 {
1618 irmp_bit2 = irmp_bit - 1;
1619 }
1620
1621 if (irmp_bit2 >= irmp_param2.address_offset && irmp_bit2 < irmp_param2.address_end)
1622 {
1623 irmp_tmp_address2 |= (((uint16_t) (value)) << (irmp_bit2 - irmp_param2.address_offset)); // CV wants cast
1624 }
1625 else if (irmp_bit2 >= irmp_param2.command_offset && irmp_bit2 < irmp_param2.command_end)
1626 {
1627 irmp_tmp_command2 |= (((uint16_t) (value)) << (irmp_bit2 - irmp_param2.command_offset)); // CV wants cast
1628 }
1629 }
1630 #endif // IRMP_SUPPORT_RC5_PROTOCOL == 1 && (IRMP_SUPPORT_FDC_PROTOCOL == 1 || IRMP_SUPPORT_RCCAR_PROTOCOL == 1)
1631
1632 /*---------------------------------------------------------------------------------------------------------------------------------------------------
1633 * ISR routine
1634 * @details ISR routine, called 10000 times per second
1635 *---------------------------------------------------------------------------------------------------------------------------------------------------
1636 */
1637 uint8_t
1638 irmp_ISR (void)
1639 {
1640 static uint8_t irmp_start_bit_detected; // flag: start bit detected
1641 static uint8_t wait_for_space; // flag: wait for data bit space
1642 static uint8_t wait_for_start_space; // flag: wait for start bit space
1643 static uint8_t irmp_pulse_time; // count bit time for pulse
1644 static PAUSE_LEN irmp_pause_time; // count bit time for pause
1645 static uint16_t last_irmp_address = 0xFFFF; // save last irmp address to recognize key repetition
1646 static uint16_t last_irmp_command = 0xFFFF; // save last irmp command to recognize key repetition
1647 static uint16_t repetition_len; // SIRCS repeats frame 2-5 times with 45 ms pause
1648 static uint8_t repetition_frame_number;
1649 #if IRMP_SUPPORT_DENON_PROTOCOL == 1
1650 static uint16_t last_irmp_denon_command; // save last irmp command to recognize DENON frame repetition
1651 #endif
1652 #if IRMP_SUPPORT_RC5_PROTOCOL == 1
1653 static uint8_t rc5_cmd_bit6; // bit 6 of RC5 command is the inverted 2nd start bit
1654 #endif
1655 #if IRMP_SUPPORT_MANCHESTER == 1
1656 static PAUSE_LEN last_pause; // last pause value
1657 #endif
1658 #if IRMP_SUPPORT_MANCHESTER == 1 || IRMP_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1
1659 static uint8_t last_value; // last bit value
1660 #endif
1661 uint8_t irmp_input; // input value
1662
1663 #ifdef ANALYZE
1664 time_counter++;
1665 #endif
1666
1667 irmp_input = input(IRMP_PIN);
1668
1669 #if IRMP_USE_CALLBACK == 1
1670 if (irmp_callback_ptr)
1671 {
1672 static uint8_t last_inverted_input;
1673
1674 if (last_inverted_input != !irmp_input)
1675 {
1676 (*irmp_callback_ptr) (! irmp_input);
1677 last_inverted_input = !irmp_input;
1678 }
1679 }
1680 #endif // IRMP_USE_CALLBACK == 1
1681
1682 irmp_log(irmp_input); // log ir signal, if IRMP_LOGGING defined
1683
1684 if (! irmp_ir_detected) // ir code already detected?
1685 { // no...
1686 if (! irmp_start_bit_detected) // start bit detected?
1687 { // no...
1688 if (! irmp_input) // receiving burst?
1689 { // yes...
1690 // irmp_busy_flag = TRUE;
1691 #ifdef ANALYZE
1692 if (! irmp_pulse_time)
1693 {
1694 ANALYZE_PRINTF("%8.3fms [starting pulse]\n", (double) (time_counter * 1000) / F_INTERRUPTS);
1695 }
1696 #endif
1697 irmp_pulse_time++; // increment counter
1698 }
1699 else
1700 { // no...
1701 if (irmp_pulse_time) // it's dark....
1702 { // set flags for counting the time of darkness...
1703 irmp_start_bit_detected = 1;
1704 wait_for_start_space = 1;
1705 wait_for_space = 0;
1706 irmp_tmp_command = 0;
1707 irmp_tmp_address = 0;
1708 #if IRMP_SUPPORT_KASEIKYO_PROTOCOL == 1
1709 genre2 = 0;
1710 #endif
1711
1712 #if IRMP_SUPPORT_RC5_PROTOCOL == 1 && (IRMP_SUPPORT_FDC_PROTOCOL == 1 || IRMP_SUPPORT_RCCAR_PROTOCOL == 1) || IRMP_SUPPORT_NEC42_PROTOCOL == 1
1713 irmp_tmp_command2 = 0;
1714 irmp_tmp_address2 = 0;
1715 #endif
1716
1717 irmp_bit = 0xff;
1718 irmp_pause_time = 1; // 1st pause: set to 1, not to 0!
1719 #if IRMP_SUPPORT_RC5_PROTOCOL == 1
1720 rc5_cmd_bit6 = 0; // fm 2010-03-07: bugfix: reset it after incomplete RC5 frame!
1721 #endif
1722 }
1723 else
1724 {
1725 if (repetition_len < 0xFFFF) // avoid overflow of counter
1726 {
1727 repetition_len++;
1728
1729 #if IRMP_SUPPORT_DENON_PROTOCOL == 1
1730 if (repetition_len >= DENON_AUTO_REPETITION_PAUSE_LEN && last_irmp_denon_command != 0)
1731 {
1732 ANALYZE_PRINTF ("%8.3fms error 6: did not receive inverted command repetition\n",
1733 (double) (time_counter * 1000) / F_INTERRUPTS);
1734 last_irmp_denon_command = 0;
1735 }
1736 #endif // IRMP_SUPPORT_DENON_PROTOCOL == 1
1737 }
1738 }
1739 }
1740 }
1741 else
1742 {
1743 if (wait_for_start_space) // we have received start bit...
1744 { // ...and are counting the time of darkness
1745 if (irmp_input) // still dark?
1746 { // yes
1747 irmp_pause_time++; // increment counter
1748
1749 #if IRMP_SUPPORT_NIKON_PROTOCOL == 1
1750 if (((irmp_pulse_time < NIKON_START_BIT_PULSE_LEN_MIN || irmp_pulse_time > NIKON_START_BIT_PULSE_LEN_MAX) && irmp_pause_time > IRMP_TIMEOUT_LEN) ||
1751 irmp_pause_time > IRMP_TIMEOUT_NIKON_LEN)
1752 #else
1753 if (irmp_pause_time > IRMP_TIMEOUT_LEN) // timeout?
1754 #endif
1755 { // yes...
1756 #if IRMP_SUPPORT_JVC_PROTOCOL == 1
1757 if (irmp_protocol == IRMP_JVC_PROTOCOL) // don't show eror if JVC protocol, irmp_pulse_time has been set below!
1758 {
1759 ;
1760 }
1761 else
1762 #endif // IRMP_SUPPORT_JVC_PROTOCOL == 1
1763 {
1764 ANALYZE_PRINTF ("%8.3fms error 1: pause after start bit pulse %d too long: %d\n", (double) (time_counter * 1000) / F_INTERRUPTS, irmp_pulse_time, irmp_pause_time);
1765 ANALYZE_ONLY_NORMAL_PUTCHAR ('\n');
1766 }
1767 // irmp_busy_flag = FALSE;
1768 irmp_start_bit_detected = 0; // reset flags, let's wait for another start bit
1769 irmp_pulse_time = 0;
1770 irmp_pause_time = 0;
1771 }
1772 }
1773 else
1774 { // receiving first data pulse!
1775 IRMP_PARAMETER * irmp_param_p = (IRMP_PARAMETER *) 0;
1776
1777 #if IRMP_SUPPORT_RC5_PROTOCOL == 1 && (IRMP_SUPPORT_FDC_PROTOCOL == 1 || IRMP_SUPPORT_RCCAR_PROTOCOL == 1)
1778 irmp_param2.protocol = 0;
1779 #endif
1780
1781 ANALYZE_PRINTF ("%8.3fms [start-bit: pulse = %2d, pause = %2d]\n", (double) (time_counter * 1000) / F_INTERRUPTS, irmp_pulse_time, irmp_pause_time);
1782
1783 #if IRMP_SUPPORT_SIRCS_PROTOCOL == 1
1784 if (irmp_pulse_time >= SIRCS_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= SIRCS_START_BIT_PULSE_LEN_MAX &&
1785 irmp_pause_time >= SIRCS_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= SIRCS_START_BIT_PAUSE_LEN_MAX)
1786 { // it's SIRCS
1787 ANALYZE_PRINTF ("protocol = SIRCS, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1788 SIRCS_START_BIT_PULSE_LEN_MIN, SIRCS_START_BIT_PULSE_LEN_MAX,
1789 SIRCS_START_BIT_PAUSE_LEN_MIN, SIRCS_START_BIT_PAUSE_LEN_MAX);
1790 irmp_param_p = (IRMP_PARAMETER *) (IRMP_PARAMETER *) &sircs_param;
1791 }
1792 else
1793 #endif // IRMP_SUPPORT_SIRCS_PROTOCOL == 1
1794
1795 #if IRMP_SUPPORT_JVC_PROTOCOL == 1
1796 if (irmp_protocol == IRMP_JVC_PROTOCOL && // last protocol was JVC, awaiting repeat frame
1797 irmp_pulse_time >= JVC_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= JVC_START_BIT_PULSE_LEN_MAX &&
1798 irmp_pause_time >= JVC_REPEAT_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= JVC_REPEAT_START_BIT_PAUSE_LEN_MAX)
1799 {
1800 ANALYZE_PRINTF ("protocol = NEC or JVC (type 1) repeat frame, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1801 JVC_START_BIT_PULSE_LEN_MIN, JVC_START_BIT_PULSE_LEN_MAX,
1802 JVC_REPEAT_START_BIT_PAUSE_LEN_MIN, JVC_REPEAT_START_BIT_PAUSE_LEN_MAX);
1803 irmp_param_p = (IRMP_PARAMETER *) &nec_param;
1804 }
1805 else
1806 #endif // IRMP_SUPPORT_JVC_PROTOCOL == 1
1807
1808 #if IRMP_SUPPORT_NEC_PROTOCOL == 1
1809 if (irmp_pulse_time >= NEC_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= NEC_START_BIT_PULSE_LEN_MAX &&
1810 irmp_pause_time >= NEC_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= NEC_START_BIT_PAUSE_LEN_MAX)
1811 {
1812 #if IRMP_SUPPORT_NEC42_PROTOCOL == 1
1813 ANALYZE_PRINTF ("protocol = NEC42, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1814 NEC_START_BIT_PULSE_LEN_MIN, NEC_START_BIT_PULSE_LEN_MAX,
1815 NEC_START_BIT_PAUSE_LEN_MIN, NEC_START_BIT_PAUSE_LEN_MAX);
1816 irmp_param_p = (IRMP_PARAMETER *) &nec42_param;
1817 #else
1818 ANALYZE_PRINTF ("protocol = NEC, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1819 NEC_START_BIT_PULSE_LEN_MIN, NEC_START_BIT_PULSE_LEN_MAX,
1820 NEC_START_BIT_PAUSE_LEN_MIN, NEC_START_BIT_PAUSE_LEN_MAX);
1821 irmp_param_p = (IRMP_PARAMETER *) &nec_param;
1822 #endif
1823
1824 }
1825 else if (irmp_pulse_time >= NEC_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= NEC_START_BIT_PULSE_LEN_MAX &&
1826 irmp_pause_time >= NEC_REPEAT_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= NEC_REPEAT_START_BIT_PAUSE_LEN_MAX)
1827 { // it's NEC
1828 #if IRMP_SUPPORT_JVC_PROTOCOL == 1
1829 if (irmp_protocol == IRMP_JVC_PROTOCOL) // last protocol was JVC, awaiting repeat frame
1830 { // some jvc remote controls use nec repetition frame for jvc repetition frame
1831 ANALYZE_PRINTF ("protocol = JVC repeat frame type 2, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1832 NEC_START_BIT_PULSE_LEN_MIN, NEC_START_BIT_PULSE_LEN_MAX,
1833 NEC_REPEAT_START_BIT_PAUSE_LEN_MIN, NEC_REPEAT_START_BIT_PAUSE_LEN_MAX);
1834 irmp_param_p = (IRMP_PARAMETER *) &nec_param;
1835 }
1836 else
1837 #endif // IRMP_SUPPORT_JVC_PROTOCOL == 1
1838 {
1839 ANALYZE_PRINTF ("protocol = NEC (repetition frame), start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1840 NEC_START_BIT_PULSE_LEN_MIN, NEC_START_BIT_PULSE_LEN_MAX,
1841 NEC_REPEAT_START_BIT_PAUSE_LEN_MIN, NEC_REPEAT_START_BIT_PAUSE_LEN_MAX);
1842
1843 irmp_param_p = (IRMP_PARAMETER *) &nec_rep_param;
1844 }
1845 }
1846 else
1847
1848 #if IRMP_SUPPORT_JVC_PROTOCOL == 1
1849 if (irmp_protocol == IRMP_JVC_PROTOCOL && // last protocol was JVC, awaiting repeat frame
1850 irmp_pulse_time >= NEC_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= NEC_START_BIT_PULSE_LEN_MAX &&
1851 irmp_pause_time >= NEC_0_PAUSE_LEN_MIN && irmp_pause_time <= NEC_0_PAUSE_LEN_MAX)
1852 { // it's JVC repetition type 3
1853 ANALYZE_PRINTF ("protocol = JVC repeat frame type 3, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1854 NEC_START_BIT_PULSE_LEN_MIN, NEC_START_BIT_PULSE_LEN_MAX,
1855 NEC_0_PAUSE_LEN_MIN, NEC_0_PAUSE_LEN_MAX);
1856 irmp_param_p = (IRMP_PARAMETER *) &nec_param;
1857 }
1858 else
1859 #endif // IRMP_SUPPORT_JVC_PROTOCOL == 1
1860
1861 #endif // IRMP_SUPPORT_NEC_PROTOCOL == 1
1862
1863 #if IRMP_SUPPORT_NIKON_PROTOCOL == 1
1864 if (irmp_pulse_time >= NIKON_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= NIKON_START_BIT_PULSE_LEN_MAX &&
1865 irmp_pause_time >= NIKON_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= NIKON_START_BIT_PAUSE_LEN_MAX)
1866 {
1867 ANALYZE_PRINTF ("protocol = NIKON, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1868 NIKON_START_BIT_PULSE_LEN_MIN, NIKON_START_BIT_PULSE_LEN_MAX,
1869 NIKON_START_BIT_PAUSE_LEN_MIN, NIKON_START_BIT_PAUSE_LEN_MAX);
1870 irmp_param_p = (IRMP_PARAMETER *) &nikon_param;
1871 }
1872 else
1873 #endif // IRMP_SUPPORT_NIKON_PROTOCOL == 1
1874
1875 #if IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1
1876 if (irmp_pulse_time >= SAMSUNG_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= SAMSUNG_START_BIT_PULSE_LEN_MAX &&
1877 irmp_pause_time >= SAMSUNG_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= SAMSUNG_START_BIT_PAUSE_LEN_MAX)
1878 { // it's SAMSUNG
1879 ANALYZE_PRINTF ("protocol = SAMSUNG, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1880 SAMSUNG_START_BIT_PULSE_LEN_MIN, SAMSUNG_START_BIT_PULSE_LEN_MAX,
1881 SAMSUNG_START_BIT_PAUSE_LEN_MIN, SAMSUNG_START_BIT_PAUSE_LEN_MAX);
1882 irmp_param_p = (IRMP_PARAMETER *) &samsung_param;
1883 }
1884 else
1885 #endif // IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1
1886
1887 #if IRMP_SUPPORT_MATSUSHITA_PROTOCOL == 1
1888 if (irmp_pulse_time >= MATSUSHITA_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= MATSUSHITA_START_BIT_PULSE_LEN_MAX &&
1889 irmp_pause_time >= MATSUSHITA_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= MATSUSHITA_START_BIT_PAUSE_LEN_MAX)
1890 { // it's MATSUSHITA
1891 ANALYZE_PRINTF ("protocol = MATSUSHITA, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1892 MATSUSHITA_START_BIT_PULSE_LEN_MIN, MATSUSHITA_START_BIT_PULSE_LEN_MAX,
1893 MATSUSHITA_START_BIT_PAUSE_LEN_MIN, MATSUSHITA_START_BIT_PAUSE_LEN_MAX);
1894 irmp_param_p = (IRMP_PARAMETER *) &matsushita_param;
1895 }
1896 else
1897 #endif // IRMP_SUPPORT_MATSUSHITA_PROTOCOL == 1
1898
1899 #if IRMP_SUPPORT_KASEIKYO_PROTOCOL == 1
1900 if (irmp_pulse_time >= KASEIKYO_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= KASEIKYO_START_BIT_PULSE_LEN_MAX &&
1901 irmp_pause_time >= KASEIKYO_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= KASEIKYO_START_BIT_PAUSE_LEN_MAX)
1902 { // it's KASEIKYO
1903 ANALYZE_PRINTF ("protocol = KASEIKYO, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1904 KASEIKYO_START_BIT_PULSE_LEN_MIN, KASEIKYO_START_BIT_PULSE_LEN_MAX,
1905 KASEIKYO_START_BIT_PAUSE_LEN_MIN, KASEIKYO_START_BIT_PAUSE_LEN_MAX);
1906 irmp_param_p = (IRMP_PARAMETER *) &kaseikyo_param;
1907 }
1908 else
1909 #endif // IRMP_SUPPORT_KASEIKYO_PROTOCOL == 1
1910
1911 #if IRMP_SUPPORT_RECS80_PROTOCOL == 1
1912 if (irmp_pulse_time >= RECS80_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= RECS80_START_BIT_PULSE_LEN_MAX &&
1913 irmp_pause_time >= RECS80_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= RECS80_START_BIT_PAUSE_LEN_MAX)
1914 { // it's RECS80
1915 ANALYZE_PRINTF ("protocol = RECS80, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1916 RECS80_START_BIT_PULSE_LEN_MIN, RECS80_START_BIT_PULSE_LEN_MAX,
1917 RECS80_START_BIT_PAUSE_LEN_MIN, RECS80_START_BIT_PAUSE_LEN_MAX);
1918 irmp_param_p = (IRMP_PARAMETER *) &recs80_param;
1919 }
1920 else
1921 #endif // IRMP_SUPPORT_RECS80_PROTOCOL == 1
1922
1923 #if IRMP_SUPPORT_RC5_PROTOCOL == 1
1924 if (((irmp_pulse_time >= RC5_START_BIT_LEN_MIN && irmp_pulse_time <= RC5_START_BIT_LEN_MAX) ||
1925 (irmp_pulse_time >= 2 * RC5_START_BIT_LEN_MIN && irmp_pulse_time <= 2 * RC5_START_BIT_LEN_MAX)) &&
1926 ((irmp_pause_time >= RC5_START_BIT_LEN_MIN && irmp_pause_time <= RC5_START_BIT_LEN_MAX) ||
1927 (irmp_pause_time >= 2 * RC5_START_BIT_LEN_MIN && irmp_pause_time <= 2 * RC5_START_BIT_LEN_MAX)))
1928 { // it's RC5
1929 #if IRMP_SUPPORT_FDC_PROTOCOL == 1
1930 if (irmp_pulse_time >= FDC_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= FDC_START_BIT_PULSE_LEN_MAX &&
1931 irmp_pause_time >= FDC_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= FDC_START_BIT_PAUSE_LEN_MAX)
1932 {
1933 ANALYZE_PRINTF ("protocol = RC5 or FDC\n");
1934 ANALYZE_PRINTF ("FDC start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1935 FDC_START_BIT_PULSE_LEN_MIN, FDC_START_BIT_PULSE_LEN_MAX,
1936 FDC_START_BIT_PAUSE_LEN_MIN, FDC_START_BIT_PAUSE_LEN_MAX);
1937 ANALYZE_PRINTF ("RC5 start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1938 RC5_START_BIT_LEN_MIN, RC5_START_BIT_LEN_MAX,
1939 RC5_START_BIT_LEN_MIN, RC5_START_BIT_LEN_MAX);
1940 memcpy_P (&irmp_param2, &fdc_param, sizeof (IRMP_PARAMETER));
1941 }
1942 else
1943 #endif // IRMP_SUPPORT_FDC_PROTOCOL == 1
1944
1945 #if IRMP_SUPPORT_RCCAR_PROTOCOL == 1
1946 if (irmp_pulse_time >= RCCAR_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= RCCAR_START_BIT_PULSE_LEN_MAX &&
1947 irmp_pause_time >= RCCAR_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= RCCAR_START_BIT_PAUSE_LEN_MAX)
1948 {
1949 ANALYZE_PRINTF ("protocol = RC5 or RCCAR\n");
1950 ANALYZE_PRINTF ("RCCAR start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1951 RCCAR_START_BIT_PULSE_LEN_MIN, RCCAR_START_BIT_PULSE_LEN_MAX,
1952 RCCAR_START_BIT_PAUSE_LEN_MIN, RCCAR_START_BIT_PAUSE_LEN_MAX);
1953 ANALYZE_PRINTF ("RC5 start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1954 RC5_START_BIT_LEN_MIN, RC5_START_BIT_LEN_MAX,
1955 RC5_START_BIT_LEN_MIN, RC5_START_BIT_LEN_MAX);
1956 memcpy_P (&irmp_param2, &rccar_param, sizeof (IRMP_PARAMETER));
1957 }
1958 else
1959 #endif // IRMP_SUPPORT_RCCAR_PROTOCOL == 1
1960 {
1961 ANALYZE_PRINTF ("protocol = RC5, start bit timings: pulse: %3d - %3d, pause: %3d - %3d or pulse: %3d - %3d, pause: %3d - %3d\n",
1962 RC5_START_BIT_LEN_MIN, RC5_START_BIT_LEN_MAX,
1963 2 * RC5_START_BIT_LEN_MIN, 2 * RC5_START_BIT_LEN_MAX,
1964 RC5_START_BIT_LEN_MIN, RC5_START_BIT_LEN_MAX,
1965 2 * RC5_START_BIT_LEN_MIN, 2 * RC5_START_BIT_LEN_MAX);
1966 }
1967
1968 irmp_param_p = (IRMP_PARAMETER *) &rc5_param;
1969 last_pause = irmp_pause_time;
1970
1971 if ((irmp_pulse_time > RC5_START_BIT_LEN_MAX && irmp_pulse_time <= 2 * RC5_START_BIT_LEN_MAX) ||
1972 (irmp_pause_time > RC5_START_BIT_LEN_MAX && irmp_pause_time <= 2 * RC5_START_BIT_LEN_MAX))
1973 {
1974 last_value = 0;
1975 rc5_cmd_bit6 = 1<<6;
1976 }
1977 else
1978 {
1979 last_value = 1;
1980 }
1981 }
1982 else
1983 #endif // IRMP_SUPPORT_RC5_PROTOCOL == 1
1984
1985 #if IRMP_SUPPORT_DENON_PROTOCOL == 1
1986 if ( (irmp_pulse_time >= DENON_PULSE_LEN_MIN && irmp_pulse_time <= DENON_PULSE_LEN_MAX) &&
1987 ((irmp_pause_time >= DENON_1_PAUSE_LEN_MIN && irmp_pause_time <= DENON_1_PAUSE_LEN_MAX) ||
1988 (irmp_pause_time >= DENON_0_PAUSE_LEN_MIN && irmp_pause_time <= DENON_0_PAUSE_LEN_MAX)))
1989 { // it's DENON
1990 ANALYZE_PRINTF ("protocol = DENON, start bit timings: pulse: %3d - %3d, pause: %3d - %3d or %3d - %3d\n",
1991 DENON_PULSE_LEN_MIN, DENON_PULSE_LEN_MAX,
1992 DENON_1_PAUSE_LEN_MIN, DENON_1_PAUSE_LEN_MAX,
1993 DENON_0_PAUSE_LEN_MIN, DENON_0_PAUSE_LEN_MAX);
1994 irmp_param_p = (IRMP_PARAMETER *) &denon_param;
1995 }
1996 else
1997 #endif // IRMP_SUPPORT_DENON_PROTOCOL == 1
1998
1999 #if IRMP_SUPPORT_THOMSON_PROTOCOL == 1
2000 if ( (irmp_pulse_time >= THOMSON_PULSE_LEN_MIN && irmp_pulse_time <= THOMSON_PULSE_LEN_MAX) &&
2001 ((irmp_pause_time >= THOMSON_1_PAUSE_LEN_MIN && irmp_pause_time <= THOMSON_1_PAUSE_LEN_MAX) ||
2002 (irmp_pause_time >= THOMSON_0_PAUSE_LEN_MIN && irmp_pause_time <= THOMSON_0_PAUSE_LEN_MAX)))
2003 { // it's THOMSON
2004 ANALYZE_PRINTF ("protocol = THOMSON, start bit timings: pulse: %3d - %3d, pause: %3d - %3d or %3d - %3d\n",
2005 THOMSON_PULSE_LEN_MIN, THOMSON_PULSE_LEN_MAX,
2006 THOMSON_1_PAUSE_LEN_MIN, THOMSON_1_PAUSE_LEN_MAX,
2007 THOMSON_0_PAUSE_LEN_MIN, THOMSON_0_PAUSE_LEN_MAX);
2008 irmp_param_p = (IRMP_PARAMETER *) &thomson_param;
2009 }
2010 else
2011 #endif // IRMP_SUPPORT_THOMSON_PROTOCOL == 1
2012
2013 #if IRMP_SUPPORT_BOSE_PROTOCOL == 1
2014 if (irmp_pulse_time >= BOSE_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= BOSE_START_BIT_PULSE_LEN_MAX &&
2015 irmp_pause_time >= BOSE_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= BOSE_START_BIT_PAUSE_LEN_MAX)
2016 {
2017 ANALYZE_PRINTF ("protocol = BOSE, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
2018 BOSE_START_BIT_PULSE_LEN_MIN, BOSE_START_BIT_PULSE_LEN_MAX,
2019 BOSE_START_BIT_PAUSE_LEN_MIN, BOSE_START_BIT_PAUSE_LEN_MAX);
2020 irmp_param_p = (IRMP_PARAMETER *) &bose_param;
2021 }
2022 else
2023 #endif // IRMP_SUPPORT_BOSE_PROTOCOL == 1
2024
2025 #if IRMP_SUPPORT_RC6_PROTOCOL == 1
2026 if (irmp_pulse_time >= RC6_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= RC6_START_BIT_PULSE_LEN_MAX &&
2027 irmp_pause_time >= RC6_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= RC6_START_BIT_PAUSE_LEN_MAX)
2028 { // it's RC6
2029 ANALYZE_PRINTF ("protocol = RC6, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
2030 RC6_START_BIT_PULSE_LEN_MIN, RC6_START_BIT_PULSE_LEN_MAX,
2031 RC6_START_BIT_PAUSE_LEN_MIN, RC6_START_BIT_PAUSE_LEN_MAX);
2032 irmp_param_p = (IRMP_PARAMETER *) &rc6_param;
2033 last_pause = 0;
2034 last_value = 1;
2035 }
2036 else
2037 #endif // IRMP_SUPPORT_RC6_PROTOCOL == 1
2038
2039 #if IRMP_SUPPORT_RECS80EXT_PROTOCOL == 1
2040 if (irmp_pulse_time >= RECS80EXT_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= RECS80EXT_START_BIT_PULSE_LEN_MAX &&
2041 irmp_pause_time >= RECS80EXT_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= RECS80EXT_START_BIT_PAUSE_LEN_MAX)
2042 { // it's RECS80EXT
2043 ANALYZE_PRINTF ("protocol = RECS80EXT, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
2044 RECS80EXT_START_BIT_PULSE_LEN_MIN, RECS80EXT_START_BIT_PULSE_LEN_MAX,
2045 RECS80EXT_START_BIT_PAUSE_LEN_MIN, RECS80EXT_START_BIT_PAUSE_LEN_MAX);
2046 irmp_param_p = (IRMP_PARAMETER *) &recs80ext_param;
2047 }
2048 else
2049 #endif // IRMP_SUPPORT_RECS80EXT_PROTOCOL == 1
2050
2051 #if IRMP_SUPPORT_NUBERT_PROTOCOL == 1
2052 if (irmp_pulse_time >= NUBERT_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= NUBERT_START_BIT_PULSE_LEN_MAX &&
2053 irmp_pause_time >= NUBERT_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= NUBERT_START_BIT_PAUSE_LEN_MAX)
2054 { // it's NUBERT
2055 ANALYZE_PRINTF ("protocol = NUBERT, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
2056 NUBERT_START_BIT_PULSE_LEN_MIN, NUBERT_START_BIT_PULSE_LEN_MAX,
2057 NUBERT_START_BIT_PAUSE_LEN_MIN, NUBERT_START_BIT_PAUSE_LEN_MAX);
2058 irmp_param_p = (IRMP_PARAMETER *) &nubert_param;
2059 }
2060 else
2061 #endif // IRMP_SUPPORT_NUBERT_PROTOCOL == 1
2062
2063 #if IRMP_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1
2064 if (irmp_pulse_time >= BANG_OLUFSEN_START_BIT1_PULSE_LEN_MIN && irmp_pulse_time <= BANG_OLUFSEN_START_BIT1_PULSE_LEN_MAX &&
2065 irmp_pause_time >= BANG_OLUFSEN_START_BIT1_PAUSE_LEN_MIN && irmp_pause_time <= BANG_OLUFSEN_START_BIT1_PAUSE_LEN_MAX)
2066 { // it's BANG_OLUFSEN
2067 ANALYZE_PRINTF ("protocol = BANG_OLUFSEN\n");
2068 ANALYZE_PRINTF ("start bit 1 timings: pulse: %3d - %3d, pause: %3d - %3d\n",
2069 BANG_OLUFSEN_START_BIT1_PULSE_LEN_MIN, BANG_OLUFSEN_START_BIT1_PULSE_LEN_MAX,
2070 BANG_OLUFSEN_START_BIT1_PAUSE_LEN_MIN, BANG_OLUFSEN_START_BIT1_PAUSE_LEN_MAX);
2071 ANALYZE_PRINTF ("start bit 2 timings: pulse: %3d - %3d, pause: %3d - %3d\n",
2072 BANG_OLUFSEN_START_BIT2_PULSE_LEN_MIN, BANG_OLUFSEN_START_BIT2_PULSE_LEN_MAX,
2073 BANG_OLUFSEN_START_BIT2_PAUSE_LEN_MIN, BANG_OLUFSEN_START_BIT2_PAUSE_LEN_MAX);
2074 ANALYZE_PRINTF ("start bit 3 timings: pulse: %3d - %3d, pause: %3d - %3d\n",
2075 BANG_OLUFSEN_START_BIT3_PULSE_LEN_MIN, BANG_OLUFSEN_START_BIT3_PULSE_LEN_MAX,
2076 BANG_OLUFSEN_START_BIT3_PAUSE_LEN_MIN, BANG_OLUFSEN_START_BIT3_PAUSE_LEN_MAX);
2077 ANALYZE_PRINTF ("start bit 4 timings: pulse: %3d - %3d, pause: %3d - %3d\n",
2078 BANG_OLUFSEN_START_BIT4_PULSE_LEN_MIN, BANG_OLUFSEN_START_BIT4_PULSE_LEN_MAX,
2079 BANG_OLUFSEN_START_BIT4_PAUSE_LEN_MIN, BANG_OLUFSEN_START_BIT4_PAUSE_LEN_MAX);
2080 irmp_param_p = (IRMP_PARAMETER *) &bang_olufsen_param;
2081 last_value = 0;
2082 }
2083 else
2084 #endif // IRMP_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1
2085
2086 #if IRMP_SUPPORT_GRUNDIG_NOKIA_IR60_PROTOCOL == 1
2087 if (irmp_pulse_time >= GRUNDIG_NOKIA_IR60_START_BIT_LEN_MIN && irmp_pulse_time <= GRUNDIG_NOKIA_IR60_START_BIT_LEN_MAX &&
2088 irmp_pause_time >= GRUNDIG_NOKIA_IR60_PRE_PAUSE_LEN_MIN && irmp_pause_time <= GRUNDIG_NOKIA_IR60_PRE_PAUSE_LEN_MAX)
2089 { // it's GRUNDIG
2090 ANALYZE_PRINTF ("protocol = GRUNDIG, pre bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
2091 GRUNDIG_NOKIA_IR60_START_BIT_LEN_MIN, GRUNDIG_NOKIA_IR60_START_BIT_LEN_MAX,
2092 GRUNDIG_NOKIA_IR60_PRE_PAUSE_LEN_MIN, GRUNDIG_NOKIA_IR60_PRE_PAUSE_LEN_MAX);
2093 irmp_param_p = (IRMP_PARAMETER *) &grundig_param;
2094 last_pause = irmp_pause_time;
2095 last_value = 1;
2096 }
2097 else
2098 #endif // IRMP_SUPPORT_GRUNDIG_NOKIA_IR60_PROTOCOL == 1
2099
2100 #if IRMP_SUPPORT_SIEMENS_OR_RUWIDO_PROTOCOL == 1
2101 if (((irmp_pulse_time >= SIEMENS_OR_RUWIDO_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= SIEMENS_OR_RUWIDO_START_BIT_PULSE_LEN_MAX) ||
2102 (irmp_pulse_time >= 2 * SIEMENS_OR_RUWIDO_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= 2 * SIEMENS_OR_RUWIDO_START_BIT_PULSE_LEN_MAX)) &&
2103 ((irmp_pause_time >= SIEMENS_OR_RUWIDO_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= SIEMENS_OR_RUWIDO_START_BIT_PAUSE_LEN_MAX) ||
2104 (irmp_pause_time >= 2 * SIEMENS_OR_RUWIDO_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= 2 * SIEMENS_OR_RUWIDO_START_BIT_PAUSE_LEN_MAX)))
2105 { // it's RUWIDO or SIEMENS
2106 ANALYZE_PRINTF ("protocol = RUWIDO, start bit timings: pulse: %3d - %3d or %3d - %3d, pause: %3d - %3d or %3d - %3d\n",
2107 SIEMENS_OR_RUWIDO_START_BIT_PULSE_LEN_MIN, SIEMENS_OR_RUWIDO_START_BIT_PULSE_LEN_MAX,
2108 2 * SIEMENS_OR_RUWIDO_START_BIT_PULSE_LEN_MIN, 2 * SIEMENS_OR_RUWIDO_START_BIT_PULSE_LEN_MAX,
2109 SIEMENS_OR_RUWIDO_START_BIT_PAUSE_LEN_MIN, SIEMENS_OR_RUWIDO_START_BIT_PAUSE_LEN_MAX,
2110 2 * SIEMENS_OR_RUWIDO_START_BIT_PAUSE_LEN_MIN, 2 * SIEMENS_OR_RUWIDO_START_BIT_PAUSE_LEN_MAX);
2111 irmp_param_p = (IRMP_PARAMETER *) &ruwido_param;
2112 last_pause = irmp_pause_time;
2113 last_value = 1;
2114 }
2115 else
2116 #endif // IRMP_SUPPORT_SIEMENS_OR_RUWIDO_PROTOCOL == 1
2117
2118 #if IRMP_SUPPORT_FDC_PROTOCOL == 1
2119 if (irmp_pulse_time >= FDC_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= FDC_START_BIT_PULSE_LEN_MAX &&
2120 irmp_pause_time >= FDC_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= FDC_START_BIT_PAUSE_LEN_MAX)
2121 {
2122 ANALYZE_PRINTF ("protocol = FDC, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
2123 FDC_START_BIT_PULSE_LEN_MIN, FDC_START_BIT_PULSE_LEN_MAX,
2124 FDC_START_BIT_PAUSE_LEN_MIN, FDC_START_BIT_PAUSE_LEN_MAX);
2125 irmp_param_p = (IRMP_PARAMETER *) &fdc_param;
2126 }
2127 else
2128 #endif // IRMP_SUPPORT_FDC_PROTOCOL == 1
2129
2130 #if IRMP_SUPPORT_RCCAR_PROTOCOL == 1
2131 if (irmp_pulse_time >= RCCAR_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= RCCAR_START_BIT_PULSE_LEN_MAX &&
2132 irmp_pause_time >= RCCAR_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= RCCAR_START_BIT_PAUSE_LEN_MAX)
2133 {
2134 ANALYZE_PRINTF ("protocol = RCCAR, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
2135 RCCAR_START_BIT_PULSE_LEN_MIN, RCCAR_START_BIT_PULSE_LEN_MAX,
2136 RCCAR_START_BIT_PAUSE_LEN_MIN, RCCAR_START_BIT_PAUSE_LEN_MAX);
2137 irmp_param_p = (IRMP_PARAMETER *) &rccar_param;
2138 }
2139 else
2140 #endif // IRMP_SUPPORT_RCCAR_PROTOCOL == 1
2141
2142 #if IRMP_SUPPORT_KATHREIN_PROTOCOL == 1
2143 if (irmp_pulse_time >= KATHREIN_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= KATHREIN_START_BIT_PULSE_LEN_MAX &&
2144 irmp_pause_time >= KATHREIN_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= KATHREIN_START_BIT_PAUSE_LEN_MAX)
2145 { // it's KATHREIN
2146 ANALYZE_PRINTF ("protocol = KATHREIN, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
2147 KATHREIN_START_BIT_PULSE_LEN_MIN, KATHREIN_START_BIT_PULSE_LEN_MAX,
2148 KATHREIN_START_BIT_PAUSE_LEN_MIN, KATHREIN_START_BIT_PAUSE_LEN_MAX);
2149 irmp_param_p = (IRMP_PARAMETER *) &kathrein_param;
2150 }
2151 else
2152 #endif // IRMP_SUPPORT_KATHREIN_PROTOCOL == 1
2153
2154 #if IRMP_SUPPORT_NETBOX_PROTOCOL == 1
2155 if (irmp_pulse_time >= NETBOX_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= NETBOX_START_BIT_PULSE_LEN_MAX &&
2156 irmp_pause_time >= NETBOX_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= NETBOX_START_BIT_PAUSE_LEN_MAX)
2157 { // it's NETBOX
2158 ANALYZE_PRINTF ("protocol = NETBOX, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
2159 NETBOX_START_BIT_PULSE_LEN_MIN, NETBOX_START_BIT_PULSE_LEN_MAX,
2160 NETBOX_START_BIT_PAUSE_LEN_MIN, NETBOX_START_BIT_PAUSE_LEN_MAX);
2161 irmp_param_p = (IRMP_PARAMETER *) &netbox_param;
2162 }
2163 else
2164 #endif // IRMP_SUPPORT_NETBOX_PROTOCOL == 1
2165
2166 #if IRMP_SUPPORT_LEGO_PROTOCOL == 1
2167 if (irmp_pulse_time >= LEGO_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= LEGO_START_BIT_PULSE_LEN_MAX &&
2168 irmp_pause_time >= LEGO_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= LEGO_START_BIT_PAUSE_LEN_MAX)
2169 {
2170 ANALYZE_PRINTF ("protocol = LEGO, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
2171 LEGO_START_BIT_PULSE_LEN_MIN, LEGO_START_BIT_PULSE_LEN_MAX,
2172 LEGO_START_BIT_PAUSE_LEN_MIN, LEGO_START_BIT_PAUSE_LEN_MAX);
2173 irmp_param_p = (IRMP_PARAMETER *) &lego_param;
2174 }
2175 else
2176 #endif // IRMP_SUPPORT_LEGO_PROTOCOL == 1
2177
2178 {
2179 ANALYZE_PRINTF ("protocol = UNKNOWN\n");
2180 // irmp_busy_flag = FALSE;
2181 irmp_start_bit_detected = 0; // wait for another start bit...
2182 }
2183
2184 if (irmp_start_bit_detected)
2185 {
2186 memcpy_P (&irmp_param, irmp_param_p, sizeof (IRMP_PARAMETER));
2187
2188 #ifdef ANALYZE
2189 if (! (irmp_param.flags & IRMP_PARAM_FLAG_IS_MANCHESTER))
2190 {
2191 ANALYZE_PRINTF ("pulse_1: %3d - %3d\n", irmp_param.pulse_1_len_min, irmp_param.pulse_1_len_max);
2192 ANALYZE_PRINTF ("pause_1: %3d - %3d\n", irmp_param.pause_1_len_min, irmp_param.pause_1_len_max);
2193 }
2194 else
2195 {
2196 ANALYZE_PRINTF ("pulse: %3d - %3d or %3d - %3d\n", irmp_param.pulse_1_len_min, irmp_param.pulse_1_len_max,
2197 2 * irmp_param.pulse_1_len_min, 2 * irmp_param.pulse_1_len_max);
2198 ANALYZE_PRINTF ("pause: %3d - %3d or %3d - %3d\n", irmp_param.pause_1_len_min, irmp_param.pause_1_len_max,
2199 2 * irmp_param.pause_1_len_min, 2 * irmp_param.pause_1_len_max);
2200 }
2201
2202 #if IRMP_SUPPORT_RC5_PROTOCOL == 1 && (IRMP_SUPPORT_FDC_PROTOCOL == 1 || IRMP_SUPPORT_RCCAR_PROTOCOL == 1)
2203 if (irmp_param2.protocol)
2204 {
2205 ANALYZE_PRINTF ("pulse_0: %3d - %3d\n", irmp_param2.pulse_0_len_min, irmp_param2.pulse_0_len_max);
2206 ANALYZE_PRINTF ("pause_0: %3d - %3d\n", irmp_param2.pause_0_len_min, irmp_param2.pause_0_len_max);
2207 ANALYZE_PRINTF ("pulse_1: %3d - %3d\n", irmp_param2.pulse_1_len_min, irmp_param2.pulse_1_len_max);
2208 ANALYZE_PRINTF ("pause_1: %3d - %3d\n", irmp_param2.pause_1_len_min, irmp_param2.pause_1_len_max);
2209 }
2210 #endif
2211
2212
2213 #if IRMP_SUPPORT_RC6_PROTOCOL == 1
2214 if (irmp_param.protocol == IRMP_RC6_PROTOCOL)
2215 {
2216 ANALYZE_PRINTF ("pulse_toggle: %3d - %3d\n", RC6_TOGGLE_BIT_LEN_MIN, RC6_TOGGLE_BIT_LEN_MAX);
2217 }
2218 #endif
2219
2220 if (! (irmp_param.flags & IRMP_PARAM_FLAG_IS_MANCHESTER))
2221 {
2222 ANALYZE_PRINTF ("pulse_0: %3d - %3d\n", irmp_param.pulse_0_len_min, irmp_param.pulse_0_len_max);
2223 ANALYZE_PRINTF ("pause_0: %3d - %3d\n", irmp_param.pause_0_len_min, irmp_param.pause_0_len_max);
2224 }
2225 else
2226 {
2227 ANALYZE_PRINTF ("pulse: %3d - %3d or %3d - %3d\n", irmp_param.pulse_0_len_min, irmp_param.pulse_0_len_max,
2228 2 * irmp_param.pulse_0_len_min, 2 * irmp_param.pulse_0_len_max);
2229 ANALYZE_PRINTF ("pause: %3d - %3d or %3d - %3d\n", irmp_param.pause_0_len_min, irmp_param.pause_0_len_max,
2230 2 * irmp_param.pause_0_len_min, 2 * irmp_param.pause_0_len_max);
2231 }
2232
2233 #if IRMP_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1
2234 if (irmp_param.protocol == IRMP_BANG_OLUFSEN_PROTOCOL)
2235 {
2236 ANALYZE_PRINTF ("pulse_r: %3d - %3d\n", irmp_param.pulse_0_len_min, irmp_param.pulse_0_len_max);
2237 ANALYZE_PRINTF ("pause_r: %3d - %3d\n", BANG_OLUFSEN_R_PAUSE_LEN_MIN, BANG_OLUFSEN_R_PAUSE_LEN_MAX);
2238 }
2239 #endif
2240
2241 ANALYZE_PRINTF ("command_offset: %2d\n", irmp_param.command_offset);
2242 ANALYZE_PRINTF ("command_len: %3d\n", irmp_param.command_end - irmp_param.command_offset);
2243 ANALYZE_PRINTF ("complete_len: %3d\n", irmp_param.complete_len);
2244 ANALYZE_PRINTF ("stop_bit: %3d\n", irmp_param.stop_bit);
2245 #endif // ANALYZE
2246 }
2247
2248 irmp_bit = 0;
2249
2250 #if IRMP_SUPPORT_MANCHESTER == 1
2251 if ((irmp_param.flags & IRMP_PARAM_FLAG_IS_MANCHESTER) &&
2252 irmp_param.protocol != IRMP_RUWIDO_PROTOCOL && // Manchester, but not RUWIDO
2253 irmp_param.protocol != IRMP_RC6_PROTOCOL) // Manchester, but not RC6
2254 {
2255 if (irmp_pause_time > irmp_param.pulse_1_len_max && irmp_pause_time <= 2 * irmp_param.pulse_1_len_max)
2256 {
2257 ANALYZE_PRINTF ("%8.3fms [bit %2d: pulse = %3d, pause = %3d] ", (double) (time_counter * 1000) / F_INTERRUPTS, irmp_bit, irmp_pulse_time, irmp_pause_time);
2258 ANALYZE_PUTCHAR ((irmp_param.flags & IRMP_PARAM_FLAG_1ST_PULSE_IS_1) ? '0' : '1');
2259 ANALYZE_NEWLINE ();
2260 irmp_store_bit ((irmp_param.flags & IRMP_PARAM_FLAG_1ST_PULSE_IS_1) ? 0 : 1);
2261 }
2262 else if (! last_value) // && irmp_pause_time >= irmp_param.pause_1_len_min && irmp_pause_time <= irmp_param.pause_1_len_max)
2263 {
2264 ANALYZE_PRINTF ("%8.3fms [bit %2d: pulse = %3d, pause = %3d] ", (double) (time_counter * 1000) / F_INTERRUPTS, irmp_bit, irmp_pulse_time, irmp_pause_time);
2265
2266 ANALYZE_PUTCHAR ((irmp_param.flags & IRMP_PARAM_FLAG_1ST_PULSE_IS_1) ? '1' : '0');
2267 ANALYZE_NEWLINE ();
2268 irmp_store_bit ((irmp_param.flags & IRMP_PARAM_FLAG_1ST_PULSE_IS_1) ? 1 : 0);
2269 }
2270 }
2271 else
2272 #endif // IRMP_SUPPORT_MANCHESTER == 1
2273
2274 #if IRMP_SUPPORT_SERIAL == 1
2275 if (irmp_param.flags & IRMP_PARAM_FLAG_IS_SERIAL)
2276 {
2277 ; // do nothing
2278 }
2279 else
2280 #endif // IRMP_SUPPORT_SERIAL == 1
2281
2282
2283 #if IRMP_SUPPORT_DENON_PROTOCOL == 1
2284 if (irmp_param.protocol == IRMP_DENON_PROTOCOL)
2285 {
2286 ANALYZE_PRINTF ("%8.3fms [bit %2d: pulse = %3d, pause = %3d] ", (double) (time_counter * 1000) / F_INTERRUPTS, irmp_bit, irmp_pulse_time, irmp_pause_time);
2287
2288 if (irmp_pause_time >= DENON_1_PAUSE_LEN_MIN && irmp_pause_time <= DENON_1_PAUSE_LEN_MAX)
2289 { // pause timings correct for "1"?
2290 ANALYZE_PUTCHAR ('1'); // yes, store 1
2291 ANALYZE_NEWLINE ();
2292 irmp_store_bit (1);
2293 }
2294 else // if (irmp_pause_time >= DENON_0_PAUSE_LEN_MIN && irmp_pause_time <= DENON_0_PAUSE_LEN_MAX)
2295 { // pause timings correct for "0"?
2296 ANALYZE_PUTCHAR ('0'); // yes, store 0
2297 ANALYZE_NEWLINE ();
2298 irmp_store_bit (0);
2299 }
2300 }
2301 else
2302 #endif // IRMP_SUPPORT_DENON_PROTOCOL == 1
2303 #if IRMP_SUPPORT_THOMSON_PROTOCOL == 1
2304 if (irmp_param.protocol == IRMP_THOMSON_PROTOCOL)
2305 {
2306 ANALYZE_PRINTF ("%8.3fms [bit %2d: pulse = %3d, pause = %3d] ", (double) (time_counter * 1000) / F_INTERRUPTS, irmp_bit, irmp_pulse_time, irmp_pause_time);
2307
2308 if (irmp_pause_time >= THOMSON_1_PAUSE_LEN_MIN && irmp_pause_time <= THOMSON_1_PAUSE_LEN_MAX)
2309 { // pause timings correct for "1"?
2310 ANALYZE_PUTCHAR ('1'); // yes, store 1
2311 ANALYZE_NEWLINE ();
2312 irmp_store_bit (1);
2313 }
2314 else // if (irmp_pause_time >= THOMSON_0_PAUSE_LEN_MIN && irmp_pause_time <= THOMSON_0_PAUSE_LEN_MAX)
2315 { // pause timings correct for "0"?
2316 ANALYZE_PUTCHAR ('0'); // yes, store 0
2317 ANALYZE_NEWLINE ();
2318 irmp_store_bit (0);
2319 }
2320 }
2321 else
2322 #endif // IRMP_SUPPORT_THOMSON_PROTOCOL == 1
2323 {
2324 ; // else do nothing
2325 }
2326
2327 irmp_pulse_time = 1; // set counter to 1, not 0
2328 irmp_pause_time = 0;
2329 wait_for_start_space = 0;
2330 }
2331 }
2332 else if (wait_for_space) // the data section....
2333 { // counting the time of darkness....
2334 uint8_t got_light = FALSE;
2335
2336 if (irmp_input) // still dark?
2337 { // yes...
2338 if (irmp_bit == irmp_param.complete_len && irmp_param.stop_bit == 1)
2339 {
2340 if (
2341 #if IRMP_SUPPORT_MANCHESTER == 1
2342 (irmp_param.flags & IRMP_PARAM_FLAG_IS_MANCHESTER) ||
2343 #endif
2344 #if IRMP_SUPPORT_SERIAL == 1
2345 (irmp_param.flags & IRMP_PARAM_FLAG_IS_SERIAL) ||
2346 #endif
2347 (irmp_pulse_time >= irmp_param.pulse_0_len_min && irmp_pulse_time <= irmp_param.pulse_0_len_max))
2348 {
2349 #ifdef ANALYZE
2350 if (! (irmp_param.flags & IRMP_PARAM_FLAG_IS_MANCHESTER))
2351 {
2352 ANALYZE_PRINTF ("stop bit detected\n");
2353 }
2354 #endif
2355 irmp_param.stop_bit = 0;
2356 }
2357 else
2358 {
2359 ANALYZE_PRINTF ("error: stop bit timing wrong, irmp_bit = %d, irmp_pulse_time = %d, pulse_0_len_min = %d, pulse_0_len_max = %d\n",
2360 irmp_bit, irmp_pulse_time, irmp_param.pulse_0_len_min, irmp_param.pulse_0_len_max);
2361
2362 // irmp_busy_flag = FALSE;
2363 irmp_start_bit_detected = 0; // wait for another start bit...
2364 irmp_pulse_time = 0;
2365 irmp_pause_time = 0;
2366 }
2367 }
2368 else
2369 {
2370 irmp_pause_time++; // increment counter
2371
2372 #if IRMP_SUPPORT_SIRCS_PROTOCOL == 1
2373 if (irmp_param.protocol == IRMP_SIRCS_PROTOCOL && // Sony has a variable number of bits:
2374 irmp_pause_time > SIRCS_PAUSE_LEN_MAX && // minimum is 12
2375 irmp_bit >= 12 - 1) // pause too long?
2376 { // yes, break and close this frame
2377 irmp_param.complete_len = irmp_bit + 1; // set new complete length
2378 got_light = TRUE; // this is a lie, but helps (generates stop bit)
2379 irmp_tmp_address |= (irmp_bit - SIRCS_MINIMUM_DATA_LEN + 1) << 8; // new: store number of additional bits in upper byte of address!
2380 irmp_param.command_end = irmp_param.command_offset + irmp_bit + 1; // correct command length
2381 irmp_pause_time = SIRCS_PAUSE_LEN_MAX - 1; // correct pause length
2382 }
2383 else
2384 #endif
2385 #if IRMP_SUPPORT_SERIAL == 1
2386 // NETBOX generates no stop bit, here is the timeout condition:
2387 if ((irmp_param.flags & IRMP_PARAM_FLAG_IS_SERIAL) && irmp_param.protocol == IRMP_NETBOX_PROTOCOL &&
2388 irmp_pause_time >= NETBOX_PULSE_LEN * (NETBOX_COMPLETE_DATA_LEN - irmp_bit))
2389 {
2390 got_light = TRUE; // this is a lie, but helps (generates stop bit)
2391 }
2392 else
2393 #endif
2394 #if IRMP_SUPPORT_GRUNDIG_NOKIA_IR60_PROTOCOL == 1
2395 if (irmp_param.protocol == IRMP_GRUNDIG_PROTOCOL && !irmp_param.stop_bit)
2396 {
2397 if (irmp_pause_time > IR60_TIMEOUT_LEN && (irmp_bit == 5 || irmp_bit == 6))
2398 {
2399 ANALYZE_PRINTF ("Switching to IR60 protocol\n");
2400 got_light = TRUE; // this is a lie, but generates a stop bit ;-)
2401 irmp_param.stop_bit = TRUE; // set flag
2402
2403 irmp_param.protocol = IRMP_IR60_PROTOCOL; // change protocol
2404 irmp_param.complete_len = IR60_COMPLETE_DATA_LEN; // correct complete len
2405 irmp_param.address_offset = IR60_ADDRESS_OFFSET;
2406 irmp_param.address_end = IR60_ADDRESS_OFFSET + IR60_ADDRESS_LEN;
2407 irmp_param.command_offset = IR60_COMMAND_OFFSET;
2408 irmp_param.command_end = IR60_COMMAND_OFFSET + IR60_COMMAND_LEN;
2409
2410 irmp_tmp_command <<= 1;
2411 irmp_tmp_command |= first_bit;
2412 }
2413 else if (irmp_pause_time >= 2 * irmp_param.pause_1_len_max && irmp_bit >= GRUNDIG_COMPLETE_DATA_LEN - 2)
2414 { // special manchester decoder
2415 irmp_param.complete_len = GRUNDIG_COMPLETE_DATA_LEN; // correct complete len
2416 got_light = TRUE; // this is a lie, but generates a stop bit ;-)
2417 irmp_param.stop_bit = TRUE; // set flag
2418 }
2419 else if (irmp_bit >= GRUNDIG_COMPLETE_DATA_LEN)
2420 {
2421 ANALYZE_PRINTF ("Switching to NOKIA protocol\n");
2422 irmp_param.protocol = IRMP_NOKIA_PROTOCOL; // change protocol
2423 irmp_param.address_offset = NOKIA_ADDRESS_OFFSET;
2424 irmp_param.address_end = NOKIA_ADDRESS_OFFSET + NOKIA_ADDRESS_LEN;
2425 irmp_param.command_offset = NOKIA_COMMAND_OFFSET;
2426 irmp_param.command_end = NOKIA_COMMAND_OFFSET + NOKIA_COMMAND_LEN;
2427
2428 if (irmp_tmp_command & 0x300)
2429 {
2430 irmp_tmp_address = (irmp_tmp_command >> 8);
2431 irmp_tmp_command &= 0xFF;
2432 }
2433 }
2434 }
2435 else
2436 #endif
2437 #if IRMP_SUPPORT_SIEMENS_OR_RUWIDO_PROTOCOL == 1
2438 if (irmp_param.protocol == IRMP_RUWIDO_PROTOCOL && !irmp_param.stop_bit)
2439 {
2440 if (irmp_pause_time >= 2 * irmp_param.pause_1_len_max && irmp_bit >= RUWIDO_COMPLETE_DATA_LEN - 2)
2441 { // special manchester decoder
2442 irmp_param.complete_len = RUWIDO_COMPLETE_DATA_LEN; // correct complete len
2443 got_light = TRUE; // this is a lie, but generates a stop bit ;-)
2444 irmp_param.stop_bit = TRUE; // set flag
2445 }
2446 else if (irmp_bit >= RUWIDO_COMPLETE_DATA_LEN)
2447 {
2448 ANALYZE_PRINTF ("Switching to SIEMENS protocol\n");
2449 irmp_param.protocol = IRMP_SIEMENS_PROTOCOL; // change protocol
2450 irmp_param.address_offset = SIEMENS_ADDRESS_OFFSET;
2451 irmp_param.address_end = SIEMENS_ADDRESS_OFFSET + SIEMENS_ADDRESS_LEN;
2452 irmp_param.command_offset = SIEMENS_COMMAND_OFFSET;
2453 irmp_param.command_end = SIEMENS_COMMAND_OFFSET + SIEMENS_COMMAND_LEN;
2454
2455 // 76543210
2456 // RUWIDO: AAAAAAAAACCCCCCCp
2457 // SIEMENS: AAAAAAAAAAACCCCCCCCCCp
2458 irmp_tmp_address <<= 2;
2459 irmp_tmp_address |= (irmp_tmp_command >> 6);
2460 irmp_tmp_command &= 0x003F;
2461 irmp_tmp_command <<= 4;
2462 irmp_tmp_command |= last_value;
2463 }
2464 }
2465 else
2466 #endif
2467 #if IRMP_SUPPORT_MANCHESTER == 1
2468 if ((irmp_param.flags & IRMP_PARAM_FLAG_IS_MANCHESTER) &&
2469 irmp_pause_time >= 2 * irmp_param.pause_1_len_max && irmp_bit >= irmp_param.complete_len - 2 && !irmp_param.stop_bit)
2470 { // special manchester decoder
2471 got_light = TRUE; // this is a lie, but generates a stop bit ;-)
2472 irmp_param.stop_bit = TRUE; // set flag
2473 }
2474 else
2475 #endif // IRMP_SUPPORT_MANCHESTER == 1
2476 if (irmp_pause_time > IRMP_TIMEOUT_LEN) // timeout?
2477 { // yes...
2478 if (irmp_bit == irmp_param.complete_len - 1 && irmp_param.stop_bit == 0)
2479 {
2480 irmp_bit++;
2481 }
2482 #if IRMP_SUPPORT_JVC_PROTOCOL == 1
2483 else if (irmp_param.protocol == IRMP_NEC_PROTOCOL && (irmp_bit == 16 || irmp_bit == 17)) // it was a JVC stop bit
2484 {
2485 ANALYZE_PRINTF ("Switching to JVC protocol, irmp_bit = %d\n", irmp_bit);
2486 irmp_param.stop_bit = TRUE; // set flag
2487 irmp_param.protocol = IRMP_JVC_PROTOCOL; // switch protocol
2488 irmp_param.complete_len = irmp_bit; // patch length: 16 or 17
2489 irmp_tmp_command = (irmp_tmp_address >> 4); // set command: upper 12 bits are command bits
2490 irmp_tmp_address = irmp_tmp_address & 0x000F; // lower 4 bits are address bits
2491 irmp_start_bit_detected = 1; // tricky: don't wait for another start bit...
2492 }
2493 #endif // IRMP_SUPPORT_JVC_PROTOCOL == 1
2494
2495 #if IRMP_SUPPORT_NEC42_PROTOCOL == 1
2496 #if IRMP_SUPPORT_NEC_PROTOCOL == 1
2497 else if (irmp_param.protocol == IRMP_NEC42_PROTOCOL && irmp_bit == 32) // it was a NEC stop bit
2498 {
2499 ANALYZE_PRINTF ("Switching to NEC protocol\n");
2500 irmp_param.stop_bit = TRUE; // set flag
2501 irmp_param.protocol = IRMP_NEC_PROTOCOL; // switch protocol
2502 irmp_param.complete_len = irmp_bit; // patch length: 16 or 17
2503
2504 // 0123456789ABC0123456789ABC0123456701234567
2505 // NEC42: AAAAAAAAAAAAAaaaaaaaaaaaaaCCCCCCCCcccccccc
2506 // NEC: AAAAAAAAaaaaaaaaCCCCCCCCcccccccc
2507 irmp_tmp_address |= (irmp_tmp_address2 & 0x0007) << 13; // fm 2012-02-13: 12 -> 13
2508 irmp_tmp_command = (irmp_tmp_address2 >> 3) | (irmp_tmp_command << 10);
2509 }
2510 #endif // IRMP_SUPPORT_NEC_PROTOCOL == 1
2511 #if IRMP_SUPPORT_JVC_PROTOCOL == 1
2512 else if (irmp_param.protocol == IRMP_NEC42_PROTOCOL && (irmp_bit == 16 || irmp_bit == 17)) // it was a JVC stop bit
2513 {
2514 ANALYZE_PRINTF ("Switching to JVC protocol, irmp_bit = %d\n", irmp_bit);
2515 irmp_param.stop_bit = TRUE; // set flag
2516 irmp_param.protocol = IRMP_JVC_PROTOCOL; // switch protocol
2517 irmp_param.complete_len = irmp_bit; // patch length: 16 or 17
2518
2519 // 0123456789ABC0123456789ABC0123456701234567
2520 // NEC42: AAAAAAAAAAAAAaaaaaaaaaaaaaCCCCCCCCcccccccc
2521 // JVC: AAAACCCCCCCCCCCC
2522 irmp_tmp_command = (irmp_tmp_address >> 4) | (irmp_tmp_address2 << 9); // set command: upper 12 bits are command bits
2523 irmp_tmp_address = irmp_tmp_address & 0x000F; // lower 4 bits are address bits
2524 }
2525 #endif // IRMP_SUPPORT_JVC_PROTOCOL == 1
2526 #endif // IRMP_SUPPORT_NEC42_PROTOCOL == 1
2527 else
2528 {
2529 ANALYZE_PRINTF ("error 2: pause %d after data bit %d too long\n", irmp_pause_time, irmp_bit);
2530 ANALYZE_ONLY_NORMAL_PUTCHAR ('\n');
2531
2532 // irmp_busy_flag = FALSE;
2533 irmp_start_bit_detected = 0; // wait for another start bit...
2534 irmp_pulse_time = 0;
2535 irmp_pause_time = 0;
2536 }
2537 }
2538 }
2539 }
2540 else
2541 { // got light now!
2542 got_light = TRUE;
2543 }
2544
2545 if (got_light)
2546 {
2547 ANALYZE_PRINTF ("%8.3fms [bit %2d: pulse = %3d, pause = %3d] ", (double) (time_counter * 1000) / F_INTERRUPTS, irmp_bit, irmp_pulse_time, irmp_pause_time);
2548
2549 #if IRMP_SUPPORT_MANCHESTER == 1
2550 if ((irmp_param.flags & IRMP_PARAM_FLAG_IS_MANCHESTER)) // Manchester
2551 {
2552 #if 1
2553 if (irmp_pulse_time > irmp_param.pulse_1_len_max /* && irmp_pulse_time <= 2 * irmp_param.pulse_1_len_max */)
2554 #else // better, but some IR-RCs use asymmetric timings :-/
2555 if (irmp_pulse_time > irmp_param.pulse_1_len_max && irmp_pulse_time <= 2 * irmp_param.pulse_1_len_max &&
2556 irmp_pause_time <= 2 * irmp_param.pause_1_len_max)
2557 #endif
2558 {
2559 #if IRMP_SUPPORT_RC6_PROTOCOL == 1
2560 if (irmp_param.protocol == IRMP_RC6_PROTOCOL && irmp_bit == 4 && irmp_pulse_time > RC6_TOGGLE_BIT_LEN_MIN) // RC6 toggle bit
2561 {
2562 ANALYZE_PUTCHAR ('T');
2563 if (irmp_param.complete_len == RC6_COMPLETE_DATA_LEN_LONG) // RC6 mode 6A
2564 {
2565 irmp_store_bit (1);
2566 last_value = 1;
2567 }
2568 else // RC6 mode 0
2569 {
2570 irmp_store_bit (0);
2571 last_value = 0;
2572 }
2573 ANALYZE_NEWLINE ();
2574 }
2575 else
2576 #endif // IRMP_SUPPORT_RC6_PROTOCOL == 1
2577 {
2578 ANALYZE_PUTCHAR ((irmp_param.flags & IRMP_PARAM_FLAG_1ST_PULSE_IS_1) ? '0' : '1');
2579 irmp_store_bit ((irmp_param.flags & IRMP_PARAM_FLAG_1ST_PULSE_IS_1) ? 0 : 1 );
2580
2581 #if IRMP_SUPPORT_RC6_PROTOCOL == 1
2582 if (irmp_param.protocol == IRMP_RC6_PROTOCOL && irmp_bit == 4 && irmp_pulse_time > RC6_TOGGLE_BIT_LEN_MIN) // RC6 toggle bit
2583 {
2584 ANALYZE_PUTCHAR ('T');
2585 irmp_store_bit (1);
2586
2587 if (irmp_pause_time > 2 * irmp_param.pause_1_len_max)
2588 {
2589 last_value = 0;
2590 }
2591 else
2592 {
2593 last_value = 1;
2594 }
2595 ANALYZE_NEWLINE ();
2596 }
2597 else
2598 #endif // IRMP_SUPPORT_RC6_PROTOCOL == 1
2599 {
2600 ANALYZE_PUTCHAR ((irmp_param.flags & IRMP_PARAM_FLAG_1ST_PULSE_IS_1) ? '1' : '0');
2601 irmp_store_bit ((irmp_param.flags & IRMP_PARAM_FLAG_1ST_PULSE_IS_1) ? 1 : 0 );
2602 #if IRMP_SUPPORT_RC5_PROTOCOL == 1 && (IRMP_SUPPORT_FDC_PROTOCOL == 1 || IRMP_SUPPORT_RCCAR_PROTOCOL == 1)
2603 if (! irmp_param2.protocol)
2604 #endif
2605 {
2606 ANALYZE_NEWLINE ();
2607 }
2608 last_value = (irmp_param.flags & IRMP_PARAM_FLAG_1ST_PULSE_IS_1) ? 1 : 0;
2609 }
2610 }
2611 }
2612 else if (irmp_pulse_time >= irmp_param.pulse_1_len_min && irmp_pulse_time <= irmp_param.pulse_1_len_max
2613 /* && irmp_pause_time <= 2 * irmp_param.pause_1_len_max */)
2614 {
2615 uint8_t manchester_value;
2616
2617 if (last_pause > irmp_param.pause_1_len_max && last_pause <= 2 * irmp_param.pause_1_len_max)
2618 {
2619 manchester_value = last_value ? 0 : 1;
2620 last_value = manchester_value;
2621 }
2622 else
2623 {
2624 manchester_value = last_value;
2625 }
2626
2627 ANALYZE_PUTCHAR (manchester_value + '0');
2628
2629 #if IRMP_SUPPORT_RC5_PROTOCOL == 1 && (IRMP_SUPPORT_FDC_PROTOCOL == 1 || IRMP_SUPPORT_RCCAR_PROTOCOL == 1)
2630 if (! irmp_param2.protocol)
2631 #endif
2632 {
2633 ANALYZE_NEWLINE ();
2634 }
2635
2636 #if IRMP_SUPPORT_RC6_PROTOCOL == 1
2637 if (irmp_param.protocol == IRMP_RC6_PROTOCOL && irmp_bit == 1 && manchester_value == 1) // RC6 mode != 0 ???
2638 {
2639 ANALYZE_PRINTF ("Switching to RC6A protocol\n");
2640 irmp_param.complete_len = RC6_COMPLETE_DATA_LEN_LONG;
2641 irmp_param.address_offset = 5;
2642 irmp_param.address_end = irmp_param.address_offset + 15;
2643 irmp_param.command_offset = irmp_param.address_end + 1; // skip 1 system bit, changes like a toggle bit
2644 irmp_param.command_end = irmp_param.command_offset + 16 - 1;
2645 irmp_tmp_address = 0;
2646 }
2647 #endif // IRMP_SUPPORT_RC6_PROTOCOL == 1
2648
2649 irmp_store_bit (manchester_value);
2650 }
2651 else
2652 {
2653 #if IRMP_SUPPORT_RC5_PROTOCOL == 1 && IRMP_SUPPORT_FDC_PROTOCOL == 1
2654 if (irmp_param2.protocol == IRMP_FDC_PROTOCOL &&
2655 irmp_pulse_time >= FDC_PULSE_LEN_MIN && irmp_pulse_time <= FDC_PULSE_LEN_MAX &&
2656 ((irmp_pause_time >= FDC_1_PAUSE_LEN_MIN && irmp_pause_time <= FDC_1_PAUSE_LEN_MAX) ||
2657 (irmp_pause_time >= FDC_0_PAUSE_LEN_MIN && irmp_pause_time <= FDC_0_PAUSE_LEN_MAX)))
2658 {
2659 ANALYZE_PUTCHAR ('?');
2660 irmp_param.protocol = 0; // switch to FDC, see below
2661 }
2662 else
2663 #endif // IRMP_SUPPORT_FDC_PROTOCOL == 1
2664 #if IRMP_SUPPORT_RC5_PROTOCOL == 1 && IRMP_SUPPORT_RCCAR_PROTOCOL == 1
2665 if (irmp_param2.protocol == IRMP_RCCAR_PROTOCOL &&
2666 irmp_pulse_time >= RCCAR_PULSE_LEN_MIN && irmp_pulse_time <= RCCAR_PULSE_LEN_MAX &&
2667 ((irmp_pause_time >= RCCAR_1_PAUSE_LEN_MIN && irmp_pause_time <= RCCAR_1_PAUSE_LEN_MAX) ||
2668 (irmp_pause_time >= RCCAR_0_PAUSE_LEN_MIN && irmp_pause_time <= RCCAR_0_PAUSE_LEN_MAX)))
2669 {
2670 ANALYZE_PUTCHAR ('?');
2671 irmp_param.protocol = 0; // switch to RCCAR, see below
2672 }
2673 else
2674 #endif // IRMP_SUPPORT_RCCAR_PROTOCOL == 1
2675 {
2676 ANALYZE_PUTCHAR ('?');
2677 ANALYZE_NEWLINE ();
2678 ANALYZE_PRINTF ("error 3 manchester: timing not correct: data bit %d, pulse: %d, pause: %d\n", irmp_bit, irmp_pulse_time, irmp_pause_time);
2679 ANALYZE_ONLY_NORMAL_PUTCHAR ('\n');
2680 // irmp_busy_flag = FALSE;
2681 irmp_start_bit_detected = 0; // reset flags and wait for next start bit
2682 irmp_pause_time = 0;
2683 }
2684 }
2685
2686 #if IRMP_SUPPORT_RC5_PROTOCOL == 1 && IRMP_SUPPORT_FDC_PROTOCOL == 1
2687 if (irmp_param2.protocol == IRMP_FDC_PROTOCOL && irmp_pulse_time >= FDC_PULSE_LEN_MIN && irmp_pulse_time <= FDC_PULSE_LEN_MAX)
2688 {
2689 if (irmp_pause_time >= FDC_1_PAUSE_LEN_MIN && irmp_pause_time <= FDC_1_PAUSE_LEN_MAX)
2690 {
2691 ANALYZE_PRINTF (" 1 (FDC)\n");
2692 irmp_store_bit2 (1);
2693 }
2694 else if (irmp_pause_time >= FDC_0_PAUSE_LEN_MIN && irmp_pause_time <= FDC_0_PAUSE_LEN_MAX)
2695 {
2696 ANALYZE_PRINTF (" 0 (FDC)\n");
2697 irmp_store_bit2 (0);
2698 }
2699
2700 if (! irmp_param.protocol)
2701 {
2702 ANALYZE_PRINTF ("Switching to FDC protocol\n");
2703 memcpy (&irmp_param, &irmp_param2, sizeof (IRMP_PARAMETER));
2704 irmp_param2.protocol = 0;
2705 irmp_tmp_address = irmp_tmp_address2;
2706 irmp_tmp_command = irmp_tmp_command2;
2707 }
2708 }
2709 #endif // IRMP_SUPPORT_FDC_PROTOCOL == 1
2710 #if IRMP_SUPPORT_RC5_PROTOCOL == 1 && IRMP_SUPPORT_RCCAR_PROTOCOL == 1
2711 if (irmp_param2.protocol == IRMP_RCCAR_PROTOCOL && irmp_pulse_time >= RCCAR_PULSE_LEN_MIN && irmp_pulse_time <= RCCAR_PULSE_LEN_MAX)
2712 {
2713 if (irmp_pause_time >= RCCAR_1_PAUSE_LEN_MIN && irmp_pause_time <= RCCAR_1_PAUSE_LEN_MAX)
2714 {
2715 ANALYZE_PRINTF (" 1 (RCCAR)\n");
2716 irmp_store_bit2 (1);
2717 }
2718 else if (irmp_pause_time >= RCCAR_0_PAUSE_LEN_MIN && irmp_pause_time <= RCCAR_0_PAUSE_LEN_MAX)
2719 {
2720 ANALYZE_PRINTF (" 0 (RCCAR)\n");
2721 irmp_store_bit2 (0);
2722 }
2723
2724 if (! irmp_param.protocol)
2725 {
2726 ANALYZE_PRINTF ("Switching to RCCAR protocol\n");
2727 memcpy (&irmp_param, &irmp_param2, sizeof (IRMP_PARAMETER));
2728 irmp_param2.protocol = 0;
2729 irmp_tmp_address = irmp_tmp_address2;
2730 irmp_tmp_command = irmp_tmp_command2;
2731 }
2732 }
2733 #endif // IRMP_SUPPORT_RCCAR_PROTOCOL == 1
2734
2735 last_pause = irmp_pause_time;
2736 wait_for_space = 0;
2737 }
2738 else
2739 #endif // IRMP_SUPPORT_MANCHESTER == 1
2740
2741 #if IRMP_SUPPORT_SERIAL == 1
2742 if (irmp_param.flags & IRMP_PARAM_FLAG_IS_SERIAL)
2743 {
2744 while (irmp_bit < irmp_param.complete_len && irmp_pulse_time > irmp_param.pulse_1_len_max)
2745 {
2746 ANALYZE_PUTCHAR ('1');
2747 irmp_store_bit (1);
2748
2749 if (irmp_pulse_time >= irmp_param.pulse_1_len_min)
2750 {
2751 irmp_pulse_time -= irmp_param.pulse_1_len_min;
2752 }
2753 else
2754 {
2755 irmp_pulse_time = 0;
2756 }
2757 }
2758
2759 while (irmp_bit < irmp_param.complete_len && irmp_pause_time > irmp_param.pause_1_len_max)
2760 {
2761 ANALYZE_PUTCHAR ('0');
2762 irmp_store_bit (0);
2763
2764 if (irmp_pause_time >= irmp_param.pause_1_len_min)
2765 {
2766 irmp_pause_time -= irmp_param.pause_1_len_min;
2767 }
2768 else
2769 {
2770 irmp_pause_time = 0;
2771 }
2772 }
2773 ANALYZE_NEWLINE ();
2774 wait_for_space = 0;
2775 }
2776 else
2777 #endif // IRMP_SUPPORT_SERIAL == 1
2778
2779 #if IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1
2780 if (irmp_param.protocol == IRMP_SAMSUNG_PROTOCOL && irmp_bit == 16) // Samsung: 16th bit
2781 {
2782 if (irmp_pulse_time >= SAMSUNG_PULSE_LEN_MIN && irmp_pulse_time <= SAMSUNG_PULSE_LEN_MAX &&
2783 irmp_pause_time >= SAMSUNG_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= SAMSUNG_START_BIT_PAUSE_LEN_MAX)
2784 {
2785 ANALYZE_PRINTF ("SYNC\n");
2786 wait_for_space = 0;
2787 irmp_tmp_id = 0;
2788 irmp_bit++;
2789 }
2790 else if (irmp_pulse_time >= SAMSUNG_PULSE_LEN_MIN && irmp_pulse_time <= SAMSUNG_PULSE_LEN_MAX)
2791 {
2792 irmp_param.protocol = IRMP_SAMSUNG32_PROTOCOL;
2793 irmp_param.command_offset = SAMSUNG32_COMMAND_OFFSET;
2794 irmp_param.command_end = SAMSUNG32_COMMAND_OFFSET + SAMSUNG32_COMMAND_LEN;
2795 irmp_param.complete_len = SAMSUNG32_COMPLETE_DATA_LEN;
2796
2797 if (irmp_pause_time >= SAMSUNG_1_PAUSE_LEN_MIN && irmp_pause_time <= SAMSUNG_1_PAUSE_LEN_MAX)
2798 {
2799 ANALYZE_PUTCHAR ('1');
2800 ANALYZE_NEWLINE ();
2801 irmp_store_bit (1);
2802 wait_for_space = 0;
2803 }
2804 else
2805 {
2806 ANALYZE_PUTCHAR ('0');
2807 ANALYZE_NEWLINE ();
2808 irmp_store_bit (0);
2809 wait_for_space = 0;
2810 }
2811
2812 ANALYZE_PRINTF ("Switching to SAMSUNG32 protocol\n");
2813 }
2814 else
2815 { // timing incorrect!
2816 ANALYZE_PRINTF ("error 3 Samsung: timing not correct: data bit %d, pulse: %d, pause: %d\n", irmp_bit, irmp_pulse_time, irmp_pause_time);
2817 ANALYZE_ONLY_NORMAL_PUTCHAR ('\n');
2818 // irmp_busy_flag = FALSE;
2819 irmp_start_bit_detected = 0; // reset flags and wait for next start bit
2820 irmp_pause_time = 0;
2821 }
2822 }
2823 else
2824 #endif // IRMP_SUPPORT_SAMSUNG_PROTOCOL
2825
2826 #if IRMP_SUPPORT_NEC16_PROTOCOL
2827 #if IRMP_SUPPORT_NEC42_PROTOCOL == 1
2828 if (irmp_param.protocol == IRMP_NEC42_PROTOCOL &&
2829 #else // IRMP_SUPPORT_NEC_PROTOCOL instead
2830 if (irmp_param.protocol == IRMP_NEC_PROTOCOL &&
2831 #endif // IRMP_SUPPORT_NEC42_PROTOCOL == 1
2832 irmp_bit == 8 && irmp_pause_time >= NEC_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= NEC_START_BIT_PAUSE_LEN_MAX)
2833 {
2834 ANALYZE_PRINTF ("Switching to NEC16 protocol\n");
2835 irmp_param.protocol = IRMP_NEC16_PROTOCOL;
2836 irmp_param.address_offset = NEC16_ADDRESS_OFFSET;
2837 irmp_param.address_end = NEC16_ADDRESS_OFFSET + NEC16_ADDRESS_LEN;
2838 irmp_param.command_offset = NEC16_COMMAND_OFFSET;
2839 irmp_param.command_end = NEC16_COMMAND_OFFSET + NEC16_COMMAND_LEN;
2840 irmp_param.complete_len = NEC16_COMPLETE_DATA_LEN;
2841 wait_for_space = 0;
2842 }
2843 else
2844 #endif // IRMP_SUPPORT_NEC16_PROTOCOL
2845
2846 #if IRMP_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1
2847 if (irmp_param.protocol == IRMP_BANG_OLUFSEN_PROTOCOL)
2848 {
2849 if (irmp_pulse_time >= BANG_OLUFSEN_PULSE_LEN_MIN && irmp_pulse_time <= BANG_OLUFSEN_PULSE_LEN_MAX)
2850 {
2851 if (irmp_bit == 1) // Bang & Olufsen: 3rd bit
2852 {
2853 if (irmp_pause_time >= BANG_OLUFSEN_START_BIT3_PAUSE_LEN_MIN && irmp_pause_time <= BANG_OLUFSEN_START_BIT3_PAUSE_LEN_MAX)
2854 {
2855 ANALYZE_PRINTF ("3rd start bit\n");
2856 wait_for_space = 0;
2857 irmp_bit++;
2858 }
2859 else
2860 { // timing incorrect!
2861 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);
2862 ANALYZE_ONLY_NORMAL_PUTCHAR ('\n');
2863 // irmp_busy_flag = FALSE;
2864 irmp_start_bit_detected = 0; // reset flags and wait for next start bit
2865 irmp_pause_time = 0;
2866 }
2867 }
2868 else if (irmp_bit == 19) // Bang & Olufsen: trailer bit
2869 {
2870 if (irmp_pause_time >= BANG_OLUFSEN_TRAILER_BIT_PAUSE_LEN_MIN && irmp_pause_time <= BANG_OLUFSEN_TRAILER_BIT_PAUSE_LEN_MAX)
2871 {
2872 ANALYZE_PRINTF ("trailer bit\n");
2873 wait_for_space = 0;
2874 irmp_bit++;
2875 }
2876 else
2877 { // timing incorrect!
2878 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);
2879 ANALYZE_ONLY_NORMAL_PUTCHAR ('\n');
2880 // irmp_busy_flag = FALSE;
2881 irmp_start_bit_detected = 0; // reset flags and wait for next start bit
2882 irmp_pause_time = 0;
2883 }
2884 }
2885 else
2886 {
2887 if (irmp_pause_time >= BANG_OLUFSEN_1_PAUSE_LEN_MIN && irmp_pause_time <= BANG_OLUFSEN_1_PAUSE_LEN_MAX)
2888 { // pulse & pause timings correct for "1"?
2889 ANALYZE_PUTCHAR ('1');
2890 ANALYZE_NEWLINE ();
2891 irmp_store_bit (1);
2892 last_value = 1;
2893 wait_for_space = 0;
2894 }
2895 else if (irmp_pause_time >= BANG_OLUFSEN_0_PAUSE_LEN_MIN && irmp_pause_time <= BANG_OLUFSEN_0_PAUSE_LEN_MAX)
2896 { // pulse & pause timings correct for "0"?
2897 ANALYZE_PUTCHAR ('0');
2898 ANALYZE_NEWLINE ();
2899 irmp_store_bit (0);
2900 last_value = 0;
2901 wait_for_space = 0;
2902 }
2903 else if (irmp_pause_time >= BANG_OLUFSEN_R_PAUSE_LEN_MIN && irmp_pause_time <= BANG_OLUFSEN_R_PAUSE_LEN_MAX)
2904 {
2905 ANALYZE_PUTCHAR (last_value + '0');
2906 ANALYZE_NEWLINE ();
2907 irmp_store_bit (last_value);
2908 wait_for_space = 0;
2909 }
2910 else
2911 { // timing incorrect!
2912 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);
2913 ANALYZE_ONLY_NORMAL_PUTCHAR ('\n');
2914 // irmp_busy_flag = FALSE;
2915 irmp_start_bit_detected = 0; // reset flags and wait for next start bit
2916 irmp_pause_time = 0;
2917 }
2918 }
2919 }
2920 else
2921 { // timing incorrect!
2922 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);
2923 ANALYZE_ONLY_NORMAL_PUTCHAR ('\n');
2924 // irmp_busy_flag = FALSE;
2925 irmp_start_bit_detected = 0; // reset flags and wait for next start bit
2926 irmp_pause_time = 0;
2927 }
2928 }
2929 else
2930 #endif // IRMP_SUPPORT_BANG_OLUFSEN_PROTOCOL
2931
2932 if (irmp_pulse_time >= irmp_param.pulse_1_len_min && irmp_pulse_time <= irmp_param.pulse_1_len_max &&
2933 irmp_pause_time >= irmp_param.pause_1_len_min && irmp_pause_time <= irmp_param.pause_1_len_max)
2934 { // pulse & pause timings correct for "1"?
2935 ANALYZE_PUTCHAR ('1');
2936 ANALYZE_NEWLINE ();
2937 irmp_store_bit (1);
2938 wait_for_space = 0;
2939 }
2940 else if (irmp_pulse_time >= irmp_param.pulse_0_len_min && irmp_pulse_time <= irmp_param.pulse_0_len_max &&
2941 irmp_pause_time >= irmp_param.pause_0_len_min && irmp_pause_time <= irmp_param.pause_0_len_max)
2942 { // pulse & pause timings correct for "0"?
2943 ANALYZE_PUTCHAR ('0');
2944 ANALYZE_NEWLINE ();
2945 irmp_store_bit (0);
2946 wait_for_space = 0;
2947 }
2948 else
2949 #if IRMP_SUPPORT_KATHREIN_PROTOCOL
2950
2951 if (irmp_param.protocol == IRMP_KATHREIN_PROTOCOL &&
2952 irmp_pulse_time >= KATHREIN_1_PULSE_LEN_MIN && irmp_pulse_time <= KATHREIN_1_PULSE_LEN_MAX &&
2953 (((irmp_bit == 8 || irmp_bit == 6) &&
2954 irmp_pause_time >= KATHREIN_SYNC_BIT_PAUSE_LEN_MIN && irmp_pause_time <= KATHREIN_SYNC_BIT_PAUSE_LEN_MAX) ||
2955 (irmp_bit == 12 &&
2956 irmp_pause_time >= KATHREIN_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= KATHREIN_START_BIT_PAUSE_LEN_MAX)))
2957
2958 {
2959 if (irmp_bit == 8)
2960 {
2961 irmp_bit++;
2962 ANALYZE_PUTCHAR ('S');
2963 ANALYZE_NEWLINE ();
2964 irmp_tmp_command <<= 1;
2965 }
2966 else
2967 {
2968 ANALYZE_PUTCHAR ('S');
2969 ANALYZE_NEWLINE ();
2970 irmp_store_bit (1);
2971 }
2972 wait_for_space = 0;
2973 }
2974 else
2975 #endif // IRMP_SUPPORT_KATHREIN_PROTOCOL
2976 { // timing incorrect!
2977 ANALYZE_PRINTF ("error 3: timing not correct: data bit %d, pulse: %d, pause: %d\n", irmp_bit, irmp_pulse_time, irmp_pause_time);
2978 ANALYZE_ONLY_NORMAL_PUTCHAR ('\n');
2979 // irmp_busy_flag = FALSE;
2980 irmp_start_bit_detected = 0; // reset flags and wait for next start bit
2981 irmp_pause_time = 0;
2982 }
2983
2984 irmp_pulse_time = 1; // set counter to 1, not 0
2985 }
2986 }
2987 else
2988 { // counting the pulse length ...
2989 if (! irmp_input) // still light?
2990 { // yes...
2991 irmp_pulse_time++; // increment counter
2992 }
2993 else
2994 { // now it's dark!
2995 wait_for_space = 1; // let's count the time (see above)
2996 irmp_pause_time = 1; // set pause counter to 1, not 0
2997 }
2998 }
2999
3000 if (irmp_start_bit_detected && irmp_bit == irmp_param.complete_len && irmp_param.stop_bit == 0) // enough bits received?
3001 {
3002 if (last_irmp_command == irmp_tmp_command && repetition_len < AUTO_FRAME_REPETITION_LEN)
3003 {
3004 repetition_frame_number++;
3005 }
3006 else
3007 {
3008 repetition_frame_number = 0;
3009 }
3010
3011 #if IRMP_SUPPORT_SIRCS_PROTOCOL == 1
3012 // if SIRCS protocol and the code will be repeated within 50 ms, we will ignore 2nd and 3rd repetition frame
3013 if (irmp_param.protocol == IRMP_SIRCS_PROTOCOL && (repetition_frame_number == 1 || repetition_frame_number == 2))
3014 {
3015 ANALYZE_PRINTF ("code skipped: SIRCS auto repetition frame #%d, counter = %d, auto repetition len = %d\n",
3016 repetition_frame_number + 1, repetition_len, AUTO_FRAME_REPETITION_LEN);
3017 repetition_len = 0;
3018 }
3019 else
3020 #endif
3021
3022 #if IRMP_SUPPORT_KASEIKYO_PROTOCOL == 1
3023 // if KASEIKYO protocol and the code will be repeated within 50 ms, we will ignore 2nd repetition frame
3024 if (irmp_param.protocol == IRMP_KASEIKYO_PROTOCOL && repetition_frame_number == 1)
3025 {
3026 ANALYZE_PRINTF ("code skipped: KASEIKYO auto repetition frame #%d, counter = %d, auto repetition len = %d\n",
3027 repetition_frame_number + 1, repetition_len, AUTO_FRAME_REPETITION_LEN);
3028 repetition_len = 0;
3029 }
3030 else
3031 #endif
3032
3033 #if IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1
3034 // if SAMSUNG32 protocol and the code will be repeated within 50 ms, we will ignore every 2nd frame
3035 if (irmp_param.protocol == IRMP_SAMSUNG32_PROTOCOL && (repetition_frame_number & 0x01))
3036 {
3037 ANALYZE_PRINTF ("code skipped: SAMSUNG32 auto repetition frame #%d, counter = %d, auto repetition len = %d\n",
3038 repetition_frame_number + 1, repetition_len, AUTO_FRAME_REPETITION_LEN);
3039 repetition_len = 0;
3040 }
3041 else
3042 #endif
3043
3044 #if IRMP_SUPPORT_NUBERT_PROTOCOL == 1
3045 // if NUBERT protocol and the code will be repeated within 50 ms, we will ignore every 2nd frame
3046 if (irmp_param.protocol == IRMP_NUBERT_PROTOCOL && (repetition_frame_number & 0x01))
3047 {
3048 ANALYZE_PRINTF ("code skipped: NUBERT auto repetition frame #%d, counter = %d, auto repetition len = %d\n",
3049 repetition_frame_number + 1, repetition_len, AUTO_FRAME_REPETITION_LEN);
3050 repetition_len = 0;
3051 }
3052 else
3053 #endif
3054
3055 {
3056 ANALYZE_PRINTF ("%8.3fms code detected, length = %d\n", (double) (time_counter * 1000) / F_INTERRUPTS, irmp_bit);
3057 irmp_ir_detected = TRUE;
3058
3059 #if IRMP_SUPPORT_DENON_PROTOCOL == 1
3060 if (irmp_param.protocol == IRMP_DENON_PROTOCOL)
3061 { // check for repetition frame
3062 if ((~irmp_tmp_command & 0x3FF) == last_irmp_denon_command) // command bits must be inverted
3063 {
3064 irmp_tmp_command = last_irmp_denon_command; // use command received before!
3065 last_irmp_denon_command = 0;
3066
3067 irmp_protocol = irmp_param.protocol; // store protocol
3068 irmp_address = irmp_tmp_address; // store address
3069 irmp_command = irmp_tmp_command ; // store command
3070 }
3071 else
3072 {
3073 ANALYZE_PRINTF ("%8.3fms waiting for inverted command repetition\n", (double) (time_counter * 1000) / F_INTERRUPTS);
3074 irmp_ir_detected = FALSE;
3075 last_irmp_denon_command = irmp_tmp_command;
3076 repetition_len = 0;
3077 }
3078 }
3079 else
3080 #endif // IRMP_SUPPORT_DENON_PROTOCOL
3081
3082 #if IRMP_SUPPORT_GRUNDIG_PROTOCOL == 1
3083 if (irmp_param.protocol == IRMP_GRUNDIG_PROTOCOL && irmp_tmp_command == 0x01ff)
3084 { // Grundig start frame?
3085 ANALYZE_PRINTF ("Detected GRUNDIG start frame, ignoring it\n");
3086 irmp_ir_detected = FALSE;
3087 }
3088 else
3089 #endif // IRMP_SUPPORT_GRUNDIG_PROTOCOL
3090
3091 #if IRMP_SUPPORT_NOKIA_PROTOCOL == 1
3092 if (irmp_param.protocol == IRMP_NOKIA_PROTOCOL && irmp_tmp_address == 0x00ff && irmp_tmp_command == 0x00fe)
3093 { // Nokia start frame?
3094 ANALYZE_PRINTF ("Detected NOKIA start frame, ignoring it\n");
3095 irmp_ir_detected = FALSE;
3096 }
3097 else
3098 #endif // IRMP_SUPPORT_NOKIA_PROTOCOL
3099 {
3100 #if IRMP_SUPPORT_NEC_PROTOCOL == 1
3101 if (irmp_param.protocol == IRMP_NEC_PROTOCOL && irmp_bit == 0) // repetition frame
3102 {
3103 if (repetition_len < NEC_FRAME_REPEAT_PAUSE_LEN_MAX)
3104 {
3105 ANALYZE_PRINTF ("Detected NEC repetition frame, repetition_len = %d\n", repetition_len);
3106 irmp_tmp_address = last_irmp_address; // address is last address
3107 irmp_tmp_command = last_irmp_command; // command is last command
3108 irmp_flags |= IRMP_FLAG_REPETITION;
3109 repetition_len = 0;
3110 }
3111 else
3112 {
3113 ANALYZE_PRINTF ("Detected NEC repetition frame, ignoring it: timeout occured, repetition_len = %d > %d\n",
3114 repetition_len, NEC_FRAME_REPEAT_PAUSE_LEN_MAX);
3115 irmp_ir_detected = FALSE;
3116 }
3117 }
3118 #endif // IRMP_SUPPORT_NEC_PROTOCOL
3119
3120 #if IRMP_SUPPORT_KASEIKYO_PROTOCOL == 1
3121 if (irmp_param.protocol == IRMP_KASEIKYO_PROTOCOL)
3122 {
3123 uint8_t xor_value;
3124 // ANALYZE_PRINTF ("0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
3125 // xor_check[0], xor_check[1], xor_check[2], xor_check[3], xor_check[4], xor_check[5]);
3126
3127 xor_value = (xor_check[0] & 0x0F) ^ ((xor_check[0] & 0xF0) >> 4) ^ (xor_check[1] & 0x0F) ^ ((xor_check[1] & 0xF0) >> 4);
3128
3129 if (xor_value != (xor_check[2] & 0x0F))
3130 {
3131 ANALYZE_PRINTF ("error 4: wrong XOR check for customer id: 0x%1x 0x%1x\n", xor_value, xor_check[2] & 0x0F);
3132 irmp_ir_detected = FALSE;
3133 }
3134
3135 xor_value = xor_check[2] ^ xor_check[3] ^ xor_check[4];
3136
3137 if (xor_value != xor_check[5])
3138 {
3139 ANALYZE_PRINTF ("error 5: wrong XOR check for data bits: 0x%02x 0x%02x\n", xor_value, xor_check[5]);
3140 irmp_ir_detected = FALSE;
3141 }
3142
3143 irmp_flags |= genre2; // write the genre2 bits into MSB of the flag byte
3144 }
3145 #endif // IRMP_SUPPORT_KASEIKYO_PROTOCOL == 1
3146
3147 #if IRMP_SUPPORT_RC6_PROTOCOL == 1
3148 if (irmp_param.protocol == IRMP_RC6_PROTOCOL && irmp_param.complete_len == RC6_COMPLETE_DATA_LEN_LONG) // RC6 mode = 6?
3149 {
3150 irmp_protocol = IRMP_RC6A_PROTOCOL;
3151 }
3152 else
3153 #endif // IRMP_SUPPORT_RC6_PROTOCOL == 1
3154 {
3155 irmp_protocol = irmp_param.protocol;
3156 }
3157
3158 #if IRMP_SUPPORT_FDC_PROTOCOL == 1
3159 if (irmp_param.protocol == IRMP_FDC_PROTOCOL)
3160 {
3161 if (irmp_tmp_command & 0x000F) // released key?
3162 {
3163 irmp_tmp_command = (irmp_tmp_command >> 4) | 0x80; // yes, set bit 7
3164 }
3165 else
3166 {
3167 irmp_tmp_command >>= 4; // no, it's a pressed key
3168 }
3169 irmp_tmp_command |= (irmp_tmp_address << 2) & 0x0F00; // 000000CCCCAAAAAA -> 0000CCCC00000000
3170 irmp_tmp_address &= 0x003F;
3171 }
3172 #endif
3173
3174 irmp_address = irmp_tmp_address; // store address
3175 #if IRMP_SUPPORT_NEC_PROTOCOL == 1
3176 if (irmp_param.protocol == IRMP_NEC_PROTOCOL)
3177 {
3178 last_irmp_address = irmp_tmp_address; // store as last address, too
3179 }
3180 #endif
3181
3182 #if IRMP_SUPPORT_RC5_PROTOCOL == 1
3183 if (irmp_param.protocol == IRMP_RC5_PROTOCOL)
3184 {
3185 irmp_tmp_command |= rc5_cmd_bit6; // store bit 6
3186 }
3187 #endif
3188 irmp_command = irmp_tmp_command; // store command
3189
3190 #if IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1
3191 irmp_id = irmp_tmp_id;
3192 #endif
3193 }
3194 }
3195
3196 if (irmp_ir_detected)
3197 {
3198 if (last_irmp_command == irmp_tmp_command &&
3199 last_irmp_address == irmp_tmp_address &&
3200 repetition_len < IRMP_KEY_REPETITION_LEN)
3201 {
3202 irmp_flags |= IRMP_FLAG_REPETITION;
3203 }
3204
3205 last_irmp_address = irmp_tmp_address; // store as last address, too
3206 last_irmp_command = irmp_tmp_command; // store as last command, too
3207
3208 repetition_len = 0;
3209 }
3210 else
3211 {
3212 ANALYZE_ONLY_NORMAL_PUTCHAR ('\n');
3213 }
3214
3215 // irmp_busy_flag = FALSE;
3216 irmp_start_bit_detected = 0; // and wait for next start bit
3217 irmp_tmp_command = 0;
3218 irmp_pulse_time = 0;
3219 irmp_pause_time = 0;
3220
3221 #if IRMP_SUPPORT_JVC_PROTOCOL == 1
3222 if (irmp_protocol == IRMP_JVC_PROTOCOL) // the stop bit of JVC frame is also start bit of next frame
3223 { // set pulse time here!
3224 irmp_pulse_time = ((uint8_t)(F_INTERRUPTS * JVC_START_BIT_PULSE_TIME));
3225 }
3226 #endif // IRMP_SUPPORT_JVC_PROTOCOL == 1
3227 }
3228 }
3229 }
3230 return (irmp_ir_detected);
3231 }
3232
3233 #ifdef ANALYZE
3234
3235 /*---------------------------------------------------------------------------------------------------------------------------------------------------
3236 * main functions - for Unix/Linux + Windows only!
3237 *
3238 * AVR: see main.c!
3239 *
3240 * Compile it under linux with:
3241 * cc irmp.c -o irmp
3242 *
3243 * usage: ./irmp [-v|-s|-a|-l|-p] < file
3244 *
3245 * options:
3246 * -v verbose
3247 * -s silent
3248 * -a analyze
3249 * -l list pulse/pauses
3250 * -p print timings
3251 *---------------------------------------------------------------------------------------------------------------------------------------------------
3252 */
3253
3254 static void
3255 print_timings (void)
3256 {
3257 printf ("IRMP_TIMEOUT_LEN: %d [%d byte(s)]\n", IRMP_TIMEOUT_LEN, sizeof (PAUSE_LEN));
3258 printf ("IRMP_KEY_REPETITION_LEN %d\n", IRMP_KEY_REPETITION_LEN);
3259 puts ("");
3260 printf ("PROTOCOL S S-PULSE S-PAUSE PULSE-0 PAUSE-0 PULSE-1 PAUSE-1\n");
3261 printf ("====================================================================================\n");
3262 printf ("SIRCS 1 %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n",
3263 SIRCS_START_BIT_PULSE_LEN_MIN, SIRCS_START_BIT_PULSE_LEN_MAX, SIRCS_START_BIT_PAUSE_LEN_MIN, SIRCS_START_BIT_PAUSE_LEN_MAX,
3264 SIRCS_0_PULSE_LEN_MIN, SIRCS_0_PULSE_LEN_MAX, SIRCS_PAUSE_LEN_MIN, SIRCS_PAUSE_LEN_MAX,
3265 SIRCS_1_PULSE_LEN_MIN, SIRCS_1_PULSE_LEN_MAX, SIRCS_PAUSE_LEN_MIN, SIRCS_PAUSE_LEN_MAX);
3266
3267 printf ("NEC 1 %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n",
3268 NEC_START_BIT_PULSE_LEN_MIN, NEC_START_BIT_PULSE_LEN_MAX, NEC_START_BIT_PAUSE_LEN_MIN, NEC_START_BIT_PAUSE_LEN_MAX,
3269 NEC_PULSE_LEN_MIN, NEC_PULSE_LEN_MAX, NEC_0_PAUSE_LEN_MIN, NEC_0_PAUSE_LEN_MAX,
3270 NEC_PULSE_LEN_MIN, NEC_PULSE_LEN_MAX, NEC_1_PAUSE_LEN_MIN, NEC_1_PAUSE_LEN_MAX);
3271
3272 printf ("NEC (rep) 1 %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n",
3273 NEC_START_BIT_PULSE_LEN_MIN, NEC_START_BIT_PULSE_LEN_MAX, NEC_REPEAT_START_BIT_PAUSE_LEN_MIN, NEC_REPEAT_START_BIT_PAUSE_LEN_MAX,
3274 NEC_PULSE_LEN_MIN, NEC_PULSE_LEN_MAX, NEC_0_PAUSE_LEN_MIN, NEC_0_PAUSE_LEN_MAX,
3275 NEC_PULSE_LEN_MIN, NEC_PULSE_LEN_MAX, NEC_1_PAUSE_LEN_MIN, NEC_1_PAUSE_LEN_MAX);
3276
3277 printf ("SAMSUNG 1 %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n",
3278 SAMSUNG_START_BIT_PULSE_LEN_MIN, SAMSUNG_START_BIT_PULSE_LEN_MAX, SAMSUNG_START_BIT_PAUSE_LEN_MIN, SAMSUNG_START_BIT_PAUSE_LEN_MAX,
3279 SAMSUNG_PULSE_LEN_MIN, SAMSUNG_PULSE_LEN_MAX, SAMSUNG_0_PAUSE_LEN_MIN, SAMSUNG_0_PAUSE_LEN_MAX,
3280 SAMSUNG_PULSE_LEN_MIN, SAMSUNG_PULSE_LEN_MAX, SAMSUNG_1_PAUSE_LEN_MIN, SAMSUNG_1_PAUSE_LEN_MAX);
3281
3282 printf ("MATSUSHITA 1 %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n",
3283 MATSUSHITA_START_BIT_PULSE_LEN_MIN, MATSUSHITA_START_BIT_PULSE_LEN_MAX, MATSUSHITA_START_BIT_PAUSE_LEN_MIN, MATSUSHITA_START_BIT_PAUSE_LEN_MAX,
3284 MATSUSHITA_PULSE_LEN_MIN, MATSUSHITA_PULSE_LEN_MAX, MATSUSHITA_0_PAUSE_LEN_MIN, MATSUSHITA_0_PAUSE_LEN_MAX,
3285 MATSUSHITA_PULSE_LEN_MIN, MATSUSHITA_PULSE_LEN_MAX, MATSUSHITA_1_PAUSE_LEN_MIN, MATSUSHITA_1_PAUSE_LEN_MAX);
3286
3287 printf ("KASEIKYO 1 %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n",
3288 KASEIKYO_START_BIT_PULSE_LEN_MIN, KASEIKYO_START_BIT_PULSE_LEN_MAX, KASEIKYO_START_BIT_PAUSE_LEN_MIN, KASEIKYO_START_BIT_PAUSE_LEN_MAX,
3289 KASEIKYO_PULSE_LEN_MIN, KASEIKYO_PULSE_LEN_MAX, KASEIKYO_0_PAUSE_LEN_MIN, KASEIKYO_0_PAUSE_LEN_MAX,
3290 KASEIKYO_PULSE_LEN_MIN, KASEIKYO_PULSE_LEN_MAX, KASEIKYO_1_PAUSE_LEN_MIN, KASEIKYO_1_PAUSE_LEN_MAX);
3291
3292 printf ("RECS80 1 %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n",
3293 RECS80_START_BIT_PULSE_LEN_MIN, RECS80_START_BIT_PULSE_LEN_MAX, RECS80_START_BIT_PAUSE_LEN_MIN, RECS80_START_BIT_PAUSE_LEN_MAX,
3294 RECS80_PULSE_LEN_MIN, RECS80_PULSE_LEN_MAX, RECS80_0_PAUSE_LEN_MIN, RECS80_0_PAUSE_LEN_MAX,
3295 RECS80_PULSE_LEN_MIN, RECS80_PULSE_LEN_MAX, RECS80_1_PAUSE_LEN_MIN, RECS80_1_PAUSE_LEN_MAX);
3296
3297 printf ("RC5 1 %3d - %3d %3d - %3d %3d - %3d\n",
3298 RC5_START_BIT_LEN_MIN, RC5_START_BIT_LEN_MAX, RC5_START_BIT_LEN_MIN, RC5_START_BIT_LEN_MAX,
3299 RC5_BIT_LEN_MIN, RC5_BIT_LEN_MAX);
3300
3301 printf ("DENON 1 %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n",
3302 DENON_PULSE_LEN_MIN, DENON_PULSE_LEN_MAX,
3303 DENON_PULSE_LEN_MIN, DENON_PULSE_LEN_MAX, DENON_0_PAUSE_LEN_MIN, DENON_0_PAUSE_LEN_MAX,
3304 DENON_PULSE_LEN_MIN, DENON_PULSE_LEN_MAX, DENON_1_PAUSE_LEN_MIN, DENON_1_PAUSE_LEN_MAX);
3305
3306 printf ("THOMSON 1 %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n",
3307 THOMSON_PULSE_LEN_MIN, THOMSON_PULSE_LEN_MAX,
3308 THOMSON_PULSE_LEN_MIN, THOMSON_PULSE_LEN_MAX, THOMSON_0_PAUSE_LEN_MIN, THOMSON_0_PAUSE_LEN_MAX,
3309 THOMSON_PULSE_LEN_MIN, THOMSON_PULSE_LEN_MAX, THOMSON_1_PAUSE_LEN_MIN, THOMSON_1_PAUSE_LEN_MAX);
3310
3311 printf ("RC6 1 %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n",
3312 RC6_START_BIT_PULSE_LEN_MIN, RC6_START_BIT_PULSE_LEN_MAX, RC6_START_BIT_PAUSE_LEN_MIN, RC6_START_BIT_PAUSE_LEN_MAX,
3313 RC6_BIT_PULSE_LEN_MIN, RC6_BIT_PULSE_LEN_MAX, RC6_BIT_PAUSE_LEN_MIN, RC6_BIT_PAUSE_LEN_MAX);
3314
3315 printf ("RECS80EXT 1 %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n",
3316 RECS80EXT_START_BIT_PULSE_LEN_MIN, RECS80EXT_START_BIT_PULSE_LEN_MAX, RECS80EXT_START_BIT_PAUSE_LEN_MIN, RECS80EXT_START_BIT_PAUSE_LEN_MAX,
3317 RECS80EXT_PULSE_LEN_MIN, RECS80EXT_PULSE_LEN_MAX, RECS80EXT_0_PAUSE_LEN_MIN, RECS80EXT_0_PAUSE_LEN_MAX,
3318 RECS80EXT_PULSE_LEN_MIN, RECS80EXT_PULSE_LEN_MAX, RECS80EXT_1_PAUSE_LEN_MIN, RECS80EXT_1_PAUSE_LEN_MAX);
3319
3320 printf ("NUBERT 1 %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n",
3321 NUBERT_START_BIT_PULSE_LEN_MIN, NUBERT_START_BIT_PULSE_LEN_MAX, NUBERT_START_BIT_PAUSE_LEN_MIN, NUBERT_START_BIT_PAUSE_LEN_MAX,
3322 NUBERT_0_PULSE_LEN_MIN, NUBERT_0_PULSE_LEN_MAX, NUBERT_0_PAUSE_LEN_MIN, NUBERT_0_PAUSE_LEN_MAX,
3323 NUBERT_1_PULSE_LEN_MIN, NUBERT_1_PULSE_LEN_MAX, NUBERT_1_PAUSE_LEN_MIN, NUBERT_1_PAUSE_LEN_MAX);
3324
3325 printf ("BANG_OLUFSEN 1 %3d - %3d %3d - %3d\n",
3326 BANG_OLUFSEN_START_BIT1_PULSE_LEN_MIN, BANG_OLUFSEN_START_BIT1_PULSE_LEN_MAX,
3327 BANG_OLUFSEN_START_BIT1_PAUSE_LEN_MIN, BANG_OLUFSEN_START_BIT1_PAUSE_LEN_MAX);
3328
3329 printf ("BANG_OLUFSEN 2 %3d - %3d %3d - %3d\n",
3330 BANG_OLUFSEN_START_BIT2_PULSE_LEN_MIN, BANG_OLUFSEN_START_BIT2_PULSE_LEN_MAX,
3331 BANG_OLUFSEN_START_BIT2_PAUSE_LEN_MIN, BANG_OLUFSEN_START_BIT2_PAUSE_LEN_MAX);
3332
3333 printf ("BANG_OLUFSEN 3 %3d - %3d %3d - %3d\n",
3334 BANG_OLUFSEN_START_BIT3_PULSE_LEN_MIN, BANG_OLUFSEN_START_BIT3_PULSE_LEN_MAX,
3335 BANG_OLUFSEN_START_BIT3_PAUSE_LEN_MIN, BANG_OLUFSEN_START_BIT3_PAUSE_LEN_MAX);
3336
3337 printf ("BANG_OLUFSEN 4 %3d - %3d %3d - %3d\n",
3338 BANG_OLUFSEN_START_BIT4_PULSE_LEN_MIN, BANG_OLUFSEN_START_BIT4_PULSE_LEN_MAX,
3339 BANG_OLUFSEN_START_BIT4_PAUSE_LEN_MIN, BANG_OLUFSEN_START_BIT4_PAUSE_LEN_MAX);
3340
3341 printf ("BANG_OLUFSEN - %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n",
3342 BANG_OLUFSEN_PULSE_LEN_MIN, BANG_OLUFSEN_PULSE_LEN_MAX, BANG_OLUFSEN_0_PAUSE_LEN_MIN, BANG_OLUFSEN_0_PAUSE_LEN_MAX,
3343 BANG_OLUFSEN_PULSE_LEN_MIN, BANG_OLUFSEN_PULSE_LEN_MAX, BANG_OLUFSEN_1_PAUSE_LEN_MIN, BANG_OLUFSEN_1_PAUSE_LEN_MAX);
3344
3345 printf ("GRUNDIG/NOKIA 1 %3d - %3d %3d - %3d %3d - %3d\n",
3346 GRUNDIG_NOKIA_IR60_START_BIT_LEN_MIN, GRUNDIG_NOKIA_IR60_START_BIT_LEN_MAX,
3347 GRUNDIG_NOKIA_IR60_PRE_PAUSE_LEN_MIN, GRUNDIG_NOKIA_IR60_PRE_PAUSE_LEN_MAX,
3348 GRUNDIG_NOKIA_IR60_BIT_LEN_MIN, GRUNDIG_NOKIA_IR60_BIT_LEN_MAX);
3349
3350 printf ("SIEMENS/RUWIDO 1 %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n",
3351 SIEMENS_OR_RUWIDO_START_BIT_PULSE_LEN_MIN, SIEMENS_OR_RUWIDO_START_BIT_PULSE_LEN_MAX,
3352 SIEMENS_OR_RUWIDO_START_BIT_PAUSE_LEN_MIN, SIEMENS_OR_RUWIDO_START_BIT_PAUSE_LEN_MAX,
3353 SIEMENS_OR_RUWIDO_BIT_PULSE_LEN_MIN, SIEMENS_OR_RUWIDO_BIT_PULSE_LEN_MAX,
3354 SIEMENS_OR_RUWIDO_BIT_PAUSE_LEN_MIN, SIEMENS_OR_RUWIDO_BIT_PAUSE_LEN_MAX,
3355 2 * SIEMENS_OR_RUWIDO_BIT_PULSE_LEN_MIN, 2 * SIEMENS_OR_RUWIDO_BIT_PULSE_LEN_MAX,
3356 2 * SIEMENS_OR_RUWIDO_BIT_PAUSE_LEN_MIN, 2 * SIEMENS_OR_RUWIDO_BIT_PAUSE_LEN_MAX);
3357
3358 printf ("FDC 1 %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n",
3359 FDC_START_BIT_PULSE_LEN_MIN, FDC_START_BIT_PULSE_LEN_MAX, FDC_START_BIT_PAUSE_LEN_MIN, FDC_START_BIT_PAUSE_LEN_MAX,
3360 FDC_PULSE_LEN_MIN, FDC_PULSE_LEN_MAX, FDC_0_PAUSE_LEN_MIN, FDC_0_PAUSE_LEN_MAX,
3361 FDC_PULSE_LEN_MIN, FDC_PULSE_LEN_MAX, FDC_1_PAUSE_LEN_MIN, FDC_1_PAUSE_LEN_MAX);
3362
3363 printf ("RCCAR 1 %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n",
3364 RCCAR_START_BIT_PULSE_LEN_MIN, RCCAR_START_BIT_PULSE_LEN_MAX, RCCAR_START_BIT_PAUSE_LEN_MIN, RCCAR_START_BIT_PAUSE_LEN_MAX,
3365 RCCAR_PULSE_LEN_MIN, RCCAR_PULSE_LEN_MAX, RCCAR_0_PAUSE_LEN_MIN, RCCAR_0_PAUSE_LEN_MAX,
3366 RCCAR_PULSE_LEN_MIN, RCCAR_PULSE_LEN_MAX, RCCAR_1_PAUSE_LEN_MIN, RCCAR_1_PAUSE_LEN_MAX);
3367
3368 printf ("NIKON 1 %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n",
3369 NIKON_START_BIT_PULSE_LEN_MIN, NIKON_START_BIT_PULSE_LEN_MAX, NIKON_START_BIT_PAUSE_LEN_MIN, NIKON_START_BIT_PAUSE_LEN_MAX,
3370 NIKON_PULSE_LEN_MIN, NIKON_PULSE_LEN_MAX, NIKON_0_PAUSE_LEN_MIN, NIKON_0_PAUSE_LEN_MAX,
3371 NIKON_PULSE_LEN_MIN, NIKON_PULSE_LEN_MAX, NIKON_1_PAUSE_LEN_MIN, NIKON_1_PAUSE_LEN_MAX);
3372
3373 printf ("LEGO 1 %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n",
3374 LEGO_START_BIT_PULSE_LEN_MIN, LEGO_START_BIT_PULSE_LEN_MAX, LEGO_START_BIT_PAUSE_LEN_MIN, LEGO_START_BIT_PAUSE_LEN_MAX,
3375 LEGO_PULSE_LEN_MIN, LEGO_PULSE_LEN_MAX, LEGO_0_PAUSE_LEN_MIN, LEGO_0_PAUSE_LEN_MAX,
3376 LEGO_PULSE_LEN_MIN, LEGO_PULSE_LEN_MAX, LEGO_1_PAUSE_LEN_MIN, LEGO_1_PAUSE_LEN_MAX);
3377
3378 }
3379
3380 void
3381 print_spectrum (char * text, int * buf, int is_pulse)
3382 {
3383 int i;
3384 int j;
3385 int min;
3386 int max;
3387 int max_value = 0;
3388 int value;
3389 int sum = 0;
3390 int counter = 0;
3391 double average = 0;
3392 double tolerance;
3393
3394 puts ("-------------------------------------------------------------------------------");
3395 printf ("%s:\n", text);
3396
3397 for (i = 0; i < 256; i++)
3398 {
3399 if (buf[i] > max_value)
3400 {
3401 max_value = buf[i];
3402 }
3403 }
3404
3405 for (i = 1; i < 100; i++)
3406 {
3407 if (buf[i] > 0)
3408 {
3409 printf ("%3d ", i);
3410 value = (buf[i] * 60) / max_value;
3411
3412 for (j = 0; j < value; j++)
3413 {
3414 putchar ('o');
3415 }
3416 printf (" %d\n", buf[i]);
3417
3418 sum += i * buf[i];
3419 counter += buf[i];
3420 }
3421 else
3422 {
3423 max = i - 1;
3424
3425 if (counter > 0)
3426 {
3427 average = (float) sum / (float) counter;
3428
3429 if (is_pulse)
3430 {
3431 printf ("pulse ");
3432 }
3433 else
3434 {
3435 printf ("pause ");
3436 }
3437
3438 printf ("avg: %4.1f=%6.1f us, ", average, (1000000. * average) / (float) F_INTERRUPTS);
3439 printf ("min: %2d=%6.1f us, ", min, (1000000. * min) / (float) F_INTERRUPTS);
3440 printf ("max: %2d=%6.1f us, ", max, (1000000. * max) / (float) F_INTERRUPTS);
3441
3442 tolerance = (max - average);
3443
3444 if (average - min > tolerance)
3445 {
3446 tolerance = average - min;
3447 }
3448
3449 tolerance = tolerance * 100 / average;
3450 printf ("tol: %4.1f%%\n", tolerance);
3451 }
3452
3453 counter = 0;
3454 sum = 0;
3455 min = i + 1;
3456 }
3457 }
3458 }
3459
3460 #define STATE_LEFT_SHIFT 0x01
3461 #define STATE_RIGHT_SHIFT 0x02
3462 #define STATE_LEFT_CTRL 0x04
3463 #define STATE_LEFT_ALT 0x08
3464 #define STATE_RIGHT_ALT 0x10
3465
3466 #define KEY_ESCAPE 0x1B // keycode = 0x006e
3467 #define KEY_MENUE 0x80 // keycode = 0x0070
3468 #define KEY_BACK 0x81 // keycode = 0x0071
3469 #define KEY_FORWARD 0x82 // keycode = 0x0072
3470 #define KEY_ADDRESS 0x83 // keycode = 0x0073
3471 #define KEY_WINDOW 0x84 // keycode = 0x0074
3472 #define KEY_1ST_PAGE 0x85 // keycode = 0x0075
3473 #define KEY_STOP 0x86 // keycode = 0x0076
3474 #define KEY_MAIL 0x87 // keycode = 0x0077
3475 #define KEY_FAVORITES 0x88 // keycode = 0x0078
3476 #define KEY_NEW_PAGE 0x89 // keycode = 0x0079
3477 #define KEY_SETUP 0x8A // keycode = 0x007a
3478 #define KEY_FONT 0x8B // keycode = 0x007b
3479 #define KEY_PRINT 0x8C // keycode = 0x007c
3480 #define KEY_ON_OFF 0x8E // keycode = 0x007c
3481
3482 #define KEY_INSERT 0x90 // keycode = 0x004b
3483 #define KEY_DELETE 0x91 // keycode = 0x004c
3484 #define KEY_LEFT 0x92 // keycode = 0x004f
3485 #define KEY_HOME 0x93 // keycode = 0x0050
3486 #define KEY_END 0x94 // keycode = 0x0051
3487 #define KEY_UP 0x95 // keycode = 0x0053
3488 #define KEY_DOWN 0x96 // keycode = 0x0054
3489 #define KEY_PAGE_UP 0x97 // keycode = 0x0055
3490 #define KEY_PAGE_DOWN 0x98 // keycode = 0x0056
3491 #define KEY_RIGHT 0x99 // keycode = 0x0059
3492 #define KEY_MOUSE_1 0x9E // keycode = 0x0400
3493 #define KEY_MOUSE_2 0x9F // keycode = 0x0800
3494
3495 static uint8_t
3496 get_fdc_key (uint16_t cmd)
3497 {
3498 static uint8_t key_table[128] =
3499 {
3500 // 0 1 2 3 4 5 6 7 8 9 A B C D E F
3501 0, '^', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', 'ß', '´', 0, '\b',
3502 '\t','q', 'w', 'e', 'r', 't', 'z', 'u', 'i', 'o', 'p', 'ü', '+', 0, 0, 'a',
3503 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'ö', 'ä', '#', '\r', 0, '<', 'y', 'x',
3504 'c', 'v', 'b', 'n', 'm', ',', '.', '-', 0, 0, 0, 0, 0, ' ', 0, 0,
3505
3506 0, '°', '!', '"', '§', '$', '%', '&', '/', '(', ')', '=', '?', '`', 0, '\b',
3507 '\t','Q', 'W', 'E', 'R', 'T', 'Z', 'U', 'I', 'O', 'P', 'Ü', '*', 0, 0, 'A',
3508 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'Ö', 'Ä', '\'','\r', 0, '>', 'Y', 'X',
3509 'C', 'V', 'B', 'N', 'M', ';', ':', '_', 0, 0, 0, 0, 0, ' ', 0, 0
3510 };
3511 static uint8_t state;
3512
3513 uint8_t key = 0;
3514
3515 switch (cmd)
3516 {
3517 case 0x002C: state |= STATE_LEFT_SHIFT; break; // pressed left shift
3518 case 0x00AC: state &= ~STATE_LEFT_SHIFT; break; // released left shift
3519 case 0x0039: state |= STATE_RIGHT_SHIFT; break; // pressed right shift
3520 case 0x00B9: state &= ~STATE_RIGHT_SHIFT; break; // released right shift
3521 case 0x003A: state |= STATE_LEFT_CTRL; break; // pressed left ctrl
3522 case 0x00BA: state &= ~STATE_LEFT_CTRL; break; // released left ctrl
3523 case 0x003C: state |= STATE_LEFT_ALT; break; // pressed left alt
3524 case 0x00BC: state &= ~STATE_LEFT_ALT; break; // released left alt
3525 case 0x003E: state |= STATE_RIGHT_ALT; break; // pressed left alt
3526 case 0x00BE: state &= ~STATE_RIGHT_ALT; break; // released left alt
3527
3528 case 0x006e: key = KEY_ESCAPE; break;
3529 case 0x004b: key = KEY_INSERT; break;
3530 case 0x004c: key = KEY_DELETE; break;
3531 case 0x004f: key = KEY_LEFT; break;
3532 case 0x0050: key = KEY_HOME; break;
3533 case 0x0051: key = KEY_END; break;
3534 case 0x0053: key = KEY_UP; break;
3535 case 0x0054: key = KEY_DOWN; break;
3536 case 0x0055: key = KEY_PAGE_UP; break;
3537 case 0x0056: key = KEY_PAGE_DOWN; break;
3538 case 0x0059: key = KEY_RIGHT; break;
3539 case 0x0400: key = KEY_MOUSE_1; break;
3540 case 0x0800: key = KEY_MOUSE_2; break;
3541
3542 default:
3543 {
3544 if (!(cmd & 0x80)) // pressed key
3545 {
3546 if (cmd >= 0x70 && cmd <= 0x7F) // function keys
3547 {
3548 key = cmd + 0x10; // 7x -> 8x
3549 }
3550 else if (cmd < 64) // key listed in key_table
3551 {
3552 if (state & (STATE_LEFT_ALT | STATE_RIGHT_ALT))
3553 {
3554 switch (cmd)
3555 {
3556 case 0x0003: key = '²'; break;
3557 case 0x0008: key = '{'; break;
3558 case 0x0009: key = '['; break;
3559 case 0x000A: key = ']'; break;
3560 case 0x000B: key = '}'; break;
3561 case 0x000C: key = '\\'; break;
3562 case 0x001C: key = '~'; break;
3563 case 0x002D: key = '|'; break;
3564 case 0x0034: key = 0xB5; break; // Mu
3565 }
3566 }
3567 else if (state & (STATE_LEFT_CTRL))
3568 {
3569 if (key_table[cmd] >= 'a' && key_table[cmd] <= 'z')
3570 {
3571 key = key_table[cmd] - 'a' + 1;
3572 }
3573 else
3574 {
3575 key = key_table[cmd];
3576 }
3577 }
3578 else
3579 {
3580 int idx = cmd + ((state & (STATE_LEFT_SHIFT | STATE_RIGHT_SHIFT)) ? 64 : 0);
3581
3582 if (key_table[idx])
3583 {
3584 key = key_table[idx];
3585 }
3586 }
3587 }
3588 }
3589 break;
3590 }
3591 }
3592
3593 return (key);
3594 }
3595
3596 static int analyze = FALSE;
3597 static int list = FALSE;
3598 static IRMP_DATA irmp_data;
3599
3600 static void
3601 next_tick (void)
3602 {
3603 if (! analyze && ! list)
3604 {
3605 (void) irmp_ISR ();
3606
3607 if (irmp_get_data (&irmp_data))
3608 {
3609 uint8_t key;
3610
3611 ANALYZE_ONLY_NORMAL_PUTCHAR (' ');
3612
3613 if (verbose)
3614 {
3615 printf ("%8.3fms ", (double) (time_counter * 1000) / F_INTERRUPTS);
3616 }
3617
3618 if (irmp_data.protocol == IRMP_FDC_PROTOCOL && (key = get_fdc_key (irmp_data.command)) != 0)
3619 {
3620 if ((key >= 0x20 && key < 0x7F) || key >= 0xA0)
3621 {
3622 printf ("p = %2d, a = 0x%04x, c = 0x%04x, f = 0x%02x, asc = 0x%02x, key = '%c'\n",
3623 irmp_data.protocol, irmp_data.address, irmp_data.command, irmp_data.flags, key, key);
3624 }
3625 else if (key == '\r' || key == '\t' || key == KEY_ESCAPE || (key >= 0x80 && key <= 0x9F)) // function keys
3626 {
3627 char * p = (char *) NULL;
3628
3629 switch (key)
3630 {
3631 case '\t' : p = "TAB"; break;
3632 case '\r' : p = "CR"; break;
3633 case KEY_ESCAPE : p = "ESCAPE"; break;
3634 case KEY_MENUE : p = "MENUE"; break;
3635 case KEY_BACK : p = "BACK"; break;
3636 case KEY_FORWARD : p = "FORWARD"; break;
3637 case KEY_ADDRESS : p = "ADDRESS"; break;
3638 case KEY_WINDOW : p = "WINDOW"; break;
3639 case KEY_1ST_PAGE : p = "1ST_PAGE"; break;
3640 case KEY_STOP : p = "STOP"; break;
3641 case KEY_MAIL : p = "MAIL"; break;
3642 case KEY_FAVORITES : p = "FAVORITES"; break;
3643 case KEY_NEW_PAGE : p = "NEW_PAGE"; break;
3644 case KEY_SETUP : p = "SETUP"; break;
3645 case KEY_FONT : p = "FONT"; break;
3646 case KEY_PRINT : p = "PRINT"; break;
3647 case KEY_ON_OFF : p = "ON_OFF"; break;
3648
3649 case KEY_INSERT : p = "INSERT"; break;
3650 case KEY_DELETE : p = "DELETE"; break;
3651 case KEY_LEFT : p = "LEFT"; break;
3652 case KEY_HOME : p = "HOME"; break;
3653 case KEY_END : p = "END"; break;
3654 case KEY_UP : p = "UP"; break;
3655 case KEY_DOWN : p = "DOWN"; break;
3656 case KEY_PAGE_UP : p = "PAGE_UP"; break;
3657 case KEY_PAGE_DOWN : p = "PAGE_DOWN"; break;
3658 case KEY_RIGHT : p = "RIGHT"; break;
3659 case KEY_MOUSE_1 : p = "KEY_MOUSE_1"; break;
3660 case KEY_MOUSE_2 : p = "KEY_MOUSE_2"; break;
3661 default : p = "<UNKNWON>"; break;
3662 }
3663
3664 printf ("p = %2d, a = 0x%04x, c = 0x%04x, f = 0x%02x, asc = 0x%02x, key = %s\n",
3665 irmp_data.protocol, irmp_data.address, irmp_data.command, irmp_data.flags, key, p);
3666 }
3667 else
3668 {
3669 printf ("p = %2d, a = 0x%04x, c = 0x%04x, f = 0x%02x, asc = 0x%02x\n",
3670 irmp_data.protocol, irmp_data.address, irmp_data.command, irmp_data.flags, key);
3671 }
3672 }
3673 else
3674 {
3675 printf ("p = %2d, a = 0x%04x, c = 0x%04x, f = 0x%02x\n",
3676 irmp_data.protocol, irmp_data.address, irmp_data.command, irmp_data.flags);
3677 }
3678 }
3679 }
3680 }
3681
3682 int
3683 main (int argc, char ** argv)
3684 {
3685 int i;
3686 int ch;
3687 int last_ch = 0;
3688 int pulse = 0;
3689 int pause = 0;
3690
3691 int start_pulses[256];
3692 int start_pauses[256];
3693 int pulses[256];
3694 int pauses[256];
3695
3696 int first_pulse = TRUE;
3697 int first_pause = TRUE;
3698
3699 if (argc == 2)
3700 {
3701 if (! strcmp (argv[1], "-v"))
3702 {
3703 verbose = TRUE;
3704 }
3705 else if (! strcmp (argv[1], "-l"))
3706 {
3707 list = TRUE;
3708 }
3709 else if (! strcmp (argv[1], "-a"))
3710 {
3711 analyze = TRUE;
3712 }
3713 else if (! strcmp (argv[1], "-s"))
3714 {
3715 silent = TRUE;
3716 }
3717 else if (! strcmp (argv[1], "-p"))
3718 {
3719 print_timings ();
3720 return (0);
3721 }
3722 }
3723
3724 for (i = 0; i < 256; i++)
3725 {
3726 start_pulses[i] = 0;
3727 start_pauses[i] = 0;
3728 pulses[i] = 0;
3729 pauses[i] = 0;
3730 }
3731
3732 IRMP_PIN = 0xFF;
3733
3734 while ((ch = getchar ()) != EOF)
3735 {
3736 if (ch == '_' || ch == '0')
3737 {
3738 if (last_ch != ch)
3739 {
3740 if (pause > 0)
3741 {
3742 if (list)
3743 {
3744 printf ("pause: %d\n", pause);
3745 }
3746
3747 if (analyze)
3748 {
3749 if (first_pause)
3750 {
3751 if (pause < 256)
3752 {
3753 start_pauses[pause]++;
3754 }
3755 first_pause = FALSE;
3756 }
3757 else
3758 {
3759 if (pause < 256)
3760 {
3761 pauses[pause]++;
3762 }
3763 }
3764 }
3765 }
3766 pause = 0;
3767 }
3768 pulse++;
3769 IRMP_PIN = 0x00;
3770 }
3771 else if (ch == 0xaf || ch == '-' || ch == '1')
3772 {
3773 if (last_ch != ch)
3774 {
3775 if (list)
3776 {
3777 printf ("pulse: %d ", pulse);
3778 }
3779
3780 if (analyze)
3781 {
3782 if (first_pulse)
3783 {
3784 if (pulse < 256)
3785 {
3786 start_pulses[pulse]++;
3787 }
3788 first_pulse = FALSE;
3789 }
3790 else
3791 {
3792 if (pulse < 256)
3793 {
3794 pulses[pulse]++;
3795 }
3796 }
3797 }
3798 pulse = 0;
3799 }
3800
3801 pause++;
3802 IRMP_PIN = 0xff;
3803 }
3804 else if (ch == '\n')
3805 {
3806 IRMP_PIN = 0xff;
3807
3808 if (list && pause > 0)
3809 {
3810 printf ("pause: %d\n", pause);
3811 }
3812 pause = 0;
3813
3814 if (! analyze)
3815 {
3816 for (i = 0; i < (int) ((10000.0 * F_INTERRUPTS) / 10000); i++) // newline: long pause of 10000 msec
3817 {
3818 next_tick ();
3819 }
3820 }
3821 first_pulse = TRUE;
3822 first_pause = TRUE;
3823 }
3824 else if (ch == '#')
3825 {
3826 if (analyze)
3827 {
3828 while ((ch = getchar()) != '\n' && ch != EOF)
3829 {
3830 ;
3831 }
3832 }
3833 else
3834 {
3835 puts ("-------------------------------------------------------------------");
3836 putchar (ch);
3837
3838 while ((ch = getchar()) != '\n' && ch != EOF)
3839 {
3840 if (ch != '\r') // ignore CR in DOS/Windows files
3841 {
3842 putchar (ch);
3843 }
3844 }
3845 putchar ('\n');
3846 }
3847
3848 }
3849
3850 last_ch = ch;
3851
3852 next_tick ();
3853 }
3854
3855 if (analyze)
3856 {
3857 print_spectrum ("START PULSES", start_pulses, TRUE);
3858 print_spectrum ("START PAUSES", start_pauses, FALSE);
3859 print_spectrum ("PULSES", pulses, TRUE);
3860 print_spectrum ("PAUSES", pauses, FALSE);
3861 puts ("-------------------------------------------------------------------------------");
3862 }
3863 return 0;
3864 }
3865
3866 #endif // ANALYZE