LIRC libraries: /tmp/work/src/lirc-0.10.2/lib/ir_remote.h Source File

LIRC libraries Linux Infrared Remote Control

Loading...
Searching...
No Matches
ir_remote.h
Go to the documentation of this file.
1/****************************************************************************
2** ir_remote.h *************************************************************
3****************************************************************************
4*
5* ir_remote.h - describes and decodes the signals from IR remotes
6*
7* Copyright (C) 1996,97 Ralph Metzler <rjkm@thp.uni-koeln.de>
8* Copyright (C) 1998 Christoph Bartelmus <lirc@bartelmus.de>
9*
10*/
21#ifndef IR_REMOTE_H
22#define IR_REMOTE_H
23
24#include <sys/types.h>
25#include <sys/time.h>
26#include <unistd.h>
27#include <string.h>
28#include <math.h>
29#include <stdlib.h>
30
31#include "driver.h"
32
33#include "ir_remote_types.h"
34
35#ifdef __cplusplus
36extern "C" {
37#endif
38
39
41struct ir_ncode* ncode_dup(struct ir_ncode* ncode);
42
44void ncode_free(struct ir_ncode* ncode);
45
46
50extern struct ir_remote* last_remote;
51
52
57extern struct ir_remote* repeat_remote;
58
62extern struct ir_ncode* repeat_code;
63
64
65static inline ir_code get_ir_code(const struct ir_ncode* ncode,
66 const struct ir_code_node* node)
67{
68 if (ncode->next && node != NULL)
69 return node->code;
70 return ncode->code;
71}
72
73static inline struct ir_code_node*
74get_next_ir_code_node(const struct ir_ncode* ncode,
75 const struct ir_code_node* node)
76{
77 if (node == NULL)
78 return ncode->next;
79 return node->next;
80}
81
82static inline int bit_count(const struct ir_remote* remote)
83{
84 return remote->pre_data_bits + remote->bits + remote->post_data_bits;
85}
86
87static inline int bits_set(ir_code data)
88{
89 int ret = 0;
90
91 while (data) {
92 if (data & 1)
93 ret++;
94 data >>= 1;
95 }
96 return ret;
97}
98
99static inline ir_code reverse(ir_code data, int bits)
100{
101 int i;
102 ir_code c;
103
104 c = 0;
105 for (i = 0; i < bits; i++)
106 c |= (ir_code)(((data & (((ir_code)1) << i)) ? 1 : 0))
107 << (bits - 1 - i);
108 return c;
109}
110
111static inline int is_pulse(lirc_t data)
112{
113 return ((data & LIRC_MODE2_MASK)==LIRC_MODE2_PULSE) ? 1 : 0;
114}
115
116static inline int is_space(lirc_t data)
117{
118 return ((data & LIRC_MODE2_MASK)==LIRC_MODE2_SPACE) ? 1 : 0;
119}
120
121static inline int is_timeout(lirc_t data)
122{
123 return ((data & LIRC_MODE2_MASK)==LIRC_MODE2_TIMEOUT) ? 1 : 0;
124}
125
126static inline int is_overflow(lirc_t data)
127{
128 return ((data & LIRC_MODE2_MASK)==LIRC_MODE2_OVERFLOW) ? 1 : 0;
129}
130
131static inline int has_repeat(const struct ir_remote* remote)
132{
133 if (remote->prepeat > 0 && remote->srepeat > 0)
134 return 1;
135 else
136 return 0;
137}
138
139static inline void set_protocol(struct ir_remote* remote, int protocol)
140{
141 remote->flags &= ~(IR_PROTOCOL_MASK);
142 remote->flags |= protocol;
143}
144
145static inline int is_raw(const struct ir_remote* remote)
146{
147 if ((remote->flags & IR_PROTOCOL_MASK) == RAW_CODES)
148 return 1;
149 else
150 return 0;
151}
152
153static inline int is_space_enc(const struct ir_remote* remote)
154{
155 if ((remote->flags & IR_PROTOCOL_MASK) == SPACE_ENC)
156 return 1;
157 else
158 return 0;
159}
160
161static inline int is_space_first(const struct ir_remote* remote)
162{
163 if ((remote->flags & IR_PROTOCOL_MASK) == SPACE_FIRST)
164 return 1;
165 else
166 return 0;
167}
168
169static inline int is_rc5(const struct ir_remote* remote)
170{
171 if ((remote->flags & IR_PROTOCOL_MASK) == RC5)
172 return 1;
173 else
174 return 0;
175}
176
177static inline int is_rc6(const struct ir_remote* remote)
178{
179 if ((remote->flags & IR_PROTOCOL_MASK) == RC6 || remote->rc6_mask)
180 return 1;
181 else
182 return 0;
183}
184
185static inline int is_biphase(const struct ir_remote* remote)
186{
187 if (is_rc5(remote) || is_rc6(remote))
188 return 1;
189 else
190 return 0;
191}
192
193static inline int is_rcmm(const struct ir_remote* remote)
194{
195 if ((remote->flags & IR_PROTOCOL_MASK) == RCMM)
196 return 1;
197 else
198 return 0;
199}
200
201static inline int is_grundig(const struct ir_remote* remote)
202{
203 if ((remote->flags & IR_PROTOCOL_MASK) == GRUNDIG)
204 return 1;
205 else
206 return 0;
207}
208
209static inline int is_bo(const struct ir_remote* remote)
210{
211 if ((remote->flags & IR_PROTOCOL_MASK) == BO)
212 return 1;
213 else
214 return 0;
215}
216
217static inline int is_serial(const struct ir_remote* remote)
218{
219 if ((remote->flags & IR_PROTOCOL_MASK) == SERIAL)
220 return 1;
221 else
222 return 0;
223}
224
225static inline int is_xmp(const struct ir_remote* remote)
226{
227 if ((remote->flags & IR_PROTOCOL_MASK) == XMP)
228 return 1;
229 else
230 return 0;
231}
232
233static inline int is_const(const struct ir_remote* remote)
234{
235 if (remote->flags & CONST_LENGTH)
236 return 1;
237 else
238 return 0;
239}
240
241static inline int has_repeat_gap(const struct ir_remote* remote)
242{
243 if (remote->repeat_gap > 0)
244 return 1;
245 else
246 return 0;
247}
248
249static inline int has_pre(const struct ir_remote* remote)
250{
251 if (remote->pre_data_bits > 0)
252 return 1;
253 else
254 return 0;
255}
256
257static inline int has_post(const struct ir_remote* remote)
258{
259 if (remote->post_data_bits > 0)
260 return 1;
261 else
262 return 0;
263}
264
265static inline int has_header(const struct ir_remote* remote)
266{
267 if (remote->phead > 0 && remote->shead > 0)
268 return 1;
269 else
270 return 0;
271}
272
273static inline int has_foot(const struct ir_remote* remote)
274{
275 if (remote->pfoot > 0 && remote->sfoot > 0)
276 return 1;
277 else
278 return 0;
279}
280
281static inline int has_toggle_bit_mask(const struct ir_remote* remote)
282{
283 if (remote->toggle_bit_mask > 0)
284 return 1;
285 else
286 return 0;
287}
288
289static inline int has_ignore_mask(const struct ir_remote* remote)
290{
291 if (remote->ignore_mask > 0)
292 return 1;
293 else
294 return 0;
295}
296
297static inline int has_repeat_mask(struct ir_remote* remote)
298{
299 if (remote->repeat_mask > 0)
300 return 1;
301 else
302 return 0;
303}
304
305static inline int has_toggle_mask(const struct ir_remote* remote)
306{
307 if (remote->toggle_mask > 0)
308 return 1;
309 else
310 return 0;
311}
312
313static inline lirc_t min_gap(const struct ir_remote* remote)
314{
315 if (remote->gap2 != 0 && remote->gap2 < remote->gap)
316 return remote->gap2;
317 else
318 return remote->gap;
319}
320
321static inline lirc_t max_gap(const struct ir_remote* remote)
322{
323 if (remote->gap2 > remote->gap)
324 return remote->gap2;
325 else
326 return remote->gap;
327}
328
329static inline unsigned int get_duty_cycle(const struct ir_remote* remote)
330{
331 if (remote->duty_cycle == 0)
332 return 50;
333 else if (remote->duty_cycle < 0)
334 return 1;
335 else if (remote->duty_cycle > 100)
336 return 100;
337 else
338 return remote->duty_cycle;
339}
340
341/* check if delta is inside exdelta +/- exdelta*eps/100 */
342
343static inline int expect(const struct ir_remote* remote,
344 lirc_t delta,
345 lirc_t exdelta)
346{
347 int aeps = curr_driver->resolution > remote->aeps ?
348 curr_driver->resolution : remote->aeps;
349
350 if (abs(exdelta - delta) <= exdelta * remote->eps / 100
351 || abs(exdelta - delta) <= aeps)
352 return 1;
353 return 0;
354}
355
356static inline int expect_at_least(const struct ir_remote* remote,
357 lirc_t delta,
358 lirc_t exdelta)
359{
360 int aeps = curr_driver->resolution > remote->aeps ?
361 curr_driver->resolution : remote->aeps;
362
363 if (delta + exdelta * remote->eps / 100 >= exdelta
364 || delta + aeps >= exdelta)
365 return 1;
366 return 0;
367}
368
369static inline int expect_at_most(const struct ir_remote* remote,
370 lirc_t delta,
371 lirc_t exdelta)
372{
373 int aeps = curr_driver->resolution > remote->aeps ?
374 curr_driver->resolution : remote->aeps;
375
376 if (delta <= exdelta + exdelta * remote->eps / 100
377 || delta <= exdelta + aeps)
378 return 1;
379 return 0;
380}
381
382static inline lirc_t upper_limit(const struct ir_remote* remote, lirc_t val)
383{
384 int aeps = curr_driver->resolution > remote->aeps ?
385 curr_driver->resolution : remote->aeps;
386 lirc_t eps_val = val * (100 + remote->eps) / 100;
387 lirc_t aeps_val = val + aeps;
388
389 return eps_val > aeps_val ? eps_val : aeps_val;
390}
391
392static inline lirc_t lower_limit(const struct ir_remote* remote, lirc_t val)
393{
394 int aeps = curr_driver->resolution > remote->aeps ?
395 curr_driver->resolution : remote->aeps;
396 lirc_t eps_val = val * (100 - remote->eps) / 100;
397 lirc_t aeps_val = val - aeps;
398
399 if (eps_val <= 0)
400 eps_val = 1;
401 if (aeps_val <= 0)
402 aeps_val = 1;
403
404 return eps_val < aeps_val ? eps_val : aeps_val;
405}
406
407/* only works if last <= current */
408static inline unsigned long time_elapsed(const struct timeval* last,
409 const struct timeval* current)
410{
411 unsigned long secs, diff;
412
413 secs = current->tv_sec - last->tv_sec;
414
415 diff = 1000000 * secs + current->tv_usec - last->tv_usec;
416
417 return diff;
418}
419
420static inline ir_code gen_mask(int bits)
421{
422 int i;
423 ir_code mask;
424
425 mask = 0;
426 for (i = 0; i < bits; i++) {
427 mask <<= 1;
428 mask |= 1;
429 }
430 return mask;
431}
432
433static inline ir_code gen_ir_code(const struct ir_remote* remote,
434 ir_code pre,
435 ir_code code,
436 ir_code post)
437{
438 ir_code all;
439
440 all = (pre & gen_mask(remote->pre_data_bits));
441 all <<= remote->bits;
442 all |= is_raw(remote) ? code : (code & gen_mask(remote->bits));
443 all <<= remote->post_data_bits;
444 all |= post & gen_mask(remote->post_data_bits);
445
446 return all;
447}
448
456const struct ir_remote* is_in_remotes(const struct ir_remote* remotes,
457 const struct ir_remote* remote);
458
460struct ir_remote* get_ir_remote(const struct ir_remote* remotes,
461 const char* name);
462
463void get_frequency_range(const struct ir_remote* remotes,
464 unsigned int* min_freq,
465 unsigned int* max_freq);
466
467void get_filter_parameters(const struct ir_remote* remotes,
468 lirc_t* max_gap_lengthp,
469 lirc_t* min_pulse_lengthp,
470 lirc_t* min_space_lengthp,
471 lirc_t* max_pulse_lengthp,
472 lirc_t* max_space_lengthp);
473
474int map_code(const struct ir_remote* remote,
475 struct decode_ctx_t* ctx,
476 int pre_bits,
477 ir_code pre,
478 int bits,
479 ir_code code,
480 int post_bits,
481 ir_code post);
482
483void map_gap(const struct ir_remote* remote,
484 struct decode_ctx_t* ctx,
485 const struct timeval* start,
486 const struct timeval* last,
487 lirc_t signal_length);
488
490struct ir_ncode* get_code_by_name(const struct ir_remote* remote,
491 const char* name);
492
493int write_message(char* buffer,
494 size_t size,
495 const char* remote_name,
496 const char* button_name,
497 const char* button_suffix,
498 ir_code code,
499 int reps);
500
511char* decode_all(struct ir_remote* remotes);
512
525int send_ir_ncode(struct ir_remote* remote, struct ir_ncode* code, int delay);
526
527#ifdef __cplusplus
528}
529#endif
530
537void ir_remote_init(int use_dyncodes);
538
540const struct ir_remote* get_decoding(void);
541
544#endif
curr_driver
const struct driver *const curr_driver
Read-only access to drv for client code.
Definition driver.c:34
driver.h
Interface to the userspace drivers.
write_message
int write_message(char *buffer, size_t size, const char *remote_name, const char *button_name, const char *button_suffix, ir_code code, int reps)
Formats the arguments into a readable string.
Definition ir_remote.c:709
get_code_by_name
struct ir_ncode * get_code_by_name(const struct ir_remote *remote, const char *name)
Return code with given name in remote's list of codes or NULL.
Definition ir_remote.c:393
get_frequency_range
void get_frequency_range(const struct ir_remote *remotes, unsigned int *min_freq, unsigned int *max_freq)
Definition ir_remote.c:152
get_filter_parameters
void get_filter_parameters(const struct ir_remote *remotes, lirc_t *max_gap_lengthp, lirc_t *min_pulse_lengthp, lirc_t *min_space_lengthp, lirc_t *max_pulse_lengthp, lirc_t *max_space_lengthp)
Definition ir_remote.c:189
repeat_code
struct ir_ncode * repeat_code
Global pointer to the code currently repeating.
Definition ir_remote.c:59
ncode_free
void ncode_free(struct ir_ncode *ncode)
Dispose an ir_ncode instance obtained from ncode_dup().
Definition ir_remote.c:100
last_remote
struct ir_remote * last_remote
TODO.
Definition ir_remote.c:55
send_ir_ncode
int send_ir_ncode(struct ir_remote *remote, struct ir_ncode *code, int delay)
Transmits the actual code in the second argument by calling the current hardware driver.
Definition ir_remote.c:819
decode_all
char * decode_all(struct ir_remote *remotes)
Tries to decode current signal trying all known remotes.
Definition ir_remote.c:729
repeat_remote
struct ir_remote * repeat_remote
Global pointer to the remote that contains the code currently repeating.
Definition ir_remote.c:57
ir_remote_init
void ir_remote_init(int use_dyncodes)
Initiate: define if dynamic codes should be used.
Definition ir_remote.c:120
get_decoding
const struct ir_remote * get_decoding(void)
Return pointer to currently decoded remote.
Definition ir_remote.c:850
get_ir_remote
struct ir_remote * get_ir_remote(const struct ir_remote *remotes, const char *name)
Return ir_remote with given name in remotes list, or NULL if not found.
Definition ir_remote.c:247
map_code
int map_code(const struct ir_remote *remote, struct decode_ctx_t *ctx, int pre_bits, ir_code pre, int bits, ir_code code, int post_bits, ir_code post)
Definition ir_remote.c:279
map_gap
void map_gap(const struct ir_remote *remote, struct decode_ctx_t *ctx, const struct timeval *start, const struct timeval *last, lirc_t signal_length)
Definition ir_remote.c:325
is_in_remotes
const struct ir_remote * is_in_remotes(const struct ir_remote *remotes, const struct ir_remote *remote)
Test if a given remote is in a list of remotes.
Definition ir_remote.c:235
ncode_dup
struct ir_ncode * ncode_dup(struct ir_ncode *ncode)
Create a malloc'd, deep copy of ncode.
Definition ir_remote.c:65
ir_remote_types.h
Describes and decodes the signals from IR remotes.
RAW_CODES
#define RAW_CODES
for internal use only
Definition ir_remote_types.h:100
XMP
#define XMP
XMP protocol.
Definition ir_remote_types.h:114
RC6
#define RC6
IR data follows RC6 protocol.
Definition ir_remote_types.h:107
GRUNDIG
#define GRUNDIG
encoding found on Grundig remote
Definition ir_remote_types.h:111
BO
#define BO
encoding found on Bang & Olufsen remote
Definition ir_remote_types.h:112
ir_code
uint64_t ir_code
Denotes an internal coded representation for an IR transmission.
Definition ir_remote_types.h:43
SPACE_FIRST
#define SPACE_FIRST
bits are encoded as space+pulse
Definition ir_remote_types.h:110
SPACE_ENC
#define SPACE_ENC
IR data is space encoded.
Definition ir_remote_types.h:109
RC5
#define RC5
IR data follows RC5 protocol.
Definition ir_remote_types.h:101
SERIAL
#define SERIAL
serial protocol
Definition ir_remote_types.h:113
CONST_LENGTH
#define CONST_LENGTH
signal length+gap is always constant
Definition ir_remote_types.h:120
RCMM
#define RCMM
IR data follows RC-MM protocol.
Definition ir_remote_types.h:108
eps
unsigned int eps
Shared list of remotes.
Definition irrecord.c:62
aeps
lirc_t aeps
Error tolerance in per cent.
Definition irrecord.c:63
decode_ctx_t
State describing code, pre, post + gap and repeat state.
Definition ir_remote_types.h:137
driver::resolution
unsigned int resolution
The resolution in microseconds of the recorded durations when reading signals.
Definition driver.h:230
ir_code_node
An ir_code for entering into (singly) linked lists, i.e.
Definition ir_remote_types.h:49
ir_ncode
IR Command, corresponding to one (command defining) line of the configuration file.
Definition ir_remote_types.h:60
ir_ncode::next
struct ir_code_node * next
Linked list of the subsequent ir_code's, after the first one.
Definition ir_remote_types.h:75
ir_ncode::code
ir_code code
The first code of the command.
Definition ir_remote_types.h:65
ir_ncode::name
char * name
Name of command.
Definition ir_remote_types.h:62
ir_remote
One remote as represented in the configuration file.
Definition ir_remote_types.h:150
ir_remote::repeat_gap
uint32_t repeat_gap
time between two repeat codes if different from gap
Definition ir_remote_types.h:188
ir_remote::aeps
unsigned int aeps
detecting very short pulses is difficult with relative tolerance for some remotes,...
Definition ir_remote_types.h:157
ir_remote::gap2
uint32_t gap2
time between signals in usecs
Definition ir_remote_types.h:187
ir_remote::sfoot
lirc_t sfoot
foot
Definition ir_remote_types.h:176
ir_remote::rc6_mask
ir_code rc6_mask
RC-6 doubles signal length of some bits.
Definition ir_remote_types.h:206
ir_remote::duty_cycle
unsigned int duty_cycle
0<duty cycle<=100 default: 50
Definition ir_remote_types.h:204
ir_remote::repeat_mask
ir_code repeat_mask
mask defines which bits are inverted for repeats
Definition ir_remote_types.h:217
ir_remote::srepeat
lirc_t srepeat
indicate repeating
Definition ir_remote_types.h:177
ir_remote::bits
int bits
bits (length of code)
Definition ir_remote_types.h:154
ir_remote::post_data_bits
int post_data_bits
length of post_data
Definition ir_remote_types.h:181
ir_remote::ignore_mask
ir_code ignore_mask
mask defines which bits can be ignored when matching a code
Definition ir_remote_types.h:216
ir_remote::shead
lirc_t shead
header
Definition ir_remote_types.h:169
ir_remote::toggle_mask
ir_code toggle_mask
Sharp (?) error detection scheme.
Definition ir_remote_types.h:205
ir_remote::flags
int flags
flags
Definition ir_remote_types.h:155
ir_remote::gap
uint32_t gap
time between signals in usecs
Definition ir_remote_types.h:186
ir_remote::eps
int eps
eps (relative tolerance)
Definition ir_remote_types.h:156
ir_remote::name
const char * name
name of remote control
Definition ir_remote_types.h:151
ir_remote::toggle_bit_mask
ir_code toggle_bit_mask
previously only one bit called toggle_bit
Definition ir_remote_types.h:190
ir_remote::pre_data_bits
int pre_data_bits
length of pre_data
Definition ir_remote_types.h:179