Commit | Line | Data |
---|---|---|
abbca718 LOK |
1 | /* |
2 | * This file is part of the libCEC(R) library. | |
3 | * | |
b492c10e | 4 | * libCEC(R) is Copyright (C) 2011-2012 Pulse-Eight Limited. All rights reserved. |
abbca718 LOK |
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 | ||
2b44051c LOK |
33 | #include "env.h" |
34 | #include "cec.h" | |
35 | #include "cecc.h" | |
abbca718 LOK |
36 | |
37 | using namespace CEC; | |
38 | using namespace std; | |
39 | ||
40 | /*! | |
41 | * C interface implementation | |
42 | */ | |
43 | //@{ | |
2abe74eb | 44 | ICECAdapter *cec_parser; |
abbca718 | 45 | |
3efda01a | 46 | int cec_initialise(libcec_configuration *configuration) |
f8513317 | 47 | { |
caca2d81 LOK |
48 | cec_parser = (ICECAdapter *) CECInitialise(configuration); |
49 | return (cec_parser != NULL) ? 1 : 0; | |
50 | } | |
51 | ||
52 | int cec_init_typed(const char *strDeviceName, cec_device_type_list deviceTypes) | |
53 | { | |
54 | cec_parser = (ICECAdapter *) CECInit(strDeviceName, deviceTypes); | |
f8513317 LOK |
55 | return (cec_parser != NULL) ? 1 : 0; |
56 | } | |
57 | ||
5f39c4d8 LOK |
58 | void cec_destroy(void) |
59 | { | |
60 | cec_close(); | |
25701fa6 | 61 | CECDestroy(cec_parser); |
5f39c4d8 LOK |
62 | cec_parser = NULL; |
63 | } | |
64 | ||
02ee2c68 | 65 | int cec_open(const char *strPort, uint32_t iTimeout) |
abbca718 LOK |
66 | { |
67 | if (cec_parser) | |
68 | return cec_parser->Open(strPort, iTimeout); | |
69 | return false; | |
70 | } | |
71 | ||
5f39c4d8 | 72 | void cec_close(void) |
f99bc831 | 73 | { |
f99bc831 | 74 | if (cec_parser) |
5f39c4d8 | 75 | cec_parser->Close(); |
f99bc831 LOK |
76 | } |
77 | ||
547b390d | 78 | int cec_enable_callbacks(void *cbParam, ICECCallbacks *callbacks) |
fa4798bd LOK |
79 | { |
80 | if (cec_parser) | |
547b390d | 81 | return cec_parser->EnableCallbacks(cbParam, callbacks) ? 1 : 0; |
fa4798bd LOK |
82 | return -1; |
83 | } | |
84 | ||
25701fa6 | 85 | int8_t cec_find_adapters(cec_adapter *deviceList, uint8_t iBufSize, const char *strDevicePath /* = NULL */) |
abbca718 LOK |
86 | { |
87 | if (cec_parser) | |
25701fa6 | 88 | return cec_parser->FindAdapters(deviceList, iBufSize, strDevicePath); |
2abe74eb | 89 | return -1; |
abbca718 LOK |
90 | } |
91 | ||
02ee2c68 | 92 | int cec_ping_adapters(void) |
abbca718 LOK |
93 | { |
94 | if (cec_parser) | |
02ee2c68 LOK |
95 | return cec_parser->PingAdapter() ? 1 : 0; |
96 | return -1; | |
abbca718 LOK |
97 | } |
98 | ||
02ee2c68 | 99 | int cec_start_bootloader(void) |
abbca718 LOK |
100 | { |
101 | if (cec_parser) | |
02ee2c68 LOK |
102 | return cec_parser->StartBootloader() ? 1 : 0; |
103 | return -1; | |
abbca718 LOK |
104 | } |
105 | ||
65894f58 | 106 | int8_t cec_get_min_lib_version(void) |
abbca718 LOK |
107 | { |
108 | if (cec_parser) | |
d75be19b | 109 | return cec_parser->GetMinLibVersion(); |
2abe74eb | 110 | return -1; |
abbca718 LOK |
111 | } |
112 | ||
d75be19b | 113 | int8_t cec_get_lib_version_major(void) |
abbca718 LOK |
114 | { |
115 | if (cec_parser) | |
d75be19b | 116 | return cec_parser->GetLibVersionMajor(); |
2abe74eb | 117 | return -1; |
abbca718 LOK |
118 | } |
119 | ||
eafd9bed LOK |
120 | int8_t cec_get_lib_version_minor(void) |
121 | { | |
122 | if (cec_parser) | |
123 | return cec_parser->GetLibVersionMinor(); | |
124 | return -1; | |
125 | } | |
126 | ||
02ee2c68 | 127 | int cec_get_next_log_message(cec_log_message *message) |
abbca718 LOK |
128 | { |
129 | if (cec_parser) | |
02ee2c68 LOK |
130 | return cec_parser->GetNextLogMessage(message) ? 1 : 0; |
131 | return -1; | |
abbca718 LOK |
132 | } |
133 | ||
02ee2c68 | 134 | int cec_get_next_keypress(cec_keypress *key) |
abbca718 LOK |
135 | { |
136 | if (cec_parser) | |
02ee2c68 LOK |
137 | return cec_parser->GetNextKeypress(key) ? 1 : 0; |
138 | return -1; | |
abbca718 LOK |
139 | } |
140 | ||
02ee2c68 | 141 | int cec_get_next_command(cec_command *command) |
825ddb96 LOK |
142 | { |
143 | if (cec_parser) | |
02ee2c68 LOK |
144 | return cec_parser->GetNextCommand(command) ? 1 : 0; |
145 | return -1; | |
825ddb96 LOK |
146 | } |
147 | ||
f958766e | 148 | int cec_transmit(const CEC::cec_command *data) |
abbca718 LOK |
149 | { |
150 | if (cec_parser) | |
f958766e | 151 | return cec_parser->Transmit(*data) ? 1 : 0; |
02ee2c68 | 152 | return -1; |
abbca718 LOK |
153 | } |
154 | ||
2492216a | 155 | int cec_set_logical_address(cec_logical_address iLogicalAddress /* = CECDEVICE_PLAYBACKDEVICE1 */) |
abbca718 LOK |
156 | { |
157 | if (cec_parser) | |
02ee2c68 LOK |
158 | return cec_parser->SetLogicalAddress(iLogicalAddress) ? 1 : 0; |
159 | return -1; | |
6dfe9213 LOK |
160 | } |
161 | ||
2492216a LOK |
162 | int cec_set_physical_address(uint16_t iPhysicalAddress /* = CEC_DEFAULT_PHYSICAL_ADDRESS */) |
163 | { | |
164 | if (cec_parser) | |
165 | return cec_parser->SetPhysicalAddress(iPhysicalAddress) ? 1 : 0; | |
166 | return -1; | |
167 | } | |
168 | ||
02ee2c68 | 169 | int cec_power_on_devices(cec_logical_address address /* = CECDEVICE_TV */) |
6dfe9213 LOK |
170 | { |
171 | if (cec_parser) | |
02ee2c68 LOK |
172 | return cec_parser->PowerOnDevices(address) ? 1 : 0; |
173 | return -1; | |
abbca718 LOK |
174 | } |
175 | ||
02ee2c68 | 176 | int cec_standby_devices(cec_logical_address address /* = CECDEVICE_BROADCAST */) |
abbca718 LOK |
177 | { |
178 | if (cec_parser) | |
02ee2c68 LOK |
179 | return cec_parser->StandbyDevices(address) ? 1 : 0; |
180 | return -1; | |
abbca718 LOK |
181 | } |
182 | ||
02ee2c68 | 183 | int cec_set_active_view(void) |
abbca718 LOK |
184 | { |
185 | if (cec_parser) | |
02ee2c68 LOK |
186 | return cec_parser->SetActiveView() ? 1 : 0; |
187 | return -1; | |
abbca718 LOK |
188 | } |
189 | ||
18203d17 LOK |
190 | int cec_set_active_source(cec_device_type type) |
191 | { | |
192 | if (cec_parser) | |
193 | return cec_parser->SetActiveSource(type) ? 1 : 0; | |
194 | return -1; | |
195 | } | |
196 | ||
f2cdbc36 PG |
197 | int cec_set_deck_control_mode(cec_deck_control_mode mode, int bSendUpdate) { |
198 | if (cec_parser) | |
199 | return cec_parser->SetDeckControlMode(mode, bSendUpdate == 1) ? 1 : 0; | |
200 | return -1; | |
201 | } | |
202 | ||
203 | int cec_set_deck_info(cec_deck_info info, int bSendUpdate) { | |
204 | if (cec_parser) | |
205 | return cec_parser->SetDeckInfo(info, bSendUpdate == 1) ? 1 : 0; | |
206 | return -1; | |
207 | ||
208 | } | |
209 | ||
02ee2c68 | 210 | int cec_set_inactive_view(void) |
abbca718 LOK |
211 | { |
212 | if (cec_parser) | |
02ee2c68 LOK |
213 | return cec_parser->SetInactiveView() ? 1 : 0; |
214 | return -1; | |
abbca718 LOK |
215 | } |
216 | ||
f2cdbc36 PG |
217 | int cec_set_menu_state(cec_menu_state state, int bSendUpdate) { |
218 | if (cec_parser) | |
219 | return cec_parser->SetMenuState(state, bSendUpdate == 1) ? 1 : 0; | |
220 | return -1; | |
221 | } | |
222 | ||
1969b140 LOK |
223 | int cec_set_osd_string(cec_logical_address iLogicalAddress, cec_display_control duration, const char *strMessage) |
224 | { | |
225 | if (cec_parser) | |
226 | return cec_parser->SetOSDString(iLogicalAddress, duration, strMessage) ? 1 : 0; | |
227 | return -1; | |
228 | } | |
229 | ||
8b7e5ff6 LOK |
230 | int cec_switch_monitoring(int bEnable) |
231 | { | |
232 | if (cec_parser) | |
233 | return cec_parser->SwitchMonitoring(bEnable == 1) ? 1 : 0; | |
234 | return -1; | |
235 | } | |
236 | ||
6a1c0009 LOK |
237 | cec_version cec_get_device_cec_version(cec_logical_address iLogicalAddress) |
238 | { | |
239 | if (cec_parser) | |
240 | return cec_parser->GetDeviceCecVersion(iLogicalAddress); | |
241 | return CEC_VERSION_UNKNOWN; | |
242 | } | |
243 | ||
a3269a0a LOK |
244 | int cec_get_device_menu_language(cec_logical_address iLogicalAddress, cec_menu_language *language) |
245 | { | |
246 | if (cec_parser) | |
247 | return cec_parser->GetDeviceMenuLanguage(iLogicalAddress, language) ? 1 : 0; | |
248 | return -1; | |
249 | } | |
250 | ||
44c74256 LOK |
251 | uint64_t cec_get_device_vendor_id(cec_logical_address iLogicalAddress) |
252 | { | |
253 | if (cec_parser) | |
254 | return cec_parser->GetDeviceVendorId(iLogicalAddress); | |
255 | return 0; | |
256 | } | |
257 | ||
eab72c40 LOK |
258 | uint16_t cec_get_device_physical_address(cec_logical_address iLogicalAddress) |
259 | { | |
260 | if (cec_parser) | |
261 | return cec_parser->GetDevicePhysicalAddress(iLogicalAddress); | |
262 | return 0; | |
263 | } | |
264 | ||
b4b1b49b LOK |
265 | cec_logical_address cec_get_active_source(void) |
266 | { | |
267 | if (cec_parser) | |
268 | return cec_parser->GetActiveSource(); | |
269 | return CECDEVICE_UNKNOWN; | |
270 | } | |
271 | ||
272 | int cec_is_active_source(cec_logical_address iAddress) | |
273 | { | |
274 | if (cec_parser) | |
275 | return cec_parser->IsActiveSource(iAddress); | |
276 | return false; | |
277 | } | |
278 | ||
e55f3f70 LOK |
279 | cec_power_status cec_get_device_power_status(cec_logical_address iLogicalAddress) |
280 | { | |
281 | if (cec_parser) | |
282 | return cec_parser->GetDevicePowerStatus(iLogicalAddress); | |
283 | return CEC_POWER_STATUS_UNKNOWN; | |
284 | } | |
285 | ||
57f45e6c LOK |
286 | int cec_poll_device(cec_logical_address iLogicalAddress) |
287 | { | |
288 | if (cec_parser) | |
6d858ba4 LOK |
289 | return cec_parser->PollDevice(iLogicalAddress) ? 1 : 0; |
290 | return -1; | |
291 | } | |
292 | ||
293 | cec_logical_addresses cec_get_active_devices(void) | |
294 | { | |
295 | cec_logical_addresses addresses; | |
988de7b9 | 296 | addresses.Clear(); |
6d858ba4 LOK |
297 | if (cec_parser) |
298 | addresses = cec_parser->GetActiveDevices(); | |
299 | return addresses; | |
300 | } | |
301 | ||
302 | int cec_is_active_device(cec_logical_address iAddress) | |
303 | { | |
304 | if (cec_parser) | |
305 | return cec_parser->IsActiveDevice(iAddress) ? 1 : 0; | |
306 | return -1; | |
307 | } | |
308 | ||
309 | int cec_is_active_device_type(cec_device_type type) | |
310 | { | |
311 | if (cec_parser) | |
312 | return cec_parser->IsActiveDeviceType(type) ? 1 : 0; | |
57f45e6c LOK |
313 | return -1; |
314 | } | |
315 | ||
d2f1c157 | 316 | int cec_set_hdmi_port(cec_logical_address iBaseDevice, uint8_t iPort) |
16b1e052 LOK |
317 | { |
318 | if (cec_parser) | |
d2f1c157 | 319 | return cec_parser->SetHDMIPort(iBaseDevice, iPort) ? 1 : 0; |
16b1e052 LOK |
320 | return -1; |
321 | } | |
322 | ||
5c73f7f7 | 323 | int cec_volume_up(int bSendRelease) |
04e637f9 LOK |
324 | { |
325 | if (cec_parser) | |
5c73f7f7 | 326 | return cec_parser->VolumeUp(bSendRelease == 1); |
04e637f9 LOK |
327 | return -1; |
328 | } | |
329 | ||
5c73f7f7 | 330 | int cec_volume_down(int bSendRelease) |
04e637f9 LOK |
331 | { |
332 | if (cec_parser) | |
5c73f7f7 | 333 | return cec_parser->VolumeDown(bSendRelease == 1); |
04e637f9 LOK |
334 | return -1; |
335 | } | |
336 | ||
5c73f7f7 | 337 | int cec_mute_audio(int bSendRelease) |
04e637f9 LOK |
338 | { |
339 | if (cec_parser) | |
5c73f7f7 | 340 | return cec_parser->MuteAudio(bSendRelease == 1); |
04e637f9 LOK |
341 | return -1; |
342 | } | |
343 | ||
a33794d8 LOK |
344 | int cec_send_keypress(cec_logical_address iDestination, cec_user_control_code key, int bWait) |
345 | { | |
346 | if (cec_parser) | |
347 | return cec_parser->SendKeypress(iDestination, key, bWait == 1) ? 1 : 0; | |
348 | return -1; | |
349 | } | |
350 | ||
351 | int cec_send_key_release(cec_logical_address iDestination, int bWait) | |
352 | { | |
353 | if (cec_parser) | |
354 | return cec_parser->SendKeyRelease(iDestination, bWait == 1) ? 1 : 0; | |
355 | return -1; | |
356 | } | |
357 | ||
f71a1df9 | 358 | cec_osd_name cec_get_device_osd_name(cec_logical_address iAddress) |
ed21be2a LOK |
359 | { |
360 | cec_osd_name retVal; | |
361 | retVal.device = iAddress; | |
362 | retVal.name[0] = 0; | |
363 | ||
364 | if (cec_parser) | |
f71a1df9 | 365 | retVal = cec_parser->GetDeviceOSDName(iAddress); |
ed21be2a LOK |
366 | |
367 | return retVal; | |
368 | } | |
369 | ||
2dbd78f8 LOK |
370 | int cec_enable_physical_address_detection(void) |
371 | { | |
372 | return cec_parser ? (cec_parser->EnablePhysicalAddressDetection() ? 1 : 0) : -1; | |
373 | } | |
374 | ||
f42d3e0f LOK |
375 | int cec_set_stream_path_logical(CEC::cec_logical_address iAddress) |
376 | { | |
377 | return cec_parser ? (cec_parser->SetStreamPath(iAddress) ? 1 : 0) : -1; | |
378 | } | |
379 | ||
380 | int cec_set_stream_path_physical(uint16_t iPhysicalAddress) | |
381 | { | |
382 | return cec_parser ? (cec_parser->SetStreamPath(iPhysicalAddress) ? 1 : 0) : -1; | |
383 | } | |
384 | ||
80b72250 LOK |
385 | cec_logical_addresses cec_get_logical_addresses(void) |
386 | { | |
387 | cec_logical_addresses addr; | |
388 | addr.Clear(); | |
389 | if (cec_parser) | |
390 | addr = cec_parser->GetLogicalAddresses(); | |
391 | return addr; | |
392 | } | |
393 | ||
d40928b5 LOK |
394 | int cec_get_current_configuration(libcec_configuration *configuration) |
395 | { | |
396 | return cec_parser ? (cec_parser->GetCurrentConfiguration(configuration) ? 1 : 0) : -1; | |
397 | } | |
398 | ||
224ea877 LOK |
399 | int cec_can_persist_configuration(void) |
400 | { | |
401 | return cec_parser ? (cec_parser->CanPersistConfiguration() ? 1 : 0) : -1; | |
402 | } | |
403 | ||
30b4aac0 | 404 | int cec_persist_configuration(libcec_configuration *configuration) |
224ea877 LOK |
405 | { |
406 | return cec_parser ? (cec_parser->PersistConfiguration(configuration) ? 1 : 0) : -1; | |
407 | } | |
408 | ||
30b4aac0 LOK |
409 | int cec_set_configuration(libcec_configuration *configuration) |
410 | { | |
411 | return cec_parser ? (cec_parser->SetConfiguration(configuration) ? 1 : 0) : -1; | |
412 | } | |
413 | ||
3efda01a LOK |
414 | void cec_rescan_devices(void) |
415 | { | |
416 | if (cec_parser) | |
417 | cec_parser->RescanActiveDevices(); | |
418 | } | |
419 | ||
c9549d35 LOK |
420 | int cec_is_libcec_active_source(void) |
421 | { | |
422 | return cec_parser ? (cec_parser->IsLibCECActiveSource() ? 1 : 0) : -1; | |
423 | } | |
424 | ||
bd624ba8 LOK |
425 | int cec_get_device_information(const char *strPort, CEC::libcec_configuration *config, uint32_t iTimeoutMs) |
426 | { | |
427 | return cec_parser ? (cec_parser->GetDeviceInformation(strPort, config, iTimeoutMs) ? 1 : 0) : -1; | |
428 | } | |
429 | ||
2b44051c LOK |
430 | const char * cec_get_lib_info(void) |
431 | { | |
432 | return cec_parser ? cec_parser->GetLibInfo() : NULL; | |
433 | } | |
434 | ||
435 | void cec_init_video_standalone(void) | |
436 | { | |
437 | if (cec_parser) | |
438 | cec_parser->InitVideoStandalone(); | |
439 | } | |
440 | ||
abbca718 | 441 | //@} |