LIRC libraries Linux Infrared Remote Control

Loading...
Searching...
No Matches
release.c
Go to the documentation of this file.
1/****************************************************************************
2** release.c ***************************************************************
3****************************************************************************
4*
5* Copyright (C) 2007 Christoph Bartelmus (lirc@bartelmus.de)
6*
7*/
8
17#ifdef HAVE_CONFIG_H
18# include <config.h>
19#endif
20
21#include <stdlib.h>
22#include <stdio.h>
23#include <sys/time.h>
24
25#include "media/lirc.h"
26
27#include "lirc/release.h"
28#include "lirc/receive.h"
29#include "lirc/lirc_log.h"
30
31 static const logchannel_t logchannel = LOG_LIB;
32
33 static struct timeval release_time;
34 static struct ir_remote* release_remote;
35 static struct ir_ncode* release_ncode;
36 static ir_code release_code;
37 static int release_reps;
38 static lirc_t release_gap;
39
40 static struct ir_remote* release_remote2;
41 static struct ir_ncode* release_ncode2;
42 static ir_code release_code2;
43
44 static void register_input(void)
45{
46 struct timeval gap;
47
48 if (release_remote == NULL)
49 return;
50
51 timerclear(&gap);
52 gap.tv_usec = release_gap;
53
54 gettimeofday(&release_time, NULL);
55 timeradd(&release_time, &gap, &release_time);
56}
57
58 void register_button_press(struct ir_remote* remote,
59 struct ir_ncode* ncode,
60 ir_code code,
61 int reps)
62{
63 if (reps == 0 && release_remote != NULL) {
64 release_remote2 = release_remote;
65 release_ncode2 = release_ncode;
66 release_code2 = release_code;
67 }
68
69 release_remote = remote;
70 release_ncode = ncode;
71 release_code = code;
72 release_reps = reps;
73 /* some additional safety margin */
74 release_gap = upper_limit(remote,
75 remote->max_total_signal_length
76 - remote->min_gap_length)
77 + receive_timeout(upper_limit(remote,
78 remote->min_gap_length))
79 + 10000;
80 log_trace("release_gap: %lu", release_gap);
81 register_input();
82}
83
84 void get_release_data(const char** remote_name,
85 const char** button_name,
86 int* reps)
87{
88 if (release_remote != NULL) {
89 *remote_name = release_remote->name;
90 *button_name = release_ncode->name;
91 *reps = release_reps;
92 } else {
93 *remote_name = *button_name = "(NULL)";
94 *reps = 0;
95 }
96}
97
98
99 void get_release_time(struct timeval* tv)
100{
101 *tv = release_time;
102}
ir_code
uint64_t ir_code
Denotes an internal coded representation for an IR transmission.
Definition ir_remote_types.h:43
log_trace
#define log_trace(fmt,...)
Log a trace message.
Definition lirc_log.h:129
logchannel_t
logchannel_t
Log channels used to filter messages.
Definition lirc_log.h:53
get_release_data
void get_release_data(const char **remote_name, const char **button_name, int *reps)
Get data from saved from last call to register_button_press().
Definition release.c:84
register_button_press
void register_button_press(struct ir_remote *remote, struct ir_ncode *ncode, ir_code code, int reps)
Set up pending events for given button, including the release_gap.
Definition release.c:58
get_release_time
void get_release_time(struct timeval *tv)
Get time for last call to register_button_press() if defined, else a noop.
Definition release.c:99
ir_ncode
IR Command, corresponding to one (command defining) line of the configuration file.
Definition ir_remote_types.h:60
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::min_gap_length
lirc_t min_gap_length
how long is the shortest gap
Definition ir_remote_types.h:232
ir_remote::name
const char * name
name of remote control
Definition ir_remote_types.h:151
ir_remote::max_total_signal_length
lirc_t max_total_signal_length
how long is the longest signal including gap
Definition ir_remote_types.h:231