libftdi Archives

Subject: [RFC PATCH] Rename python wrapper to ftdi1. Adapt examples with minimal code changes

From: Thomas Jarosch <thomas.jarosch@xxxxxxxxxxxxx>
To: libftdi@xxxxxxxxxxxxxxxxxxxxxxx
Date: Sat, 7 Jul 2012 15:05:28 +0200
RFC patch for the upcoming libftdi 1.x.

The python wrapper will be renamed to "ftdi1" so it can
co-exist with the python wrapper from libftdi 0.x.

Client code needs a one line change if it doesn't
use any special async API:

"import ftdi"

->

"import ftdi1 as ftdi".

Signed-off-by: Thomas Jarosch <thomas.jarosch@xxxxxxxxxxxxx>
---
 bindings/CMakeLists.txt     |    8 ++--
 bindings/ftdi.i             |   88 -------------------------------------------
 bindings/ftdi1.i            |   88 +++++++++++++++++++++++++++++++++++++++++++
 examples/python/complete.py |    2 +-
 examples/python/simple.py   |    2 +-
 5 files changed, 94 insertions(+), 94 deletions(-)
 delete mode 100644 bindings/ftdi.i
 create mode 100644 bindings/ftdi1.i

diff --git a/bindings/CMakeLists.txt b/bindings/CMakeLists.txt
index 3f25225..28061a6 100644
--- a/bindings/CMakeLists.txt
+++ b/bindings/CMakeLists.txt
@@ -10,8 +10,8 @@ if(PYTHON_BINDINGS AND SWIG_FOUND AND PYTHONLIBS_FOUND AND 
PYTHONINTERP_FOUND)
     INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_PATH})
     LINK_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}/../src)
 
-    SWIG_ADD_MODULE(ftdi python ftdi.i)
-    SWIG_LINK_LIBRARIES(ftdi ftdi1 ${PYTHON_LIBRARIES})
+    SWIG_ADD_MODULE(ftdi1 python ftdi1.i)
+    SWIG_LINK_LIBRARIES(ftdi1 ftdi1 ${PYTHON_LIBRARIES})
 
     execute_process ( COMMAND ${PYTHON_EXECUTABLE} -c "import sys; print 
'%d.%d' % ( sys.version_info[0], sys.version_info[1] )"
                       OUTPUT_VARIABLE PYTHON_VERSION
@@ -19,8 +19,8 @@ if(PYTHON_BINDINGS AND SWIG_FOUND AND PYTHONLIBS_FOUND AND 
PYTHONINTERP_FOUND)
 
     set ( SITEPACKAGE lib${LIB_SUFFIX}/python${PYTHON_VERSION}/site-packages )
 
-    INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/_ftdi.so DESTINATION 
${SITEPACKAGE})
-    INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/ftdi.py DESTINATION 
${SITEPACKAGE})
+    INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/_ftdi1.so DESTINATION 
${SITEPACKAGE})
+    INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/ftdi1.py DESTINATION 
${SITEPACKAGE})
 
     message(STATUS "Building python bindings via swig. Will be installed under 
${CMAKE_INSTALL_PREFIX}/${SITEPACKAGE}")
 else(PYTHON_BINDINGS AND SWIG_FOUND AND PYTHONLIBS_FOUND AND 
PYTHONINTERP_FOUND)
diff --git a/bindings/ftdi.i b/bindings/ftdi.i
deleted file mode 100644
index faf2022..0000000
--- a/bindings/ftdi.i
+++ /dev/null
@@ -1,88 +0,0 @@
-/* File: ftdi.i */
-
-%module(docstring="Python interface to libftdi1") ftdi
-
-%include <typemaps.i>
-%include <cstring.i>
-
-%typemap(in) unsigned char* = char*;
-
-%ignore ftdi_write_data_async;
-%ignore ftdi_async_complete;
-
-%immutable ftdi_version_info::version_str;
-%immutable ftdi_version_info::snapshot_str;
-
-%rename("%(strip:[ftdi_])s") "";
-
-%newobject ftdi_new;
-%typemap(newfree) struct ftdi_context *ftdi "ftdi_free($1);";
-%delobject ftdi_free;
-
-%typemap(in,numinputs=0) SWIGTYPE** OUTPUT ($*ltype temp) %{ $1 = &temp; %}
-%typemap(argout) SWIGTYPE** OUTPUT %{ $result = 
SWIG_Python_AppendOutput($result, 
SWIG_NewPointerObj((void*)*$1,$*descriptor,0)); %}
-%apply SWIGTYPE** OUTPUT { struct ftdi_device_list **devlist };
-    int ftdi_usb_find_all(struct ftdi_context *ftdi, struct ftdi_device_list 
**devlist,
-                          int vendor, int product);
-%clear struct ftdi_device_list **devlist;
-
-%apply char *OUTPUT { char * manufacturer, char * description, char * serial };
-%cstring_bounded_output( char * manufacturer, 256 );
-%cstring_bounded_output( char * description, 256 );
-%cstring_bounded_output( char * serial, 256 );
-%typemap(default,noblock=1) int mnf_len, int desc_len, int serial_len { $1 = 
256; }
-    int ftdi_usb_get_strings(struct ftdi_context *ftdi, struct libusb_device 
*dev,
-                             char * manufacturer, int mnf_len,
-                             char * description, int desc_len,
-                             char * serial, int serial_len);
-%clear char * manufacturer, char * description, char * serial;
-%clear int mnf_len, int desc_len, int serial_len;
-
-%typemap(in,numinputs=1) (unsigned char *buf, int size) %{ $2 = 
PyInt_AsLong($input);$1 = (unsigned char*)malloc($2*sizeof(char)); %}
-%typemap(argout) (unsigned char *buf, int size) %{ if(result<0) $2=0; $result 
= SWIG_Python_AppendOutput($result, PyString_FromStringAndSize((char*)$1, 
$2)); free($1); %}
-    int ftdi_read_data(struct ftdi_context *ftdi, unsigned char *buf, int 
size);
-%clear (unsigned char *buf, int size);
-
-%apply int *OUTPUT { unsigned int *chunksize };
-    int ftdi_read_data_get_chunksize(struct ftdi_context *ftdi, unsigned int 
*chunksize);
-    int ftdi_write_data_get_chunksize(struct ftdi_context *ftdi, unsigned int 
*chunksize);
-%clear unsigned int *chunksize;
-
-%apply char *OUTPUT { unsigned char *pins };
-    int ftdi_read_pins(struct ftdi_context *ftdi, unsigned char *pins);
-%clear unsigned char *pins;
-
-%apply char *OUTPUT { unsigned char *latency };
-    int ftdi_get_latency_timer(struct ftdi_context *ftdi, unsigned char 
*latency);
-%clear unsigned char *latency;
-
-%apply short *OUTPUT { unsigned short *status };
-    int ftdi_poll_modem_status(struct ftdi_context *ftdi, unsigned short 
*status);
-%clear unsigned short *status;
-
-%apply int *OUTPUT { int* value };
-    int ftdi_get_eeprom_value(struct ftdi_context *ftdi, enum 
ftdi_eeprom_value value_name, int* value);
-%clear int* value;
-
-%typemap(in,numinputs=1) (unsigned char *buf, int size) %{ $2 = 
PyInt_AsLong($input);$1 = (unsigned char*)malloc($2*sizeof(char)); %}
-%typemap(argout) (unsigned char *buf, int size) %{ if(result<0) $2=0; $result 
= SWIG_Python_AppendOutput($result, PyString_FromStringAndSize((char*)$1, 
$2)); free($1); %}
-    int ftdi_get_eeprom_buf(struct ftdi_context *ftdi, unsigned char * buf, 
int size);
-%clear (unsigned char *buf, int size);
-
-%apply short *OUTPUT { unsigned short *eeprom_val };
-    int ftdi_read_eeprom_location (struct ftdi_context *ftdi, int eeprom_addr, 
unsigned short *eeprom_val);
-%clear unsigned short *eeprom_val;
-
-%apply int *OUTPUT { unsigned int *chipid };
-    int ftdi_read_chipid(struct ftdi_context *ftdi, unsigned int *chipid);
-%clear unsigned int *chipid;
-
-%include ftdi.h
-%{
-#include <ftdi.h>
-%}
-
-%include ftdi_i.h
-%{
-#include <ftdi_i.h>
-%}
diff --git a/bindings/ftdi1.i b/bindings/ftdi1.i
new file mode 100644
index 0000000..17e2e81
--- /dev/null
+++ b/bindings/ftdi1.i
@@ -0,0 +1,88 @@
+/* File: ftdi1.i */
+
+%module(docstring="Python interface to libftdi1") ftdi1
+
+%include <typemaps.i>
+%include <cstring.i>
+
+%typemap(in) unsigned char* = char*;
+
+%ignore ftdi_write_data_async;
+%ignore ftdi_async_complete;
+
+%immutable ftdi_version_info::version_str;
+%immutable ftdi_version_info::snapshot_str;
+
+%rename("%(strip:[ftdi_])s") "";
+
+%newobject ftdi_new;
+%typemap(newfree) struct ftdi_context *ftdi "ftdi_free($1);";
+%delobject ftdi_free;
+
+%typemap(in,numinputs=0) SWIGTYPE** OUTPUT ($*ltype temp) %{ $1 = &temp; %}
+%typemap(argout) SWIGTYPE** OUTPUT %{ $result = 
SWIG_Python_AppendOutput($result, 
SWIG_NewPointerObj((void*)*$1,$*descriptor,0)); %}
+%apply SWIGTYPE** OUTPUT { struct ftdi_device_list **devlist };
+    int ftdi_usb_find_all(struct ftdi_context *ftdi, struct ftdi_device_list 
**devlist,
+                          int vendor, int product);
+%clear struct ftdi_device_list **devlist;
+
+%apply char *OUTPUT { char * manufacturer, char * description, char * serial };
+%cstring_bounded_output( char * manufacturer, 256 );
+%cstring_bounded_output( char * description, 256 );
+%cstring_bounded_output( char * serial, 256 );
+%typemap(default,noblock=1) int mnf_len, int desc_len, int serial_len { $1 = 
256; }
+    int ftdi_usb_get_strings(struct ftdi_context *ftdi, struct libusb_device 
*dev,
+                             char * manufacturer, int mnf_len,
+                             char * description, int desc_len,
+                             char * serial, int serial_len);
+%clear char * manufacturer, char * description, char * serial;
+%clear int mnf_len, int desc_len, int serial_len;
+
+%typemap(in,numinputs=1) (unsigned char *buf, int size) %{ $2 = 
PyInt_AsLong($input);$1 = (unsigned char*)malloc($2*sizeof(char)); %}
+%typemap(argout) (unsigned char *buf, int size) %{ if(result<0) $2=0; $result 
= SWIG_Python_AppendOutput($result, PyString_FromStringAndSize((char*)$1, 
$2)); free($1); %}
+    int ftdi_read_data(struct ftdi_context *ftdi, unsigned char *buf, int 
size);
+%clear (unsigned char *buf, int size);
+
+%apply int *OUTPUT { unsigned int *chunksize };
+    int ftdi_read_data_get_chunksize(struct ftdi_context *ftdi, unsigned int 
*chunksize);
+    int ftdi_write_data_get_chunksize(struct ftdi_context *ftdi, unsigned int 
*chunksize);
+%clear unsigned int *chunksize;
+
+%apply char *OUTPUT { unsigned char *pins };
+    int ftdi_read_pins(struct ftdi_context *ftdi, unsigned char *pins);
+%clear unsigned char *pins;
+
+%apply char *OUTPUT { unsigned char *latency };
+    int ftdi_get_latency_timer(struct ftdi_context *ftdi, unsigned char 
*latency);
+%clear unsigned char *latency;
+
+%apply short *OUTPUT { unsigned short *status };
+    int ftdi_poll_modem_status(struct ftdi_context *ftdi, unsigned short 
*status);
+%clear unsigned short *status;
+
+%apply int *OUTPUT { int* value };
+    int ftdi_get_eeprom_value(struct ftdi_context *ftdi, enum 
ftdi_eeprom_value value_name, int* value);
+%clear int* value;
+
+%typemap(in,numinputs=1) (unsigned char *buf, int size) %{ $2 = 
PyInt_AsLong($input);$1 = (unsigned char*)malloc($2*sizeof(char)); %}
+%typemap(argout) (unsigned char *buf, int size) %{ if(result<0) $2=0; $result 
= SWIG_Python_AppendOutput($result, PyString_FromStringAndSize((char*)$1, 
$2)); free($1); %}
+    int ftdi_get_eeprom_buf(struct ftdi_context *ftdi, unsigned char * buf, 
int size);
+%clear (unsigned char *buf, int size);
+
+%apply short *OUTPUT { unsigned short *eeprom_val };
+    int ftdi_read_eeprom_location (struct ftdi_context *ftdi, int eeprom_addr, 
unsigned short *eeprom_val);
+%clear unsigned short *eeprom_val;
+
+%apply int *OUTPUT { unsigned int *chipid };
+    int ftdi_read_chipid(struct ftdi_context *ftdi, unsigned int *chipid);
+%clear unsigned int *chipid;
+
+%include ftdi.h
+%{
+#include <ftdi.h>
+%}
+
+%include ftdi_i.h
+%{
+#include <ftdi_i.h>
+%}
diff --git a/examples/python/complete.py b/examples/python/complete.py
index cee917d..f1b737c 100644
--- a/examples/python/complete.py
+++ b/examples/python/complete.py
@@ -9,7 +9,7 @@ of the swig generated python wrapper
 You need to build and install the wrapper first"""
 
 import os
-import ftdi
+import ftdi1 as ftdi
 import time
 
 # initialize
diff --git a/examples/python/simple.py b/examples/python/simple.py
index ecd5c2f..82ef6bb 100644
--- a/examples/python/simple.py
+++ b/examples/python/simple.py
@@ -8,7 +8,7 @@ of the swig generated python wrapper
 
 You need to build and install the wrapper first"""
 
-import ftdi
+import ftdi1 as ftdi
 
 def main():
     """Main program"""
-- 
1.7.6.5

--
libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to libftdi+unsubscribe@xxxxxxxxxxxxxxxxxxxxxxx   

Current Thread
  • [RFC PATCH] Rename python wrapper to ftdi1. Adapt examples with minimal code changes, Thomas Jarosch <=