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