1
/****************************************************************************
2
** hw_atwf83.c *************************************************************
3
****************************************************************************
5
* Lirc driver for Aureal remote (ATWF@83-W001 ESKY.CC USB_V3B)
7
* Copyright (C) 2010 Romain Henriet <romain-devel@laposte.net>
9
* Distribute under GPL version 2 or later.
15
#include <sys/fcntl.h>
18
#include "ir_remote.h"
27
static int atwf83_init();
28
static int atwf83_deinit();
29
static char *atwf83_rec(struct ir_remote *remotes);
30
static int atwf83_decode(struct ir_remote *remote,
31
ir_code *prep, ir_code *codep, ir_code *postp,
33
lirc_t *min_remaining_gapp,
34
lirc_t *max_remaining_gapp);
35
static void* atwf83_repeat();
37
const unsigned release_code =0x00000000;
38
/** Time to wait before first repetition */
39
const unsigned repeat_time1_us = 500000;
40
/** Time to wait between two repetitions */
41
const unsigned repeat_time2_us = 100000;
42
/** Pipe between main thread and repetition thread */
43
static int fd_pipe[2] = {-1,-1};
44
/** Thread that simulates repetitions */
45
static pthread_t repeat_thread;
46
/** File descriptor for the real device */
49
const int main_code_length = 32;
50
static signed int main_code = 0;
51
static struct timeval start,end,last;
52
static int repeat_state = RPT_NO;
54
/* Aureal USB iR Receiver */
55
struct hardware hw_atwf83=
57
"/dev/hidraw0", /* "device" */
59
LIRC_CAN_REC_LIRCCODE, /* features */
61
LIRC_MODE_LIRCCODE, /* rec_mode */
63
atwf83_init, /* init_func */
64
atwf83_deinit, /* deinit_func */
66
atwf83_rec, /* rec_func */
67
atwf83_decode, /* decode_func */
68
NULL, /* ioctl_func */
73
int atwf83_decode(struct ir_remote *remote,
74
ir_code *prep, ir_code *codep, ir_code *postp,
76
lirc_t *min_remaining_gapp,
77
lirc_t *max_remaining_gapp)
79
LOGPRINTF(1, "atwf83_decode");
81
if(!map_code(remote,prep,codep,postp,0,0,
82
main_code_length,main_code,0,0))
87
map_gap(remote, &start, &last, 0, repeat_flagp,
88
min_remaining_gapp, max_remaining_gapp);
90
*repeat_flagp = repeat_state;
97
logprintf(LOG_INFO, "initializing '%s'", hw.device);
98
if ((fd_hidraw = open(hw.device, O_RDONLY)) < 0)
100
logprintf(LOG_ERR, "unable to open '%s'", hw.device);
103
/* Create pipe so that events sent by the repeat thread will
104
trigger main thread */
105
if (pipe(fd_pipe) != 0)
107
logperror(LOG_ERR, "couldn't open pipe");
112
/* Create thread to simulate repetitions */
113
if (pthread_create(&repeat_thread, NULL, atwf83_repeat, NULL))
115
logprintf(LOG_ERR, "Could not create \"repeat thread\"");
123
pthread_cancel(repeat_thread);
126
logprintf(LOG_INFO, "closing '%s'", hw.device);
145
* Runtime that reads device, forwards codes to main thread
146
* and simulates repetitions.
148
void* atwf83_repeat()
151
unsigned current_code;
154
struct timeval delay;
160
// Initialize set to monitor device's events
162
FD_SET(fd_hidraw, &files);
165
sel = select(FD_SETSIZE, &files, NULL, NULL, &delay);
169
sel = select(FD_SETSIZE, &files, NULL, NULL, NULL);
175
// Data ready in device's file
176
rd = read(fd_hidraw, ev, sizeof(ev));
180
logprintf(LOG_ERR, "(%s) Could not read %s",
181
__FUNCTION__, hw.device);
186
(rd==7 && ev[0]==0x200) ||
189
// Release code : stop repetitions
191
current_code = release_code;
195
// Key code : forward it to main thread
198
delay.tv_usec = repeat_time1_us;
199
current_code = ev[0];
203
// Timeout : send current_code again to main
204
// thread to simulate repetition
206
delay.tv_usec = repeat_time2_us;
210
logprintf(LOG_ERR,"(%s) select() failed",
214
// Send code to main thread through pipe
215
write(fd, ¤t_code, sizeof(current_code));
225
* Aureal Technology ATWF@83 cheap remote
229
char *atwf83_rec(struct ir_remote *remotes)
234
gettimeofday(&start,NULL);
235
rd = read(hw.fd, &ev, sizeof(ev));
240
logprintf(LOG_ERR,"(%s) could not read pipe", __FUNCTION__);
252
LOGPRINTF(1, "atwf83 : %x", ev);
253
// Record the code and check for repetition
256
repeat_state = RPT_YES;
261
repeat_state = RPT_NO;
263
gettimeofday(&end,NULL);
264
return decode_all(remotes);