1 /*****************************************************************************
2 ** hw_usbx.c ****************************************************************
3 *****************************************************************************
4 * Routines for the ADSTech USBX-707 USB IR Blaster
6 * Only receiving is implemented.
8 * It uses a baudrate of 300kps on a USB serial device which, currently, is
9 * only supported by Linux.
10 * If someone knows how to set such a baudrate under other OS's, please add
11 * that functionality to daemons/serial.c to make this driver work for those
14 * Information on how to send with this device is greatly appreciated...
16 * Copyright (C) 2007 Jelle Foks <jelle@foks.8m.com>
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU Library General Public License for more details.
28 * You should have received a copy of the GNU General Public License
29 * along with this program; if not, write to the Free Software
30 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
44 #include <sys/types.h>
45 #include <sys/ioctl.h>
52 #include "ir_remote.h"
56 static unsigned char b
[6];
59 #define REPEAT_FLAG ((ir_code) 0x1)
60 #define CODE_LENGTH 48
62 struct hardware hw_usbx
= {
63 LIRC_IRTTY
, /* Default device */
65 LIRC_CAN_REC_LIRCCODE
, /* Features */
67 LIRC_MODE_LIRCCODE
, /* rec_mode */
68 CODE_LENGTH
, /* code_length */
69 usbx_init
, /* init_func */
70 NULL
, /* config_func */
71 usbx_deinit
, /* deinit_func */
73 usbx_rec
, /* rec_func */
74 usbx_decode
, /* decode_func */
75 NULL
, /* ioctl_func */
80 int usbx_decode (struct ir_remote
*remote
, ir_code
*prep
, ir_code
*codep
,
81 ir_code
*postp
, int *repeat_flagp
,
82 lirc_t
*min_remaining_gapp
, lirc_t
*max_remaining_gapp
)
84 if( remote
->flags
&CONST_LENGTH
||
85 !map_code(remote
, prep
, codep
, postp
,
86 0, 0, CODE_LENGTH
, code
&(~REPEAT_FLAG
), 0, 0))
90 /* the lsb in the code is the repeat flag */
91 *repeat_flagp
= code
&REPEAT_FLAG
? 1:0;
92 *min_remaining_gapp
=min_gap(remote
);
93 *max_remaining_gapp
=max_gap(remote
);
95 LOGPRINTF(1, "repeat_flagp: %d",*repeat_flagp
);
96 LOGPRINTF(1, "remote->gap range: %lu %lu\n",
97 (unsigned long) min_gap(remote
),
98 (unsigned long) max_gap(remote
));
99 LOGPRINTF(1,"rem: %lu %lu",
100 (unsigned long) remote
->min_remaining_gap
,
101 (unsigned long) remote
->max_remaining_gap
);
107 if(!tty_create_lock(hw
.device
))
109 logprintf(LOG_ERR
,"could not create lock files for '%s'",
113 if ( (hw
.fd
= open (hw
.device
, O_RDWR
| O_NONBLOCK
| O_NOCTTY
)) < 0)
116 logprintf (LOG_ERR
, "Could not open the '%s' device",
120 LOGPRINTF(1, "device '%s' opened", hw
.device
);
122 if(!tty_reset(hw
.fd
) ||
123 !tty_setbaud(hw
.fd
, 300000) ||
124 !tty_setrtscts(hw
.fd
, 1))
126 logprintf(LOG_ERR
,"could not configure the serial port for "
135 int usbx_deinit (void)
143 char *usbx_rec (struct ir_remote
*remotes
)
149 for (i
= 0 ; i
< 6; i
++)
153 if (!waitfordata(20000))
155 LOGPRINTF(LOG_ERR
,"timeout reading byte %d",i
);
159 if (read(hw
.fd
, &b
[i
], 1) != 1)
161 LOGPRINTF(LOG_ERR
, "reading of byte %d failed.", i
);
165 LOGPRINTF(1, "byte %d: %02x", i
, b
[i
]);
169 for ( i
= 0 ; i
< x
; i
++ )
172 code
|= ((ir_code
) b
[i
]);
175 LOGPRINTF(1," -> %0llx",(unsigned long long) code
);
177 m
= decode_all(remotes
);