1 /* $Id: hw_creative.c,v 5.10 2007/07/29 18:20:07 lirc Exp $ */
3 /****************************************************************************
4 ** hw_creative.c ***********************************************************
5 ****************************************************************************
7 * routines for Creative receiver
9 * Copyright (C) 1999 Christoph Bartelmus <lirc@bartelmus.de>
24 #include <sys/types.h>
25 #include <sys/ioctl.h>
29 #include "ir_remote.h"
31 #include "hw_creative.h"
36 extern struct ir_remote
*repeat_remote
,*last_remote
;
38 unsigned char b
[NUMBYTES
];
39 struct timeval start
,end
,last
;
40 lirc_t gap
,signal_length
;
43 struct hardware hw_creative
=
45 LIRC_DRIVER_DEVICE
, /* default device */
47 LIRC_CAN_REC_LIRCCODE
, /* features */
49 LIRC_MODE_LIRCCODE
, /* rec_mode */
51 creative_init
, /* init_func */
52 NULL
, /* config_func */
53 creative_deinit
, /* deinit_func */
55 creative_rec
, /* rec_func */
56 creative_decode
, /* decode_func */
57 NULL
, /* ioctl_func */
62 int creative_decode(struct ir_remote
*remote
,
63 ir_code
*prep
,ir_code
*codep
,ir_code
*postp
,
65 lirc_t
*min_remaining_gapp
,
66 lirc_t
*max_remaining_gapp
)
68 if(!map_code(remote
,prep
,codep
,postp
,
74 map_gap(remote
, &start
, &last
, signal_length
, repeat_flagp
,
75 min_remaining_gapp
, max_remaining_gapp
);
80 int creative_init(void)
84 if(!tty_create_lock(hw
.device
))
86 logprintf(LOG_ERR
,"could not create lock files");
89 if((hw
.fd
=open(hw
.device
,O_RDWR
|O_NONBLOCK
|O_NOCTTY
))<0)
91 logprintf(LOG_ERR
,"could not open %s",hw
.device
);
92 logperror(LOG_ERR
,"creative_init()");
98 logprintf(LOG_ERR
,"could not reset tty");
102 if(!tty_setbaud(hw
.fd
,2400))
104 logprintf(LOG_ERR
,"could not set baud rate");
111 int creative_deinit(void)
118 char *creative_rec(struct ir_remote
*remotes
)
129 gettimeofday(&start
,NULL
);
130 for(i
=0;i
<NUMBYTES
;i
++)
134 if(!waitfordata(TIMEOUT
))
136 logprintf(LOG_ERR
,"timeout reading byte %d",i
);
140 if(read(hw
.fd
,&b
[i
],1)!=1)
142 logprintf(LOG_ERR
,"reading of byte %d failed",i
);
143 logperror(LOG_ERR
,NULL
);
147 b
[1]!=0x05 /* || b[4]!=0xac || b[5]!=0x21 */)
149 logprintf(LOG_ERR
,"bad envelope");
154 if(b
[2]!=((~b
[3])&0xff))
156 logprintf(LOG_ERR
,"bad checksum");
160 LOGPRINTF(1,"byte %d: %02x",i
,b
[i
]);
162 gettimeofday(&end
,NULL
);
165 pre
=reverse((((ir_code
) b
[4])<<8) | ((ir_code
) b
[5]),16);
166 code
= reverse((((ir_code
) b
[2]) << 8) | ((ir_code
) b
[3]), 16);
168 m
=decode_all(remotes
);