Commit 4a140cf0 authored by Jussi Lindgren's avatar Jussi Lindgren

Examples: VRPN examples now print out the used device names

- In openvibe-to-vrpn C++ client, you can now specify the device
parent 857de75c
......@@ -31,6 +31,21 @@ void VRPN_CALLBACK vrpn_analog_callback(void* user_data, vrpn_ANALOGCB analog)
int main(int argc, char** argv)
{
if(argc!=1 && argc!=3) {
std::cout << "Usage:\n\n" << argv[0] << " [buttonDevice] [analogDevice]\n";
return 1;
}
const char *buttonDevice = "openvibe_vrpn_button@localhost";
const char *analogDevice = "openvibe_vrpn_analog@localhost";
if(argc==3) {
buttonDevice=argv[1];
analogDevice=argv[2];
}
std::cout << "Polling these VRPN devices\n Button: " << buttonDevice << "\n Analog: " << analogDevice << "\n";
/* flag used to stop the program execution */
bool running = true;
......@@ -38,14 +53,14 @@ int main(int argc, char** argv)
vrpn_Button_Remote* VRPNButton;
/* Binding of the VRPN Button to a callback */
VRPNButton = new vrpn_Button_Remote( "openvibe_vrpn_button@localhost" );
VRPNButton = new vrpn_Button_Remote( buttonDevice );
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 = new vrpn_Analog_Remote( analogDevice );
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 */
......
......@@ -12,8 +12,13 @@ int main(int argc, char** argv)
{
GenericVRPNServer* vrpnServer = GenericVRPNServer::getInstance(DEFAULT_PORT);
vrpnServer->addButton("button_test", 1);
vrpnServer->addAnalog("analog_test", 2);
const char *buttonDevice = "button_test";
const char *analogDevice = "analog_test";
std::cout << "Creating devices [" << buttonDevice << "] and [" << analogDevice << "] using port [" << DEFAULT_PORT << "]\n";
vrpnServer->addButton(buttonDevice, 1);
vrpnServer->addAnalog(analogDevice, 2);
double time = 0;
double period = 0;
......@@ -22,11 +27,11 @@ int main(int argc, char** argv)
{
if (period >= 2 * M_PI)
{
vrpnServer->changeButtonState("button_test", 0, 1 - vrpnServer->getButtonState("button_test", 0));
vrpnServer->changeButtonState(buttonDevice, 0, 1 - vrpnServer->getButtonState(buttonDevice, 0));
period = 0;
}
vrpnServer->changeAnalogState("analog_test", sin(time), cos(time));
vrpnServer->changeAnalogState(analogDevice, sin(time), cos(time));
time = time + 0.01;
period = period + 0.01;
......
......@@ -13,8 +13,13 @@ int main(int argc, char** argv)
{
GenericVRPNServer* vrpnServer = GenericVRPNServer::getInstance(DEFAULT_PORT);
vrpnServer->addButton("button_test", 1);
vrpnServer->addAnalog("analog_test", 2);
const char *buttonDevice = "button_test";
const char *analogDevice = "analog_test";
std::cout << "Creating devices [" << buttonDevice << "] and [" << analogDevice << "] using port [" << DEFAULT_PORT << "]\n";
vrpnServer->addButton(buttonDevice, 1);
vrpnServer->addAnalog(analogDevice, 2);
double time = 0;
double period = 0;
......@@ -23,11 +28,11 @@ int main(int argc, char** argv)
{
if (period >= 2 * M_PI)
{
vrpnServer->changeButtonState("button_test", 0, 1 - vrpnServer->getButtonState("button_test", 0));
vrpnServer->changeButtonState(buttonDevice, 0, 1 - vrpnServer->getButtonState(buttonDevice, 0));
period = 0;
}
vrpnServer->changeAnalogState("analog_test", sin(time), cos(time));
vrpnServer->changeAnalogState(analogDevice, sin(time), cos(time));
time = time + 0.01;
period = period + 0.01;
......
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