diff --git a/CMakeLists.txt b/CMakeLists.txt index ffe909b..d0a6144 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,12 +2,19 @@ cmake_minimum_required(VERSION 3.0) project(mynteye VERSION 2.0.0 LANGUAGES C CXX) +include(cmake/Common.cmake) + # options # flags -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra") -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra") +if(OS_WIN) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") +else() + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra") +endif() include(cmake/DetectCXX11.cmake) @@ -41,7 +48,7 @@ configure_file( # targets -include(cmake/Common.cmake) +add_definitions(-DMYNTEYE_EXPORTS) set(OUT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/_output") set_outdir( diff --git a/Makefile b/Makefile index a91110e..5a6997f 100644 --- a/Makefile +++ b/Makefile @@ -79,7 +79,15 @@ test: install install: build @$(call echo,Make $@) +ifeq ($(HOST_OS),Win) +ifneq ($(HOST_NAME),MinGW) + @cd ./_build; msbuild.exe INSTALL.vcxproj /property:Configuration=Release +else @cd ./_build; make install +endif +else + @cd ./_build; make install +endif .PHONY: install @@ -103,7 +111,11 @@ tools: install ros: install @$(call echo,Make $@) +ifeq ($(HOST_OS),Win) + $(error "Can't make ros on win") +else @cd ./wrappers/ros && catkin_make +endif .PHONY: ros diff --git a/doc/zh-Hans/api.doxyfile b/doc/zh-Hans/api.doxyfile index d92f85e..00d13a4 100644 --- a/doc/zh-Hans/api.doxyfile +++ b/doc/zh-Hans/api.doxyfile @@ -793,6 +793,7 @@ WARN_LOGFILE = INPUT = mainpage.md \ guides.md \ guide_build_linux.md \ + guide_build_win.md \ guide_samples.md \ guide_tools.md \ guide_log.md \ diff --git a/doc/zh-Hans/guide_build_linux.md b/doc/zh-Hans/guide_build_linux.md index 86c9090..1fa95ec 100644 --- a/doc/zh-Hans/guide_build_linux.md +++ b/doc/zh-Hans/guide_build_linux.md @@ -1,5 +1,7 @@ # 编译 on Linux {#guide_build_linux} +> Ubuntu 16.04, Ubuntu 14.04 + ## 获取代码 ```bash diff --git a/doc/zh-Hans/guide_build_win.md b/doc/zh-Hans/guide_build_win.md new file mode 100644 index 0000000..713f8f1 --- /dev/null +++ b/doc/zh-Hans/guide_build_win.md @@ -0,0 +1,103 @@ +# 编译 on Windows {#guide_build_win} + +> Windows 10 + +## 前提条件 + +* [Git](https://git-scm.com/downloads),用于获取代码。 +* [CMake](https://cmake.org/download/),用于构建编译。 +* [Doxygen](http://www.stack.nl/~dimitri/doxygen/download.html),用于生成文档。 + +最终,命令提示符(Command Prompt, cmd)里可找到如下命令: + +```cmd +>cmake --version +cmake version 3.10.1 + +>git --version +git version 2.11.1.windows.1 + +>doxygen --version +1.8.13 +``` + +* [Visual Studio](https://www.visualstudio.com/) + * [Visual Studio 2015](https://my.visualstudio.com/Downloads?q=Visual Studio 2015) + * [Visual Studio 2017](https://my.visualstudio.com/Downloads?q=Visual Studio 2017) +* [Windows 10 SDK](https://developer.microsoft.com/en-US/windows/downloads/windows-10-sdk) + +以 Visual Studio 2015 举例,请在系统环境变量 `PATH` 里添加上如下路径: + + C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin + C:\Program Files (x86)\MSBuild\14.0\Bin + +最终,命令提示符(Command Prompt, cmd)里可找到如下命令: + +```cmd +>cl +Microsoft (R) C/C++ Optimizing Compiler Version 19.00.24215.1 for x86 + +>link +Microsoft (R) Incremental Linker Version 14.00.24215.1 + +>lib +Microsoft (R) Library Manager Version 14.00.24215.1 + +>msbuild +Microsoft (R) 生成引擎版本 14.0.25420.1 +``` + +* [MSYS2](http://www.msys2.org/) + * [国内镜像](https://lug.ustc.edu.cn/wiki/mirrors/help/msys2) + * [pacman](https://wiki.archlinux.org/index.php/pacman) + +打开 MSYS2 MSYS ,然后执行: + +```msys +$ pacman -Syu +$ pacman -S make +``` + +并在系统环境变量 `PATH` 里添加上如下路径: + + C:\msys64\usr\bin + +最终,命令提示符(Command Prompt, cmd)里可找到如下命令: + +```cmd +>make --version +GNU Make 4.2.1 +``` + +## 获取代码 + +```cmd +>git clone https://github.com/slightech/MYNT-EYE-SDK-2.git +``` + +## 准备依赖 + +```cmd +>cd mynt-eye-sdk-2 +>make init +Make init +Init deps +Install cmd: pacman -S +Install deps: git clang-format +pacman -S clang-format (not exists) +error: target not found: clang-format +pip install --upgrade autopep8 cpplint pylint requests +... +Init git hooks +ERROR: clang-format-diff is not installed! +Expect cmake version >= 3.0 +cmake version 3.10.1 +How to upgrade cmake in Ubuntu + https://askubuntu.com/questions/829310/how-to-upgrade-cmake-in-ubuntu +``` + +## 编译代码 + +```cmd +>make install +``` diff --git a/doc/zh-Hans/guide_samples.md b/doc/zh-Hans/guide_samples.md index 5f831eb..ba4653e 100644 --- a/doc/zh-Hans/guide_samples.md +++ b/doc/zh-Hans/guide_samples.md @@ -12,6 +12,12 @@ * [OpenCV](https://opencv.org/),用于显示图像。 + + ## 编译 ```bash diff --git a/doc/zh-Hans/guides.md b/doc/zh-Hans/guides.md index b1b46b7..39ae5c4 100644 --- a/doc/zh-Hans/guides.md +++ b/doc/zh-Hans/guides.md @@ -1,6 +1,7 @@ # SDK 指导 {#guides} * @subpage guide_build_linux +* @subpage guide_build_win * @subpage guide_samples * @subpage guide_tools * @subpage guide_log diff --git a/include/mynteye/callbacks.h b/include/mynteye/callbacks.h index 79a6d74..4a2cb6f 100644 --- a/include/mynteye/callbacks.h +++ b/include/mynteye/callbacks.h @@ -16,7 +16,7 @@ MYNTEYE_BEGIN_NAMESPACE namespace device { -class Frame { +class MYNTEYE_API Frame { public: using data_t = std::vector; diff --git a/include/mynteye/types.h b/include/mynteye/types.h index 7b97cce..992fd31 100644 --- a/include/mynteye/types.h +++ b/include/mynteye/types.h @@ -166,7 +166,7 @@ enum class Source : std::uint8_t { }; #define MYNTEYE_ENUM_HELPERS(TYPE) \ - const char *to_string(const TYPE &value); \ + MYNTEYE_API const char *to_string(const TYPE &value); \ inline bool is_valid(const TYPE &value) { \ using utype = std::underlying_type::type; \ utype val = static_cast(value); \ @@ -209,13 +209,13 @@ enum class Format : std::uint32_t { #undef MYNTEYE_FOURCC -const char *to_string(const Format &value); +MYNTEYE_API const char *to_string(const Format &value); inline std::ostream &operator<<(std::ostream &os, const Format &value) { return os << to_string(value); } -std::size_t bytes_per_pixel(const Format &value); +MYNTEYE_API std::size_t bytes_per_pixel(const Format &value); /** * Stream request. @@ -239,6 +239,7 @@ struct MYNTEYE_API StreamRequest { } }; +MYNTEYE_API std::ostream &operator<<(std::ostream &os, const StreamRequest &request); /** @@ -269,6 +270,7 @@ struct MYNTEYE_API Intrinsics { double coeffs[5]; }; +MYNTEYE_API std::ostream &operator<<(std::ostream &os, const Intrinsics &in); /** @@ -291,6 +293,7 @@ struct MYNTEYE_API ImuIntrinsics { double bias[3]; }; +MYNTEYE_API std::ostream &operator<<(std::ostream &os, const ImuIntrinsics &in); /** @@ -302,6 +305,7 @@ struct MYNTEYE_API MotionIntrinsics { ImuIntrinsics gyro; }; +MYNTEYE_API std::ostream &operator<<(std::ostream &os, const MotionIntrinsics &in); /** @@ -313,6 +317,7 @@ struct MYNTEYE_API Extrinsics { double translation[3]; /**< translation vector */ }; +MYNTEYE_API std::ostream &operator<<(std::ostream &os, const Extrinsics &ex); /** diff --git a/include/mynteye/utils.h b/include/mynteye/utils.h index a3c05a4..80371c5 100644 --- a/include/mynteye/utils.h +++ b/include/mynteye/utils.h @@ -13,7 +13,7 @@ class Device; namespace device { /** Detecting MYNT EYE devices and prompt user to select one */ -std::shared_ptr select(); +MYNTEYE_API std::shared_ptr select(); } // namespace device diff --git a/samples/CMakeLists.txt b/samples/CMakeLists.txt index 4093677..60706b1 100644 --- a/samples/CMakeLists.txt +++ b/samples/CMakeLists.txt @@ -4,10 +4,17 @@ project(mynteye_samples VERSION 2.0.0 LANGUAGES C CXX) get_filename_component(PRO_DIR ${PROJECT_SOURCE_DIR} DIRECTORY) +include(${PRO_DIR}/cmake/Common.cmake) + # flags -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra") -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra") +if(OS_WIN) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") +else() + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra") +endif() include(${PRO_DIR}/cmake/DetectCXX11.cmake) @@ -36,8 +43,6 @@ message(STATUS "Found OpenCV: ${OpenCV_VERSION}") # targets -include(${PRO_DIR}/cmake/Common.cmake) - set(OUT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/_output") # samples above device layer diff --git a/src/device/context.h b/src/device/context.h index 7e12fce..e4eb409 100644 --- a/src/device/context.h +++ b/src/device/context.h @@ -17,7 +17,7 @@ struct context; class Device; -class Context { +class MYNTEYE_API Context { public: Context(); ~Context(); diff --git a/src/device/device.h b/src/device/device.h index ce57c14..a504d6c 100644 --- a/src/device/device.h +++ b/src/device/device.h @@ -33,7 +33,7 @@ class Channels; class Motions; class Streams; -class Device { +class MYNTEYE_API Device { public: using stream_callback_t = device::StreamCallback; using motion_callback_t = device::MotionCallback; diff --git a/src/internal/channels.h b/src/internal/channels.h index e887f22..8177d22 100644 --- a/src/internal/channels.h +++ b/src/internal/channels.h @@ -21,7 +21,7 @@ struct xu; } // namespace uvc -class Channels { +class MYNTEYE_API Channels { public: typedef enum Channel { CHANNEL_CAM_CTRL = 0x0100, diff --git a/src/internal/files.h b/src/internal/files.h index bd63099..3f963e7 100644 --- a/src/internal/files.h +++ b/src/internal/files.h @@ -10,7 +10,7 @@ MYNTEYE_BEGIN_NAMESPACE namespace files { -bool mkdir(const std::string &path); +MYNTEYE_API bool mkdir(const std::string &path); } // namespace files diff --git a/src/internal/strings.h b/src/internal/strings.h index d6c7d03..89c6eac 100644 --- a/src/internal/strings.h +++ b/src/internal/strings.h @@ -11,7 +11,7 @@ MYNTEYE_BEGIN_NAMESPACE -class strings_error : public std::runtime_error { +class MYNTEYE_API strings_error : public std::runtime_error { public: explicit strings_error(const std::string &what_arg) noexcept : std::runtime_error(std::move(what_arg)) {} @@ -21,17 +21,21 @@ class strings_error : public std::runtime_error { namespace strings { +MYNTEYE_API int hex2int(const std::string &text); +MYNTEYE_API bool starts_with(const std::string &text, const std::string &prefix); +MYNTEYE_API std::vector split( const std::string &text, const std::string &delimiters); -void ltrim(std::string &s); // NOLINT -void rtrim(std::string &s); // NOLINT -void trim(std::string &s); // NOLINT +MYNTEYE_API void ltrim(std::string &s); // NOLINT +MYNTEYE_API void rtrim(std::string &s); // NOLINT +MYNTEYE_API void trim(std::string &s); // NOLINT +MYNTEYE_API std::string trim_copy(const std::string &text); } // namespace strings diff --git a/src/internal/types.h b/src/internal/types.h index 6b740bd..6f67aa1 100644 --- a/src/internal/types.h +++ b/src/internal/types.h @@ -28,7 +28,7 @@ MYNTEYE_BEGIN_NAMESPACE /** * Version. */ -class Version { +class MYNTEYE_API Version { public: using size_t = std::size_t; using value_t = std::uint8_t; @@ -77,7 +77,7 @@ class Version { /** * Hardware version. */ -class HardwareVersion : public Version { +class MYNTEYE_API HardwareVersion : public Version { public: using flag_t = std::bitset<8>; @@ -93,7 +93,7 @@ class HardwareVersion : public Version { /** * Type. */ -class Type { +class MYNTEYE_API Type { public: using size_t = std::size_t; using value_t = std::uint16_t; @@ -115,7 +115,7 @@ class Type { * @ingroup datatypes * Device infomation. */ -struct DeviceInfo { +struct MYNTEYE_API DeviceInfo { std::string name; std::string serial_number; Version firmware_version; diff --git a/src/uvc/uvc-wmf.cc b/src/uvc/uvc-wmf.cc new file mode 100644 index 0000000..8200e7d --- /dev/null +++ b/src/uvc/uvc-wmf.cc @@ -0,0 +1,116 @@ +#include "uvc/uvc.h" // NOLINT + +#include + +MYNTEYE_BEGIN_NAMESPACE + +namespace uvc { + +struct context { + context() { + VLOG(2) << __func__; + } + + ~context() { + VLOG(2) << __func__; + } +}; + +struct device { + const std::shared_ptr parent; + + int vid, pid; + + device(std::shared_ptr parent) : parent(parent) { + VLOG(2) << __func__; + } + + ~device() { + VLOG(2) << __func__; + } +}; + +std::shared_ptr create_context() { + return std::make_shared(); +} + +std::vector> query_devices( + std::shared_ptr context) { + std::vector> devices; + UNUSED(context) + return devices; +} + +int get_vendor_id(const device &device) { + return device.vid; +} + +int get_product_id(const device &device) { + return device.pid; +} + +std::string get_name(const device &device) { + UNUSED(device) + return ""; +} + +std::string get_video_name(const device &device) { + UNUSED(device) + return ""; +} + +bool pu_control_range( + const device &device, Option option, int32_t *min, int32_t *max, + int32_t *def) { + UNUSED(device) + UNUSED(option) + UNUSED(min) + UNUSED(max) + UNUSED(def) + return false; +} + +bool pu_control_query( + const device &device, Option option, pu_query query, int32_t *value) { + UNUSED(device) + UNUSED(option) + UNUSED(query) + UNUSED(value) + return false; +} + +bool xu_control_query( + const device &device, const xu &xu, uint8_t selector, xu_query query, + uint16_t size, uint8_t *data) { + UNUSED(device) + UNUSED(xu) + UNUSED(selector) + UNUSED(query) + UNUSED(size) + UNUSED(data) + return false; +} + +void set_device_mode( + device &device, int width, int height, int fourcc, int fps, // NOLINT + video_channel_callback callback) { + UNUSED(device) + UNUSED(width) + UNUSED(height) + UNUSED(fourcc) + UNUSED(fps) + UNUSED(callback) +} + +void start_streaming(device &device, int num_transfer_bufs) { // NOLINT + UNUSED(device) + UNUSED(num_transfer_bufs) +} + +void stop_streaming(device &device) { // NOLINT + UNUSED(device) +} + +} // namespace uvc + +MYNTEYE_END_NAMESPACE diff --git a/src/uvc/uvc.h b/src/uvc/uvc.h index 62666c7..d0f6466 100644 --- a/src/uvc/uvc.h +++ b/src/uvc/uvc.h @@ -24,7 +24,7 @@ typedef enum pu_query { } pu_query; // Extension Unit -struct xu { +struct MYNTEYE_API xu { uint8_t unit; }; @@ -42,40 +42,40 @@ struct context; // Opaque type representing access to the underlying UVC struct device; // Opaque type representing access to a specific UVC device // Enumerate devices -std::shared_ptr create_context(); -std::vector> query_devices( +MYNTEYE_API std::shared_ptr create_context(); +MYNTEYE_API std::vector> query_devices( std::shared_ptr context); // Static device properties -std::string get_name(const device &device); -int get_vendor_id(const device &device); -int get_product_id(const device &device); +MYNTEYE_API std::string get_name(const device &device); +MYNTEYE_API int get_vendor_id(const device &device); +MYNTEYE_API int get_product_id(const device &device); -std::string get_video_name(const device &device); +MYNTEYE_API std::string get_video_name(const device &device); // Access PU (Processing Unit) controls inline bool is_pu_control(Option option) { return option >= Option::GAIN && option <= Option::CONTRAST; } -bool pu_control_range( +MYNTEYE_API bool pu_control_range( const device &device, Option option, int32_t *min, int32_t *max, int32_t *def); -bool pu_control_query( +MYNTEYE_API bool pu_control_query( const device &device, Option option, pu_query query, int32_t *value); // Access XU (Extension Unit) controls -bool xu_control_query( +MYNTEYE_API bool xu_control_query( const device &device, const xu &xu, uint8_t selector, xu_query query, uint16_t size, uint8_t *data); // Control streaming typedef std::function video_channel_callback; -void set_device_mode( +MYNTEYE_API void set_device_mode( device &device, int width, int height, int fourcc, int fps, // NOLINT video_channel_callback callback); -void start_streaming(device &device, int num_transfer_bufs); // NOLINT -void stop_streaming(device &device); // NOLINT +MYNTEYE_API void start_streaming(device &device, int num_transfer_bufs); // NOLINT +MYNTEYE_API void stop_streaming(device &device); // NOLINT } // namespace uvc diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 9b48da0..95a7c32 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -4,10 +4,17 @@ project(mynteye_test VERSION 2.0.0 LANGUAGES C CXX) get_filename_component(PRO_DIR ${PROJECT_SOURCE_DIR} DIRECTORY) +include(${PRO_DIR}/cmake/Common.cmake) + # flags -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra") -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra") +if(OS_WIN) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") +else() + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra") +endif() include(${PRO_DIR}/cmake/DetectCXX11.cmake) @@ -51,8 +58,6 @@ message(STATUS "Found gtest libs: ${GTEST_LIBS}") # targets -include(${PRO_DIR}/cmake/Common.cmake) - set(OUT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/_output") set_outdir( diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 3f12957..ff84179 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -4,10 +4,17 @@ project(mynteye_tools VERSION 2.0.0 LANGUAGES C CXX) get_filename_component(PRO_DIR ${PROJECT_SOURCE_DIR} DIRECTORY) +include(${PRO_DIR}/cmake/Common.cmake) + # flags -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra") -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra") +if(OS_WIN) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") +else() + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra") +endif() include(${PRO_DIR}/cmake/DetectCXX11.cmake) @@ -41,8 +48,6 @@ endif() # targets -include(${PRO_DIR}/cmake/Common.cmake) - set(OUT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/_output") include_directories(