2 Copyright 2004-2005 Chris Tallon; 2012 Marten Richter
4 This file is part of VOMP.
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.
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.
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.
21 #include "remotelinux.h"
24 #include "woptionpane.h"
26 #include <linux/input.h>
27 #include <sys/types.h>
44 #include <libcec/cecloader.h>
49 #define W_G_HCW(type,code) ( (((ULLONG)(type))<<32) | code)
51 #define W_HCW_KC 1 /* key code as defined by kernel for keyboard and remotes through /dev/input */
52 #define W_HCW_CEC 2 /* HDMI_CEC */
53 #define W_HCW_LIRC 3 /* remote control LIRC*/
56 RemoteLinux::RemoteLinux()
66 cechandlesvolume=false;
70 RemoteLinux::~RemoteLinux()
72 for (unsigned int i=0; i<devices.size();i++) {
77 #define test_bit(input,b) ((1 << ((b) % 8))&(input)[b / 8] )
80 int RemoteLinux::init(char* devName)
82 if (initted) return 0;
87 for (int eventid=0;eventid<100;eventid++){
89 sprintf(buffer,"/dev/input/event%d",eventid);
93 if (stat(buffer,&test_buf)==0) {
94 Log::getInstance()->log("Remote", Log::NOTICE, "Probe /dev/input/event%d",eventid);
96 unsigned long ev_type=0;
97 int new_fd=open(buffer,O_RDONLY);
99 Log::getInstance()->log("Remote", Log::NOTICE, "Can not open /dev/input/event%d",eventid);
102 if (ioctl(new_fd, EVIOCGBIT(0, EV_MAX), &ev_type) < 0) {
103 Log::getInstance()->log("Remote", Log::NOTICE, "Ioctl failed /dev/input/event%d %d",eventid,errno);
106 //Now test if it generates keyboard presses
107 if (test_bit((char*)&ev_type , EV_KEY)) {
108 Log::getInstance()->log("Remote", Log::NOTICE, "Add /dev/input/event%d to List",eventid);
109 devices.push_back(new_fd);
127 int RemoteLinux::initCec() {
129 // bcm_host_init(); //may be move to custom hardware init?
131 Log::getInstance()->log("Remote", Log::NOTICE, "Init LibCEC");
133 cec_callbacks.Clear();
134 cec_callbacks.CBCecLogMessage = cecLogMessage;
135 cec_callbacks.CBCecKeyPress = cecKeyPress;
136 cec_callbacks.CBCecCommand = cecCommand;
137 cec_callbacks.CBCecConfigurationChanged = cecConfigurationChanged;
138 cec_callbacks.CBCecSourceActivated = cecSourceActivated;
139 cec_config.clientVersion=LIBCEC_VERSION_CURRENT;
140 cec_config.bActivateSource=1;
141 cec_config.bUseTVMenuLanguage=1;
142 //cec_config.deviceTypes.Add(CEC_DEVICE_TYPE_PLAYBACK_DEVICE);
143 cec_config.deviceTypes.Add(CEC_DEVICE_TYPE_RECORDING_DEVICE);
144 //cec_config.deviceTypes.Add(CEC_DEVICE_TYPE_TUNER);
146 strncpy(cec_config.strDeviceName,"vomp",sizeof(cec_config.strDeviceName));
149 cec_config.callbackParam = NULL; // I do not care
150 cec_config.callbacks = &cec_callbacks;
152 cec_adap = LibCecInitialise(&cec_config);
154 Log::getInstance()->log("Remote", Log::ERR, "Init LibCEC failed");
157 cec_adap->InitVideoStandalone();
160 cec_adapter cec_devices[10];
161 int adap_num=cec_adap->FindAdapters(cec_devices,10,NULL);
163 Log::getInstance()->log("Remote", Log::ERR, "CEC:Failed to find adapter");
168 Log::getInstance()->log("Remote", Log::NOTICE, "CEC: No adapter found");
172 if (!cec_adap->Open(cec_devices[0].comm)) {
173 Log::getInstance()->log("Remote", Log::ERR, "CEC:Failed to open adapter");
177 if (!cec_adap->SetActiveSource(cec_config.deviceTypes[0])) {
178 Log::getInstance()->log("Remote", Log::ERR, "CEC:Failed set active source");
188 int RemoteLinux::shutdown()
190 if (!initted) return 0;
192 while (devices.size()) {
193 int cur_fd = devices.back();
202 void RemoteLinux::deinitCec()
205 Log::getInstance()->log("Remote", Log::NOTICE, "Shutdown libcec begin");
206 cec_adap->SetInactiveView();
208 vc_cec_register_callback(NULL, NULL);//deactivate callback!
209 UnloadLibCec(cec_adap);
211 Log::getInstance()->log("Remote", Log::NOTICE, "Shutdown libcec end");
216 UCHAR RemoteLinux::getButtonPress(int waitType) {
218 how = 1 - start new wait
219 how = 2 - continue wait
233 } else if (waitType == 1) {
236 } else if (waitType == 2) {
237 if (num_loop<=0) num_loop = 25;
238 } else if (waitType == 3) {
246 while (num_loop!=0) {
251 for (int i = 0; i < devices.size(); i++) {
252 int cur_fd = devices[i];
253 maxfd = max(cur_fd, maxfd);
254 FD_SET(cur_fd, &readfds);
257 retval = select(maxfd + 1, &readfds, NULL, NULL, &tv);
260 // 0 = nothing happened
261 // 1 = data arrived (actually num of descriptors that changed)
262 // other value = signal or error
266 return (UCHAR) TranslateHWC(W_G_HCW(W_HCW_CEC,curcec));
275 Log::getInstance()->log("Remote", Log::NOTICE, "na_signal");
279 for (int i = 0; i < devices.size(); i++) {
280 int cur_fd = devices[i];
281 if (FD_ISSET(cur_fd, &readfds)) {
282 struct input_event ev;
283 int count = read(cur_fd, &ev, sizeof(ev));
284 if (count == sizeof(ev)) {
285 if (ev.type == EV_KEY && ev.value == 1) {
286 UCHAR retty=(UCHAR) TranslateHWC(
287 W_G_HCW(W_HCW_KC,ev.code));
297 //Log::getInstance()->log("Remote", Log::NOTICE, "numloop: %d %d",num_loop,retval);
308 void RemoteLinux::clearBuffer()
310 UCHAR buttonpress=getButtonPress(3);
311 while(buttonpress != NA_NONE && buttonpress!=NA_UNKNOWN){
312 buttonpress=getButtonPress(3);
316 UCHAR RemoteLinux::TranslateHWCFixed(ULLONG code)
320 case W_G_HCW(W_HCW_KC,KEY_DOWN):
322 case W_G_HCW(W_HCW_KC,KEY_UP):
324 case W_G_HCW(W_HCW_KC,KEY_LEFT):
326 case W_G_HCW(W_HCW_KC,KEY_RIGHT):
328 case W_G_HCW(W_HCW_KC,KEY_M):
329 case W_G_HCW(W_HCW_KC,KEY_MEDIA):
331 case W_G_HCW(W_HCW_KC,KEY_BACKSPACE):
332 case W_G_HCW(W_HCW_KC,KEY_EXIT):
334 case W_G_HCW(W_HCW_KC,KEY_ENTER):
335 case W_G_HCW(W_HCW_KC,KEY_SPACE):
336 case W_G_HCW(W_HCW_KC,KEY_OK):
339 case W_G_HCW(W_HCW_CEC,CEC_USER_CONTROL_CODE_DOWN):
341 case W_G_HCW(W_HCW_CEC,CEC_USER_CONTROL_CODE_UP):
343 case W_G_HCW(W_HCW_CEC,CEC_USER_CONTROL_CODE_LEFT):
345 case W_G_HCW(W_HCW_CEC,CEC_USER_CONTROL_CODE_RIGHT):
347 case W_G_HCW(W_HCW_CEC,CEC_USER_CONTROL_CODE_ROOT_MENU):
348 case W_G_HCW(W_HCW_CEC,CEC_USER_CONTROL_CODE_CONTENTS_MENU):
349 case W_G_HCW(W_HCW_CEC,CEC_USER_CONTROL_CODE_SETUP_MENU):
351 case W_G_HCW(W_HCW_CEC,CEC_USER_CONTROL_CODE_EXIT ):
353 case W_G_HCW(W_HCW_CEC,CEC_USER_CONTROL_CODE_ENTER):
354 case W_G_HCW(W_HCW_CEC,CEC_USER_CONTROL_CODE_SELECT):
355 case W_G_HCW(W_HCW_CEC,CEC_USER_CONTROL_CODE_AN_RETURN):
357 case W_G_HCW(W_HCW_KC,KEY_SLEEP):
358 case W_G_HCW(W_HCW_KC,KEY_POWER):
359 case W_G_HCW(W_HCW_KC,KEY_ESC):
360 case W_G_HCW(W_HCW_CEC,CEC_USER_CONTROL_CODE_POWER):
368 const char*RemoteLinux::HardcodedTranslateStr(UCHAR command)
383 return tr("Backspace, Back");
385 return tr("Return, Space");
393 void RemoteLinux::InitHWCListwithDefaults()
395 //Processing VK_Messages
396 translist[W_G_HCW(W_HCW_KC,KEY_9)] = NINE;
397 translist[W_G_HCW(W_HCW_KC,KEY_8)] = EIGHT;
398 translist[W_G_HCW(W_HCW_KC,KEY_7)] = SEVEN;
399 translist[W_G_HCW(W_HCW_KC,KEY_6)] = SIX;
400 translist[W_G_HCW(W_HCW_KC,KEY_5)] = FIVE;
401 translist[W_G_HCW(W_HCW_KC,KEY_4)] = FOUR;
402 translist[W_G_HCW(W_HCW_KC,KEY_3)] = THREE;
403 translist[W_G_HCW(W_HCW_KC,KEY_2)] = TWO;
404 translist[W_G_HCW(W_HCW_KC,KEY_1)] = ONE;
405 translist[W_G_HCW(W_HCW_KC,KEY_0)] = ZERO;
406 translist[W_G_HCW(W_HCW_KC,KEY_KPDOT)] = STAR;
407 // translist[W_G_HCW(W_HCW_KC,KEY_#)] = HASH;
409 translist[W_G_HCW(W_HCW_KC,KEY_KP9)] = NINE;
410 translist[W_G_HCW(W_HCW_KC,KEY_KP8)] = EIGHT;
411 translist[W_G_HCW(W_HCW_KC,KEY_KP7)] = SEVEN;
412 translist[W_G_HCW(W_HCW_KC,KEY_KP6)] = SIX;
413 translist[W_G_HCW(W_HCW_KC,KEY_KP5)] = FIVE;
414 translist[W_G_HCW(W_HCW_KC,KEY_KP4)] = FOUR;
415 translist[W_G_HCW(W_HCW_KC,KEY_KP3)] = THREE;
416 translist[W_G_HCW(W_HCW_KC,KEY_KP2)] = TWO;
417 translist[W_G_HCW(W_HCW_KC,KEY_KP1)] = ONE;
418 translist[W_G_HCW(W_HCW_KC,KEY_KP0)] = ZERO;
420 translist[W_G_HCW(W_HCW_KC,KEY_NUMERIC_9)] = NINE;
421 translist[W_G_HCW(W_HCW_KC,KEY_NUMERIC_8)] = EIGHT;
422 translist[W_G_HCW(W_HCW_KC,KEY_NUMERIC_7)] = SEVEN;
423 translist[W_G_HCW(W_HCW_KC,KEY_NUMERIC_6)] = SIX;
424 translist[W_G_HCW(W_HCW_KC,KEY_NUMERIC_5)] = FIVE;
425 translist[W_G_HCW(W_HCW_KC,KEY_NUMERIC_4)] = FOUR;
426 translist[W_G_HCW(W_HCW_KC,KEY_NUMERIC_3)] = THREE;
427 translist[W_G_HCW(W_HCW_KC,KEY_NUMERIC_2)] = TWO;
428 translist[W_G_HCW(W_HCW_KC,KEY_NUMERIC_1)] = ONE;
429 translist[W_G_HCW(W_HCW_KC,KEY_NUMERIC_0)] = ZERO;
430 translist[W_G_HCW(W_HCW_KC,KEY_NUMERIC_STAR)] = STAR;
431 translist[W_G_HCW(W_HCW_KC,KEY_NUMERIC_POUND)] = HASH;
434 translist[W_G_HCW(W_HCW_KC,KEY_J)] = GO; //j for JUMP TO instead of go to
435 translist[W_G_HCW(W_HCW_KC,KEY_R)] = RED;
436 translist[W_G_HCW(W_HCW_KC,KEY_G)] = GREEN;
437 translist[W_G_HCW(W_HCW_KC,KEY_Y)] = YELLOW;
438 translist[W_G_HCW(W_HCW_KC,KEY_B)] = BLUE;
439 //Processing Remote Style Messages
440 translist[W_G_HCW(W_HCW_KC,KEY_GREEN)] = GREEN;
441 translist[W_G_HCW(W_HCW_KC,KEY_RED)] = RED;
442 translist[W_G_HCW(W_HCW_KC,KEY_YELLOW)] = YELLOW;
443 translist[W_G_HCW(W_HCW_KC,KEY_BLUE)] = BLUE;
444 translist[W_G_HCW(W_HCW_KC,KEY_MENU)] = MENU;
446 translist[W_G_HCW(W_HCW_KC,KEY_RECORD)] = RECORD;
447 translist[W_G_HCW(W_HCW_KC,KEY_PLAY)] = PLAY; //Playback Televison
448 translist[W_G_HCW(W_HCW_KC,KEY_PAUSE)] = PAUSE;
449 translist[W_G_HCW(W_HCW_KC,KEY_STOP)] = STOP;
450 translist[W_G_HCW(W_HCW_KC,KEY_PLAYPAUSE)] = PLAYPAUSE;
451 translist[W_G_HCW(W_HCW_KC,KEY_P)] = PLAYPAUSE;
452 translist[W_G_HCW(W_HCW_KC,KEY_NEXT)] = SKIPFORWARD;
453 translist[W_G_HCW(W_HCW_KC,KEY_F2)] = SKIPFORWARD;
454 translist[W_G_HCW(W_HCW_KC,KEY_PREVIOUS)] = SKIPBACK;
455 translist[W_G_HCW(W_HCW_KC,KEY_F1)] = SKIPBACK;
456 translist[W_G_HCW(W_HCW_KC,KEY_FORWARD)] = FORWARD;
457 translist[W_G_HCW(W_HCW_KC,KEY_FASTFORWARD)] = FORWARD;
458 translist[W_G_HCW(W_HCW_KC,KEY_F)] = FORWARD;
459 translist[W_G_HCW(W_HCW_KC,KEY_BACK)] = REVERSE;
460 translist[W_G_HCW(W_HCW_KC,KEY_REWIND)] = REVERSE;
461 translist[W_G_HCW(W_HCW_KC,KEY_T)] = REVERSE;
462 translist[W_G_HCW(W_HCW_KC,KEY_MUTE)] = MUTE;
463 translist[W_G_HCW(W_HCW_KC,KEY_F8)] = MUTE;
464 translist[W_G_HCW(W_HCW_KC,KEY_F10)] = VOLUMEUP;
465 translist[W_G_HCW(W_HCW_KC,KEY_F9)] = VOLUMEDOWN;
466 translist[W_G_HCW(W_HCW_KC,KEY_VOLUMEUP)] = VOLUMEUP;
467 translist[W_G_HCW(W_HCW_KC,KEY_VOLUMEDOWN)] = VOLUMEDOWN;
468 translist[W_G_HCW(W_HCW_KC,KEY_CHANNELUP)] = CHANNELUP;
469 translist[W_G_HCW(W_HCW_KC,KEY_CHANNELDOWN)] = CHANNELDOWN;
470 translist[W_G_HCW(W_HCW_KC,KEY_PAGEUP)] = CHANNELUP;
471 translist[W_G_HCW(W_HCW_KC,KEY_PAGEDOWN)] = CHANNELDOWN;
474 //Processing CEC_Messages
475 translist[W_G_HCW(W_HCW_CEC,CEC_USER_CONTROL_CODE_NUMBER9)] = NINE;
476 translist[W_G_HCW(W_HCW_CEC,CEC_USER_CONTROL_CODE_NUMBER8)] = EIGHT;
477 translist[W_G_HCW(W_HCW_CEC,CEC_USER_CONTROL_CODE_NUMBER7)] = SEVEN;
478 translist[W_G_HCW(W_HCW_CEC,CEC_USER_CONTROL_CODE_NUMBER6)] = SIX;
479 translist[W_G_HCW(W_HCW_CEC,CEC_USER_CONTROL_CODE_NUMBER5)] = FIVE;
480 translist[W_G_HCW(W_HCW_CEC,CEC_USER_CONTROL_CODE_NUMBER4)] = FOUR;
481 translist[W_G_HCW(W_HCW_CEC,CEC_USER_CONTROL_CODE_NUMBER3)] = THREE;
482 translist[W_G_HCW(W_HCW_CEC,CEC_USER_CONTROL_CODE_NUMBER2)] = TWO;
483 translist[W_G_HCW(W_HCW_CEC,CEC_USER_CONTROL_CODE_NUMBER1)] = ONE;
484 translist[W_G_HCW(W_HCW_CEC,CEC_USER_CONTROL_CODE_NUMBER0)] = ZERO;
485 //translist[W_G_HCW(W_HCW_CEC,KEY_KPDOT)] = STAR;
489 //translist[W_G_HCW(W_HCW_CEC,KEY_J)] = GO; //j for JUMP TO instead of go to
490 translist[W_G_HCW(W_HCW_CEC,CEC_USER_CONTROL_CODE_F2_RED)] = RED;
491 translist[W_G_HCW(W_HCW_CEC,CEC_USER_CONTROL_CODE_F3_GREEN)] = GREEN;
492 translist[W_G_HCW(W_HCW_CEC,CEC_USER_CONTROL_CODE_F4_YELLOW)] = YELLOW;
493 translist[W_G_HCW(W_HCW_CEC,CEC_USER_CONTROL_CODE_F1_BLUE)] = BLUE;
494 //Processing Remote Style Messages
495 translist[W_G_HCW(W_HCW_CEC,CEC_USER_CONTROL_CODE_FAVORITE_MENU)] = MENU;
497 translist[W_G_HCW(W_HCW_CEC,CEC_USER_CONTROL_CODE_RECORD)] = RECORD;
498 translist[W_G_HCW(W_HCW_CEC,CEC_USER_CONTROL_CODE_PLAY)] = PLAY; //Playback Televison
499 translist[W_G_HCW(W_HCW_CEC,CEC_USER_CONTROL_CODE_PAUSE)] = PAUSE;
500 translist[W_G_HCW(W_HCW_CEC,CEC_USER_CONTROL_CODE_STOP)] = STOP;
501 translist[W_G_HCW(W_HCW_CEC,CEC_USER_CONTROL_CODE_PAUSE_PLAY_FUNCTION)] = PLAYPAUSE;
502 translist[W_G_HCW(W_HCW_CEC,CEC_USER_CONTROL_CODE_FORWARD)] = SKIPFORWARD;
503 translist[W_G_HCW(W_HCW_CEC,CEC_USER_CONTROL_CODE_BACKWARD)] = SKIPBACK;
504 translist[W_G_HCW(W_HCW_CEC,CEC_USER_CONTROL_CODE_FAST_FORWARD )] = FORWARD;
505 translist[W_G_HCW(W_HCW_CEC,CEC_USER_CONTROL_CODE_REWIND)] = REVERSE;
506 translist[W_G_HCW(W_HCW_CEC,CEC_USER_CONTROL_CODE_MUTE)] = MUTE;
507 translist[W_G_HCW(W_HCW_CEC,CEC_USER_CONTROL_CODE_VOLUME_UP)] = VOLUMEUP;
508 translist[W_G_HCW(W_HCW_CEC,CEC_USER_CONTROL_CODE_VOLUME_DOWN)] = VOLUMEDOWN;
509 translist[W_G_HCW(W_HCW_CEC,CEC_USER_CONTROL_CODE_CHANNEL_UP )] = CHANNELUP;
510 translist[W_G_HCW(W_HCW_CEC,CEC_USER_CONTROL_CODE_CHANNEL_DOWN)] = CHANNELDOWN;
514 #define NAMETRICK(pre, code) linux_keymap[pre ## code]= #code
515 #define NAMETRICK2(pre, code) cec_keymap[pre ## code]= #code
516 //extracte from linux/input.h
518 static const char * linux_keymap[KEY_MAX+1];
519 static const char * cec_keymap[CEC_USER_CONTROL_CODE_MAX+1];
521 void RemoteLinux::InitKeymap()
523 for (int i=0;i<KEY_MAX+1;i++) {
524 linux_keymap[i]=NULL;
526 NAMETRICK(KEY_,RESERVED);
538 NAMETRICK(KEY_,MINUS);
539 NAMETRICK(KEY_,EQUAL);
540 NAMETRICK(KEY_,BACKSPACE);
552 NAMETRICK(KEY_,LEFTBRACE);
553 NAMETRICK(KEY_,RIGHTBRACE);
554 NAMETRICK(KEY_,ENTER);
555 NAMETRICK(KEY_,LEFTCTRL);
565 NAMETRICK(KEY_,SEMICOLON);
566 NAMETRICK(KEY_,APOSTROPHE);
567 NAMETRICK(KEY_,GRAVE);
568 NAMETRICK(KEY_,LEFTSHIFT);
569 NAMETRICK(KEY_,BACKSLASH);
577 NAMETRICK(KEY_,COMMA);
579 NAMETRICK(KEY_,SLASH);
580 NAMETRICK(KEY_,RIGHTSHIFT);
581 NAMETRICK(KEY_,KPASTERISK);
582 NAMETRICK(KEY_,LEFTALT);
583 NAMETRICK(KEY_,SPACE);
584 NAMETRICK(KEY_,CAPSLOCK);
595 NAMETRICK(KEY_,NUMLOCK);
596 NAMETRICK(KEY_,SCROLLLOCK);
600 NAMETRICK(KEY_,KPMINUS);
604 NAMETRICK(KEY_,KPPLUS);
609 NAMETRICK(KEY_,KPDOT);
612 NAMETRICK(KEY_,KPENTER);
613 NAMETRICK(KEY_,RIGHTCTRL);
614 NAMETRICK(KEY_,KPSLASH);
615 NAMETRICK(KEY_,SYSRQ);
616 NAMETRICK(KEY_,RIGHTALT);
617 NAMETRICK(KEY_,LINEFEED);
618 NAMETRICK(KEY_,HOME);
620 NAMETRICK(KEY_,PAGEUP);
621 NAMETRICK(KEY_,LEFT);
622 NAMETRICK(KEY_,RIGHT);
624 NAMETRICK(KEY_,DOWN);
625 NAMETRICK(KEY_,PAGEDOWN);
626 NAMETRICK(KEY_,INSERT);
627 NAMETRICK(KEY_,DELETE);
628 NAMETRICK(KEY_,MACRO);
629 NAMETRICK(KEY_,MUTE);
630 NAMETRICK(KEY_,VOLUMEDOWN);
631 NAMETRICK(KEY_,VOLUMEUP);
632 NAMETRICK(KEY_,POWER);
633 NAMETRICK(KEY_,KPEQUAL);
634 NAMETRICK(KEY_,KPPLUSMINUS);
635 NAMETRICK(KEY_,PLAY);
636 NAMETRICK(KEY_,PAUSE);
637 NAMETRICK(KEY_,SCALE);
638 NAMETRICK(KEY_,KPCOMMA);
640 NAMETRICK(KEY_,LEFTMETA);
641 NAMETRICK(KEY_,RIGHTMETA);
642 NAMETRICK(KEY_,COMPOSE);
643 NAMETRICK(KEY_,STOP);
644 NAMETRICK(KEY_,AGAIN);
645 NAMETRICK(KEY_,PROPS);
646 NAMETRICK(KEY_,UNDO);
647 NAMETRICK(KEY_,FRONT);
648 NAMETRICK(KEY_,COPY);
649 NAMETRICK(KEY_,OPEN);
650 NAMETRICK(KEY_,PASTE);
651 NAMETRICK(KEY_,FIND);
653 NAMETRICK(KEY_,HELP);
654 NAMETRICK(KEY_,MENU);
655 NAMETRICK(KEY_,CALC);
656 NAMETRICK(KEY_,SETUP);
657 NAMETRICK(KEY_,SLEEP);
658 NAMETRICK(KEY_,WAKEUP);
659 NAMETRICK(KEY_,FILE);
660 NAMETRICK(KEY_,SENDFILE);
661 NAMETRICK(KEY_,DELETEFILE);
662 NAMETRICK(KEY_,XFER);
663 NAMETRICK(KEY_,PROG1);
664 NAMETRICK(KEY_,PROG2);
666 NAMETRICK(KEY_,MSDOS);
667 NAMETRICK(KEY_,COFFEE);
668 NAMETRICK(KEY_,DIRECTION);
669 NAMETRICK(KEY_,CYCLEWINDOWS);
670 NAMETRICK(KEY_,MAIL);
671 NAMETRICK(KEY_,BOOKMARKS);
672 NAMETRICK(KEY_,COMPUTER);
673 NAMETRICK(KEY_,BACK);
674 NAMETRICK(KEY_,FORWARD);
675 NAMETRICK(KEY_,FASTFORWARD);
676 NAMETRICK(KEY_,CLOSECD);
677 NAMETRICK(KEY_,EJECTCD);
678 NAMETRICK(KEY_,EJECTCLOSECD);
679 NAMETRICK(KEY_,NEXTSONG);
680 NAMETRICK(KEY_,PLAYPAUSE);
681 NAMETRICK(KEY_,PREVIOUSSONG);
682 NAMETRICK(KEY_,STOPCD);
683 NAMETRICK(KEY_,RECORD);
684 NAMETRICK(KEY_,REWIND);
685 NAMETRICK(KEY_,PHONE);
687 NAMETRICK(KEY_,CONFIG);
688 NAMETRICK(KEY_,HOMEPAGE);
689 NAMETRICK(KEY_,REFRESH);
690 NAMETRICK(KEY_,EXIT);
691 NAMETRICK(KEY_,MOVE);
692 NAMETRICK(KEY_,EDIT);
693 NAMETRICK(KEY_,SCROLLUP);
694 NAMETRICK(KEY_,SCROLLDOWN);
695 NAMETRICK(KEY_,KPLEFTPAREN);
696 NAMETRICK(KEY_,KPRIGHTPAREN);
698 NAMETRICK(KEY_,REDO);
700 NAMETRICK(KEY_,SELECT);
701 NAMETRICK(KEY_,GOTO);
702 NAMETRICK(KEY_,CLEAR);
703 NAMETRICK(KEY_,POWER2);
704 NAMETRICK(KEY_,OPTION);
705 NAMETRICK(KEY_,INFO);
706 NAMETRICK(KEY_,TIME);
707 NAMETRICK(KEY_,VENDOR);
708 NAMETRICK(KEY_,ARCHIVE);
709 NAMETRICK(KEY_,PROGRAM);
710 NAMETRICK(KEY_,CHANNEL);
711 NAMETRICK(KEY_,FAVORITES);
715 NAMETRICK(KEY_,LANGUAGE);
716 NAMETRICK(KEY_,TITLE);
717 NAMETRICK(KEY_,SUBTITLE);
718 NAMETRICK(KEY_,ANGLE);
719 NAMETRICK(KEY_,ZOOM);
720 NAMETRICK(KEY_,MODE);
721 NAMETRICK(KEY_,KEYBOARD);
722 NAMETRICK(KEY_,SCREEN);
724 NAMETRICK(KEY_,GREEN);
725 NAMETRICK(KEY_,YELLOW);
726 NAMETRICK(KEY_,BLUE);
727 NAMETRICK(KEY_,CHANNELUP);
728 NAMETRICK(KEY_,CHANNELDOWN);
729 NAMETRICK(KEY_,FIRST);
730 NAMETRICK(KEY_,LAST);
732 NAMETRICK(KEY_,NEXT);
733 NAMETRICK(KEY_,RESTART);
734 NAMETRICK(KEY_,SLOW);
735 NAMETRICK(KEY_,SHUFFLE);
736 NAMETRICK(KEY_,BREAK);
737 NAMETRICK(KEY_,PREVIOUS);
738 NAMETRICK(KEY_,DIGITS);
739 NAMETRICK(KEY_,TEEN);
740 NAMETRICK(KEY_,TWEN);
741 NAMETRICK(KEY_,VIDEOPHONE);
742 NAMETRICK(KEY_,GAMES);
743 NAMETRICK(KEY_,ZOOMIN);
744 NAMETRICK(KEY_,ZOOMOUT);
745 NAMETRICK(KEY_,ZOOMRESET);
746 NAMETRICK(KEY_,DOLLAR);
747 NAMETRICK(KEY_,EURO);
748 NAMETRICK(KEY_,MEDIA);
749 NAMETRICK(KEY_,FRAMEBACK);
750 NAMETRICK(KEY_,FRAMEFORWARD);
751 NAMETRICK(KEY_,CONTEXT_MENU);
752 NAMETRICK(KEY_,MEDIA_REPEAT);
753 NAMETRICK(KEY_,NUMERIC_0);
754 NAMETRICK(KEY_,NUMERIC_1);
755 NAMETRICK(KEY_,NUMERIC_2);
756 NAMETRICK(KEY_,NUMERIC_3);
757 NAMETRICK(KEY_,NUMERIC_4);
758 NAMETRICK(KEY_,NUMERIC_5);
759 NAMETRICK(KEY_,NUMERIC_6);
760 NAMETRICK(KEY_,NUMERIC_7);
761 NAMETRICK(KEY_,NUMERIC_8);
762 NAMETRICK(KEY_,NUMERIC_9);
763 NAMETRICK(KEY_,NUMERIC_STAR);
764 NAMETRICK(KEY_,NUMERIC_POUND);
766 for (int i=0;i<CEC_USER_CONTROL_CODE_MAX+1;i++) {
769 NAMETRICK2(CEC_USER_CONTROL_CODE_,SELECT);
770 NAMETRICK2(CEC_USER_CONTROL_CODE_,UP);
771 NAMETRICK2(CEC_USER_CONTROL_CODE_,DOWN);
772 NAMETRICK2(CEC_USER_CONTROL_CODE_,LEFT);
773 NAMETRICK2(CEC_USER_CONTROL_CODE_,RIGHT);
774 NAMETRICK2(CEC_USER_CONTROL_CODE_,RIGHT_UP);
775 NAMETRICK2(CEC_USER_CONTROL_CODE_,RIGHT_DOWN);
776 NAMETRICK2(CEC_USER_CONTROL_CODE_,LEFT_UP);
777 NAMETRICK2(CEC_USER_CONTROL_CODE_,LEFT_DOWN);
778 NAMETRICK2(CEC_USER_CONTROL_CODE_,ROOT_MENU);
779 NAMETRICK2(CEC_USER_CONTROL_CODE_,SETUP_MENU);
780 NAMETRICK2(CEC_USER_CONTROL_CODE_,CONTENTS_MENU);
781 NAMETRICK2(CEC_USER_CONTROL_CODE_,FAVORITE_MENU);
782 NAMETRICK2(CEC_USER_CONTROL_CODE_,EXIT);
783 NAMETRICK2(CEC_USER_CONTROL_CODE_,NUMBER0);
784 NAMETRICK2(CEC_USER_CONTROL_CODE_,NUMBER1);
785 NAMETRICK2(CEC_USER_CONTROL_CODE_,NUMBER2);
786 NAMETRICK2(CEC_USER_CONTROL_CODE_,NUMBER3);
787 NAMETRICK2(CEC_USER_CONTROL_CODE_,NUMBER4);
788 NAMETRICK2(CEC_USER_CONTROL_CODE_,NUMBER5);
789 NAMETRICK2(CEC_USER_CONTROL_CODE_,NUMBER6);
790 NAMETRICK2(CEC_USER_CONTROL_CODE_,NUMBER7);
791 NAMETRICK2(CEC_USER_CONTROL_CODE_,NUMBER8);
792 NAMETRICK2(CEC_USER_CONTROL_CODE_,NUMBER9);
793 NAMETRICK2(CEC_USER_CONTROL_CODE_,DOT);
794 NAMETRICK2(CEC_USER_CONTROL_CODE_,ENTER);
795 NAMETRICK2(CEC_USER_CONTROL_CODE_,CLEAR);
796 NAMETRICK2(CEC_USER_CONTROL_CODE_,NEXT_FAVORITE);
797 NAMETRICK2(CEC_USER_CONTROL_CODE_,CHANNEL_UP);
798 NAMETRICK2(CEC_USER_CONTROL_CODE_,CHANNEL_DOWN);
799 NAMETRICK2(CEC_USER_CONTROL_CODE_,PREVIOUS_CHANNEL);
800 NAMETRICK2(CEC_USER_CONTROL_CODE_,SOUND_SELECT);
801 NAMETRICK2(CEC_USER_CONTROL_CODE_,INPUT_SELECT);
802 NAMETRICK2(CEC_USER_CONTROL_CODE_,DISPLAY_INFORMATION);
803 NAMETRICK2(CEC_USER_CONTROL_CODE_,HELP);
804 NAMETRICK2(CEC_USER_CONTROL_CODE_,PAGE_UP);
805 NAMETRICK2(CEC_USER_CONTROL_CODE_,PAGE_DOWN);
806 NAMETRICK2(CEC_USER_CONTROL_CODE_,POWER );
807 NAMETRICK2(CEC_USER_CONTROL_CODE_,VOLUME_UP );
808 NAMETRICK2(CEC_USER_CONTROL_CODE_,VOLUME_DOWN );
809 NAMETRICK2(CEC_USER_CONTROL_CODE_,MUTE );
810 NAMETRICK2(CEC_USER_CONTROL_CODE_,PLAY );
811 NAMETRICK2(CEC_USER_CONTROL_CODE_,STOP );
812 NAMETRICK2(CEC_USER_CONTROL_CODE_,PAUSE );
813 NAMETRICK2(CEC_USER_CONTROL_CODE_,RECORD );
814 NAMETRICK2(CEC_USER_CONTROL_CODE_,REWIND );
815 NAMETRICK2(CEC_USER_CONTROL_CODE_,FAST_FORWARD );
816 NAMETRICK2(CEC_USER_CONTROL_CODE_,EJECT );
817 NAMETRICK2(CEC_USER_CONTROL_CODE_,FORWARD );
818 NAMETRICK2(CEC_USER_CONTROL_CODE_,BACKWARD );
819 NAMETRICK2(CEC_USER_CONTROL_CODE_,STOP_RECORD );
820 NAMETRICK2(CEC_USER_CONTROL_CODE_,PAUSE_RECORD );
821 NAMETRICK2(CEC_USER_CONTROL_CODE_,ANGLE );
822 NAMETRICK2(CEC_USER_CONTROL_CODE_,SUB_PICTURE );
823 NAMETRICK2(CEC_USER_CONTROL_CODE_,VIDEO_ON_DEMAND );
824 NAMETRICK2(CEC_USER_CONTROL_CODE_,ELECTRONIC_PROGRAM_GUIDE );
825 NAMETRICK2(CEC_USER_CONTROL_CODE_,TIMER_PROGRAMMING );
826 NAMETRICK2(CEC_USER_CONTROL_CODE_,INITIAL_CONFIGURATION );
827 NAMETRICK2(CEC_USER_CONTROL_CODE_,PLAY_FUNCTION );
828 NAMETRICK2(CEC_USER_CONTROL_CODE_,PAUSE_PLAY_FUNCTION );
829 NAMETRICK2(CEC_USER_CONTROL_CODE_,RECORD_FUNCTION );
830 NAMETRICK2(CEC_USER_CONTROL_CODE_,PAUSE_RECORD_FUNCTION );
831 NAMETRICK2(CEC_USER_CONTROL_CODE_,STOP_FUNCTION );
832 NAMETRICK2(CEC_USER_CONTROL_CODE_,MUTE_FUNCTION );
833 NAMETRICK2(CEC_USER_CONTROL_CODE_,RESTORE_VOLUME_FUNCTION );
834 NAMETRICK2(CEC_USER_CONTROL_CODE_,TUNE_FUNCTION );
835 NAMETRICK2(CEC_USER_CONTROL_CODE_,SELECT_MEDIA_FUNCTION );
836 NAMETRICK2(CEC_USER_CONTROL_CODE_,SELECT_AV_INPUT_FUNCTION );
837 NAMETRICK2(CEC_USER_CONTROL_CODE_,SELECT_AUDIO_INPUT_FUNCTION );
838 NAMETRICK2(CEC_USER_CONTROL_CODE_,POWER_TOGGLE_FUNCTION );
839 NAMETRICK2(CEC_USER_CONTROL_CODE_,POWER_OFF_FUNCTION );
840 NAMETRICK2(CEC_USER_CONTROL_CODE_,POWER_ON_FUNCTION );
841 NAMETRICK2(CEC_USER_CONTROL_CODE_,F1_BLUE );
842 NAMETRICK2(CEC_USER_CONTROL_CODE_,F2_RED );
843 NAMETRICK2(CEC_USER_CONTROL_CODE_,F3_GREEN );
844 NAMETRICK2(CEC_USER_CONTROL_CODE_,F4_YELLOW );
845 NAMETRICK2(CEC_USER_CONTROL_CODE_,F5 );
846 NAMETRICK2(CEC_USER_CONTROL_CODE_,DATA );
847 NAMETRICK2(CEC_USER_CONTROL_CODE_,AN_RETURN );
848 NAMETRICK2(CEC_USER_CONTROL_CODE_,AN_CHANNELS_LIST );
849 NAMETRICK2(CEC_USER_CONTROL_CODE_,MAX );
855 char* RemoteLinux::HCWDesc(unsigned long long hcw)
858 unsigned int type = hcw >> 32;
863 unsigned int vk=(ULONG)hcw;
865 const char *desc=linux_keymap[vk];
869 sprintf(rt,"0x%x",vk);
873 unsigned int vk=(ULONG)hcw;
875 const char *desc=cec_keymap[vk];
879 sprintf(rt,"0x%x",vk);
886 sprintf(rt,"R: %X",ri);
893 void RemoteLinux::changePowerState(bool poweron){
896 //Log::getInstance()->log("Remote", Log::DEBUG, "CEC set active source" );
897 cec_adap->SetActiveSource(cec_config.deviceTypes[0]);
900 //Log::getInstance()->log("Remote", Log::DEBUG, "CEC set inactive view" );
901 cec_adap->SetInactiveView();
902 haspower=false; //clear stuff
908 int RemoteLinux::cecLogMessage(void *param, const cec_log_message &message)
910 Log::getInstance()->log("Remote", Log::DEBUG, "CECLOG: %lld %d %s",message.time , message.level, message.message );
914 int RemoteLinux::cecKeyPress(void*param, const cec_keypress &key)
916 //Log::getInstance()->log("Remote", Log::DEBUG, "Incoming cec key %d %d", key.keycode,key.duration);
917 if (key.duration==0) ((RemoteLinux*)Remote::getInstance())->incomingCECkey(key.keycode);
920 int RemoteLinux::cecCommand(void *param, const cec_command &command)
922 Log::getInstance()->log("Remote", Log::DEBUG, "CECCommand: %d",command.opcode);
923 switch (command.opcode) {
924 case CEC_OPCODE_STANDBY: {
925 if (command.initiator==CECDEVICE_TV) {
926 ((RemoteLinux*)Remote::getInstance())->incomingPowerkey(POWEROFF);
929 case CEC_OPCODE_DECK_CONTROL: {
930 if (command.initiator==CECDEVICE_TV && command.parameters.size == 1
931 && command.parameters[0]==CEC_DECK_CONTROL_MODE_STOP) {
932 ((RemoteLinux*)Remote::getInstance())->incomingCECkey(CEC_USER_CONTROL_CODE_STOP);
937 case CEC_OPCODE_PLAY: {
938 if (command.initiator==CECDEVICE_TV && command.parameters.size == 1) {
939 if (command.parameters[0]==CEC_PLAY_MODE_PLAY_FORWARD) {
940 ((RemoteLinux*)Remote::getInstance())->incomingCECkey(CEC_USER_CONTROL_CODE_PLAY);
941 } else if (command.parameters[0]==CEC_PLAY_MODE_PLAY_STILL) {
942 ((RemoteLinux*)Remote::getInstance())->incomingCECkey(CEC_USER_CONTROL_CODE_PAUSE);
954 int RemoteLinux::cecConfigurationChanged(void *param, const libcec_configuration &config)
956 Log::getInstance()->log("Remote", Log::DEBUG, "CECConfig:"/*,config.string()*/);
961 void RemoteLinux::cecSourceActivated(void*param, const cec_logical_address address, const uint8_t activated)
963 Log::getInstance()->log("Remote", Log::DEBUG, "CECSourceActivated: %d %d", address, activated);
965 ((RemoteLinux*)Remote::getInstance())->incomingPowerkey(POWERON);
969 void RemoteLinux::incomingCECkey(int keys)
976 void RemoteLinux::incomingPowerkey(UCHAR key){
981 bool RemoteLinux::loadOptionsfromServer(VDR* vdr)
986 name = vdr->configLoad("RemoteLinux", "HandleVolume");
989 if (STRCASECMP(name, "Vomp") == 0) {
990 cechandlesvolume=false;
991 } else if (STRCASECMP(name, "Cec") == 0) {
992 cechandlesvolume=true;
995 return Remote::loadOptionsfromServer(vdr);
998 bool RemoteLinux::saveOptionstoServer()
1000 if (cechandlesvolume) VDR::getInstance()->configSave("RemoteLinux", "HandleVolume","Cec");
1001 else VDR::getInstance()->configSave("RemoteLinux", "HandleVolume","Vomp");
1003 return Remote::saveOptionstoServer();
1006 bool RemoteLinux::addOptionsToPanes(int panenumber,Options *options,WOptionPane* pane)
1008 if (!Remote::addOptionsToPanes(panenumber,options,pane)) return false;
1012 if (panenumber == 2)
1014 static const char* volumeopts[]={"Vomp","Cec"};
1015 option = new Option(100,tr("Volume handled by"), "RemoteLinux","HandleVolume",Option::TYPE_TEXT,/*4,2*/2,0,0,volumeopts,NULL,false,this);
1016 options->push_back(option);
1017 pane->addOptionLine(option);
1023 bool RemoteLinux::handleOptionChanges(Option* option)
1025 if (Remote::handleOptionChanges(option))
1027 switch (option->id) {
1029 if (STRCASECMP(option->options[option->userSetChoice], "Vomp") == 0) {
1030 cechandlesvolume=false;
1031 } else if (STRCASECMP(option->options[option->userSetChoice], "Cec")
1033 cechandlesvolume=true;
1035 Log::getInstance()->log("Remote", Log::DEBUG, "Set volume handling to to %s %d",option->options[option->userSetChoice],cechandlesvolume);
1044 void RemoteLinux::volumeUp()
1046 cec_adap->VolumeUp();
1049 void RemoteLinux::volumeDown()
1051 cec_adap->VolumeDown();
1054 void RemoteLinux::volumeMute()
1056 cec_adap->MuteAudio();