# HG changeset patch # User František Kučera # Date 1565792218 -7200 # Node ID 6ff501639c23ae23366bafd53dcc0e102accb851 project skeleton, open USB HID device diff -r 000000000000 -r 6ff501639c23 .hgignore --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.hgignore Wed Aug 14 16:16:58 2019 +0200 @@ -0,0 +1,13 @@ +syntax: glob + +*~ +CMakeLists.txt.user + +syntax: regexp + +^temp/ + +^\.dep\.inc +^dist/ +^build/ +^nbproject/private/ diff -r 000000000000 -r 6ff501639c23 CMakeLists.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CMakeLists.txt Wed Aug 14 16:16:58 2019 +0200 @@ -0,0 +1,3 @@ +project (cadMousePro) +cmake_minimum_required(VERSION 2.8) +add_subdirectory (src) diff -r 000000000000 -r 6ff501639c23 nbproject/configurations.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nbproject/configurations.xml Wed Aug 14 16:16:58 2019 +0200 @@ -0,0 +1,136 @@ + + + + + + + cadMousePro.cpp + + + + CMakeLists.txt + build/Debug/Makefile + build/Release/Makefile + + + ^(nbproject|build)$ + + . + + build/Debug/Makefile + + + + default + false + false + + + + + + + + + build/Debug + ${MAKE} -f Makefile + ${MAKE} -f Makefile clean + build/Debug/src/welcome + + + /usr/include/hidapi + build/Debug/src + + + + + build/Debug + ${CMAKE} -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=${IDE_CC} -DCMAKE_CXX_COMPILER=${IDE_CXX} -DCMAKE_EXPORT_COMPILE_COMMANDS=ON ../.. + true + + + + + + + + + + default + false + false + + + + + + + + + build/Release + ${MAKE} -f Makefile + ${MAKE} -f Makefile clean + build/Release/src/welcome + + + build/Release/src + + + NDEBUG + + + + + build/Release + ${CMAKE} -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=${IDE_CC} -DCMAKE_CXX_COMPILER=${IDE_CXX} -DCMAKE_EXPORT_COMPILE_COMMANDS=ON ../.. + true + + + + + + + + + diff -r 000000000000 -r 6ff501639c23 nbproject/project.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nbproject/project.xml Wed Aug 14 16:16:58 2019 +0200 @@ -0,0 +1,72 @@ + + + + org.netbeans.modules.cnd.makeproject + + + cadMousePro + + cpp + + UTF-8 + + . + + + + . + + + + Debug + 0 + + + Release + 0 + + + + false + + + + diff -r 000000000000 -r 6ff501639c23 src/CMakeLists.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/CMakeLists.txt Wed Aug 14 16:16:58 2019 +0200 @@ -0,0 +1,21 @@ +set(EXECUTABLE_FILE "cadMousePro") + +# USB libraries: +INCLUDE(FindPkgConfig) +pkg_check_modules (USB_LIBS hidapi-hidraw) +include_directories(${USB_LIBS_INCLUDE_DIRS}) +link_directories(${USB_LIBS_LIBRARY_DIRS}) + +# Add ASan AddressSanitizer +set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address") +set(CMAKE_LINKER_FLAGS_DEBUG "${CMAKE_LINKER_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address") + +# Executable output: +add_executable( + ${EXECUTABLE_FILE} + cadMousePro.cpp +) + +# Link libraries: +target_link_libraries(${EXECUTABLE_FILE} ${USB_LIBS_LIBRARIES}) +set_property(TARGET ${EXECUTABLE_FILE} PROPERTY INSTALL_RPATH_USE_LINK_PATH TRUE) diff -r 000000000000 -r 6ff501639c23 src/cadMousePro.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/cadMousePro.cpp Wed Aug 14 16:16:58 2019 +0200 @@ -0,0 +1,49 @@ +#include + +#include + +class HIDException { +private: + std::wstring message; +public: + + HIDException(std::wstring message) : message(message) { + } + + virtual ~HIDException() { + } + + const std::wstring getMessage() const { + return message; + } + +}; + +class HIDDevice { +private: + hid_device* handle; +public: + + HIDDevice(unsigned short vendorId, unsigned short productId, const wchar_t *serialNumber) { + handle = hid_open(vendorId, productId, serialNumber); + if (handle == nullptr) throw HIDException(L"Unable to open HID device. Are you root? Is mouse present?"); + } + + virtual ~HIDDevice() { + hid_close(handle); + } + + +}; + +int main(int argc, char** argv) { + try { + + std::wcout << L"cadMousePro" << std::endl; + HIDDevice mouse(0x256f, 0xc652, nullptr); + std::wcout << L"mouse opened" << std::endl; + } catch (const HIDException& e) { + std::wcout << L"HIDException: " << e.getMessage() << std::endl; + + } +} \ No newline at end of file