]> git.vomp.tv Git - vompclient.git/blob - remotewin.cc
Change WSelectList option data to void*. About 65 CWFs
[vompclient.git] / remotewin.cc
1 /*
2     Copyright 2004-2005 Chris Tallon
3
4     This file is part of VOMP.
5
6     VOMP is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     VOMP is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with VOMP; if not, write to the Free Software
18     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19 */
20
21 #include "remotewin.h"
22 #include "vompreswin.h"
23 #include "i18n.h"
24
25 #define W_G_HCW(type,code) ( (((ULLONG)(type))<<32) | code)
26
27 #define W_HCW_VK 1 /* virtual key */
28 #define W_HCW_AP 2 /* App command */
29 #define W_HCW_RI 3 /* remote control */
30 #define W_HCW_CH 4 /* char */
31
32 RemoteWin::RemoteWin()
33 {
34   initted = 0;
35   curevent=0;
36   hascurevent=false;
37   signal=false;
38 }
39
40 RemoteWin::~RemoteWin()
41 {
42 }
43
44 int RemoteWin::init(const char* devName)
45 {
46   if (initted) return 0;
47   initted = 1;
48   event = CreateEvent(NULL,/*FALSE*/TRUE,FALSE,NULL);
49
50
51   return 1;
52 }
53
54 int RemoteWin::shutdown()
55 {
56   if (!initted) return 0;
57   CloseHandle(event);
58   initted = 0;
59   return 1;
60 }
61
62 UCHAR RemoteWin::getButtonPress(int waitType)
63 {
64   /* how = 0 - block
65      how = 1 - start new wait
66      how = 2 - continue wait
67      how = 3 - no wait
68   */
69   DWORD wait;
70   
71
72   if (hascurevent) {
73           UCHAR temp=curevent;
74       hascurevent=false;
75
76           return temp;
77   }
78   if (waitType==3) {
79           return NA_NONE;
80   }
81   if (waitType==0) {
82           wait=INFINITE;
83   } else { //We do not distingish between 2 and 3
84           wait=1000;
85
86   }
87   WaitForSingleObject(event,wait);
88   ResetEvent(event);
89   if (!hascurevent) {
90           if (signal) {
91                   signal=false;
92                   return NA_SIGNAL; //Since we have no signals on windows, we simulate this
93           } else {
94                   return NA_NONE;
95           }
96   }
97   UCHAR temp2=curevent;
98   hascurevent=false;
99   return temp2;
100   
101 }
102
103 UCHAR RemoteWin::TranslateHWCFixed(ULLONG code)
104 {
105     switch (code) 
106     {
107     case W_G_HCW(W_HCW_VK,VK_DOWN):
108         return DOWN;
109     case W_G_HCW(W_HCW_VK,VK_UP):
110         return UP;
111     case W_G_HCW(W_HCW_VK,VK_LEFT):
112         return LEFT;
113     case W_G_HCW(W_HCW_VK,VK_RIGHT):
114         return RIGHT;
115     case W_G_HCW(W_HCW_CH,'m'):
116         return MENU;
117     case W_G_HCW(W_HCW_VK,VK_BACK):
118         return BACK;
119     case W_G_HCW(W_HCW_VK,VK_RETURN):
120     case W_G_HCW(W_HCW_VK,VK_SPACE):
121         return OK;
122     /* Menu IDs, no sense to make it user selectable */
123     case W_G_HCW(W_HCW_AP,APPCOMMAND_BROWSER_BACKWARD):
124                 return BACK;
125         case W_G_HCW(W_HCW_AP,APPCOMMAND_MEDIA_CHANNEL_DOWN):
126                 return CHANNELDOWN;break;
127         case W_G_HCW(W_HCW_AP,APPCOMMAND_MEDIA_CHANNEL_UP):
128                 return CHANNELUP;break;
129         case W_G_HCW(W_HCW_AP,APPCOMMAND_MEDIA_FAST_FORWARD):
130                 return FORWARD;break;
131         case W_G_HCW(W_HCW_AP,APPCOMMAND_VOLUME_MUTE):
132                 return MUTE;break;
133         case W_G_HCW(W_HCW_AP,APPCOMMAND_MEDIA_PAUSE):
134                 return PAUSE;break;
135         case W_G_HCW(W_HCW_AP,APPCOMMAND_MEDIA_PLAY):
136                 return PLAY;break;
137         case W_G_HCW(W_HCW_AP,APPCOMMAND_MEDIA_RECORD):
138                 return RECORD;break;
139         case W_G_HCW(W_HCW_AP,APPCOMMAND_MEDIA_PREVIOUSTRACK):
140                 return SKIPBACK;break;
141         case W_G_HCW(W_HCW_AP,APPCOMMAND_MEDIA_REWIND):
142                 return REVERSE;break;
143         case W_G_HCW(W_HCW_AP,APPCOMMAND_MEDIA_NEXTTRACK):
144                 return SKIPFORWARD;break;
145         case W_G_HCW(W_HCW_AP,APPCOMMAND_MEDIA_STOP):
146                 return STOP;break;
147         case W_G_HCW(W_HCW_AP,APPCOMMAND_VOLUME_DOWN):
148                 return VOLUMEDOWN;break;
149         case W_G_HCW(W_HCW_AP,APPCOMMAND_VOLUME_UP):
150                 return VOLUMEUP;break;
151         case W_G_HCW(W_HCW_AP,VOMP_YELLOW):
152                 return YELLOW; break;
153         case W_G_HCW(W_HCW_AP,VOMP_BLUE):
154                 return BLUE;break;
155         case W_G_HCW(W_HCW_AP,VOMP_RED):
156                 return RED;break;
157         case W_G_HCW(W_HCW_AP,VOMP_GREEN):
158                 return GREEN;break;
159         case W_G_HCW(W_HCW_AP,VOMP_ENTER):
160                 return OK;break;
161         case W_G_HCW(W_HCW_AP,VOMP_CANCEL):
162                 return BACK;break;
163         case W_G_HCW(W_HCW_AP,VOMP_UP):
164                 return UP;break;
165         case W_G_HCW(W_HCW_AP,VOMP_DOWN):
166                 return DOWN;break;
167         case W_G_HCW(W_HCW_AP,VOMP_LEFT):
168                 return LEFT;break;
169         case W_G_HCW(W_HCW_AP,VOMP_RIGHT):
170                 return RIGHT;break;
171     case POWER:
172         return POWER;
173     default:
174         return NA_UNKNOWN;
175     };
176 }
177
178 const char*RemoteWin::HardcodedTranslateStr(UCHAR command)
179 {
180     switch (command) 
181     {
182     case DOWN:
183         return tr("Down");
184     case UP:
185         return tr("Up");
186     case LEFT:
187         return tr("Left");
188     case RIGHT:
189         return tr("Right");
190     case MENU:
191         return tr("M");
192     case BACK:
193         return tr("Backspace, Back");
194     case OK:
195         return tr("Return, Space");
196     case CHANNELDOWN:
197         return tr("Insrt, C+Insrt, Pg down");
198     case CHANNELUP:
199         return tr("+, C++, Pg up");
200     case VOLUMEUP:
201         return "F10";
202     case VOLUMEDOWN:
203         return "F9";
204     case POWER:
205         return "Esc, A+F4";
206     case MUTE:
207         return "F8";
208     case REVERSE:
209         return"S+C+B";
210     case FORWARD:
211         return "S+C+F";
212     case SKIPBACK:
213         return "C+B";
214     case SKIPFORWARD:
215         return "C+F";
216     case PLAY:
217         return "S+P";
218     case STOP:
219         return "C+S";
220     case PAUSE:
221         return "C+P";
222     default:
223         return NULL;
224     };
225     
226 }
227
228
229 void RemoteWin::InitHWCListwithDefaults()
230 {
231     //Processing VK_Messages
232     translist[W_G_HCW(W_HCW_CH,'9')] = NINE;
233     translist[W_G_HCW(W_HCW_CH,'8')] = EIGHT;
234     translist[W_G_HCW(W_HCW_CH,'7')] = SEVEN;
235     translist[W_G_HCW(W_HCW_CH,'6')] = SIX;
236     translist[W_G_HCW(W_HCW_CH,'5')] = FIVE;
237     translist[W_G_HCW(W_HCW_CH,'4')] = FOUR;
238     translist[W_G_HCW(W_HCW_CH,'3')] = THREE;
239     translist[W_G_HCW(W_HCW_CH,'2')] = TWO;
240     translist[W_G_HCW(W_HCW_CH,'1')] = ONE;
241     translist[W_G_HCW(W_HCW_CH,'0')] = ZERO;
242     translist[W_G_HCW(W_HCW_CH,'*')] = STAR;
243     translist[W_G_HCW(W_HCW_CH,'#')] = HASH;
244     translist[W_G_HCW(W_HCW_CH,'j')] = GO; //j for JUMP TO instead of go to
245     translist[W_G_HCW(W_HCW_CH,'r')] = RED; 
246     translist[W_G_HCW(W_HCW_CH,'g')] = GREEN;
247     translist[W_G_HCW(W_HCW_CH,'y')] = YELLOW; 
248     translist[W_G_HCW(W_HCW_CH,'b')] = BLUE; 
249     //Processing RI Messages
250     translist[W_G_HCW(W_HCW_RI,0x35c)] = GREEN;
251     translist[W_G_HCW(W_HCW_RI,0x35b)] = RED;
252     translist[W_G_HCW(W_HCW_RI,0x35d)] = YELLOW;
253     translist[W_G_HCW(W_HCW_RI,0x35e)] = BLUE;
254     translist[W_G_HCW(W_HCW_RI,0x30d)] = MENU;//MCE Button, used for Menu
255     translist[W_G_HCW(W_HCW_RI,0x348)] = RECORD; //Record Television
256     translist[W_G_HCW(W_HCW_RI,0x325)] = PLAY; //Playback Televison 
257     translist[W_G_HCW(W_HCW_RI,0x324)] = PLAY; //Playback DVD
258     translist[W_G_HCW(W_HCW_RI,0x209)] = OK;//Properties
259     translist[W_G_HCW(W_HCW_RI,0x35a)] = OK;//Teletext?
260
261 }
262
263 char* RemoteWin::HCWDesc(ULLONG hcw)
264 {
265     //Determine type
266     ULONG type =  hcw >> 32;
267     char *rt=NULL;
268     switch(type)
269     {
270     case W_HCW_VK:{
271         ULONG vk=(ULONG)hcw;
272         ULONG scancode=MapVirtualKey(vk,0);
273         rt=new char[10];
274         GetKeyNameText(scancode << 16,rt,10); 
275                   }break;
276     case W_HCW_CH:{
277         ULONG ch=(ULONG)hcw;
278         ULONG scancode=OemKeyScan(ch);
279   
280         rt=new char[10];
281         GetKeyNameText(scancode << 16,rt,10); 
282                   }break;
283     case W_HCW_RI:{
284         ULONG ri=(ULONG)hcw;
285         rt=new char[10];
286         sprintf(rt,"R: %X",ri);
287                   }break;
288
289     };
290     return rt;
291 }
292
293
294 int RemoteWin::ReceiveButtonVK(UINT button) {
295 /*      UCHAR pb=NA_NONE;
296         //should we use a translation table ? No APPCOMMAND iS DWORD!
297         switch (button) { //Processing VK_Messages
298         case VK_DOWN:
299                 pb=DOWN; break;
300         case VK_RETURN:
301         case VK_SPACE:
302                 pb=OK;break;
303         case VK_LEFT:
304                 pb=LEFT;break;
305         case '9':
306         case VK_NUMPAD9:
307                 pb=NINE;break;
308         case '8':
309         case VK_NUMPAD8:
310                 pb=EIGHT;break;
311         case '7':
312         case VK_NUMPAD7:
313                 pb=SEVEN;break;
314         case '6':
315         case VK_NUMPAD6:
316                 pb=SIX;break;
317         case '5':
318         case VK_NUMPAD5:
319                 pb=FIVE;break;
320         case '4':
321         case VK_NUMPAD4:
322                 pb=FOUR;break;
323         case '3':
324         case VK_NUMPAD3:
325                 pb=THREE;break;
326         case '2':
327         case VK_NUMPAD2:
328                 pb=TWO;break;
329         case '1':
330         case VK_NUMPAD1:
331                 pb=ONE;break;
332         case '0':
333         case VK_NUMPAD0:
334                 pb=ZERO;break;
335         case VK_RIGHT:
336                 pb=RIGHT;break;
337         case VK_UP:
338                 pb=UP;break;
339         case VK_MULTIPLY:
340                 pb=STAR;break;
341         case 'J'://j for JUMP TO instead of go to
342                 pb=GO;break;
343         //case VK_ESCAPE:
344         //      pb=POWER;break;
345         case VK_BACK:
346                 pb=BACK;break;
347         case 'M':
348                 pb=MENU;break;
349         case 'R':
350                 pb=RED;break;
351         case 'G':
352                 pb=GREEN;break;
353         case 'Y':
354                 pb=YELLOW;break;
355         case 'B':
356                 pb=BLUE; break;
357
358
359         }; //All other commands are process via APPCOMMAND_MESSAGES
360         if (pb==NA_NONE) return 0;*/
361     UCHAR pb=NA_NONE;
362         pb=TranslateHWC(W_G_HCW(W_HCW_VK,button));
363     if (pb==NA_UNKNOWN || pb==NA_NONE) return 0;
364     curevent=pb;
365     hascurevent=true;
366         //PulseEvent(event);
367         SetEvent(event);
368         return 1;
369 }
370
371 int RemoteWin::ReceiveButtonCH(UINT button) {
372     UCHAR pb=NA_NONE;
373         pb=TranslateHWC(W_G_HCW(W_HCW_CH,button));
374     if (pb==NA_UNKNOWN || pb==NA_NONE) return 0;
375     curevent=pb;
376     hascurevent=true;
377         //PulseEvent(event);
378         SetEvent(event);
379         return 1;
380 }
381
382 int RemoteWin::ReceiveButtonAP(UINT button) {
383 /*      UCHAR pb=NA_NONE;
384         //should we use a translation table ? No APPCOMMAND iS DWORD!
385         switch (button) { //Processing VK_Messages
386         case APPCOMMAND_BROWSER_BACKWARD:
387                 pb=BACK;break;
388         case APPCOMMAND_MEDIA_CHANNEL_DOWN:
389                 pb=CHANNELDOWN;break;
390         case APPCOMMAND_MEDIA_CHANNEL_UP:
391                 pb=CHANNELUP;break;
392         case APPCOMMAND_MEDIA_FAST_FORWARD:
393                 pb=FORWARD;break;
394         case APPCOMMAND_VOLUME_MUTE:
395                 pb=MUTE;break;
396         case APPCOMMAND_MEDIA_PAUSE:
397                 pb=PAUSE;break;
398         case APPCOMMAND_MEDIA_PLAY:
399                 pb=PLAY;break;
400         case APPCOMMAND_MEDIA_RECORD:
401                 pb=RECORD;break;
402         case APPCOMMAND_MEDIA_PREVIOUSTRACK:
403                 pb=SKIPBACK;break;
404         case APPCOMMAND_MEDIA_REWIND:
405                 pb=REVERSE;break;
406         case APPCOMMAND_MEDIA_NEXTTRACK:
407                 pb=SKIPFORWARD;break;
408         case APPCOMMAND_MEDIA_STOP:
409                 pb=STOP;break;
410         case APPCOMMAND_VOLUME_DOWN:
411                 pb=VOLUMEDOWN;break;
412         case APPCOMMAND_VOLUME_UP:
413                 pb=VOLUMEUP;break;
414         case VOMP_YELLOW:
415                 pb=YELLOW; break;
416         case VOMP_BLUE:
417                 pb=BLUE;break;
418         case VOMP_RED:
419                 pb=RED;break;
420         case VOMP_GREEN:
421                 pb=GREEN;break;
422         case VOMP_ENTER:
423                 pb=OK;break;
424         case VOMP_CANCEL:
425                 pb=BACK;break;
426         case VOMP_UP:
427                 pb=UP;break;
428         case VOMP_DOWN:
429                 pb=DOWN;break;
430         case VOMP_LEFT:
431                 pb=LEFT;break;
432         case VOMP_RIGHT:
433                 pb=RIGHT;break;
434         };*/
435     
436         //if (pb==NA_NONE) return 0;
437     UCHAR pb=NA_NONE;
438         pb=TranslateHWC(W_G_HCW(W_HCW_AP,button));
439     if (pb==NA_UNKNOWN || pb==NA_NONE) return 0;
440     curevent=pb;
441     hascurevent=true;
442         //PulseEvent(event);
443         SetEvent(event);
444         return 1;
445 }
446
447 int RemoteWin::ReceiveButtonRI(UINT button) {
448         //UCHAR pb=NA_NONE;
449         //Raw Input
450         /* Note Codes above 0x29c are not listed in the specs on usb.org
451            therefore they are used by try, they might be device dependent
452            thus please supply codes of your remote control */
453 /*      switch (button) { //Processing VK_Messages
454         case 0x35c: //Green
455                 pb=GREEN;break;
456         case 0x35b: //Red
457                 pb=RED;break;
458         case 0x35d: //Yellow
459                 pb=YELLOW;break;
460         case 0x35e: //Blue
461                 pb=BLUE;break;
462         case 0x30d: //MCE Button, used for Menu
463                 pb=MENU;break;
464         case 0x348: //Record Television
465                 pb=RECORD;break;
466         case 0x28d: //Attach File Mmh, how should we assign this
467                 pb=NA_NONE;break;
468         case 0x325: //Playback Televison
469                 pb=PLAY;break;
470         case 0x324: //Playback DVD
471                 pb=PLAY;break;
472         case 0x209: //Properties
473         case 0x35a: //Teletext?
474                 pb=OK;break;
475
476         
477         };
478         if (pb==NA_NONE) return 0;*/
479
480     UCHAR pb=NA_NONE;
481         pb=TranslateHWC(W_G_HCW(W_HCW_RI,button));
482     if (pb==NA_UNKNOWN || pb==NA_NONE) return 0;
483     curevent=pb;
484     hascurevent=true;
485         //PulseEvent(event);
486         SetEvent(event);
487         return 1;
488 }
489
490 void RemoteWin::Signal() {
491         signal=true;
492         //PulseEvent(event);
493         SetEvent(event);
494 }
495
496 void RemoteWin::SendPower()
497 {
498
499         curevent=POWER;
500     hascurevent=true;
501         SetEvent(event);
502 }
503