cec: mark the tv as powered up for panasonic once it sends the audiomode request
[deb_libcec.git] / src / lib / CECTypeUtils.h
CommitLineData
0d800fe5
LOK
1#pragma once
2/*
3 * This file is part of the libCEC(R) library.
4 *
5 * libCEC(R) is Copyright (C) 2011-2012 Pulse-Eight Limited. All rights reserved.
6 * libCEC(R) is an original work, containing original code.
7 *
8 * libCEC(R) is a trademark of Pulse-Eight Limited.
9 *
10 * This program is dual-licensed; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 *
24 *
25 * Alternatively, you can license this library under a commercial license,
26 * please contact Pulse-Eight Licensing for more information.
27 *
28 * For more information contact:
29 * Pulse-Eight Licensing <license@pulse-eight.com>
30 * http://www.pulse-eight.com/
31 * http://www.pulse-eight.net/
32 */
33
34#include "../../include/cectypes.h"
35
36namespace CEC
37{
38 class CCECTypeUtils
39 {
40 public:
41 /*!
42 * @brief Get the device type for the given logical address.
43 * @param address The address to get the type for.
44 * @return The type, or CEC_DEVICE_TYPE_RESERVED if unknown.
45 */
46 static cec_device_type GetType(const cec_logical_address address)
47 {
48 switch (address)
49 {
50 case CECDEVICE_AUDIOSYSTEM:
51 return CEC_DEVICE_TYPE_AUDIO_SYSTEM;
52 case CECDEVICE_PLAYBACKDEVICE1:
53 case CECDEVICE_PLAYBACKDEVICE2:
54 case CECDEVICE_PLAYBACKDEVICE3:
55 return CEC_DEVICE_TYPE_PLAYBACK_DEVICE;
56 case CECDEVICE_RECORDINGDEVICE1:
57 case CECDEVICE_RECORDINGDEVICE2:
58 case CECDEVICE_RECORDINGDEVICE3:
59 return CEC_DEVICE_TYPE_RECORDING_DEVICE;
60 case CECDEVICE_TUNER1:
61 case CECDEVICE_TUNER2:
62 case CECDEVICE_TUNER3:
63 case CECDEVICE_TUNER4:
64 return CEC_DEVICE_TYPE_TUNER;
65 case CECDEVICE_TV:
66 return CEC_DEVICE_TYPE_TV;
67 default:
68 return CEC_DEVICE_TYPE_RESERVED;
69 }
70 }
71
72 /*!
73 * @brief Get the ackmask for all devices of the same type as the given logical address.
74 * @param address The address to get the ackmask for.
75 * @return The ackmask for this type.
76 */
77 static uint16_t GetMaskForType(cec_logical_address address)
78 {
79 return GetMaskForType(GetType(address));
80 }
81
82 /*!
83 * @brief Get the ackmask for all devices of the given type.
84 * @param type The type to get the ackmask for.
85 * @return The ackmask for this type, or 0 of no types match.
86 */
87 static uint16_t GetMaskForType(const cec_device_type type)
88 {
89 switch (type)
90 {
91 case CEC_DEVICE_TYPE_AUDIO_SYSTEM:
92 {
93 cec_logical_addresses addr;
94 addr.Clear();
95 addr.Set(CECDEVICE_AUDIOSYSTEM);
96 return addr.AckMask();
97 }
98 case CEC_DEVICE_TYPE_PLAYBACK_DEVICE:
99 {
100 cec_logical_addresses addr;
101 addr.Clear();
102 addr.Set(CECDEVICE_PLAYBACKDEVICE1);
103 addr.Set(CECDEVICE_PLAYBACKDEVICE2);
104 addr.Set(CECDEVICE_PLAYBACKDEVICE3);
105 return addr.AckMask();
106 }
107 case CEC_DEVICE_TYPE_RECORDING_DEVICE:
108 {
109 cec_logical_addresses addr;
110 addr.Clear();
111 addr.Set(CECDEVICE_RECORDINGDEVICE1);
112 addr.Set(CECDEVICE_RECORDINGDEVICE2);
113 addr.Set(CECDEVICE_RECORDINGDEVICE3);
114 return addr.AckMask();
115 }
116 case CEC_DEVICE_TYPE_TUNER:
117 {
118 cec_logical_addresses addr;
119 addr.Clear();
120 addr.Set(CECDEVICE_TUNER1);
121 addr.Set(CECDEVICE_TUNER2);
122 addr.Set(CECDEVICE_TUNER3);
123 addr.Set(CECDEVICE_TUNER4);
124 return addr.AckMask();
125 }
126 case CEC_DEVICE_TYPE_TV:
127 {
128 cec_logical_addresses addr;
129 addr.Clear();
130 addr.Set(CECDEVICE_TV);
131 return addr.AckMask();
132 }
133 default:
134 return 0;
135 }
136 }
137
138 static const char *ToString(const cec_device_type type)
139 {
140 switch (type)
141 {
142 case CEC_DEVICE_TYPE_AUDIO_SYSTEM:
143 return "audio system";
144 case CEC_DEVICE_TYPE_PLAYBACK_DEVICE:
145 return "playback device";
146 case CEC_DEVICE_TYPE_RECORDING_DEVICE:
147 return "recording device";
148 case CEC_DEVICE_TYPE_RESERVED:
149 return "reserved";
150 case CEC_DEVICE_TYPE_TUNER:
151 return "tuner";
152 case CEC_DEVICE_TYPE_TV:
153 return "TV";
154 default:
155 return "unknown";
156 }
157 }
158
159 static const char *ToString(const cec_menu_state state)
160 {
161 switch (state)
162 {
163 case CEC_MENU_STATE_ACTIVATED:
164 return "activated";
165 case CEC_MENU_STATE_DEACTIVATED:
166 return "deactivated";
167 default:
168 return "unknown";
169 }
170 }
171
172 static const char *ToString(const cec_version version)
173 {
174 switch (version)
175 {
176 case CEC_VERSION_1_2:
177 return "1.2";
178 case CEC_VERSION_1_2A:
179 return "1.2a";
180 case CEC_VERSION_1_3:
181 return "1.3";
182 case CEC_VERSION_1_3A:
183 return "1.3a";
184 case CEC_VERSION_1_4:
185 return "1.4";
186 default:
187 return "unknown";
188 }
189 }
190
191 static const char *ToString(const cec_power_status status)
192 {
193 switch (status)
194 {
195 case CEC_POWER_STATUS_ON:
196 return "on";
197 case CEC_POWER_STATUS_STANDBY:
198 return "standby";
199 case CEC_POWER_STATUS_IN_TRANSITION_ON_TO_STANDBY:
200 return "in transition from on to standby";
201 case CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON:
202 return "in transition from standby to on";
203 default:
204 return "unknown";
205 }
206 }
207
208 static const char *ToString(const cec_logical_address address)
209 {
210 switch(address)
211 {
212 case CECDEVICE_AUDIOSYSTEM:
213 return "Audio";
214 case CECDEVICE_BROADCAST:
215 return "Broadcast";
216 case CECDEVICE_FREEUSE:
217 return "Free use";
218 case CECDEVICE_PLAYBACKDEVICE1:
219 return "Playback 1";
220 case CECDEVICE_PLAYBACKDEVICE2:
221 return "Playback 2";
222 case CECDEVICE_PLAYBACKDEVICE3:
223 return "Playback 3";
224 case CECDEVICE_RECORDINGDEVICE1:
225 return "Recorder 1";
226 case CECDEVICE_RECORDINGDEVICE2:
227 return "Recorder 2";
228 case CECDEVICE_RECORDINGDEVICE3:
229 return "Recorder 3";
230 case CECDEVICE_RESERVED1:
231 return "Reserved 1";
232 case CECDEVICE_RESERVED2:
233 return "Reserved 2";
234 case CECDEVICE_TUNER1:
235 return "Tuner 1";
236 case CECDEVICE_TUNER2:
237 return "Tuner 2";
238 case CECDEVICE_TUNER3:
239 return "Tuner 3";
240 case CECDEVICE_TUNER4:
241 return "Tuner 4";
242 case CECDEVICE_TV:
243 return "TV";
244 default:
245 return "unknown";
246 }
247 }
248
249 static const char *ToString(const cec_deck_control_mode mode)
250 {
251 switch (mode)
252 {
253 case CEC_DECK_CONTROL_MODE_SKIP_FORWARD_WIND:
254 return "skip forward wind";
255 case CEC_DECK_CONTROL_MODE_EJECT:
256 return "eject";
257 case CEC_DECK_CONTROL_MODE_SKIP_REVERSE_REWIND:
258 return "reverse rewind";
259 case CEC_DECK_CONTROL_MODE_STOP:
260 return "stop";
261 default:
262 return "unknown";
263 }
264 }
265
266 static const char *ToString(const cec_deck_info status)
267 {
268 switch (status)
269 {
270 case CEC_DECK_INFO_PLAY:
271 return "play";
272 case CEC_DECK_INFO_RECORD:
273 return "record";
274 case CEC_DECK_INFO_PLAY_REVERSE:
275 return "play reverse";
276 case CEC_DECK_INFO_STILL:
277 return "still";
278 case CEC_DECK_INFO_SLOW:
279 return "slow";
280 case CEC_DECK_INFO_SLOW_REVERSE:
281 return "slow reverse";
282 case CEC_DECK_INFO_FAST_FORWARD:
283 return "fast forward";
284 case CEC_DECK_INFO_FAST_REVERSE:
285 return "fast reverse";
286 case CEC_DECK_INFO_NO_MEDIA:
287 return "no media";
288 case CEC_DECK_INFO_STOP:
289 return "stop";
290 case CEC_DECK_INFO_SKIP_FORWARD_WIND:
291 return "info skip forward wind";
292 case CEC_DECK_INFO_SKIP_REVERSE_REWIND:
293 return "info skip reverse rewind";
294 case CEC_DECK_INFO_INDEX_SEARCH_FORWARD:
295 return "info index search forward";
296 case CEC_DECK_INFO_INDEX_SEARCH_REVERSE:
297 return "info index search reverse";
298 case CEC_DECK_INFO_OTHER_STATUS:
299 return "other";
300 case CEC_DECK_INFO_OTHER_STATUS_LG:
301 return "LG other";
302 default:
303 return "unknown";
304 }
305 }
306
307 static const char *ToString(const cec_opcode opcode)
308 {
309 switch (opcode)
310 {
311 case CEC_OPCODE_ACTIVE_SOURCE:
312 return "active source";
313 case CEC_OPCODE_IMAGE_VIEW_ON:
314 return "image view on";
315 case CEC_OPCODE_TEXT_VIEW_ON:
316 return "text view on";
317 case CEC_OPCODE_INACTIVE_SOURCE:
318 return "inactive source";
319 case CEC_OPCODE_REQUEST_ACTIVE_SOURCE:
320 return "request active source";
321 case CEC_OPCODE_ROUTING_CHANGE:
322 return "routing change";
323 case CEC_OPCODE_ROUTING_INFORMATION:
324 return "routing information";
325 case CEC_OPCODE_SET_STREAM_PATH:
326 return "set stream path";
327 case CEC_OPCODE_STANDBY:
328 return "standby";
329 case CEC_OPCODE_RECORD_OFF:
330 return "record off";
331 case CEC_OPCODE_RECORD_ON:
332 return "record on";
333 case CEC_OPCODE_RECORD_STATUS:
334 return "record status";
335 case CEC_OPCODE_RECORD_TV_SCREEN:
336 return "record tv screen";
337 case CEC_OPCODE_CLEAR_ANALOGUE_TIMER:
338 return "clear analogue timer";
339 case CEC_OPCODE_CLEAR_DIGITAL_TIMER:
340 return "clear digital timer";
341 case CEC_OPCODE_CLEAR_EXTERNAL_TIMER:
342 return "clear external timer";
343 case CEC_OPCODE_SET_ANALOGUE_TIMER:
344 return "set analogue timer";
345 case CEC_OPCODE_SET_DIGITAL_TIMER:
346 return "set digital timer";
347 case CEC_OPCODE_SET_EXTERNAL_TIMER:
348 return "set external timer";
349 case CEC_OPCODE_SET_TIMER_PROGRAM_TITLE:
350 return "set timer program title";
351 case CEC_OPCODE_TIMER_CLEARED_STATUS:
352 return "timer cleared status";
353 case CEC_OPCODE_TIMER_STATUS:
354 return "timer status";
355 case CEC_OPCODE_CEC_VERSION:
356 return "cec version";
357 case CEC_OPCODE_GET_CEC_VERSION:
358 return "get cec version";
359 case CEC_OPCODE_GIVE_PHYSICAL_ADDRESS:
360 return "give physical address";
361 case CEC_OPCODE_GET_MENU_LANGUAGE:
362 return "get menu language";
363 case CEC_OPCODE_REPORT_PHYSICAL_ADDRESS:
364 return "report physical address";
365 case CEC_OPCODE_SET_MENU_LANGUAGE:
366 return "set menu language";
367 case CEC_OPCODE_DECK_CONTROL:
368 return "deck control";
369 case CEC_OPCODE_DECK_STATUS:
370 return "deck status";
371 case CEC_OPCODE_GIVE_DECK_STATUS:
372 return "give deck status";
373 case CEC_OPCODE_PLAY:
374 return "play";
375 case CEC_OPCODE_GIVE_TUNER_DEVICE_STATUS:
376 return "give tuner status";
377 case CEC_OPCODE_SELECT_ANALOGUE_SERVICE:
378 return "select analogue service";
379 case CEC_OPCODE_SELECT_DIGITAL_SERVICE:
380 return "set digital service";
381 case CEC_OPCODE_TUNER_DEVICE_STATUS:
382 return "tuner device status";
383 case CEC_OPCODE_TUNER_STEP_DECREMENT:
384 return "tuner step decrement";
385 case CEC_OPCODE_TUNER_STEP_INCREMENT:
386 return "tuner step increment";
387 case CEC_OPCODE_DEVICE_VENDOR_ID:
388 return "device vendor id";
389 case CEC_OPCODE_GIVE_DEVICE_VENDOR_ID:
390 return "give device vendor id";
391 case CEC_OPCODE_VENDOR_COMMAND:
392 return "vendor command";
393 case CEC_OPCODE_VENDOR_COMMAND_WITH_ID:
394 return "vendor command with id";
395 case CEC_OPCODE_VENDOR_REMOTE_BUTTON_DOWN:
396 return "vendor remote button down";
397 case CEC_OPCODE_VENDOR_REMOTE_BUTTON_UP:
398 return "vendor remote button up";
399 case CEC_OPCODE_SET_OSD_STRING:
400 return "set osd string";
401 case CEC_OPCODE_GIVE_OSD_NAME:
402 return "give osd name";
403 case CEC_OPCODE_SET_OSD_NAME:
404 return "set osd name";
405 case CEC_OPCODE_MENU_REQUEST:
406 return "menu request";
407 case CEC_OPCODE_MENU_STATUS:
408 return "menu status";
409 case CEC_OPCODE_USER_CONTROL_PRESSED:
410 return "user control pressed";
411 case CEC_OPCODE_USER_CONTROL_RELEASE:
412 return "user control release";
413 case CEC_OPCODE_GIVE_DEVICE_POWER_STATUS:
414 return "give device power status";
415 case CEC_OPCODE_REPORT_POWER_STATUS:
416 return "report power status";
417 case CEC_OPCODE_FEATURE_ABORT:
418 return "feature abort";
419 case CEC_OPCODE_ABORT:
420 return "abort";
421 case CEC_OPCODE_GIVE_AUDIO_STATUS:
422 return "give audio status";
423 case CEC_OPCODE_GIVE_SYSTEM_AUDIO_MODE_STATUS:
424 return "give audio mode status";
425 case CEC_OPCODE_REPORT_AUDIO_STATUS:
426 return "report audio status";
427 case CEC_OPCODE_SET_SYSTEM_AUDIO_MODE:
428 return "set system audio mode";
429 case CEC_OPCODE_SYSTEM_AUDIO_MODE_REQUEST:
430 return "system audio mode request";
431 case CEC_OPCODE_SYSTEM_AUDIO_MODE_STATUS:
432 return "system audio mode status";
433 case CEC_OPCODE_SET_AUDIO_RATE:
434 return "set audio rate";
435 case CEC_OPCODE_START_ARC:
436 return "start ARC";
437 case CEC_OPCODE_REPORT_ARC_STARTED:
438 return "report ARC started";
439 case CEC_OPCODE_REPORT_ARC_ENDED:
440 return "report ARC ended";
441 case CEC_OPCODE_REQUEST_ARC_START:
442 return "request ARC start";
443 case CEC_OPCODE_REQUEST_ARC_END:
444 return "request ARC end";
445 case CEC_OPCODE_END_ARC:
446 return "end ARC";
447 case CEC_OPCODE_CDC:
448 return "CDC";
449 case CEC_OPCODE_NONE:
450 return "poll";
451 default:
452 return "UNKNOWN";
453 }
454 }
455
456 static const char *ToString(const cec_system_audio_status mode)
457 {
458 switch(mode)
459 {
460 case CEC_SYSTEM_AUDIO_STATUS_ON:
461 return "on";
462 case CEC_SYSTEM_AUDIO_STATUS_OFF:
463 return "off";
464 default:
465 return "unknown";
466 }
467 }
468
469 static const char *ToString(const cec_audio_status UNUSED(status))
470 {
471 // TODO this is a mask
472 return "TODO";
473 }
474
475 static const char *ToString(const cec_vendor_id vendor)
476 {
477 switch (vendor)
478 {
479 case CEC_VENDOR_SAMSUNG:
480 return "Samsung";
481 case CEC_VENDOR_LG:
482 return "LG";
483 case CEC_VENDOR_PANASONIC:
484 return "Panasonic";
485 case CEC_VENDOR_PIONEER:
486 return "Pioneer";
487 case CEC_VENDOR_ONKYO:
488 return "Onkyo";
489 case CEC_VENDOR_YAMAHA:
490 return "Yamaha";
491 case CEC_VENDOR_PHILIPS:
492 return "Philips";
493 case CEC_VENDOR_SONY:
494 return "Sony";
495 case CEC_VENDOR_TOSHIBA:
496 return "Toshiba";
497 default:
498 return "Unknown";
499 }
500 }
501
502 static const char *ToString(const cec_client_version version)
503 {
504 switch (version)
505 {
506 case CEC_CLIENT_VERSION_PRE_1_5:
507 return "pre-1.5";
508 case CEC_CLIENT_VERSION_1_5_0:
509 return "1.5.0";
510 case CEC_CLIENT_VERSION_1_5_1:
511 return "1.5.1";
512 case CEC_CLIENT_VERSION_1_5_2:
513 return "1.5.2";
514 case CEC_CLIENT_VERSION_1_5_3:
515 return "1.5.3";
516 case CEC_CLIENT_VERSION_1_6_0:
517 return "1.6.0";
518 case CEC_CLIENT_VERSION_1_6_1:
519 return "1.6.1";
520 case CEC_CLIENT_VERSION_1_6_2:
521 return "1.6.2";
522 case CEC_CLIENT_VERSION_1_6_3:
523 return "1.6.3";
0a61dc24
LOK
524 case CEC_CLIENT_VERSION_1_7_0:
525 return "1.7.0";
92eea1e7
LOK
526 case CEC_CLIENT_VERSION_1_7_1:
527 return "1.7.1";
0d800fe5
LOK
528 default:
529 return "Unknown";
530 }
531 }
532
533 static const char *ToString(const cec_server_version version)
534 {
535 switch (version)
536 {
537 case CEC_SERVER_VERSION_PRE_1_5:
538 return "pre-1.5";
539 case CEC_SERVER_VERSION_1_5_0:
540 return "1.5.0";
541 case CEC_SERVER_VERSION_1_5_1:
542 return "1.5.1";
543 case CEC_SERVER_VERSION_1_5_2:
544 return "1.5.2";
545 case CEC_SERVER_VERSION_1_5_3:
546 return "1.5.3";
547 case CEC_SERVER_VERSION_1_6_0:
548 return "1.6.0";
549 case CEC_SERVER_VERSION_1_6_1:
550 return "1.6.1";
551 case CEC_SERVER_VERSION_1_6_2:
552 return "1.6.2";
553 case CEC_SERVER_VERSION_1_6_3:
554 return "1.6.3";
0a61dc24
LOK
555 case CEC_SERVER_VERSION_1_7_0:
556 return "1.7.0";
92eea1e7
LOK
557 case CEC_SERVER_VERSION_1_7_1:
558 return "1.7.1";
0d800fe5
LOK
559 default:
560 return "Unknown";
561 }
562 }
9a54dc82
LOK
563
564 static const char *ToString(const cec_abort_reason reason)
565 {
566 switch(reason)
567 {
568 case CEC_ABORT_REASON_UNRECOGNIZED_OPCODE:
569 return "unrecognised opcode";
570 case CEC_ABORT_REASON_NOT_IN_CORRECT_MODE_TO_RESPOND:
571 return "not in correct mode to respond";
572 case CEC_ABORT_REASON_CANNOT_PROVIDE_SOURCE:
573 return "cannot provide source";
574 case CEC_ABORT_REASON_INVALID_OPERAND:
575 return "invalid operand";
576 case CEC_ABORT_REASON_REFUSED:
577 return "refused";
578 default:
579 return "unknown";
580 }
581 }
0d800fe5
LOK
582 };
583}