init
This commit is contained in:
+62
@@ -0,0 +1,62 @@
|
||||
IF(OV_DISABLE_GTK)
|
||||
MESSAGE(STATUS "Skipping VRPN Simulator, no GTK")
|
||||
RETURN()
|
||||
ENDIF(OV_DISABLE_GTK)
|
||||
|
||||
PROJECT(openvibe-vrpn-simulator)
|
||||
|
||||
SET(PROJECT_VERSION_MAJOR ${OV_GLOBAL_VERSION_MAJOR})
|
||||
SET(PROJECT_VERSION ${OV_GLOBAL_VERSION_STRING})
|
||||
|
||||
INCLUDE("FindThirdPartyVRPN_Check")
|
||||
IF(NOT PATH_VRPN)
|
||||
MESSAGE(STATUS " --> Not building ${PROJECT_NAME}")
|
||||
RETURN()
|
||||
ENDIF(NOT PATH_VRPN)
|
||||
|
||||
FILE(GLOB_RECURSE SRC_FILES src/*.cpp src/*.h src/*.inl)
|
||||
ADD_EXECUTABLE(${PROJECT_NAME} ${SRC_FILES})
|
||||
SET_PROPERTY(TARGET ${PROJECT_NAME} PROPERTY FOLDER ${APP_FOLDER})
|
||||
|
||||
INCLUDE("FindOpenViBE")
|
||||
INCLUDE("FindOpenViBECommon")
|
||||
INCLUDE("FindThirdPartyGTK")
|
||||
INCLUDE("FindThirdPartyVRPN")
|
||||
|
||||
# ---------------------------------
|
||||
# Finds standard library pthread
|
||||
# Adds library to target
|
||||
# Adds include path
|
||||
# ---------------------------------
|
||||
IF(UNIX)
|
||||
FIND_LIBRARY(LIB_STANDARD_MODULE_PTHREAD pthread)
|
||||
IF(LIB_STANDARD_MODULE_PTHREAD)
|
||||
MESSAGE(STATUS " Found pthread...")
|
||||
TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${LIB_STANDARD_MODULE_PTHREAD})
|
||||
ELSE(LIB_STANDARD_MODULE_PTHREAD)
|
||||
MESSAGE(STATUS " FAILED to find pthread...")
|
||||
ENDIF(LIB_STANDARD_MODULE_PTHREAD)
|
||||
ENDIF(UNIX)
|
||||
|
||||
# ---------------------------------
|
||||
|
||||
|
||||
|
||||
|
||||
# ---------------------------------
|
||||
|
||||
|
||||
# ----------------------
|
||||
# Generate launch script
|
||||
# ----------------------
|
||||
OV_INSTALL_LAUNCH_SCRIPT(SCRIPT_PREFIX "${PROJECT_NAME}" EXECUTABLE_NAME "${PROJECT_NAME}")
|
||||
|
||||
# -----------------------------
|
||||
# Install files
|
||||
# -----------------------------
|
||||
INSTALL(TARGETS ${PROJECT_NAME}
|
||||
RUNTIME DESTINATION ${DIST_BINDIR}
|
||||
LIBRARY DESTINATION ${DIST_LIBDIR}
|
||||
ARCHIVE DESTINATION ${DIST_LIBDIR})
|
||||
|
||||
INSTALL(DIRECTORY share/ DESTINATION ${DIST_DATADIR}/openvibe/applications/vrpn-simulator)
|
||||
+293
@@ -0,0 +1,293 @@
|
||||
<?xml version="1.0"?>
|
||||
<interface>
|
||||
<!-- interface-requires gtk+ 2.12 -->
|
||||
<!-- interface-naming-policy toplevel-contextual -->
|
||||
<object class="GtkAdjustment" id="adjustment1">
|
||||
<property name="lower">-100</property>
|
||||
<property name="upper">100</property>
|
||||
<property name="step_increment">0.01</property>
|
||||
<property name="page_increment">1</property>
|
||||
</object>
|
||||
<object class="GtkAdjustment" id="adjustment2">
|
||||
<property name="lower">-100</property>
|
||||
<property name="upper">100</property>
|
||||
<property name="step_increment">0.01</property>
|
||||
<property name="page_increment">1</property>
|
||||
</object>
|
||||
<object class="GtkAdjustment" id="adjustment3">
|
||||
<property name="lower">-100</property>
|
||||
<property name="upper">100</property>
|
||||
<property name="step_increment">0.01</property>
|
||||
<property name="page_increment">1</property>
|
||||
</object>
|
||||
<object class="GtkAdjustment" id="adjustment4">
|
||||
<property name="lower">-100</property>
|
||||
<property name="upper">100</property>
|
||||
<property name="step_increment">0.01</property>
|
||||
<property name="page_increment">1</property>
|
||||
</object>
|
||||
<object class="GtkAdjustment" id="adjustment5">
|
||||
<property name="lower">-100</property>
|
||||
<property name="upper">100</property>
|
||||
<property name="step_increment">0.01</property>
|
||||
<property name="page_increment">1</property>
|
||||
</object>
|
||||
<object class="GtkAdjustment" id="adjustment6">
|
||||
<property name="lower">-100</property>
|
||||
<property name="upper">100</property>
|
||||
<property name="step_increment">0.01</property>
|
||||
<property name="page_increment">1</property>
|
||||
</object>
|
||||
<object class="GtkAdjustment" id="adjustment7">
|
||||
<property name="lower">-100</property>
|
||||
<property name="upper">100</property>
|
||||
<property name="step_increment">0.01</property>
|
||||
<property name="page_increment">1</property>
|
||||
</object>
|
||||
<object class="GtkAdjustment" id="adjustment8">
|
||||
<property name="lower">-100</property>
|
||||
<property name="upper">100</property>
|
||||
<property name="step_increment">0.01</property>
|
||||
<property name="page_increment">1</property>
|
||||
</object>
|
||||
<object class="GtkWindow" id="window">
|
||||
<child>
|
||||
<object class="GtkVBox" id="vbox">
|
||||
<property name="visible">True</property>
|
||||
<child>
|
||||
<object class="GtkHBox" id="hbox_analog">
|
||||
<property name="visible">True</property>
|
||||
<child>
|
||||
<object class="GtkVScale" id="vscale_0">
|
||||
<property name="height_request">256</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="adjustment">adjustment1</property>
|
||||
<property name="inverted">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkVScale" id="vscale_1">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="adjustment">adjustment2</property>
|
||||
<property name="inverted">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkVScale" id="vscale_2">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="adjustment">adjustment3</property>
|
||||
<property name="inverted">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="position">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkVScale" id="vscale_3">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="adjustment">adjustment4</property>
|
||||
<property name="inverted">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="position">3</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkVScale" id="vscale_4">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="adjustment">adjustment5</property>
|
||||
<property name="inverted">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="position">4</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkVScale" id="vscale_5">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="adjustment">adjustment6</property>
|
||||
<property name="inverted">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="position">5</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkVScale" id="vscale_6">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="adjustment">adjustment7</property>
|
||||
<property name="inverted">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="position">6</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkVScale" id="vscale_7">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="adjustment">adjustment8</property>
|
||||
<property name="inverted">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="position">7</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkHBox" id="hbox_button">
|
||||
<property name="visible">True</property>
|
||||
<child>
|
||||
<object class="GtkToggleButton" id="togglebutton_0">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<child>
|
||||
<object class="GtkImage" id="image">
|
||||
<property name="visible">True</property>
|
||||
<property name="stock">gtk-about</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkToggleButton" id="togglebutton_1">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<child>
|
||||
<object class="GtkImage" id="image1">
|
||||
<property name="visible">True</property>
|
||||
<property name="stock">gtk-about</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkToggleButton" id="togglebutton_2">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<child>
|
||||
<object class="GtkImage" id="image2">
|
||||
<property name="visible">True</property>
|
||||
<property name="stock">gtk-about</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="position">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkToggleButton" id="togglebutton_3">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<child>
|
||||
<object class="GtkImage" id="image3">
|
||||
<property name="visible">True</property>
|
||||
<property name="stock">gtk-about</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="position">3</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkToggleButton" id="togglebutton_4">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<child>
|
||||
<object class="GtkImage" id="image4">
|
||||
<property name="visible">True</property>
|
||||
<property name="stock">gtk-about</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="position">4</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkToggleButton" id="togglebutton_5">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<child>
|
||||
<object class="GtkImage" id="image5">
|
||||
<property name="visible">True</property>
|
||||
<property name="stock">gtk-about</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="position">5</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkToggleButton" id="togglebutton_6">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<child>
|
||||
<object class="GtkImage" id="image6">
|
||||
<property name="visible">True</property>
|
||||
<property name="stock">gtk-about</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="position">6</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkToggleButton" id="togglebutton_7">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<child>
|
||||
<object class="GtkImage" id="image7">
|
||||
<property name="visible">True</property>
|
||||
<property name="stock">gtk-about</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="position">7</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</interface>
|
||||
+136
@@ -0,0 +1,136 @@
|
||||
#if defined TARGET_HAS_ThirdPartyVRPN
|
||||
|
||||
#include <clocale> // std::setlocale
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
#include <gdk/gdk.h>
|
||||
|
||||
#include <openvibe/ov_directories.h>
|
||||
#include <openvibe/ovCString.h>
|
||||
|
||||
#include <vrpn_Button.h>
|
||||
#include <vrpn_Analog.h>
|
||||
#include <vrpn_Connection.h>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#define _vrpn_peripheral_name_ "openvibe-vrpn@localhost"
|
||||
|
||||
// #define _DEBUG
|
||||
|
||||
vrpn_Connection* connection = nullptr;
|
||||
vrpn_Button_Server* buttonServer = nullptr;
|
||||
vrpn_Analog_Server* analogServer = nullptr;
|
||||
long nAnalog = 0;
|
||||
long nButton = 0;
|
||||
|
||||
typedef union
|
||||
{
|
||||
gpointer data;
|
||||
int idx;
|
||||
} user_data_t;
|
||||
|
||||
void fScrollCB(GtkRange* range, gpointer data)
|
||||
{
|
||||
user_data_t userData;
|
||||
userData.data = data;
|
||||
const gdouble value = gtk_range_get_value(range);
|
||||
analogServer->channels()[userData.idx] = value;
|
||||
|
||||
#if defined _DEBUG
|
||||
std::cout << "Channel " << int(data) << " value changed to " << value << "\n";
|
||||
#endif
|
||||
}
|
||||
|
||||
void fSwitchCB(GtkToggleButton* button, gpointer data)
|
||||
{
|
||||
user_data_t userData;
|
||||
userData.data = data;
|
||||
const gboolean value = gtk_toggle_button_get_active(button);
|
||||
buttonServer->set_button(userData.idx, value);
|
||||
|
||||
#if defined _DEBUG
|
||||
std::cout << "Channel " << userData.idx << " toggled to " << value << "\n";
|
||||
#endif
|
||||
}
|
||||
|
||||
void fConnectCB(GtkWidget* widget, gpointer /*data*/)
|
||||
{
|
||||
if (GTK_IS_RANGE(widget))
|
||||
{
|
||||
g_signal_connect(G_OBJECT(widget), "value-changed", G_CALLBACK(fScrollCB), gpointer(nAnalog));
|
||||
nAnalog++;
|
||||
}
|
||||
|
||||
if (GTK_IS_TOGGLE_BUTTON(widget))
|
||||
{
|
||||
g_signal_connect(G_OBJECT(widget), "toggled", G_CALLBACK(fSwitchCB), reinterpret_cast<void*>(nButton));
|
||||
nButton++;
|
||||
}
|
||||
}
|
||||
|
||||
gboolean fIdleApplicationLoop(gpointer /*data*/)
|
||||
{
|
||||
buttonServer->mainloop();
|
||||
analogServer->report_changes();
|
||||
analogServer->mainloop();
|
||||
connection->mainloop();
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
#endif // TARGET_HAS_ThirdPartyVRPN
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
#if defined TARGET_HAS_ThirdPartyVRPN
|
||||
const int nChannels = 8;
|
||||
|
||||
gtk_init(&argc, &argv);
|
||||
|
||||
// We rely on this with 64bit/gtk 2.24, to roll back gtk_init() sometimes switching
|
||||
// the locale to one where ',' is needed instead of '.' for separators of floats,
|
||||
// causing issues, for example getConfigurationManager.expandAsFloat("0.05") -> 0;
|
||||
// due to implementation by std::stod().
|
||||
std::setlocale(LC_ALL, "C");
|
||||
|
||||
// g_pConnection=new ::vrpn_Connection;
|
||||
connection = vrpn_create_server_connection();
|
||||
buttonServer = new vrpn_Button_Server(_vrpn_peripheral_name_, connection, nChannels);
|
||||
analogServer = new vrpn_Analog_Server(_vrpn_peripheral_name_, connection, nChannels);
|
||||
|
||||
GtkBuilder* builder =
|
||||
gtk_builder_new(); // glade_xml_new(OpenViBE::Directories::getDataDir() + "/applications/vrpn-simulator/interface.ui", "window", nullptr);
|
||||
const OpenViBE::CString filename = OpenViBE::Directories::getDataDir() + "/applications/vrpn-simulator/interface.ui";
|
||||
if (!gtk_builder_add_from_file(builder, filename, nullptr))
|
||||
{
|
||||
std::cout << "Problem loading [" << filename << "]\n";
|
||||
return -1;
|
||||
}
|
||||
|
||||
GtkWidget* mainWindow = GTK_WIDGET(gtk_builder_get_object(builder, "window"));
|
||||
GtkWidget* hBoxButton = GTK_WIDGET(gtk_builder_get_object(builder, "hbox_button"));
|
||||
GtkWidget* hBoxAnalog = GTK_WIDGET(gtk_builder_get_object(builder, "hbox_analog"));
|
||||
|
||||
g_signal_connect(G_OBJECT(mainWindow), "destroy", gtk_main_quit, nullptr);
|
||||
gtk_container_foreach(GTK_CONTAINER(hBoxButton), fConnectCB, nullptr);
|
||||
gtk_container_foreach(GTK_CONTAINER(hBoxAnalog), fConnectCB, nullptr);
|
||||
gtk_builder_connect_signals(builder, nullptr);
|
||||
|
||||
std::cout << "VRPN Stimulator\n";
|
||||
std::cout << "Got " << nAnalog << " analogs...\n";
|
||||
std::cout << "Got " << nButton << " buttons...\n";
|
||||
std::cout << "Using " << nChannels << " VRPN channels...\n";
|
||||
std::cout << "Signals will be sent to peripheral [" << _vrpn_peripheral_name_ << "]\n";
|
||||
|
||||
g_idle_add(fIdleApplicationLoop, nullptr);
|
||||
|
||||
gtk_widget_show(mainWindow);
|
||||
gtk_main();
|
||||
|
||||
delete analogServer;
|
||||
delete buttonServer;
|
||||
delete connection;
|
||||
|
||||
#endif // TARGET_HAS_ThirdPartyVRPN
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user