[prev in list] [next in list] [prev in thread] [next in thread] 

List:       libftdi
Subject:    [PATCH 1/1] Fix Direction and ModemCtl enumerations to not use 0 for, bit mask.
From:       Eric Schott <els6 () psu ! edu>
Date:       2017-07-21 0:29:29
Message-ID: 2f1e03ee-d215-a707-9b71-8a46cf52edfe () psu ! edu
[Download RAW message or body]

For FTDI1 C++ implementation, correct the purge Direction and
ModemCtl enumerations definitions to not use value of zero for bit
masks.  The new enumeration values are defined so programs compiled
with the old ftdi.hpp include would work as previously (doing nothing
when the enumeration with the zero value was bit-or'ed into the
argument).
---
  ftdipp/ftdi.cpp | 24 +++++++++++++++++++-----
  ftdipp/ftdi.hpp |  8 ++++----
  2 files changed, 23 insertions(+), 9 deletions(-)

diff --git a/ftdipp/ftdi.cpp b/ftdipp/ftdi.cpp
index aca686a..ff10a84 100644
--- a/ftdipp/ftdi.cpp
+++ b/ftdipp/ftdi.cpp
@@ -144,12 +144,26 @@ int Context::reset()

  int Context::flush(int mask)
  {
-    int ret = 1;
+    int ret;

-    if (mask & Input)
-        ret &= ftdi_usb_purge_rx_buffer(d->ftdi);
-    if (mask & Output)
-        ret &= ftdi_usb_purge_tx_buffer(d->ftdi);
+    switch (mask & (Input | Output)) {
+    case Input:
+        ret = ftdi_usb_purge_rx_buffer(d->ftdi);
+        break;
+
+    case Output:
+        ret = ftdi_usb_purge_tx_buffer(d->ftdi);
+        break;
+
+    case Input | Output:
+        ret = ftdi_usb_purge_buffers(d->ftdi);
+        break;
+
+    default:
+        // Emulate behavior of previous version.
+        ret = 1;
+        break;
+    }

      return ret;
  }
diff --git a/ftdipp/ftdi.hpp b/ftdipp/ftdi.hpp
index dc035cc..2241bf3 100644
--- a/ftdipp/ftdi.hpp
+++ b/ftdipp/ftdi.hpp
@@ -55,16 +55,16 @@ public:
       */
      enum Direction
      {
-        Input,
-        Output
+        Input = 0x2,
+        Output = 0x1,
      };

      /*! \brief Modem control flags.
       */
      enum ModemCtl
      {
-        Dtr,
-        Rts
+        Dtr = 0x2,
+        Rts = 0x1,
      };

      /* Constructor, Destructor */
-- 
2.12.3


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

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic