From 2f7b15598665aacde6010e91f858cdb4f078c764 Mon Sep 17 00:00:00 2001 From: Marten Richter Date: Sat, 23 Nov 2013 11:03:55 +0100 Subject: [PATCH] Improve cec handling in remote linux --- command.cc | 29 ++++++++++++++++++++++++++++- command.h | 2 ++ remote.h | 3 +++ remotelinux.cc | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ remotelinux.h | 4 ++++ 5 files changed, 85 insertions(+), 1 deletion(-) diff --git a/command.cc b/command.cc index 1406d86..ada68c6 100644 --- a/command.cc +++ b/command.cc @@ -504,6 +504,16 @@ void Command::handleCommand(int button) doStandby(); return; } + case Remote::POWERON: + { + doPowerOn(); + return; + } + case Remote::POWEROFF: + { + doPowerOff(); + return; + } case Remote::OK: { // FIXME @@ -532,6 +542,19 @@ void Command::sig1() } void Command::doStandby() +{ + if (isStandby) + { + doPowerOn(); + } + else + { + doPowerOff(); + } +} + + +void Command::doPowerOn() { if (isStandby) { @@ -545,7 +568,11 @@ void Command::doStandby() boxstack->add(vconnect); vconnect->run(); } - else +} + +void Command::doPowerOff() +{ + if (!isStandby) { VDR::getInstance()->shutdownVDR(); boxstack->removeAll(); diff --git a/command.h b/command.h index 4ce464b..746b011 100644 --- a/command.h +++ b/command.h @@ -68,6 +68,8 @@ class Command : public MessageQueue private: void handleCommand(int); void doStandby(); + void doPowerOn(); + void doPowerOff(); void doJustConnected(VConnect* vconnect); void doWallpaper(); void doFromTheTop(bool which); // true - show vinfo,wait. false - del vinfo,restart diff --git a/remote.h b/remote.h index 72c0292..19f3701 100644 --- a/remote.h +++ b/remote.h @@ -138,6 +138,9 @@ class Remote: public AbstractOption // Android only const static UCHAR PLAYPAUSE = 201; + // cec only + const static UCHAR POWERON = 202; + const static UCHAR POWEROFF = 203; // Remote types diff --git a/remotelinux.cc b/remotelinux.cc index 7726238..c0af036 100644 --- a/remotelinux.cc +++ b/remotelinux.cc @@ -58,6 +58,8 @@ RemoteLinux::RemoteLinux() initted = 0; curcec=0; hascurcec=false; + haspower=false; + powerkey=0; signal=false; cec_adap=NULL; num_loop=0; @@ -133,6 +135,7 @@ int RemoteLinux::initCec() { cec_callbacks.CBCecKeyPress = cecKeyPress; cec_callbacks.CBCecCommand = cecCommand; cec_callbacks.CBCecConfigurationChanged = cecConfigurationChanged; + cec_callbacks.CBCecSourceActivated = cecSourceActivated; cec_config.clientVersion=LIBCEC_VERSION_CURRENT; cec_config.bActivateSource=1; cec_config.bUseTVMenuLanguage=1; @@ -262,6 +265,10 @@ UCHAR RemoteLinux::getButtonPress(int waitType) { hascurcec = false; return (UCHAR) TranslateHWC(W_G_HCW(W_HCW_CEC,curcec)); } + if (haspower) { + haspower =false; + return powerkey; + } ret = NA_NONE; } else { if (retval == -1) { @@ -911,6 +918,34 @@ int RemoteLinux::cecKeyPress(void*param, const cec_keypress &key) int RemoteLinux::cecCommand(void *param, const cec_command &command) { Log::getInstance()->log("Remote", Log::DEBUG, "CECCommand: %d",command.opcode); + switch (command.opcode) { + case CEC_OPCODE_STANDBY: { + if (command.initiator==CECDEVICE_TV) { + ((RemoteLinux*)Remote::getInstance())->incomingPowerkey(POWEROFF); + } + } break; + case CEC_OPCODE_DECK_CONTROL: { + if (command.initiator==CECDEVICE_TV && command.parameters.size == 1 + && command.parameters[0]==CEC_DECK_CONTROL_MODE_STOP) { + ((RemoteLinux*)Remote::getInstance())->incomingCECkey(CEC_USER_CONTROL_CODE_STOP); + + } + + } break; + case CEC_OPCODE_PLAY: { + if (command.initiator==CECDEVICE_TV && command.parameters.size == 1) { + if (command.parameters[0]==CEC_PLAY_MODE_PLAY_FORWARD) { + ((RemoteLinux*)Remote::getInstance())->incomingCECkey(CEC_USER_CONTROL_CODE_PLAY); + } else if (command.parameters[0]==CEC_PLAY_MODE_PLAY_STILL) { + ((RemoteLinux*)Remote::getInstance())->incomingCECkey(CEC_USER_CONTROL_CODE_PAUSE); + } + } + + + } break; + default: + break; + }; return 1; } @@ -921,6 +956,14 @@ int RemoteLinux::cecConfigurationChanged(void *param, const libcec_configuration } +void RemoteLinux::cecSourceActivated(void*param, const cec_logical_address address, const uint8_t activated) +{ + Log::getInstance()->log("Remote", Log::DEBUG, "CECSourceActivated: %d %d", address, activated); + if (activated==1) { + ((RemoteLinux*)Remote::getInstance())->incomingPowerkey(POWERON); + } +} + void RemoteLinux::incomingCECkey(int keys) { curcec=keys; @@ -928,6 +971,11 @@ void RemoteLinux::incomingCECkey(int keys) } +void RemoteLinux::incomingPowerkey(UCHAR key){ + haspower=true; + powerkey=key; +} + bool RemoteLinux::loadOptionsfromServer(VDR* vdr) { diff --git a/remotelinux.h b/remotelinux.h index 9f65884..bce8760 100644 --- a/remotelinux.h +++ b/remotelinux.h @@ -77,6 +77,8 @@ class RemoteLinux : public Remote int curcec; bool hascurcec; bool cechandlesvolume; + bool haspower; + UCHAR powerkey; UCHAR TranslateHWCFixed(ULLONG code); void InitKeymap(); @@ -88,11 +90,13 @@ class RemoteLinux : public Remote CEC::ICECCallbacks cec_callbacks; void incomingCECkey(int keys); + void incomingPowerkey(UCHAR key); static int cecLogMessage(void *param, const CEC::cec_log_message &message); static int cecKeyPress(void*param, const CEC::cec_keypress &key); static int cecCommand(void *param, const CEC::cec_command &command); static int cecConfigurationChanged(void *param, const CEC::libcec_configuration &config); + static void cecSourceActivated(void*param, const CEC::cec_logical_address address, const uint8_t activated); }; -- 2.39.2