From e799b660ac392aad83ba2462d45ec9d4260194cc Mon Sep 17 00:00:00 2001 From: Stefano Date: Thu, 14 Nov 2024 18:43:06 +0100 Subject: [PATCH] Added a RPC call to run the server manually --- src/devices/openxrheadset/OpenXrHeadset.cpp | 15 ++++++++------- src/devices/openxrheadset/OpenXrHeadset.h | 8 +++++++- .../thrifts/OpenXrHeadsetCommands.thrift | 6 ++++++ 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/devices/openxrheadset/OpenXrHeadset.cpp b/src/devices/openxrheadset/OpenXrHeadset.cpp index cf84972..34628a0 100644 --- a/src/devices/openxrheadset/OpenXrHeadset.cpp +++ b/src/devices/openxrheadset/OpenXrHeadset.cpp @@ -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()); @@ -614,7 +614,7 @@ void yarp::dev::OpenXrHeadset::run() return; } - if (shouldResetJoypadServer) + if (shouldResetJoypadServer && m_autoJoypadControlServer) { startJoypadControlServer(); } @@ -1044,14 +1044,15 @@ bool yarp::dev::OpenXrHeadset::resetTransforms() return true; } -bool yarp::dev::OpenXrHeadset::startJoypadControlServer() +bool yarp::dev::OpenXrHeadset::restartJoypadControlServer() { std::lock_guard lock(m_mutex); + startJoypadControlServer(); +} - if (!m_launchJoypadControlServer) - { - return true; - } +bool yarp::dev::OpenXrHeadset::startJoypadControlServer() +{ + stopJoypadControlServer(); yarp::os::Property options; options.put("device", "joypadControlServer"); diff --git a/src/devices/openxrheadset/OpenXrHeadset.h b/src/devices/openxrheadset/OpenXrHeadset.h index 7d19dc7..1549fb4 100644 --- a/src/devices/openxrheadset/OpenXrHeadset.h +++ b/src/devices/openxrheadset/OpenXrHeadset.h @@ -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: /** @@ -343,7 +349,7 @@ class yarp::dev::OpenXrHeadset : public yarp::dev::DeviceDriver, std::vector m_axes; std::vector m_thumbsticks; - bool m_launchJoypadControlServer{ false }; + bool m_autoJoypadControlServer{ false }; std::unique_ptr m_joypadControlServerPtr; yarp::dev::IWrapper* m_joypadControlServerWrapper = nullptr; yarp::dev::PolyDriver m_thisDevice; diff --git a/src/devices/openxrheadset/thrifts/OpenXrHeadsetCommands.thrift b/src/devices/openxrheadset/thrifts/OpenXrHeadsetCommands.thrift index cc9fde3..499fe51 100644 --- a/src/devices/openxrheadset/thrifts/OpenXrHeadsetCommands.thrift +++ b/src/devices/openxrheadset/thrifts/OpenXrHeadsetCommands.thrift @@ -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(); }