From a1eee77aebd4b49b937b3eee5b4a1099c70f10d4 Mon Sep 17 00:00:00 2001
From: Stefano Miccoli <mocme@icloud.com>
Date: Wed, 27 Jan 2016 23:33:23 +0100
Subject: [PATCH] fix MIN/MAX macro problem

---
 module/owlib/src/c/ow_ftdi.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/module/owlib/src/c/ow_ftdi.c b/module/owlib/src/c/ow_ftdi.c
index 9548213..1653791 100644
--- a/module/owlib/src/c/ow_ftdi.c
+++ b/module/owlib/src/c/ow_ftdi.c
@@ -58,6 +58,16 @@
 #if OW_FTDI
 //#define BENCH
 
+inline int min(int a, int b) {
+    if (a > b)
+        return b;
+    return a;
+}
+inline int max(int a, int b) {
+    if (a > b)
+        return a;
+    return b;
+}
 #define FTDI_LINKUSB_VID 0x0403
 #define FTDI_LINKUSB_PID 0x6001
 
@@ -426,7 +436,7 @@ SIZE_OR_ERROR owftdi_read(BYTE * data, size_t requested_size, struct connection_
 			 * Testing shows that we usually get our data within one or two loops
 			 * in normal situations, so this isn't really heavy busyloading.
 			 */
-			usleep(MIN(timeleft, (retries < 10) ? 200 : 1000));
+			usleep(min(timeleft, (retries < 10) ? 200 : 1000));
 			retries++;
 			continue;
 		}
@@ -493,7 +503,7 @@ void owftdi_slurp(struct connection_in *in, uint64_t usec) {
 	}
 
 	// Allow for at least 2 rounds of latency timeouts.. or we seem to miss \n in 19200 sometimes..
-	usec = MAX(usec, 2*1000);
+	usec = max(usec, 2*1000);
 
 	// USB block transfer timeout
 	int prev_timeout = FTDIC(in)->usb_read_timeout;
@@ -522,7 +532,7 @@ void owftdi_slurp(struct connection_in *in, uint64_t usec) {
 				return;
 			}
 
-			usleep(MIN(timeleft, 200));
+			usleep(min(timeleft, 200));
 			continue;
 		}
 
-- 
2.7.0

