Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CMakeLists.txt #53

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
*.o
*.a
/C++/Build
build/
C++/.idea/
C++/cmake-build-release/
26 changes: 26 additions & 0 deletions C++/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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} )


File renamed without changes.
60 changes: 60 additions & 0 deletions C++/Navio/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
#)
24 changes: 12 additions & 12 deletions C++/Navio/Common/I2Cdev.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,34 +375,34 @@ 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);
count = write(fd, buf, length+1);
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.
Expand All @@ -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++) {
Expand All @@ -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.
Expand Down
5 changes: 0 additions & 5 deletions C++/Navio/Common/I2Cdev.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,6 @@ THE SOFTWARE.

#define I2CDEV RASPBERRY_PI_I2C

#ifndef TRUE
#define TRUE (1==1)
#define FALSE (0==1)
#endif

#include <stdint.h>

class I2Cdev {
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`