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