Increase copyright year to 2014
[libftdi] / ftdipp / ftdi.cpp
index 5e45dce..d9b6fbf 100644 (file)
@@ -2,11 +2,11 @@
                           ftdi.cpp  -  C++ wraper for libftdi
                              -------------------
     begin                : Mon Oct 13 2008
-    copyright            : (C) 2008 by Marek Vavruša
+    copyright            : (C) 2008-2014 by Marek Vavruša / libftdi developers
     email                : opensource@intra2net.com and marek@vavrusa.com
  ***************************************************************************/
 /*
-Copyright (C) 2008 by Marek Vavruša
+Copyright (C) 2008-2014 by Marek Vavruša / libftdi developers
 
 The software in this package is distributed under the GNU General
 Public License version 2 (with a special exception described below).
@@ -26,6 +26,7 @@ in accordance with section (3) of the GNU General Public License.
 This exception does not invalidate any other reasons why a work based
 on this file might be covered by the GNU General Public License.
 */
+#include <libusb.h>
 #include "ftdi.hpp"
 #include "ftdi_i.h"
 #include "ftdi.h"
@@ -132,6 +133,7 @@ int Context::open(struct libusb_device *dev)
 int Context::close()
 {
     d->open = false;
+    d->dev = 0;
     return ftdi_usb_close(d->ftdi);
 }
 
@@ -178,6 +180,26 @@ int Context::set_line_property(enum ftdi_bits_type bits, enum ftdi_stopbits_type
     return ftdi_set_line_property2(d->ftdi, bits, sbit, parity, break_type);
 }
 
+int Context::get_usb_read_timeout() const
+{
+    return d->ftdi->usb_read_timeout;
+}
+
+void Context::set_usb_read_timeout(int usb_read_timeout)
+{
+    d->ftdi->usb_read_timeout = usb_read_timeout;
+}
+
+int Context::get_usb_write_timeout() const
+{
+    return d->ftdi->usb_write_timeout;
+}
+
+void Context::set_usb_write_timeout(int usb_write_timeout)
+{
+    d->ftdi->usb_write_timeout = usb_write_timeout;
+}
+
 int Context::read(unsigned char *buf, int size)
 {
     return ftdi_read_data(d->ftdi, buf, size);
@@ -316,6 +338,11 @@ int Context::get_strings()
 
 int Context::get_strings_and_reopen()
 {
+    if ( d->dev == 0 )
+    {
+        d->dev = libusb_get_device(d->ftdi->usb_dev);
+    }
+
     // Get device strings (closes device)
     int ret=get_strings();
     if (ret < 0)
@@ -613,13 +640,10 @@ List::iterator List::erase(iterator beg, iterator end)
     return d->list.erase(beg, end);
 }
 
-List* List::find_all(int vendor, int product)
+List* List::find_all(Context &context, int vendor, int product)
 {
     struct ftdi_device_list* dlist = 0;
-    struct ftdi_context ftdi;
-    ftdi_init(&ftdi);
-    ftdi_usb_find_all(&ftdi, &dlist, vendor, product);
-    ftdi_deinit(&ftdi);
+    ftdi_usb_find_all(context.context(), &dlist, vendor, product);
     return new List(dlist);
 }