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