 - 	ch->count = 0;
 - 
 - 	return (ret);
--diff -Nurp libphidget22-1.4.20190605.orig/configure libphidget22-1.4.20190605/configure
----- libphidget22-1.4.20190605.orig/configure	2019-06-05 16:06:56.000000000 -0400
--+++ libphidget22-1.4.20190605/configure	2019-09-05 11:50:10.510502872 -0400
--@@ -5676,7 +5676,7 @@ esac
-- fi
-- 
-- : ${AR=ar}
---: ${AR_FLAGS=cru}
--+: ${AR_FLAGS=cr}
-- 
-- 
-- 
+-diff -urp libphidget22-1.6.20200417.orig/src/device/dataadapterdevice.c libphidget22-1.6.20200417/src/device/dataadapterdevice.c
+---- libphidget22-1.6.20200417.orig/src/device/dataadapterdevice.c	2020-04-17 21:50:41.000000000 +0000
+-+++ libphidget22-1.6.20200417/src/device/dataadapterdevice.c	2020-06-02 13:28:12.385198805 +0000
+-@@ -699,25 +699,3 @@ PhidgetReturnCode sendDataBuffer(Phidget
+- 	}
+- 	return ret;
+- }
+--
+--
+--//CRC16 function found from https://ctlsys.com/support/how_to_compute_the_modbus_rtu_message_crc/
+--// Compute the MODBUS RTU CRC
+--uint16_t ModRTU_CRC(uint8_t *buf, uint16_t len)
+--{
+--	uint16_t crc = 0xFFFF;
+--
+--	for (uint16_t pos = 0; pos < len; pos++) {
+--		crc ^= (uint16_t)buf[pos];          // XOR byte into least sig. byte of crc
+--
+--		for (int i = 8; i != 0; i--) {    // Loop over each bit
+--			if ((crc & 0x0001) != 0) {      // If the LSB is set
+--				crc >>= 1;                    // Shift right and XOR 0xA001
+--				crc ^= 0xA001;
+--			} else                            // Else LSB is not set
+--				crc >>= 1;                    // Just shift right
+--		}
+--	}
+--	// Note, this number has low and high bytes swapped, so use it accordingly (or swap bytes)
+--	return crc;
+--}
+-diff -urp libphidget22-1.6.20200417.orig/src/device/genericdevice.c libphidget22-1.6.20200417/src/device/genericdevice.c
+---- libphidget22-1.6.20200417.orig/src/device/genericdevice.c	2020-04-17 21:50:41.000000000 +0000
+-+++ libphidget22-1.6.20200417/src/device/genericdevice.c	2020-06-02 13:28:50.317025565 +0000
+-@@ -104,7 +104,7 @@ PhidgetGenericDevice_bridgeInput(Phidget
+- 		case PHIDUID_GENERIC_PHIDUSB:
+- 			len = getBridgePacketArrayLen(bp, 2);
+- 
+--			if (len > (int)phid->OUTPacketLength[0])
+-+			if (len > (size_t)phid->OUTPacketLength[0])
+- 				return (EPHIDGET_INVALIDARG);
+- 
+- 			return (PhidgetDevice_transferpacket(bp->iop, (PhidgetDeviceHandle)phid, PHIDGETUSB_REQ_CHANNEL_WRITE,
+-@@ -120,7 +120,7 @@ PhidgetGenericDevice_bridgeInput(Phidget
+- 		case PHIDUID_GENERIC_PHIDUSB:
+- 			len = getBridgePacketArrayLen(bp, 1);
+- 
+--			if (len > (int)phid->OUTPacketLength[0])
+-+			if (len > (size_t)phid->OUTPacketLength[0])
+- 				return (EPHIDGET_INVALIDARG);
+- 
+- 			return (PhidgetDevice_transferpacket(bp->iop, (PhidgetDeviceHandle)phid, PHIDGETUSB_REQ_DEVICE_WRITE,
+-@@ -136,8 +136,8 @@ PhidgetGenericDevice_bridgeInput(Phidget
+- 		case PHIDUID_GENERIC_PHIDUSB:
+- 			len = getBridgePacketInt32(bp, 2);
+- 
+--			if (len > (int)phid->OUTPacketLength[0])
+--				len = (int)phid->OUTPacketLength[0];
+-+			if (len > (size_t)phid->OUTPacketLength[0])
+-+				len = (size_t)phid->OUTPacketLength[0];
+- 
+- 			ret = PhidgetDevice_transferpacket(bp->iop, (PhidgetDeviceHandle)phid, PHIDGETUSB_REQ_CHANNEL_READ,
+- 				getBridgePacketInt32(bp, 0), getBridgePacketInt32(bp, 1),
+-@@ -170,8 +170,8 @@ PhidgetGenericDevice_bridgeInput(Phidget
+- 		case PHIDUID_GENERIC_PHIDUSB:
+- 			len = getBridgePacketInt32(bp, 1);
+- 
+--			if (len > (int)phid->OUTPacketLength[0])
+--				len = (int)phid->OUTPacketLength[0];
+-+			if (len > (size_t)phid->OUTPacketLength[0])
+-+				len = (size_t)phid->OUTPacketLength[0];
+- 
+- 			ret = PhidgetDevice_transferpacket(bp->iop, (PhidgetDeviceHandle)phid, PHIDGETUSB_REQ_DEVICE_READ,
+- 				getBridgePacketInt32(bp, 0), 0,
+-diff -urp libphidget22-1.6.20200417.orig/src/phidget.c libphidget22-1.6.20200417/src/phidget.c
+---- libphidget22-1.6.20200417.orig/src/phidget.c	2020-04-17 21:50:39.000000000 +0000
+-+++ libphidget22-1.6.20200417/src/phidget.c	2020-06-02 13:30:49.607480749 +0000
+-@@ -2317,7 +2317,7 @@ createPhidgetHIDUSBDevice(const PhidgetU
+- #ifdef _WINDOWS
+- 	wcsncpy(conn->DevicePath, (const wchar_t *)devpath, MAX_PATH);
+- #elif defined(_LINUX) || defined(_FREEBSD) && !defined(_ANDROID)
+--	strncpy(conn->uniqueName, (const char *)devpath, 20);
+-+	strncpy(conn->uniqueName, (const char *)devpath, 19);
+- #endif
+- #if defined(_ANDROID)
+- 	mos_strncpy(conn->dev, (const char *)devpath, sizeof(conn->dev));
+-@@ -2348,7 +2348,7 @@ createPhidgetPHIDUSBDevice(const Phidget
+- #ifdef _WINDOWS
+- 	wcsncpy(conn->DevicePath, (const wchar_t *)devpath, MAX_PATH);
+- #elif defined(_LINUX) || defined(_FREEBSD) && !defined(_ANDROID)
+--	strncpy(conn->uniqueName, (const char *)devpath, 20);
+-+	strncpy(conn->uniqueName, (const char *)devpath, 19);
+- #endif
+- #if defined(_ANDROID)
+- 	mos_strncpy(conn->dev, (const char *)devpath, sizeof(conn->dev));

From 122764a72cd8b21d9366f29647050d2cd2517eb0 Mon Sep 17 00:00:00 2001
From: Martin Jansa <martin.jansa@lge.com>
Date: Wed, 18 Dec 2019 11:11:30 -0800
Subject: [PATCH] Use libphidget22 from libphidget22-upstream and normal prefix


Signed-off-by: Martin Jansa <martin.jansa@lge.com>
---
 CMakeLists.txt                                |  37 +--
 cmake/libphidget22-extras.cmake.in            |   4 +-
 ...phidgets22-1.6.20200417-fix-warnings.patch | 260 ------------------
 3 files changed, 3 insertions(+), 298 deletions(-)
 delete mode 100644 patch/libphidgets22-1.6.20200417-fix-warnings.patch

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 462ee7f..706e59a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -3,41 +3,6 @@ project(libphidget22)
 
 find_package(ament_cmake REQUIRED)
 
-set(extra_c_flags "-g -O2 -Wno-incompatible-pointer-types -Wno-deprecated-declarations -Wno-format-truncation -fPIC")
-
-include(ExternalProject)
-ExternalProject_Add(EP_${PROJECT_NAME}
-    URL https://www.phidgets.com/downloads/phidget22/libraries/linux/libphidget22/libphidget22-1.6.20200417.tar.gz
-    URL_MD5 f8c85f8348ddc0fb46146c0d9d8f884e
-
-    PATCH_COMMAND patch -p1 < ${CMAKE_CURRENT_SOURCE_DIR}/patch/libphidgets22-1.6.20200417-fix-warnings.patch
-    SOURCE_DIR ${PROJECT_BINARY_DIR}/${PROJECT_NAME}-src
-    CONFIGURE_COMMAND
-      <SOURCE_DIR>/configure
-      CFLAGS=${extra_c_flags}
-      --prefix=${CMAKE_CURRENT_BINARY_DIR}/libphidget22_install
-      --disable-ldconfig
-    BUILD_COMMAND $(MAKE)
-    INSTALL_COMMAND $(MAKE) install
-)
