]> git.vomp.tv Git - vompclient-marten.git/blob - remotelinux.cc
Fix fastforward and backward, some change to pause
[vompclient-marten.git] / remotelinux.cc
1 /*
2     Copyright 2004-2005 Chris Tallon; 2012 Marten Richter
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 "remotelinux.h"
22 #include "i18n.h"
23 #include <linux/input.h>
24 #include <sys/types.h>
25
26
27 #include <errno.h>
28
29 #include <sys/stat.h>
30 #include <fcntl.h>
31
32 #include <cstdio>
33 #include <iostream>
34 #include <ostream>
35
36 #include <bcm_host.h>
37
38 using namespace std;
39 using namespace CEC;
40
41 #include <libcec/cecloader.h>
42
43
44
45
46 #define W_G_HCW(type,code) ( (((ULLONG)(type))<<32) | code)
47
48 #define W_HCW_KC 1 /* key code as defined by kernel for keyboard and remotes through /dev/input */
49 #define W_HCW_CEC 2 /* HDMI_CEC */
50 #define W_HCW_LIRC 3 /* remote control LIRC*/
51
52
53 RemoteLinux::RemoteLinux()
54 {
55   initted = 0;
56   curcec=0;
57   hascurcec=false;
58   signal=false;
59   cec_adap=NULL;
60   num_loop=0;
61
62 }
63
64 RemoteLinux::~RemoteLinux()
65 {
66         for (unsigned int i=0; i<devices.size();i++) {
67                 close(devices[i]);
68         }
69 }
70
71 #define test_bit(input,b)  ((1 << ((b) % 8))&(input)[b / 8] )
72
73
74 int RemoteLinux::init(char* devName)
75 {
76   if (initted) return 0;
77   initted = 1;
78
79   InitKeymap();
80
81   for (int eventid=0;eventid<100;eventid++){
82           char buffer[1024];
83           sprintf(buffer,"/dev/input/event%d",eventid);
84
85
86           struct stat test_buf;
87           if (stat(buffer,&test_buf)==0) {
88                   Log::getInstance()->log("Remote", Log::NOTICE, "Probe /dev/input/event%d",eventid);
89                   // file exists
90                   unsigned long ev_type=0;
91                   int new_fd=open(buffer,O_RDONLY);
92                   if (new_fd<0) {
93                           Log::getInstance()->log("Remote", Log::NOTICE, "Can not open /dev/input/event%d",eventid);
94                           continue;
95                   }
96                   if (ioctl(new_fd, EVIOCGBIT(0, EV_MAX), &ev_type) < 0) {
97                           Log::getInstance()->log("Remote", Log::NOTICE, "Ioctl failed /dev/input/event%d %d",eventid,errno);
98                       close(new_fd);
99                   }
100                   //Now test if it generates keyboard presses
101                   if (test_bit((char*)&ev_type , EV_KEY)) {
102                           Log::getInstance()->log("Remote", Log::NOTICE, "Add /dev/input/event%d to List",eventid);
103                           devices.push_back(new_fd);
104                   } else {
105                           close(new_fd);
106                   }
107
108
109
110
111           }
112
113
114
115
116
117   }
118   return initCec();
119 }
120
121 int RemoteLinux::initCec() {
122
123   // bcm_host_init(); //may be move to custom hardware init?
124 // now init cec
125         Log::getInstance()->log("Remote", Log::NOTICE, "Init LibCEC");
126         cec_config.Clear();
127         cec_callbacks.Clear();
128         cec_callbacks.CBCecLogMessage = cecLogMessage;
129         cec_callbacks.CBCecKeyPress = cecKeyPress;
130         cec_callbacks.CBCecCommand = cecCommand;
131         cec_callbacks.CBCecConfigurationChanged = cecConfigurationChanged;
132         cec_config.clientVersion=LIBCEC_VERSION_CURRENT;
133         cec_config.bActivateSource=1;
134         cec_config.bUseTVMenuLanguage=1;
135         //cec_config.deviceTypes.Add(CEC_DEVICE_TYPE_PLAYBACK_DEVICE);
136         cec_config.deviceTypes.Add(CEC_DEVICE_TYPE_TUNER);
137
138         strncpy(cec_config.strDeviceName,"vomp",sizeof(cec_config.strDeviceName));
139
140
141         cec_config.callbackParam = NULL; // I do not care
142         cec_config.callbacks = &cec_callbacks;
143
144         cec_adap = LibCecInitialise(&cec_config);
145         if (!cec_adap) {
146                 Log::getInstance()->log("Remote", Log::ERR, "Init LibCEC failed");
147                 return 1;
148         }
149         cec_adap->InitVideoStandalone();
150
151
152         cec_adapter  cec_devices[10];
153         int adap_num=cec_adap->FindAdapters(cec_devices,10,NULL);
154         if (adap_num<0) {
155                 Log::getInstance()->log("Remote", Log::ERR, "CEC:Failed to find adapter");
156                 return 1;
157
158         }
159         if (adap_num==0) {
160                 Log::getInstance()->log("Remote", Log::NOTICE, "CEC: No adapter found");
161                 return 1;
162
163         }
164         if (!cec_adap->Open(cec_devices[0].comm)) {
165                 Log::getInstance()->log("Remote", Log::ERR, "CEC:Failed to open adapter");
166                 return 1;
167         }
168
169         if (!cec_adap->SetActiveSource(cec_config.deviceTypes[0])) {
170                 Log::getInstance()->log("Remote", Log::ERR, "CEC:Failed set active source");
171                 return 1;
172         }
173
174
175
176
177   return 1;
178 }
179
180 int RemoteLinux::shutdown()
181 {
182   if (!initted) return 0;
183   deinitCec();
184
185
186   initted = 0;
187   return 1;
188 }
189
190 void RemoteLinux::deinitCec()
191 {
192         if (cec_adap) {
193                 cec_adap->SetInactiveView();
194                 cec_adap->Close();
195                 UnloadLibCec(cec_adap);
196                 cec_adap = NULL;
197         }
198
199 }
200
201 UCHAR RemoteLinux::getButtonPress(int waitType) {
202         /* how = 0 - block
203          how = 1 - start new wait
204          how = 2 - continue wait
205          how = 3 - no wait
206          */
207
208          //in units of 40 ms
209
210         int retval;
211         fd_set readfds;
212         struct timeval tv;
213
214         tv.tv_sec = 0;
215         tv.tv_usec = 40000;
216         if (waitType == 0) {
217                 num_loop = -1;
218         } else if (waitType == 1) {
219
220                 num_loop = 25;
221         } else if (waitType == 2) {
222                 if (num_loop<=0) num_loop = 25;
223         } else if (waitType == 3) {
224                 tv.tv_sec = 0;
225                 tv.tv_usec = 0;
226                 num_loop = 0;
227         }
228
229
230         int ret = 0;
231         while (num_loop!=0) {
232                 ret = NA_UNKNOWN;
233                 FD_ZERO(&readfds);
234
235                 int maxfd = 0;
236                 for (int i = 0; i < devices.size(); i++) {
237                         int cur_fd = devices[i];
238                         maxfd = max(cur_fd, maxfd);
239                         FD_SET(cur_fd, &readfds);
240                 }
241
242                 retval = select(maxfd + 1, &readfds, NULL, NULL, &tv);
243                 tv.tv_sec = 0;
244                 tv.tv_usec = 40000;
245                 // 0 = nothing happened
246                 // 1 = data arrived (actually num of descriptors that changed)
247                 // other value = signal or error
248                 if (retval == 0) {
249                         if (hascurcec) {
250                                 hascurcec = false;
251                                 return (UCHAR) TranslateHWC(W_G_HCW(W_HCW_CEC,curcec));
252                         }
253                         ret = NA_NONE;
254                 } else {
255                         if (retval == -1) {
256                                 Log::getInstance()->log("Remote", Log::NOTICE, "na_signal");
257                                 return NA_SIGNAL;
258
259                         }
260                         for (int i = 0; i < devices.size(); i++) {
261                                 int cur_fd = devices[i];
262                                 if (FD_ISSET(cur_fd, &readfds)) {
263                                         struct input_event ev;
264                                         int count = read(cur_fd, &ev, sizeof(ev));
265                                         if (count == sizeof(ev)) {
266                                                 if (ev.type == EV_KEY && ev.value == 1) {
267                                                         UCHAR retty=(UCHAR) TranslateHWC(
268                                                                                         W_G_HCW(W_HCW_KC,ev.code));
269                                                         return retty;
270                                                 }
271                                         }
272
273                                 }
274
275                         }
276
277                 }
278                 //Log::getInstance()->log("Remote", Log::NOTICE, "numloop: %d %d",num_loop,retval);
279                 if (num_loop > 0)
280                 num_loop--;
281         }
282         if (ret != 0)
283                 return ret;
284
285         return NA_UNKNOWN;
286
287 }
288
289 void RemoteLinux::clearBuffer()
290 {
291           while(getButtonPress(3) != NA_NONE);
292 }
293
294 UCHAR RemoteLinux::TranslateHWCFixed(ULLONG code)
295 {
296     switch (code) 
297     {
298     case W_G_HCW(W_HCW_KC,KEY_DOWN):
299         return DOWN;
300     case W_G_HCW(W_HCW_KC,KEY_UP):
301         return UP;
302     case W_G_HCW(W_HCW_KC,KEY_LEFT):
303         return LEFT;
304     case W_G_HCW(W_HCW_KC,KEY_RIGHT):
305         return RIGHT;
306     case W_G_HCW(W_HCW_KC,KEY_M):
307         return MENU;
308     case W_G_HCW(W_HCW_KC,KEY_BACKSPACE):
309         return BACK;
310     case W_G_HCW(W_HCW_KC,KEY_ENTER):
311     case W_G_HCW(W_HCW_KC,KEY_SPACE):
312     case W_G_HCW(W_HCW_KC,KEY_OK):
313         return OK;
314     //CEC
315     case W_G_HCW(W_HCW_CEC,CEC_USER_CONTROL_CODE_DOWN):
316         return DOWN;
317     case W_G_HCW(W_HCW_CEC,CEC_USER_CONTROL_CODE_UP):
318         return UP;
319     case W_G_HCW(W_HCW_CEC,CEC_USER_CONTROL_CODE_LEFT):
320         return LEFT;
321     case W_G_HCW(W_HCW_CEC,CEC_USER_CONTROL_CODE_RIGHT):
322         return RIGHT;
323     case W_G_HCW(W_HCW_CEC,CEC_USER_CONTROL_CODE_ROOT_MENU):
324     case W_G_HCW(W_HCW_CEC,CEC_USER_CONTROL_CODE_CONTENTS_MENU):
325     case W_G_HCW(W_HCW_CEC,CEC_USER_CONTROL_CODE_SETUP_MENU):
326         return MENU;
327     case W_G_HCW(W_HCW_CEC,CEC_USER_CONTROL_CODE_EXIT ):
328         return BACK;
329     case W_G_HCW(W_HCW_CEC,CEC_USER_CONTROL_CODE_ENTER):
330     case W_G_HCW(W_HCW_CEC,CEC_USER_CONTROL_CODE_SELECT):
331     case W_G_HCW(W_HCW_CEC,CEC_USER_CONTROL_CODE_AN_RETURN):
332         return OK;
333     case POWER:
334         return POWER;
335     default:
336         return NA_UNKNOWN;
337     };
338 }
339
340 const char*RemoteLinux::HardcodedTranslateStr(UCHAR command)
341 {
342     switch (command) 
343     {
344     case DOWN:
345         return tr("Down");
346     case UP:
347         return tr("Up");
348     case LEFT:
349         return tr("Left");
350     case RIGHT:
351         return tr("Right");
352     case MENU:
353         return tr("M");
354     case BACK:
355         return tr("Backspace, Back");
356     case OK:
357         return tr("Return, Space");
358     default:
359         return NULL;
360     };
361     
362 }
363
364
365 void RemoteLinux::InitHWCListwithDefaults()
366 {
367     //Processing VK_Messages
368     translist[W_G_HCW(W_HCW_KC,KEY_9)] = NINE;
369     translist[W_G_HCW(W_HCW_KC,KEY_8)] = EIGHT;
370     translist[W_G_HCW(W_HCW_KC,KEY_7)] = SEVEN;
371     translist[W_G_HCW(W_HCW_KC,KEY_6)] = SIX;
372     translist[W_G_HCW(W_HCW_KC,KEY_5)] = FIVE;
373     translist[W_G_HCW(W_HCW_KC,KEY_4)] = FOUR;
374     translist[W_G_HCW(W_HCW_KC,KEY_3)] = THREE;
375     translist[W_G_HCW(W_HCW_KC,KEY_2)] = TWO;
376     translist[W_G_HCW(W_HCW_KC,KEY_1)] = ONE;
377     translist[W_G_HCW(W_HCW_KC,KEY_0)] = ZERO;
378     translist[W_G_HCW(W_HCW_KC,KEY_KPDOT)] = STAR;
379    // translist[W_G_HCW(W_HCW_KC,KEY_#)] = HASH;
380
381     translist[W_G_HCW(W_HCW_KC,KEY_KP9)] = NINE;
382     translist[W_G_HCW(W_HCW_KC,KEY_KP8)] = EIGHT;
383     translist[W_G_HCW(W_HCW_KC,KEY_KP7)] = SEVEN;
384     translist[W_G_HCW(W_HCW_KC,KEY_KP6)] = SIX;
385     translist[W_G_HCW(W_HCW_KC,KEY_KP5)] = FIVE;
386     translist[W_G_HCW(W_HCW_KC,KEY_KP4)] = FOUR;
387     translist[W_G_HCW(W_HCW_KC,KEY_KP3)] = THREE;
388     translist[W_G_HCW(W_HCW_KC,KEY_KP2)] = TWO;
389     translist[W_G_HCW(W_HCW_KC,KEY_KP1)] = ONE;
390     translist[W_G_HCW(W_HCW_KC,KEY_KP0)] = ZERO;
391
392     translist[W_G_HCW(W_HCW_KC,KEY_NUMERIC_9)] = NINE;
393         translist[W_G_HCW(W_HCW_KC,KEY_NUMERIC_8)] = EIGHT;
394         translist[W_G_HCW(W_HCW_KC,KEY_NUMERIC_7)] = SEVEN;
395         translist[W_G_HCW(W_HCW_KC,KEY_NUMERIC_6)] = SIX;
396         translist[W_G_HCW(W_HCW_KC,KEY_NUMERIC_5)] = FIVE;
397         translist[W_G_HCW(W_HCW_KC,KEY_NUMERIC_4)] = FOUR;
398         translist[W_G_HCW(W_HCW_KC,KEY_NUMERIC_3)] = THREE;
399         translist[W_G_HCW(W_HCW_KC,KEY_NUMERIC_2)] = TWO;
400         translist[W_G_HCW(W_HCW_KC,KEY_NUMERIC_1)] = ONE;
401         translist[W_G_HCW(W_HCW_KC,KEY_NUMERIC_0)] = ZERO;
402         translist[W_G_HCW(W_HCW_KC,KEY_NUMERIC_STAR)] = STAR;
403         translist[W_G_HCW(W_HCW_KC,KEY_NUMERIC_POUND)] = HASH;
404
405
406     translist[W_G_HCW(W_HCW_KC,KEY_J)] = GO; //j for JUMP TO instead of go to
407     translist[W_G_HCW(W_HCW_KC,KEY_R)] = RED;
408     translist[W_G_HCW(W_HCW_KC,KEY_G)] = GREEN;
409     translist[W_G_HCW(W_HCW_KC,KEY_Y)] = YELLOW;
410     translist[W_G_HCW(W_HCW_KC,KEY_B)] = BLUE;
411     //Processing Remote Style Messages
412     translist[W_G_HCW(W_HCW_KC,KEY_GREEN)] = GREEN;
413     translist[W_G_HCW(W_HCW_KC,KEY_RED)] = RED;
414     translist[W_G_HCW(W_HCW_KC,KEY_YELLOW)] = YELLOW;
415     translist[W_G_HCW(W_HCW_KC,KEY_BLUE)] = BLUE;
416     translist[W_G_HCW(W_HCW_KC,KEY_MENU)] = MENU;
417
418     translist[W_G_HCW(W_HCW_KC,KEY_RECORD)] = RECORD;
419     translist[W_G_HCW(W_HCW_KC,KEY_PLAY)] = PLAY; //Playback Televison
420     translist[W_G_HCW(W_HCW_KC,KEY_PAUSE)] = PAUSE;
421     translist[W_G_HCW(W_HCW_KC,KEY_STOP)] = STOP;
422     translist[W_G_HCW(W_HCW_KC,KEY_PLAYPAUSE)] = PLAYPAUSE;
423     translist[W_G_HCW(W_HCW_KC,KEY_P)] = PLAYPAUSE;
424     translist[W_G_HCW(W_HCW_KC,KEY_NEXT)] = SKIPFORWARD;
425     translist[W_G_HCW(W_HCW_KC,KEY_F2)] = SKIPFORWARD;
426     translist[W_G_HCW(W_HCW_KC,KEY_PREVIOUS)] = SKIPBACK;
427     translist[W_G_HCW(W_HCW_KC,KEY_F1)] = SKIPBACK;
428     translist[W_G_HCW(W_HCW_KC,KEY_FORWARD)] = FORWARD;
429     translist[W_G_HCW(W_HCW_KC,KEY_F)] = FORWARD;
430     translist[W_G_HCW(W_HCW_KC,KEY_BACK)] = REVERSE;
431     translist[W_G_HCW(W_HCW_KC,KEY_T)] = REVERSE;
432     translist[W_G_HCW(W_HCW_KC,KEY_MUTE)] = MUTE;
433     translist[W_G_HCW(W_HCW_KC,KEY_F9)] = VOLUMEUP;
434     translist[W_G_HCW(W_HCW_KC,KEY_F10)] = VOLUMEDOWN;
435     translist[W_G_HCW(W_HCW_KC,KEY_VOLUMEUP)] = VOLUMEUP;
436     translist[W_G_HCW(W_HCW_KC,KEY_VOLUMEDOWN)] = VOLUMEDOWN;
437     translist[W_G_HCW(W_HCW_KC,KEY_CHANNELUP)] = CHANNELUP;
438     translist[W_G_HCW(W_HCW_KC,KEY_CHANNELDOWN)] = CHANNELDOWN;
439     translist[W_G_HCW(W_HCW_KC,KEY_PAGEUP)] = CHANNELUP;
440     translist[W_G_HCW(W_HCW_KC,KEY_PAGEDOWN)] = CHANNELDOWN;
441
442
443     //Processing CEC_Messages
444     translist[W_G_HCW(W_HCW_CEC,CEC_USER_CONTROL_CODE_NUMBER9)] = NINE;
445     translist[W_G_HCW(W_HCW_CEC,CEC_USER_CONTROL_CODE_NUMBER8)] = EIGHT;
446     translist[W_G_HCW(W_HCW_CEC,CEC_USER_CONTROL_CODE_NUMBER7)] = SEVEN;
447     translist[W_G_HCW(W_HCW_CEC,CEC_USER_CONTROL_CODE_NUMBER6)] = SIX;
448     translist[W_G_HCW(W_HCW_CEC,CEC_USER_CONTROL_CODE_NUMBER5)] = FIVE;
449     translist[W_G_HCW(W_HCW_CEC,CEC_USER_CONTROL_CODE_NUMBER4)] = FOUR;
450     translist[W_G_HCW(W_HCW_CEC,CEC_USER_CONTROL_CODE_NUMBER3)] = THREE;
451     translist[W_G_HCW(W_HCW_CEC,CEC_USER_CONTROL_CODE_NUMBER2)] = TWO;
452     translist[W_G_HCW(W_HCW_CEC,CEC_USER_CONTROL_CODE_NUMBER1)] = ONE;
453     translist[W_G_HCW(W_HCW_CEC,CEC_USER_CONTROL_CODE_NUMBER0)] = ZERO;
454     translist[W_G_HCW(W_HCW_CEC,KEY_KPDOT)] = STAR;
455
456
457
458     //translist[W_G_HCW(W_HCW_CEC,KEY_J)] = GO; //j for JUMP TO instead of go to
459     translist[W_G_HCW(W_HCW_CEC,CEC_USER_CONTROL_CODE_F2_RED)] = RED;
460     translist[W_G_HCW(W_HCW_CEC,CEC_USER_CONTROL_CODE_F3_GREEN)] = GREEN;
461     translist[W_G_HCW(W_HCW_CEC,CEC_USER_CONTROL_CODE_F4_YELLOW)] = YELLOW;
462     translist[W_G_HCW(W_HCW_CEC,CEC_USER_CONTROL_CODE_F1_BLUE)] = BLUE;
463     //Processing Remote Style Messages
464     translist[W_G_HCW(W_HCW_CEC,CEC_USER_CONTROL_CODE_FAVORITE_MENU)] = MENU;
465
466     translist[W_G_HCW(W_HCW_CEC,CEC_USER_CONTROL_CODE_RECORD)] = RECORD;
467     translist[W_G_HCW(W_HCW_CEC,CEC_USER_CONTROL_CODE_PLAY)] = PLAY; //Playback Televison
468     translist[W_G_HCW(W_HCW_CEC,CEC_USER_CONTROL_CODE_PAUSE)] = PAUSE;
469     translist[W_G_HCW(W_HCW_CEC,CEC_USER_CONTROL_CODE_STOP)] = STOP;
470     translist[W_G_HCW(W_HCW_CEC,CEC_USER_CONTROL_CODE_PAUSE_PLAY_FUNCTION)] = PLAYPAUSE;
471     translist[W_G_HCW(W_HCW_CEC,CEC_USER_CONTROL_CODE_FORWARD)] = SKIPFORWARD;
472     translist[W_G_HCW(W_HCW_CEC,CEC_USER_CONTROL_CODE_BACKWARD)] = SKIPBACK;
473     translist[W_G_HCW(W_HCW_CEC,CEC_USER_CONTROL_CODE_FAST_FORWARD )] = FORWARD;
474     translist[W_G_HCW(W_HCW_CEC,CEC_USER_CONTROL_CODE_REWIND)] = REVERSE;
475     translist[W_G_HCW(W_HCW_CEC,CEC_USER_CONTROL_CODE_MUTE)] = MUTE;
476     translist[W_G_HCW(W_HCW_CEC,CEC_USER_CONTROL_CODE_VOLUME_UP)] = VOLUMEUP;
477     translist[W_G_HCW(W_HCW_CEC,CEC_USER_CONTROL_CODE_VOLUME_DOWN)] = VOLUMEDOWN;
478     translist[W_G_HCW(W_HCW_CEC,CEC_USER_CONTROL_CODE_CHANNEL_UP )] = CHANNELUP;
479     translist[W_G_HCW(W_HCW_CEC,CEC_USER_CONTROL_CODE_CHANNEL_DOWN)] = CHANNELDOWN;
480
481
482
483 }
484
485 #define NAMETRICK(pre, code) linux_keymap[pre ## code]=  #code
486 #define NAMETRICK2(pre, code) cec_keymap[pre ## code]=  #code
487 //extracte from linux/input.h
488
489 static const char * linux_keymap[KEY_MAX+1];
490 static const char * cec_keymap[CEC_USER_CONTROL_CODE_MAX+1];
491
492 void RemoteLinux::InitKeymap()
493 {
494         for (int i=0;i<KEY_MAX+1;i++) {
495                 linux_keymap[i]=NULL;
496         }
497         NAMETRICK(KEY_,RESERVED);
498         NAMETRICK(KEY_,ESC);
499         NAMETRICK(KEY_,1);
500         NAMETRICK(KEY_,2);
501         NAMETRICK(KEY_,3);
502         NAMETRICK(KEY_,4);
503         NAMETRICK(KEY_,5);
504         NAMETRICK(KEY_,6);
505         NAMETRICK(KEY_,7);
506         NAMETRICK(KEY_,8);
507         NAMETRICK(KEY_,9);
508         NAMETRICK(KEY_,0);
509         NAMETRICK(KEY_,MINUS);
510         NAMETRICK(KEY_,EQUAL);
511         NAMETRICK(KEY_,BACKSPACE);
512         NAMETRICK(KEY_,TAB);
513         NAMETRICK(KEY_,Q);
514         NAMETRICK(KEY_,W);
515         NAMETRICK(KEY_,E);
516         NAMETRICK(KEY_,R);
517         NAMETRICK(KEY_,T);
518         NAMETRICK(KEY_,Y);
519         NAMETRICK(KEY_,U);
520         NAMETRICK(KEY_,I);
521         NAMETRICK(KEY_,O);
522         NAMETRICK(KEY_,P);
523         NAMETRICK(KEY_,LEFTBRACE);
524         NAMETRICK(KEY_,RIGHTBRACE);
525         NAMETRICK(KEY_,ENTER);
526         NAMETRICK(KEY_,LEFTCTRL);
527         NAMETRICK(KEY_,A);
528         NAMETRICK(KEY_,S);
529         NAMETRICK(KEY_,D);
530         NAMETRICK(KEY_,F);
531         NAMETRICK(KEY_,G);
532         NAMETRICK(KEY_,H);
533         NAMETRICK(KEY_,J);
534         NAMETRICK(KEY_,K);
535         NAMETRICK(KEY_,L);
536         NAMETRICK(KEY_,SEMICOLON);
537         NAMETRICK(KEY_,APOSTROPHE);
538         NAMETRICK(KEY_,GRAVE);
539         NAMETRICK(KEY_,LEFTSHIFT);
540         NAMETRICK(KEY_,BACKSLASH);
541         NAMETRICK(KEY_,Z);
542         NAMETRICK(KEY_,X);
543         NAMETRICK(KEY_,C);
544         NAMETRICK(KEY_,V);
545         NAMETRICK(KEY_,B);
546         NAMETRICK(KEY_,N);
547         NAMETRICK(KEY_,M);
548         NAMETRICK(KEY_,COMMA);
549         NAMETRICK(KEY_,DOT);
550         NAMETRICK(KEY_,SLASH);
551         NAMETRICK(KEY_,RIGHTSHIFT);
552         NAMETRICK(KEY_,KPASTERISK);
553         NAMETRICK(KEY_,LEFTALT);
554         NAMETRICK(KEY_,SPACE);
555         NAMETRICK(KEY_,CAPSLOCK);
556         NAMETRICK(KEY_,F1);
557         NAMETRICK(KEY_,F2);
558         NAMETRICK(KEY_,F3);
559         NAMETRICK(KEY_,F4);
560         NAMETRICK(KEY_,F5);
561         NAMETRICK(KEY_,F6);
562         NAMETRICK(KEY_,F7);
563         NAMETRICK(KEY_,F8);
564         NAMETRICK(KEY_,F9);
565         NAMETRICK(KEY_,F10);
566         NAMETRICK(KEY_,NUMLOCK);
567         NAMETRICK(KEY_,SCROLLLOCK);
568         NAMETRICK(KEY_,KP7);
569         NAMETRICK(KEY_,KP8);
570         NAMETRICK(KEY_,KP9);
571         NAMETRICK(KEY_,KPMINUS);
572         NAMETRICK(KEY_,KP4);
573         NAMETRICK(KEY_,KP5);
574         NAMETRICK(KEY_,KP6);
575         NAMETRICK(KEY_,KPPLUS);
576         NAMETRICK(KEY_,KP1);
577         NAMETRICK(KEY_,KP2);
578         NAMETRICK(KEY_,KP3);
579         NAMETRICK(KEY_,KP0);
580         NAMETRICK(KEY_,KPDOT);
581         NAMETRICK(KEY_,F11);
582         NAMETRICK(KEY_,F12);
583         NAMETRICK(KEY_,KPENTER);
584         NAMETRICK(KEY_,RIGHTCTRL);
585         NAMETRICK(KEY_,KPSLASH);
586         NAMETRICK(KEY_,SYSRQ);
587         NAMETRICK(KEY_,RIGHTALT);
588         NAMETRICK(KEY_,LINEFEED);
589         NAMETRICK(KEY_,HOME);
590         NAMETRICK(KEY_,UP);
591         NAMETRICK(KEY_,PAGEUP);
592         NAMETRICK(KEY_,LEFT);
593         NAMETRICK(KEY_,RIGHT);
594         NAMETRICK(KEY_,END);
595         NAMETRICK(KEY_,DOWN);
596         NAMETRICK(KEY_,PAGEDOWN);
597         NAMETRICK(KEY_,INSERT);
598         NAMETRICK(KEY_,DELETE);
599         NAMETRICK(KEY_,MACRO);
600         NAMETRICK(KEY_,MUTE);
601         NAMETRICK(KEY_,VOLUMEDOWN);
602         NAMETRICK(KEY_,VOLUMEUP);
603         NAMETRICK(KEY_,POWER);
604         NAMETRICK(KEY_,KPEQUAL);
605         NAMETRICK(KEY_,KPPLUSMINUS);
606         NAMETRICK(KEY_,PLAY);
607         NAMETRICK(KEY_,PAUSE);
608         NAMETRICK(KEY_,SCALE);
609         NAMETRICK(KEY_,KPCOMMA);
610         NAMETRICK(KEY_,YEN);
611         NAMETRICK(KEY_,LEFTMETA);
612         NAMETRICK(KEY_,RIGHTMETA);
613         NAMETRICK(KEY_,COMPOSE);
614         NAMETRICK(KEY_,STOP);
615         NAMETRICK(KEY_,AGAIN);
616         NAMETRICK(KEY_,PROPS);
617         NAMETRICK(KEY_,UNDO);
618         NAMETRICK(KEY_,FRONT);
619         NAMETRICK(KEY_,COPY);
620         NAMETRICK(KEY_,OPEN);
621         NAMETRICK(KEY_,PASTE);
622         NAMETRICK(KEY_,FIND);
623         NAMETRICK(KEY_,CUT);
624         NAMETRICK(KEY_,HELP);
625         NAMETRICK(KEY_,MENU);
626         NAMETRICK(KEY_,CALC);
627         NAMETRICK(KEY_,SETUP);
628         NAMETRICK(KEY_,SLEEP);
629         NAMETRICK(KEY_,WAKEUP);
630         NAMETRICK(KEY_,FILE);
631         NAMETRICK(KEY_,SENDFILE);
632         NAMETRICK(KEY_,DELETEFILE);
633         NAMETRICK(KEY_,XFER);
634         NAMETRICK(KEY_,PROG1);
635         NAMETRICK(KEY_,PROG2);
636         NAMETRICK(KEY_,WWW);
637         NAMETRICK(KEY_,MSDOS);
638         NAMETRICK(KEY_,COFFEE);
639         NAMETRICK(KEY_,DIRECTION);
640         NAMETRICK(KEY_,CYCLEWINDOWS);
641         NAMETRICK(KEY_,MAIL);
642         NAMETRICK(KEY_,BOOKMARKS);
643         NAMETRICK(KEY_,COMPUTER);
644         NAMETRICK(KEY_,BACK);
645         NAMETRICK(KEY_,FORWARD);
646         NAMETRICK(KEY_,CLOSECD);
647         NAMETRICK(KEY_,EJECTCD);
648         NAMETRICK(KEY_,EJECTCLOSECD);
649         NAMETRICK(KEY_,NEXTSONG);
650         NAMETRICK(KEY_,PLAYPAUSE);
651         NAMETRICK(KEY_,PREVIOUSSONG);
652         NAMETRICK(KEY_,STOPCD);
653         NAMETRICK(KEY_,RECORD);
654         NAMETRICK(KEY_,REWIND);
655         NAMETRICK(KEY_,PHONE);
656         NAMETRICK(KEY_,ISO);
657         NAMETRICK(KEY_,CONFIG);
658         NAMETRICK(KEY_,HOMEPAGE);
659         NAMETRICK(KEY_,REFRESH);
660         NAMETRICK(KEY_,EXIT);
661         NAMETRICK(KEY_,MOVE);
662         NAMETRICK(KEY_,EDIT);
663         NAMETRICK(KEY_,SCROLLUP);
664         NAMETRICK(KEY_,SCROLLDOWN);
665         NAMETRICK(KEY_,KPLEFTPAREN);
666         NAMETRICK(KEY_,KPRIGHTPAREN);
667         NAMETRICK(KEY_,NEW);
668         NAMETRICK(KEY_,REDO);
669         NAMETRICK(KEY_,OK);
670         NAMETRICK(KEY_,SELECT);
671         NAMETRICK(KEY_,GOTO);
672         NAMETRICK(KEY_,CLEAR);
673         NAMETRICK(KEY_,POWER2);
674         NAMETRICK(KEY_,OPTION);
675         NAMETRICK(KEY_,INFO);
676         NAMETRICK(KEY_,TIME);
677         NAMETRICK(KEY_,VENDOR);
678         NAMETRICK(KEY_,ARCHIVE);
679         NAMETRICK(KEY_,PROGRAM);
680         NAMETRICK(KEY_,CHANNEL);
681         NAMETRICK(KEY_,FAVORITES);
682         NAMETRICK(KEY_,EPG);
683         NAMETRICK(KEY_,PVR);
684         NAMETRICK(KEY_,MHP);
685         NAMETRICK(KEY_,LANGUAGE);
686         NAMETRICK(KEY_,TITLE);
687         NAMETRICK(KEY_,SUBTITLE);
688         NAMETRICK(KEY_,ANGLE);
689         NAMETRICK(KEY_,ZOOM);
690         NAMETRICK(KEY_,MODE);
691         NAMETRICK(KEY_,KEYBOARD);
692         NAMETRICK(KEY_,SCREEN);
693         NAMETRICK(KEY_,RED);
694         NAMETRICK(KEY_,GREEN);
695         NAMETRICK(KEY_,YELLOW);
696         NAMETRICK(KEY_,BLUE);
697         NAMETRICK(KEY_,CHANNELUP);
698         NAMETRICK(KEY_,CHANNELDOWN);
699         NAMETRICK(KEY_,FIRST);
700         NAMETRICK(KEY_,LAST);
701         NAMETRICK(KEY_,AB);
702         NAMETRICK(KEY_,NEXT);
703         NAMETRICK(KEY_,RESTART);
704         NAMETRICK(KEY_,SLOW);
705         NAMETRICK(KEY_,SHUFFLE);
706         NAMETRICK(KEY_,BREAK);
707         NAMETRICK(KEY_,PREVIOUS);
708         NAMETRICK(KEY_,DIGITS);
709         NAMETRICK(KEY_,TEEN);
710         NAMETRICK(KEY_,TWEN);
711         NAMETRICK(KEY_,VIDEOPHONE);
712         NAMETRICK(KEY_,GAMES);
713         NAMETRICK(KEY_,ZOOMIN);
714         NAMETRICK(KEY_,ZOOMOUT);
715         NAMETRICK(KEY_,ZOOMRESET);
716         NAMETRICK(KEY_,DOLLAR);
717         NAMETRICK(KEY_,EURO);
718         NAMETRICK(KEY_,FRAMEBACK);
719         NAMETRICK(KEY_,FRAMEFORWARD);
720         NAMETRICK(KEY_,CONTEXT_MENU);
721         NAMETRICK(KEY_,MEDIA_REPEAT);
722         NAMETRICK(KEY_,NUMERIC_0);
723         NAMETRICK(KEY_,NUMERIC_1);
724         NAMETRICK(KEY_,NUMERIC_2);
725         NAMETRICK(KEY_,NUMERIC_3);
726         NAMETRICK(KEY_,NUMERIC_4);
727         NAMETRICK(KEY_,NUMERIC_5);
728         NAMETRICK(KEY_,NUMERIC_6);
729         NAMETRICK(KEY_,NUMERIC_7);
730         NAMETRICK(KEY_,NUMERIC_8);
731         NAMETRICK(KEY_,NUMERIC_9);
732         NAMETRICK(KEY_,NUMERIC_STAR);
733         NAMETRICK(KEY_,NUMERIC_POUND);
734
735         for (int i=0;i<CEC_USER_CONTROL_CODE_MAX+1;i++) {
736                         cec_keymap[i]=NULL;
737         }
738         NAMETRICK2(CEC_USER_CONTROL_CODE_,SELECT);
739         NAMETRICK2(CEC_USER_CONTROL_CODE_,UP);
740         NAMETRICK2(CEC_USER_CONTROL_CODE_,DOWN);
741         NAMETRICK2(CEC_USER_CONTROL_CODE_,LEFT);
742         NAMETRICK2(CEC_USER_CONTROL_CODE_,RIGHT);
743         NAMETRICK2(CEC_USER_CONTROL_CODE_,RIGHT_UP);
744         NAMETRICK2(CEC_USER_CONTROL_CODE_,RIGHT_DOWN);
745         NAMETRICK2(CEC_USER_CONTROL_CODE_,LEFT_UP);
746         NAMETRICK2(CEC_USER_CONTROL_CODE_,LEFT_DOWN);
747         NAMETRICK2(CEC_USER_CONTROL_CODE_,ROOT_MENU);
748         NAMETRICK2(CEC_USER_CONTROL_CODE_,SETUP_MENU);
749         NAMETRICK2(CEC_USER_CONTROL_CODE_,CONTENTS_MENU);
750         NAMETRICK2(CEC_USER_CONTROL_CODE_,FAVORITE_MENU);
751         NAMETRICK2(CEC_USER_CONTROL_CODE_,EXIT);
752         NAMETRICK2(CEC_USER_CONTROL_CODE_,NUMBER0);
753         NAMETRICK2(CEC_USER_CONTROL_CODE_,NUMBER1);
754         NAMETRICK2(CEC_USER_CONTROL_CODE_,NUMBER2);
755         NAMETRICK2(CEC_USER_CONTROL_CODE_,NUMBER3);
756         NAMETRICK2(CEC_USER_CONTROL_CODE_,NUMBER4);
757         NAMETRICK2(CEC_USER_CONTROL_CODE_,NUMBER5);
758         NAMETRICK2(CEC_USER_CONTROL_CODE_,NUMBER6);
759         NAMETRICK2(CEC_USER_CONTROL_CODE_,NUMBER7);
760         NAMETRICK2(CEC_USER_CONTROL_CODE_,NUMBER8);
761         NAMETRICK2(CEC_USER_CONTROL_CODE_,NUMBER9);
762         NAMETRICK2(CEC_USER_CONTROL_CODE_,DOT);
763         NAMETRICK2(CEC_USER_CONTROL_CODE_,ENTER);
764         NAMETRICK2(CEC_USER_CONTROL_CODE_,CLEAR);
765         NAMETRICK2(CEC_USER_CONTROL_CODE_,NEXT_FAVORITE);
766         NAMETRICK2(CEC_USER_CONTROL_CODE_,CHANNEL_UP);
767         NAMETRICK2(CEC_USER_CONTROL_CODE_,CHANNEL_DOWN);
768         NAMETRICK2(CEC_USER_CONTROL_CODE_,PREVIOUS_CHANNEL);
769         NAMETRICK2(CEC_USER_CONTROL_CODE_,SOUND_SELECT);
770         NAMETRICK2(CEC_USER_CONTROL_CODE_,INPUT_SELECT);
771         NAMETRICK2(CEC_USER_CONTROL_CODE_,DISPLAY_INFORMATION);
772         NAMETRICK2(CEC_USER_CONTROL_CODE_,HELP);
773         NAMETRICK2(CEC_USER_CONTROL_CODE_,PAGE_UP);
774         NAMETRICK2(CEC_USER_CONTROL_CODE_,PAGE_DOWN);
775         NAMETRICK2(CEC_USER_CONTROL_CODE_,POWER );
776         NAMETRICK2(CEC_USER_CONTROL_CODE_,VOLUME_UP );
777         NAMETRICK2(CEC_USER_CONTROL_CODE_,VOLUME_DOWN );
778         NAMETRICK2(CEC_USER_CONTROL_CODE_,MUTE );
779         NAMETRICK2(CEC_USER_CONTROL_CODE_,PLAY );
780         NAMETRICK2(CEC_USER_CONTROL_CODE_,STOP );
781         NAMETRICK2(CEC_USER_CONTROL_CODE_,PAUSE );
782         NAMETRICK2(CEC_USER_CONTROL_CODE_,RECORD );
783         NAMETRICK2(CEC_USER_CONTROL_CODE_,REWIND );
784         NAMETRICK2(CEC_USER_CONTROL_CODE_,FAST_FORWARD );
785         NAMETRICK2(CEC_USER_CONTROL_CODE_,EJECT );
786         NAMETRICK2(CEC_USER_CONTROL_CODE_,FORWARD );
787         NAMETRICK2(CEC_USER_CONTROL_CODE_,BACKWARD );
788         NAMETRICK2(CEC_USER_CONTROL_CODE_,STOP_RECORD );
789         NAMETRICK2(CEC_USER_CONTROL_CODE_,PAUSE_RECORD );
790         NAMETRICK2(CEC_USER_CONTROL_CODE_,ANGLE );
791         NAMETRICK2(CEC_USER_CONTROL_CODE_,SUB_PICTURE );
792         NAMETRICK2(CEC_USER_CONTROL_CODE_,VIDEO_ON_DEMAND );
793         NAMETRICK2(CEC_USER_CONTROL_CODE_,ELECTRONIC_PROGRAM_GUIDE );
794         NAMETRICK2(CEC_USER_CONTROL_CODE_,TIMER_PROGRAMMING );
795         NAMETRICK2(CEC_USER_CONTROL_CODE_,INITIAL_CONFIGURATION );
796         NAMETRICK2(CEC_USER_CONTROL_CODE_,PLAY_FUNCTION );
797         NAMETRICK2(CEC_USER_CONTROL_CODE_,PAUSE_PLAY_FUNCTION );
798         NAMETRICK2(CEC_USER_CONTROL_CODE_,RECORD_FUNCTION );
799         NAMETRICK2(CEC_USER_CONTROL_CODE_,PAUSE_RECORD_FUNCTION );
800         NAMETRICK2(CEC_USER_CONTROL_CODE_,STOP_FUNCTION );
801         NAMETRICK2(CEC_USER_CONTROL_CODE_,MUTE_FUNCTION );
802         NAMETRICK2(CEC_USER_CONTROL_CODE_,RESTORE_VOLUME_FUNCTION );
803         NAMETRICK2(CEC_USER_CONTROL_CODE_,TUNE_FUNCTION );
804         NAMETRICK2(CEC_USER_CONTROL_CODE_,SELECT_MEDIA_FUNCTION );
805         NAMETRICK2(CEC_USER_CONTROL_CODE_,SELECT_AV_INPUT_FUNCTION );
806         NAMETRICK2(CEC_USER_CONTROL_CODE_,SELECT_AUDIO_INPUT_FUNCTION );
807         NAMETRICK2(CEC_USER_CONTROL_CODE_,POWER_TOGGLE_FUNCTION );
808         NAMETRICK2(CEC_USER_CONTROL_CODE_,POWER_OFF_FUNCTION );
809         NAMETRICK2(CEC_USER_CONTROL_CODE_,POWER_ON_FUNCTION );
810         NAMETRICK2(CEC_USER_CONTROL_CODE_,F1_BLUE );
811         NAMETRICK2(CEC_USER_CONTROL_CODE_,F2_RED );
812         NAMETRICK2(CEC_USER_CONTROL_CODE_,F3_GREEN );
813         NAMETRICK2(CEC_USER_CONTROL_CODE_,F4_YELLOW );
814         NAMETRICK2(CEC_USER_CONTROL_CODE_,F5 );
815         NAMETRICK2(CEC_USER_CONTROL_CODE_,DATA );
816         NAMETRICK2(CEC_USER_CONTROL_CODE_,AN_RETURN );
817         NAMETRICK2(CEC_USER_CONTROL_CODE_,AN_CHANNELS_LIST );
818         NAMETRICK2(CEC_USER_CONTROL_CODE_,MAX );
819
820 }
821
822
823
824 char* RemoteLinux::HCWDesc(unsigned long long hcw)
825 {
826     //Determine type
827     unsigned int type =  hcw >> 32;
828     char *rt=NULL;
829     switch(type)
830     {
831     case W_HCW_KC:{
832         unsigned int vk=(ULONG)hcw;
833         rt=new char[10];
834         const char *desc=linux_keymap[vk];
835         if (desc) {
836                 strncpy(rt,desc,9);
837         } else {
838                 sprintf(rt,"0x%x",vk);
839         }
840                   }break;
841     case W_HCW_CEC:{
842         unsigned int vk=(ULONG)hcw;
843         rt=new char[10];
844         const char *desc=cec_keymap[vk];
845         if (desc) {
846                 strncpy(rt,desc,9);
847         } else {
848                 sprintf(rt,"0x%x",vk);
849         }
850                   }break;
851   /*
852     case W_HCW_LIRC:{
853         ULONG ri=(ULONG)hcw;
854         rt=new char[10];
855         sprintf(rt,"R: %X",ri);
856                   }break;*/
857
858     };
859     return rt;
860 }
861
862
863 int RemoteLinux::cecLogMessage(void *param, const cec_log_message &message)
864 {
865         Log::getInstance()->log("Remote", Log::DEBUG, "CECLOG: %lld %d %s",message.time , message.level, message.message );
866         return 0;
867 }
868
869 int RemoteLinux::cecKeyPress(void*param, const cec_keypress &key)
870 {
871         //Log::getInstance()->log("Remote", Log::DEBUG, "Incoming cec key %d %d", key.keycode,key.duration);
872         if (key.duration==0) ((RemoteLinux*)Remote::getInstance())->incomingCECkey(key.keycode);
873         return 1;
874 }
875 int RemoteLinux::cecCommand(void *param, const cec_command &command)
876 {
877         //Log::getInstance()->log("Remote", Log::DEBUG, "CECCommand: %d",command.opcode);
878         return 1;
879 }
880
881 int RemoteLinux::cecConfigurationChanged(void *param, const libcec_configuration &config)
882 {
883         //Log::getInstance()->log("Remote", Log::DEBUG, "CECConfig:"/*,config.string()*/);
884         return 1;
885
886 }
887
888 void RemoteLinux::incomingCECkey(int keys)
889 {
890         curcec=keys;
891         hascurcec=true;
892
893 }
894
895 /*
896 void RemoteLinux::Signal() {
897         signal=true;
898         //PulseEvent(event);
899         SetEvent(event);
900 }
901
902 void RemoteLinux::SendPower()
903 {
904
905         curevent=POWER;
906     hascurevent=true;
907         SetEvent(event);
908 }*/
909