31 #include <sys/ioctl.h>
33 #include "include/media/lirc.h"
34 #include "lirc/ir_remote.h"
35 #include "lirc/driver.h"
36 #include "lirc/release.h"
37 #include "lirc/lirc_log.h"
41 {
"__EOF",
LIRC_EOF, 1, NULL, NULL, NULL, 0};
44 static const char*
const PACKET_EOF =
"0000000008000000 00 __EOF lirc\n";
47 static struct ir_remote lirc_internal_remote = {
"lirc"};
57 static int dyncodes = 0;
61 dyncodes= use_dyncodes;
64 static lirc_t time_left(
struct timeval *
current,
struct timeval *last, lirc_t gap)
66 unsigned long secs, diff;
68 secs = current->tv_sec - last->tv_sec;
70 diff = 1000000 * secs + current->tv_usec - last->tv_usec;
72 return ((lirc_t) (diff < gap ? gap - diff : 0));
97 *min_freq = scan->
freq;
98 *max_freq = scan->
freq;
102 if (scan->
freq != 0) {
103 if (scan->
freq > *max_freq) {
104 *max_freq = scan->
freq;
105 }
else if (scan->
freq < *min_freq) {
106 *min_freq = scan->
freq;
123 lirc_t * min_space_lengthp, lirc_t * max_pulse_lengthp, lirc_t * max_space_lengthp)
127 lirc_t min_pulse_length = 0, min_space_length = 0;
128 lirc_t max_pulse_length = 0, max_space_length = 0;
133 if (val > max_gap_length) {
134 max_gap_length = val;
136 val = lower_limit(scan, scan->min_pulse_length);
137 if (min_pulse_length == 0 || val < min_pulse_length) {
138 min_pulse_length = val;
140 val = lower_limit(scan, scan->min_space_length);
141 if (min_space_length == 0 || val > min_space_length) {
142 min_space_length = val;
144 val = upper_limit(scan, scan->max_pulse_length);
145 if (val > max_pulse_length) {
146 max_pulse_length = val;
148 val = upper_limit(scan, scan->max_space_length);
149 if (val > max_space_length) {
150 max_space_length = val;
155 *min_pulse_lengthp = min_pulse_length;
156 *min_space_lengthp = min_space_length;
157 *max_pulse_lengthp = max_pulse_length;
158 *max_space_lengthp = max_space_length;
170 while (remotes != NULL) {
171 if (remotes == remote) {
174 remotes = remotes->next;
192 if (strcmp(name,
"lirc") == 0) {
193 return &lirc_internal_remote;
196 if (strcasecmp(all->
name, name) == 0) {
233 all = (pre & gen_mask(pre_bits));
235 all |= (code & gen_mask(bits));
237 all |= (post & gen_mask(post_bits));
241 ctx->
code = (all & gen_mask(remote->
bits));
242 all >>= remote->
bits;
265 const struct timeval *start,
266 const struct timeval *last,
267 lirc_t signal_length)
274 if (start->tv_sec - last->tv_sec >= 2) {
280 gap = time_elapsed(last, start);
293 if (is_const(remote)) {
296 if (min_gap(remote) > signal_length) {
301 if (max_gap(remote) > signal_length) {
315 LOGPRINTF(1,
"is_const(remote): %d", is_const(remote));
316 LOGPRINTF(1,
"remote->gap range: %lu %lu", (__u32) min_gap(remote), (__u32) max_gap(remote));
319 LOGPRINTF(1,
"signal length: %lu", (__u32) signal_length);
336 if (strcmp(remote->
name,
"lirc") == 0) {
337 return strcmp(name,
"__EOF") == 0 ? &NCODE_EOF : 0;
339 while (all->
name != NULL) {
340 if (strcasecmp(all->
name, name) == 0) {
349 int *repeat_flag,
ir_code * toggle_bit_mask_statep)
351 ir_code pre_mask, code_mask, post_mask, toggle_bit_mask_state, all;
352 int found_code, have_code;
355 pre_mask = code_mask = post_mask = 0;
357 if (has_toggle_bit_mask(remote)) {
361 if (has_ignore_mask(remote)) {
365 if (has_toggle_mask(remote) && remote->toggle_mask_state % 2) {
366 ir_code *affected, mask, mask_bit;
367 int bit, current_bit;
371 for (bit = current_bit = 0; bit < bit_count(remote); bit++, current_bit++) {
381 (*affected) ^= (mask_bit << current_bit);
385 if (has_pre(remote)) {
386 if ((pre | pre_mask) != (remote->
pre_data | pre_mask)) {
394 if (has_post(remote)) {
395 if ((post | post_mask) != (remote->
post_data | post_mask)) {
403 all = gen_ir_code(remote, pre, code, post);
405 if(*repeat_flag && has_repeat_mask(remote)) {
414 codes = remote->codes;
416 while (codes->
name != NULL) {
420 gen_ir_code(remote, remote->
pre_data, get_ir_code(codes, codes->
current),
422 if (match_ir_code(remote, next_all, all) ||
423 (*repeat_flag && has_repeat_mask(remote) &&
424 match_ir_code(remote, next_all, all ^ remote->
repeat_mask))) {
426 if (codes->
next != NULL) {
443 search = codes->
next;
444 if (search == NULL || (codes->
next != NULL && codes->
current == NULL)) {
447 int sequence_match = 0;
449 while (search != codes->
current->next) {
455 while (next != codes->
current) {
456 if (get_ir_code(codes, prev) != get_ir_code(codes, next)) {
460 prev = get_next_ir_code_node(codes, prev);
461 next = get_next_ir_code_node(codes, next);
465 gen_ir_code(remote, remote->
pre_data,
466 get_ir_code(codes, prev), remote->
post_data);
467 if (match_ir_code(remote, next_all, all)) {
468 codes->
current = get_next_ir_code_node(codes, prev);
477 search = search->next;
486 if (!found_code && dyncodes) {
495 if (found_code && found != NULL && has_toggle_mask(remote)) {
496 if (!(remote->toggle_mask_state % 2)) {
507 *toggle_bit_mask_statep = toggle_bit_mask_state;
513 struct timeval current;
514 static struct ir_remote *last_decoded = NULL;
518 gettimeofday(¤t, NULL);
519 LOGPRINTF(1,
"%lx %lx %lx %d %d %d %d %d %d %d",
520 remote, last_remote, last_decoded,
521 remote == last_decoded,
523 time_elapsed(&remote->
last_send, ¤t) < 1000000, (!has_toggle_bit_mask(remote)
524 || toggle_bit_mask_state ==
525 remote->toggle_bit_mask_state));
529 LOGPRINTF(0,
"repeat indicated although release was detected before");
533 if (remote == last_decoded &&
535 ctx->
repeat_flag && time_elapsed(&remote->
last_send, ¤t) < 1000000 && (!has_toggle_bit_mask(remote)
536 || toggle_bit_mask_state ==
537 remote->toggle_bit_mask_state)) {
538 if (has_toggle_mask(remote)) {
539 remote->toggle_mask_state++;
540 if (remote->toggle_mask_state == 4) {
542 remote->toggle_mask_state = 2;
544 }
else if (found->
current == NULL) {
548 if (found->
next != NULL && found->
current == NULL) {
553 if (has_toggle_mask(remote)) {
554 remote->toggle_mask_state = 1;
557 if (has_toggle_bit_mask(remote)) {
558 remote->toggle_bit_mask_state = toggle_bit_mask_state;
561 last_remote = remote;
562 last_decoded = remote;
570 if (has_pre(remote)) {
575 if (has_post(remote)) {
584 ctx->
code = reverse(ctx->
code, bit_count(remote));
601 int write_message(
char *buffer,
size_t size,
const char *remote_name,
const char *button_name,
602 const char *button_suffix,
ir_code code,
int reps)
606 len = snprintf(buffer, size,
"%016llx %02x %s%s %s\n",
607 (
unsigned long long)code, reps, button_name, button_suffix, remote_name);
628 decoding = remote = remotes;
635 if (ncode == &NCODE_EOF) {
636 logprintf(LIRC_DEBUG,
"decode all: returning EOF");
637 strncpy(message, PACKET_EOF,
sizeof(message));
640 ctx.
code = set_code(remote, ncode, toggle_bit_mask_state, &ctx);
641 if ((has_toggle_mask(remote) && remote->toggle_mask_state % 2) || ncode->
current != NULL) {
646 for (scan = decoding; scan != NULL; scan = scan->next) {
647 for (scan_ncode = scan->codes; scan_ncode->
name != NULL; scan_ncode++) {
651 if (is_xmp(remote)) {
654 reps = remote->reps - (ncode->
next ? 1 : 0);
656 if (reps <= remote->suppress_repeat) {
663 register_button_press(remote, remote->
last_code, ctx.
code, reps);
670 logprintf(LIRC_ERROR,
"message buffer overflow");
678 remote->toggle_mask_state = 0;
679 remote = remote->next;
683 LOGPRINTF(1,
"decoding failed for all remotes");
700 struct timeval current;
703 gettimeofday(¤t, NULL);
704 usecs = time_left(¤t,
708 if (repeat_remote == NULL || remote != repeat_remote
struct ir_remote * last_remote
struct ir_ncode * repeat_code
int(*const send_func)(struct ir_remote *remote, struct ir_ncode *code)
void ir_remote_init(int use_dyncodes)
struct ir_ncode * toggle_code
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)
struct ir_code_node * next
struct ir_ncode * get_code_by_name(const struct ir_remote *remote, const char *name)
struct ir_ncode * last_code
struct ir_remote * get_ir_remote(const struct ir_remote *remotes, const char *name)
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)
char * decode_all(struct ir_remote *remotes)
struct ir_code_node * current
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)
const struct ir_remote * is_in_remotes(const struct ir_remote *remotes, const struct ir_remote *remote)
#define LOGPRINTF(level, fmt, args...)
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)
void get_frequency_range(const struct ir_remote *remotes, unsigned int *min_freq, unsigned int *max_freq)
int(*const decode_func)(struct ir_remote *remote, struct decode_ctx_t *ctx)
const struct driver const * curr_driver
struct ir_ncode dyncodes[2]
struct ir_remote * repeat_remote
int send_ir_ncode(struct ir_remote *remote, struct ir_ncode *code, int delay)