2 * This file is part of the libCEC(R) library.
4 * libCEC(R) is Copyright (C) 2011-2013 Pulse-Eight Limited. All rights reserved.
5 * libCEC(R) is an original work, containing original code.
7 * libCEC(R) is a trademark of Pulse-Eight Limited.
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.
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.
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.
24 * Alternatively, you can license this library under a commercial license,
25 * please contact Pulse-Eight Licensing for more information.
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/
33 #include "CecSharpTypes.h"
36 using namespace System
;
37 using namespace System::Runtime::InteropServices
;
39 using namespace msclr::interop
;
44 /// Create a LibCecSharp instance and pass the configuration as argument.
45 /// Then call Open() to open a connection to the adapter. Close() closes the
48 /// libCEC can send commands to other devices on the CEC bus via the methods
49 /// on this interface, and all commands that libCEC received are sent back
50 /// to the application via callback methods. The callback methods can be
51 /// found in CecSharpTypes.h, CecCallbackMethods.
53 public ref
class LibCecSharp
: public CecCallbackMethods
57 /// Create a new LibCecSharp instance.
59 /// <param name="config">The configuration to pass to libCEC.</param>
60 LibCecSharp(LibCECConfiguration
^config
)
62 m_callbacks
= config
->Callbacks
;
63 CecCallbackMethods::EnableCallbacks(m_callbacks
);
64 if (!InitialiseLibCec(config
))
65 throw gcnew
Exception("Could not initialise LibCecSharp");
75 /// Try to find all connected CEC adapters.
77 /// <param name="path">The path filter for adapters. Leave empty to return all adapters.</param>
78 /// <returns>The adapters that were found.</returns>
79 array
<CecAdapter
^> ^ FindAdapters(String
^ path
)
81 cec_adapter
*devices
= new cec_adapter
[10];
83 marshal_context
^ context
= gcnew
marshal_context();
84 const char* strPathC
= path
->Length
> 0 ? context
->marshal_as
<const char*>(path
) : NULL
;
86 uint8_t iDevicesFound
= m_libCec
->FindAdapters(devices
, 10, NULL
);
88 array
<CecAdapter
^> ^ adapters
= gcnew array
<CecAdapter
^>(iDevicesFound
);
89 for (unsigned int iPtr
= 0; iPtr
< iDevicesFound
; iPtr
++)
90 adapters
[iPtr
] = gcnew
CecAdapter(gcnew
String(devices
[iPtr
].path
), gcnew
String(devices
[iPtr
].comm
));
98 /// Open a connection to the CEC adapter.
100 /// <param name="strPort">The COM port of the adapter</param>
101 /// <param name="iTimeoutMs">Connection timeout in milliseconds</param>
102 /// <returns>True when a connection was opened, false otherwise.</returns>
103 bool Open(String
^ strPort
, int iTimeoutMs
)
105 CecCallbackMethods::EnableCallbacks(m_callbacks
);
106 EnableCallbacks(m_callbacks
);
107 marshal_context
^ context
= gcnew
marshal_context();
108 const char* strPortC
= context
->marshal_as
<const char*>(strPort
);
109 bool bReturn
= m_libCec
->Open(strPortC
, iTimeoutMs
);
115 /// Close the connection to the CEC adapter
124 /// Disable all calls to callback methods.
126 virtual void DisableCallbacks(void) override
128 // delete the callbacks, since these might already have been destroyed in .NET
129 CecCallbackMethods::DisableCallbacks();
131 m_libCec
->EnableCallbacks(NULL
, NULL
);
135 /// Enable or change the callback methods that libCEC uses to send changes to the client application.
137 /// <param name="callbacks">The new callback methods to use.</param>
138 /// <returns>True when the callbacks were changed, false otherwise</returns>
139 virtual bool EnableCallbacks(CecCallbackMethods
^ callbacks
) override
141 if (m_libCec
&& CecCallbackMethods::EnableCallbacks(callbacks
))
142 return m_libCec
->EnableCallbacks((void*)GetCallbackPtr(), &g_cecCallbacks
);
148 /// Sends a ping command to the adapter, to check if it's responding.
150 /// <returns>True when the ping was succesful, false otherwise</returns>
151 bool PingAdapter(void)
153 return m_libCec
->PingAdapter();
157 /// Start the bootloader of the CEC adapter. Closes the connection when successful.
159 /// <returns>True when the command was sent successfully, false otherwise.</returns>
160 bool StartBootloader(void)
162 return m_libCec
->StartBootloader();
166 /// Transmit a raw CEC command over the CEC line.
168 /// <param name="command">The command to transmit</param>
169 /// <returns>True when the data was sent and acked, false otherwise.</returns>
170 bool Transmit(CecCommand
^ command
)
172 cec_command ccommand
;
173 cec_command::Format(ccommand
, (cec_logical_address
)command
->Initiator
, (cec_logical_address
)command
->Destination
, (cec_opcode
)command
->Opcode
);
174 ccommand
.transmit_timeout
= command
->TransmitTimeout
;
175 ccommand
.eom
= command
->Eom
;
176 ccommand
.ack
= command
->Ack
;
177 for (unsigned int iPtr
= 0; iPtr
< command
->Parameters
->Size
; iPtr
++)
178 ccommand
.parameters
.PushBack(command
->Parameters
->Data
[iPtr
]);
180 return m_libCec
->Transmit(ccommand
);
184 /// Change the logical address on the CEC bus of the CEC adapter. libCEC automatically assigns a logical address, and this method is only available for debugging purposes.
186 /// <param name="logicalAddress">The CEC adapter's new logical address.</param>
187 /// <returns>True when the logical address was set successfully, false otherwise.</returns>
188 bool SetLogicalAddress(CecLogicalAddress logicalAddress
)
190 return m_libCec
->SetLogicalAddress((cec_logical_address
) logicalAddress
);
194 /// Change the physical address (HDMI port) of the CEC adapter. libCEC will try to autodetect the physical address when connecting. If it did, it's set in libcec_configuration.
196 /// <param name="physicalAddress">The CEC adapter's new physical address.</param>
197 /// <returns>True when the physical address was set successfully, false otherwise.</returns>
198 bool SetPhysicalAddress(uint16_t physicalAddress
)
200 return m_libCec
->SetPhysicalAddress(physicalAddress
);
204 /// Power on the given CEC capable devices. If CECDEVICE_BROADCAST is used, then wakeDevice in libcec_configuration will be used.
206 /// <param name="logicalAddress">The logical address to power on.</param>
207 /// <returns>True when the command was sent succesfully, false otherwise.</returns>
208 bool PowerOnDevices(CecLogicalAddress logicalAddress
)
210 return m_libCec
->PowerOnDevices((cec_logical_address
) logicalAddress
);
214 /// Put the given CEC capable devices in standby mode. If CECDEVICE_BROADCAST is used, then standbyDevices in libcec_configuration will be used.
216 /// <param name="logicalAddress">The logical address of the device to put in standby.</param>
217 /// <returns>True when the command was sent succesfully, false otherwise.</returns>
218 bool StandbyDevices(CecLogicalAddress logicalAddress
)
220 return m_libCec
->StandbyDevices((cec_logical_address
) logicalAddress
);
224 /// Sends a POLL message to a device, to check if it's present and responding.
226 /// <param name="logicalAddress">The device to send the message to.</param>
227 /// <returns>True if the POLL was acked, false otherwise.</returns>
228 bool PollDevice(CecLogicalAddress logicalAddress
)
230 return m_libCec
->PollDevice((cec_logical_address
) logicalAddress
);
234 /// Change the active source to a device type handled by libCEC. Use CEC_DEVICE_TYPE_RESERVED to make the default type used by libCEC active.
236 /// <param name="type">The new active source. Use CEC_DEVICE_TYPE_RESERVED to use the primary type</param>
237 /// <returns>True when the command was sent succesfully, false otherwise.</returns>
238 bool SetActiveSource(CecDeviceType type
)
240 return m_libCec
->SetActiveSource((cec_device_type
) type
);
244 /// Change the deck control mode, if this adapter is registered as playback or recording device.
246 /// <param name="mode">The new control mode.</param>
247 /// <param name="sendUpdate">True to send the new status over the CEC line.</param>
248 /// <returns>True if set, false otherwise.</returns>
249 bool SetDeckControlMode(CecDeckControlMode mode
, bool sendUpdate
)
251 return m_libCec
->SetDeckControlMode((cec_deck_control_mode
) mode
, sendUpdate
);
255 /// Change the deck info, if this adapter is a playback or recording device.
257 /// <param name="info">The new deck info.</param>
258 /// <param name="sendUpdate">True to send the new status over the CEC line.</param>
259 /// <returns>True if set, false otherwise.</returns>
260 bool SetDeckInfo(CecDeckInfo info
, bool sendUpdate
)
262 return m_libCec
->SetDeckInfo((cec_deck_info
) info
, sendUpdate
);
266 /// Broadcast a message that notifies connected CEC capable devices that this device is no longer the active source.
268 /// <returns>True when the command was sent succesfully, false otherwise.</returns>
269 bool SetInactiveView(void)
271 return m_libCec
->SetInactiveView();
275 /// Change the menu state. This value is already changed by libCEC automatically if a device is (de)activated.
277 /// <param name="state">The new state.</param>
278 /// <param name="sendUpdate">True to send the new status over the CEC line.</param>
279 /// <returns>True if set, false otherwise.</returns>
280 bool SetMenuState(CecMenuState state
, bool sendUpdate
)
282 return m_libCec
->SetMenuState((cec_menu_state
) state
, sendUpdate
);
286 /// Display a message on the device with the given logical address. Not supported by most TVs.
288 /// <param name="logicalAddress">The logical address of the device to display the message on.</param>
289 /// <param name="duration">The duration of the message</param>
290 /// <param name="message">The message to display.</param>
291 /// <returns>True when the command was sent, false otherwise.</returns>
292 bool SetOSDString(CecLogicalAddress logicalAddress
, CecDisplayControl duration
, String
^ message
)
294 marshal_context
^ context
= gcnew
marshal_context();
295 const char* strMessageC
= context
->marshal_as
<const char*>(message
);
297 bool bReturn
= m_libCec
->SetOSDString((cec_logical_address
) logicalAddress
, (cec_display_control
) duration
, strMessageC
);
304 /// Enable or disable monitoring mode, for debugging purposes. If monitoring mode is enabled, libCEC won't respond to any command, but only log incoming data.
306 /// <param name="enable">True to enable, false to disable.</param>
307 /// <returns>True when switched successfully, false otherwise.</returns>
308 bool SwitchMonitoring(bool enable
)
310 return m_libCec
->SwitchMonitoring(enable
);
314 /// Get the CEC version of the device with the given logical address
316 /// <param name="logicalAddress">The logical address of the device to get the CEC version for.</param>
317 /// <returns>The version or CEC_VERSION_UNKNOWN when the version couldn't be fetched.</returns>
318 CecVersion
GetDeviceCecVersion(CecLogicalAddress logicalAddress
)
320 return (CecVersion
) m_libCec
->GetDeviceCecVersion((cec_logical_address
) logicalAddress
);
324 /// Get the menu language of the device with the given logical address
326 /// <param name="logicalAddress">The logical address of the device to get the menu language for.</param>
327 /// <returns>The requested menu language.</returns>
328 String
^ GetDeviceMenuLanguage(CecLogicalAddress logicalAddress
)
330 cec_menu_language lang
;
331 if (m_libCec
->GetDeviceMenuLanguage((cec_logical_address
) logicalAddress
, &lang
))
333 return gcnew
String(lang
.language
);
336 return gcnew
String("");
340 /// Get the vendor ID of the device with the given logical address.
342 /// <param name="logicalAddress">The logical address of the device to get the vendor ID for.</param>
343 /// <returns>The vendor ID or 0 if it wasn't found.</returns>
344 CecVendorId
GetDeviceVendorId(CecLogicalAddress logicalAddress
)
346 return (CecVendorId
)m_libCec
->GetDeviceVendorId((cec_logical_address
) logicalAddress
);
350 /// Get the power status of the device with the given logical address.
352 /// <param name="logicalAddress">The logical address of the device to get the power status for.</param>
353 /// <returns>The power status or CEC_POWER_STATUS_UNKNOWN if it wasn't found.</returns>
354 CecPowerStatus
GetDevicePowerStatus(CecLogicalAddress logicalAddress
)
356 return (CecPowerStatus
) m_libCec
->GetDevicePowerStatus((cec_logical_address
) logicalAddress
);
360 /// Tell libCEC to poll for active devices on the bus.
362 void RescanActiveDevices(void)
364 m_libCec
->RescanActiveDevices();
368 /// Get the logical addresses of the devices that are active on the bus, including those handled by libCEC.
370 /// <returns>The logical addresses of the active devices</returns>
371 CecLogicalAddresses
^ GetActiveDevices(void)
373 CecLogicalAddresses
^ retVal
= gcnew
CecLogicalAddresses();
374 unsigned int iDevices
= 0;
376 cec_logical_addresses activeDevices
= m_libCec
->GetActiveDevices();
378 for (uint8_t iPtr
= 0; iPtr
< 16; iPtr
++)
379 if (activeDevices
[iPtr
])
380 retVal
->Set((CecLogicalAddress
)iPtr
);
386 /// Check whether a device is active on the bus.
388 /// <param name="logicalAddress">The address to check.</param>
389 /// <returns>True when active, false otherwise.</returns>
390 bool IsActiveDevice(CecLogicalAddress logicalAddress
)
392 return m_libCec
->IsActiveDevice((cec_logical_address
)logicalAddress
);
396 /// Check whether a device of the given type is active on the bus.
398 /// <param name="type">The type to check.</param>
399 /// <returns>True when active, false otherwise.</returns>
400 bool IsActiveDeviceType(CecDeviceType type
)
402 return m_libCec
->IsActiveDeviceType((cec_device_type
)type
);
406 /// Changes the active HDMI port.
408 /// <param name="address">The device to which this libCEC is connected.</param>
409 /// <param name="port">The new port number.</param>
410 /// <returns>True when changed, false otherwise.</returns>
411 bool SetHDMIPort(CecLogicalAddress address
, uint8_t port
)
413 return m_libCec
->SetHDMIPort((cec_logical_address
)address
, port
);
417 /// Sends a volume up keypress to an audiosystem if it's present.
419 /// <param name="sendRelease">Send a key release after the keypress.</param>
420 /// <returns>The new audio status.</returns>
421 uint8_t VolumeUp(bool sendRelease
)
423 return m_libCec
->VolumeUp(sendRelease
);
427 /// Sends a volume down keypress to an audiosystem if it's present.
429 /// <param name="sendRelease">Send a key release after the keypress.</param>
430 /// <returns>The new audio status.</returns>
431 uint8_t VolumeDown(bool sendRelease
)
433 return m_libCec
->VolumeDown(sendRelease
);
437 /// Sends a mute keypress to an audiosystem if it's present.
439 /// <param name="sendRelease">Send a key release after the keypress.</param>
440 /// <returns>The new audio status.</returns>
441 uint8_t MuteAudio(bool sendRelease
)
443 return m_libCec
->MuteAudio(sendRelease
);
447 /// Send a keypress to a device on the CEC bus.
449 /// <param name="destination">The logical address of the device to send the message to.</param>
450 /// <param name="key">The key to send.</param>
451 /// <param name="wait">True to wait for a response, false otherwise.</param>
452 /// <returns>True when the keypress was acked, false otherwise.</returns>
453 bool SendKeypress(CecLogicalAddress destination
, CecUserControlCode key
, bool wait
)
455 return m_libCec
->SendKeypress((cec_logical_address
)destination
, (cec_user_control_code
)key
, wait
);
459 /// Send a key release to a device on the CEC bus.
461 /// <param name="destination">The logical address of the device to send the message to.</param>
462 /// <param name="wait">True to wait for a response, false otherwise.</param>
463 /// <returns>True when the key release was acked, false otherwise.</returns>
464 bool SendKeyRelease(CecLogicalAddress destination
, bool wait
)
466 return m_libCec
->SendKeyRelease((cec_logical_address
)destination
, wait
);
470 /// Get the OSD name of a device on the CEC bus.
472 /// <param name="logicalAddress">The logical address of the device to get the OSD name for.</param>
473 /// <returns>The OSD name.</returns>
474 String
^ GetDeviceOSDName(CecLogicalAddress logicalAddress
)
476 cec_osd_name osd
= m_libCec
->GetDeviceOSDName((cec_logical_address
) logicalAddress
);
477 return gcnew
String(osd
.name
);
481 /// Get the logical address of the device that is currently the active source on the CEC bus.
483 /// <returns>The active source or CECDEVICE_UNKNOWN when unknown.</returns>
484 CecLogicalAddress
GetActiveSource()
486 return (CecLogicalAddress
)m_libCec
->GetActiveSource();
490 /// Check whether a device is currently the active source on the CEC bus.
492 /// <param name="logicalAddress">The logical address of the device to check.</param>
493 /// <returns>True when it is the active source, false otherwise.</returns>
494 bool IsActiveSource(CecLogicalAddress logicalAddress
)
496 return m_libCec
->IsActiveSource((cec_logical_address
)logicalAddress
);
500 /// Get the physical address of the device with the given logical address.
502 /// <param name="address">The logical address of the device to get the physical address for.</param>
503 /// <returns>The physical address or 0 if it wasn't found.</returns>
504 uint16_t GetDevicePhysicalAddress(CecLogicalAddress address
)
506 return m_libCec
->GetDevicePhysicalAddress((cec_logical_address
)address
);
510 /// Sets the stream path to the device on the given logical address.
512 /// <param name="address">The address to activate.</param>
513 /// <returns>True when the command was sent, false otherwise.</returns>
514 bool SetStreamPath(CecLogicalAddress address
)
516 return m_libCec
->SetStreamPath((cec_logical_address
)address
);
520 /// Sets the stream path to the device on the given physical address.
522 /// <param name="physicalAddress">The address to activate.</param>
523 /// <returns>True when the command was sent, false otherwise.</returns>
524 bool SetStreamPath(uint16_t physicalAddress
)
526 return m_libCec
->SetStreamPath(physicalAddress
);
530 /// Get the list of logical addresses that libCEC is controlling
532 /// <returns>The list of logical addresses that libCEC is controlling</returns>
533 CecLogicalAddresses
^GetLogicalAddresses(void)
535 CecLogicalAddresses
^addr
= gcnew
CecLogicalAddresses();
536 cec_logical_addresses libAddr
= m_libCec
->GetLogicalAddresses();
537 for (unsigned int iPtr
= 0; iPtr
< 16; iPtr
++)
538 addr
->Addresses
[iPtr
] = (CecLogicalAddress
)libAddr
.addresses
[iPtr
];
539 addr
->Primary
= (CecLogicalAddress
)libAddr
.primary
;
544 /// Get libCEC's current configuration.
546 /// <param name="configuration">The configuration.</param>
547 /// <returns>True when the configuration was updated, false otherwise.</returns>
548 bool GetCurrentConfiguration(LibCECConfiguration
^configuration
)
550 libcec_configuration config
;
553 if (m_libCec
->GetCurrentConfiguration(&config
))
555 configuration
->Update(config
);
562 /// Check whether the CEC adapter can persist a configuration.
564 /// <returns>True when this CEC adapter can persist the user configuration, false otherwise.</returns>
565 bool CanPersistConfiguration(void)
567 return m_libCec
->CanPersistConfiguration();
571 /// Persist the given configuration in adapter (if supported)
573 /// <param name="configuration">The configuration to store.</param>
574 /// <returns>True when the configuration was persisted, false otherwise.</returns>
575 bool PersistConfiguration(LibCECConfiguration
^configuration
)
577 marshal_context
^ context
= gcnew
marshal_context();
578 libcec_configuration config
;
579 ConvertConfiguration(context
, configuration
, config
);
581 bool bReturn
= m_libCec
->PersistConfiguration(&config
);
588 /// Change libCEC's configuration.
590 /// <param name="configuration">The new configuration.</param>
591 /// <returns>True when the configuration was changed successfully, false otherwise.</returns>
592 bool SetConfiguration(LibCECConfiguration
^configuration
)
594 marshal_context
^ context
= gcnew
marshal_context();
595 libcec_configuration config
;
596 ConvertConfiguration(context
, configuration
, config
);
598 bool bReturn
= m_libCec
->SetConfiguration(&config
);
605 /// Check whether libCEC is the active source on the bus.
607 /// <returns>True when libCEC is the active source on the bus, false otherwise.</returns>
608 bool IsLibCECActiveSource()
610 return m_libCec
->IsLibCECActiveSource();
614 /// Get information about the given CEC adapter.
616 /// <param name="port">The COM port to which the device is connected</param>
617 /// <param name="configuration">The device configuration</param>
618 /// <param name="timeoutMs">The timeout in milliseconds</param>
619 /// <returns>True when the device was found, false otherwise</returns>
620 bool GetDeviceInformation(String
^ port
, LibCECConfiguration
^configuration
, uint32_t timeoutMs
)
623 marshal_context
^ context
= gcnew
marshal_context();
625 libcec_configuration config
;
628 const char* strPortC
= port
->Length
> 0 ? context
->marshal_as
<const char*>(port
) : NULL
;
630 if (m_libCec
->GetDeviceInformation(strPortC
, &config
, timeoutMs
))
632 configuration
->Update(config
);
640 String
^ ToString(CecLogicalAddress iAddress
)
642 const char *retVal
= m_libCec
->ToString((cec_logical_address
)iAddress
);
643 return gcnew
String(retVal
);
646 String
^ ToString(CecVendorId iVendorId
)
648 const char *retVal
= m_libCec
->ToString((cec_vendor_id
)iVendorId
);
649 return gcnew
String(retVal
);
652 String
^ ToString(CecVersion iVersion
)
654 const char *retVal
= m_libCec
->ToString((cec_version
)iVersion
);
655 return gcnew
String(retVal
);
658 String
^ ToString(CecPowerStatus iState
)
660 const char *retVal
= m_libCec
->ToString((cec_power_status
)iState
);
661 return gcnew
String(retVal
);
664 String
^ ToString(CecMenuState iState
)
666 const char *retVal
= m_libCec
->ToString((cec_menu_state
)iState
);
667 return gcnew
String(retVal
);
670 String
^ ToString(CecDeckControlMode iMode
)
672 const char *retVal
= m_libCec
->ToString((cec_deck_control_mode
)iMode
);
673 return gcnew
String(retVal
);
676 String
^ ToString(CecDeckInfo status
)
678 const char *retVal
= m_libCec
->ToString((cec_deck_info
)status
);
679 return gcnew
String(retVal
);
682 String
^ ToString(CecOpcode opcode
)
684 const char *retVal
= m_libCec
->ToString((cec_opcode
)opcode
);
685 return gcnew
String(retVal
);
688 String
^ ToString(CecSystemAudioStatus mode
)
690 const char *retVal
= m_libCec
->ToString((cec_system_audio_status
)mode
);
691 return gcnew
String(retVal
);
694 String
^ ToString(CecAudioStatus status
)
696 const char *retVal
= m_libCec
->ToString((cec_audio_status
)status
);
697 return gcnew
String(retVal
);
700 String
^ ToString(CecClientVersion version
)
702 const char *retVal
= m_libCec
->ToString((cec_client_version
)version
);
703 return gcnew
String(retVal
);
706 String
^ ToString(CecServerVersion version
)
708 const char *retVal
= m_libCec
->ToString((cec_server_version
)version
);
709 return gcnew
String(retVal
);
713 /// Get a string with information about how libCEC was compiled.
715 /// <returns>A string with information about how libCEC was compiled.</returns>
716 String
^ GetLibInfo()
718 const char *retVal
= m_libCec
->GetLibInfo();
719 return gcnew
String(retVal
);
723 /// Calling this method will initialise the host on which libCEC is running.
724 /// On the RPi, it calls bcm_host_init(), which may only be called once per process, and is called by any process using
725 /// the video api on that system. So only call this method if libCEC is used in an application that
726 /// does not already initialise the video api.
728 /// <remarks>Should be called as first call to libCEC, directly after CECInitialise() and before using Open()</remarks>
729 void InitVideoStandalone()
731 m_libCec
->InitVideoStandalone();
735 /// Get the (virtual) USB vendor id
737 /// <returns>The (virtual) USB vendor id</returns>
738 uint16_t GetAdapterVendorId()
740 return m_libCec
->GetAdapterVendorId();
744 /// Get the (virtual) USB product id
746 /// <returns>The (virtual) USB product id</returns>
747 uint16_t GetAdapterProductId()
749 return m_libCec
->GetAdapterProductId();
759 bool InitialiseLibCec(LibCECConfiguration
^config
)
761 marshal_context
^ context
= gcnew
marshal_context();
762 libcec_configuration libCecConfig
;
763 ConvertConfiguration(context
, config
, libCecConfig
);
765 m_libCec
= (ICECAdapter
*) CECInitialise(&libCecConfig
);
766 config
->Update(libCecConfig
);
769 return m_libCec
!= NULL
;
772 void ConvertConfiguration(marshal_context
^context
, LibCECConfiguration
^netConfig
, CEC::libcec_configuration
&config
)
776 const char *strDeviceName
= context
->marshal_as
<const char*>(netConfig
->DeviceName
);
777 memcpy_s(config
.strDeviceName
, 13, strDeviceName
, 13);
778 for (unsigned int iPtr
= 0; iPtr
< 5; iPtr
++)
779 config
.deviceTypes
.types
[iPtr
] = (cec_device_type
)netConfig
->DeviceTypes
->Types
[iPtr
];
781 config
.bAutodetectAddress
= netConfig
->AutodetectAddress
? 1 : 0;
782 config
.iPhysicalAddress
= netConfig
->PhysicalAddress
;
783 config
.baseDevice
= (cec_logical_address
)netConfig
->BaseDevice
;
784 config
.iHDMIPort
= netConfig
->HDMIPort
;
785 config
.clientVersion
= (cec_client_version
)netConfig
->ClientVersion
;
786 config
.bGetSettingsFromROM
= netConfig
->GetSettingsFromROM
? 1 : 0;
787 config
.bActivateSource
= netConfig
->ActivateSource
? 1 : 0;
788 config
.tvVendor
= (cec_vendor_id
)netConfig
->TvVendor
;
789 config
.wakeDevices
.Clear();
790 for (int iPtr
= 0; iPtr
< 16; iPtr
++)
792 if (netConfig
->WakeDevices
->IsSet((CecLogicalAddress
)iPtr
))
793 config
.wakeDevices
.Set((cec_logical_address
)iPtr
);
795 config
.powerOffDevices
.Clear();
796 for (int iPtr
= 0; iPtr
< 16; iPtr
++)
798 if (netConfig
->PowerOffDevices
->IsSet((CecLogicalAddress
)iPtr
))
799 config
.powerOffDevices
.Set((cec_logical_address
)iPtr
);
801 config
.bPowerOffScreensaver
= netConfig
->PowerOffScreensaver
? 1 : 0;
802 config
.bPowerOffOnStandby
= netConfig
->PowerOffOnStandby
? 1 : 0;
804 if (netConfig
->ServerVersion
>= CecServerVersion::Version1_5_1
)
805 config
.bSendInactiveSource
= netConfig
->SendInactiveSource
? 1 : 0;
807 if (netConfig
->ServerVersion
>= CecServerVersion::Version1_6_0
)
809 config
.bPowerOffDevicesOnStandby
= netConfig
->PowerOffDevicesOnStandby
? 1 : 0;
810 config
.bShutdownOnStandby
= netConfig
->ShutdownOnStandby
? 1 : 0;
813 if (netConfig
->ServerVersion
>= CecServerVersion::Version1_6_2
)
815 const char *strDeviceLanguage
= context
->marshal_as
<const char*>(netConfig
->DeviceLanguage
);
816 memcpy_s(config
.strDeviceLanguage
, 3, strDeviceLanguage
, 3);
819 if (netConfig
->ServerVersion
>= CecServerVersion::Version1_6_3
)
820 config
.bMonitorOnly
= netConfig
->MonitorOnlyClient
? 1 : 0;
822 if (netConfig
->ServerVersion
>= CecServerVersion::Version1_8_0
)
823 config
.cecVersion
= (cec_version
)netConfig
->CECVersion
;
825 if (netConfig
->ServerVersion
>= CecServerVersion::Version2_1_0
)
826 config
.bPowerOnScreensaver
= netConfig
->PowerOnScreensaver
? 1 : 0;
828 config
.callbacks
= &g_cecCallbacks
;
832 ICECAdapter
* m_libCec
;
833 CecCallbackMethods
^ m_callbacks
;