Commit | Line | Data |
---|---|---|
26555d6b LOK |
1 | /* |
2 | * This file is part of the libCEC(R) library. | |
3 | * | |
16f47961 | 4 | * libCEC(R) is Copyright (C) 2011-2013 Pulse-Eight Limited. All rights reserved. |
26555d6b LOK |
5 | * libCEC(R) is an original work, containing original code. |
6 | * | |
7 | * libCEC(R) is a trademark of Pulse-Eight Limited. | |
8 | * | |
9 | * This program is dual-licensed; you can redistribute it and/or modify | |
10 | * it under the terms of the GNU General Public License as published by | |
11 | * the Free Software Foundation; either version 2 of the License, or | |
12 | * (at your option) any later version. | |
13 | * | |
14 | * This program is distributed in the hope that it will be useful, | |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | * GNU General Public License for more details. | |
18 | * | |
19 | * You should have received a copy of the GNU General Public License | |
20 | * along with this program; if not, write to the Free Software | |
21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
22 | * | |
23 | * | |
24 | * Alternatively, you can license this library under a commercial license, | |
25 | * please contact Pulse-Eight Licensing for more information. | |
26 | * | |
27 | * For more information contact: | |
28 | * Pulse-Eight Licensing <license@pulse-eight.com> | |
29 | * http://www.pulse-eight.com/ | |
30 | * http://www.pulse-eight.net/ | |
31 | */ | |
32 | ||
2b44051c | 33 | #include "env.h" |
26555d6b | 34 | #include "RLCommandHandler.h" |
2b44051c LOK |
35 | |
36 | #include "lib/platform/util/timeutils.h" | |
37 | #include "lib/devices/CECBusDevice.h" | |
38 | #include "lib/CECProcessor.h" | |
39 | #include "lib/LibCEC.h" | |
e7c95b16 | 40 | #include "lib/CECClient.h" |
26555d6b LOK |
41 | |
42 | using namespace CEC; | |
43 | using namespace PLATFORM; | |
44 | ||
8b99ad0f LOK |
45 | #define LIB_CEC m_busDevice->GetProcessor()->GetLib() |
46 | ||
e7c95b16 LOK |
47 | #define RL_KEY_TOP_MENU 0x10 |
48 | #define RL_KEY_DVD_MENU 0x11 | |
49 | ||
060a7b5e LOK |
50 | CRLCommandHandler::CRLCommandHandler(CCECBusDevice *busDevice, |
51 | int32_t iTransmitTimeout /* = CEC_DEFAULT_TRANSMIT_TIMEOUT */, | |
52 | int32_t iTransmitWait /* = CEC_DEFAULT_TRANSMIT_WAIT */, | |
53 | int8_t iTransmitRetries /* = CEC_DEFAULT_TRANSMIT_RETRIES */, | |
54 | int64_t iActiveSourcePending /* = 0 */) : | |
55 | CCECCommandHandler(busDevice, iTransmitTimeout, iTransmitWait, iTransmitRetries, iActiveSourcePending) | |
26555d6b | 56 | { |
abec5f17 | 57 | m_vendorId = CEC_VENDOR_TOSHIBA; |
26555d6b LOK |
58 | } |
59 | ||
60 | bool CRLCommandHandler::InitHandler(void) | |
61 | { | |
62 | if (m_bHandlerInited) | |
63 | return true; | |
64 | m_bHandlerInited = true; | |
65 | ||
0b835513 LOK |
66 | if (m_busDevice->GetLogicalAddress() != CECDEVICE_TV) |
67 | return true; | |
68 | ||
42d28d15 LOK |
69 | CCECBusDevice *primary = m_processor->GetPrimaryDevice(); |
70 | if (primary && primary->GetLogicalAddress() != CECDEVICE_UNREGISTERED) | |
26555d6b | 71 | { |
42d28d15 LOK |
72 | /* imitate Toshiba devices */ |
73 | if (m_busDevice->GetLogicalAddress() != primary->GetLogicalAddress()) | |
74 | { | |
75 | primary->SetVendorId(CEC_VENDOR_TOSHIBA); | |
76 | primary->ReplaceHandler(false); | |
77 | } | |
26555d6b | 78 | |
42d28d15 LOK |
79 | if (m_busDevice->GetLogicalAddress() == CECDEVICE_TV) |
80 | { | |
81 | /* send the vendor id */ | |
2b44051c | 82 | primary->TransmitVendorID(CECDEVICE_BROADCAST, false, false); |
42d28d15 | 83 | } |
26555d6b LOK |
84 | } |
85 | ||
86 | return true; | |
87 | } | |
e7c95b16 LOK |
88 | |
89 | int CRLCommandHandler::HandleDeviceVendorCommandWithId(const cec_command &command) | |
90 | { | |
91 | if (!m_processor->IsHandledByLibCEC(command.destination)) | |
92 | return CEC_ABORT_REASON_INVALID_OPERAND; | |
93 | ||
94 | if (command.parameters.size < 4) | |
95 | return CEC_ABORT_REASON_INVALID_OPERAND; | |
96 | ||
97 | // check whether the vendor id matches | |
98 | if (command.parameters[0] != 0x00 || | |
99 | command.parameters[1] != 0x00 || | |
100 | command.parameters[2] != 0x39) | |
101 | return CEC_ABORT_REASON_INVALID_OPERAND; | |
102 | ||
103 | bool bHandled(false); | |
104 | CCECClient* client = m_processor->GetClient(command.destination); | |
105 | if (client) | |
106 | { | |
107 | switch (command.parameters[3]) | |
108 | { | |
109 | // user control pressed | |
110 | case CEC_OPCODE_USER_CONTROL_PRESSED: | |
111 | if (command.parameters.size == 5) | |
112 | { | |
113 | switch (command.parameters[4]) | |
114 | { | |
115 | // top menu -> root menu | |
116 | case RL_KEY_TOP_MENU: | |
117 | client->SetCurrentButton(CEC_USER_CONTROL_CODE_ROOT_MENU); | |
118 | break; | |
119 | // dvd menu -> contents menu | |
120 | case RL_KEY_DVD_MENU: | |
121 | client->SetCurrentButton(CEC_USER_CONTROL_CODE_CONTENTS_MENU); | |
122 | break; | |
123 | default: | |
8b99ad0f | 124 | LIB_CEC->AddLog(CEC_LOG_NOTICE, "key with keycode '%02x' is not mapped in libCEC. please send an email to support@pulse-eight.com with this keycode, and tell which key you pressed, and we'll add support for this key."); |
e7c95b16 LOK |
125 | break; |
126 | } | |
127 | bHandled = true; | |
128 | } | |
129 | break; | |
130 | // user control released | |
131 | case CEC_OPCODE_USER_CONTROL_RELEASE: | |
132 | client->AddKey(); | |
133 | bHandled = true; | |
134 | break; | |
135 | default: | |
136 | break; | |
137 | } | |
138 | } | |
139 | ||
140 | return bHandled ? | |
141 | COMMAND_HANDLED : | |
142 | CCECCommandHandler::HandleDeviceVendorCommandWithId(command); | |
143 | } |