C++ API: Correct the purge Direction and ModemCtl enumerations definitions
authorEric Schott <eric@morningjoy.com>
Fri, 21 Jul 2017 09:56:07 +0000 (11:56 +0200)
committerThomas Jarosch <thomas.jarosch@intra2net.com>
Fri, 21 Jul 2017 09:56:07 +0000 (11:56 +0200)
Do not use value of zero for bitmasks. 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
ftdipp/ftdi.hpp

index 8eb2ec2..bdd85f5 100644 (file)
@@ -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;
 }
index 4e3511d..2289a84 100644 (file)
@@ -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 */