cec: don't forward the standby opcode more than once every 10 seconds
[deb_libcec.git] / include / cectypes.h
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 #ifndef CECTYPES_H_
35 #define CECTYPES_H_
36
37 #include <stdint.h>
38 #include <string.h>
39
40 #if defined(_WIN32) || defined(_WIN64)
41 #define CEC_CDECL __cdecl
42 #else
43 #define CEC_CDECL
44 #endif
45
46 #if !defined(DECLSPEC)
47 #if defined(_WIN32) || defined(_WIN64)
48 #include <windows.h>
49 #if defined DLL_EXPORT
50 #define DECLSPEC __declspec(dllexport)
51 #else
52 #define DECLSPEC __declspec(dllimport)
53 #endif
54 #else
55 #define DECLSPEC
56 #endif
57 #endif
58
59 #ifdef __cplusplus
60 extern "C" {
61 namespace CEC {
62 #endif
63
64 //default physical address 1.0.0.0, HDMI port 1
65 #define CEC_DEFAULT_PHYSICAL_ADDRESS 0x1000
66 #define CEC_DEFAULT_HDMI_PORT 1
67 #define CEC_DEFAULT_BASE_DEVICE 0
68 #define MSGSTART 0xFF
69 #define MSGEND 0xFE
70 #define MSGESC 0xFD
71 #define ESCOFFSET 3
72 #define CEC_BUTTON_TIMEOUT 500
73 #define CEC_POWER_STATE_REFRESH_TIME 30000
74 #define CEC_FW_VERSION_UNKNOWN 0xFFFF
75 #define CEC_FW_BUILD_UNKNOWN 0
76 #define CEC_CONNECT_TRIES 3
77
78 #define CEC_PHYSICAL_ADDRESS_TV 0
79 #define CEC_MIN_PHYSICAL_ADDRESS 0x1000
80 #define CEC_MAX_PHYSICAL_ADDRESS 0xFFFE
81 #define CEC_INVALID_PHYSICAL_ADDRESS 0xFFFF
82
83 #define CEC_MIN_VENDORID 1
84 #define CEC_MAX_VENDORID 0xFFFFFE
85 #define CEC_INVALID_VENDORID 0xFFFFFF
86
87 #define CEC_MIN_HDMI_PORTNUMBER 1
88 #define CEC_MAX_HDMI_PORTNUMBER 15
89 #define CEC_HDMI_PORTNUMBER_NONE 0
90
91 #define CEC_DEFAULT_SETTING_USE_TV_MENU_LANGUAGE 1
92 #define CEC_DEFAULT_SETTING_ACTIVATE_SOURCE 1
93 #define CEC_DEFAULT_SETTING_POWER_OFF_SHUTDOWN 1
94 #define CEC_DEFAULT_SETTING_POWER_OFF_SCREENSAVER 1
95 #define CEC_DEFAULT_SETTING_POWER_OFF_ON_STANDBY 1
96 #define CEC_DEFAULT_SETTING_SHUTDOWN_ON_STANDBY 0
97 #define CEC_DEFAULT_SETTING_SEND_INACTIVE_SOURCE 1
98 #define CEC_DEFAULT_SETTING_POWER_OFF_DEVICES_STANDBY 1
99 #define CEC_DEFAULT_DEVICE_LANGUAGE "eng"
100 #define CEC_DEFAULT_SETTING_AUTODETECT_ADDRESS 0
101 #define CEC_DEFAULT_SETTING_GET_SETTINGS_FROM_ROM 0
102
103 #define CEC_DEFAULT_TRANSMIT_RETRY_WAIT 500
104 #define CEC_DEFAULT_TRANSMIT_TIMEOUT 1000
105 #define CEC_DEFAULT_TRANSMIT_WAIT 1000
106 #define CEC_DEFAULT_TRANSMIT_RETRIES 1
107
108 #define CEC_DEFAULT_CONNECT_TIMEOUT 10000
109 #define CEC_DEFAULT_CONNECT_RETRY_WAIT 1000
110 #define CEC_SERIAL_DEFAULT_BAUDRATE 38400
111 #define CEC_CLEAR_INPUT_DEFAULT_WAIT 1000
112
113 #define CEC_ACTIVE_SOURCE_SWITCH_RETRY_TIME_MS 5000
114 #define CEC_FORWARD_STANDBY_MIN_INTERVAL 10000
115
116 #define CEC_MIN_LIB_VERSION 1
117 #define CEC_LIB_VERSION_MAJOR 1
118 #define CEC_LIB_VERSION_MAJOR_STR "1"
119 #define CEC_LIB_VERSION_MINOR 7
120
121 typedef enum cec_abort_reason
122 {
123 CEC_ABORT_REASON_UNRECOGNIZED_OPCODE = 0,
124 CEC_ABORT_REASON_NOT_IN_CORRECT_MODE_TO_RESPOND = 1,
125 CEC_ABORT_REASON_CANNOT_PROVIDE_SOURCE = 2,
126 CEC_ABORT_REASON_INVALID_OPERAND = 3,
127 CEC_ABORT_REASON_REFUSED = 4
128 } cec_abort_reason;
129
130 typedef enum cec_analogue_broadcast_type
131 {
132 CEC_ANALOGUE_BROADCAST_TYPE_CABLE = 0x00,
133 CEC_ANALOGUE_BROADCAST_TYPE_SATELLITE = 0x01,
134 CEC_ANALOGUE_BROADCAST_TYPE_TERRESTIAL = 0x02
135 } cec_analogue_broadcast_type;
136
137 typedef enum cec_audio_rate
138 {
139 CEC_AUDIO_RATE_RATE_CONTROL_OFF = 0,
140 CEC_AUDIO_RATE_STANDARD_RATE_100 = 1,
141 CEC_AUDIO_RATE_FAST_RATE_MAX_101 = 2,
142 CEC_AUDIO_RATE_SLOW_RATE_MIN_99 = 3,
143 CEC_AUDIO_RATE_STANDARD_RATE_100_0 = 4,
144 CEC_AUDIO_RATE_FAST_RATE_MAX_100_1 = 5,
145 CEC_AUDIO_RATE_SLOW_RATE_MIN_99_9 = 6
146 } cec_audio_rate;
147
148 typedef enum cec_audio_status
149 {
150 CEC_AUDIO_MUTE_STATUS_MASK = 0x80,
151 CEC_AUDIO_VOLUME_STATUS_MASK = 0x7F,
152 CEC_AUDIO_VOLUME_MIN = 0x00,
153 CEC_AUDIO_VOLUME_MAX = 0x64,
154 CEC_AUDIO_VOLUME_STATUS_UNKNOWN = 0x7F
155 } cec_audio_status;
156
157 typedef enum cec_boolean
158 {
159 CEC_FALSE = 0,
160 CEC_TRUE = 1
161 } cec_boolean;
162
163 typedef enum cec_version
164 {
165 CEC_VERSION_UNKNOWN = 0x00,
166 CEC_VERSION_1_2 = 0x01,
167 CEC_VERSION_1_2A = 0x02,
168 CEC_VERSION_1_3 = 0x03,
169 CEC_VERSION_1_3A = 0x04,
170 CEC_VERSION_1_4 = 0x05
171 } cec_version;
172
173 typedef enum cec_channel_identifier
174 {
175 CEC_CHANNEL_NUMBER_FORMAT_MASK = 0xFC000000,
176 CEC_1_PART_CHANNEL_NUMBER = 0x04000000,
177 CEC_2_PART_CHANNEL_NUMBER = 0x08000000,
178 CEC_MAJOR_CHANNEL_NUMBER_MASK = 0x3FF0000,
179 CEC_MINOR_CHANNEL_NUMBER_MASK = 0xFFFF
180 } cec_channel_identifier;
181
182 typedef enum cec_deck_control_mode
183 {
184 CEC_DECK_CONTROL_MODE_SKIP_FORWARD_WIND = 1,
185 CEC_DECK_CONTROL_MODE_SKIP_REVERSE_REWIND = 2,
186 CEC_DECK_CONTROL_MODE_STOP = 3,
187 CEC_DECK_CONTROL_MODE_EJECT = 4
188 } cec_deck_control_mode;
189
190 typedef enum cec_deck_info
191 {
192 CEC_DECK_INFO_PLAY = 0x11,
193 CEC_DECK_INFO_RECORD = 0x12,
194 CEC_DECK_INFO_PLAY_REVERSE = 0x13,
195 CEC_DECK_INFO_STILL = 0x14,
196 CEC_DECK_INFO_SLOW = 0x15,
197 CEC_DECK_INFO_SLOW_REVERSE = 0x16,
198 CEC_DECK_INFO_FAST_FORWARD = 0x17,
199 CEC_DECK_INFO_FAST_REVERSE = 0x18,
200 CEC_DECK_INFO_NO_MEDIA = 0x19,
201 CEC_DECK_INFO_STOP = 0x1A,
202 CEC_DECK_INFO_SKIP_FORWARD_WIND = 0x1B,
203 CEC_DECK_INFO_SKIP_REVERSE_REWIND = 0x1C,
204 CEC_DECK_INFO_INDEX_SEARCH_FORWARD = 0x1D,
205 CEC_DECK_INFO_INDEX_SEARCH_REVERSE = 0x1E,
206 CEC_DECK_INFO_OTHER_STATUS = 0x1F,
207 CEC_DECK_INFO_OTHER_STATUS_LG = 0x20
208 } cec_deck_info;
209
210 typedef enum cec_device_type
211 {
212 CEC_DEVICE_TYPE_TV = 0,
213 CEC_DEVICE_TYPE_RECORDING_DEVICE = 1,
214 CEC_DEVICE_TYPE_RESERVED = 2,
215 CEC_DEVICE_TYPE_TUNER = 3,
216 CEC_DEVICE_TYPE_PLAYBACK_DEVICE = 4,
217 CEC_DEVICE_TYPE_AUDIO_SYSTEM = 5
218 } cec_device_type;
219
220 typedef enum cec_display_control
221 {
222 CEC_DISPLAY_CONTROL_DISPLAY_FOR_DEFAULT_TIME = 0x00,
223 CEC_DISPLAY_CONTROL_DISPLAY_UNTIL_CLEARED = 0x40,
224 CEC_DISPLAY_CONTROL_CLEAR_PREVIOUS_MESSAGE = 0x80,
225 CEC_DISPLAY_CONTROL_RESERVED_FOR_FUTURE_USE = 0xC0
226 } cec_display_control;
227
228 typedef enum cec_external_source_specifier
229 {
230 CEC_EXTERNAL_SOURCE_SPECIFIER_EXTERNAL_PLUG = 4,
231 CEC_EXTERNAL_SOURCE_SPECIFIER_EXTERNAL_PHYSICAL_ADDRESS = 5
232 } cec_external_source_specifier;
233
234 typedef enum cec_menu_request_type
235 {
236 CEC_MENU_REQUEST_TYPE_ACTIVATE = 0,
237 CEC_MENU_REQUEST_TYPE_DEACTIVATE = 1,
238 CEC_MENU_REQUEST_TYPE_QUERY = 2
239 } cec_menu_request_type;
240
241 typedef enum cec_menu_state
242 {
243 CEC_MENU_STATE_ACTIVATED = 0,
244 CEC_MENU_STATE_DEACTIVATED = 1
245 } cec_menu_state;
246
247 typedef enum cec_play_mode
248 {
249 CEC_PLAY_MODE_PLAY_FORWARD = 0x24,
250 CEC_PLAY_MODE_PLAY_REVERSE = 0x20,
251 CEC_PLAY_MODE_PLAY_STILL = 0x25,
252 CEC_PLAY_MODE_FAST_FORWARD_MIN_SPEED = 0x05,
253 CEC_PLAY_MODE_FAST_FORWARD_MEDIUM_SPEED = 0x06,
254 CEC_PLAY_MODE_FAST_FORWARD_MAX_SPEED = 0x07,
255 CEC_PLAY_MODE_FAST_REVERSE_MIN_SPEED = 0x09,
256 CEC_PLAY_MODE_FAST_REVERSE_MEDIUM_SPEED = 0x0A,
257 CEC_PLAY_MODE_FAST_REVERSE_MAX_SPEED = 0x0B,
258 CEC_PLAY_MODE_SLOW_FORWARD_MIN_SPEED = 0x15,
259 CEC_PLAY_MODE_SLOW_FORWARD_MEDIUM_SPEED = 0x16,
260 CEC_PLAY_MODE_SLOW_FORWARD_MAX_SPEED = 0x17,
261 CEC_PLAY_MODE_SLOW_REVERSE_MIN_SPEED = 0x19,
262 CEC_PLAY_MODE_SLOW_REVERSE_MEDIUM_SPEED = 0x1A,
263 CEC_PLAY_MODE_SLOW_REVERSE_MAX_SPEED = 0x1B
264 } cec_play_mode;
265
266 typedef enum cec_power_status
267 {
268 CEC_POWER_STATUS_ON = 0x00,
269 CEC_POWER_STATUS_STANDBY = 0x01,
270 CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON = 0x02,
271 CEC_POWER_STATUS_IN_TRANSITION_ON_TO_STANDBY = 0x03,
272 CEC_POWER_STATUS_UNKNOWN = 0x99
273 } cec_power_status;
274
275 typedef enum cec_record_source_type
276 {
277 CEC_RECORD_SOURCE_TYPE_OWN_SOURCE = 1,
278 CEC_RECORD_SOURCE_TYPE_DIGITAL_SERVICE = 2,
279 CEC_RECORD_SOURCE_TYPE_ANALOGUE_SERVICE = 3,
280 CEC_RECORD_SOURCE_TYPE_EXTERNAL_PLUS = 4,
281 CEC_RECORD_SOURCE_TYPE_EXTERNAL_PHYSICAL_ADDRESS = 5
282 } cec_record_source_type;
283
284 typedef enum cec_record_status_info
285 {
286 CEC_RECORD_STATUS_INFO_RECORDING_CURRENTLY_SELECTED_SOURCE = 0x01,
287 CEC_RECORD_STATUS_INFO_RECORDING_DIGITAL_SERVICE = 0x02,
288 CEC_RECORD_STATUS_INFO_RECORDING_ANALOGUE_SERVICE = 0x03,
289 CEC_RECORD_STATUS_INFO_RECORDING_EXTERNAL_INPUT = 0x04,
290 CEC_RECORD_STATUS_INFO_NO_RECORDING_UNABLE_TO_RECORD_DIGITAL_SERVICE = 0x05,
291 CEC_RECORD_STATUS_INFO_NO_RECORDING_UNABLE_TO_RECORD_ANALOGUE_SERVICE = 0x06,
292 CEC_RECORD_STATUS_INFO_NO_RECORDING_UNABLE_TO_SELECT_REQUIRED_SERVICE = 0x07,
293 CEC_RECORD_STATUS_INFO_NO_RECORDING_INVALID_EXTERNAL_PLUG_NUMBER = 0x09,
294 CEC_RECORD_STATUS_INFO_NO_RECORDING_INVALID_EXTERNAL_ADDRESS = 0x0A,
295 CEC_RECORD_STATUS_INFO_NO_RECORDING_CA_SYSTEM_NOT_SUPPORTED = 0x0B,
296 CEC_RECORD_STATUS_INFO_NO_RECORDING_NO_OR_INSUFFICIENT_ENTITLEMENTS = 0x0C,
297 CEC_RECORD_STATUS_INFO_NO_RECORDING_NOT_ALLOWED_TO_COPY_SOURCE = 0x0D,
298 CEC_RECORD_STATUS_INFO_NO_RECORDING_NO_FURTHER_COPIES_ALLOWED = 0x0E,
299 CEC_RECORD_STATUS_INFO_NO_RECORDING_NO_MEDIA = 0x10,
300 CEC_RECORD_STATUS_INFO_NO_RECORDING_PLAYING = 0x11,
301 CEC_RECORD_STATUS_INFO_NO_RECORDING_ALREADY_RECORDING = 0x12,
302 CEC_RECORD_STATUS_INFO_NO_RECORDING_MEDIA_PROTECTED = 0x13,
303 CEC_RECORD_STATUS_INFO_NO_RECORDING_NO_SOURCE_SIGNAL = 0x14,
304 CEC_RECORD_STATUS_INFO_NO_RECORDING_MEDIA_PROBLEM = 0x15,
305 CEC_RECORD_STATUS_INFO_NO_RECORDING_NOT_ENOUGH_SPACE_AVAILABLE = 0x16,
306 CEC_RECORD_STATUS_INFO_NO_RECORDING_PARENTAL_LOCK_ON = 0x17,
307 CEC_RECORD_STATUS_INFO_RECORDING_TERMINATED_NORMALLY = 0x1A,
308 CEC_RECORD_STATUS_INFO_RECORDING_HAS_ALREADY_TERMINATED = 0x1B,
309 CEC_RECORD_STATUS_INFO_NO_RECORDING_OTHER_REASON = 0x1F
310 } cec_record_status_info;
311
312 typedef enum cec_recording_sequence
313 {
314 CEC_RECORDING_SEQUENCE_SUNDAY = 0x01,
315 CEC_RECORDING_SEQUENCE_MONDAY = 0x02,
316 CEC_RECORDING_SEQUENCE_TUESDAY = 0x04,
317 CEC_RECORDING_SEQUENCE_WEDNESDAY = 0x08,
318 CEC_RECORDING_SEQUENCE_THURSDAY = 0x10,
319 CEC_RECORDING_SEQUENCE_FRIDAY = 0x20,
320 CEC_RECORDING_SEQUENCE_SATURDAY = 0x40,
321 CEC_RECORDING_SEQUENCE_ONCE_ONLY = 0x00
322 } cec_recording_sequence;
323
324 typedef enum cec_status_request
325 {
326 CEC_STATUS_REQUEST_ON = 1,
327 CEC_STATUS_REQUEST_OFF = 2,
328 CEC_STATUS_REQUEST_ONCE = 3
329 } cec_status_request;
330
331 typedef enum cec_system_audio_status
332 {
333 CEC_SYSTEM_AUDIO_STATUS_OFF = 0,
334 CEC_SYSTEM_AUDIO_STATUS_ON = 1
335 } cec_system_audio_status;
336
337 typedef enum cec_timer_cleared_status_data
338 {
339 CEC_TIMER_CLEARED_STATUS_DATA_TIMER_NOT_CLEARED_RECORDING = 0x00,
340 CEC_TIMER_CLEARED_STATUS_DATA_TIMER_NOT_CLEARED_NO_MATCHING = 0x01,
341 CEC_TIMER_CLEARED_STATUS_DATA_TIMER_NOT_CLEARED_NO_INF0_AVAILABLE = 0x02,
342 CEC_TIMER_CLEARED_STATUS_DATA_TIMER_CLEARED = 0x80
343 } cec_timer_cleared_status_data;
344
345 typedef enum cec_timer_overlap_warning
346 {
347 CEC_TIMER_OVERLAP_WARNING_NO_OVERLAP = 0,
348 CEC_TIMER_OVERLAP_WARNING_TIMER_BLOCKS_OVERLAP = 1
349 } cec_timer_overlap_warning;
350
351 typedef enum cec_media_info
352 {
353 CEC_MEDIA_INFO_MEDIA_PRESENT_AND_NOT_PROTECTED = 0x00,
354 CEC_MEDIA_INFO_MEDIA_PRESENT_BUT_PROTECTED = 0x01,
355 CEC_MEDIA_INFO_MEDIA_NOT_PRESENT = 0x02,
356 CEC_MEDIA_INFO_FUTURE_USE = 0x03
357 } cec_media_info;
358
359 typedef enum cec_programmed_indicator
360 {
361 CEC_PROGRAMMED_INDICATOR_NOT_PROGRAMMED = 0,
362 CEC_PROGRAMMED_INDICATOR_PROGRAMMED = 1
363 } cec_programmed_indicator;
364
365 typedef enum cec_programmed_info
366 {
367 CEC_PROGRAMMED_INFO_FUTURE_USE = 0x0,
368 CEC_PROGRAMMED_INFO_ENOUGH_SPACE_AVAILABLE_FOR_RECORDING = 0x08,
369 CEC_PROGRAMMED_INFO_NOT_ENOUGH_SPACE_AVAILABLE_FOR_RECORDING = 0x09,
370 CEC_PROGRAMMED_INFO_MAY_NOT_BE_ENOUGH_SPACE_AVAILABLE = 0x0B,
371 CEC_PROGRAMMED_INFO_NO_MEDIA_INFO_AVAILABLE = 0x0A
372 } cec_programmed_info;
373
374 typedef enum cec_not_programmed_error_info
375 {
376 CEC_NOT_PROGRAMMED_ERROR_INFO_FUTURE_USE = 0x0,
377 CEC_NOT_PROGRAMMED_ERROR_INFO_NO_FREE_TIMER_AVAILABLE = 0x01,
378 CEC_NOT_PROGRAMMED_ERROR_INFO_DATE_OUT_OF_RANGE = 0x02,
379 CEC_NOT_PROGRAMMED_ERROR_INFO_RECORDING_SEQUENCE_ERROR = 0x03,
380 CEC_NOT_PROGRAMMED_ERROR_INFO_INVALID_EXTERNAL_PLUG_NUMBER = 0x04,
381 CEC_NOT_PROGRAMMED_ERROR_INFO_INVALID_EXTERNAL_PHYSICAL_ADDRESS = 0x05,
382 CEC_NOT_PROGRAMMED_ERROR_INFO_CA_SYSTEM_NOT_SUPPORTED = 0x06,
383 CEC_NOT_PROGRAMMED_ERROR_INFO_NO_OR_INSUFFICIENT_CA_ENTITLEMENTS = 0x07,
384 CEC_NOT_PROGRAMMED_ERROR_INFO_DOES_NOT_SUPPORT_RESOLUTION = 0x08,
385 CEC_NOT_PROGRAMMED_ERROR_INFO_PARENTAL_LOCK_ON = 0x09,
386 CEC_NOT_PROGRAMMED_ERROR_INFO_CLOCK_FAILURE = 0x0A,
387 CEC_NOT_PROGRAMMED_ERROR_INFO_RESERVED_FOR_FUTURE_USE_START = 0x0B,
388 CEC_NOT_PROGRAMMED_ERROR_INFO_RESERVED_FOR_FUTURE_USE_END = 0x0D,
389 CEC_NOT_PROGRAMMED_ERROR_INFO_DUPLICATE_ALREADY_PROGRAMMED = 0x0E
390 } cec_not_programmed_error_info;
391
392 typedef enum cec_recording_flag
393 {
394 CEC_RECORDING_FLAG_NOT_BEING_USED_FOR_RECORDING = 0,
395 CEC_RECORDING_FLAG_BEING_USED_FOR_RECORDING = 1
396 } cec_recording_flag;
397
398 typedef enum cec_tuner_display_info
399 {
400 CEC_TUNER_DISPLAY_INFO_DISPLAYING_DIGITAL_TUNER = 0,
401 CEC_TUNER_DISPLAY_INFO_NOT_DISPLAYING_TUNER = 1,
402 CEC_TUNER_DISPLAY_INFO_DISPLAYING_ANALOGUE_TUNER = 2
403 } cec_tuner_display_info;
404
405 typedef enum cec_broadcast_system
406 {
407 CEC_BROADCAST_SYSTEM_PAL_B_G = 0,
408 CEC_BROADCAST_SYSTEM_SECAM_L1 = 1,
409 CEC_BROADCAST_SYSTEM_PAL_M = 2,
410 CEC_BROADCAST_SYSTEM_NTSC_M = 3,
411 CEC_BROADCAST_SYSTEM_PAL_I = 4,
412 CEC_BROADCAST_SYSTEM_SECAM_DK = 5,
413 CEC_BROADCAST_SYSTEM_SECAM_B_G = 6,
414 CEC_BROADCAST_SYSTEM_SECAM_L2 = 7,
415 CEC_BROADCAST_SYSTEM_PAL_DK = 8,
416 CEC_BROADCAST_SYSTEM_OTHER_SYSTEM = 30
417 } cec_broadcast_system;
418
419 typedef enum cec_user_control_code
420 {
421 CEC_USER_CONTROL_CODE_SELECT = 0x00,
422 CEC_USER_CONTROL_CODE_UP = 0x01,
423 CEC_USER_CONTROL_CODE_DOWN = 0x02,
424 CEC_USER_CONTROL_CODE_LEFT = 0x03,
425 CEC_USER_CONTROL_CODE_RIGHT = 0x04,
426 CEC_USER_CONTROL_CODE_RIGHT_UP = 0x05,
427 CEC_USER_CONTROL_CODE_RIGHT_DOWN = 0x06,
428 CEC_USER_CONTROL_CODE_LEFT_UP = 0x07,
429 CEC_USER_CONTROL_CODE_LEFT_DOWN = 0x08,
430 CEC_USER_CONTROL_CODE_ROOT_MENU = 0x09,
431 CEC_USER_CONTROL_CODE_SETUP_MENU = 0x0A,
432 CEC_USER_CONTROL_CODE_CONTENTS_MENU = 0x0B,
433 CEC_USER_CONTROL_CODE_FAVORITE_MENU = 0x0C,
434 CEC_USER_CONTROL_CODE_EXIT = 0x0D,
435 CEC_USER_CONTROL_CODE_NUMBER0 = 0x20,
436 CEC_USER_CONTROL_CODE_NUMBER1 = 0x21,
437 CEC_USER_CONTROL_CODE_NUMBER2 = 0x22,
438 CEC_USER_CONTROL_CODE_NUMBER3 = 0x23,
439 CEC_USER_CONTROL_CODE_NUMBER4 = 0x24,
440 CEC_USER_CONTROL_CODE_NUMBER5 = 0x25,
441 CEC_USER_CONTROL_CODE_NUMBER6 = 0x26,
442 CEC_USER_CONTROL_CODE_NUMBER7 = 0x27,
443 CEC_USER_CONTROL_CODE_NUMBER8 = 0x28,
444 CEC_USER_CONTROL_CODE_NUMBER9 = 0x29,
445 CEC_USER_CONTROL_CODE_DOT = 0x2A,
446 CEC_USER_CONTROL_CODE_ENTER = 0x2B,
447 CEC_USER_CONTROL_CODE_CLEAR = 0x2C,
448 CEC_USER_CONTROL_CODE_NEXT_FAVORITE = 0x2F,
449 CEC_USER_CONTROL_CODE_CHANNEL_UP = 0x30,
450 CEC_USER_CONTROL_CODE_CHANNEL_DOWN = 0x31,
451 CEC_USER_CONTROL_CODE_PREVIOUS_CHANNEL = 0x32,
452 CEC_USER_CONTROL_CODE_SOUND_SELECT = 0x33,
453 CEC_USER_CONTROL_CODE_INPUT_SELECT = 0x34,
454 CEC_USER_CONTROL_CODE_DISPLAY_INFORMATION = 0x35,
455 CEC_USER_CONTROL_CODE_HELP = 0x36,
456 CEC_USER_CONTROL_CODE_PAGE_UP = 0x37,
457 CEC_USER_CONTROL_CODE_PAGE_DOWN = 0x38,
458 CEC_USER_CONTROL_CODE_POWER = 0x40,
459 CEC_USER_CONTROL_CODE_VOLUME_UP = 0x41,
460 CEC_USER_CONTROL_CODE_VOLUME_DOWN = 0x42,
461 CEC_USER_CONTROL_CODE_MUTE = 0x43,
462 CEC_USER_CONTROL_CODE_PLAY = 0x44,
463 CEC_USER_CONTROL_CODE_STOP = 0x45,
464 CEC_USER_CONTROL_CODE_PAUSE = 0x46,
465 CEC_USER_CONTROL_CODE_RECORD = 0x47,
466 CEC_USER_CONTROL_CODE_REWIND = 0x48,
467 CEC_USER_CONTROL_CODE_FAST_FORWARD = 0x49,
468 CEC_USER_CONTROL_CODE_EJECT = 0x4A,
469 CEC_USER_CONTROL_CODE_FORWARD = 0x4B,
470 CEC_USER_CONTROL_CODE_BACKWARD = 0x4C,
471 CEC_USER_CONTROL_CODE_STOP_RECORD = 0x4D,
472 CEC_USER_CONTROL_CODE_PAUSE_RECORD = 0x4E,
473 CEC_USER_CONTROL_CODE_ANGLE = 0x50,
474 CEC_USER_CONTROL_CODE_SUB_PICTURE = 0x51,
475 CEC_USER_CONTROL_CODE_VIDEO_ON_DEMAND = 0x52,
476 CEC_USER_CONTROL_CODE_ELECTRONIC_PROGRAM_GUIDE = 0x53,
477 CEC_USER_CONTROL_CODE_TIMER_PROGRAMMING = 0x54,
478 CEC_USER_CONTROL_CODE_INITIAL_CONFIGURATION = 0x55,
479 CEC_USER_CONTROL_CODE_PLAY_FUNCTION = 0x60,
480 CEC_USER_CONTROL_CODE_PAUSE_PLAY_FUNCTION = 0x61,
481 CEC_USER_CONTROL_CODE_RECORD_FUNCTION = 0x62,
482 CEC_USER_CONTROL_CODE_PAUSE_RECORD_FUNCTION = 0x63,
483 CEC_USER_CONTROL_CODE_STOP_FUNCTION = 0x64,
484 CEC_USER_CONTROL_CODE_MUTE_FUNCTION = 0x65,
485 CEC_USER_CONTROL_CODE_RESTORE_VOLUME_FUNCTION = 0x66,
486 CEC_USER_CONTROL_CODE_TUNE_FUNCTION = 0x67,
487 CEC_USER_CONTROL_CODE_SELECT_MEDIA_FUNCTION = 0x68,
488 CEC_USER_CONTROL_CODE_SELECT_AV_INPUT_FUNCTION = 0x69,
489 CEC_USER_CONTROL_CODE_SELECT_AUDIO_INPUT_FUNCTION = 0x6A,
490 CEC_USER_CONTROL_CODE_POWER_TOGGLE_FUNCTION = 0x6B,
491 CEC_USER_CONTROL_CODE_POWER_OFF_FUNCTION = 0x6C,
492 CEC_USER_CONTROL_CODE_POWER_ON_FUNCTION = 0x6D,
493 CEC_USER_CONTROL_CODE_F1_BLUE = 0x71,
494 CEC_USER_CONTROL_CODE_F2_RED = 0X72,
495 CEC_USER_CONTROL_CODE_F3_GREEN = 0x73,
496 CEC_USER_CONTROL_CODE_F4_YELLOW = 0x74,
497 CEC_USER_CONTROL_CODE_F5 = 0x75,
498 CEC_USER_CONTROL_CODE_DATA = 0x76,
499 CEC_USER_CONTROL_CODE_AN_RETURN = 0x91,
500 CEC_USER_CONTROL_CODE_AN_CHANNELS_LIST = 0x96,
501 CEC_USER_CONTROL_CODE_MAX = 0x96,
502 CEC_USER_CONTROL_CODE_UNKNOWN
503 } cec_user_control_code;
504
505 typedef enum cec_logical_address
506 {
507 CECDEVICE_UNKNOWN = -1, //not a valid logical address
508 CECDEVICE_TV = 0,
509 CECDEVICE_RECORDINGDEVICE1 = 1,
510 CECDEVICE_RECORDINGDEVICE2 = 2,
511 CECDEVICE_TUNER1 = 3,
512 CECDEVICE_PLAYBACKDEVICE1 = 4,
513 CECDEVICE_AUDIOSYSTEM = 5,
514 CECDEVICE_TUNER2 = 6,
515 CECDEVICE_TUNER3 = 7,
516 CECDEVICE_PLAYBACKDEVICE2 = 8,
517 CECDEVICE_RECORDINGDEVICE3 = 9,
518 CECDEVICE_TUNER4 = 10,
519 CECDEVICE_PLAYBACKDEVICE3 = 11,
520 CECDEVICE_RESERVED1 = 12,
521 CECDEVICE_RESERVED2 = 13,
522 CECDEVICE_FREEUSE = 14,
523 CECDEVICE_UNREGISTERED = 15,
524 CECDEVICE_BROADCAST = 15
525 } cec_logical_address;
526
527 typedef enum cec_opcode
528 {
529 CEC_OPCODE_ACTIVE_SOURCE = 0x82,
530 CEC_OPCODE_IMAGE_VIEW_ON = 0x04,
531 CEC_OPCODE_TEXT_VIEW_ON = 0x0D,
532 CEC_OPCODE_INACTIVE_SOURCE = 0x9D,
533 CEC_OPCODE_REQUEST_ACTIVE_SOURCE = 0x85,
534 CEC_OPCODE_ROUTING_CHANGE = 0x80,
535 CEC_OPCODE_ROUTING_INFORMATION = 0x81,
536 CEC_OPCODE_SET_STREAM_PATH = 0x86,
537 CEC_OPCODE_STANDBY = 0x36,
538 CEC_OPCODE_RECORD_OFF = 0x0B,
539 CEC_OPCODE_RECORD_ON = 0x09,
540 CEC_OPCODE_RECORD_STATUS = 0x0A,
541 CEC_OPCODE_RECORD_TV_SCREEN = 0x0F,
542 CEC_OPCODE_CLEAR_ANALOGUE_TIMER = 0x33,
543 CEC_OPCODE_CLEAR_DIGITAL_TIMER = 0x99,
544 CEC_OPCODE_CLEAR_EXTERNAL_TIMER = 0xA1,
545 CEC_OPCODE_SET_ANALOGUE_TIMER = 0x34,
546 CEC_OPCODE_SET_DIGITAL_TIMER = 0x97,
547 CEC_OPCODE_SET_EXTERNAL_TIMER = 0xA2,
548 CEC_OPCODE_SET_TIMER_PROGRAM_TITLE = 0x67,
549 CEC_OPCODE_TIMER_CLEARED_STATUS = 0x43,
550 CEC_OPCODE_TIMER_STATUS = 0x35,
551 CEC_OPCODE_CEC_VERSION = 0x9E,
552 CEC_OPCODE_GET_CEC_VERSION = 0x9F,
553 CEC_OPCODE_GIVE_PHYSICAL_ADDRESS = 0x83,
554 CEC_OPCODE_GET_MENU_LANGUAGE = 0x91,
555 CEC_OPCODE_REPORT_PHYSICAL_ADDRESS = 0x84,
556 CEC_OPCODE_SET_MENU_LANGUAGE = 0x32,
557 CEC_OPCODE_DECK_CONTROL = 0x42,
558 CEC_OPCODE_DECK_STATUS = 0x1B,
559 CEC_OPCODE_GIVE_DECK_STATUS = 0x1A,
560 CEC_OPCODE_PLAY = 0x41,
561 CEC_OPCODE_GIVE_TUNER_DEVICE_STATUS = 0x08,
562 CEC_OPCODE_SELECT_ANALOGUE_SERVICE = 0x92,
563 CEC_OPCODE_SELECT_DIGITAL_SERVICE = 0x93,
564 CEC_OPCODE_TUNER_DEVICE_STATUS = 0x07,
565 CEC_OPCODE_TUNER_STEP_DECREMENT = 0x06,
566 CEC_OPCODE_TUNER_STEP_INCREMENT = 0x05,
567 CEC_OPCODE_DEVICE_VENDOR_ID = 0x87,
568 CEC_OPCODE_GIVE_DEVICE_VENDOR_ID = 0x8C,
569 CEC_OPCODE_VENDOR_COMMAND = 0x89,
570 CEC_OPCODE_VENDOR_COMMAND_WITH_ID = 0xA0,
571 CEC_OPCODE_VENDOR_REMOTE_BUTTON_DOWN = 0x8A,
572 CEC_OPCODE_VENDOR_REMOTE_BUTTON_UP = 0x8B,
573 CEC_OPCODE_SET_OSD_STRING = 0x64,
574 CEC_OPCODE_GIVE_OSD_NAME = 0x46,
575 CEC_OPCODE_SET_OSD_NAME = 0x47,
576 CEC_OPCODE_MENU_REQUEST = 0x8D,
577 CEC_OPCODE_MENU_STATUS = 0x8E,
578 CEC_OPCODE_USER_CONTROL_PRESSED = 0x44,
579 CEC_OPCODE_USER_CONTROL_RELEASE = 0x45,
580 CEC_OPCODE_GIVE_DEVICE_POWER_STATUS = 0x8F,
581 CEC_OPCODE_REPORT_POWER_STATUS = 0x90,
582 CEC_OPCODE_FEATURE_ABORT = 0x00,
583 CEC_OPCODE_ABORT = 0xFF,
584 CEC_OPCODE_GIVE_AUDIO_STATUS = 0x71,
585 CEC_OPCODE_GIVE_SYSTEM_AUDIO_MODE_STATUS = 0x7D,
586 CEC_OPCODE_REPORT_AUDIO_STATUS = 0x7A,
587 CEC_OPCODE_SET_SYSTEM_AUDIO_MODE = 0x72,
588 CEC_OPCODE_SYSTEM_AUDIO_MODE_REQUEST = 0x70,
589 CEC_OPCODE_SYSTEM_AUDIO_MODE_STATUS = 0x7E,
590 CEC_OPCODE_SET_AUDIO_RATE = 0x9A,
591
592 /* CEC 1.4 */
593 CEC_OPCODE_START_ARC = 0xC0,
594 CEC_OPCODE_REPORT_ARC_STARTED = 0xC1,
595 CEC_OPCODE_REPORT_ARC_ENDED = 0xC2,
596 CEC_OPCODE_REQUEST_ARC_START = 0xC3,
597 CEC_OPCODE_REQUEST_ARC_END = 0xC4,
598 CEC_OPCODE_END_ARC = 0xC5,
599 CEC_OPCODE_CDC = 0xF8,
600 /* when this opcode is set, no opcode will be sent to the device. this is one of the reserved numbers */
601 CEC_OPCODE_NONE = 0xFD
602 } cec_opcode;
603
604 typedef enum cec_log_level
605 {
606 CEC_LOG_ERROR = 1,
607 CEC_LOG_WARNING = 2,
608 CEC_LOG_NOTICE = 4,
609 CEC_LOG_TRAFFIC = 8,
610 CEC_LOG_DEBUG = 16,
611 CEC_LOG_ALL = 31
612 } cec_log_level;
613
614 typedef enum cec_adapter_messagecode
615 {
616 MSGCODE_NOTHING = 0,
617 MSGCODE_PING,
618 MSGCODE_TIMEOUT_ERROR,
619 MSGCODE_HIGH_ERROR,
620 MSGCODE_LOW_ERROR,
621 MSGCODE_FRAME_START,
622 MSGCODE_FRAME_DATA,
623 MSGCODE_RECEIVE_FAILED,
624 MSGCODE_COMMAND_ACCEPTED,
625 MSGCODE_COMMAND_REJECTED,
626 MSGCODE_SET_ACK_MASK,
627 MSGCODE_TRANSMIT,
628 MSGCODE_TRANSMIT_EOM,
629 MSGCODE_TRANSMIT_IDLETIME,
630 MSGCODE_TRANSMIT_ACK_POLARITY,
631 MSGCODE_TRANSMIT_LINE_TIMEOUT,
632 MSGCODE_TRANSMIT_SUCCEEDED,
633 MSGCODE_TRANSMIT_FAILED_LINE,
634 MSGCODE_TRANSMIT_FAILED_ACK,
635 MSGCODE_TRANSMIT_FAILED_TIMEOUT_DATA,
636 MSGCODE_TRANSMIT_FAILED_TIMEOUT_LINE,
637 MSGCODE_FIRMWARE_VERSION,
638 MSGCODE_START_BOOTLOADER,
639 MSGCODE_GET_BUILDDATE,
640 MSGCODE_SET_CONTROLLED,
641 MSGCODE_GET_AUTO_ENABLED,
642 MSGCODE_SET_AUTO_ENABLED,
643 MSGCODE_GET_DEFAULT_LOGICAL_ADDRESS,
644 MSGCODE_SET_DEFAULT_LOGICAL_ADDRESS,
645 MSGCODE_GET_LOGICAL_ADDRESS_MASK,
646 MSGCODE_SET_LOGICAL_ADDRESS_MASK,
647 MSGCODE_GET_PHYSICAL_ADDRESS,
648 MSGCODE_SET_PHYSICAL_ADDRESS,
649 MSGCODE_GET_DEVICE_TYPE,
650 MSGCODE_SET_DEVICE_TYPE,
651 MSGCODE_GET_HDMI_VERSION,
652 MSGCODE_SET_HDMI_VERSION,
653 MSGCODE_GET_OSD_NAME,
654 MSGCODE_SET_OSD_NAME,
655 MSGCODE_WRITE_EEPROM,
656 MSGCODE_FRAME_EOM = 0x80,
657 MSGCODE_FRAME_ACK = 0x40,
658 } cec_adapter_messagecode;
659
660 typedef enum cec_bus_device_status
661 {
662 CEC_DEVICE_STATUS_UNKNOWN,
663 CEC_DEVICE_STATUS_PRESENT,
664 CEC_DEVICE_STATUS_NOT_PRESENT,
665 CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
666 } cec_bus_device_status;
667
668 typedef enum cec_vendor_id
669 {
670 CEC_VENDOR_SAMSUNG = 0x0000F0,
671 CEC_VENDOR_LG = 0x00E091,
672 CEC_VENDOR_PANASONIC = 0x008045,
673 CEC_VENDOR_PIONEER = 0x00E036,
674 CEC_VENDOR_ONKYO = 0x0009B0,
675 CEC_VENDOR_YAMAHA = 0x00A0DE,
676 CEC_VENDOR_PHILIPS = 0x00903E,
677 CEC_VENDOR_SONY = 0x080046,
678 CEC_VENDOR_TOSHIBA = 0x000039,
679 CEC_VENDOR_UNKNOWN = 0
680 } cec_vendor_id;
681
682 typedef struct cec_menu_language
683 {
684 char language[4]; /**< the iso language code. @bug the language code is only 3 chars long, not 4. will be changed in v2.0, because changing it now would break backwards compat */
685 cec_logical_address device; /**< the logical address of the device */
686 } cec_menu_language;
687
688 typedef struct cec_osd_name
689 {
690 char name[14]; /**< the name of the device */
691 cec_logical_address device; /**< the logical address of the device */
692 } cec_osd_name;
693
694 typedef struct cec_log_message
695 {
696 char message[1024]; /**< the actual message */
697 cec_log_level level; /**< log level of the message */
698 int64_t time; /**< the timestamp of this message */
699 } cec_log_message;
700
701 typedef struct cec_keypress
702 {
703 cec_user_control_code keycode; /**< the keycode */
704 unsigned int duration; /**< the duration of the keypress */
705 } cec_keypress;
706
707 typedef struct cec_adapter
708 {
709 char path[1024]; /**< the path to the com port */
710 char comm[1024]; /**< the name of the com port */
711 } cec_adapter;
712
713 typedef struct cec_datapacket
714 {
715 uint8_t data[100]; /**< the actual data */
716 uint8_t size; /**< the size of the data */
717
718 #ifdef __cplusplus
719 cec_datapacket &operator =(const struct cec_datapacket &packet)
720 {
721 Clear();
722 for (uint8_t iPtr = 0; iPtr < packet.size; iPtr++)
723 PushBack(packet[iPtr]);
724
725 return *this;
726 }
727
728 bool IsEmpty(void) const { return size == 0; } /**< @return True when this packet is empty, false otherwise. */
729 bool IsFull(void) const { return size == 100; } /**< @return True when this packet is false, false otherwise. */
730
731 /*!
732 * @brief Get the byte at the requested position.
733 * @param pos The position.
734 * @return The byte, or 0 when out of bounds.
735 */
736 uint8_t operator[](uint8_t pos) const { return pos < size ? data[pos] : 0; }
737 /*!
738 * @brief Get the byte at the requested position.
739 * @param pos The position.
740 * @return The byte, or 0 when out of bounds.
741 */
742 uint8_t At(uint8_t pos) const { return pos < size ? data[pos] : 0; }
743
744 /*!
745 * @brief Shift the contents of this packet.
746 * @param iShiftBy The number of positions to shift.
747 */
748 void Shift(uint8_t iShiftBy)
749 {
750 if (iShiftBy >= size)
751 {
752 Clear();
753 }
754 else
755 {
756 for (uint8_t iPtr = 0; iPtr < size; iPtr++)
757 data[iPtr] = (iPtr + iShiftBy < size) ? data[iPtr + iShiftBy] : 0;
758 size = (uint8_t) (size - iShiftBy);
759 }
760 }
761
762 /*!
763 * @brief Push a byte to the end of this packet.
764 * @param add The byte to add.
765 */
766 void PushBack(uint8_t add)
767 {
768 if (size < 100)
769 data[size++] = add;
770 }
771
772 /*!
773 * @brief Clear this packet.
774 */
775 void Clear(void)
776 {
777 memset(data, 0, sizeof(data));
778 size = 0;
779 }
780 #endif
781
782 } cec_datapacket;
783
784 typedef struct cec_command
785 {
786 cec_logical_address initiator; /**< the logical address of the initiator of this message */
787 cec_logical_address destination; /**< the logical address of the destination of this message */
788 int8_t ack; /**< 1 when the ACK bit is set, 0 otherwise */
789 int8_t eom; /**< 1 when the EOM bit is set, 0 otherwise */
790 cec_opcode opcode; /**< the opcode of this message */
791 cec_datapacket parameters; /**< the parameters attached to this message */
792 int8_t opcode_set; /**< 1 when an opcode is set, 0 otherwise (POLL message) */
793 int32_t transmit_timeout; /**< the timeout to use in ms */
794
795 #ifdef __cplusplus
796 cec_command(void)
797 {
798 Clear();
799 }
800
801 cec_command &operator =(const struct cec_command &command)
802 {
803 initiator = command.initiator;
804 destination = command.destination;
805 ack = command.ack;
806 eom = command.eom;
807 opcode = command.opcode;
808 opcode_set = command.opcode_set;
809 transmit_timeout = command.transmit_timeout;
810 parameters = command.parameters;
811
812 return *this;
813 }
814
815 /*!
816 * @brief Formats a cec_command.
817 * @param command The command to format.
818 * @param initiator The logical address of the initiator.
819 * @param destination The logical addres of the destination.
820 * @param opcode The opcode of the command.
821 * @param timeout The transmission timeout.
822 */
823 static void Format(cec_command &command, cec_logical_address initiator, cec_logical_address destination, cec_opcode opcode, int32_t timeout = CEC_DEFAULT_TRANSMIT_TIMEOUT)
824 {
825 command.Clear();
826 command.initiator = initiator;
827 command.destination = destination;
828 command.transmit_timeout = timeout;
829 if (opcode != CEC_OPCODE_NONE)
830 {
831 command.opcode = opcode;
832 command.opcode_set = 1;
833 }
834 }
835
836 /*!
837 * @brief Push a byte to the back of this command.
838 * @param data The byte to push.
839 */
840 void PushBack(uint8_t data)
841 {
842 if (initiator == CECDEVICE_UNKNOWN && destination == CECDEVICE_UNKNOWN)
843 {
844 initiator = (cec_logical_address) (data >> 4);
845 destination = (cec_logical_address) (data & 0xF);
846 }
847 else if (!opcode_set)
848 {
849 opcode_set = 1;
850 opcode = (cec_opcode) data;
851 }
852 else
853 parameters.PushBack(data);
854 }
855
856 /*!
857 * @brief Clear this command, resetting everything to the default values.
858 */
859 void Clear(void)
860 {
861 initiator = CECDEVICE_UNKNOWN;
862 destination = CECDEVICE_UNKNOWN;
863 ack = 0;
864 eom = 0;
865 opcode_set = 0;
866 opcode = CEC_OPCODE_FEATURE_ABORT;
867 transmit_timeout = CEC_DEFAULT_TRANSMIT_TIMEOUT;
868 parameters.Clear();
869 };
870
871 static cec_opcode GetResponseOpcode(cec_opcode opcode)
872 {
873 switch (opcode)
874 {
875 case CEC_OPCODE_REQUEST_ACTIVE_SOURCE:
876 return CEC_OPCODE_ACTIVE_SOURCE;
877 case CEC_OPCODE_GET_CEC_VERSION:
878 return CEC_OPCODE_CEC_VERSION;
879 case CEC_OPCODE_GIVE_PHYSICAL_ADDRESS:
880 return CEC_OPCODE_REPORT_PHYSICAL_ADDRESS;
881 case CEC_OPCODE_GET_MENU_LANGUAGE:
882 return CEC_OPCODE_SET_MENU_LANGUAGE;
883 case CEC_OPCODE_GIVE_DECK_STATUS:
884 return CEC_OPCODE_DECK_STATUS;
885 case CEC_OPCODE_GIVE_TUNER_DEVICE_STATUS:
886 return CEC_OPCODE_TUNER_DEVICE_STATUS;
887 case CEC_OPCODE_GIVE_DEVICE_VENDOR_ID:
888 return CEC_OPCODE_DEVICE_VENDOR_ID;
889 case CEC_OPCODE_GIVE_OSD_NAME:
890 return CEC_OPCODE_SET_OSD_NAME;
891 case CEC_OPCODE_MENU_REQUEST:
892 return CEC_OPCODE_MENU_STATUS;
893 case CEC_OPCODE_GIVE_DEVICE_POWER_STATUS:
894 return CEC_OPCODE_REPORT_POWER_STATUS;
895 case CEC_OPCODE_GIVE_AUDIO_STATUS:
896 return CEC_OPCODE_REPORT_AUDIO_STATUS;
897 case CEC_OPCODE_GIVE_SYSTEM_AUDIO_MODE_STATUS:
898 return CEC_OPCODE_SYSTEM_AUDIO_MODE_STATUS;
899 case CEC_OPCODE_SYSTEM_AUDIO_MODE_REQUEST:
900 return CEC_OPCODE_SET_SYSTEM_AUDIO_MODE;
901 default:
902 break;
903 }
904
905 return CEC_OPCODE_NONE;
906 }
907
908 void PushArray(size_t len, uint8_t *data)
909 {
910 for (size_t iPtr = 0; iPtr < len; iPtr++)
911 PushBack(data[iPtr]);
912 }
913 #endif
914 } cec_command;
915
916 typedef struct cec_device_type_list
917 {
918 cec_device_type types[5]; /**< the list of device types */
919
920 #ifdef __cplusplus
921 /*!
922 * @deprecated Use Clear() instead.
923 * @brief Clear this list.
924 */
925 void clear(void) { Clear(); }
926 /*!
927 * @deprecated Use Add() instead.
928 * @brief Add a type to this list.
929 * @param type The type to add.
930 */
931 void add(const cec_device_type type) { Add(type); }
932
933 /*!
934 * @brief Clear this list.
935 */
936 void Clear(void)
937 {
938 for (unsigned int iPtr = 0; iPtr < 5; iPtr++)
939 types[iPtr] = CEC_DEVICE_TYPE_RESERVED;
940 }
941
942 /*!
943 * @brief Add a type to this list.
944 * @param type The type to add.
945 */
946 void Add(const cec_device_type type)
947 {
948 for (unsigned int iPtr = 0; iPtr < 5; iPtr++)
949 {
950 if (types[iPtr] == CEC_DEVICE_TYPE_RESERVED)
951 {
952 types[iPtr] = type;
953 break;
954 }
955 }
956 }
957
958 /*!
959 * @brief Check whether a type is set in this list.
960 * @param type The type to check.
961 * @return True when set, false otherwise.
962 */
963 bool IsSet(cec_device_type type)
964 {
965 bool bReturn(false);
966 for (unsigned int iPtr = 0; !bReturn && iPtr < 5; iPtr++)
967 {
968 if (types[iPtr] == type)
969 bReturn = true;
970 }
971 return bReturn;
972 }
973
974 /*!
975 * @return True when this list is empty, false otherwise.
976 */
977 bool IsEmpty() const
978 {
979 bool bReturn(true);
980 for (unsigned int iPtr = 0; bReturn && iPtr < 5; iPtr++)
981 {
982 if (types[iPtr] != CEC_DEVICE_TYPE_RESERVED)
983 bReturn = false;
984 }
985 return bReturn;
986 }
987
988 /*!
989 * @brief Get the type at the requested position.
990 * @param pos The position.
991 * @return The type, or CEC_DEVICE_TYPE_RESERVED when out of bounds.
992 */
993 cec_device_type operator[](uint8_t pos) const { return pos < 5 ? types[pos] : CEC_DEVICE_TYPE_RESERVED; }
994
995 bool operator==(const cec_device_type_list &other) const
996 {
997 bool bEqual(true);
998 for (uint8_t iPtr = 0; iPtr < 5; iPtr++)
999 bEqual &= (types[iPtr] == other[iPtr]);
1000 return bEqual;
1001 }
1002
1003 bool operator!=(const cec_device_type_list &other) const
1004 {
1005 return !(*this == other);
1006 }
1007 #endif
1008 } cec_device_type_list;
1009
1010 typedef struct cec_logical_addresses
1011 {
1012 cec_logical_address primary; /**< the primary logical address to use */
1013 int addresses[16]; /**< the list of addresses */
1014
1015 #ifdef __cplusplus
1016 /*!
1017 * @brief Clear this list.
1018 */
1019 void Clear(void)
1020 {
1021 primary = CECDEVICE_UNREGISTERED;
1022 for (unsigned int iPtr = 0; iPtr < 16; iPtr++)
1023 addresses[iPtr] = 0;
1024 }
1025
1026 /*!
1027 * @return True when empty, false otherwise.
1028 */
1029 bool IsEmpty(void) const
1030 {
1031 return primary == CECDEVICE_UNREGISTERED;
1032 }
1033
1034 /*!
1035 * @brief Calculate the ack-mask for this list, the mask to use when determining whether to send an ack message or not.
1036 * @return The ack-mask.
1037 */
1038 uint16_t AckMask(void) const
1039 {
1040 uint16_t mask = 0;
1041 for (unsigned int iPtr = 0; iPtr < 16; iPtr++)
1042 if (addresses[iPtr] == 1)
1043 mask |= 0x1 << iPtr;
1044 return mask;
1045 }
1046
1047 /*!
1048 * @brief Mark a logical address as 'set'
1049 * @param address The logical address to add to this list.
1050 */
1051 void Set(cec_logical_address address)
1052 {
1053 if (primary == CECDEVICE_UNREGISTERED)
1054 primary = address;
1055
1056 addresses[(int) address] = 1;
1057 }
1058
1059 /*!
1060 * @brief Mark a logical address as 'unset'
1061 * @param address The logical address to remove from this list.
1062 */
1063 void Unset(const cec_logical_address address)
1064 {
1065 if (primary == address)
1066 primary = CECDEVICE_UNREGISTERED;
1067
1068 addresses[(int) address] = 0;
1069 }
1070
1071 /*!
1072 * @brief Check whether an address is set in this list.
1073 * @param address The address to check.
1074 * @return True when set, false otherwise.
1075 */
1076 bool IsSet(cec_logical_address address) const { return addresses[(int) address] == 1; }
1077
1078 /*!
1079 * @brief Check whether an address is set in this list.
1080 * @param pos The address to check.
1081 * @return True when set, false otherwise.
1082 */
1083 bool operator[](uint8_t pos) const { return pos < 16 ? IsSet((cec_logical_address) pos) : false; }
1084
1085 bool operator==(const cec_logical_addresses &other) const
1086 {
1087 bool bEqual(true);
1088 for (uint8_t iPtr = 0; iPtr < 16; iPtr++)
1089 bEqual &= ((addresses[(int)iPtr] == 1) == other[iPtr]);
1090 return bEqual;
1091 }
1092
1093 bool operator!=(const cec_logical_addresses &other) const
1094 {
1095 return !(*this == other);
1096 }
1097 #endif
1098 } cec_logical_addresses;
1099
1100 typedef enum libcec_alert
1101 {
1102 CEC_ALERT_SERVICE_DEVICE,
1103 CEC_ALERT_CONNECTION_LOST,
1104 CEC_ALERT_PERMISSION_ERROR,
1105 CEC_ALERT_PORT_BUSY
1106 } libcec_alert;
1107
1108 typedef enum libcec_parameter_type
1109 {
1110 CEC_PARAMETER_TYPE_STRING,
1111 CEC_PARAMETER_TYPE_UNKOWN
1112 } libcec_parameter_type;
1113
1114 struct libcec_parameter
1115 {
1116 libcec_parameter_type paramType; /**< the type of this parameter */
1117 void* paramData; /**< the value of this parameter */
1118 };
1119
1120 struct libcec_configuration;
1121
1122 typedef int (CEC_CDECL* CBCecLogMessageType)(void *param, const cec_log_message &);
1123 typedef int (CEC_CDECL* CBCecKeyPressType)(void *param, const cec_keypress &);
1124 typedef int (CEC_CDECL* CBCecCommandType)(void *param, const cec_command &);
1125 typedef int (CEC_CDECL* CBCecConfigurationChangedType)(void *param, const libcec_configuration &);
1126 typedef int (CEC_CDECL* CBCecAlertType)(void *param, const libcec_alert, const libcec_parameter &);
1127 typedef int (CEC_CDECL* CBCecMenuStateChangedType)(void *param, const cec_menu_state);
1128 typedef void (CEC_CDECL* CBCecSourceActivatedType)(void *param, const cec_logical_address, const uint8_t);
1129
1130 typedef struct ICECCallbacks
1131 {
1132 /*!
1133 * @brief Transfer a log message from libCEC to the client.
1134 * @param message The message to transfer.
1135 * @return 1 when ok, 0 otherwise.
1136 */
1137 CBCecLogMessageType CBCecLogMessage;
1138
1139 /*!
1140 * @brief Transfer a keypress from libCEC to the client.
1141 * @param key The keypress to transfer.
1142 * @return 1 when ok, 0 otherwise.
1143 */
1144 CBCecKeyPressType CBCecKeyPress;
1145
1146 /*!
1147 * @brief Transfer a CEC command from libCEC to the client.
1148 * @param command The command to transfer.
1149 * @return 1 when ok, 0 otherwise.
1150 */
1151 CBCecCommandType CBCecCommand;
1152
1153 /*!
1154 * @brief Transfer a changed configuration from libCEC to the client
1155 * @param configuration The configuration to transfer
1156 * @return 1 when ok, 0 otherwise
1157 */
1158 CBCecConfigurationChangedType CBCecConfigurationChanged;
1159
1160 /*!
1161 * @brief Transfer a libcec alert message from libCEC to the client
1162 * @param alert The alert type transfer.
1163 * @param data Misc. additional information.
1164 * @return 1 when ok, 0 otherwise
1165 */
1166 CBCecAlertType CBCecAlert;
1167
1168 /*!
1169 * @brief Transfer a menu state change to the client.
1170 * Transfer a menu state change to the client. If the command returns 1, then the change will be processed by
1171 * the busdevice. If 0, then the state of the busdevice won't be changed, and will always be kept 'activated',
1172 * @warning CEC does not allow the player to suppress the menu state change on the TV, so the menu on the TV will always be displayed, whatever the return value of this method is.
1173 * so keypresses are always routed.
1174 * @param newVal The new value.
1175 * @return 1 when libCEC should use this new value, 0 otherwise.
1176 */
1177 CBCecMenuStateChangedType CBCecMenuStateChanged;
1178
1179 /*!
1180 * @brief Called when a source that's handled by this client is activated.
1181 * @param logicalAddress The address that was just activated.
1182 * @param bActivated 1 when activated, 0 when deactivated.
1183 */
1184 CBCecSourceActivatedType CBCecSourceActivated;
1185
1186 #ifdef __cplusplus
1187 ICECCallbacks(void) { Clear(); }
1188 ~ICECCallbacks(void) { Clear(); };
1189
1190 void Clear(void)
1191 {
1192 CBCecLogMessage = NULL;
1193 CBCecKeyPress = NULL;
1194 CBCecCommand = NULL;
1195 CBCecConfigurationChanged = NULL;
1196 CBCecAlert = NULL;
1197 CBCecMenuStateChanged = NULL;
1198 CBCecSourceActivated = NULL;
1199 }
1200 #endif
1201 } ICECCallbacks;
1202
1203 typedef enum cec_client_version
1204 {
1205 CEC_CLIENT_VERSION_PRE_1_5 = 0,
1206 CEC_CLIENT_VERSION_1_5_0 = 0x1500,
1207 CEC_CLIENT_VERSION_1_5_1 = 0x1501,
1208 CEC_CLIENT_VERSION_1_5_2 = 0x1502,
1209 CEC_CLIENT_VERSION_1_5_3 = 0x1503,
1210 CEC_CLIENT_VERSION_1_6_0 = 0x1600,
1211 CEC_CLIENT_VERSION_1_6_1 = 0x1601,
1212 CEC_CLIENT_VERSION_1_6_2 = 0x1602,
1213 CEC_CLIENT_VERSION_1_6_3 = 0x1603,
1214 CEC_CLIENT_VERSION_1_7_0 = 0x1700,
1215 CEC_CLIENT_VERSION_1_7_1 = 0x1701
1216 } cec_client_version;
1217
1218 typedef enum cec_server_version
1219 {
1220 CEC_SERVER_VERSION_PRE_1_5 = 0,
1221 CEC_SERVER_VERSION_1_5_0 = 0x1500,
1222 CEC_SERVER_VERSION_1_5_1 = 0x1501,
1223 CEC_SERVER_VERSION_1_5_2 = 0x1502,
1224 CEC_SERVER_VERSION_1_5_3 = 0x1503,
1225 CEC_SERVER_VERSION_1_6_0 = 0x1600,
1226 CEC_SERVER_VERSION_1_6_1 = 0x1601,
1227 CEC_SERVER_VERSION_1_6_2 = 0x1602,
1228 CEC_SERVER_VERSION_1_6_3 = 0x1603,
1229 CEC_SERVER_VERSION_1_7_0 = 0x1700,
1230 CEC_SERVER_VERSION_1_7_1 = 0x1701
1231 } cec_server_version;
1232
1233 typedef struct libcec_configuration
1234 {
1235 uint32_t clientVersion; /*!< the version of the client that is connecting */
1236 char strDeviceName[13]; /*!< how to name the device on the CEC bus */
1237 cec_device_type_list deviceTypes; /*!< the CEC device types to emulate */
1238 uint8_t bAutodetectAddress; /*!< (read only) set to 1 by libCEC when the physical address was autodetected */
1239 uint16_t iPhysicalAddress; /*!< the physical address of the CEC adapter. only used when bAutodetectAddress = 0 or when the adapter doesn't support autodetection */
1240 cec_logical_address baseDevice; /*!< the logical address of the device to which the adapter is connected. only used when iPhysicalAddress = 0 and bAutodetectAddress = 0 or when the adapter doesn't support autodetection */
1241 uint8_t iHDMIPort; /*!< the HDMI port to which the adapter is connected. only used when iPhysicalAddress = 0 and bAutodetectAddress = 0 or when the adapter doesn't support autodetection */
1242 uint64_t tvVendor; /*!< override the vendor ID of the TV. leave this untouched to autodetect */
1243 cec_logical_addresses wakeDevices; /*!< wake these CEC devices when initialising libCEC or when calling PowerOnDevices() without any parameter */
1244 cec_logical_addresses powerOffDevices; /*!< power off these devices when calling StandbyDevices() without any parameter */
1245
1246 uint32_t serverVersion; /*!< the version number of the server. read-only */
1247
1248 // player specific settings
1249 uint8_t bGetSettingsFromROM; /*!< true to get the settings from the ROM (if set, and a v2 ROM is present), false to use these settings. */
1250 uint8_t bUseTVMenuLanguage; /*!< use the menu language of the TV in the player application */
1251 uint8_t bActivateSource; /*!< make libCEC the active source on the bus when starting the player application */
1252 uint8_t bPowerOffScreensaver; /*!< put devices in standby mode when activating the screensaver */
1253 uint8_t bPowerOffOnStandby; /*!< put this PC in standby mode when the TV is switched off. only used when bShutdownOnStandby = 0 */
1254 uint8_t bSendInactiveSource; /*!< send an 'inactive source' message when stopping the player. added in 1.5.1 */
1255
1256 void * callbackParam; /*!< the object to pass along with a call of the callback methods. NULL to ignore */
1257 ICECCallbacks * callbacks; /*!< the callback methods to use. set this to NULL when not using callbacks */
1258
1259 cec_logical_addresses logicalAddresses; /*!< (read-only) the current logical addresses. added in 1.5.3 */
1260 uint16_t iFirmwareVersion; /*!< (read-only) the firmware version of the adapter. added in 1.6.0 */
1261 uint8_t bPowerOffDevicesOnStandby; /*!< put devices in standby when the PC/player is put in standby. added in 1.6.0 */
1262 uint8_t bShutdownOnStandby; /*!< shutdown this PC when the TV is switched off. only used when bPowerOffOnStandby = 0. added in 1.6.0 */
1263 char strDeviceLanguage[3]; /*!< the menu language used by the client. 3 character ISO 639-2 country code. see http://http://www.loc.gov/standards/iso639-2/ added in 1.6.2 */
1264 uint32_t iFirmwareBuildDate; /*!< (read-only) the build date of the firmware, in seconds since epoch. if not available, this value will be set to 0. added in 1.6.2 */
1265 uint8_t bMonitorOnly; /*!< won't allocate a CCECClient when starting the connection when set (same as monitor mode). added in 1.6.3 */
1266
1267 #ifdef __cplusplus
1268 libcec_configuration(void) { Clear(); }
1269 ~libcec_configuration(void) { Clear(); }
1270
1271 bool operator==(const libcec_configuration &other) const
1272 {
1273 return ( clientVersion == other.clientVersion &&
1274 !strncmp(strDeviceName, other.strDeviceName, 13) &&
1275 deviceTypes == other.deviceTypes &&
1276 bAutodetectAddress == other.bAutodetectAddress &&
1277 iPhysicalAddress == other.iPhysicalAddress &&
1278 baseDevice == other.baseDevice &&
1279 iHDMIPort == other.iHDMIPort &&
1280 tvVendor == other.tvVendor &&
1281 wakeDevices == other.wakeDevices &&
1282 powerOffDevices == other.powerOffDevices &&
1283 serverVersion == other.serverVersion &&
1284 bGetSettingsFromROM == other.bGetSettingsFromROM &&
1285 bUseTVMenuLanguage == other.bUseTVMenuLanguage &&
1286 bActivateSource == other.bActivateSource &&
1287 bPowerOffScreensaver == other.bPowerOffScreensaver &&
1288 bPowerOffOnStandby == other.bPowerOffOnStandby &&
1289 bSendInactiveSource == other.bSendInactiveSource &&
1290 /* libcec 1.5.3+ */
1291 (other.clientVersion < CEC_CLIENT_VERSION_1_5_3 || logicalAddresses == other.logicalAddresses) &&
1292 /* libcec 1.6.0+ */
1293 (other.clientVersion < CEC_CLIENT_VERSION_1_6_0 || iFirmwareVersion == other.iFirmwareVersion) &&
1294 (other.clientVersion < CEC_CLIENT_VERSION_1_6_0 || bPowerOffDevicesOnStandby == other.bPowerOffDevicesOnStandby) &&
1295 (other.clientVersion < CEC_CLIENT_VERSION_1_6_0 || bShutdownOnStandby == other.bShutdownOnStandby) &&
1296 /* libcec 1.6.2+ */
1297 (other.clientVersion < CEC_CLIENT_VERSION_1_6_2 || !strncmp(strDeviceLanguage, other.strDeviceLanguage, 3)) &&
1298 (other.clientVersion < CEC_CLIENT_VERSION_1_6_2 || iFirmwareBuildDate == other.iFirmwareBuildDate) &&
1299 /* libcec 1.6.3+ */
1300 (other.clientVersion < CEC_CLIENT_VERSION_1_6_3 || bMonitorOnly == other.bMonitorOnly));
1301 }
1302
1303 bool operator!=(const libcec_configuration &other) const
1304 {
1305 return !(*this == other);
1306 }
1307
1308 /*!
1309 * @brief Reset this configution struct to the default values.
1310 */
1311 void Clear(void)
1312 {
1313 iPhysicalAddress = CEC_PHYSICAL_ADDRESS_TV;
1314 baseDevice = (cec_logical_address)CEC_DEFAULT_BASE_DEVICE;
1315 iHDMIPort = CEC_DEFAULT_HDMI_PORT;
1316 tvVendor = (uint64_t)CEC_VENDOR_UNKNOWN;
1317 clientVersion = (uint32_t)CEC_CLIENT_VERSION_PRE_1_5;
1318 serverVersion = (uint32_t)CEC_SERVER_VERSION_PRE_1_5;
1319 bAutodetectAddress = 0;
1320 bGetSettingsFromROM = CEC_DEFAULT_SETTING_GET_SETTINGS_FROM_ROM;
1321 bUseTVMenuLanguage = CEC_DEFAULT_SETTING_USE_TV_MENU_LANGUAGE;
1322 bActivateSource = CEC_DEFAULT_SETTING_ACTIVATE_SOURCE;
1323 bPowerOffScreensaver = CEC_DEFAULT_SETTING_POWER_OFF_SCREENSAVER;
1324 bPowerOffOnStandby = CEC_DEFAULT_SETTING_POWER_OFF_ON_STANDBY;
1325 bShutdownOnStandby = CEC_DEFAULT_SETTING_SHUTDOWN_ON_STANDBY;
1326 bSendInactiveSource = CEC_DEFAULT_SETTING_SEND_INACTIVE_SOURCE;
1327 iFirmwareVersion = CEC_FW_VERSION_UNKNOWN;
1328 bPowerOffDevicesOnStandby = CEC_DEFAULT_SETTING_POWER_OFF_DEVICES_STANDBY;
1329 memcpy(strDeviceLanguage, CEC_DEFAULT_DEVICE_LANGUAGE, 3);
1330 iFirmwareBuildDate = CEC_FW_BUILD_UNKNOWN;
1331 bMonitorOnly = 0;
1332
1333 memset(strDeviceName, 0, 13);
1334 deviceTypes.clear();
1335 logicalAddresses.Clear();
1336 wakeDevices.Clear();
1337 powerOffDevices.Clear();
1338
1339 #if CEC_DEFAULT_SETTING_POWER_OFF_SHUTDOWN == 1
1340 powerOffDevices.Set(CECDEVICE_BROADCAST);
1341 #endif
1342 #if CEC_DEFAULT_SETTING_ACTIVATE_SOURCE == 1
1343 wakeDevices.Set(CECDEVICE_TV);
1344 #endif
1345
1346 callbackParam = NULL;
1347 callbacks = NULL;
1348 }
1349 #endif
1350 } libcec_configuration;
1351
1352 #ifdef __cplusplus
1353 };
1354 };
1355 #endif
1356
1357 #endif /* CECTYPES_H_ */