trunk 20080912
[gitenigma.git] / boot / bootmenue / my_rc.cpp
blobd34ad805a25b5893daeeeaa96cae8e2dce4562b7
1 #ifdef HAVE_DREAMBOX_HARDWARE
2 #include "my_rc.h"
4 RcInput::RcInput()
6 char buf[32];
8 fd_rc=open(RC_DEVICE, O_RDONLY);
9 if (fd_rc<0)
11 perror(RC_DEVICE);
12 exit(-1);
14 fcntl(fd_rc, F_SETFL, O_NONBLOCK );
15 read( fd_rc, buf, 32 );
17 pthread_join(thrRc,NULL);
18 if (pthread_create (&thrRc, NULL, ThreadRc, (void *) fd_rc) != 0 )
19 perror("[RcInput] pthread_created error");
21 //bu
22 fd_bu=open(BUTTON_DEVICE, O_RDONLY);
23 if (fd_bu<0)
25 perror(BUTTON_DEVICE);
26 exit(-1);
28 pthread_join(thrBu,NULL);
29 if (pthread_create (&thrBu, NULL, ThreadBu, (void *) fd_bu) != 0 )
30 perror("[ButtonInput] pthread_created error");
33 void* RcInput::ThreadBu(void * fd_bu)
35 printf("[ButtonInput] available\n");
36 static unsigned short bucode=0;
37 unsigned short rccode=0;
38 while (1)
40 if (read((int)fd_bu, &bucode, 2)==2)
41 if(bucode != BUTTON_BREAK)
43 switch(bucode)
45 case BUTTON_EXIT: rccode = RC_EXIT; break;
46 case BUTTON_UP: rccode = RC_UP; break;
47 case BUTTON_DOWN: rccode = RC_DOWN; break;
49 RcInput::getInstance()->selected(rccode);
52 usleep(10000);//repeattimer
55 pthread_exit(0);
56 return NULL;
59 void* RcInput::ThreadRc(void * fd_rc)
61 printf("[RCInput] available\n");
62 static unsigned short rccode=0;
63 while (1)
65 if (read((int)fd_rc, &rccode, 2)==2)
66 if (rccode != RC_BREAK && rccode < 0x8000)
67 RcInput::getInstance()->selected(rccode);
69 usleep(10000);//repeattimer
72 pthread_exit(0);
73 return NULL;
75 RcInput::~RcInput()
77 pthread_exit(0);
78 if (fd_rc >= 0) close(fd_rc);
79 if (fd_bu >= 0) close(fd_bu);
82 RcInput* RcInput::getInstance()
84 static RcInput* rcinput = NULL;
85 if(rcinput == NULL) { rcinput = new RcInput(); }
86 return rcinput;
88 #endif