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

Merge CMake machinery to master #1

Open
wants to merge 3 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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -398,4 +398,6 @@ FodyWeavers.xsd
# End of https://www.toptal.com/developers/gitignore/api/visualstudio

# Ignore docs generated by doxygen
generated_docs
generated_docs
/.vscode
build/
101 changes: 101 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
cmake_minimum_required(VERSION 3.5)
project(WeArtGloveLib
LANGUAGES CXX C
VERSION 1.0.0.0)

list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)

# Defines the CMAKE_INSTALL_LIBDIR, CMAKE_INSTALL_BINDIR and many other useful macros.
# See https://cmake.org/cmake/help/latest/module/GNUInstallDirs.html
include(GNUInstallDirs)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}")

set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
# Export symbols when on windows for making a SHARED lib
if(MSVC)
set(CMAKE_DEBUG_POSTFIX "d")
endif()

# Build position independent code.(PIC)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

# List of CPP (source) library files.
set(${PROJECT_NAME}_SRC
MiddlewareStatusListener.cpp
WeArtClient.cpp
WeArtEffect.cpp
WeArtHapticObject.cpp
WeArtMessages.cpp
WeArtMessageSerializer.cpp
WeArtAnalogSensorData.cpp
WeArtThimbleTrackingObject.cpp
WeArtTrackingCalibration.cpp
WeArtTrackingRawData.cpp
)

# Shared/Dynamic or Static library?
option(BUILD_SHARED_LIBS "Build libraries as shared as opposed to static" ON)

# List of HPP (header) library files.
set(${PROJECT_NAME}_HDR
MiddlewareStatusListener.h
WeArtClient.h
WeArtCommon.h
WeArtController.h
WeArtEffect.h
WeArtForce.h
WeArtHapticObject.h
WeArtMessageListener.h
WeArtMessages.h
WeArtMessageSerializer.h
WeArtAnalogSensorData.h
WeArtTemperature.h
WeArtTexture.h
WeArtThimbleTrackingObject.h
WeArtTrackingCalibration.h
WeArtTrackingRawData.h
WeArtGloveLib.h
nlohmann/json.hpp
)

# Add SHARED library with source *.cpp in src directory
add_library(${PROJECT_NAME} ${${PROJECT_NAME}_SRC} ${${PROJECT_NAME}_HDR})

# Enable RPATH support for installed binaries and libraries
include(AddInstallRPATHSupport)
add_install_rpath_support(BIN_DIRS "${CMAKE_INSTALL_FULL_BINDIR}"
LIB_DIRS "${CMAKE_INSTALL_FULL_LIBDIR}"
INSTALL_NAME_DIR "${CMAKE_INSTALL_FULL_LIBDIR}"
USE_LINK_PATH)


set_target_properties(${PROJECT_NAME} PROPERTIES VERSION ${${PROJECT_NAME}_VERSION}
PUBLIC_HEADER "${${PROJECT_NAME}_HDR}")
set_target_properties(${PROJECT_NAME} PROPERTIES
WIN32_EXECUTABLE TRUE
)

target_link_libraries(${PROJECT_NAME} windowsapp.lib runtimeobject.lib)

target_include_directories(${PROJECT_NAME} PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>"
"$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}>")

install(TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME}
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT shlib
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT lib
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" COMPONENT bin
PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}" COMPONENT dev)

include(InstallBasicPackageFiles)
install_basic_package_files(${PROJECT_NAME}
VERSION ${${PROJECT_NAME}_VERSION}
COMPATIBILITY AnyNewerVersion
VARS_PREFIX ${PROJECT_NAME}
NO_CHECK_REQUIRED_COMPONENTS_MACRO)

# Add the uninstall target
include(AddUninstallTarget)
31 changes: 29 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ The Weart Low-Level C++ SDK allows to connect to the Weart middleware and perfo
* Receive analog raw data from the thimble's senosrs
* Send haptic effects to the devices

## Installation
## Installation (classic)

Copy the source files (.cpp and .h) into your project folder and add them to your project.

Expand All @@ -17,6 +17,33 @@ On Visual Studio:
* Click "Add" -> "Existing Item..."
* Select all the sdk source files and click "Add"

## Installation (Cmake)

It is possible to compile and install the library using [``CMake``](https://cmake.org/),
```
cd WEART-SDK-Cpp
mkdir build
cd build
cmake -G"Visual Studio 17 2022" -DCMAKE_INSTALL_PREFIX=./install ..
cmake --build . --config Release --target INSTALL
```
With these commands, the library will be installed in the folder ``<prefix>/WEART-SDK-Cpp/build/install``.
It is possible to specify a different installation folder replacing ``./install`` after ``-DCMAKE_INSTALL_PREFIX=``.

In order to find the library in a ``CMake`` project you should set the following environment variables
```
set "PATH=%PATH%;<prefix>/WEART-SDK-Cpp/build/install/bin"
set "CMAKE_PREFIX_PATH=%CMAKE_PREFIX_PATH%;<prefix>/WEART-SDK-Cpp/build/install"
```
and in your ``CMakeLists.txt``
```
find_package(WeArtGloveLib REQUIRED)

# ...

target_link_libraries(yourTarget PRIVATE WeArtGloveLib::WeArtGloveLib)
```

## Documentation and references
For the documentation, go [here](https://weart.it/developer-guide/)

Expand All @@ -25,4 +52,4 @@ An example source code application is available [here](https://github.com/WEARTH

## Copyright

Copyright &copy; 2024 Weart S.r.l.
Copyright &copy; 2024 Weart S.r.l.
1 change: 0 additions & 1 deletion WeArtAnalogSensorData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* https://www.weart.it/
*/

#include "pch.h"
#include "WeArtAnalogSensorData.h"
#include "WeArtController.h"

Expand Down
42 changes: 32 additions & 10 deletions WeArtClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,22 @@
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <ws2tcpip.h>
#include <windows.h>


#include <ppltasks.h>
using namespace Windows::Foundation;

#include <roapi.h>
#include <wrl.h>

#include <Windows.Foundation.h>
#include <Windows.System.Threading.h>
#include <wrl/event.h>
#include <stdio.h>
#include <Objbase.h>

using namespace ABI::Windows::Foundation;
using namespace ABI::Windows::System::Threading;
using namespace Microsoft::WRL;
using namespace Microsoft::WRL::Wrappers;

// Need to link with Ws2_32.lib, Mswsock.lib, and Advapi32.lib
#pragma comment (lib, "Ws2_32.lib")
Expand Down Expand Up @@ -111,13 +122,24 @@ void WeArtClient::Run() {
Connected = true;
NotifyConnectionStatus(true);

// Initialize the Windows Runtime.
RoInitializeWrapper initialize(RO_INIT_MULTITHREADED);
ComPtr<IThreadPoolStatics> threadPool;
HRESULT hr = GetActivationFactory(HStringReference(RuntimeClass_Windows_System_Threading_ThreadPool).Get(), &threadPool);
Event threadCompleted(CreateEventEx(nullptr, nullptr, CREATE_EVENT_MANUAL_RESET, WRITE_OWNER | EVENT_ALL_ACCESS));
hr = threadCompleted.IsValid() ? S_OK : HRESULT_FROM_WIN32(GetLastError());

// receive data in background
auto workItem = ref new Windows::System::Threading::WorkItemHandler([this](IAsyncAction^ workItem) {
OnReceive();
});
// receive data in background
ComPtr<IAsyncAction> asyncAction;
hr = threadPool->RunAsync(Callback<IWorkItemHandler>([this, &threadCompleted](IAsyncAction* asyncAction) -> HRESULT
{
OnReceive();

auto asyncAction = Windows::System::Threading::ThreadPool::RunAsync(workItem);
// Set the completion event and return.
SetEvent(threadCompleted.Get());
return S_OK;

}).Get(), &asyncAction);

// Ask first middleware status
GetMiddlewareStatus getStatusMessage;
Expand Down Expand Up @@ -387,7 +409,7 @@ std::string WSAGetLastErrorString() {
int errorCode = WSAGetLastError();

LPWSTR errorBuffer = nullptr;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
nullptr, errorCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), reinterpret_cast<LPWSTR>(&errorBuffer), 0, nullptr);

std::wstring errorWString(errorBuffer);
Expand All @@ -406,4 +428,4 @@ std::string FormatWSAStartupError(int result) {
case WSAEFAULT: return "lpWSAData is not a valid pointer";
default: return "unknown error (code " + std::to_string(result) + ")";
}
}
}
3 changes: 3 additions & 0 deletions WeArtCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
#include <string>
#include "nlohmann/json.hpp"

#include <cstdint>
typedef uint8_t uint8;

enum class TrackingType {
DEFAULT, //!< Deprecated, contains only closure values
WEART_HAND, //!< Tracking with closures, and abduction value for thumb
Expand Down
31 changes: 31 additions & 0 deletions WeArtGloveLib.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#define NOMINMAX

#include <iostream>
#include <string>
#include <vector>
#include <ws2tcpip.h>
#include <stdlib.h>
#include <stdio.h>
#include <windows.h>
#include <ppltasks.h>
#include <algorithm>

#undef NOMINMAX
//WeArtSDK

#include"MiddlewareStatusListener.h"
#include"WeArtClient.h"
#include"WeArtCommon.h"
#include"WeArtController.h"
#include"WeArtEffect.h"
#include"WeArtForce.h"
#include"WeArtHapticObject.h"
#include"WeArtMessageListener.h"
#include"WeArtMessages.h"
#include"WeArtMessageSerializer.h"
#include"WeArtAnalogSensorData.h"
#include"WeArtTemperature.h"
#include"WeArtTexture.h"
#include"WeArtThimbleTrackingObject.h"
#include"WeArtTrackingCalibration.h"
#include"WeArtTrackingRawData.h"
4 changes: 2 additions & 2 deletions WeArtHapticObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ class WeArtHapticObject {
WeArtHapticObject(WeArtClient* client);

// Hand/finger state variables
int32 handSideFlag;
int32 actuationPointFlag;
int32_t handSideFlag;
int32_t actuationPointFlag;

// State variables. Serialized.
WeArtTemperature weArtTemperature;
Expand Down
2 changes: 1 addition & 1 deletion WeArtMessageSerializer.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "WeArtMessageSerializer.h"
#include <sstream>
#include "nlohmann/json.hpp"
#include <nlohmann/json.hpp>

using json = nlohmann::json;

Expand Down
2 changes: 1 addition & 1 deletion WeArtTrackingRawData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* https://www.weart.it/
*/

#include "pch.h"

#include "WeArtTrackingRawData.h"
#include "WeArtController.h"

Expand Down
Loading