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