3 #include "channelinfo.h"
5 #include "cwindowgui.h"
9 #include "mwindowgui.h"
11 #include "playbackengine.h"
12 #include "playtransport.h"
14 #include "recordgui.h"
15 #include "recordmonitor.h"
16 #include "remotecontrol.h"
21 #include <linux/input.h>
23 X10TV::X10TV(MWindow *mwindow, int *fds, int nfds)
25 this->mwindow = mwindow;
26 this->ifds = new int[nfds];
28 for( int i=0; i<nfds; ++i ) this->ifds[i] = fds[i];
31 memset(ev, 0, sizeof(*ev));
49 for( int i=nfds; --i>=0; ) {
50 ioctl(ifds[i], EVIOCGRAB, 0);
64 for( int i=nfds; --i>=0; ) {
66 ioctl(fd, EVIOCGRAB, 1);
67 if( fd >= mfd ) mfd = fd+1;
74 int X10TV::open_usb_inputs(int vendor, int product, int &version,
78 const char *dev_input = "/dev/input";
79 DIR *dir = opendir(dev_input);
80 if( !dir ) return ret;
83 struct input_id dev_id;
85 while( nfds < mxfds && (dp = readdir64(dir)) != 0 ) {
86 char *fn = dp->d_name;
87 if( !strcmp(fn, ".") || !strcmp(fn, "..") ) continue;
88 char path[PATH_MAX]; struct stat st;
89 snprintf(path, PATH_MAX, "%s/%s", dev_input, fn);
90 if( stat(path, &st) < 0 ) continue;
91 if( !S_ISCHR(st.st_mode) ) continue;
92 int fd = open(path, O_RDONLY);
93 if( fd < 0 ) continue;
94 if( !ioctl(fd, EVIOCGID, &dev_id) ) {
95 if( dev_id.bustype == BUS_USB &&
96 dev_id.vendor == vendor &&
97 dev_id.product == product ) {
99 // quirk, reports pointing_stick for keys
101 (1<<INPUT_PROP_POINTING_STICK);
102 int ret = ioctl(fd, EVIOCGPROP(sizeof(props)), &props);
103 if( ret == sizeof(props) && (props & mptrs) ) {
104 version = dev_id.version;
117 X10TV *X10TV::probe(MWindow *mwindow)
119 int ver = -1, ifds[16];
120 int nfds = open_usb_inputs(0x0bc7, 0x0004, ver, ifds, 16);
121 if( nfds <= 0 ) return 0;
122 printf("detected ATI X10 remote, ver=0x%04x\n", ver);
123 return new X10TV(mwindow, ifds, nfds);
131 int ret = select(mfd, &rds, 0, 0, 0);
133 int fd = -1, k = ret > 0 ? nfds : 0;
136 if( FD_ISSET(ifd, &rds) ) {
141 printf("select failed\n");
142 usleep(100000); continue;
144 ret = read(fd, ev, sizeof(*ev));
146 if( ret != sizeof(*ev) ) {
147 if( ret < 0 ) { perror("read event"); break; }
148 fprintf(stderr, "bad read: %d\n", ret);
155 int X10TV::check_menu_keys(int code)
163 Record *record = mwindow->gui->record;
164 if( !record->running() )
167 record->record_gui->interrupt_thread->start(0);
171 mwindow->gui->channel_info->toggle_scan();
175 RemoteControl *remote_control = mwindow->gui->remote_control;
176 if( !remote_control->deactivate() )
177 remote_control->activate();
185 void X10TV::handle_event(int fd)
189 if( !ev->value ) break;
190 this->last_code = this->code;
191 this->code = ev->code;
192 if( check_menu_keys(code) ) break;
193 RemoteHandler *handler = mwindow->gui->remote_control->handler;
195 handler->process_key(ev->code);
201 time_t t = ev->time.tv_sec;
202 struct tm *tp = localtime(&t);
203 printf("x10tv event %d: %4d/%02d/%02d %02d:%02d:%02d.%03d = (%d, %d, 0x%x)\n",
204 fd, tp->tm_year+1900, tp->tm_mon+1, tp->tm_mday,
205 tp->tm_hour, tp->tm_min, tp->tm_sec,
206 (int)ev->time.tv_usec/1000, ev->type, ev->code, ev->value);
212 int X10TVCWindowHandler::x10tv_process_code(int code)
214 MWindow *mwindow = x10tv->mwindow;
215 EDL *edl = mwindow->edl;
217 PlayTransport *transport = mwindow->gui->mbuttons->transport;
218 if( !transport->get_edl() ) return 0;
219 PlaybackEngine *engine = transport->engine;
220 double position = engine->get_tracking_position();
221 double length = edl->tracks->total_length();
222 int next_command = -1;
227 case X10_POWER: break;
231 case X10_BOOK: break;
232 case X10_EDIT: break;
233 case X10_VOLDN: return 1;
234 case X10_VOLUP: return 1;
235 case X10_MUTE: break;
236 case X10_CH_DN: break;
237 case X10_CH_UP: break;
238 // select window tile config = BACK 1,2,3
239 case X10_1: case X10_2: case X10_3:
240 if( mwindow->x10tv->last_code == X10_MENU ) {
241 RemoteGUI *rgui = mwindow->gui->cwindow_remote_handler->gui;
242 rgui->tile_windows(code - X10_1);
245 // select asset program config = TEXT 1,2,3,4,5,6
246 case X10_4: case X10_5: case X10_6:
247 if( mwindow->x10tv->last_code == X10_SETUP ) {
248 mwindow->select_asset(code - X10_1, 1);
251 case X10_7: case X10_8: case X10_9:
253 // select position in 10 percent units
254 position = length * (code - X10_0)/10.0;
256 case X10_MENU: return 0;
257 case X10_SETUP: return 0;
258 case X10_C: return 1;
259 case X10_UP: position += 60.0; break;
260 case X10_D: return 1;
261 case X10_PROPS: return 1;
262 case X10_LT: position -= 10.0; break;
263 case X10_OK: return 1;
264 case X10_RT: position += 10.0; break;
266 CWindowCanvas *canvas = mwindow->cwindow->gui->canvas;
267 int on = canvas->get_fullscreen() ? 0 : 1;
268 canvas->Canvas::set_fullscreen(on, 0);
270 case X10_E: return 1;
271 case X10_DN: position -= 60.0; break;
272 case X10_F: return 1;
273 case X10_REW: next_command = FAST_REWIND; break;
274 case X10_PLAY: next_command = NORMAL_FWD; break;
275 case X10_FWD: next_command = FAST_FWD; break;
276 case X10_REC: next_command = SLOW_REWIND; break;
277 case X10_STOP: next_command = STOP; break;
278 case X10_PAUSE: next_command = SLOW_FWD; break;
281 printf("x10tv cwindow: unknown code: %04x\n", code);
285 if( next_command < 0 ) {
286 if( position < 0 ) position = 0;
287 transport->change_position(position);
290 transport->handle_transport(next_command);
294 int X10TVCWindowHandler::process_key(int key)
296 return x10tv_process_code(key);
299 int X10TVRecordHandler::process_key(int key)
301 Record *record = x10tv->mwindow->gui->record;
302 return record->x10tv_process_code(key);
306 X10TVRecordHandler::X10TVRecordHandler(X10TV *x10tv, RemoteControl *remote_control)
307 : RemoteHandler(remote_control->gui, GREEN)
312 X10TVCWindowHandler::X10TVCWindowHandler(X10TV *x10tv, RemoteControl *remote_control)
313 : RemoteHandler(remote_control->gui, BLUE)