namespace CEC {
#endif
#define CEC_MIN_VERSION 1
- #define CEC_LIB_VERSION 1
+ #define CEC_LIB_VERSION 2
#define CEC_SETTLE_DOWN_TIME 1000
typedef std::vector<uint8_t> cec_frame;
std::string path;
std::string comm;
} cec_device;
-};
+
+ //default physical address 1.0.0.0
+ #define CEC_DEFAULT_PHYSICAL_ADDRESS 0x1000
#ifdef __cplusplus
+};
+
#include "CECExportsCpp.h"
#include "CECExportsC.h"
};
#endif
/*!
- * @brief Initialise the cec device.
+ * @brief Load the CEC adapter library.
* @param strDeviceName How to present this device to other devices.
+ * @param iLogicalAddress The logical of this device. PLAYBACKDEVICE1 by default.
+ * @param iPhysicalAddress The physical address of this device. 0x1000 by default.
* @return True when initialised, false otherwise.
*/
-extern DECLSPEC bool cec_init(const char *strDeviceName);
+
+#ifdef __cplusplus
+extern DECLSPEC bool cec_init(const char *strDeviceName, CEC::cec_logical_address iLogicalAddress = CEC::CECDEVICE_PLAYBACKDEVICE1, int iPhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS);
+#else
+extern DECLSPEC bool cec_init(const char *strDeviceName, cec_logical_address iLogicalAddress = CECDEVICE_PLAYBACKDEVICE1, int iPhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS);
+#endif
/*!
- * @brief Close the cec device.
+ * @brief Close the CEC adapter connection.
* @return True when the device was closed, false otherwise.
*/
extern DECLSPEC bool cec_close(void);
/*!
* @brief Power off connected CEC capable devices.
+ * @param address The logical address to power off.
* @return True when the command was sent succesfully, false otherwise.
*/
#ifdef __cplusplus
/*!
* @brief Power on the connected CEC capable devices.
+ * @param address The logical address to power on.
* @return True when the command was sent succesfully, false otherwise.
*/
#ifdef __cplusplus
/*!
* @brief Put connected CEC capable devices in standby mode.
+ * @brief address The logical address of the device to put in standby.
* @return True when the command was sent succesfully, false otherwise.
*/
#ifdef __cplusplus
#endif
/*!
- * @brief Set this device as the active source on connected CEC capable devices.
+ * @brief Broadcast a message that notifies connected CEC capable devices that this device is the active source.
* @return True when the command was sent succesfully, false otherwise.
*/
extern DECLSPEC bool cec_set_active_view(void);
/*!
- * @brief Mark this device as inactive on connected CEC capable devices.
+ * @brief Broadcast a message that notifies connected CEC capable devices that this device is no longer the active source.
* @return True when the command was sent succesfully, false otherwise.
*/
extern DECLSPEC bool cec_set_inactive_view(void);
/*!
* @brief Get the next keypress in the queue, if there is one.
- * @param key The next keypress
+ * @param key The next keypress.
* @return True if a key was passed, false otherwise.
*/
#ifdef __cplusplus
#endif
/*!
- * @brief Transmit a frame and wait for ACK.
+ * @brief Transmit a frame on the CEC line.
* @param data The frame to send.
+ * @param bWaitForAck Wait for an ACK message for 1 second after this frame has been sent.
+ * @param iTimeout Timeout if the message could not be sent for this amount of ms. Does not influence the timeout of the wait for the ACK message. That timeout is specified by the CEC standard.
* @return True when the data was sent and acked, false otherwise.
*/
#ifdef __cplusplus
*/
extern DECLSPEC bool cec_set_ack_mask(uint16_t ackmask);
+/*!
+ * @return Get the minimal version of libcec that this version of libcec can interface with.
+ */
extern DECLSPEC int cec_get_min_version(void);
+
+/*!
+ * @return Get the version of libcec.
+ */
extern DECLSPEC int cec_get_lib_version(void);
+/*!
+ * @brief Try to find all connected CEC adapters. Only implemented on Linux at the moment.
+ * @param deviceList The vector to store device descriptors in.
+ * @param strDevicePath Optional device path. Only adds device descriptors that match the given device path.
+ * @return The number of devices that were found, or -1 when an error occured.
+ */
#ifdef __cplusplus
extern DECLSPEC int cec_find_devices(std::vector<CEC::cec_device> &deviceList, const char *strDevicePath = NULL);
#else
*/
virtual bool SetAckMask(cec_logical_address ackmask) = 0;
+ /*!
+ * @see cec_get_min_version
+ */
virtual int GetMinVersion(void) = 0;
+
+ /*!
+ * @see cec_get_lib_version
+ */
virtual int GetLibVersion(void) = 0;
};
};
-extern DECLSPEC void * CECCreate(const char *strDeviceName);
+extern DECLSPEC void * CECCreate(const char *strDeviceName, CEC::cec_logical_address iLogicalAddress = CEC::CECDEVICE_PLAYBACKDEVICE1, int iPhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS);
#if !defined(DLL_EXPORT)
#if defined(_WIN32) || defined(_WIN64)
#include <conio.h>
static HINSTANCE g_libCEC = NULL;
-inline CEC::ICECDevice *LoadLibCec(const char *strName)
+static int g_iLibCECInstanceCount = 0;
+
+/*!
+ * @see cec_init
+ */
+inline CEC::ICECDevice *LoadLibCec(const char *strName, CEC::cec_logical_address iLogicalAddress = CEC::CECDEVICE_PLAYBACKDEVICE1, int iPhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS)
{
typedef void* (__cdecl*_CreateLibCec)(const char *);
_CreateLibCec CreateLibCec;
- g_libCEC = LoadLibrary("libcec.dll");
+ if (!g_libCEC)
+ g_libCEC = LoadLibrary("libcec.dll");
if (!g_libCEC)
return NULL;
+
+ ++g_iLibCECInstanceCount;
CreateLibCec = (_CreateLibCec) (GetProcAddress(g_libCEC, "CECCreate"));
if (!CreateLibCec)
return NULL;
- return static_cast< CEC::ICECDevice* > (CreateLibCec(strName));
+ return static_cast< CEC::ICECDevice* > (CreateLibCec(strName, iLogicalAddress, iPhysicalAddress));
}
+/*!
+ * @brief Unload the given libcec instance.
+ * @param device The instance to unload.
+ */
inline void UnloadLibCec(CEC::ICECDevice *device)
{
delete device;
- FreeLibrary(g_libCEC);
+
+ if (--g_iLibCECInstanceCount == 0)
+ {
+ FreeLibrary(g_libCEC);
+ g_libCEC = NULL;
+ }
};
#else
-inline CEC::ICECDevice *LoadLibCec(const char *strName)
+
+/*!
+ * @see cec_init
+ */
+inline CEC::ICECDevice *LoadLibCec(const char *strName, CEC::cec_logical_address iLogicalAddress = CEC::CECDEVICE_PLAYBACKDEVICE1, int iPhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS)
{
- return (CEC::ICECDevice*) CECCreate(strName);
+ return (CEC::ICECDevice*) CECCreate(strName, iLogicalAddress, iPhysicalAddress);
};
+/*!
+ * @brief Unload the given libcec instance.
+ * @param device The instance to unload.
+ */
inline void UnloadLibCec(CEC::ICECDevice *device)
{
delete device;
MSGCODE_FRAME_ACK = 0x40,
} ECecMessageCode;
-//default physical address 1.0.0.0
-#define CEC_DEFAULT_PHYSICAL_ADDRESS 0x1000
#define MSGSTART 0xFF
#define MSGEND 0xFE
#define MSGESC 0xFD
* ICECDevice implementation
*/
//@{
-CCECParser::CCECParser(const char *strDeviceName) :
+CCECParser::CCECParser(const char *strDeviceName, cec_logical_address iLogicalAddress /* = CECDEVICE_PLAYBACKDEVICE1 */, int iPhysicalAddress /* = CEC_DEFAULT_PHYSICAL_ADDRESS*/) :
m_inbuf(NULL),
m_iInbufSize(0),
m_iInbufUsed(0),
m_iCurrentButton(CEC_USER_CONTROL_CODE_UNKNOWN),
- m_physicaladdress(CEC_DEFAULT_PHYSICAL_ADDRESS),
- m_iLogicalAddress(CECDEVICE_PLAYBACKDEVICE1),
+ m_physicaladdress(iPhysicalAddress),
+ m_iLogicalAddress(iLogicalAddress),
m_strDeviceName(strDeviceName),
m_bRunning(false)
{
return CCECDetect::FindDevices(deviceList, strDevicePath);
}
-DECLSPEC void * CECCreate(const char *strDeviceName)
+DECLSPEC void * CECCreate(const char *strDeviceName, CEC::cec_logical_address iLogicalAddress /* = CEC::CECDEVICE_PLAYBACKDEVICE1 */, int iPhysicalAddress /* = CEC_DEFAULT_PHYSICAL_ADDRESS */)
{
- return static_cast< void* > (new CCECParser(strDeviceName));
+ return static_cast< void* > (new CCECParser(strDeviceName, iLogicalAddress, iPhysicalAddress));
}
* ICECDevice implementation
*/
//@{
- CCECParser(const char *strDeviceName);
+ CCECParser(const char *strDeviceName, cec_logical_address iLogicalAddress = CECDEVICE_PLAYBACKDEVICE1, int iPhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS);
virtual ~CCECParser(void);
virtual bool Open(const char *strPort, int iTimeout = 10000);
//@{
ICECDevice *cec_parser;
-bool cec_init(const char *strDeviceName)
+bool cec_init(const char *strDeviceName, cec_logical_address iLogicalAddress /* = CECDEVICE_PLAYBACKDEVICE1 */, int iPhysicalAddress /* = CEC_DEFAULT_PHYSICAL_ADDRESS */)
{
- cec_parser = (ICECDevice *) CECCreate(strDeviceName);
+ cec_parser = (ICECDevice *) CECCreate(strDeviceName, iLogicalAddress, iPhysicalAddress);
return (cec_parser != NULL);
}