Commit | Line | Data |
---|---|---|
e9de9629 LOK |
1 | /* |
2 | * This file is part of the libCEC(R) library. | |
3 | * | |
4 | * libCEC(R) is Copyright (C) 2011 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 "CECBusDevice.h" | |
eafa9d46 LOK |
34 | #include "../CECProcessor.h" |
35 | #include "../implementations/ANCommandHandler.h" | |
36 | #include "../implementations/CECCommandHandler.h" | |
37 | #include "../implementations/SLCommandHandler.h" | |
38 | #include "../platform/timeutils.h" | |
e9de9629 LOK |
39 | |
40 | using namespace CEC; | |
41 | ||
42 | CCECBusDevice::CCECBusDevice(CCECProcessor *processor, cec_logical_address iLogicalAddress, uint16_t iPhysicalAddress) : | |
43 | m_iPhysicalAddress(iPhysicalAddress), | |
44 | m_iLogicalAddress(iLogicalAddress), | |
e55f3f70 | 45 | m_powerStatus(CEC_POWER_STATUS_UNKNOWN), |
e9de9629 | 46 | m_processor(processor), |
0ab58650 | 47 | m_iVendorClass(CEC_VENDOR_UNKNOWN), |
6a1c0009 LOK |
48 | m_iLastActive(0), |
49 | m_cecVersion(CEC_VERSION_UNKNOWN) | |
e9de9629 LOK |
50 | { |
51 | m_handler = new CCECCommandHandler(this); | |
a3269a0a LOK |
52 | for (unsigned int iPtr = 0; iPtr < 4; iPtr++) |
53 | m_menuLanguage.language[iPtr] = '?'; | |
54 | m_menuLanguage.language[3] = 0; | |
55 | m_menuLanguage.device = iLogicalAddress; | |
0500da96 | 56 | m_vendor.vendor = CEC_VENDOR_UNKNOWN; |
1fcf5a3f LOK |
57 | |
58 | switch(iLogicalAddress) | |
59 | { | |
60 | case CECDEVICE_AUDIOSYSTEM: | |
61 | m_type = CEC_DEVICE_TYPE_AUDIO_SYSTEM; | |
62 | m_strDeviceName = "Audio"; | |
63 | case CECDEVICE_PLAYBACKDEVICE1: | |
64 | case CECDEVICE_PLAYBACKDEVICE2: | |
65 | case CECDEVICE_PLAYBACKDEVICE3: | |
66 | m_type = CEC_DEVICE_TYPE_PLAYBACK_DEVICE; | |
67 | m_strDeviceName = "Player"; | |
68 | case CECDEVICE_RECORDINGDEVICE1: | |
69 | case CECDEVICE_RECORDINGDEVICE2: | |
70 | case CECDEVICE_RECORDINGDEVICE3: | |
71 | m_type = CEC_DEVICE_TYPE_RECORDING_DEVICE; | |
72 | m_strDeviceName = "Recorder"; | |
73 | case CECDEVICE_TUNER1: | |
74 | case CECDEVICE_TUNER2: | |
75 | case CECDEVICE_TUNER3: | |
76 | case CECDEVICE_TUNER4: | |
77 | m_type = CEC_DEVICE_TYPE_TUNER; | |
78 | m_strDeviceName = "Tuner"; | |
79 | case CECDEVICE_TV: | |
80 | m_type = CEC_DEVICE_TYPE_TV; | |
81 | m_strDeviceName = "TV"; | |
82 | default: | |
83 | m_type = CEC_DEVICE_TYPE_RESERVED; | |
84 | m_strDeviceName = "Unknown"; | |
85 | } | |
e9de9629 LOK |
86 | } |
87 | ||
88 | CCECBusDevice::~CCECBusDevice(void) | |
89 | { | |
6a1c0009 | 90 | m_condition.Broadcast(); |
e9de9629 LOK |
91 | delete m_handler; |
92 | } | |
93 | ||
94 | cec_logical_address CCECBusDevice::GetMyLogicalAddress(void) const | |
95 | { | |
96 | return m_processor->GetLogicalAddress(); | |
97 | } | |
98 | ||
f8513317 LOK |
99 | bool CCECBusDevice::MyLogicalAddressContains(cec_logical_address address) const |
100 | { | |
101 | return m_processor->HasLogicalAddress(address); | |
102 | } | |
103 | ||
e9de9629 LOK |
104 | uint16_t CCECBusDevice::GetMyPhysicalAddress(void) const |
105 | { | |
106 | return m_processor->GetPhysicalAddress(); | |
107 | } | |
108 | ||
109 | void CCECBusDevice::AddLog(cec_log_level level, const CStdString &strMessage) | |
110 | { | |
111 | m_processor->AddLog(level, strMessage); | |
112 | } | |
113 | ||
a3269a0a LOK |
114 | void CCECBusDevice::SetMenuLanguage(const cec_menu_language &language) |
115 | { | |
116 | if (language.device == m_iLogicalAddress) | |
117 | { | |
118 | CStdString strLog; | |
119 | strLog.Format("device %d menu language set to '%s'", m_iLogicalAddress, language.language); | |
120 | m_processor->AddLog(CEC_LOG_DEBUG, strLog); | |
121 | m_menuLanguage = language; | |
122 | } | |
123 | } | |
124 | ||
e55f3f70 | 125 | void CCECBusDevice::SetCecVersion(const cec_version newVersion) |
6a1c0009 LOK |
126 | { |
127 | CStdString strLog; | |
128 | m_cecVersion = newVersion; | |
129 | ||
130 | switch (newVersion) | |
131 | { | |
132 | case CEC_VERSION_1_2: | |
133 | strLog.Format("device %d reports CEC version 1.2", m_iLogicalAddress); | |
134 | break; | |
135 | case CEC_VERSION_1_2A: | |
136 | strLog.Format("device %d reports CEC version 1.2a", m_iLogicalAddress); | |
137 | break; | |
138 | case CEC_VERSION_1_3: | |
139 | strLog.Format("device %d reports CEC version 1.3", m_iLogicalAddress); | |
140 | break; | |
141 | case CEC_VERSION_1_3A: | |
142 | strLog.Format("device %d reports CEC version 1.3a", m_iLogicalAddress); | |
143 | break; | |
144 | default: | |
145 | strLog.Format("device %d reports an unknown CEC version", m_iLogicalAddress); | |
146 | m_cecVersion = CEC_VERSION_UNKNOWN; | |
147 | break; | |
148 | } | |
149 | AddLog(CEC_LOG_DEBUG, strLog); | |
150 | } | |
151 | ||
e55f3f70 LOK |
152 | void CCECBusDevice::SetPowerStatus(const cec_power_status powerStatus) |
153 | { | |
b0271d54 LOK |
154 | if (m_powerStatus != powerStatus) |
155 | { | |
156 | CStdString strLog; | |
157 | strLog.Format("device %d power status changed from %2x to %2x", m_iLogicalAddress, m_powerStatus, powerStatus); | |
158 | m_processor->AddLog(CEC_LOG_DEBUG, strLog); | |
159 | m_powerStatus = powerStatus; | |
160 | } | |
e55f3f70 LOK |
161 | } |
162 | ||
0f23c85c LOK |
163 | void CCECBusDevice::SetVendorId(const cec_datapacket &data) |
164 | { | |
165 | if (data.size < 3) | |
166 | { | |
167 | AddLog(CEC_LOG_WARNING, "invalid vendor ID received"); | |
168 | return; | |
169 | } | |
170 | ||
171 | uint64_t iVendorId = ((uint64_t)data[0] << 3) + | |
172 | ((uint64_t)data[1] << 2) + | |
173 | (uint64_t)data[2]; | |
174 | ||
175 | SetVendorId(iVendorId, data.size >= 4 ? data[3] : 0); | |
176 | } | |
177 | ||
2cd8b5d0 | 178 | void CCECBusDevice::SetVendorId(uint64_t iVendorId, uint8_t iVendorClass /* = 0 */) |
e9de9629 | 179 | { |
0500da96 | 180 | m_vendor.vendor = (cec_vendor_id)iVendorId; |
e9de9629 LOK |
181 | m_iVendorClass = iVendorClass; |
182 | ||
183 | switch (iVendorId) | |
184 | { | |
185 | case CEC_VENDOR_SAMSUNG: | |
0ab58650 LOK |
186 | if (m_handler->GetVendorId() != CEC_VENDOR_SAMSUNG) |
187 | { | |
188 | delete m_handler; | |
189 | m_handler = new CANCommandHandler(this); | |
190 | } | |
e9de9629 LOK |
191 | break; |
192 | case CEC_VENDOR_LG: | |
0ab58650 LOK |
193 | if (m_handler->GetVendorId() != CEC_VENDOR_LG) |
194 | { | |
195 | delete m_handler; | |
196 | m_handler = new CSLCommandHandler(this); | |
197 | } | |
e9de9629 LOK |
198 | break; |
199 | default: | |
0ab58650 LOK |
200 | if (m_handler->GetVendorId() != CEC_VENDOR_UNKNOWN) |
201 | { | |
202 | delete m_handler; | |
203 | m_handler = new CCECCommandHandler(this); | |
204 | } | |
e9de9629 LOK |
205 | break; |
206 | } | |
207 | ||
208 | CStdString strLog; | |
0f23c85c | 209 | strLog.Format("device %d: vendor = %s (%06x) class = %2x", m_iLogicalAddress, GetVendorName(), GetVendorId(), GetVendorClass()); |
e9de9629 LOK |
210 | m_processor->AddLog(CEC_LOG_DEBUG, strLog.c_str()); |
211 | } | |
212 | ||
213 | bool CCECBusDevice::HandleCommand(const cec_command &command) | |
214 | { | |
215 | CLockObject lock(&m_mutex); | |
0ab58650 | 216 | m_iLastActive = GetTimeMs(); |
e9de9629 | 217 | m_handler->HandleCommand(command); |
6a1c0009 | 218 | m_condition.Signal(); |
e9de9629 LOK |
219 | return true; |
220 | } | |
221 | ||
0500da96 | 222 | const cec_vendor &CCECBusDevice::GetVendor(void) |
44c74256 | 223 | { |
0500da96 | 224 | if (m_vendor.vendor == CEC_VENDOR_UNKNOWN) |
44c74256 LOK |
225 | { |
226 | AddLog(CEC_LOG_NOTICE, "<< requesting vendor ID"); | |
227 | cec_command command; | |
f8513317 | 228 | cec_command::format(command, GetMyLogicalAddress(), m_iLogicalAddress, CEC_OPCODE_GIVE_DEVICE_VENDOR_ID); |
44c74256 LOK |
229 | CLockObject lock(&m_mutex); |
230 | ||
231 | if (m_processor->Transmit(command)) | |
232 | m_condition.Wait(&m_mutex, 1000); | |
233 | } | |
234 | ||
0500da96 | 235 | return m_vendor; |
44c74256 LOK |
236 | } |
237 | ||
0ab58650 LOK |
238 | void CCECBusDevice::PollVendorId(void) |
239 | { | |
240 | CLockObject lock(&m_mutex); | |
0f23c85c | 241 | if (m_iLastActive > 0 && m_iLogicalAddress != CECDEVICE_BROADCAST && |
0500da96 | 242 | m_vendor.vendor == CEC_VENDOR_UNKNOWN && |
0ab58650 LOK |
243 | GetTimeMs() - m_iLastActive > 5000) |
244 | { | |
245 | m_iLastActive = GetTimeMs(); | |
246 | ||
247 | cec_command command; | |
f8513317 | 248 | cec_command::format(command, GetMyLogicalAddress(), m_iLogicalAddress, CEC_OPCODE_GIVE_DEVICE_VENDOR_ID); |
a9e03a86 LOK |
249 | if (m_processor->Transmit(command)) |
250 | m_condition.Wait(&m_mutex, 1000); | |
0ab58650 LOK |
251 | } |
252 | } | |
253 | ||
4e4be5cf LOK |
254 | void CCECBusDevice::SetPhysicalAddress(uint16_t iNewAddress, uint16_t iOldAddress /* = 0 */) |
255 | { | |
5eb9e3af LOK |
256 | if (iNewAddress > 0) |
257 | { | |
258 | CStdString strLog; | |
f8513317 | 259 | strLog.Format(">> %i changed physical address from %04x to %04x", m_iLogicalAddress, m_iPhysicalAddress, iNewAddress); |
5eb9e3af | 260 | AddLog(CEC_LOG_DEBUG, strLog.c_str()); |
4e4be5cf | 261 | |
5eb9e3af LOK |
262 | m_iPhysicalAddress = iNewAddress; |
263 | } | |
4e4be5cf LOK |
264 | } |
265 | ||
0f23c85c LOK |
266 | bool CCECBusDevice::PowerOn(void) |
267 | { | |
268 | CStdString strLog; | |
269 | strLog.Format("<< powering on device with logical address %d", (int8_t)m_iLogicalAddress); | |
270 | AddLog(CEC_LOG_DEBUG, strLog.c_str()); | |
271 | ||
272 | cec_command command; | |
273 | cec_command::format(command, GetMyLogicalAddress(), m_iLogicalAddress, CEC_OPCODE_IMAGE_VIEW_ON); | |
274 | ||
275 | return m_processor->Transmit(command); | |
276 | } | |
277 | ||
278 | bool CCECBusDevice::Standby(void) | |
279 | { | |
280 | CStdString strLog; | |
281 | strLog.Format("<< putting device with logical address %d in standby mode", (int8_t)m_iLogicalAddress); | |
282 | AddLog(CEC_LOG_DEBUG, strLog.c_str()); | |
283 | ||
284 | cec_command command; | |
285 | cec_command::format(command, GetMyLogicalAddress(), m_iLogicalAddress, CEC_OPCODE_STANDBY); | |
286 | ||
287 | return m_processor->Transmit(command); | |
288 | } | |
289 | ||
290 | bool CCECBusDevice::SetOSDString(cec_display_control duration, const char *strMessage) | |
291 | { | |
292 | CStdString strLog; | |
293 | strLog.Format("<< display message '%s'", strMessage); | |
294 | AddLog(CEC_LOG_NOTICE, strLog.c_str()); | |
295 | ||
296 | cec_command command; | |
297 | cec_command::format(command, GetMyLogicalAddress(), m_iLogicalAddress, CEC_OPCODE_SET_OSD_STRING); | |
298 | command.parameters.push_back((uint8_t)duration); | |
299 | ||
300 | for (unsigned int iPtr = 0; iPtr < strlen(strMessage); iPtr++) | |
301 | command.parameters.push_back(strMessage[iPtr]); | |
302 | ||
303 | return m_processor->Transmit(command); | |
304 | } | |
305 | ||
f8513317 | 306 | bool CCECBusDevice::ReportCECVersion(cec_logical_address dest) |
0f23c85c LOK |
307 | { |
308 | AddLog(CEC_LOG_NOTICE, "<< reporting CEC version as 1.3a"); | |
309 | ||
310 | cec_command command; | |
f8513317 | 311 | cec_command::format(command, m_iLogicalAddress, dest, CEC_OPCODE_CEC_VERSION); |
0f23c85c LOK |
312 | command.parameters.push_back(CEC_VERSION_1_3A); |
313 | ||
314 | return m_processor->Transmit(command); | |
315 | } | |
316 | ||
f8513317 | 317 | bool CCECBusDevice::ReportDeckStatus(cec_logical_address dest) |
0f23c85c LOK |
318 | { |
319 | // need to support opcodes play and deck control before doing anything with this | |
320 | AddLog(CEC_LOG_NOTICE, "<< deck status requested, feature abort"); | |
f8513317 | 321 | m_processor->TransmitAbort(dest, CEC_OPCODE_GIVE_DEVICE_VENDOR_ID); |
0f23c85c LOK |
322 | return false; |
323 | } | |
324 | ||
f8513317 | 325 | bool CCECBusDevice::ReportMenuState(cec_logical_address dest, bool bActive /* = true */) |
0f23c85c LOK |
326 | { |
327 | if (bActive) | |
328 | AddLog(CEC_LOG_NOTICE, "<< reporting menu state as active"); | |
329 | else | |
330 | AddLog(CEC_LOG_NOTICE, "<< reporting menu state as inactive"); | |
331 | ||
332 | cec_command command; | |
f8513317 | 333 | cec_command::format(command, m_iLogicalAddress, dest, CEC_OPCODE_MENU_STATUS); |
0f23c85c LOK |
334 | command.parameters.push_back(bActive ? (uint8_t) CEC_MENU_STATE_ACTIVATED : (uint8_t) CEC_MENU_STATE_DEACTIVATED); |
335 | ||
336 | return m_processor->Transmit(command); | |
337 | } | |
338 | ||
f8513317 | 339 | bool CCECBusDevice::ReportOSDName(cec_logical_address dest) |
0f23c85c LOK |
340 | { |
341 | const char *osdname = m_processor->GetDeviceName().c_str(); | |
342 | CStdString strLog; | |
343 | strLog.Format("<< reporting OSD name as %s", osdname); | |
344 | AddLog(CEC_LOG_NOTICE, strLog.c_str()); | |
345 | ||
346 | cec_command command; | |
f8513317 | 347 | cec_command::format(command, m_iLogicalAddress, dest, CEC_OPCODE_SET_OSD_NAME); |
0f23c85c LOK |
348 | for (unsigned int iPtr = 0; iPtr < strlen(osdname); iPtr++) |
349 | command.parameters.push_back(osdname[iPtr]); | |
350 | ||
351 | return m_processor->Transmit(command); | |
352 | } | |
353 | ||
f8513317 | 354 | bool CCECBusDevice::ReportPowerState(cec_logical_address dest) |
0f23c85c | 355 | { |
f8513317 | 356 | AddLog(CEC_LOG_NOTICE, "<< reporting \"On\" power status"); |
0f23c85c LOK |
357 | |
358 | cec_command command; | |
f8513317 LOK |
359 | cec_command::format(command, m_iLogicalAddress, dest, CEC_OPCODE_REPORT_POWER_STATUS); |
360 | // command.parameters.push_back(bOn ? (uint8_t) CEC_POWER_STATUS_ON : (uint8_t) CEC_POWER_STATUS_STANDBY); | |
361 | command.parameters.push_back((uint8_t) CEC_POWER_STATUS_ON); | |
0f23c85c LOK |
362 | |
363 | return m_processor->Transmit(command); | |
364 | } | |
365 | ||
f8513317 | 366 | bool CCECBusDevice::ReportVendorID(cec_logical_address dest) |
0f23c85c LOK |
367 | { |
368 | AddLog(CEC_LOG_NOTICE, "<< vendor ID requested, feature abort"); | |
f8513317 | 369 | m_processor->TransmitAbort(dest, CEC_OPCODE_GIVE_DEVICE_VENDOR_ID); |
0f23c85c LOK |
370 | return false; |
371 | } | |
372 | ||
373 | bool CCECBusDevice::BroadcastActiveView(void) | |
374 | { | |
375 | AddLog(CEC_LOG_DEBUG, "<< setting active view"); | |
376 | ||
377 | cec_command command; | |
f8513317 | 378 | cec_command::format(command, m_iLogicalAddress, CECDEVICE_BROADCAST, CEC_OPCODE_ACTIVE_SOURCE); |
0f23c85c LOK |
379 | command.parameters.push_back((m_iPhysicalAddress >> 8) & 0xFF); |
380 | command.parameters.push_back(m_iPhysicalAddress & 0xFF); | |
381 | ||
382 | return m_processor->Transmit(command); | |
383 | } | |
384 | ||
385 | bool CCECBusDevice::BroadcastInactiveView(void) | |
386 | { | |
387 | AddLog(CEC_LOG_DEBUG, "<< setting inactive view"); | |
388 | ||
389 | cec_command command; | |
f8513317 | 390 | cec_command::format(command, m_iLogicalAddress, CECDEVICE_BROADCAST, CEC_OPCODE_INACTIVE_SOURCE); |
0f23c85c LOK |
391 | command.parameters.push_back((m_iPhysicalAddress >> 8) & 0xFF); |
392 | command.parameters.push_back(m_iPhysicalAddress & 0xFF); | |
393 | ||
394 | return m_processor->Transmit(command); | |
395 | } | |
396 | ||
397 | bool CCECBusDevice::BroadcastPhysicalAddress(void) | |
398 | { | |
399 | CStdString strLog; | |
400 | strLog.Format("<< reporting physical address as %04x", m_iPhysicalAddress); | |
401 | AddLog(CEC_LOG_NOTICE, strLog.c_str()); | |
402 | ||
403 | cec_command command; | |
f8513317 | 404 | cec_command::format(command, m_iLogicalAddress, CECDEVICE_BROADCAST, CEC_OPCODE_REPORT_PHYSICAL_ADDRESS); |
0f23c85c LOK |
405 | command.parameters.push_back((uint8_t) ((m_iPhysicalAddress >> 8) & 0xFF)); |
406 | command.parameters.push_back((uint8_t) (m_iPhysicalAddress & 0xFF)); | |
407 | command.parameters.push_back((uint8_t) (CEC_DEVICE_TYPE_PLAYBACK_DEVICE)); | |
408 | ||
409 | return m_processor->Transmit(command); | |
410 | } | |
411 | ||
412 | bool CCECBusDevice::BroadcastActiveSource(void) | |
413 | { | |
414 | AddLog(CEC_LOG_NOTICE, "<< broadcasting active source"); | |
415 | ||
416 | cec_command command; | |
f8513317 | 417 | cec_command::format(command, m_iLogicalAddress, CECDEVICE_BROADCAST, CEC_OPCODE_ACTIVE_SOURCE); |
0f23c85c LOK |
418 | command.parameters.push_back((uint8_t) ((m_iPhysicalAddress >> 8) & 0xFF)); |
419 | command.parameters.push_back((uint8_t) (m_iPhysicalAddress & 0xFF)); | |
420 | ||
421 | return m_processor->Transmit(command); | |
422 | } | |
423 | ||
8acf4aac | 424 | cec_version CCECBusDevice::GetCecVersion(bool bRefresh /* = true */) |
6a1c0009 | 425 | { |
8acf4aac | 426 | if (bRefresh || m_cecVersion == CEC_VERSION_UNKNOWN) |
6a1c0009 LOK |
427 | { |
428 | AddLog(CEC_LOG_NOTICE, "<< requesting CEC version"); | |
429 | cec_command command; | |
430 | cec_command::format(command, GetMyLogicalAddress(), m_iLogicalAddress, CEC_OPCODE_GET_CEC_VERSION); | |
431 | CLockObject lock(&m_mutex); | |
432 | if (m_processor->Transmit(command)) | |
433 | m_condition.Wait(&m_mutex, 1000); | |
434 | } | |
435 | ||
436 | return m_cecVersion; | |
437 | } | |
438 | ||
8acf4aac | 439 | cec_menu_language &CCECBusDevice::GetMenuLanguage(bool bRefresh /* = true */) |
a3269a0a | 440 | { |
8acf4aac | 441 | if (bRefresh || !strcmp(m_menuLanguage.language, "???")) |
a3269a0a LOK |
442 | { |
443 | AddLog(CEC_LOG_NOTICE, "<< requesting menu language"); | |
444 | cec_command command; | |
445 | cec_command::format(command, GetMyLogicalAddress(), m_iLogicalAddress, CEC_OPCODE_GET_MENU_LANGUAGE); | |
446 | CLockObject lock(&m_mutex); | |
447 | if (m_processor->Transmit(command)) | |
448 | m_condition.Wait(&m_mutex, 1000); | |
449 | } | |
450 | ||
451 | return m_menuLanguage; | |
452 | } | |
453 | ||
8acf4aac | 454 | cec_power_status CCECBusDevice::GetPowerStatus(bool bRefresh /* = true */) |
e55f3f70 | 455 | { |
8acf4aac | 456 | if (bRefresh || m_powerStatus == CEC_POWER_STATUS_UNKNOWN) |
e55f3f70 LOK |
457 | { |
458 | AddLog(CEC_LOG_NOTICE, "<< requesting power status"); | |
459 | cec_command command; | |
460 | cec_command::format(command, GetMyLogicalAddress(), m_iLogicalAddress, CEC_OPCODE_GIVE_DEVICE_POWER_STATUS); | |
461 | CLockObject lock(&m_mutex); | |
462 | if (m_processor->Transmit(command)) | |
463 | m_condition.Wait(&m_mutex, 1000); | |
464 | } | |
465 | ||
466 | return m_powerStatus; | |
467 | } | |
57f45e6c | 468 | |
f8513317 | 469 | bool CCECBusDevice::PollDevice(cec_logical_address source /* = CECDEVICE_UNKNOWN */) |
57f45e6c LOK |
470 | { |
471 | bool bReturn(false); | |
472 | ||
f8513317 LOK |
473 | if (source == CECDEVICE_UNKNOWN) |
474 | source = GetMyLogicalAddress(); | |
475 | ||
57f45e6c | 476 | CStdString strLog; |
f8513317 | 477 | strLog.Format("<< sending POLL from device %1x to device %1x", (int8_t)source, m_iLogicalAddress); |
57f45e6c LOK |
478 | AddLog(CEC_LOG_DEBUG, strLog); |
479 | ||
480 | cec_command command; | |
f8513317 | 481 | cec_command::format(command, source, m_iLogicalAddress, CEC_OPCODE_NONE); |
57f45e6c LOK |
482 | CLockObject lock(&m_mutex); |
483 | ||
484 | bReturn = m_processor->Transmit(command); | |
485 | AddLog(CEC_LOG_DEBUG, bReturn ? ">> POLL sent" : ">> POLL not sent"); | |
486 | return bReturn; | |
487 | } |