From: Lars Op den Kamp Date: Thu, 16 Feb 2012 13:11:09 +0000 (+0100) Subject: cec: added RescanDevices()/cec_rescan_devices() to the interface, to let libCEC force... X-Git-Tag: upstream/2.2.0~1^2~35^2~23 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=3efda01ac7b070e09012a5725112eb44c17001b4;p=deb_libcec.git cec: added RescanDevices()/cec_rescan_devices() to the interface, to let libCEC force polls to all logical addresses. deprecated GetLibVersion() methods, and added the server version to libcec_configuration. added missing libcec_configuration conversions in LibCecSharp. --- diff --git a/include/cec.h b/include/cec.h index cbc8346..b159117 100644 --- a/include/cec.h +++ b/include/cec.h @@ -88,42 +88,6 @@ namespace CEC virtual bool StartBootloader(void) = 0; //@} - /*! - * @return Get the minimal version of libcec that this version of libcec can interface with. - */ - virtual int8_t GetMinLibVersion(void) const = 0; - - /*! - * @return Get the major version of libcec. - */ - virtual int8_t GetLibVersionMajor(void) const = 0; - - /*! - * @return Get the minor version of libcec. - */ - virtual int8_t GetLibVersionMinor(void) const = 0; - - /*! - * @brief Get the next log message in the queue, if there is one. - * @param message The next message. - * @return True if a message was passed, false otherwise. - */ - virtual bool GetNextLogMessage(cec_log_message *message) = 0; - - /*! - * @brief Get the next keypress in the queue, if there is one. - * @param key The next keypress. - * @return True if a key was passed, false otherwise. - */ - virtual bool GetNextKeypress(cec_keypress *key) = 0; - - /*! - * @brief Get the next CEC command that was received by the adapter. - * @param action The next command. - * @return True when a command was passed, false otherwise. - */ - virtual bool GetNextCommand(cec_command *command) = 0; - /*! * @brief Transmit a command over the CEC line. * @param data The command to send. @@ -145,13 +109,6 @@ namespace CEC */ virtual bool SetPhysicalAddress(uint16_t iPhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS) = 0; - /*! - * @deprecated Use libcec_configuration instead. - * @brief Enable physical address detection (if the connected adapter supports this). - * @return True when physical address detection was enabled, false otherwise. - */ - virtual bool EnablePhysicalAddressDetection(void) = 0; - /*! * @brief Changes the active HDMI port. * @param iBaseDevice The device to which this libcec is connected. @@ -181,11 +138,6 @@ namespace CEC */ virtual bool SetActiveSource(cec_device_type type = CEC_DEVICE_TYPE_RESERVED) = 0; - /*! - * @deprecated Use SetActiveSource() instead - */ - virtual bool SetActiveView(void) = 0; - /*! * @brief Change the deck control mode, if this adapter is registered as playback device. * @param mode The new control mode. @@ -279,6 +231,11 @@ namespace CEC */ virtual cec_logical_addresses GetActiveDevices(void) = 0; + /*! + * @brief Tell libCEC to poll for active devices on the bus. + */ + virtual void RescanActiveDevices(void) = 0; + /*! * @brief Check whether a device is active on the bus. * @param iAddress The address to check. @@ -407,6 +364,64 @@ namespace CEC virtual const char *ToString(const cec_audio_status status) = 0; virtual const char *ToString(const cec_vendor_id vendor) = 0; virtual const char *ToString(const cec_client_version version) = 0; + virtual const char *ToString(const cec_server_version version) = 0; + + ////// deprecated methods, may be removed in a future version ////// + + /*! + * @deprecated Use libcec_configuration instead. + * @brief Enable physical address detection (if the connected adapter supports this). + * @return True when physical address detection was enabled, false otherwise. + */ + virtual bool EnablePhysicalAddressDetection(void) = 0; + + /*! + * @deprecated Use SetActiveSource() instead + */ + virtual bool SetActiveView(void) = 0; + + /*! + * @deprecated Use libcec_configuration instead + * @return Get the minimal version of libcec that this version of libcec can interface with. + */ + virtual int8_t GetMinLibVersion(void) const = 0; + + /*! + * @deprecated Use libcec_configuration instead + * @return Get the major version of libcec. + */ + virtual int8_t GetLibVersionMajor(void) const = 0; + + /*! + * @deprecated Use libcec_configuration instead + * @return Get the minor version of libcec. + */ + virtual int8_t GetLibVersionMinor(void) const = 0; + + /*! + * @deprecated Use callback methods instead + * @brief Get the next log message in the queue, if there is one. + * @param message The next message. + * @return True if a message was passed, false otherwise. + */ + virtual bool GetNextLogMessage(cec_log_message *message) = 0; + + /*! + * @deprecated Use callback methods instead + * @brief Get the next keypress in the queue, if there is one. + * @param key The next keypress. + * @return True if a key was passed, false otherwise. + */ + virtual bool GetNextKeypress(cec_keypress *key) = 0; + + /*! + * @deprecated Use callback methods instead + * @brief Get the next CEC command that was received by the adapter. + * @param action The next command. + * @return True when a command was passed, false otherwise. + */ + virtual bool GetNextCommand(cec_command *command) = 0; + }; }; @@ -424,7 +439,7 @@ extern "C" DECLSPEC void * CECInit(const char *strDeviceName, CEC::cec_device_ty * @param configuration The configuration to pass to libCEC * @return An instance of ICECAdapter or NULL on error. */ -extern "C" DECLSPEC void * CECInitialise(const CEC::libcec_configuration *configuration); +extern "C" DECLSPEC void * CECInitialise(CEC::libcec_configuration *configuration); /*! * @brief Unload the CEC adapter library. diff --git a/include/cecc.h b/include/cecc.h index 072678b..f2928ed 100644 --- a/include/cecc.h +++ b/include/cecc.h @@ -41,9 +41,9 @@ extern "C" { #endif #ifdef __cplusplus -extern DECLSPEC int cec_initialise(const CEC::libcec_configuration *configuration); +extern DECLSPEC int cec_initialise(CEC::libcec_configuration *configuration); #else -extern DECLSPEC int cec_initialise(const libcec_configuration *configuration); +extern DECLSPEC int cec_initialise(libcec_configuration *configuration); #endif #ifdef __cplusplus @@ -74,12 +74,6 @@ extern DECLSPEC int cec_ping_adapters(void); extern DECLSPEC int cec_start_bootloader(void); -extern DECLSPEC int8_t cec_get_min_lib_version(void); - -extern DECLSPEC int8_t cec_get_lib_version_major(void); - -extern DECLSPEC int8_t cec_get_lib_version_minor(void); - #ifdef __cplusplus extern DECLSPEC int cec_power_on_devices(CEC::cec_logical_address address); #else @@ -92,8 +86,6 @@ extern DECLSPEC int cec_standby_devices(CEC::cec_logical_address address); extern DECLSPEC int cec_standby_devices(cec_logical_address address); #endif -extern DECLSPEC int cec_set_active_view(void); - #ifdef __cplusplus extern DECLSPEC int cec_set_active_source(CEC::cec_device_type type); #else @@ -120,24 +112,6 @@ extern DECLSPEC int cec_set_menu_state(CEC::cec_menu_state state, int bSendUpdat extern DECLSPEC int cec_set_menu_state(cec_menu_state state, int bSendUpdate); #endif -#ifdef __cplusplus -extern DECLSPEC int cec_get_next_log_message(CEC::cec_log_message *message); -#else -extern DECLSPEC int cec_get_next_log_message(cec_log_message *message); -#endif - -#ifdef __cplusplus -extern DECLSPEC int cec_get_next_keypress(CEC::cec_keypress *key); -#else -extern DECLSPEC int cec_get_next_keypress(cec_keypress *key); -#endif - -#ifdef __cplusplus -extern DECLSPEC int cec_get_next_command(CEC::cec_command *command); -#else -extern DECLSPEC int cec_get_next_command(cec_command *command); -#endif - #ifdef __cplusplus extern DECLSPEC int cec_transmit(const CEC::cec_command *data); #else @@ -256,8 +230,6 @@ extern DECLSPEC CEC::cec_osd_name cec_get_device_osd_name(CEC::cec_logical_addre extern DECLSPEC cec_osd_name cec_get_device_osd_name(cec_logical_address iAddress); #endif -extern DECLSPEC int cec_enable_physical_address_detection(void); - #ifdef __cplusplus extern DECLSPEC int cec_set_stream_path_logical(CEC::cec_logical_address iAddress); #else @@ -292,6 +264,38 @@ extern DECLSPEC int cec_set_configuration(const CEC::libcec_configuration *confi extern DECLSPEC int cec_set_configuration(const libcec_configuration *configuration); #endif +extern DECLSPEC void cec_rescan_devices(void); + +////// deprecated methods, may be removed in a future version ////// + +extern DECLSPEC int cec_enable_physical_address_detection(void); + +extern DECLSPEC int cec_set_active_view(void); + +extern DECLSPEC int8_t cec_get_min_lib_version(void); + +extern DECLSPEC int8_t cec_get_lib_version_major(void); + +extern DECLSPEC int8_t cec_get_lib_version_minor(void); + +#ifdef __cplusplus +extern DECLSPEC int cec_get_next_log_message(CEC::cec_log_message *message); +#else +extern DECLSPEC int cec_get_next_log_message(cec_log_message *message); +#endif + +#ifdef __cplusplus +extern DECLSPEC int cec_get_next_keypress(CEC::cec_keypress *key); +#else +extern DECLSPEC int cec_get_next_keypress(cec_keypress *key); +#endif + +#ifdef __cplusplus +extern DECLSPEC int cec_get_next_command(CEC::cec_command *command); +#else +extern DECLSPEC int cec_get_next_command(cec_command *command); +#endif + #ifdef __cplusplus }; #endif diff --git a/include/cecloader.h b/include/cecloader.h index 1a75169..624f29a 100644 --- a/include/cecloader.h +++ b/include/cecloader.h @@ -72,7 +72,7 @@ CEC::ICECAdapter *LibCecInit(const char *strDeviceName, CEC::cec_device_type_lis * @param strLib The name of and/or path to libCEC * @return An instance of ICECAdapter or NULL on error. */ -CEC::ICECAdapter *LibCecInitialise(const CEC::libcec_configuration *configuration, const char *strLib = NULL) +CEC::ICECAdapter *LibCecInitialise(CEC::libcec_configuration *configuration, const char *strLib = NULL) { if (!g_libCEC) #if defined(_WIN64) @@ -83,7 +83,7 @@ CEC::ICECAdapter *LibCecInitialise(const CEC::libcec_configuration *configuratio if (!g_libCEC) return NULL; - typedef void* (__cdecl*_LibCecInitialise)(const CEC::libcec_configuration *); + typedef void* (__cdecl*_LibCecInitialise)(CEC::libcec_configuration *); _LibCecInitialise LibCecInitialise; LibCecInitialise = (_LibCecInitialise) (GetProcAddress(g_libCEC, "CECInitialise")); if (!LibCecInitialise) @@ -161,7 +161,7 @@ CEC::ICECAdapter *LibCecInit(const char *strDeviceName, CEC::cec_device_type_lis * @param strLib The name of and/or path to libCEC * @return An instance of ICECAdapter or NULL on error. */ -CEC::ICECAdapter *LibCecInitialise(const CEC::libcec_configuration *configuration, const char *strLib = NULL) +CEC::ICECAdapter *LibCecInitialise(CEC::libcec_configuration *configuration, const char *strLib = NULL) { if (!g_libCEC) { @@ -181,7 +181,7 @@ CEC::ICECAdapter *LibCecInitialise(const CEC::libcec_configuration *configuratio } } - typedef void* _LibCecInitialise(const CEC::libcec_configuration *); + typedef void* _LibCecInitialise(CEC::libcec_configuration *); _LibCecInitialise* LibCecInitialise = (_LibCecInitialise*) dlsym(g_libCEC, "CECInitialise"); if (!LibCecInitialise) { diff --git a/include/cectypes.h b/include/cectypes.h index ca02f09..960f6a0 100644 --- a/include/cectypes.h +++ b/include/cectypes.h @@ -86,7 +86,7 @@ namespace CEC { #define CEC_MIN_LIB_VERSION 1 #define CEC_LIB_VERSION_MAJOR 1 -#define CEC_LIB_VERSION_MINOR 4 +#define CEC_LIB_VERSION_MINOR 5 typedef enum cec_abort_reason { @@ -947,19 +947,27 @@ typedef enum cec_client_version CEC_CLIENT_VERSION_1_5_0 = 0x1500 } cec_client_version; +typedef enum cec_server_version +{ + CEC_SERVER_VERSION_PRE_1_5 = 0, + CEC_SERVER_VERSION_1_5_0 = 0x1500 +} cec_server_version; + typedef struct libcec_configuration { - cec_client_version clientVersion; /*!< the version of the client that is connecting */ + uint32_t clientVersion; /*!< the version of the client that is connecting */ char strDeviceName[13]; /*!< how to name the device on the CEC bus */ cec_device_type_list deviceTypes; /*!< the CEC device types to emulate */ uint8_t bAutodetectAddress; /*!< try to autodetect the physical address when 1 */ uint16_t iPhysicalAddress; /*!< the physical address of the CEC adapter. only used when bAutodetectAddress = 0 or when the adapter doesn't support autodetection */ cec_logical_address baseDevice; /*!< the logical address of the device to which the adapter is connected. only used when iPhysicalAddress = 0 and bAutodetectAddress = 0 or when the adapter doesn't support autodetection */ uint8_t iHDMIPort; /*!< the HDMI port to which the adapter is connected. only used when iPhysicalAddress = 0 and bAutodetectAddress = 0 or when the adapter doesn't support autodetection */ - cec_vendor_id tvVendor; /*!< override the vendor ID of the TV. leave this untouched to autodetect */ + uint64_t tvVendor; /*!< override the vendor ID of the TV. leave this untouched to autodetect */ cec_logical_addresses wakeDevices; /*!< wake these CEC devices when initialising libCEC or when calling PowerOnDevices() without any parameter */ cec_logical_addresses powerOffDevices; /*!< power off these devices when calling StandbyDevices() without any parameter */ + uint32_t serverVersion; /*!< the version number of the server. read-only */ + // player specific settings uint8_t bGetSettingsFromROM; /*!< true to get the settings from the ROM (if set, and a v2 ROM is present), false to use these settings. */ uint8_t bUseTVMenuLanguage; /*!< use the menu language of the TV in the player application */ @@ -978,8 +986,9 @@ typedef struct libcec_configuration iPhysicalAddress = 0; baseDevice = (cec_logical_address)CEC_DEFAULT_BASE_DEVICE; iHDMIPort = CEC_DEFAULT_HDMI_PORT; - tvVendor = CEC_VENDOR_UNKNOWN; - clientVersion = CEC_CLIENT_VERSION_PRE_1_5; + tvVendor = (uint64_t)CEC_VENDOR_UNKNOWN; + clientVersion = (uint32_t)CEC_CLIENT_VERSION_PRE_1_5; + serverVersion = (uint32_t)CEC_SERVER_VERSION_PRE_1_5; wakeDevices.Clear(); powerOffDevices.Clear(); diff --git a/src/CecSharpTester/CecSharpClient.cs b/src/CecSharpTester/CecSharpClient.cs index 061a992..006c83a 100644 --- a/src/CecSharpTester/CecSharpClient.cs +++ b/src/CecSharpTester/CecSharpClient.cs @@ -50,7 +50,7 @@ namespace CecSharpClient Lib = new LibCecSharp(Config); - Console.WriteLine("CEC Parser created - libcec version " + Lib.GetLibVersionMajor() + "." + Lib.GetLibVersionMinor()); + Console.WriteLine("CEC Parser created - libcec version " + Lib.ToString(Config.ServerVersion)); } public override int ReceiveCommand(CecCommand command) @@ -198,9 +198,6 @@ namespace CecSharpClient public void MainLoop() { - Lib.PowerOnDevices(CecLogicalAddress.Tv); - Lib.SetActiveSource(CecDeviceType.PlaybackDevice); - bool bContinue = true; string command; while (bContinue) diff --git a/src/LibCecSharp/CecSharpTypes.h b/src/LibCecSharp/CecSharpTypes.h index 135eecf..5d61794 100644 --- a/src/LibCecSharp/CecSharpTypes.h +++ b/src/LibCecSharp/CecSharpTypes.h @@ -329,6 +329,12 @@ namespace CecSharp Version1_5_0 = 0x1500 }; + public enum class CecServerVersion + { + VersionPre1_5 = 0, + Version1_5_0 = 0x1500 + }; + public ref class CecAdapter { public: @@ -524,6 +530,7 @@ namespace CecSharp BaseDevice = (CecLogicalAddress)CEC_DEFAULT_BASE_DEVICE; HDMIPort = CEC_DEFAULT_HDMI_PORT; ClientVersion = CecClientVersion::VersionPre1_5; + ServerVersion = CecServerVersion::VersionPre1_5; TvVendor = CecVendorId::Unknown; GetSettingsFromROM = false; @@ -547,6 +554,40 @@ namespace CecSharp Callbacks = callbacks; } + void Update(const CEC::libcec_configuration &config) + { + DeviceName = gcnew System::String(config.strDeviceName); + + for (unsigned int iPtr = 0; iPtr < 5; iPtr++) + DeviceTypes->Types[iPtr] = (CecDeviceType)config.deviceTypes.types[iPtr]; + + AutodetectAddress = config.bAutodetectAddress == 1; + PhysicalAddress = config.iPhysicalAddress; + BaseDevice = (CecLogicalAddress)config.baseDevice; + HDMIPort = config.iHDMIPort; + ClientVersion = (CecClientVersion)config.clientVersion; + ServerVersion = (CecServerVersion)config.serverVersion; + TvVendor = (CecVendorId)config.tvVendor; + + // player specific settings + GetSettingsFromROM = config.bGetSettingsFromROM == 1; + UseTVMenuLanguage = config.bUseTVMenuLanguage == 1; + ActivateSource = config.bActivateSource == 1; + + WakeDevices->Clear(); + for (uint8_t iPtr = 0; iPtr <= 16; iPtr++) + if (config.wakeDevices[iPtr]) + WakeDevices->Set((CecLogicalAddress)iPtr); + + PowerOffDevices->Clear(); + for (uint8_t iPtr = 0; iPtr <= 16; iPtr++) + if (config.powerOffDevices[iPtr]) + PowerOffDevices->Set((CecLogicalAddress)iPtr); + + PowerOffScreensaver = config.bPowerOffScreensaver == 1; + PowerOffOnStandby = config.bPowerOffOnStandby == 1; + } + property System::String ^ DeviceName; property CecDeviceTypeList ^ DeviceTypes; property bool AutodetectAddress; @@ -554,6 +595,7 @@ namespace CecSharp property CecLogicalAddress BaseDevice; property uint8_t HDMIPort; property CecClientVersion ClientVersion; + property CecServerVersion ServerVersion; property CecVendorId TvVendor; // player specific settings @@ -740,30 +782,7 @@ namespace CecSharp 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->ActivateSource = config.bActivateSource == 1; - - netConfig->WakeDevices->Clear(); - for (uint8_t iPtr = 0; iPtr <= 16; iPtr++) - if (config.wakeDevices[iPtr]) - netConfig->WakeDevices->Set((CecLogicalAddress)iPtr); - - netConfig->PowerOffDevices->Clear(); - for (uint8_t iPtr = 0; iPtr <= 16; iPtr++) - if (config.powerOffDevices[iPtr]) - netConfig->PowerOffDevices->Set((CecLogicalAddress)iPtr); - - netConfig->PowerOffScreensaver = config.bPowerOffScreensaver == 1; - netConfig->PowerOffOnStandby = config.bPowerOffOnStandby == 1; - + netConfig->Update(config); iReturn = m_callbacks->ConfigurationChanged(netConfig); } return iReturn; diff --git a/src/LibCecSharp/LibCecSharp.cpp b/src/LibCecSharp/LibCecSharp.cpp index 4bf39f0..014dea0 100644 --- a/src/LibCecSharp/LibCecSharp.cpp +++ b/src/LibCecSharp/LibCecSharp.cpp @@ -80,6 +80,8 @@ namespace CecSharp ConvertConfiguration(context, config, libCecConfig); m_libCec = (ICECAdapter *) CECInitialise(&libCecConfig); + config->Update(libCecConfig); + delete context; return m_libCec != NULL; @@ -334,6 +336,11 @@ namespace CecSharp return (CecPowerStatus) m_libCec->GetDevicePowerStatus((cec_logical_address) logicalAddress); } + void RescanActiveDevices(void) + { + m_libCec->RescanActiveDevices(); + } + CecLogicalAddresses ^ GetActiveDevices(void) { CecLogicalAddresses ^ retVal = gcnew CecLogicalAddresses(); @@ -436,29 +443,7 @@ namespace CecSharp if (m_libCec->GetCurrentConfiguration(&config)) { - configuration->AutodetectAddress = config.bAutodetectAddress == 1; - configuration->BaseDevice = (CecLogicalAddress)config.baseDevice; - configuration->DeviceName = gcnew String(config.strDeviceName); - configuration->HDMIPort = config.iHDMIPort; - configuration->PhysicalAddress = config.iPhysicalAddress; - configuration->PowerOffOnStandby = config.bPowerOffOnStandby == 1; - configuration->PowerOffScreensaver = config.bPowerOffScreensaver == 1; - configuration->ActivateSource = config.bActivateSource == 1; - configuration->TvVendor = (CecVendorId)config.tvVendor; - - configuration->WakeDevices->Clear(); - for (uint8_t iPtr = 0; iPtr <= 16; iPtr++) - if (config.wakeDevices[iPtr]) - configuration->WakeDevices->Set((CecLogicalAddress)iPtr); - - configuration->PowerOffDevices->Clear(); - for (uint8_t iPtr = 0; iPtr <= 16; iPtr++) - if (config.powerOffDevices[iPtr]) - configuration->PowerOffDevices->Set((CecLogicalAddress)iPtr); - - configuration->UseTVMenuLanguage = config.bUseTVMenuLanguage == 1; - for (unsigned int iPtr = 0; iPtr < 5; iPtr++) - configuration->DeviceTypes->Types[iPtr] = (CecDeviceType)config.deviceTypes.types[iPtr]; + configuration->Update(config); return true; } return false; @@ -553,6 +538,18 @@ namespace CecSharp 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); + } + private: ICECAdapter * m_libCec; }; diff --git a/src/cec-config-gui/CecConfigGUI.cs b/src/cec-config-gui/CecConfigGUI.cs index 4f84b2c..e3decec 100644 --- a/src/cec-config-gui/CecConfigGUI.cs +++ b/src/cec-config-gui/CecConfigGUI.cs @@ -884,7 +884,7 @@ namespace CecConfigGui if (!SuppressUpdates && ActiveProcess == null) { SetControlsEnabled(false); - ActiveProcess = new RescanDevices(); + ActiveProcess = new RescanDevices(ref Lib); ActiveProcess.EventHandler += new EventHandler(ProcessEventHandler); (new Thread(new ThreadStart(ActiveProcess.Run))).Start(); } @@ -1032,6 +1032,8 @@ namespace CecConfigGui SetCheckboxItemChecked(cbWakeDevices, iPtr, Config.WakeDevices.IsSet((CecLogicalAddress)iPtr)); for (int iPtr = 0; iPtr < 15; iPtr++) SetCheckboxItemChecked(cbPowerOffDevices, iPtr, Config.PowerOffDevices.IsSet((CecLogicalAddress)iPtr)); + + SetControlText(this, "Pulse-Eight USB-CEC Adapter - libCEC " + Lib.ToString(Config.ServerVersion)); return 1; } diff --git a/src/cec-config-gui/actions/RescanDevices.cs b/src/cec-config-gui/actions/RescanDevices.cs index 0e110a8..c81538d 100644 --- a/src/cec-config-gui/actions/RescanDevices.cs +++ b/src/cec-config-gui/actions/RescanDevices.cs @@ -5,14 +5,25 @@ namespace CecConfigGui.actions { class RescanDevices : UpdateProcess { + public RescanDevices(ref LibCecSharp lib) + { + Lib = lib; + } + public override void Process() { SendEvent(UpdateEventType.ProgressBar, 10); SendEvent(UpdateEventType.StatusText, "Polling active devices"); + Lib.RescanActiveDevices(); + + SendEvent(UpdateEventType.ProgressBar, 80); + SendEvent(UpdateEventType.StatusText, "Refreshing device list"); SendEvent(UpdateEventType.PollDevices); SendEvent(UpdateEventType.ProgressBar, 100); SendEvent(UpdateEventType.StatusText, "Ready."); } + + private LibCecSharp Lib; } } diff --git a/src/cec-config/cec-config.cpp b/src/cec-config/cec-config.cpp index b5ecd8e..d0840ce 100644 --- a/src/cec-config/cec-config.cpp +++ b/src/cec-config/cec-config.cpp @@ -185,7 +185,7 @@ bool OpenConnection(cec_device_type type = CEC_DEVICE_TYPE_RECORDING_DEVICE) g_config.Clear(); snprintf(g_config.strDeviceName, 13, "CEC-config"); g_config.callbackParam = NULL; - g_config.clientVersion = CEC_CLIENT_VERSION_1_5_0; + g_config.clientVersion = (uint32_t)CEC_CLIENT_VERSION_1_5_0; g_callbacks.CBCecLogMessage = &CecLogMessage; g_callbacks.CBCecKeyPress = &CecKeyPress; g_callbacks.CBCecCommand = &CecCommand; diff --git a/src/lib/CECProcessor.cpp b/src/lib/CECProcessor.cpp index 643defa..54162b9 100644 --- a/src/lib/CECProcessor.cpp +++ b/src/lib/CECProcessor.cpp @@ -47,7 +47,7 @@ using namespace CEC; using namespace std; using namespace PLATFORM; -CCECProcessor::CCECProcessor(CLibCEC *controller, const libcec_configuration *configuration) : +CCECProcessor::CCECProcessor(CLibCEC *controller, libcec_configuration *configuration) : m_bInitialised(false), m_communication(NULL), m_controller(controller), @@ -59,11 +59,13 @@ CCECProcessor::CCECProcessor(CLibCEC *controller, const libcec_configuration *co m_logicalAddresses.Clear(); CreateBusDevices(); m_configuration.Clear(); - + m_configuration.serverVersion = CEC_SERVER_VERSION_1_5_0; SetConfiguration(configuration); if (m_configuration.tvVendor != CEC_VENDOR_UNKNOWN) m_busDevices[CECDEVICE_TV]->ReplaceHandler(false); + + GetCurrentConfiguration(configuration); } CCECProcessor::CCECProcessor(CLibCEC *controller, const char *strDeviceName, const cec_device_type_list &types, uint16_t iPhysicalAddress) : @@ -76,9 +78,10 @@ CCECProcessor::CCECProcessor(CLibCEC *controller, const char *strDeviceName, con m_iLastTransmission(0) { m_configuration.Clear(); + m_configuration.serverVersion = CEC_SERVER_VERSION_1_5_0; // client version < 1.5.0 - m_configuration.clientVersion = CEC_CLIENT_VERSION_PRE_1_5; + m_configuration.clientVersion = (uint32_t)CEC_CLIENT_VERSION_PRE_1_5; snprintf(m_configuration.strDeviceName, 13, "%s", strDeviceName); m_configuration.deviceTypes = types; m_configuration.iPhysicalAddress = iPhysicalAddress; @@ -182,7 +185,7 @@ bool CCECProcessor::OpenConnection(const char *strPort, uint16_t iBaudRate, uint } if (bReturn) - CLibCEC::AddLog(CEC_LOG_NOTICE, "connected to the CEC adapter. firmware version = %d, client version = %s", m_communication->GetFirmwareVersion(), ToString(m_configuration.clientVersion)); + CLibCEC::AddLog(CEC_LOG_NOTICE, "connected to the CEC adapter. firmware version = %d, client version = %s", m_communication->GetFirmwareVersion(), ToString((cec_client_version)m_configuration.clientVersion)); return bReturn; } @@ -1365,6 +1368,19 @@ const char *CCECProcessor::ToString(const cec_client_version version) } } +const char *CCECProcessor::ToString(const cec_server_version version) +{ + switch (version) + { + case CEC_SERVER_VERSION_PRE_1_5: + return "pre-1.5"; + case CEC_SERVER_VERSION_1_5_0: + return "1.5.0"; + default: + return "Unknown"; + } +} + void *CCECBusScan::Process(void) { CCECBusDevice *device(NULL); @@ -1520,6 +1536,8 @@ bool CCECProcessor::SetConfiguration(const libcec_configuration *configuration) } // just copy these + m_configuration.clientVersion = configuration->clientVersion; + m_configuration.bActivateSource = configuration->bActivateSource; m_configuration.bGetSettingsFromROM = configuration->bGetSettingsFromROM; m_configuration.powerOffDevices = configuration->powerOffDevices; m_configuration.bPowerOffScreensaver = configuration->bPowerOffScreensaver; @@ -1545,16 +1563,20 @@ bool CCECProcessor::SetConfiguration(const libcec_configuration *configuration) bool CCECProcessor::GetCurrentConfiguration(libcec_configuration *configuration) { // client version 1.5.0 - configuration->clientVersion = m_configuration.clientVersion; snprintf(configuration->strDeviceName, 13, "%s", m_configuration.strDeviceName); configuration->deviceTypes = m_configuration.deviceTypes; configuration->bAutodetectAddress = m_configuration.bAutodetectAddress; configuration->iPhysicalAddress = m_configuration.iPhysicalAddress; configuration->baseDevice = m_configuration.baseDevice; configuration->iHDMIPort = m_configuration.iHDMIPort; + configuration->clientVersion = m_configuration.clientVersion; + configuration->serverVersion = m_configuration.serverVersion; configuration->tvVendor = m_configuration.tvVendor; - configuration->wakeDevices = m_configuration.wakeDevices; + configuration->bGetSettingsFromROM = m_configuration.bGetSettingsFromROM; + configuration->bUseTVMenuLanguage = m_configuration.bUseTVMenuLanguage; + configuration->bActivateSource = m_configuration.bActivateSource; + configuration->wakeDevices = m_configuration.wakeDevices; configuration->powerOffDevices = m_configuration.powerOffDevices; configuration->bPowerOffScreensaver = m_configuration.bPowerOffScreensaver; configuration->bPowerOffOnStandby = m_configuration.bPowerOffOnStandby; @@ -1571,3 +1593,9 @@ bool CCECProcessor::PersistConfiguration(libcec_configuration *configuration) { return m_communication->PersistConfiguration(configuration); } + +void CCECProcessor::RescanActiveDevices(void) +{ + for (unsigned int iPtr = 0; iPtr < 16; iPtr++) + m_busDevices[iPtr]->GetStatus(true); +} diff --git a/src/lib/CECProcessor.h b/src/lib/CECProcessor.h index 9a6f842..5a65753 100644 --- a/src/lib/CECProcessor.h +++ b/src/lib/CECProcessor.h @@ -47,7 +47,7 @@ namespace CEC { public: CCECProcessor(CLibCEC *controller, const char *strDeviceName, const cec_device_type_list &types, uint16_t iPhysicalAddress); - CCECProcessor(CLibCEC *controller, const libcec_configuration *configuration); + CCECProcessor(CLibCEC *controller, libcec_configuration *configuration); virtual ~CCECProcessor(void); virtual bool Start(const char *strPort, uint16_t iBaudRate = 38400, uint32_t iTimeoutMs = 10000); @@ -84,7 +84,7 @@ namespace CEC virtual bool IsActiveSource(cec_logical_address iAddress); virtual bool IsInitialised(void); virtual bool SetStreamPath(uint16_t iPhysicalAddress); - virtual cec_client_version GetClientVersion(void) const { return m_configuration.clientVersion; }; + virtual cec_client_version GetClientVersion(void) const { return (cec_client_version)m_configuration.clientVersion; }; virtual bool StandbyDevices(cec_logical_address address = CECDEVICE_BROADCAST); virtual bool PowerOnDevices(cec_logical_address address = CECDEVICE_BROADCAST); @@ -112,6 +112,7 @@ namespace CEC virtual bool SetConfiguration(const libcec_configuration *configuration); virtual bool CanPersistConfiguration(void); virtual bool PersistConfiguration(libcec_configuration *configuration); + virtual void RescanActiveDevices(void); bool SetLineTimeout(uint8_t iTimeout); @@ -127,6 +128,7 @@ namespace CEC const char *ToString(const cec_audio_status status); const char *ToString(const cec_vendor_id vendor); const char *ToString(const cec_client_version version); + const char *ToString(const cec_server_version version); virtual bool Transmit(const cec_command &data); virtual void TransmitAbort(cec_logical_address address, cec_opcode opcode, cec_abort_reason reason = CEC_ABORT_REASON_UNRECOGNIZED_OPCODE); @@ -150,7 +152,6 @@ namespace CEC void CreateBusDevices(void); void ReplaceHandlers(void); - void ScanCECBus(void); bool PhysicalAddressInUse(uint16_t iPhysicalAddress); bool TryLogicalAddress(cec_logical_address address); bool FindLogicalAddressRecordingDevice(void); diff --git a/src/lib/LibCEC.cpp b/src/lib/LibCEC.cpp index 44e368f..01ce2cf 100644 --- a/src/lib/LibCEC.cpp +++ b/src/lib/LibCEC.cpp @@ -52,7 +52,7 @@ CLibCEC::CLibCEC(const char *strDeviceName, cec_device_type_list types, uint16_t m_cec = new CCECProcessor(this, strDeviceName, types, iPhysicalAddress); } -CLibCEC::CLibCEC(const libcec_configuration *configuration) : +CLibCEC::CLibCEC(libcec_configuration *configuration) : m_iStartTime(GetTimeMs()), m_iCurrentButton(CEC_USER_CONTROL_CODE_UNKNOWN), m_buttontime(0), @@ -485,7 +485,7 @@ void * CECInit(const char *strDeviceName, CEC::cec_device_type_list types, uint1 return static_cast< void* > (lib); } -void * CECInitialise(const libcec_configuration *configuration) +void * CECInitialise(libcec_configuration *configuration) { CLibCEC *lib = new CLibCEC(configuration); CLibCEC::SetInstance(lib); @@ -552,6 +552,11 @@ const char *CLibCEC::ToString(const cec_client_version version) return m_cec->ToString(version); } +const char *CLibCEC::ToString(const cec_server_version version) +{ + return m_cec->ToString(version); +} + bool CLibCEC::GetCurrentConfiguration(libcec_configuration *configuration) { return m_cec->GetCurrentConfiguration(configuration); @@ -571,3 +576,8 @@ bool CLibCEC::PersistConfiguration(libcec_configuration *configuration) { return m_cec->PersistConfiguration(configuration); } + +void CLibCEC::RescanActiveDevices(void) +{ + return m_cec->RescanActiveDevices(); +} diff --git a/src/lib/LibCEC.h b/src/lib/LibCEC.h index 2df5b63..a2ed9ac 100644 --- a/src/lib/LibCEC.h +++ b/src/lib/LibCEC.h @@ -48,7 +48,7 @@ namespace CEC */ //@{ CLibCEC(const char *strDeviceName, cec_device_type_list types, uint16_t iPhysicalAddress = 0); - CLibCEC(const libcec_configuration *configuration); + CLibCEC(libcec_configuration *configuration); virtual ~CLibCEC(void); virtual bool Open(const char *strPort, uint32_t iTimeout = 10000); @@ -58,7 +58,7 @@ namespace CEC virtual bool PingAdapter(void); virtual bool StartBootloader(void); - virtual int8_t GetMinLibVersion(void) const{ return CEC_MIN_LIB_VERSION; }; + virtual int8_t GetMinLibVersion(void) const { return CEC_MIN_LIB_VERSION; }; virtual int8_t GetLibVersionMajor(void) const { return CEC_LIB_VERSION_MAJOR; }; virtual int8_t GetLibVersionMinor(void) const { return CEC_LIB_VERSION_MINOR; }; @@ -106,6 +106,7 @@ namespace CEC virtual bool SetConfiguration(const libcec_configuration *configuration); virtual bool CanPersistConfiguration(void); virtual bool PersistConfiguration(libcec_configuration *configuration); + virtual void RescanActiveDevices(void); const char *ToString(const cec_menu_state state); const char *ToString(const cec_version version); @@ -118,6 +119,7 @@ namespace CEC const char *ToString(const cec_audio_status status); const char *ToString(const cec_vendor_id vendor); const char *ToString(const cec_client_version version); + const char *ToString(const cec_server_version version); //@} static void AddLog(const cec_log_level level, const char *strFormat, ...); diff --git a/src/lib/LibCECC.cpp b/src/lib/LibCECC.cpp index c6f1563..b87e06c 100644 --- a/src/lib/LibCECC.cpp +++ b/src/lib/LibCECC.cpp @@ -42,7 +42,7 @@ using namespace std; //@{ ICECAdapter *cec_parser; -int cec_initialise(const libcec_configuration *configuration) +int cec_initialise(libcec_configuration *configuration) { cec_parser = (ICECAdapter *) CECInitialise(configuration); return (cec_parser != NULL) ? 1 : 0; @@ -410,4 +410,10 @@ int cec_set_configuration(libcec_configuration *configuration) return cec_parser ? (cec_parser->SetConfiguration(configuration) ? 1 : 0) : -1; } +void cec_rescan_devices(void) +{ + if (cec_parser) + cec_parser->RescanActiveDevices(); +} + //@} diff --git a/src/testclient/main.cpp b/src/testclient/main.cpp index a8f03a5..69309bc 100644 --- a/src/testclient/main.cpp +++ b/src/testclient/main.cpp @@ -1058,7 +1058,7 @@ int main (int argc, char *argv[]) if (!g_bSingleCommand) { CStdString strLog; - strLog.Format("CEC Parser created - libcec version %d.%d", parser->GetLibVersionMajor(), parser->GetLibVersionMinor()); + strLog.Format("CEC Parser created - libCEC version %s", parser->ToString((cec_server_version)g_config.serverVersion)); cout << strLog.c_str() << endl; //make stdin non-blocking