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