Commit | Line | Data |
---|---|---|
a75e3a5a LOK |
1 | /* |
2 | * This file is part of the libCEC(R) library. | |
3 | * | |
4 | * libCEC(R) is Copyright (C) 2011-2012 Pulse-Eight Limited. All rights reserved. | |
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" |
a75e3a5a | 34 | #include "USBCECAdapterCommands.h" |
2b44051c LOK |
35 | |
36 | #include "USBCECAdapterMessage.h" | |
37 | #include "USBCECAdapterCommunication.h" | |
38 | #include "lib/LibCEC.h" | |
39 | #include "lib/CECProcessor.h" | |
40 | #include "lib/CECTypeUtils.h" | |
41 | #include <stdio.h> | |
a75e3a5a LOK |
42 | |
43 | using namespace CEC; | |
44 | using namespace PLATFORM; | |
45 | ||
004b8382 | 46 | #define LIB_CEC m_comm->m_callback->GetLib() |
0d800fe5 | 47 | #define ToString(p) CCECTypeUtils::ToString(p) |
004b8382 | 48 | |
7c5c5bf4 LOK |
49 | CUSBCECAdapterCommands::CUSBCECAdapterCommands(CUSBCECAdapterCommunication *comm) : |
50 | m_comm(comm), | |
51 | m_bSettingsRetrieved(false), | |
52 | m_bSettingAutoEnabled(false), | |
53 | m_settingCecVersion(CEC_VERSION_UNKNOWN), | |
54 | m_iSettingLAMask(0), | |
b2f56d35 | 55 | m_bNeedsWrite(false), |
a38292a3 LOK |
56 | m_iBuildDate(CEC_FW_BUILD_UNKNOWN), |
57 | m_bControlledMode(false) | |
7c5c5bf4 LOK |
58 | { |
59 | m_persistedConfiguration.Clear(); | |
60 | } | |
61 | ||
a75e3a5a LOK |
62 | cec_datapacket CUSBCECAdapterCommands::RequestSetting(cec_adapter_messagecode msgCode) |
63 | { | |
64 | cec_datapacket retVal; | |
65 | retVal.Clear(); | |
66 | ||
67 | CCECAdapterMessage params; | |
68 | CCECAdapterMessage *message = m_comm->SendCommand(msgCode, params); | |
69 | if (message->state == ADAPTER_MESSAGE_STATE_SENT_ACKED) | |
70 | { | |
71 | retVal = message->response; | |
72 | retVal.Shift(2); // shift out start and msgcode | |
73 | retVal.size -= 1; // remove end | |
74 | } | |
c9d15485 | 75 | |
a75e3a5a LOK |
76 | delete message; |
77 | return retVal; | |
78 | } | |
79 | ||
80 | uint16_t CUSBCECAdapterCommands::RequestFirmwareVersion(void) | |
81 | { | |
7c5c5bf4 | 82 | m_persistedConfiguration.iFirmwareVersion = CEC_FW_VERSION_UNKNOWN; |
a75e3a5a LOK |
83 | unsigned int iFwVersionTry(0); |
84 | ||
7c5c5bf4 | 85 | while (m_persistedConfiguration.iFirmwareVersion == CEC_FW_VERSION_UNKNOWN && iFwVersionTry++ < 3) |
a75e3a5a | 86 | { |
004b8382 | 87 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "requesting the firmware version"); |
a75e3a5a LOK |
88 | cec_datapacket response = RequestSetting(MSGCODE_FIRMWARE_VERSION); |
89 | if (response.size == 2) | |
7c5c5bf4 | 90 | m_persistedConfiguration.iFirmwareVersion = (response[0] << 8 | response[1]); |
a75e3a5a LOK |
91 | else |
92 | { | |
004b8382 | 93 | LIB_CEC->AddLog(CEC_LOG_WARNING, "the adapter did not respond with a correct firmware version (try %d)", iFwVersionTry); |
a75e3a5a LOK |
94 | CEvent::Sleep(500); |
95 | } | |
96 | } | |
97 | ||
7c5c5bf4 | 98 | if (m_persistedConfiguration.iFirmwareVersion == CEC_FW_VERSION_UNKNOWN) |
a75e3a5a | 99 | { |
004b8382 | 100 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "defaulting to firmware version 1"); |
7c5c5bf4 | 101 | m_persistedConfiguration.iFirmwareVersion = 1; |
a75e3a5a LOK |
102 | } |
103 | ||
7c5c5bf4 | 104 | return m_persistedConfiguration.iFirmwareVersion; |
a75e3a5a LOK |
105 | } |
106 | ||
7c5c5bf4 | 107 | bool CUSBCECAdapterCommands::RequestSettingAutoEnabled(void) |
a75e3a5a | 108 | { |
004b8382 | 109 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "requesting autonomous mode setting"); |
a75e3a5a LOK |
110 | |
111 | cec_datapacket response = RequestSetting(MSGCODE_GET_AUTO_ENABLED); | |
112 | if (response.size == 1) | |
113 | { | |
7c5c5bf4 | 114 | m_bSettingAutoEnabled = response[0] == 1; |
004b8382 | 115 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "using persisted autonomous mode setting: '%s'", m_bSettingAutoEnabled ? "enabled" : "disabled"); |
a75e3a5a LOK |
116 | return true; |
117 | } | |
118 | return false; | |
119 | } | |
120 | ||
7c5c5bf4 | 121 | bool CUSBCECAdapterCommands::RequestSettingCECVersion(void) |
a75e3a5a | 122 | { |
004b8382 | 123 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "requesting CEC version setting"); |
a75e3a5a LOK |
124 | |
125 | cec_datapacket response = RequestSetting(MSGCODE_GET_HDMI_VERSION); | |
126 | if (response.size == 1) | |
127 | { | |
7c5c5bf4 | 128 | m_settingCecVersion = (cec_version)response[0]; |
004b8382 | 129 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "using persisted CEC version setting: '%s'", ToString(m_settingCecVersion)); |
a75e3a5a LOK |
130 | return true; |
131 | } | |
132 | return false; | |
133 | } | |
134 | ||
b2f56d35 LOK |
135 | uint32_t CUSBCECAdapterCommands::RequestBuildDate(void) |
136 | { | |
d2d1660c | 137 | if (m_iBuildDate == CEC_FW_BUILD_UNKNOWN) |
c37545cf | 138 | { |
004b8382 | 139 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "requesting firmware build date"); |
b2f56d35 | 140 | |
c37545cf LOK |
141 | cec_datapacket response = RequestSetting(MSGCODE_GET_BUILDDATE); |
142 | if (response.size == 4) | |
143 | m_iBuildDate = (uint32_t)response[0] << 24 | (uint32_t)response[1] << 16 | (uint32_t)response[2] << 8 | (uint32_t)response[3]; | |
144 | } | |
145 | return m_iBuildDate; | |
b2f56d35 LOK |
146 | } |
147 | ||
7c5c5bf4 | 148 | bool CUSBCECAdapterCommands::RequestSettingDefaultLogicalAddress(void) |
a75e3a5a | 149 | { |
004b8382 | 150 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "requesting default logical address setting"); |
a75e3a5a LOK |
151 | |
152 | cec_datapacket response = RequestSetting(MSGCODE_GET_DEFAULT_LOGICAL_ADDRESS); | |
153 | if (response.size == 1) | |
154 | { | |
7c5c5bf4 | 155 | m_persistedConfiguration.logicalAddresses.primary = (cec_logical_address)response[0]; |
004b8382 | 156 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "using persisted logical address setting: '%s'", ToString(m_persistedConfiguration.logicalAddresses.primary)); |
a75e3a5a LOK |
157 | return true; |
158 | } | |
159 | return false; | |
160 | } | |
161 | ||
7c5c5bf4 | 162 | bool CUSBCECAdapterCommands::RequestSettingDeviceType(void) |
a75e3a5a | 163 | { |
004b8382 | 164 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "requesting device type setting"); |
7c5c5bf4 | 165 | m_persistedConfiguration.deviceTypes.Clear(); |
a75e3a5a LOK |
166 | |
167 | cec_datapacket response = RequestSetting(MSGCODE_GET_DEVICE_TYPE); | |
168 | if (response.size == 1) | |
169 | { | |
7c5c5bf4 | 170 | m_persistedConfiguration.deviceTypes.Add((cec_device_type)response[0]); |
004b8382 | 171 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "using persisted device type setting: '%s'", ToString((cec_device_type)response[0])); |
a75e3a5a LOK |
172 | return true; |
173 | } | |
004b8382 | 174 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "no persisted device type setting"); |
a75e3a5a LOK |
175 | return false; |
176 | } | |
177 | ||
7c5c5bf4 | 178 | bool CUSBCECAdapterCommands::RequestSettingLogicalAddressMask(void) |
a75e3a5a | 179 | { |
004b8382 | 180 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "requesting logical address mask setting"); |
a75e3a5a LOK |
181 | |
182 | cec_datapacket response = RequestSetting(MSGCODE_GET_LOGICAL_ADDRESS_MASK); | |
183 | if (response.size == 2) | |
184 | { | |
7c5c5bf4 | 185 | m_iSettingLAMask = ((uint16_t)response[0] << 8) | ((uint16_t)response[1]); |
004b8382 | 186 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "using persisted logical address mask setting: '%x'", m_iSettingLAMask); |
a75e3a5a LOK |
187 | return true; |
188 | } | |
189 | return false; | |
190 | } | |
191 | ||
7c5c5bf4 | 192 | bool CUSBCECAdapterCommands::RequestSettingOSDName(void) |
a75e3a5a | 193 | { |
004b8382 | 194 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "requesting OSD name setting"); |
a75e3a5a | 195 | |
7c5c5bf4 | 196 | memset(m_persistedConfiguration.strDeviceName, 0, 13); |
a75e3a5a LOK |
197 | cec_datapacket response = RequestSetting(MSGCODE_GET_OSD_NAME); |
198 | if (response.size == 0) | |
7c5c5bf4 | 199 | { |
004b8382 | 200 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "no persisted device name setting"); |
a75e3a5a | 201 | return false; |
7c5c5bf4 | 202 | } |
a75e3a5a LOK |
203 | |
204 | char buf[14]; | |
205 | for (uint8_t iPtr = 0; iPtr < response.size && iPtr < 13; iPtr++) | |
206 | buf[iPtr] = (char)response[iPtr]; | |
207 | buf[response.size] = 0; | |
208 | ||
7c5c5bf4 | 209 | snprintf(m_persistedConfiguration.strDeviceName, 13, "%s", buf); |
004b8382 | 210 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "using persisted device name setting: '%s'", buf); |
a75e3a5a LOK |
211 | return true; |
212 | } | |
213 | ||
7c5c5bf4 | 214 | bool CUSBCECAdapterCommands::RequestSettingPhysicalAddress(void) |
a75e3a5a | 215 | { |
004b8382 | 216 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "requesting physical address setting"); |
a75e3a5a LOK |
217 | |
218 | cec_datapacket response = RequestSetting(MSGCODE_GET_PHYSICAL_ADDRESS); | |
219 | if (response.size == 2) | |
220 | { | |
7c5c5bf4 | 221 | m_persistedConfiguration.iPhysicalAddress = ((uint16_t)response[0] << 8) | ((uint16_t)response[1]); |
004b8382 | 222 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "using persisted physical address setting: '%4x'", m_persistedConfiguration.iPhysicalAddress); |
a75e3a5a LOK |
223 | return true; |
224 | } | |
004b8382 | 225 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "no persisted physical address setting"); |
a75e3a5a LOK |
226 | return false; |
227 | } | |
228 | ||
229 | bool CUSBCECAdapterCommands::SetSettingAutoEnabled(bool enabled) | |
230 | { | |
2b44051c | 231 | bool bReturn(false); |
7c5c5bf4 LOK |
232 | |
233 | /* check whether this value was changed */ | |
c8b0c13a LOK |
234 | { |
235 | CLockObject lock(m_mutex); | |
236 | if (m_bSettingAutoEnabled == enabled) | |
237 | return bReturn; | |
238 | m_bNeedsWrite = true; | |
239 | } | |
7c5c5bf4 | 240 | |
004b8382 | 241 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "turning autonomous mode %s", enabled ? "on" : "off"); |
a75e3a5a LOK |
242 | |
243 | CCECAdapterMessage params; | |
244 | params.PushEscaped(enabled ? 1 : 0); | |
245 | CCECAdapterMessage *message = m_comm->SendCommand(MSGCODE_SET_AUTO_ENABLED, params); | |
7c5c5bf4 | 246 | bReturn = message->state == ADAPTER_MESSAGE_STATE_SENT_ACKED; |
a75e3a5a | 247 | delete message; |
7c5c5bf4 LOK |
248 | |
249 | if (bReturn) | |
c8b0c13a LOK |
250 | { |
251 | CLockObject lock(m_mutex); | |
7c5c5bf4 | 252 | m_bSettingAutoEnabled = enabled; |
c8b0c13a | 253 | } |
7c5c5bf4 | 254 | |
a75e3a5a LOK |
255 | return bReturn; |
256 | } | |
257 | ||
258 | bool CUSBCECAdapterCommands::SetSettingDeviceType(cec_device_type type) | |
259 | { | |
2b44051c | 260 | bool bReturn(false); |
7c5c5bf4 LOK |
261 | |
262 | /* check whether this value was changed */ | |
c8b0c13a LOK |
263 | { |
264 | CLockObject lock(m_mutex); | |
265 | if (m_persistedConfiguration.deviceTypes.types[0] == type) | |
266 | return bReturn; | |
267 | m_bNeedsWrite = true; | |
268 | } | |
7c5c5bf4 | 269 | |
004b8382 | 270 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "setting the device type to %X (previous: %X)", (uint8_t)type, (uint8_t)m_persistedConfiguration.deviceTypes.types[0]); |
a75e3a5a LOK |
271 | |
272 | CCECAdapterMessage params; | |
273 | params.PushEscaped((uint8_t)type); | |
274 | CCECAdapterMessage *message = m_comm->SendCommand(MSGCODE_SET_DEVICE_TYPE, params); | |
7c5c5bf4 | 275 | bReturn = message->state == ADAPTER_MESSAGE_STATE_SENT_ACKED; |
a75e3a5a | 276 | delete message; |
7c5c5bf4 | 277 | |
c8b0c13a LOK |
278 | if (bReturn) |
279 | { | |
280 | CLockObject lock(m_mutex); | |
281 | m_persistedConfiguration.deviceTypes.types[0] = type; | |
282 | } | |
283 | ||
a75e3a5a LOK |
284 | return bReturn; |
285 | } | |
286 | ||
287 | bool CUSBCECAdapterCommands::SetSettingDefaultLogicalAddress(cec_logical_address address) | |
288 | { | |
2b44051c | 289 | bool bReturn(false); |
7c5c5bf4 LOK |
290 | |
291 | /* check whether this value was changed */ | |
c8b0c13a LOK |
292 | { |
293 | CLockObject lock(m_mutex); | |
294 | if (m_persistedConfiguration.logicalAddresses.primary == address) | |
295 | return bReturn; | |
296 | m_bNeedsWrite = true; | |
297 | } | |
7c5c5bf4 | 298 | |
004b8382 | 299 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "setting the default logical address to %X (previous: %X)", (uint8_t)address, (uint8_t)m_persistedConfiguration.logicalAddresses.primary); |
a75e3a5a LOK |
300 | |
301 | CCECAdapterMessage params; | |
302 | params.PushEscaped((uint8_t)address); | |
303 | CCECAdapterMessage *message = m_comm->SendCommand(MSGCODE_SET_DEFAULT_LOGICAL_ADDRESS, params); | |
7c5c5bf4 | 304 | bReturn = message->state == ADAPTER_MESSAGE_STATE_SENT_ACKED; |
a75e3a5a | 305 | delete message; |
7c5c5bf4 LOK |
306 | |
307 | if (bReturn) | |
c8b0c13a LOK |
308 | { |
309 | CLockObject lock(m_mutex); | |
7c5c5bf4 | 310 | m_persistedConfiguration.logicalAddresses.primary = address; |
c8b0c13a | 311 | } |
7c5c5bf4 | 312 | |
a75e3a5a LOK |
313 | return bReturn; |
314 | } | |
315 | ||
316 | bool CUSBCECAdapterCommands::SetSettingLogicalAddressMask(uint16_t iMask) | |
317 | { | |
2b44051c | 318 | bool bReturn(false); |
7c5c5bf4 LOK |
319 | |
320 | /* check whether this value was changed */ | |
c8b0c13a LOK |
321 | { |
322 | CLockObject lock(m_mutex); | |
323 | if (m_iSettingLAMask == iMask) | |
324 | return bReturn; | |
325 | m_bNeedsWrite = true; | |
326 | } | |
7c5c5bf4 | 327 | |
004b8382 | 328 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "setting the logical address mask to %2X (previous: %2X)", iMask, m_iSettingLAMask); |
a75e3a5a LOK |
329 | |
330 | CCECAdapterMessage params; | |
331 | params.PushEscaped(iMask >> 8); | |
332 | params.PushEscaped((uint8_t)iMask); | |
333 | CCECAdapterMessage *message = m_comm->SendCommand(MSGCODE_SET_LOGICAL_ADDRESS_MASK, params); | |
7c5c5bf4 | 334 | bReturn = message->state == ADAPTER_MESSAGE_STATE_SENT_ACKED; |
a75e3a5a | 335 | delete message; |
7c5c5bf4 LOK |
336 | |
337 | if (bReturn) | |
c8b0c13a LOK |
338 | { |
339 | CLockObject lock(m_mutex); | |
7c5c5bf4 | 340 | m_iSettingLAMask = iMask; |
c8b0c13a | 341 | } |
7c5c5bf4 | 342 | |
a75e3a5a LOK |
343 | return bReturn; |
344 | } | |
345 | ||
346 | bool CUSBCECAdapterCommands::SetSettingPhysicalAddress(uint16_t iPhysicalAddress) | |
347 | { | |
2b44051c | 348 | bool bReturn(false); |
7c5c5bf4 LOK |
349 | |
350 | /* check whether this value was changed */ | |
c8b0c13a LOK |
351 | { |
352 | CLockObject lock(m_mutex); | |
353 | if (m_persistedConfiguration.iPhysicalAddress == iPhysicalAddress) | |
354 | return bReturn; | |
355 | m_bNeedsWrite = true; | |
356 | } | |
7c5c5bf4 | 357 | |
004b8382 | 358 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "setting the physical address to %04X (previous: %04X)", iPhysicalAddress, m_persistedConfiguration.iPhysicalAddress); |
a75e3a5a LOK |
359 | |
360 | CCECAdapterMessage params; | |
361 | params.PushEscaped(iPhysicalAddress >> 8); | |
362 | params.PushEscaped((uint8_t)iPhysicalAddress); | |
363 | CCECAdapterMessage *message = m_comm->SendCommand(MSGCODE_SET_PHYSICAL_ADDRESS, params); | |
7c5c5bf4 | 364 | bReturn = message->state == ADAPTER_MESSAGE_STATE_SENT_ACKED; |
a75e3a5a | 365 | delete message; |
7c5c5bf4 LOK |
366 | |
367 | if (bReturn) | |
c8b0c13a LOK |
368 | { |
369 | CLockObject lock(m_mutex); | |
7c5c5bf4 | 370 | m_persistedConfiguration.iPhysicalAddress = iPhysicalAddress; |
c8b0c13a | 371 | } |
7c5c5bf4 | 372 | |
a75e3a5a LOK |
373 | return bReturn; |
374 | } | |
375 | ||
376 | bool CUSBCECAdapterCommands::SetSettingCECVersion(cec_version version) | |
377 | { | |
2b44051c | 378 | bool bReturn(false); |
7c5c5bf4 LOK |
379 | |
380 | /* check whether this value was changed */ | |
c8b0c13a LOK |
381 | { |
382 | CLockObject lock(m_mutex); | |
383 | if (m_settingCecVersion == version) | |
384 | return bReturn; | |
385 | m_bNeedsWrite = true; | |
386 | } | |
7c5c5bf4 | 387 | |
004b8382 | 388 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "setting the CEC version to %s (previous: %s)", ToString(version), ToString(m_settingCecVersion)); |
a75e3a5a LOK |
389 | |
390 | CCECAdapterMessage params; | |
391 | params.PushEscaped((uint8_t)version); | |
392 | CCECAdapterMessage *message = m_comm->SendCommand(MSGCODE_SET_HDMI_VERSION, params); | |
7c5c5bf4 | 393 | bReturn = message->state == ADAPTER_MESSAGE_STATE_SENT_ACKED; |
a75e3a5a | 394 | delete message; |
7c5c5bf4 LOK |
395 | |
396 | if (bReturn) | |
c8b0c13a LOK |
397 | { |
398 | CLockObject lock(m_mutex); | |
7c5c5bf4 | 399 | m_settingCecVersion = version; |
c8b0c13a | 400 | } |
7c5c5bf4 | 401 | |
a75e3a5a LOK |
402 | return bReturn; |
403 | } | |
404 | ||
405 | bool CUSBCECAdapterCommands::SetSettingOSDName(const char *strOSDName) | |
406 | { | |
2b44051c | 407 | bool bReturn(false); |
7c5c5bf4 LOK |
408 | |
409 | /* check whether this value was changed */ | |
410 | if (!strcmp(m_persistedConfiguration.strDeviceName, strOSDName)) | |
7c5c5bf4 | 411 | return bReturn; |
7c5c5bf4 | 412 | |
004b8382 | 413 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "setting the OSD name to %s (previous: %s)", strOSDName, m_persistedConfiguration.strDeviceName); |
a75e3a5a LOK |
414 | |
415 | CCECAdapterMessage params; | |
416 | for (size_t iPtr = 0; iPtr < strlen(strOSDName); iPtr++) | |
417 | params.PushEscaped(strOSDName[iPtr]); | |
418 | CCECAdapterMessage *message = m_comm->SendCommand(MSGCODE_SET_OSD_NAME, params); | |
7c5c5bf4 | 419 | bReturn = message->state == ADAPTER_MESSAGE_STATE_SENT_ACKED; |
a75e3a5a | 420 | delete message; |
7c5c5bf4 LOK |
421 | |
422 | if (bReturn) | |
423 | snprintf(m_persistedConfiguration.strDeviceName, 13, "%s", strOSDName); | |
424 | ||
a75e3a5a LOK |
425 | return bReturn; |
426 | } | |
427 | ||
428 | bool CUSBCECAdapterCommands::WriteEEPROM(void) | |
429 | { | |
c8b0c13a LOK |
430 | { |
431 | CLockObject lock(m_mutex); | |
432 | if (!m_bNeedsWrite) | |
433 | return true; | |
434 | } | |
7c5c5bf4 | 435 | |
004b8382 | 436 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "writing settings in the EEPROM"); |
a75e3a5a LOK |
437 | |
438 | CCECAdapterMessage params; | |
439 | CCECAdapterMessage *message = m_comm->SendCommand(MSGCODE_WRITE_EEPROM, params); | |
c8b0c13a | 440 | bool bReturn = message->state == ADAPTER_MESSAGE_STATE_SENT_ACKED; |
a75e3a5a | 441 | delete message; |
c8b0c13a LOK |
442 | |
443 | if (bReturn) | |
444 | { | |
445 | CLockObject lock(m_mutex); | |
446 | m_bNeedsWrite = false; | |
447 | } | |
448 | ||
449 | return bReturn; | |
a75e3a5a LOK |
450 | } |
451 | ||
c0152c09 | 452 | bool CUSBCECAdapterCommands::PersistConfiguration(const libcec_configuration &configuration) |
a75e3a5a | 453 | { |
2b44051c | 454 | bool bReturn(false); |
7c5c5bf4 | 455 | if (m_persistedConfiguration.iFirmwareVersion < 2) |
2b44051c | 456 | return bReturn; |
7c5c5bf4 LOK |
457 | |
458 | if (!RequestSettings()) | |
2b44051c LOK |
459 | return bReturn; |
460 | ||
461 | bReturn |= SetSettingAutoEnabled(true); | |
462 | bReturn |= SetSettingDeviceType(CLibCEC::GetType(configuration.logicalAddresses.primary)); | |
463 | bReturn |= SetSettingDefaultLogicalAddress(configuration.logicalAddresses.primary); | |
464 | bReturn |= SetSettingLogicalAddressMask(CLibCEC::GetMaskForType(configuration.logicalAddresses.primary)); | |
465 | bReturn |= SetSettingPhysicalAddress(configuration.iPhysicalAddress); | |
466 | bReturn |= SetSettingCECVersion(configuration.clientVersion >= CEC_CLIENT_VERSION_1_8_0 ? configuration.cecVersion : CEC_VERSION_1_4); | |
467 | bReturn |= SetSettingOSDName(configuration.strDeviceName); | |
a75e3a5a | 468 | |
a75e3a5a LOK |
469 | return bReturn; |
470 | } | |
471 | ||
7c5c5bf4 | 472 | bool CUSBCECAdapterCommands::RequestSettings(void) |
a75e3a5a | 473 | { |
7c5c5bf4 | 474 | if (m_persistedConfiguration.iFirmwareVersion < 2) |
a75e3a5a | 475 | { |
004b8382 | 476 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "%s - firmware version %d does not have any eeprom settings", __FUNCTION__, m_persistedConfiguration.iFirmwareVersion); |
7c5c5bf4 LOK |
477 | // settings can only be persisted with firmware v2+ |
478 | return false; | |
a75e3a5a LOK |
479 | } |
480 | ||
4c70b3b6 | 481 | if (m_bSettingsRetrieved) |
7c5c5bf4 | 482 | return true; |
a75e3a5a | 483 | |
7c5c5bf4 LOK |
484 | bool bReturn(true); |
485 | bReturn &= RequestSettingAutoEnabled(); | |
486 | bReturn &= RequestSettingCECVersion(); | |
487 | bReturn &= RequestSettingDefaultLogicalAddress(); | |
488 | bReturn &= RequestSettingDeviceType(); | |
489 | bReturn &= RequestSettingLogicalAddressMask(); | |
490 | bReturn &= RequestSettingOSDName(); | |
491 | bReturn &= RequestSettingPhysicalAddress(); | |
a75e3a5a LOK |
492 | |
493 | // don't read the following settings: | |
494 | // - auto enabled (always enabled) | |
495 | // - default logical address (autodetected) | |
496 | // - logical address mask (autodetected) | |
497 | // - CEC version (1.3a) | |
498 | ||
499 | // TODO to be added to the firmware: | |
500 | // - base device (4 bits) | |
501 | // - HDMI port number (4 bits) | |
502 | // - TV vendor id (12 bits) | |
503 | // - wake devices (8 bits) | |
504 | // - standby devices (8 bits) | |
505 | // - use TV menu language (1 bit) | |
506 | // - activate source (1 bit) | |
507 | // - power off screensaver (1 bit) | |
508 | // - power off on standby (1 bit) | |
509 | // - send inactive source (1 bit) | |
7c5c5bf4 LOK |
510 | |
511 | m_bSettingsRetrieved = true; | |
512 | ||
a75e3a5a LOK |
513 | return bReturn; |
514 | } | |
515 | ||
c0152c09 | 516 | bool CUSBCECAdapterCommands::GetConfiguration(libcec_configuration &configuration) |
7c5c5bf4 LOK |
517 | { |
518 | // get the settings from the eeprom if needed | |
519 | if (!RequestSettings()) | |
520 | return false; | |
521 | ||
522 | // copy the settings | |
c0152c09 LOK |
523 | configuration.iFirmwareVersion = m_persistedConfiguration.iFirmwareVersion; |
524 | configuration.deviceTypes = m_persistedConfiguration.deviceTypes; | |
525 | configuration.iPhysicalAddress = m_persistedConfiguration.iPhysicalAddress; | |
526 | snprintf(configuration.strDeviceName, 13, "%s", m_persistedConfiguration.strDeviceName); | |
7c5c5bf4 LOK |
527 | |
528 | return true; | |
529 | } | |
530 | ||
a75e3a5a LOK |
531 | bool CUSBCECAdapterCommands::PingAdapter(void) |
532 | { | |
004b8382 | 533 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "sending ping"); |
a75e3a5a LOK |
534 | |
535 | CCECAdapterMessage params; | |
536 | CCECAdapterMessage *message = m_comm->SendCommand(MSGCODE_PING, params); | |
537 | bool bReturn = message->state == ADAPTER_MESSAGE_STATE_SENT_ACKED; | |
538 | delete message; | |
539 | return bReturn; | |
540 | } | |
541 | ||
542 | bool CUSBCECAdapterCommands::SetAckMask(uint16_t iMask) | |
543 | { | |
004b8382 | 544 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "setting ackmask to %2x", iMask); |
a75e3a5a LOK |
545 | |
546 | CCECAdapterMessage params; | |
547 | params.PushEscaped(iMask >> 8); | |
548 | params.PushEscaped((uint8_t)iMask); | |
549 | CCECAdapterMessage *message = m_comm->SendCommand(MSGCODE_SET_ACK_MASK, params); | |
550 | bool bReturn = message->state == ADAPTER_MESSAGE_STATE_SENT_ACKED; | |
551 | delete message; | |
552 | return bReturn; | |
553 | } | |
554 | ||
555 | bool CUSBCECAdapterCommands::StartBootloader(void) | |
556 | { | |
004b8382 | 557 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "starting the bootloader"); |
a75e3a5a LOK |
558 | |
559 | CCECAdapterMessage params; | |
560 | CCECAdapterMessage *message = m_comm->SendCommand(MSGCODE_START_BOOTLOADER, params); | |
561 | bool bReturn = message->state == ADAPTER_MESSAGE_STATE_SENT_ACKED; | |
562 | delete message; | |
563 | return bReturn; | |
564 | } | |
565 | ||
566 | bool CUSBCECAdapterCommands::SetLineTimeout(uint8_t iTimeout) | |
567 | { | |
004b8382 | 568 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "setting the line timeout to %d", iTimeout); |
a75e3a5a LOK |
569 | CCECAdapterMessage params; |
570 | params.PushEscaped(iTimeout); | |
571 | CCECAdapterMessage *message = m_comm->SendCommand(MSGCODE_TRANSMIT_IDLETIME, params); | |
572 | bool bReturn = message->state == ADAPTER_MESSAGE_STATE_SENT_ACKED; | |
573 | delete message; | |
574 | return bReturn; | |
575 | } | |
576 | ||
577 | bool CUSBCECAdapterCommands::SetControlledMode(bool controlled) | |
578 | { | |
a38292a3 LOK |
579 | { |
580 | CLockObject lock(m_mutex); | |
581 | if (m_bControlledMode == controlled) | |
582 | return true; | |
583 | } | |
584 | ||
004b8382 | 585 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "turning controlled mode %s", controlled ? "on" : "off"); |
a75e3a5a LOK |
586 | |
587 | CCECAdapterMessage params; | |
588 | params.PushEscaped(controlled ? 1 : 0); | |
589 | CCECAdapterMessage *message = m_comm->SendCommand(MSGCODE_SET_CONTROLLED, params); | |
590 | bool bReturn = message->state == ADAPTER_MESSAGE_STATE_SENT_ACKED; | |
591 | delete message; | |
a38292a3 LOK |
592 | |
593 | if (bReturn) | |
594 | { | |
595 | CLockObject lock(m_mutex); | |
596 | m_bControlledMode = controlled; | |
597 | } | |
598 | ||
a75e3a5a LOK |
599 | return bReturn; |
600 | } |