Skip to content

Commit

Permalink
Added a RPC call to run the server manually
Browse files Browse the repository at this point in the history
  • Loading branch information
S-Dafarra committed Nov 14, 2024
1 parent a3ada7d commit e799b66
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
15 changes: 8 additions & 7 deletions src/devices/openxrheadset/OpenXrHeadset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ bool yarp::dev::OpenXrHeadset::open(yarp::os::Searchable &cfg)
double period = cfg.check("vr_period", yarp::os::Value(0.011)).asFloat64();
this->setPeriod(period);

m_launchJoypadControlServer = cfg.check("launch_joypad_control_server") && (cfg.find("launch_joypad_control_server").isNull() || cfg.find("launch_joypad_control_server").asBool());
m_autoJoypadControlServer = cfg.check("joypad_control_server_auto") && (cfg.find("joypad_control_server_auto").isNull() || cfg.find("joypad_control_server_auto").asBool());

m_useNativeQuadLayers = cfg.check("use_native_quad_layers") && (cfg.find("use_native_quad_layers").isNull() || cfg.find("use_native_quad_layers").asBool());

Expand Down Expand Up @@ -614,7 +614,7 @@ void yarp::dev::OpenXrHeadset::run()
return;
}

if (shouldResetJoypadServer)
if (shouldResetJoypadServer && m_autoJoypadControlServer)
{
startJoypadControlServer();
}
Expand Down Expand Up @@ -1044,14 +1044,15 @@ bool yarp::dev::OpenXrHeadset::resetTransforms()
return true;
}

bool yarp::dev::OpenXrHeadset::startJoypadControlServer()
bool yarp::dev::OpenXrHeadset::restartJoypadControlServer()
{
std::lock_guard<std::mutex> lock(m_mutex);
startJoypadControlServer();
}

if (!m_launchJoypadControlServer)
{
return true;
}
bool yarp::dev::OpenXrHeadset::startJoypadControlServer()
{
stopJoypadControlServer();

yarp::os::Property options;
options.put("device", "joypadControlServer");
Expand Down
8 changes: 7 additions & 1 deletion src/devices/openxrheadset/OpenXrHeadset.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,12 @@ class yarp::dev::OpenXrHeadset : public yarp::dev::DeviceDriver,
*/
virtual bool resetTransforms() override;

/**
* Start the joypad control server. The server will restart if already started.
* @return True if the server is started successfully, false otherwise.
*/
virtual bool restartJoypadControlServer() override;

private:

/**
Expand Down Expand Up @@ -343,7 +349,7 @@ class yarp::dev::OpenXrHeadset : public yarp::dev::DeviceDriver,
std::vector<float> m_axes;
std::vector<Eigen::Vector2f> m_thumbsticks;

bool m_launchJoypadControlServer{ false };
bool m_autoJoypadControlServer{ false };
std::unique_ptr<yarp::dev::PolyDriver> m_joypadControlServerPtr;
yarp::dev::IWrapper* m_joypadControlServerWrapper = nullptr;
yarp::dev::PolyDriver m_thisDevice;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,10 @@ service OpenXrHeadsetCommands
* as it will reset all the transforms, including the ones that are not published by this module.
*/
bool resetTransforms();

/**
* Start the joypad control server. The server will restart if already started.
* @return True if the server is started successfully, false otherwise.
*/
bool restartJoypadControlServer();
}

0 comments on commit e799b66

Please sign in to comment.