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