- marshal_context ^ context = gcnew marshal_context();
- const char* strPortC = context->marshal_as<const char*>(strPort);
- bool bReturn = m_libCec->Open(strPortC, iTimeoutMs);
- delete context;
- return bReturn;
- }
-
- void Close(void)
- {
- DisableCallbacks();
- m_libCec->Close();
- }
-
- virtual void DisableCallbacks(void) override
- {
- // delete the callbacks, since these might already have been destroyed in .NET
- CecCallbackMethods::DisableCallbacks();
- if (m_libCec)
- m_libCec->EnableCallbacks(NULL, NULL);
- }
-
- virtual bool EnableCallbacks(CecCallbackMethods ^ callbacks) override
- {
- if (m_libCec && CecCallbackMethods::EnableCallbacks(callbacks))
- return m_libCec->EnableCallbacks((void*)GetCallbackPtr(), &g_cecCallbacks);
-
- return false;
- }
-
- bool PingAdapter(void)
- {
- return m_libCec->PingAdapter();
- }
-
- bool StartBootloader(void)
- {
- return m_libCec->StartBootloader();
- }
-
- int GetMinLibVersion(void)
- {
- return m_libCec->GetMinLibVersion();
- }
-
- int GetLibVersionMajor(void)
- {
- return m_libCec->GetLibVersionMajor();
- }
-
- int GetLibVersionMinor(void)
- {
- return m_libCec->GetLibVersionMinor();
- }
-
- CecLogMessage ^ GetNextLogMessage(void)
- {
- cec_log_message msg;
- if (m_libCec->GetNextLogMessage(&msg))
- {
- return gcnew CecLogMessage(gcnew String(msg.message), (CecLogLevel)msg.level, msg.time);
- }
-
- return gcnew CecLogMessage();
- }
-
- CecKeypress ^ GetNextKeypress(void)
- {
- cec_keypress key;
- if (m_libCec->GetNextKeypress(&key))
- {
- return gcnew CecKeypress((CecUserControlCode)key.keycode, key.duration);
- }
-
- return gcnew CecKeypress();
- }
-
- CecCommand ^ GetNextCommand(void)
- {
- cec_command command;
- if (m_libCec->GetNextCommand(&command))
- {
- CecCommand ^ retVal = gcnew CecCommand((CecLogicalAddress)command.initiator, (CecLogicalAddress)command.destination, command.ack == 1 ? true : false, command.eom == 1 ? true : false, (CecOpcode)command.opcode, command.transmit_timeout);
- for (uint8_t iPtr = 0; iPtr < command.parameters.size; iPtr++)
- retVal->Parameters->PushBack(command.parameters[iPtr]);
- return retVal;
- }
-
- return gcnew CecCommand();
- }
-
- bool Transmit(CecCommand ^ command)
- {
- cec_command ccommand;
- cec_command::Format(ccommand, (cec_logical_address)command->Initiator, (cec_logical_address)command->Destination, (cec_opcode)command->Opcode);
- ccommand.transmit_timeout = command->TransmitTimeout;
- ccommand.eom = command->Eom;
- ccommand.ack = command->Ack;
- for (unsigned int iPtr = 0; iPtr < command->Parameters->Size; iPtr++)
- ccommand.parameters.PushBack(command->Parameters->Data[iPtr]);
-
- return m_libCec->Transmit(ccommand);
- }
-
- bool SetLogicalAddress(CecLogicalAddress logicalAddress)
- {
- return m_libCec->SetLogicalAddress((cec_logical_address) logicalAddress);
- }
-
- bool SetPhysicalAddress(uint16_t physicalAddress)
- {
- return m_libCec->SetPhysicalAddress(physicalAddress);
- }
-
- bool PowerOnDevices(CecLogicalAddress logicalAddress)
- {
- return m_libCec->PowerOnDevices((cec_logical_address) logicalAddress);
- }
-
- bool StandbyDevices(CecLogicalAddress logicalAddress)
- {
- return m_libCec->StandbyDevices((cec_logical_address) logicalAddress);
- }
-
- bool PollDevice(CecLogicalAddress logicalAddress)
- {
- return m_libCec->PollDevice((cec_logical_address) logicalAddress);
- }
-
- bool SetActiveSource(CecDeviceType type)
- {
- return m_libCec->SetActiveSource((cec_device_type) type);
- }
-
- bool SetDeckControlMode(CecDeckControlMode mode, bool sendUpdate)
- {
- return m_libCec->SetDeckControlMode((cec_deck_control_mode) mode, sendUpdate);
- }
-
- bool SetDeckInfo(CecDeckInfo info, bool sendUpdate)
- {
- return m_libCec->SetDeckInfo((cec_deck_info) info, sendUpdate);
- }
-
- bool SetInactiveView(void)
- {
- return m_libCec->SetInactiveView();
- }
-
- bool SetMenuState(CecMenuState state, bool sendUpdate)
- {
- return m_libCec->SetMenuState((cec_menu_state) state, sendUpdate);
- }
-
- bool SetOSDString(CecLogicalAddress logicalAddress, CecDisplayControl duration, String ^ message)
- {
- marshal_context ^ context = gcnew marshal_context();
- const char* strMessageC = context->marshal_as<const char*>(message);
-
- bool bReturn = m_libCec->SetOSDString((cec_logical_address) logicalAddress, (cec_display_control) duration, strMessageC);
-
- delete context;
- return bReturn;
- }
-
- bool SwitchMonitoring(bool enable)
- {
- return m_libCec->SwitchMonitoring(enable);
- }
-
- CecVersion GetDeviceCecVersion(CecLogicalAddress logicalAddress)
- {
- return (CecVersion) m_libCec->GetDeviceCecVersion((cec_logical_address) logicalAddress);
- }
-
- String ^ GetDeviceMenuLanguage(CecLogicalAddress logicalAddress)
- {
- cec_menu_language lang;
- if (m_libCec->GetDeviceMenuLanguage((cec_logical_address) logicalAddress, &lang))
- {
- return gcnew String(lang.language);
- }
-
- return gcnew String("");
- }
-
- CecVendorId GetDeviceVendorId(CecLogicalAddress logicalAddress)
- {
- return (CecVendorId)m_libCec->GetDeviceVendorId((cec_logical_address) logicalAddress);
- }
-
- CecPowerStatus GetDevicePowerStatus(CecLogicalAddress logicalAddress)
- {
- return (CecPowerStatus) m_libCec->GetDevicePowerStatus((cec_logical_address) logicalAddress);
- }
-
- void RescanActiveDevices(void)
- {
- m_libCec->RescanActiveDevices();
- }
-
- CecLogicalAddresses ^ GetActiveDevices(void)
- {
- CecLogicalAddresses ^ retVal = gcnew CecLogicalAddresses();
- unsigned int iDevices = 0;
-
- cec_logical_addresses activeDevices = m_libCec->GetActiveDevices();
-
- for (uint8_t iPtr = 0; iPtr < 16; iPtr++)
- if (activeDevices[iPtr])
- retVal->Addresses[iDevices++] = (CecLogicalAddress)iPtr;
-
- return retVal;
- }
-
- bool IsActiveDevice(CecLogicalAddress logicalAddress)
- {
- return m_libCec->IsActiveDevice((cec_logical_address)logicalAddress);
- }
-
- bool IsActiveDeviceType(CecDeviceType type)
- {
- return m_libCec->IsActiveDeviceType((cec_device_type)type);
- }
-
- bool SetHDMIPort(CecLogicalAddress address, uint8_t port)
- {
- return m_libCec->SetHDMIPort((cec_logical_address)address, port);
- }
-
- uint8_t VolumeUp(bool wait)
- {
- return m_libCec->VolumeUp(wait);
- }
-
- uint8_t VolumeDown(bool wait)
- {
- return m_libCec->VolumeDown(wait);
- }
-
- uint8_t MuteAudio(bool wait)
- {
- return m_libCec->MuteAudio(wait);
- }
-
- bool SendKeypress(CecLogicalAddress destination, CecUserControlCode key, bool wait)
- {
- return m_libCec->SendKeypress((cec_logical_address)destination, (cec_user_control_code)key, wait);
- }
-
- bool SendKeyRelease(CecLogicalAddress destination, bool wait)
- {
- return m_libCec->SendKeyRelease((cec_logical_address)destination, wait);
- }
-
- String ^ GetDeviceOSDName(CecLogicalAddress logicalAddress)
- {
- cec_osd_name osd = m_libCec->GetDeviceOSDName((cec_logical_address) logicalAddress);
- return gcnew String(osd.name);
- }
-
- CecLogicalAddress GetActiveSource()
- {
- return (CecLogicalAddress)m_libCec->GetActiveSource();
- }
-
- bool IsActiveSource(CecLogicalAddress logicalAddress)
- {
- return m_libCec->IsActiveSource((cec_logical_address)logicalAddress);
- }
-
- uint16_t GetDevicePhysicalAddress(CecLogicalAddress iAddress)
- {
- return m_libCec->GetDevicePhysicalAddress((cec_logical_address)iAddress);
- }
-
- bool SetStreamPath(CecLogicalAddress iAddress)
- {
- return m_libCec->SetStreamPath((cec_logical_address)iAddress);
- }
-
- bool SetStreamPath(uint16_t iPhysicalAddress)
- {
- return m_libCec->SetStreamPath(iPhysicalAddress);
- }
-
- CecLogicalAddresses ^GetLogicalAddresses(void)
- {
- CecLogicalAddresses ^addr = gcnew CecLogicalAddresses();
- cec_logical_addresses libAddr = m_libCec->GetLogicalAddresses();
- for (unsigned int iPtr = 0; iPtr < 16; iPtr++)
- addr->Addresses[iPtr] = (CecLogicalAddress)libAddr.addresses[iPtr];
- addr->Primary = (CecLogicalAddress)libAddr.primary;
- return addr;
- }
-
- bool GetCurrentConfiguration(LibCECConfiguration ^configuration)
- {
- libcec_configuration config;
- config.Clear();
-
- if (m_libCec->GetCurrentConfiguration(&config))
- {
- configuration->Update(config);
- return true;
- }
- return false;
- }
+ marshal_context ^ context = gcnew marshal_context();
+ const char* strPortC = context->marshal_as<const char*>(strPort);
+ bool bReturn = m_libCec->Open(strPortC, iTimeoutMs);
+ delete context;
+ return bReturn;
+ }
+
+ /// <summary>
+ /// Close the connection to the CEC adapter
+ /// </summary>
+ void Close(void)
+ {
+ DisableCallbacks();
+ m_libCec->Close();
+ }
+
+ /// <summary>
+ /// Disable all calls to callback methods.
+ /// </summary>
+ virtual void DisableCallbacks(void) override
+ {
+ // delete the callbacks, since these might already have been destroyed in .NET
+ CecCallbackMethods::DisableCallbacks();
+ if (m_libCec)
+ m_libCec->EnableCallbacks(NULL, NULL);
+ }
+
+ /// <summary>
+ /// Enable or change the callback methods that libCEC uses to send changes to the client application.
+ /// </summary>
+ /// <param name="callbacks">The new callback methods to use.</param>
+ /// <returns>True when the callbacks were changed, false otherwise</returns>
+ virtual bool EnableCallbacks(CecCallbackMethods ^ callbacks) override
+ {
+ if (m_libCec && CecCallbackMethods::EnableCallbacks(callbacks))
+ return m_libCec->EnableCallbacks((void*)GetCallbackPtr(), &g_cecCallbacks);
+
+ return false;
+ }
+
+ /// <summary>
+ /// Sends a ping command to the adapter, to check if it's responding.
+ /// </summary>
+ /// <returns>True when the ping was succesful, false otherwise</returns>
+ bool PingAdapter(void)
+ {
+ return m_libCec->PingAdapter();
+ }
+
+ /// <summary>
+ /// Start the bootloader of the CEC adapter. Closes the connection when successful.
+ /// </summary>
+ /// <returns>True when the command was sent successfully, false otherwise.</returns>
+ bool StartBootloader(void)
+ {
+ return m_libCec->StartBootloader();
+ }
+
+ /// <summary>
+ /// Transmit a raw CEC command over the CEC line.
+ /// </summary>
+ /// <param name="command">The command to transmit</param>
+ /// <returns>True when the data was sent and acked, false otherwise.</returns>
+ bool Transmit(CecCommand ^ command)
+ {
+ cec_command ccommand;
+ cec_command::Format(ccommand, (cec_logical_address)command->Initiator, (cec_logical_address)command->Destination, (cec_opcode)command->Opcode);
+ ccommand.transmit_timeout = command->TransmitTimeout;
+ ccommand.eom = command->Eom;
+ ccommand.ack = command->Ack;
+ for (unsigned int iPtr = 0; iPtr < command->Parameters->Size; iPtr++)
+ ccommand.parameters.PushBack(command->Parameters->Data[iPtr]);
+
+ return m_libCec->Transmit(ccommand);
+ }
+
+ /// <summary>
+ /// 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.
+ /// </summary>
+ /// <param name="logicalAddress">The CEC adapter's new logical address.</param>
+ /// <returns>True when the logical address was set successfully, false otherwise.</returns>
+ bool SetLogicalAddress(CecLogicalAddress logicalAddress)
+ {
+ return m_libCec->SetLogicalAddress((cec_logical_address) logicalAddress);
+ }
+
+ /// <summary>
+ /// 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.
+ /// </summary>
+ /// <param name="physicalAddress">The CEC adapter's new physical address.</param>
+ /// <returns>True when the physical address was set successfully, false otherwise.</returns>
+ bool SetPhysicalAddress(uint16_t physicalAddress)
+ {
+ return m_libCec->SetPhysicalAddress(physicalAddress);
+ }
+
+ /// <summary>
+ /// Power on the given CEC capable devices. If CECDEVICE_BROADCAST is used, then wakeDevice in libcec_configuration will be used.
+ /// </summary>
+ /// <param name="logicalAddress">The logical address to power on.</param>
+ /// <returns>True when the command was sent succesfully, false otherwise.</returns>
+ bool PowerOnDevices(CecLogicalAddress logicalAddress)
+ {
+ return m_libCec->PowerOnDevices((cec_logical_address) logicalAddress);
+ }
+
+ /// <summary>
+ /// Put the given CEC capable devices in standby mode. If CECDEVICE_BROADCAST is used, then standbyDevices in libcec_configuration will be used.
+ /// </summary>
+ /// <param name="logicalAddress">The logical address of the device to put in standby.</param>
+ /// <returns>True when the command was sent succesfully, false otherwise.</returns>
+ bool StandbyDevices(CecLogicalAddress logicalAddress)
+ {
+ return m_libCec->StandbyDevices((cec_logical_address) logicalAddress);
+ }
+
+ /// <summary>
+ /// Sends a POLL message to a device, to check if it's present and responding.
+ /// </summary>
+ /// <param name="logicalAddress">The device to send the message to.</param>
+ /// <returns>True if the POLL was acked, false otherwise.</returns>
+ bool PollDevice(CecLogicalAddress logicalAddress)
+ {
+ return m_libCec->PollDevice((cec_logical_address) logicalAddress);
+ }
+
+ /// <summary>
+ /// 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.
+ /// </summary>
+ /// <param name="type">The new active source. Use CEC_DEVICE_TYPE_RESERVED to use the primary type</param>
+ /// <returns>True when the command was sent succesfully, false otherwise.</returns>
+ bool SetActiveSource(CecDeviceType type)
+ {
+ return m_libCec->SetActiveSource((cec_device_type) type);
+ }
+
+ /// <summary>
+ /// Change the deck control mode, if this adapter is registered as playback or recording device.
+ /// </summary>
+ /// <param name="mode">The new control mode.</param>
+ /// <param name="sendUpdate">True to send the new status over the CEC line.</param>
+ /// <returns>True if set, false otherwise.</returns>
+ bool SetDeckControlMode(CecDeckControlMode mode, bool sendUpdate)
+ {
+ return m_libCec->SetDeckControlMode((cec_deck_control_mode) mode, sendUpdate);
+ }
+
+ /// <summary>
+ /// Change the deck info, if this adapter is a playback or recording device.
+ /// </summary>
+ /// <param name="info">The new deck info.</param>
+ /// <param name="sendUpdate">True to send the new status over the CEC line.</param>
+ /// <returns>True if set, false otherwise.</returns>
+ bool SetDeckInfo(CecDeckInfo info, bool sendUpdate)
+ {
+ return m_libCec->SetDeckInfo((cec_deck_info) info, sendUpdate);
+ }
+
+ /// <summary>
+ /// Broadcast a message that notifies connected CEC capable devices that this device is no longer the active source.
+ /// </summary>
+ /// <returns>True when the command was sent succesfully, false otherwise.</returns>
+ bool SetInactiveView(void)
+ {
+ return m_libCec->SetInactiveView();
+ }
+
+ /// <summary>
+ /// Change the menu state. This value is already changed by libCEC automatically if a device is (de)activated.
+ /// </summary>
+ /// <param name="state">The new state.</param>
+ /// <param name="sendUpdate">True to send the new status over the CEC line.</param>
+ /// <returns>True if set, false otherwise.</returns>
+ bool SetMenuState(CecMenuState state, bool sendUpdate)
+ {
+ return m_libCec->SetMenuState((cec_menu_state) state, sendUpdate);
+ }
+
+ /// <summary>
+ /// Display a message on the device with the given logical address. Not supported by most TVs.
+ /// </summary>
+ /// <param name="logicalAddress">The logical address of the device to display the message on.</param>
+ /// <param name="duration">The duration of the message</param>
+ /// <param name="message">The message to display.</param>
+ /// <returns>True when the command was sent, false otherwise.</returns>
+ bool SetOSDString(CecLogicalAddress logicalAddress, CecDisplayControl duration, String ^ message)
+ {
+ marshal_context ^ context = gcnew marshal_context();
+ const char* strMessageC = context->marshal_as<const char*>(message);
+
+ bool bReturn = m_libCec->SetOSDString((cec_logical_address) logicalAddress, (cec_display_control) duration, strMessageC);
+
+ delete context;
+ return bReturn;
+ }
+
+ /// <summary>
+ /// 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.
+ /// </summary>
+ /// <param name="enable">True to enable, false to disable.</param>
+ /// <returns>True when switched successfully, false otherwise.</returns>
+ bool SwitchMonitoring(bool enable)
+ {
+ return m_libCec->SwitchMonitoring(enable);
+ }
+
+ /// <summary>
+ /// Get the CEC version of the device with the given logical address
+ /// </summary>
+ /// <param name="logicalAddress">The logical address of the device to get the CEC version for.</param>
+ /// <returns>The version or CEC_VERSION_UNKNOWN when the version couldn't be fetched.</returns>
+ CecVersion GetDeviceCecVersion(CecLogicalAddress logicalAddress)
+ {
+ return (CecVersion) m_libCec->GetDeviceCecVersion((cec_logical_address) logicalAddress);
+ }
+
+ /// <summary>
+ /// Get the menu language of the device with the given logical address
+ /// </summary>
+ /// <param name="logicalAddress">The logical address of the device to get the menu language for.</param>
+ /// <returns>The requested menu language.</returns>
+ String ^ GetDeviceMenuLanguage(CecLogicalAddress logicalAddress)
+ {
+ cec_menu_language lang;
+ if (m_libCec->GetDeviceMenuLanguage((cec_logical_address) logicalAddress, &lang))
+ {
+ return gcnew String(lang.language);
+ }
+
+ return gcnew String("");
+ }
+
+ /// <summary>
+ /// Get the vendor ID of the device with the given logical address.
+ /// </summary>
+ /// <param name="logicalAddress">The logical address of the device to get the vendor ID for.</param>
+ /// <returns>The vendor ID or 0 if it wasn't found.</returns>
+ CecVendorId GetDeviceVendorId(CecLogicalAddress logicalAddress)
+ {
+ return (CecVendorId)m_libCec->GetDeviceVendorId((cec_logical_address) logicalAddress);
+ }
+
+ /// <summary>
+ /// Get the power status of the device with the given logical address.
+ /// </summary>
+ /// <param name="logicalAddress">The logical address of the device to get the power status for.</param>
+ /// <returns>The power status or CEC_POWER_STATUS_UNKNOWN if it wasn't found.</returns>
+ CecPowerStatus GetDevicePowerStatus(CecLogicalAddress logicalAddress)
+ {
+ return (CecPowerStatus) m_libCec->GetDevicePowerStatus((cec_logical_address) logicalAddress);
+ }
+
+ /// <summary>
+ /// Tell libCEC to poll for active devices on the bus.
+ /// </summary>
+ void RescanActiveDevices(void)
+ {
+ m_libCec->RescanActiveDevices();
+ }
+
+ /// <summary>
+ /// Get the logical addresses of the devices that are active on the bus, including those handled by libCEC.
+ /// </summary>
+ /// <returns>The logical addresses of the active devices</returns>
+ CecLogicalAddresses ^ GetActiveDevices(void)
+ {
+ CecLogicalAddresses ^ retVal = gcnew CecLogicalAddresses();
+ unsigned int iDevices = 0;
+
+ cec_logical_addresses activeDevices = m_libCec->GetActiveDevices();
+
+ for (uint8_t iPtr = 0; iPtr < 16; iPtr++)
+ if (activeDevices[iPtr])
+ retVal->Set((CecLogicalAddress)iPtr);
+
+ return retVal;
+ }
+
+ /// <summary>
+ /// Check whether a device is active on the bus.
+ /// </summary>
+ /// <param name="logicalAddress">The address to check.</param>
+ /// <returns>True when active, false otherwise.</returns>
+ bool IsActiveDevice(CecLogicalAddress logicalAddress)
+ {
+ return m_libCec->IsActiveDevice((cec_logical_address)logicalAddress);
+ }
+
+ /// <summary>
+ /// Check whether a device of the given type is active on the bus.
+ /// </summary>
+ /// <param name="type">The type to check.</param>
+ /// <returns>True when active, false otherwise.</returns>
+ bool IsActiveDeviceType(CecDeviceType type)
+ {
+ return m_libCec->IsActiveDeviceType((cec_device_type)type);
+ }
+
+ /// <summary>
+ /// Changes the active HDMI port.
+ /// </summary>
+ /// <param name="address">The device to which this libCEC is connected.</param>
+ /// <param name="port">The new port number.</param>
+ /// <returns>True when changed, false otherwise.</returns>
+ bool SetHDMIPort(CecLogicalAddress address, uint8_t port)
+ {
+ return m_libCec->SetHDMIPort((cec_logical_address)address, port);
+ }
+
+ /// <summary>
+ /// Sends a volume up keypress to an audiosystem if it's present.
+ /// </summary>
+ /// <param name="sendRelease">Send a key release after the keypress.</param>
+ /// <returns>The new audio status.</returns>
+ uint8_t VolumeUp(bool sendRelease)
+ {
+ return m_libCec->VolumeUp(sendRelease);
+ }
+
+ /// <summary>
+ /// Sends a volume down keypress to an audiosystem if it's present.
+ /// </summary>
+ /// <param name="sendRelease">Send a key release after the keypress.</param>
+ /// <returns>The new audio status.</returns>
+ uint8_t VolumeDown(bool sendRelease)
+ {
+ return m_libCec->VolumeDown(sendRelease);
+ }