Commit 3d449abc authored by Jussi Lindgren's avatar Jussi Lindgren

Applications: Added OpenViBE->VRPN tutorial example

parent 537c9efd
PROJECT(openvibe-examples-openvibe-to-vrpn)
SET(PROJECT_VERSION_MAJOR ${OV_GLOBAL_VERSION_MAJOR})
SET(PROJECT_VERSION_MINOR ${OV_GLOBAL_VERSION_MINOR})
SET(PROJECT_VERSION_PATCH ${OV_GLOBAL_VERSION_PATCH})
SET(PROJECT_VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH})
INCLUDE("FindThirdPartyVRPN_Check")
IF(NOT PATH_VRPN)
MESSAGE(STATUS " --> Not building ${PROJECT_NAME}")
RETURN()
ENDIF(NOT PATH_VRPN)
FILE(GLOB_RECURSE source_files src/*.cpp src/*.h src/*.hpp src/*.inl include/*.h)
INCLUDE_DIRECTORIES(include)
ADD_EXECUTABLE(${PROJECT_NAME} ${source_files})
INCLUDE("FindThirdPartyVRPN")
# ---------------------------------
# Target macros
# Defines target operating system
# Defines target architecture
# Defines target compiler
# ---------------------------------
IF(WIN32)
ADD_DEFINITIONS(-D_CRT_SECURE_NO_DEPRECATE)
ADD_DEFINITIONS(-DTARGET_OS_Windows)
ADD_DEFINITIONS(-DTARGET_ARCHITECTURE_i386)
ADD_DEFINITIONS(-DTARGET_COMPILER_VisualStudio)
ENDIF(WIN32)
IF(UNIX)
# ADD_DEFINITIONS(-fvisibility=hidden) # This flag should be present... man gcc
ADD_DEFINITIONS(-g)
ADD_DEFINITIONS(-fnon-call-exceptions)
ADD_DEFINITIONS(-DTARGET_OS_Linux)
ADD_DEFINITIONS(-DTARGET_ARCHITECTURE_i386)
ADD_DEFINITIONS(-DTARGET_COMPILER_GCC)
ENDIF(UNIX)
# ----------------------
# Generate launch script
# ----------------------
OV_INSTALL_LAUNCH_SCRIPT("openvibe-examples-openvibe-to-vrpn")
# -----------------------------
# Install files
# -----------------------------
INSTALL(TARGETS ${PROJECT_NAME}
RUNTIME DESTINATION ${CMAKE_INSTALL_FULL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR})
INSTALL(DIRECTORY box-tutorials/ DESTINATION ${CMAKE_INSTALL_FULL_DATADIR}/openvibe/scenarios/box-tutorials PATTERN ".svn" EXCLUDE)
#INSTALL(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_FULL_INCLUDEDIR}/ FILES_MATCHING PATTERN "*.h" PATTERN ".svn" EXCLUDE)
/*
* Receives data from OpenViBE's VRPN boxes
*
* See here: http://openvibe.inria.fr/vrpn-tutorial-sending-data-from-openvibe-to-an-external-application/
*
*/
#include <iostream>
#include <vrpn_Button.h>
#include <vrpn_Analog.h>
void VRPN_CALLBACK vrpn_button_callback(void* user_data, vrpn_BUTTONCB button)
{
std::cout << "Button ID : " << button.button << " / Button State : " << button.state << std::endl;
if (button.button == 1)
{
*(bool*)user_data = false;
}
}
void VRPN_CALLBACK vrpn_analog_callback(void* user_data, vrpn_ANALOGCB analog)
{
for (int i = 0; i < analog.num_channel; i++)
{
std::cout << "Analog Channel : " << i << " / Analog Value : " << analog.channel[i] << std::endl;
}
}
int main(int argc, char** argv)
{
/* flag used to stop the program execution */
bool running = true;
/* VRPN Button object */
vrpn_Button_Remote* VRPNButton;
/* Binding of the VRPN Button to a callback */
VRPNButton = new vrpn_Button_Remote( "openvibe_vrpn_button@localhost" );
VRPNButton->register_change_handler( &running, vrpn_button_callback );
/* VRPN Analog object */
vrpn_Analog_Remote* VRPNAnalog;
/* Binding of the VRPN Analog to a callback */
VRPNAnalog = new vrpn_Analog_Remote( "openvibe_vrpn_analog@localhost" );
VRPNAnalog->register_change_handler( NULL, vrpn_analog_callback );
/* The main loop of the program, each VRPN object must be called in order to process data */
while (running)
{
VRPNButton->mainloop();
}
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment