diff --git a/.gitignore b/.gitignore index ce536c60..3435aedf 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ *.o *.a /C++/Build +build/ +C++/.idea/ +C++/cmake-build-release/ \ No newline at end of file diff --git a/C++/CMakeLists.txt b/C++/CMakeLists.txt new file mode 100644 index 00000000..5957f9a0 --- /dev/null +++ b/C++/CMakeLists.txt @@ -0,0 +1,26 @@ +cmake_minimum_required(VERSION 2.8.3) +project(navio2_cpp) + +set (CMAKE_CXX_STANDARD 14) + +add_subdirectory(Navio) + +include_directories(Examples) + +set(EXMPL_SRCS + AccelGyroMag.cpp + ADC.cpp + AHRS.cpp + Barometer.cpp + LED.cpp + RCInput.cpp + Servo.cpp + threaded_baro.cpp) + +foreach( testsourcefile ${EXMPL_SRCS} ) + string( REPLACE ".cpp" "" testname ${testsourcefile} ) + add_executable( ${testname} Examples/${testsourcefile} ) + target_link_libraries( ${testname} navio pigpio pthread ) +endforeach( testsourcefile ${EXMPL_SRCS} ) + + diff --git a/C++/Makefile b/C++/Makefile.bak similarity index 100% rename from C++/Makefile rename to C++/Makefile.bak diff --git a/C++/Navio/CMakeLists.txt b/C++/Navio/CMakeLists.txt new file mode 100644 index 00000000..99c5ecff --- /dev/null +++ b/C++/Navio/CMakeLists.txt @@ -0,0 +1,60 @@ +cmake_minimum_required(VERSION 2.8.3) +project(navio) + +set(CMAKE_CXX_STANDARD 14) + +include_directories( + Common + Navio+ + Navio2 + pigpio +) + + +set(DEFAULT_BUILD_TYPE "Release") +if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) + message(STATUS "Setting build type to '${DEFAULT_BUILD_TYPE}' as none was specified.") + set(CMAKE_BUILD_TYPE "${DEFAULT_BUILD_TYPE}" CACHE STRING "Choose the type of build." FORCE) + # Set the possible values of build type for cmake-gui + set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo") +endif () + +include(GNUInstallDirs) + +add_subdirectory(pigpio) + +set(SOURCE_FILES + Common/I2Cdev.cpp + Common/MPU9250.cpp + Common/MS5611.cpp + Common/Ublox.cpp + Common/Util.cpp + Common/gpio.cpp + Navio2/ADC_Navio2.cpp + Navio2/LSM9DS1.cpp + Navio2/Led_Navio2.cpp + Navio2/PWM.cpp + Navio2/RCInput_Navio2.cpp + Navio2/RCOutput_Navio2.cpp + Navio2/RGBled.cpp + Navio+/ADC_Navio.cpp + Navio+/ADS1115.cpp + Navio+/Led_Navio.cpp + Navio+/MB85RC256.cpp + Navio+/PCA9685.cpp + Navio+/RCInput_Navio.cpp + Navio+/RCOutput_Navio.cpp + ) + +add_library(navio SHARED ${SOURCE_FILES}) +target_include_directories(navio PUBLIC . Navio+ Navio2 Common pigpio) + +# set_target_properties(navio PROPERTIES PUBLIC_HEADER ${HEADER_FILES}) +#install(TARGETS navio +# LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} +# PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) +#install(DIRECTORY "${CMAKE_SOURCE_DIR}/" # source directory +# DESTINATION "include" # target directory +# FILES_MATCHING # install only matched files +# PATTERN "*.h" # select header files +#) diff --git a/C++/Navio/Common/I2Cdev.cpp b/C++/Navio/Common/I2Cdev.cpp index 00b985ef..5d69c10c 100644 --- a/C++/Navio/Common/I2Cdev.cpp +++ b/C++/Navio/Common/I2Cdev.cpp @@ -375,18 +375,18 @@ bool I2Cdev::writeBytes(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint8_ if (length > 127) { fprintf(stderr, "Byte write count (%d) > 127\n", length); - return(FALSE); + return(false); } fd = open(I2CDEV , O_RDWR); if (fd < 0) { fprintf(stderr, "Failed to open device: %s\n", strerror(errno)); - return(FALSE); + return(false); } if (ioctl(fd, I2C_SLAVE, devAddr) < 0) { fprintf(stderr, "Failed to select device: %s\n", strerror(errno)); close(fd); - return(FALSE); + return(false); } buf[0] = regAddr; memcpy(buf+1,data,length); @@ -394,15 +394,15 @@ bool I2Cdev::writeBytes(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint8_ if (count < 0) { fprintf(stderr, "Failed to write device(%d): %s\n", count, ::strerror(errno)); close(fd); - return(FALSE); + return(false); } else if (count != length+1) { fprintf(stderr, "Short write to device, expected %d, got %d\n", length+1, count); close(fd); - return(FALSE); + return(false); } close(fd); - return TRUE; + return true; } /** Write multiple words to a 16-bit device register. @@ -422,18 +422,18 @@ bool I2Cdev::writeWords(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint16 if (length > 63) { fprintf(stderr, "Word write count (%d) > 63\n", length); - return(FALSE); + return(false); } fd = open(I2CDEV, O_RDWR); if (fd < 0) { fprintf(stderr, "Failed to open device: %s\n", strerror(errno)); - return(FALSE); + return(false); } if (ioctl(fd, I2C_SLAVE, devAddr) < 0) { fprintf(stderr, "Failed to select device: %s\n", strerror(errno)); close(fd); - return(FALSE); + return(false); } buf[0] = regAddr; for (i = 0; i < length; i++) { @@ -444,14 +444,14 @@ bool I2Cdev::writeWords(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint16 if (count < 0) { fprintf(stderr, "Failed to write device(%d): %s\n", count, ::strerror(errno)); close(fd); - return(FALSE); + return(false); } else if (count != length*2+1) { fprintf(stderr, "Short write to device, expected %d, got %d\n", length+1, count); close(fd); - return(FALSE); + return(false); } close(fd); - return TRUE; + return true; } /** Default timeout value for read operations. diff --git a/C++/Navio/Common/I2Cdev.h b/C++/Navio/Common/I2Cdev.h index ea32d1ed..b75b2706 100644 --- a/C++/Navio/Common/I2Cdev.h +++ b/C++/Navio/Common/I2Cdev.h @@ -49,11 +49,6 @@ THE SOFTWARE. #define I2CDEV RASPBERRY_PI_I2C -#ifndef TRUE -#define TRUE (1==1) -#define FALSE (0==1) -#endif - #include class I2Cdev { diff --git a/README.md b/README.md index bac61347..07157e31 100644 --- a/README.md +++ b/README.md @@ -63,3 +63,12 @@ Applications and utilities for Navio. * `export CXX=arm-linux-gnueabihf-g++` * Compile the examples via `make` +* CMake install + - `$ cd C++/Navio` + - `$ mkdir build && cd build` + - `$ cmake ..` + - `$ make` + - `$ sudo make install` +* Running example + - `$ cd C++/Examples` + - `$ g++ AccelGyroMag.cpp -o out -lnavio`