summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHelmut Schmidt <Helmut.3.Schmidt@continental-corporation.com>2016-02-11 12:45:36 +0100
committerHelmut Schmidt <Helmut.3.Schmidt@continental-corporation.com>2016-02-11 12:45:36 +0100
commit76787a4257cdbfb52474daec5b73700da99466c2 (patch)
treeeb138a8175b3a19f05f4d4e86e29ecebd0141ccb
parent699a2a36eb164598b63b2a07d7d28d9e932119ae (diff)
downloadpositioning-76787a4257cdbfb52474daec5b73700da99466c2.tar.gz
Positioning PoC: improve check for i2c-dev.h
-rw-r--r--sensors-service/src/CMakeLists.txt5
-rw-r--r--sensors-service/src/i2ccomm.cpp14
2 files changed, 13 insertions, 6 deletions
diff --git a/sensors-service/src/CMakeLists.txt b/sensors-service/src/CMakeLists.txt
index 1c0975b..1dbbadf 100644
--- a/sensors-service/src/CMakeLists.txt
+++ b/sensors-service/src/CMakeLists.txt
@@ -73,11 +73,6 @@ elseif(WITH_SENSORS)
)
if (I2CDEV_H)
message(STATUS "I2CDEV found: ${I2CDEV_H}")
-
- #TODO remove the following line
- # - when i2c-dev.h detection really works (there seem to be 2 variants of i2c-dev.h and only 1 is OK)
- # - in case you really have the correct version of i2c-dev.h
- add_definitions(-DI2C_NOT_AVAILABLE)
else (I2CDEV_H)
message(STATUS "I2CDEV not found")
add_definitions(-DI2C_NOT_AVAILABLE)
diff --git a/sensors-service/src/i2ccomm.cpp b/sensors-service/src/i2ccomm.cpp
index 346eb29..4a87bb8 100644
--- a/sensors-service/src/i2ccomm.cpp
+++ b/sensors-service/src/i2ccomm.cpp
@@ -21,8 +21,20 @@
#include "i2ccomm.h"
//linux i2c access
+#ifndef I2C_NOT_AVAILABLE
#include <linux/i2c-dev.h> //RPi: located in /usr/include/linux/i2c-dev.h - all functions inline
-
+//Unfortunately, there are two files named "i2c-dev.h" out there
+//Only the one provided by packages libi2c-dev or i2c-tools provides all necessary definitions
+// http://lxr.free-electrons.com/source/Documentation/i2c/dev-interface?v=3.7
+// http://raspberrypi.stackexchange.com/questions/37689/how-do-i-use-the-i2c-bus
+//So we have to test explicitly and set #define I2C_NOT_AVAILABLE if the wrong header is available
+#ifndef I2C_M_RD
+//seems that the wrong i2c-dev.h version has been included
+#define I2C_NOT_AVAILABLE
+#warning "i2c-dev.h wrong version - disabling I2C functionality during runtime"
+#warning "Please install correct version, typically available in packages libi2c-dev or i2c-tools"
+#endif
+#endif
//standard c library functions
#include <unistd.h>
#include <fcntl.h>