+ String ^ ToString(CecVersion iVersion)
+ {
+ const char *retVal = m_libCec->ToString((cec_version)iVersion);
+ return gcnew String(retVal);
+ }
+
+ String ^ ToString(CecPowerStatus iState)
+ {
+ const char *retVal = m_libCec->ToString((cec_power_status)iState);
+ return gcnew String(retVal);
+ }
+
+ String ^ ToString(CecMenuState iState)
+ {
+ const char *retVal = m_libCec->ToString((cec_menu_state)iState);
+ return gcnew String(retVal);
+ }
+
+ String ^ ToString(CecDeckControlMode iMode)
+ {
+ const char *retVal = m_libCec->ToString((cec_deck_control_mode)iMode);
+ return gcnew String(retVal);
+ }
+
+ String ^ ToString(CecDeckInfo status)
+ {
+ const char *retVal = m_libCec->ToString((cec_deck_info)status);
+ return gcnew String(retVal);
+ }
+
+ String ^ ToString(CecOpcode opcode)
+ {
+ const char *retVal = m_libCec->ToString((cec_opcode)opcode);
+ return gcnew String(retVal);
+ }
+
+ String ^ ToString(CecSystemAudioStatus mode)
+ {
+ const char *retVal = m_libCec->ToString((cec_system_audio_status)mode);
+ return gcnew String(retVal);
+ }
+
+ String ^ ToString(CecAudioStatus status)
+ {
+ const char *retVal = m_libCec->ToString((cec_audio_status)status);
+ return gcnew String(retVal);
+ }
+
+ String ^ ToString(CecClientVersion version)
+ {
+ const char *retVal = m_libCec->ToString((cec_client_version)version);
+ return gcnew String(retVal);
+ }
+
+ String ^ ToString(CecServerVersion version)
+ {
+ const char *retVal = m_libCec->ToString((cec_server_version)version);
+ return gcnew String(retVal);
+ }
+
+ /// <summary>
+ /// Get a string with information about how libCEC was compiled.
+ /// </summary>
+ /// <returns>A string with information about how libCEC was compiled.</returns>
+ String ^ GetLibInfo()
+ {
+ const char *retVal = m_libCec->GetLibInfo();
+ return gcnew String(retVal);
+ }
+
+ /// <summary>
+ /// Calling this method will initialise the host on which libCEC is running.
+ /// On the RPi, it calls bcm_host_init(), which may only be called once per process, and is called by any process using
+ /// the video api on that system. So only call this method if libCEC is used in an application that
+ /// does not already initialise the video api.
+ /// </summary>
+ /// <remarks>Should be called as first call to libCEC, directly after CECInitialise() and before using Open()</remarks>
+ void InitVideoStandalone()
+ {
+ m_libCec->InitVideoStandalone();
+ }
+
+ /// <summary>
+ /// Get the (virtual) USB vendor id
+ /// </summary>
+ /// <returns>The (virtual) USB vendor id</returns>
+ uint16_t GetAdapterVendorId()
+ {
+ return m_libCec->GetAdapterVendorId();
+ }
+
+ /// <summary>
+ /// Get the (virtual) USB product id
+ /// </summary>
+ /// <returns>The (virtual) USB product id</returns>
+ uint16_t GetAdapterProductId()
+ {
+ return m_libCec->GetAdapterProductId();
+ }
+
+ private:
+ !LibCecSharp(void)
+ {
+ Close();
+ m_libCec = NULL;
+ }
+
+ bool InitialiseLibCec(LibCECConfiguration ^config)
+ {
+ marshal_context ^ context = gcnew marshal_context();
+ libcec_configuration libCecConfig;
+ ConvertConfiguration(context, config, libCecConfig);
+
+ m_libCec = (ICECAdapter *) CECInitialise(&libCecConfig);
+ config->Update(libCecConfig);
+
+ delete context;
+ return m_libCec != NULL;
+ }
+
+ void ConvertConfiguration(marshal_context ^context, LibCECConfiguration ^netConfig, CEC::libcec_configuration &config)
+ {
+ config.Clear();
+
+ const char *strDeviceName = context->marshal_as<const char*>(netConfig->DeviceName);
+ memcpy_s(config.strDeviceName, 13, strDeviceName, 13);
+ for (unsigned int iPtr = 0; iPtr < 5; iPtr++)
+ config.deviceTypes.types[iPtr] = (cec_device_type)netConfig->DeviceTypes->Types[iPtr];
+
+ config.bAutodetectAddress = netConfig->AutodetectAddress ? 1 : 0;
+ config.iPhysicalAddress = netConfig->PhysicalAddress;
+ config.baseDevice = (cec_logical_address)netConfig->BaseDevice;
+ config.iHDMIPort = netConfig->HDMIPort;
+ config.clientVersion = (cec_client_version)netConfig->ClientVersion;
+ config.bGetSettingsFromROM = netConfig->GetSettingsFromROM ? 1 : 0;
+ config.bActivateSource = netConfig->ActivateSource ? 1 : 0;
+ config.tvVendor = (cec_vendor_id)netConfig->TvVendor;
+ config.wakeDevices.Clear();
+ for (int iPtr = 0; iPtr < 16; iPtr++)
+ {
+ if (netConfig->WakeDevices->IsSet((CecLogicalAddress)iPtr))
+ config.wakeDevices.Set((cec_logical_address)iPtr);
+ }
+ config.powerOffDevices.Clear();
+ for (int iPtr = 0; iPtr < 16; iPtr++)
+ {
+ if (netConfig->PowerOffDevices->IsSet((CecLogicalAddress)iPtr))
+ config.powerOffDevices.Set((cec_logical_address)iPtr);
+ }
+ config.bPowerOffScreensaver = netConfig->PowerOffScreensaver ? 1 : 0;
+ config.bPowerOffOnStandby = netConfig->PowerOffOnStandby ? 1 : 0;
+
+ if (netConfig->ServerVersion >= CecServerVersion::Version1_5_1)
+ config.bSendInactiveSource = netConfig->SendInactiveSource ? 1 : 0;
+
+ if (netConfig->ServerVersion >= CecServerVersion::Version1_6_0)
+ {
+ config.bPowerOffDevicesOnStandby = netConfig->PowerOffDevicesOnStandby ? 1 : 0;
+ config.bShutdownOnStandby = netConfig->ShutdownOnStandby ? 1 : 0;
+ }
+
+ if (netConfig->ServerVersion >= CecServerVersion::Version1_6_2)
+ {
+ const char *strDeviceLanguage = context->marshal_as<const char*>(netConfig->DeviceLanguage);
+ memcpy_s(config.strDeviceLanguage, 3, strDeviceLanguage, 3);
+ }
+
+ if (netConfig->ServerVersion >= CecServerVersion::Version1_6_3)
+ config.bMonitorOnly = netConfig->MonitorOnlyClient ? 1 : 0;
+
+ if (netConfig->ServerVersion >= CecServerVersion::Version1_8_0)
+ config.cecVersion = (cec_version)netConfig->CECVersion;
+
+ if (netConfig->ServerVersion >= CecServerVersion::Version2_1_0)
+ config.bPowerOnScreensaver = netConfig->PowerOnScreensaver ? 1 : 0;
+
+ config.callbacks = &g_cecCallbacks;
+ }