Skip to content

Commit

Permalink
fix python adapter detection. removed unneeded bits from the python api
Browse files Browse the repository at this point in the history
  • Loading branch information
opdenkamp committed Mar 25, 2015
1 parent 82cb9a0 commit 0d187f0
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 12 deletions.
1 change: 0 additions & 1 deletion include/cec.h
Expand Up @@ -457,7 +457,6 @@ namespace CEC
* @return The number of devices that were found, or -1 when an error occured.
*/
virtual int8_t DetectAdapters(cec_adapter_descriptor *deviceList, uint8_t iBufSize, const char *strDevicePath = NULL, bool bQuickScan = false) = 0;

};
};

Expand Down
37 changes: 36 additions & 1 deletion include/cectypes.h
Expand Up @@ -58,6 +58,7 @@
#endif

#ifdef __cplusplus
#include <string>
extern "C" {
namespace CEC {
#endif
Expand Down Expand Up @@ -941,6 +942,41 @@ typedef struct cec_adapter_descriptor
cec_adapter_type adapterType;
} cec_adapter_descriptor;

#if defined(__cplusplus)
typedef struct AdapterDescriptor
{
AdapterDescriptor(void) :
iVendorId(0),
iProductId(0),
iFirmwareVersion(0),
iPhysicalAddress(0),
iFirmwareBuildDate(0)
{
}

AdapterDescriptor(const cec_adapter_descriptor& other)
{
strComPath = other.strComPath;
strComName = other.strComName;
iVendorId = other.iVendorId;
iProductId = other.iProductId;
iFirmwareVersion = other.iFirmwareVersion;
iPhysicalAddress = other.iPhysicalAddress;
iFirmwareBuildDate = other.iFirmwareBuildDate;
adapterType = other.adapterType;
}

std::string strComPath; /**< the path to the com port */
std::string strComName; /**< the name of the com port */
uint16_t iVendorId;
uint16_t iProductId;
uint16_t iFirmwareVersion;
uint16_t iPhysicalAddress;
uint32_t iFirmwareBuildDate;
cec_adapter_type adapterType;
} AdapterDescriptor;
#endif

typedef struct cec_datapacket
{
uint8_t data[100]; /**< the actual data */
Expand Down Expand Up @@ -1472,7 +1508,6 @@ struct libcec_configuration
cec_user_control_code comboKey; /*!< key code that initiates combo keys. defaults to CEC_USER_CONTROL_CODE_F1_BLUE. CEC_USER_CONTROL_CODE_UNKNOWN to disable. added in 2.0.5 */
uint32_t iComboKeyTimeoutMs; /*!< timeout until the combo key is sent as normal keypress */

CBCecLogMessageType CBCecLogMessage2;
#ifdef __cplusplus
libcec_configuration(void) { Clear(); }
~libcec_configuration(void) { Clear(); }
Expand Down
1 change: 1 addition & 0 deletions src/libcec/SwigHelper.h
Expand Up @@ -33,6 +33,7 @@
*/

#define SWIG_FILE_WITH_INIT
#define LIBCEC_SWIG_EXPORTS

#include "cectypes.h"
#include "cec.h"
Expand Down
28 changes: 26 additions & 2 deletions src/libcec/libcec.i
Expand Up @@ -7,6 +7,7 @@
%include "stdint.i"
%include "cstring.i"
%include "std_string.i"
%include "std_vector.i"

%ignore *::operator=;

Expand Down Expand Up @@ -95,8 +96,14 @@
}

%ignore CEC::libcec_configuration::~libcec_configuration;
%ignore CEC::libcec_configuration::callbacks;
%ignore CEC::libcec_configuration::callbackParam;

/////// replace CECInitialise() and CECDestroy() ///////
namespace std {
%template(AdapterVector) vector<CEC::AdapterDescriptor>;
}

/////// replace CECInitialise(), CECDestroy() and DetectAdapters() ///////

%extend CEC::ICECAdapter {
public:
Expand All @@ -120,11 +127,28 @@
}
return lib;
}

std::vector<CEC::AdapterDescriptor> DetectAdapters(const char *strDevicePath = NULL, bool bQuickScan = false)
{
std::vector<CEC::AdapterDescriptor> retval;
CEC::cec_adapter_descriptor devList[10];
int nbAdapters = self->DetectAdapters(devList, 10, strDevicePath, bQuickScan);
for (int adapter = 0; adapter < nbAdapters; ++adapter)
retval.push_back(CEC::AdapterDescriptor(devList[adapter]));
return retval;
}
}

%ignore CEC::ICECAdapter::~ICECAdapter;
%ignore CEC::ICECCallbacks;
%ignore CEC::DetectAdapters;

%ignore CEC::cec_keypress;
%ignore CEC::cec_log_message;
%ignore CEC::cec_adapter_descriptor;
%ignore CEC::cec_adapter;
%ignore CECInitialise;
%ignore CECDestroy;
%ignore CEC::ICECAdapter::~ICECAdapter;

%include "cectypes.h"
%include "cec.h"
16 changes: 8 additions & 8 deletions src/pyCecClient/pyCecClient.py
Expand Up @@ -24,15 +24,15 @@ def SetKeyPressCallback(self, callback):

# detect an adapter and return the com port path
def DetectAdapter(self):
adapters = cec.cec_adapter_descriptor()
if self.lib.DetectAdapters(adapters, 1) == 1:
retval = None
adapters = self.lib.DetectAdapters()
for adapter in adapters:
print("found a CEC adapter:")
print("port: " + adapters.strComName)
print("vendor: " + hex(adapters.iVendorId))
print("product: " + hex(adapters.iProductId))
return adapters.strComName
else:
return None
print("port: " + adapter.strComName)
print("vendor: " + hex(adapter.iVendorId))
print("product: " + hex(adapter.iProductId))
retval = adapter.strComName
return retval

# initialise libCEC
def InitLibCec(self):
Expand Down

0 comments on commit 0d187f0

Please sign in to comment.