#endif
} cec_logical_addresses;
-typedef int (CEC_CDECL* CBCecLogMessageType)(void *param, const CEC::cec_log_message &);
+struct libcec_configuration;
+
+typedef int (CEC_CDECL* CBCecLogMessageType)(void *param, const cec_log_message &);
typedef int (CEC_CDECL* CBCecKeyPressType)(void *param, const cec_keypress &);
typedef int (CEC_CDECL* CBCecCommandType)(void *param, const cec_command &);
+typedef int (CEC_CDECL* CBCecConfigurationChangedType)(void *param, const libcec_configuration &);
typedef struct ICECCallbacks
{
* @return 1 when ok, 0 otherwise.
*/
CBCecCommandType CBCecCommand;
+
+ /*!
+ * @brief Transfer a changed configuration from libCEC to the client
+ * @param configuration The configuration to transfer
+ * @return 1 when ok, 0 otherwise
+ */
+ CBCecConfigurationChangedType CBCecConfigurationChanged;
} ICECCallbacks;
typedef enum cec_client_version
public enum class CecClientVersion
{
VersionPre1_5 = 0,
- Version1_5_0 = 1
+ Version1_5_0 = 0x1500
};
public ref class CecAdapter
property int64_t Time;
};
+ ref class CecCallbackMethods; //forward
+ public ref class LibCECConfiguration
+ {
+ public:
+ LibCECConfiguration(void)
+ {
+ DeviceName = "";
+ DeviceTypes = gcnew CecDeviceTypeList();
+ PhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS;
+ BaseDevice = (CecLogicalAddress)CEC_DEFAULT_BASE_DEVICE;
+ HDMIPort = CEC_DEFAULT_HDMI_PORT;
+ ClientVersion = CecClientVersion::VersionPre1_5;
+
+ GetSettingsFromROM = false;
+ UseTVMenuLanguage = CEC_DEFAULT_SETTING_USE_TV_MENU_LANGUAGE == 1;
+ PowerOnStartup = CEC_DEFAULT_SETTING_POWER_ON_STARTUP == 1;
+ PowerOffShutdown = CEC_DEFAULT_SETTING_POWER_OFF_SHUTDOWN == 1;
+ PowerOffScreensaver = CEC_DEFAULT_SETTING_POWER_OFF_SCREENSAVER == 1;
+ PowerOffOnStandby = CEC_DEFAULT_SETTING_POWER_OFF_ON_STANDBY == 1;
+ }
+
+ void SetCallbacks(CecCallbackMethods ^callbacks)
+ {
+ Callbacks = callbacks;
+ }
+
+ property System::String ^ DeviceName;
+ property CecDeviceTypeList ^ DeviceTypes;
+ property uint16_t PhysicalAddress;
+ property CecLogicalAddress BaseDevice;
+ property uint8_t HDMIPort;
+ property CecClientVersion ClientVersion;
+
+ // player specific settings
+ property bool GetSettingsFromROM;
+ property bool UseTVMenuLanguage;
+ property bool PowerOnStartup;
+ property bool PowerOffShutdown;
+ property bool PowerOffScreensaver;
+ property bool PowerOffOnStandby;
+
+ property CecCallbackMethods ^Callbacks;
+ };
+
// the callback methods are called by unmanaged code, so we need some delegates for this
#pragma unmanaged
// unmanaged callback methods
typedef int (__stdcall *LOGCB) (const CEC::cec_log_message &message);
typedef int (__stdcall *KEYCB) (const CEC::cec_keypress &key);
typedef int (__stdcall *COMMANDCB)(const CEC::cec_command &command);
+ typedef int (__stdcall *CONFIGCB) (const CEC::libcec_configuration &config);
static LOGCB g_logCB;
static KEYCB g_keyCB;
static COMMANDCB g_commandCB;
+ static CONFIGCB g_configCB;
static CEC::ICECCallbacks g_cecCallbacks;
int CecLogMessageCB(void *cbParam, const CEC::cec_log_message &message)
return 0;
}
+ int CecConfigCB(void *cbParam, const CEC::libcec_configuration &config)
+ {
+ if (g_configCB)
+ return g_configCB(config);
+ return 0;
+ }
+
#pragma managed
// delegates for the unmanaged callback methods
public delegate int CecLogMessageManagedDelegate(const CEC::cec_log_message &);
public delegate int CecKeyPressManagedDelegate(const CEC::cec_keypress &);
public delegate int CecCommandManagedDelegate(const CEC::cec_command &);
+ public delegate int CecConfigManagedDelegate(const CEC::libcec_configuration &);
// callback method interface
public ref class CecCallbackMethods
g_commandCB = static_cast<COMMANDCB>(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_commandDelegate).ToPointer());
g_cecCallbacks.CBCecCommand = CecCommandCB;
+ // create the delegate method for the configuration change callback
+ m_configDelegate = gcnew CecConfigManagedDelegate(this, &CecCallbackMethods::CecConfigManaged);
+ m_configGCHandle = System::Runtime::InteropServices::GCHandle::Alloc(m_configDelegate);
+ g_configCB = static_cast<CONFIGCB>(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_configDelegate).ToPointer());
+ g_cecCallbacks.CBCecConfigurationChanged = CecConfigCB;
+
delete context;
}
return 0;
}
+ virtual int ConfigurationChanged(LibCECConfiguration ^ config)
+ {
+ return 0;
+ }
protected:
// managed callback methods
int CecLogMessageManaged(const CEC::cec_log_message &message)
return iReturn;
}
+ int CecConfigManaged(const CEC::libcec_configuration &config)
+ {
+ int iReturn(0);
+ if (m_bHasCallbacks)
+ {
+ LibCECConfiguration ^netConfig = gcnew LibCECConfiguration();
+ netConfig->DeviceName = gcnew System::String(config.strDeviceName);
+ for (unsigned int iPtr = 0; iPtr < 5; iPtr++)
+ netConfig->DeviceTypes->Types[iPtr] = (CecDeviceType)config.deviceTypes.types[iPtr];
+
+ netConfig->PhysicalAddress = config.iPhysicalAddress;
+ netConfig->BaseDevice = (CecLogicalAddress)config.baseDevice;
+ netConfig->HDMIPort = config.iHDMIPort;
+ netConfig->ClientVersion = (CecClientVersion)config.clientVersion;
+ netConfig->GetSettingsFromROM = config.bGetSettingsFromROM == 1;
+ netConfig->PowerOnStartup = config.bPowerOnStartup == 1;
+ netConfig->PowerOffShutdown = config.bPowerOffShutdown == 1;
+ netConfig->PowerOffScreensaver = config.bPowerOffScreensaver == 1;
+ netConfig->PowerOffOnStandby = config.bPowerOffOnStandby == 1;
+
+ iReturn = m_callbacks->ConfigurationChanged(netConfig);
+ }
+ return iReturn;
+ }
+
void DestroyDelegates()
{
if (m_bHasCallbacks)
static System::Runtime::InteropServices::GCHandle m_commandGCHandle;
COMMANDCB m_commandCallback;
+ CecConfigManagedDelegate ^ m_configDelegate;
+ static System::Runtime::InteropServices::GCHandle m_configGCHandle;
+ CONFIGCB m_configCallback;
+
CecCallbackMethods ^ m_callbacks;
bool m_bHasCallbacks;
};
-
- public ref class LibCECConfiguration
- {
- public:
- LibCECConfiguration(void)
- {
- DeviceName = "";
- DeviceTypes = gcnew CecDeviceTypeList();
- PhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS;
- BaseDevice = (CecLogicalAddress)CEC_DEFAULT_BASE_DEVICE;
- HDMIPort = CEC_DEFAULT_HDMI_PORT;
- ClientVersion = CecClientVersion::VersionPre1_5;
-
- GetSettingsFromROM = false;
- UseTVMenuLanguage = CEC_DEFAULT_SETTING_USE_TV_MENU_LANGUAGE == 1;
- PowerOnStartup = CEC_DEFAULT_SETTING_POWER_ON_STARTUP == 1;
- PowerOffShutdown = CEC_DEFAULT_SETTING_POWER_OFF_SHUTDOWN == 1;
- PowerOffScreensaver = CEC_DEFAULT_SETTING_POWER_OFF_SCREENSAVER == 1;
- PowerOffOnStandby = CEC_DEFAULT_SETTING_POWER_OFF_ON_STANDBY == 1;
- }
-
- void SetCallbacks(CecCallbackMethods ^callbacks)
- {
- Callbacks = callbacks;
- }
-
- property System::String ^ DeviceName;
- property CecDeviceTypeList ^ DeviceTypes;
- property uint16_t PhysicalAddress;
- property CecLogicalAddress BaseDevice;
- property uint8_t HDMIPort;
- property CecClientVersion ClientVersion;
-
- // player specific settings
- property bool GetSettingsFromROM;
- property bool UseTVMenuLanguage;
- property bool PowerOnStartup;
- property bool PowerOffShutdown;
- property bool PowerOffScreensaver;
- property bool PowerOffOnStandby;
-
- property CecCallbackMethods ^Callbacks;
- };
}
public:
LibCecSharp(LibCECConfiguration ^config)
{
- m_configuration = config;
- CecCallbackMethods::EnableCallbacks(m_configuration->Callbacks);
- if (!InitialiseLibCec())
+ CecCallbackMethods::EnableCallbacks(config->Callbacks);
+ if (!InitialiseLibCec(config))
throw gcnew Exception("Could not initialise LibCecSharp");
}
LibCecSharp(String ^ strDeviceName, CecDeviceTypeList ^ deviceTypes)
{
- m_configuration = gcnew LibCECConfiguration();
- m_configuration->SetCallbacks(this);
- m_configuration->DeviceName = strDeviceName;
- m_configuration->DeviceTypes = deviceTypes;
- if (!InitialiseLibCec())
+ LibCECConfiguration ^config = gcnew LibCECConfiguration();
+ config->SetCallbacks(this);
+ config->DeviceName = strDeviceName;
+ config->DeviceTypes = deviceTypes;
+ if (!InitialiseLibCec(config))
throw gcnew Exception("Could not initialise LibCecSharp");
}
m_libCec = NULL;
}
- bool InitialiseLibCec(void)
+ bool InitialiseLibCec(LibCECConfiguration ^config)
{
marshal_context ^ context = gcnew marshal_context();
- libcec_configuration config;
- GetConfiguration(context, config);
+ libcec_configuration libCecConfig;
+ ConvertConfiguration(context, config, libCecConfig);
- m_libCec = (ICECAdapter *) CECInitialise(&config);
+ m_libCec = (ICECAdapter *) CECInitialise(&libCecConfig);
delete context;
return m_libCec != NULL;
}
- void GetConfiguration(marshal_context ^context, libcec_configuration &config)
+ void ConvertConfiguration(marshal_context ^context, LibCECConfiguration ^netConfig, CEC::libcec_configuration &config)
{
config.Clear();
- _snprintf_s(config.strDeviceName, 13, context->marshal_as<const char*>(m_configuration->DeviceName));
+ _snprintf_s(config.strDeviceName, 13, context->marshal_as<const char*>(netConfig->DeviceName));
for (unsigned int iPtr = 0; iPtr < 5; iPtr++)
- config.deviceTypes.types[iPtr] = (cec_device_type)m_configuration->DeviceTypes->Types[iPtr];
+ config.deviceTypes.types[iPtr] = (cec_device_type)netConfig->DeviceTypes->Types[iPtr];
- config.iPhysicalAddress = m_configuration->PhysicalAddress;
- config.baseDevice = (cec_logical_address)m_configuration->BaseDevice;
- config.iHDMIPort = m_configuration->HDMIPort;
- config.clientVersion = (cec_client_version)m_configuration->ClientVersion;
- config.bGetSettingsFromROM = m_configuration->GetSettingsFromROM;
- config.bPowerOnStartup = m_configuration->PowerOnStartup;
- config.bPowerOffShutdown = m_configuration->PowerOffShutdown;
- config.bPowerOffScreensaver = m_configuration->PowerOffScreensaver;
- config.bPowerOffOnStandby = m_configuration->PowerOffOnStandby;
- config.callbacks = &g_cecCallbacks;
+ 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;
+ config.bPowerOnStartup = netConfig->PowerOnStartup;
+ config.bPowerOffShutdown = netConfig->PowerOffShutdown;
+ config.bPowerOffScreensaver = netConfig->PowerOffScreensaver;
+ config.bPowerOffOnStandby = netConfig->PowerOffOnStandby;
+ config.callbacks = &g_cecCallbacks;
}
public:
configuration->PowerOnStartup = config.bPowerOnStartup == 1;
configuration->UseTVMenuLanguage = config.bUseTVMenuLanguage == 1;
for (unsigned int iPtr = 0; iPtr < 5; iPtr++)
- m_configuration->DeviceTypes->Types[iPtr] = (CecDeviceType)config.deviceTypes.types[iPtr];
+ configuration->DeviceTypes->Types[iPtr] = (CecDeviceType)config.deviceTypes.types[iPtr];
return true;
}
return false;
{
marshal_context ^ context = gcnew marshal_context();
libcec_configuration config;
- GetConfiguration(context, config);
+ ConvertConfiguration(context, configuration, config);
bool bReturn = m_libCec->PersistConfiguration(&config);
return bReturn;
}
+ bool SetConfiguration(LibCECConfiguration ^configuration)
+ {
+ marshal_context ^ context = gcnew marshal_context();
+ libcec_configuration config;
+ ConvertConfiguration(context, configuration, config);
+
+ bool bReturn = m_libCec->SetConfiguration(&config);
+
+ delete context;
+ return bReturn;
+ }
+
String ^ ToString(CecLogicalAddress iAddress)
{
const char *retVal = m_libCec->ToString((cec_logical_address)iAddress);
private:
ICECAdapter * m_libCec;
- LibCECConfiguration ^m_configuration;
};
}
CecAdapter[] adapters = Lib.FindAdapters(string.Empty);
if (adapters.Length == 0 || !Lib.Open(adapters[0].ComPort, 10000))
{
- MessageBox.Show("Could not connect to any CEC adapter. Please check your configuration.", "Pulse-Eight USB-CEC Adapter", MessageBoxButtons.OK);
+ MessageBox.Show("Could not connect to any CEC adapter. Please check your configuration and try again.", "Pulse-Eight USB-CEC Adapter", MessageBoxButtons.OK);
Application.Exit();
}
this.cecButtonConfigBindingSource.Add(new CecButtonConfigItem("(Samsung) Return", (new CecSharp.CecKeypress() { Keycode = 0x91 }), string.Empty));
}
- public int ReceiveCommand(CecCommand command)
+ public int ConfigurationChanged(LibCECConfiguration config)
{
- bool bGetNewPhysicalAddress = false;
- if (command.Opcode == CecOpcode.ReportPhysicalAddress)
- bGetNewPhysicalAddress = true;
+ SetControlText(this.tbPhysicalAddress, String.Format("{0,4:X}", config.PhysicalAddress));
+ return 1;
+ }
- if (bGetNewPhysicalAddress)
- {
- LibCECConfiguration config = new LibCECConfiguration();
- Lib.GetCurrentConfiguration(config);
- SetControlText(this.tbPhysicalAddress, String.Format("{0,4:X}", config.PhysicalAddress));
- }
+ public int ReceiveCommand(CecCommand command)
+ {
return 1;
}
return Gui.ReceiveLogMessage(message);
}
+ public override int ConfigurationChanged(LibCECConfiguration config)
+ {
+ return Gui.ConfigurationChanged(config);
+ }
+
private CecConfigGUI Gui;
}
}
g_callbacks.CBCecLogMessage = &CecLogMessage;
g_callbacks.CBCecKeyPress = &CecKeyPress;
g_callbacks.CBCecCommand = &CecCommand;
+ g_callbacks.CBCecConfigurationChanged = NULL;
adapter->EnableCallbacks(NULL, &g_callbacks);
}
WakeDevices();
SetInitialised(bReturn);
+ CLibCEC::ConfigurationChanged(m_configuration);
return bReturn;
}
if (bSendActiveView)
SetActiveView();
+ if (bReturn)
+ CLibCEC::ConfigurationChanged(m_configuration);
+
return bReturn;
}
return retVal;
}
-void CLibCEC::AddLog(cec_log_level level, const char *strFormat, ...)
+void CLibCEC::AddLog(const cec_log_level level, const char *strFormat, ...)
{
CStdString strLog;
instance->m_logBuffer.Push(message);
}
-void CLibCEC::AddKey(cec_keypress &key)
+void CLibCEC::AddKey(const cec_keypress &key)
{
CLibCEC *instance = CLibCEC::GetInstance();
CLockObject lock(instance->m_mutex);
instance->m_buttontime = key.duration > 0 ? 0 : GetTimeMs();
}
+void CLibCEC::ConfigurationChanged(const libcec_configuration &config)
+{
+ CLibCEC *instance = CLibCEC::GetInstance();
+ CLockObject lock(instance->m_mutex);
+
+ if (instance->m_callbacks &&
+ config.clientVersion >= CEC_CLIENT_VERSION_1_5_0 &&
+ instance->m_callbacks->CBCecConfigurationChanged != NULL)
+ instance->m_callbacks->CBCecConfigurationChanged(instance->m_cbParam, config);
+}
+
void CLibCEC::SetCurrentButton(cec_user_control_code iButtonCode)
{
/* push keypress to the keybuffer with 0 duration.
const char *ToString(const cec_client_version version);
//@}
- static void AddLog(cec_log_level level, const char *strFormat, ...);
+ static void AddLog(const cec_log_level level, const char *strFormat, ...);
static void AddKey(void);
- static void AddKey(cec_keypress &key);
+ static void AddKey(const cec_keypress &key);
static void AddCommand(const cec_command &command);
+ static void ConfigurationChanged(const libcec_configuration &config);
static void SetCurrentButton(cec_user_control_code iButtonCode);
virtual void CheckKeypressTimeout(void);
g_callbacks.CBCecLogMessage = &CecLogMessage;
g_callbacks.CBCecKeyPress = &CecKeyPress;
g_callbacks.CBCecCommand = &CecCommand;
+ g_callbacks.CBCecConfigurationChanged = NULL;
adapter->EnableCallbacks(NULL, &g_callbacks);
}