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