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 | ||
e7c95b16 LOK |
45 | #define RL_KEY_TOP_MENU 0x10 |
46 | #define RL_KEY_DVD_MENU 0x11 | |
47 | ||
060a7b5e LOK |
48 | CRLCommandHandler::CRLCommandHandler(CCECBusDevice *busDevice, |
49 | int32_t iTransmitTimeout /* = CEC_DEFAULT_TRANSMIT_TIMEOUT */, | |
50 | int32_t iTransmitWait /* = CEC_DEFAULT_TRANSMIT_WAIT */, | |
51 | int8_t iTransmitRetries /* = CEC_DEFAULT_TRANSMIT_RETRIES */, | |
52 | int64_t iActiveSourcePending /* = 0 */) : | |
53 | CCECCommandHandler(busDevice, iTransmitTimeout, iTransmitWait, iTransmitRetries, iActiveSourcePending) | |
26555d6b | 54 | { |
abec5f17 | 55 | m_vendorId = CEC_VENDOR_TOSHIBA; |
26555d6b LOK |
56 | } |
57 | ||
58 | bool CRLCommandHandler::InitHandler(void) | |
59 | { | |
60 | if (m_bHandlerInited) | |
61 | return true; | |
62 | m_bHandlerInited = true; | |
63 | ||
0b835513 LOK |
64 | if (m_busDevice->GetLogicalAddress() != CECDEVICE_TV) |
65 | return true; | |
66 | ||
42d28d15 LOK |
67 | CCECBusDevice *primary = m_processor->GetPrimaryDevice(); |
68 | if (primary && primary->GetLogicalAddress() != CECDEVICE_UNREGISTERED) | |
26555d6b | 69 | { |
42d28d15 LOK |
70 | /* imitate Toshiba devices */ |
71 | if (m_busDevice->GetLogicalAddress() != primary->GetLogicalAddress()) | |
72 | { | |
73 | primary->SetVendorId(CEC_VENDOR_TOSHIBA); | |
74 | primary->ReplaceHandler(false); | |
75 | } | |
26555d6b | 76 | |
42d28d15 LOK |
77 | if (m_busDevice->GetLogicalAddress() == CECDEVICE_TV) |
78 | { | |
79 | /* send the vendor id */ | |
2b44051c | 80 | primary->TransmitVendorID(CECDEVICE_BROADCAST, false, false); |
42d28d15 | 81 | } |
26555d6b LOK |
82 | } |
83 | ||
84 | return true; | |
85 | } | |
e7c95b16 LOK |
86 | |
87 | int CRLCommandHandler::HandleDeviceVendorCommandWithId(const cec_command &command) | |
88 | { | |
89 | if (!m_processor->IsHandledByLibCEC(command.destination)) | |
90 | return CEC_ABORT_REASON_INVALID_OPERAND; | |
91 | ||
92 | if (command.parameters.size < 4) | |
93 | return CEC_ABORT_REASON_INVALID_OPERAND; | |
94 | ||
95 | // check whether the vendor id matches | |
96 | if (command.parameters[0] != 0x00 || | |
97 | command.parameters[1] != 0x00 || | |
98 | command.parameters[2] != 0x39) | |
99 | return CEC_ABORT_REASON_INVALID_OPERAND; | |
100 | ||
101 | bool bHandled(false); | |
102 | CCECClient* client = m_processor->GetClient(command.destination); | |
103 | if (client) | |
104 | { | |
105 | switch (command.parameters[3]) | |
106 | { | |
107 | // user control pressed | |
108 | case CEC_OPCODE_USER_CONTROL_PRESSED: | |
109 | if (command.parameters.size == 5) | |
110 | { | |
3ff78be2 | 111 | bHandled = true; |
e7c95b16 LOK |
112 | switch (command.parameters[4]) |
113 | { | |
114 | // top menu -> root menu | |
115 | case RL_KEY_TOP_MENU: | |
116 | client->SetCurrentButton(CEC_USER_CONTROL_CODE_ROOT_MENU); | |
117 | break; | |
118 | // dvd menu -> contents menu | |
119 | case RL_KEY_DVD_MENU: | |
120 | client->SetCurrentButton(CEC_USER_CONTROL_CODE_CONTENTS_MENU); | |
121 | break; | |
122 | default: | |
3ff78be2 | 123 | bHandled = false; |
e7c95b16 LOK |
124 | break; |
125 | } | |
e7c95b16 LOK |
126 | } |
127 | break; | |
128 | // user control released | |
129 | case CEC_OPCODE_USER_CONTROL_RELEASE: | |
130 | client->AddKey(); | |
131 | bHandled = true; | |
132 | break; | |
133 | default: | |
134 | break; | |
135 | } | |
136 | } | |
137 | ||
138 | return bHandled ? | |
139 | COMMAND_HANDLED : | |
140 | CCECCommandHandler::HandleDeviceVendorCommandWithId(command); | |
141 | } |