LIRC libraries: /home/mk/tmp/lirc/lib/release.c (085323c 2016-01-06 15:32:54 +0100) Source File

| LIRC libraries LinuxInfraredRemoteControl

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 #ifdef HAVE_KERNEL_LIRC_H
26 #include <linux/lirc.h>
27 #else
28 #include "include/media/lirc.h"
29 #endif
30
31 #include "lirc/release.h"
32 #include "lirc/receive.h"
33 #include "lirc/lirc_log.h"
34
35 static const logchannel_t logchannel = LOG_LIB;
36
37 static struct timeval release_time;
38 static struct ir_remote* release_remote;
39 static struct ir_ncode* release_ncode;
40 static ir_code release_code;
41 static int release_reps;
42 static lirc_t release_gap;
43
44 static struct ir_remote* release_remote2;
45 static struct ir_ncode* release_ncode2;
46 static ir_code release_code2;
47 static const char* release_suffix = LIRC_RELEASE_SUFFIX;
48 static char message[PACKET_SIZE + 1];
49
50 void register_input(void)
51 {
52 struct timeval gap;
53
54 if (release_remote == NULL)
55 return;
56
57 timerclear(&gap);
58 gap.tv_usec = release_gap;
59
60 gettimeofday(&release_time, NULL);
61 timeradd(&release_time, &gap, &release_time);
62 }
63
64 void register_button_press(struct ir_remote* remote, struct ir_ncode* ncode, ir_code code, int reps)
65 {
66 if (reps == 0 && release_remote != NULL) {
67 release_remote2 = release_remote;
68 release_ncode2 = release_ncode;
69 release_code2 = release_code;
70 }
71
72 release_remote = remote;
73 release_ncode = ncode;
74 release_code = code;
75 release_reps = reps;
76 /* some additional safety margin */
77 release_gap = upper_limit(remote,
78 remote->max_total_signal_length - remote->min_gap_length)
79 + receive_timeout(upper_limit(remote, remote->min_gap_length)) + 10000;
80
81 log_trace("release_gap: %lu", release_gap);
82
83 register_input();
84 }
85
86 void get_release_data(const char** remote_name, const char** button_name, 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 void set_release_suffix(const char* s)
99 {
100 release_suffix = s;
101 }
102
103 void get_release_time(struct timeval* tv)
104 {
105 *tv = release_time;
106 }
107
108 const char* check_release_event(const char** remote_name, const char** button_name)
109 {
110 int len = 0;
111
112 if (release_remote2 != NULL) {
113 *remote_name = release_remote2->name;
114 *button_name = release_ncode2->name;
115 len = write_message(message,
116 PACKET_SIZE + 1,
117 release_remote2->name,
118 release_ncode2->name,
119 release_suffix,
120 release_code2,
121 0);
122 release_remote2 = NULL;
123 release_ncode2 = NULL;
124 release_code2 = 0;
125
126 if (len >= PACKET_SIZE + 1) {
127 log_error("message buffer overflow");
128 return NULL;
129 }
130
131 log_trace2("check");
132 return message;
133 }
134 return NULL;
135 }
136
137 const char* trigger_release_event(const char** remote_name, const char** button_name)
138 {
139 int len = 0;
140
141 if (release_remote != NULL) {
142 release_remote->release_detected = 1;
143 *remote_name = release_remote->name;
144 *button_name = release_ncode->name;
145 len = write_message(message,
146 PACKET_SIZE + 1,
147 release_remote->name,
148 release_ncode->name,
149 release_suffix,
150 release_code,
151 0);
152 timerclear(&release_time);
153 release_remote = NULL;
154 release_ncode = NULL;
155 release_code = 0;
156
157 if (len >= PACKET_SIZE + 1) {
158 log_error("message buffer overflow");
159 return NULL;
160 }
161 log_trace2("trigger");
162 return message;
163 }
164 return NULL;
165 }
166
167 const char* release_map_remotes(struct ir_remote* old, struct ir_remote* new, const char** remote_name,
168 const char** button_name)
169 {
170 struct ir_remote* remote;
171 struct ir_ncode* ncode = NULL;
172
173 if (release_remote2 != NULL) {
174 /* should not happen */
175 log_error("release_remote2 still in use");
176 release_remote2 = NULL;
177 }
178 if (release_remote && is_in_remotes(old, release_remote)) {
179 remote = get_ir_remote(new, release_remote->name);
180 if (remote)
181 ncode = get_code_by_name(remote, release_ncode->name);
182 if (remote && ncode) {
183 release_remote = remote;
184 release_ncode = ncode;
185 } else {
186 return trigger_release_event(remote_name, button_name);
187 }
188 }
189 return NULL;
190 }
ir_remote
Definition: ir_remote_types.h:167
ir_remote::max_total_signal_length
lirc_t max_total_signal_length
Definition: ir_remote_types.h:248
ir_remote::name
const char * name
Definition: ir_remote_types.h:168
get_code_by_name
struct ir_ncode * get_code_by_name(const struct ir_remote *remote, const char *name)
Definition: ir_remote.c:396
get_ir_remote
struct ir_remote * get_ir_remote(const struct ir_remote *remotes, const char *name)
Definition: ir_remote.c:250
ir_code
__u64 ir_code
Definition: ir_remote_types.h:59
ir_remote::min_gap_length
lirc_t min_gap_length
Definition: ir_remote_types.h:249
PACKET_SIZE
#define PACKET_SIZE
Definition: lirc_config.h:98
logchannel_t
logchannel_t
Definition: lirc_log.h:53
ir_ncode::name
char * name
Definition: ir_remote_types.h:78
log_trace2
#define log_trace2(fmt,...)
Definition: lirc_log.h:139
log_error
#define log_error(fmt,...)
Definition: lirc_log.h:104
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)
Definition: ir_remote.c:712
log_trace
#define log_trace(fmt,...)
Definition: lirc_log.h:129
is_in_remotes
const struct ir_remote * is_in_remotes(const struct ir_remote *remotes, const struct ir_remote *remote)
Definition: ir_remote.c:238
LIRC_RELEASE_SUFFIX
#define LIRC_RELEASE_SUFFIX
Definition: lirc_config.h:77
ir_ncode
Definition: ir_remote_types.h:76
ir_remote::release_detected
int release_detected
Definition: ir_remote_types.h:253