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