Add gamepad forwarding through OpenXR
Forward a gamepad paired to the headset to the server. Useful when the controller is in range of the headset but not the server, such as a DualSense paired to a Quest over Bluetooth. The headset reads the gamepad through the OpenXR microsoft/xbox_controller profile and forwards it on the existing input rails: gamepad device ids in the inputs packet, plus a gamepad entry in the interaction profile array that signals connection and disconnection from the tracking thread. The server exposes a native OpenXR gamepad at /user/gamepad, connected while the headset reports a gamepad interaction profile. This needs no permission and is always available. Rumble is sent back to the headset and applied through OpenXR haptics.
This commit is contained in:
@@ -249,10 +249,13 @@ bool android_hid::input_handler::handle_input(scene * current_scene, AInputEvent
|
|||||||
{
|
{
|
||||||
const int32_t type = AInputEvent_getType(event);
|
const int32_t type = AInputEvent_getType(event);
|
||||||
const int32_t src = AInputEvent_getSource(event);
|
const int32_t src = AInputEvent_getSource(event);
|
||||||
const int32_t dev = AInputEvent_getDeviceId(event);
|
|
||||||
|
|
||||||
if (type == AINPUT_EVENT_TYPE_KEY)
|
if (type == AINPUT_EVENT_TYPE_KEY)
|
||||||
{
|
{
|
||||||
|
// Gamepad input is read through the OpenXR microsoft/xbox_controller profile, not here.
|
||||||
|
if ((src & AINPUT_SOURCE_GAMEPAD) == AINPUT_SOURCE_GAMEPAD)
|
||||||
|
return false;
|
||||||
|
|
||||||
int32_t flags = AKeyEvent_getFlags(event);
|
int32_t flags = AKeyEvent_getFlags(event);
|
||||||
if ((flags & AKEY_EVENT_FLAG_SOFT_KEYBOARD) != 0)
|
if ((flags & AKEY_EVENT_FLAG_SOFT_KEYBOARD) != 0)
|
||||||
return false; // ignore soft keyboards
|
return false; // ignore soft keyboards
|
||||||
@@ -288,6 +291,10 @@ bool android_hid::input_handler::handle_input(scene * current_scene, AInputEvent
|
|||||||
|
|
||||||
if (type == AINPUT_EVENT_TYPE_MOTION)
|
if (type == AINPUT_EVENT_TYPE_MOTION)
|
||||||
{
|
{
|
||||||
|
// Gamepad axes are read through the OpenXR microsoft/xbox_controller profile, not here.
|
||||||
|
if ((src & AINPUT_SOURCE_JOYSTICK) == AINPUT_SOURCE_JOYSTICK)
|
||||||
|
return false;
|
||||||
|
|
||||||
// don't care about absolute mouse due to mapping difficulties
|
// don't care about absolute mouse due to mapping difficulties
|
||||||
if ((src & AINPUT_SOURCE_MOUSE_RELATIVE) == 0)
|
if ((src & AINPUT_SOURCE_MOUSE_RELATIVE) == 0)
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
+43
-7
@@ -39,6 +39,7 @@
|
|||||||
#include <boost/locale.hpp>
|
#include <boost/locale.hpp>
|
||||||
#include <boost/url/parse.hpp>
|
#include <boost/url/parse.hpp>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
#include <cstring>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <exception>
|
#include <exception>
|
||||||
#include <magic_enum.hpp>
|
#include <magic_enum.hpp>
|
||||||
@@ -602,6 +603,35 @@ static std::vector<interaction_profile> interaction_profiles{
|
|||||||
"/user/eyes_ext/input/gaze_ext/pose",
|
"/user/eyes_ext/input/gaze_ext/pose",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
interaction_profile{
|
||||||
|
.profile_name = "/interaction_profiles/microsoft/xbox_controller",
|
||||||
|
.input_sources = {
|
||||||
|
"/user/gamepad/input/menu/click",
|
||||||
|
"/user/gamepad/input/view/click",
|
||||||
|
"/user/gamepad/input/a/click",
|
||||||
|
"/user/gamepad/input/b/click",
|
||||||
|
"/user/gamepad/input/x/click",
|
||||||
|
"/user/gamepad/input/y/click",
|
||||||
|
"/user/gamepad/input/dpad_up/click",
|
||||||
|
"/user/gamepad/input/dpad_down/click",
|
||||||
|
"/user/gamepad/input/dpad_left/click",
|
||||||
|
"/user/gamepad/input/dpad_right/click",
|
||||||
|
"/user/gamepad/input/shoulder_left/click",
|
||||||
|
"/user/gamepad/input/shoulder_right/click",
|
||||||
|
"/user/gamepad/input/thumbstick_left/click",
|
||||||
|
"/user/gamepad/input/thumbstick_right/click",
|
||||||
|
"/user/gamepad/input/trigger_left/value",
|
||||||
|
"/user/gamepad/input/trigger_right/value",
|
||||||
|
"/user/gamepad/input/thumbstick_left/x",
|
||||||
|
"/user/gamepad/input/thumbstick_left/y",
|
||||||
|
"/user/gamepad/input/thumbstick_right/x",
|
||||||
|
"/user/gamepad/input/thumbstick_right/y",
|
||||||
|
"/user/gamepad/output/haptic_left",
|
||||||
|
"/user/gamepad/output/haptic_right",
|
||||||
|
"/user/gamepad/output/haptic_left_trigger",
|
||||||
|
"/user/gamepad/output/haptic_right_trigger",
|
||||||
|
},
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
static const std::pair<std::string_view, XrActionType> action_suffixes[] =
|
static const std::pair<std::string_view, XrActionType> action_suffixes[] =
|
||||||
@@ -634,11 +664,15 @@ static const std::pair<std::string_view, XrActionType> action_suffixes[] =
|
|||||||
{"/ready_ext", XR_ACTION_TYPE_BOOLEAN_INPUT},
|
{"/ready_ext", XR_ACTION_TYPE_BOOLEAN_INPUT},
|
||||||
|
|
||||||
// Output paths
|
// Output paths
|
||||||
{"/haptic", XR_ACTION_TYPE_VIBRATION_OUTPUT},
|
{"/haptic", XR_ACTION_TYPE_VIBRATION_OUTPUT},
|
||||||
{"/haptic_trigger", XR_ACTION_TYPE_VIBRATION_OUTPUT},
|
{"/haptic_trigger", XR_ACTION_TYPE_VIBRATION_OUTPUT},
|
||||||
{"/haptic_trigger_fb",XR_ACTION_TYPE_VIBRATION_OUTPUT},
|
{"/haptic_trigger_fb", XR_ACTION_TYPE_VIBRATION_OUTPUT},
|
||||||
{"/haptic_thumb", XR_ACTION_TYPE_VIBRATION_OUTPUT},
|
{"/haptic_thumb", XR_ACTION_TYPE_VIBRATION_OUTPUT},
|
||||||
{"/haptic_thumb_fb", XR_ACTION_TYPE_VIBRATION_OUTPUT},
|
{"/haptic_thumb_fb", XR_ACTION_TYPE_VIBRATION_OUTPUT},
|
||||||
|
{"/haptic_left", XR_ACTION_TYPE_VIBRATION_OUTPUT},
|
||||||
|
{"/haptic_right", XR_ACTION_TYPE_VIBRATION_OUTPUT},
|
||||||
|
{"/haptic_left_trigger", XR_ACTION_TYPE_VIBRATION_OUTPUT},
|
||||||
|
{"/haptic_right_trigger",XR_ACTION_TYPE_VIBRATION_OUTPUT},
|
||||||
// clang-format on
|
// clang-format on
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1717,8 +1751,10 @@ void application::run()
|
|||||||
while (ALooper_pollOnce(100, nullptr, &events, (void **)&source) >= 0)
|
while (ALooper_pollOnce(100, nullptr, &events, (void **)&source) >= 0)
|
||||||
{
|
{
|
||||||
// Process this event.
|
// Process this event.
|
||||||
if (source != nullptr)
|
if (source == nullptr)
|
||||||
source->process(app_info.native_app, source);
|
continue;
|
||||||
|
|
||||||
|
source->process(app_info.native_app, source);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (app_info.native_app->destroyRequested)
|
if (app_info.native_app->destroyRequested)
|
||||||
|
|||||||
@@ -206,6 +206,11 @@ public:
|
|||||||
{
|
{
|
||||||
return instance().app_info.native_app;
|
return instance().app_info.native_app;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static android_hid::input_handler & get_input_handler()
|
||||||
|
{
|
||||||
|
return instance().input_handler;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static bool is_session_running()
|
static bool is_session_running()
|
||||||
|
|||||||
@@ -138,6 +138,27 @@ static const std::unordered_map<std::string, device_id> device_ids = {
|
|||||||
{"/user/hand/right/input/aim_activate_ext/ready_ext",device_id::RIGHT_AIM_ACTIVATE_READY},
|
{"/user/hand/right/input/aim_activate_ext/ready_ext",device_id::RIGHT_AIM_ACTIVATE_READY},
|
||||||
{"/user/hand/right/input/grasp_ext/value", device_id::RIGHT_GRASP_VALUE},
|
{"/user/hand/right/input/grasp_ext/value", device_id::RIGHT_GRASP_VALUE},
|
||||||
{"/user/hand/right/input/grasp_ext/ready_ext", device_id::RIGHT_GRASP_READY},
|
{"/user/hand/right/input/grasp_ext/ready_ext", device_id::RIGHT_GRASP_READY},
|
||||||
|
|
||||||
|
{"/user/gamepad/input/menu/click", device_id::GAMEPAD_MENU_CLICK},
|
||||||
|
{"/user/gamepad/input/view/click", device_id::GAMEPAD_VIEW_CLICK},
|
||||||
|
{"/user/gamepad/input/a/click", device_id::GAMEPAD_A_CLICK},
|
||||||
|
{"/user/gamepad/input/b/click", device_id::GAMEPAD_B_CLICK},
|
||||||
|
{"/user/gamepad/input/x/click", device_id::GAMEPAD_X_CLICK},
|
||||||
|
{"/user/gamepad/input/y/click", device_id::GAMEPAD_Y_CLICK},
|
||||||
|
{"/user/gamepad/input/dpad_down/click", device_id::GAMEPAD_DPAD_DOWN_CLICK},
|
||||||
|
{"/user/gamepad/input/dpad_right/click", device_id::GAMEPAD_DPAD_RIGHT_CLICK},
|
||||||
|
{"/user/gamepad/input/dpad_up/click", device_id::GAMEPAD_DPAD_UP_CLICK},
|
||||||
|
{"/user/gamepad/input/dpad_left/click", device_id::GAMEPAD_DPAD_LEFT_CLICK},
|
||||||
|
{"/user/gamepad/input/shoulder_left/click", device_id::GAMEPAD_SHOULDER_LEFT_CLICK},
|
||||||
|
{"/user/gamepad/input/shoulder_right/click", device_id::GAMEPAD_SHOULDER_RIGHT_CLICK},
|
||||||
|
{"/user/gamepad/input/thumbstick_left/click", device_id::GAMEPAD_THUMBSTICK_LEFT_CLICK},
|
||||||
|
{"/user/gamepad/input/thumbstick_right/click", device_id::GAMEPAD_THUMBSTICK_RIGHT_CLICK},
|
||||||
|
{"/user/gamepad/input/trigger_left/value", device_id::GAMEPAD_TRIGGER_LEFT_VALUE},
|
||||||
|
{"/user/gamepad/input/trigger_right/value", device_id::GAMEPAD_TRIGGER_RIGHT_VALUE},
|
||||||
|
{"/user/gamepad/input/thumbstick_left/x", device_id::GAMEPAD_THUMBSTICK_LEFT_X},
|
||||||
|
{"/user/gamepad/input/thumbstick_left/y", device_id::GAMEPAD_THUMBSTICK_LEFT_Y},
|
||||||
|
{"/user/gamepad/input/thumbstick_right/x", device_id::GAMEPAD_THUMBSTICK_RIGHT_X},
|
||||||
|
{"/user/gamepad/input/thumbstick_right/y", device_id::GAMEPAD_THUMBSTICK_RIGHT_Y},
|
||||||
};
|
};
|
||||||
// clang-format on
|
// clang-format on
|
||||||
|
|
||||||
@@ -380,7 +401,12 @@ std::shared_ptr<scenes::stream> scenes::stream::create(std::unique_ptr<wivrn_ses
|
|||||||
std::tuple(device_id::LEFT_THUMB_HAPTIC, "/user/hand/left", "/output/haptic_thumb"),
|
std::tuple(device_id::LEFT_THUMB_HAPTIC, "/user/hand/left", "/output/haptic_thumb"),
|
||||||
std::tuple(device_id::RIGHT_THUMB_HAPTIC, "/user/hand/right", "/output/haptic_thumb"),
|
std::tuple(device_id::RIGHT_THUMB_HAPTIC, "/user/hand/right", "/output/haptic_thumb"),
|
||||||
std::tuple(device_id::LEFT_THUMB_HAPTIC, "/user/hand/left", "/output/haptic_thumb_fb"),
|
std::tuple(device_id::LEFT_THUMB_HAPTIC, "/user/hand/left", "/output/haptic_thumb_fb"),
|
||||||
std::tuple(device_id::RIGHT_THUMB_HAPTIC, "/user/hand/right", "/output/haptic_thumb_fb")})
|
std::tuple(device_id::RIGHT_THUMB_HAPTIC, "/user/hand/right", "/output/haptic_thumb_fb"),
|
||||||
|
|
||||||
|
std::tuple(device_id::GAMEPAD_HAPTIC_LEFT, "/user/gamepad", "/output/haptic_left"),
|
||||||
|
std::tuple(device_id::GAMEPAD_HAPTIC_RIGHT, "/user/gamepad", "/output/haptic_right"),
|
||||||
|
std::tuple(device_id::GAMEPAD_HAPTIC_LEFT_TRIGGER, "/user/gamepad", "/output/haptic_left_trigger"),
|
||||||
|
std::tuple(device_id::GAMEPAD_HAPTIC_RIGHT_TRIGGER, "/user/gamepad", "/output/haptic_right_trigger")})
|
||||||
{
|
{
|
||||||
if (auto action = application::get_action(std::string(path) + output); action.first)
|
if (auto action = application::get_action(std::string(path) + output); action.first)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ private:
|
|||||||
std::unique_ptr<wivrn_session> network_session;
|
std::unique_ptr<wivrn_session> network_session;
|
||||||
std::thread network_thread;
|
std::thread network_thread;
|
||||||
thread_safe<to_headset::tracking_control> tracking_control{};
|
thread_safe<to_headset::tracking_control> tracking_control{};
|
||||||
std::array<std::atomic<interaction_profile>, 2> interaction_profiles; // left and right hand
|
std::array<std::atomic<interaction_profile>, 3> interaction_profiles; // left hand, right hand, gamepad
|
||||||
std::atomic<bool> interaction_profile_changed = false;
|
std::atomic<bool> interaction_profile_changed = false;
|
||||||
std::atomic<XrTime> scheduled_derived_pose = 0; // Tracking thread will compute derived pose when time is reached
|
std::atomic<XrTime> scheduled_derived_pose = 0; // Tracking thread will compute derived pose when time is reached
|
||||||
std::atomic<bool> recenter_requested = false;
|
std::atomic<bool> recenter_requested = false;
|
||||||
|
|||||||
@@ -443,6 +443,7 @@ void scenes::stream::tracking()
|
|||||||
tracking.interaction_profiles = {
|
tracking.interaction_profiles = {
|
||||||
interaction_profiles[0].load(),
|
interaction_profiles[0].load(),
|
||||||
interaction_profiles[1].load(),
|
interaction_profiles[1].load(),
|
||||||
|
interaction_profiles[2].load(),
|
||||||
};
|
};
|
||||||
|
|
||||||
tracking.production_timestamp = t0;
|
tracking.production_timestamp = t0;
|
||||||
@@ -664,6 +665,7 @@ void scenes::stream::on_interaction_profile_changed(const XrEventDataInteraction
|
|||||||
std::array path = {
|
std::array path = {
|
||||||
"/user/hand/left",
|
"/user/hand/left",
|
||||||
"/user/hand/right",
|
"/user/hand/right",
|
||||||
|
"/user/gamepad",
|
||||||
};
|
};
|
||||||
#define DO_PROFILE(vendor, name) \
|
#define DO_PROFILE(vendor, name) \
|
||||||
if (profile == "/interaction_profiles/" #vendor "/" #name) \
|
if (profile == "/interaction_profiles/" #vendor "/" #name) \
|
||||||
@@ -672,7 +674,7 @@ void scenes::stream::on_interaction_profile_changed(const XrEventDataInteraction
|
|||||||
continue; \
|
continue; \
|
||||||
}
|
}
|
||||||
|
|
||||||
for (size_t i = 0; i < 2; ++i)
|
for (size_t i = 0; i < path.size(); ++i)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|||||||
+118
-92
@@ -43,96 +43,122 @@ static constexpr int protocol_revision = 2;
|
|||||||
|
|
||||||
enum class device_id : uint8_t
|
enum class device_id : uint8_t
|
||||||
{
|
{
|
||||||
HEAD, // /user/head
|
HEAD, // /user/head
|
||||||
LEFT_CONTROLLER_HAPTIC, // /user/hand/left/output/haptic
|
LEFT_CONTROLLER_HAPTIC, // /user/hand/left/output/haptic
|
||||||
RIGHT_CONTROLLER_HAPTIC, // /user/hand/right/output/haptic
|
RIGHT_CONTROLLER_HAPTIC, // /user/hand/right/output/haptic
|
||||||
LEFT_TRIGGER_HAPTIC, // /user/hand/left/output/haptic_trigger
|
LEFT_TRIGGER_HAPTIC, // /user/hand/left/output/haptic_trigger
|
||||||
RIGHT_TRIGGER_HAPTIC, // /user/hand/right/output/haptic_trigger
|
RIGHT_TRIGGER_HAPTIC, // /user/hand/right/output/haptic_trigger
|
||||||
LEFT_THUMB_HAPTIC, // /user/hand/left/output/haptic_thumb
|
LEFT_THUMB_HAPTIC, // /user/hand/left/output/haptic_thumb
|
||||||
RIGHT_THUMB_HAPTIC, // /user/hand/right/output/haptic_thumb
|
RIGHT_THUMB_HAPTIC, // /user/hand/right/output/haptic_thumb
|
||||||
LEFT_GRIP, // /user/hand/left/input/grip/pose
|
GAMEPAD_HAPTIC_LEFT, // /user/gamepad/output/haptic_left
|
||||||
LEFT_AIM, // /user/hand/left/input/aim/pose
|
GAMEPAD_HAPTIC_RIGHT, // /user/gamepad/output/haptic_right
|
||||||
LEFT_PALM, // /user/hand/left/palm_ext/pose
|
GAMEPAD_HAPTIC_LEFT_TRIGGER, // /user/gamepad/output/haptic_left_trigger
|
||||||
RIGHT_GRIP, // /user/hand/right/input/grip/pose
|
GAMEPAD_HAPTIC_RIGHT_TRIGGER, // /user/gamepad/output/haptic_right_trigger
|
||||||
RIGHT_AIM, // /user/hand/right/input/aim/pose
|
LEFT_GRIP, // /user/hand/left/input/grip/pose
|
||||||
RIGHT_PALM, // /user/hand/right/palm_ext/pose
|
LEFT_AIM, // /user/hand/left/input/aim/pose
|
||||||
X_CLICK, // /user/hand/left/input/x/click
|
LEFT_PALM, // /user/hand/left/palm_ext/pose
|
||||||
X_TOUCH, // /user/hand/left/input/x/touch
|
RIGHT_GRIP, // /user/hand/right/input/grip/pose
|
||||||
Y_CLICK, // /user/hand/left/input/y/click
|
RIGHT_AIM, // /user/hand/right/input/aim/pose
|
||||||
Y_TOUCH, // /user/hand/left/input/y/touch
|
RIGHT_PALM, // /user/hand/right/palm_ext/pose
|
||||||
MENU_CLICK, // /user/hand/left/input/menu/click
|
X_CLICK, // /user/hand/left/input/x/click
|
||||||
LEFT_SQUEEZE_CLICK, // /user/hand/left/input/squeeze/click
|
X_TOUCH, // /user/hand/left/input/x/touch
|
||||||
LEFT_SQUEEZE_FORCE, // /user/hand/left/input/squeeze/force
|
Y_CLICK, // /user/hand/left/input/y/click
|
||||||
LEFT_SQUEEZE_VALUE, // /user/hand/left/input/squeeze/value
|
Y_TOUCH, // /user/hand/left/input/y/touch
|
||||||
LEFT_TRIGGER_CLICK, // /user/hand/left/input/trigger/click
|
MENU_CLICK, // /user/hand/left/input/menu/click
|
||||||
LEFT_TRIGGER_VALUE, // /user/hand/left/input/trigger/value
|
LEFT_SQUEEZE_CLICK, // /user/hand/left/input/squeeze/click
|
||||||
LEFT_TRIGGER_TOUCH, // /user/hand/left/input/trigger/touch
|
LEFT_SQUEEZE_FORCE, // /user/hand/left/input/squeeze/force
|
||||||
LEFT_TRIGGER_PROXIMITY, // /user/hand/left/input/trigger/proximity
|
LEFT_SQUEEZE_VALUE, // /user/hand/left/input/squeeze/value
|
||||||
LEFT_TRIGGER_CURL, // /user/hand/left/input/trigger/curl_fb
|
LEFT_TRIGGER_CLICK, // /user/hand/left/input/trigger/click
|
||||||
LEFT_TRIGGER_SLIDE, // /user/hand/left/input/trigger/slide_fb
|
LEFT_TRIGGER_VALUE, // /user/hand/left/input/trigger/value
|
||||||
LEFT_TRIGGER_FORCE, // /user/hand/left/input/trigger/force
|
LEFT_TRIGGER_TOUCH, // /user/hand/left/input/trigger/touch
|
||||||
LEFT_THUMBSTICK_X, // /user/hand/left/input/thumbstick/x
|
LEFT_TRIGGER_PROXIMITY, // /user/hand/left/input/trigger/proximity
|
||||||
LEFT_THUMBSTICK_Y, // /user/hand/left/input/thumbstick/y
|
LEFT_TRIGGER_CURL, // /user/hand/left/input/trigger/curl_fb
|
||||||
LEFT_THUMBSTICK_CLICK, // /user/hand/left/input/thumbstick/click
|
LEFT_TRIGGER_SLIDE, // /user/hand/left/input/trigger/slide_fb
|
||||||
LEFT_THUMBSTICK_TOUCH, // /user/hand/left/input/thumbstick/touch
|
LEFT_TRIGGER_FORCE, // /user/hand/left/input/trigger/force
|
||||||
LEFT_THUMBREST_TOUCH, // /user/hand/left/input/thumbrest/touch
|
LEFT_THUMBSTICK_X, // /user/hand/left/input/thumbstick/x
|
||||||
LEFT_THUMBREST_FORCE, // /user/hand/left/input/thumbrest/force
|
LEFT_THUMBSTICK_Y, // /user/hand/left/input/thumbstick/y
|
||||||
LEFT_THUMB_PROXIMITY, // /user/hand/left/input/thumb_resting_surfaces/proximity
|
LEFT_THUMBSTICK_CLICK, // /user/hand/left/input/thumbstick/click
|
||||||
LEFT_TRACKPAD_X, // /user/hand/left/input/trackpad/x
|
LEFT_THUMBSTICK_TOUCH, // /user/hand/left/input/thumbstick/touch
|
||||||
LEFT_TRACKPAD_Y, // /user/hand/left/input/trackpad/y
|
LEFT_THUMBREST_TOUCH, // /user/hand/left/input/thumbrest/touch
|
||||||
LEFT_TRACKPAD_CLICK, // /user/hand/left/input/trackpad/click
|
LEFT_THUMBREST_FORCE, // /user/hand/left/input/thumbrest/force
|
||||||
LEFT_TRACKPAD_TOUCH, // /user/hand/left/input/trackpad/touch
|
LEFT_THUMB_PROXIMITY, // /user/hand/left/input/thumb_resting_surfaces/proximity
|
||||||
LEFT_TRACKPAD_FORCE, // /user/hand/left/input/trackpad/force
|
LEFT_TRACKPAD_X, // /user/hand/left/input/trackpad/x
|
||||||
LEFT_STYLUS_FORCE, // /user/hand/left/input/stylus_fb/force
|
LEFT_TRACKPAD_Y, // /user/hand/left/input/trackpad/y
|
||||||
LEFT_PINCH_POSE, // /user/hand/left/input/pinch_ext/pose
|
LEFT_TRACKPAD_CLICK, // /user/hand/left/input/trackpad/click
|
||||||
LEFT_PINCH_VALUE, // /user/hand/left/input/pinch_ext/value
|
LEFT_TRACKPAD_TOUCH, // /user/hand/left/input/trackpad/touch
|
||||||
LEFT_PINCH_READY, // /user/hand/left/input/pinch_ext/ready_ext
|
LEFT_TRACKPAD_FORCE, // /user/hand/left/input/trackpad/force
|
||||||
LEFT_POKE, // /user/hand/left/input/poke_ext/pose
|
LEFT_STYLUS_FORCE, // /user/hand/left/input/stylus_fb/force
|
||||||
LEFT_AIM_ACTIVATE_VALUE, // /user/hand/left/input/aim_activate_ext/value
|
LEFT_PINCH_POSE, // /user/hand/left/input/pinch_ext/pose
|
||||||
LEFT_AIM_ACTIVATE_READY, // /user/hand/left/input/aim_activate_ext/ready_ext
|
LEFT_PINCH_VALUE, // /user/hand/left/input/pinch_ext/value
|
||||||
LEFT_GRASP_VALUE, // /user/hand/left/input/grasp_ext/value
|
LEFT_PINCH_READY, // /user/hand/left/input/pinch_ext/ready_ext
|
||||||
LEFT_GRASP_READY, // /user/hand/left/input/grasp_ext/ready_ext
|
LEFT_POKE, // /user/hand/left/input/poke_ext/pose
|
||||||
A_CLICK, // /user/hand/right/input/a/click
|
LEFT_AIM_ACTIVATE_VALUE, // /user/hand/left/input/aim_activate_ext/value
|
||||||
A_TOUCH, // /user/hand/right/input/a/touch
|
LEFT_AIM_ACTIVATE_READY, // /user/hand/left/input/aim_activate_ext/ready_ext
|
||||||
B_CLICK, // /user/hand/right/input/b/click
|
LEFT_GRASP_VALUE, // /user/hand/left/input/grasp_ext/value
|
||||||
B_TOUCH, // /user/hand/right/input/b/touch
|
LEFT_GRASP_READY, // /user/hand/left/input/grasp_ext/ready_ext
|
||||||
SYSTEM_CLICK, // /user/hand/right/input/system/click
|
A_CLICK, // /user/hand/right/input/a/click
|
||||||
RIGHT_SQUEEZE_CLICK, // /user/hand/right/input/squeeze/click
|
A_TOUCH, // /user/hand/right/input/a/touch
|
||||||
RIGHT_SQUEEZE_FORCE, // /user/hand/right/input/squeeze/force
|
B_CLICK, // /user/hand/right/input/b/click
|
||||||
RIGHT_SQUEEZE_VALUE, // /user/hand/right/input/squeeze/value
|
B_TOUCH, // /user/hand/right/input/b/touch
|
||||||
RIGHT_TRIGGER_CLICK, // /user/hand/right/input/trigger/click
|
SYSTEM_CLICK, // /user/hand/right/input/system/click
|
||||||
RIGHT_TRIGGER_VALUE, // /user/hand/right/input/trigger/value
|
RIGHT_SQUEEZE_CLICK, // /user/hand/right/input/squeeze/click
|
||||||
RIGHT_TRIGGER_TOUCH, // /user/hand/right/input/trigger/touch
|
RIGHT_SQUEEZE_FORCE, // /user/hand/right/input/squeeze/force
|
||||||
RIGHT_TRIGGER_PROXIMITY, // /user/hand/right/input/trigger/proximity
|
RIGHT_SQUEEZE_VALUE, // /user/hand/right/input/squeeze/value
|
||||||
RIGHT_TRIGGER_CURL, // /user/hand/right/input/trigger/curl_fb
|
RIGHT_TRIGGER_CLICK, // /user/hand/right/input/trigger/click
|
||||||
RIGHT_TRIGGER_SLIDE, // /user/hand/right/input/trigger/slide_fb
|
RIGHT_TRIGGER_VALUE, // /user/hand/right/input/trigger/value
|
||||||
RIGHT_TRIGGER_FORCE, // /user/hand/right/input/trigger/force
|
RIGHT_TRIGGER_TOUCH, // /user/hand/right/input/trigger/touch
|
||||||
RIGHT_THUMBSTICK_X, // /user/hand/right/input/thumbstick/x
|
RIGHT_TRIGGER_PROXIMITY, // /user/hand/right/input/trigger/proximity
|
||||||
RIGHT_THUMBSTICK_Y, // /user/hand/right/input/thumbstick/y
|
RIGHT_TRIGGER_CURL, // /user/hand/right/input/trigger/curl_fb
|
||||||
RIGHT_THUMBSTICK_CLICK, // /user/hand/right/input/thumbstick/click
|
RIGHT_TRIGGER_SLIDE, // /user/hand/right/input/trigger/slide_fb
|
||||||
RIGHT_THUMBSTICK_TOUCH, // /user/hand/right/input/thumbstick/touch
|
RIGHT_TRIGGER_FORCE, // /user/hand/right/input/trigger/force
|
||||||
RIGHT_THUMBREST_TOUCH, // /user/hand/right/input/thumbrest/touch
|
RIGHT_THUMBSTICK_X, // /user/hand/right/input/thumbstick/x
|
||||||
RIGHT_THUMBREST_FORCE, // /user/hand/right/input/thumbrest/force
|
RIGHT_THUMBSTICK_Y, // /user/hand/right/input/thumbstick/y
|
||||||
RIGHT_THUMB_PROXIMITY, // /user/hand/right/input/thumb_resting_surfaces/proximity
|
RIGHT_THUMBSTICK_CLICK, // /user/hand/right/input/thumbstick/click
|
||||||
RIGHT_TRACKPAD_X, // /user/hand/right/input/trackpad/x
|
RIGHT_THUMBSTICK_TOUCH, // /user/hand/right/input/thumbstick/touch
|
||||||
RIGHT_TRACKPAD_Y, // /user/hand/right/input/trackpad/y
|
RIGHT_THUMBREST_TOUCH, // /user/hand/right/input/thumbrest/touch
|
||||||
RIGHT_TRACKPAD_CLICK, // /user/hand/right/input/trackpad/click
|
RIGHT_THUMBREST_FORCE, // /user/hand/right/input/thumbrest/force
|
||||||
RIGHT_TRACKPAD_TOUCH, // /user/hand/right/input/trackpad/touch
|
RIGHT_THUMB_PROXIMITY, // /user/hand/right/input/thumb_resting_surfaces/proximity
|
||||||
RIGHT_TRACKPAD_FORCE, // /user/hand/right/input/trackpad/force
|
RIGHT_TRACKPAD_X, // /user/hand/right/input/trackpad/x
|
||||||
RIGHT_STYLUS_FORCE, // /user/hand/right/input/stylus_fb/force
|
RIGHT_TRACKPAD_Y, // /user/hand/right/input/trackpad/y
|
||||||
RIGHT_PINCH_POSE, // /user/hand/right/input/pinch_ext/pose
|
RIGHT_TRACKPAD_CLICK, // /user/hand/right/input/trackpad/click
|
||||||
RIGHT_PINCH_VALUE, // /user/hand/right/input/pinch_ext/value
|
RIGHT_TRACKPAD_TOUCH, // /user/hand/right/input/trackpad/touch
|
||||||
RIGHT_PINCH_READY, // /user/hand/right/input/pinch_ext/ready_ext
|
RIGHT_TRACKPAD_FORCE, // /user/hand/right/input/trackpad/force
|
||||||
RIGHT_POKE, // /user/hand/right/input/poke_ext/pose
|
RIGHT_STYLUS_FORCE, // /user/hand/right/input/stylus_fb/force
|
||||||
RIGHT_AIM_ACTIVATE_VALUE, // /user/hand/right/input/aim_activate_ext/value
|
RIGHT_PINCH_POSE, // /user/hand/right/input/pinch_ext/pose
|
||||||
RIGHT_AIM_ACTIVATE_READY, // /user/hand/right/input/aim_activate_ext/ready_ext
|
RIGHT_PINCH_VALUE, // /user/hand/right/input/pinch_ext/value
|
||||||
RIGHT_GRASP_VALUE, // /user/hand/right/input/grasp_ext/value
|
RIGHT_PINCH_READY, // /user/hand/right/input/pinch_ext/ready_ext
|
||||||
RIGHT_GRASP_READY, // /user/hand/right/input/grasp_ext/ready_ext
|
RIGHT_POKE, // /user/hand/right/input/poke_ext/pose
|
||||||
EYE_GAZE, // /user/eyes_ext/input/gaze_ext/pose
|
RIGHT_AIM_ACTIVATE_VALUE, // /user/hand/right/input/aim_activate_ext/value
|
||||||
LEFT_HAND, // identify hand tracking
|
RIGHT_AIM_ACTIVATE_READY, // /user/hand/right/input/aim_activate_ext/ready_ext
|
||||||
RIGHT_HAND, // identify hand tracking
|
RIGHT_GRASP_VALUE, // /user/hand/right/input/grasp_ext/value
|
||||||
BODY, // identify body tracking
|
RIGHT_GRASP_READY, // /user/hand/right/input/grasp_ext/ready_ext
|
||||||
FACE, // identify face tracking
|
EYE_GAZE, // /user/eyes_ext/input/gaze_ext/pose
|
||||||
|
LEFT_HAND, // identify hand tracking
|
||||||
|
RIGHT_HAND, // identify hand tracking
|
||||||
|
BODY, // identify body tracking
|
||||||
|
FACE, // identify face tracking
|
||||||
|
|
||||||
|
// Gamepad, microsoft/xbox_controller profile (/user/gamepad)
|
||||||
|
GAMEPAD_MENU_CLICK, // /user/gamepad/input/menu/click
|
||||||
|
GAMEPAD_VIEW_CLICK, // /user/gamepad/input/view/click
|
||||||
|
GAMEPAD_A_CLICK, // /user/gamepad/input/a/click
|
||||||
|
GAMEPAD_B_CLICK, // /user/gamepad/input/b/click
|
||||||
|
GAMEPAD_X_CLICK, // /user/gamepad/input/x/click
|
||||||
|
GAMEPAD_Y_CLICK, // /user/gamepad/input/y/click
|
||||||
|
GAMEPAD_DPAD_DOWN_CLICK, // /user/gamepad/input/dpad_down/click
|
||||||
|
GAMEPAD_DPAD_RIGHT_CLICK, // /user/gamepad/input/dpad_right/click
|
||||||
|
GAMEPAD_DPAD_UP_CLICK, // /user/gamepad/input/dpad_up/click
|
||||||
|
GAMEPAD_DPAD_LEFT_CLICK, // /user/gamepad/input/dpad_left/click
|
||||||
|
GAMEPAD_SHOULDER_LEFT_CLICK, // /user/gamepad/input/shoulder_left/click
|
||||||
|
GAMEPAD_SHOULDER_RIGHT_CLICK, // /user/gamepad/input/shoulder_right/click
|
||||||
|
GAMEPAD_THUMBSTICK_LEFT_CLICK, // /user/gamepad/input/thumbstick_left/click
|
||||||
|
GAMEPAD_THUMBSTICK_RIGHT_CLICK, // /user/gamepad/input/thumbstick_right/click
|
||||||
|
GAMEPAD_TRIGGER_LEFT_VALUE, // /user/gamepad/input/trigger_left/value
|
||||||
|
GAMEPAD_TRIGGER_RIGHT_VALUE, // /user/gamepad/input/trigger_right/value
|
||||||
|
GAMEPAD_THUMBSTICK_LEFT_X, // /user/gamepad/input/thumbstick_left/x
|
||||||
|
GAMEPAD_THUMBSTICK_LEFT_Y, // /user/gamepad/input/thumbstick_left/y
|
||||||
|
GAMEPAD_THUMBSTICK_RIGHT_X, // /user/gamepad/input/thumbstick_right/x
|
||||||
|
GAMEPAD_THUMBSTICK_RIGHT_Y, // /user/gamepad/input/thumbstick_right/y
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class interaction_profile : uint8_t
|
enum class interaction_profile : uint8_t
|
||||||
@@ -319,8 +345,8 @@ struct tracking
|
|||||||
XrFovf fov;
|
XrFovf fov;
|
||||||
};
|
};
|
||||||
|
|
||||||
// /user/hand/left and /user/hand/right
|
// /user/hand/left, /user/hand/right and /user/gamepad
|
||||||
std::array<interaction_profile, 2> interaction_profiles;
|
std::array<interaction_profile, 3> interaction_profiles;
|
||||||
|
|
||||||
XrTime production_timestamp;
|
XrTime production_timestamp;
|
||||||
XrTime timestamp;
|
XrTime timestamp;
|
||||||
|
|||||||
@@ -123,6 +123,7 @@ if (WIVRN_BUILD_SERVER)
|
|||||||
driver/wivrn_hmd.cpp
|
driver/wivrn_hmd.cpp
|
||||||
driver/wivrn_controller.cpp
|
driver/wivrn_controller.cpp
|
||||||
driver/wivrn_eye_tracker.cpp
|
driver/wivrn_eye_tracker.cpp
|
||||||
|
driver/wivrn_gamepad.cpp
|
||||||
driver/wivrn_android_face_tracker.cpp
|
driver/wivrn_android_face_tracker.cpp
|
||||||
driver/wivrn_fb_face2_tracker.cpp
|
driver/wivrn_fb_face2_tracker.cpp
|
||||||
driver/wivrn_htc_face_tracker.cpp
|
driver/wivrn_htc_face_tracker.cpp
|
||||||
|
|||||||
@@ -757,6 +757,9 @@ void wivrn_controller::set_inputs(const from_headset::inputs & inputs, const clo
|
|||||||
|
|
||||||
for (const auto & input: inputs.values)
|
for (const auto & input: inputs.values)
|
||||||
{
|
{
|
||||||
|
// Gamepad inputs are handled by wivrn_gamepad
|
||||||
|
if (input.id >= device_id::GAMEPAD_MENU_CLICK)
|
||||||
|
continue;
|
||||||
int64_t last_change_time = input.last_change_time ? clock_offset.from_headset(input.last_change_time) : 0;
|
int64_t last_change_time = input.last_change_time ? clock_offset.from_headset(input.last_change_time) : 0;
|
||||||
auto [index, type, device] = map_input(input.id);
|
auto [index, type, device] = map_input(input.id);
|
||||||
if (device != device_type)
|
if (device != device_type)
|
||||||
|
|||||||
@@ -0,0 +1,185 @@
|
|||||||
|
/*
|
||||||
|
* WiVRn VR streaming
|
||||||
|
* Copyright (C) 2026 JR Lanteigne <root@dnim.dev>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "wivrn_gamepad.h"
|
||||||
|
|
||||||
|
#include "wivrn_gamepad_map.h"
|
||||||
|
#include "wivrn_session.h"
|
||||||
|
|
||||||
|
#include "xrt/xrt_defines.h"
|
||||||
|
#include "xrt/xrt_device.h"
|
||||||
|
|
||||||
|
#include "os/os_time.h"
|
||||||
|
#include "util/u_logging.h"
|
||||||
|
#include "utils/method.h"
|
||||||
|
|
||||||
|
namespace wivrn
|
||||||
|
{
|
||||||
|
|
||||||
|
static_assert(gp_count == 18);
|
||||||
|
|
||||||
|
wivrn_gamepad::wivrn_gamepad(wivrn::wivrn_session & cnx) :
|
||||||
|
xrt_device{
|
||||||
|
.name = XRT_DEVICE_XBOX_CONTROLLER,
|
||||||
|
.device_type = XRT_DEVICE_TYPE_GAMEPAD,
|
||||||
|
.str = "WiVRn Gamepad",
|
||||||
|
.serial = "WiVRn Gamepad",
|
||||||
|
.tracking_origin = &origin,
|
||||||
|
.update_inputs = method_pointer<&wivrn_gamepad::update_inputs>,
|
||||||
|
.get_tracked_pose = method_pointer<&wivrn_gamepad::get_tracked_pose>,
|
||||||
|
.set_output = method_pointer<&wivrn_gamepad::set_output>,
|
||||||
|
.destroy = [](xrt_device *) {},
|
||||||
|
},
|
||||||
|
origin{
|
||||||
|
.type = XRT_TRACKING_TYPE_OTHER,
|
||||||
|
.initial_offset = XRT_POSE_IDENTITY,
|
||||||
|
},
|
||||||
|
cnx(&cnx)
|
||||||
|
{
|
||||||
|
inputs_array = {};
|
||||||
|
inputs_staging = {};
|
||||||
|
inputs = inputs_array.data();
|
||||||
|
input_count = inputs_array.size();
|
||||||
|
|
||||||
|
inputs_array[gp_menu].name = XRT_INPUT_XBOX_MENU_CLICK;
|
||||||
|
inputs_array[gp_view].name = XRT_INPUT_XBOX_VIEW_CLICK;
|
||||||
|
inputs_array[gp_a].name = XRT_INPUT_XBOX_A_CLICK;
|
||||||
|
inputs_array[gp_b].name = XRT_INPUT_XBOX_B_CLICK;
|
||||||
|
inputs_array[gp_x].name = XRT_INPUT_XBOX_X_CLICK;
|
||||||
|
inputs_array[gp_y].name = XRT_INPUT_XBOX_Y_CLICK;
|
||||||
|
inputs_array[gp_dpad_down].name = XRT_INPUT_XBOX_DPAD_DOWN_CLICK;
|
||||||
|
inputs_array[gp_dpad_right].name = XRT_INPUT_XBOX_DPAD_RIGHT_CLICK;
|
||||||
|
inputs_array[gp_dpad_up].name = XRT_INPUT_XBOX_DPAD_UP_CLICK;
|
||||||
|
inputs_array[gp_dpad_left].name = XRT_INPUT_XBOX_DPAD_LEFT_CLICK;
|
||||||
|
inputs_array[gp_shoulder_left].name = XRT_INPUT_XBOX_SHOULDER_LEFT_CLICK;
|
||||||
|
inputs_array[gp_shoulder_right].name = XRT_INPUT_XBOX_SHOULDER_RIGHT_CLICK;
|
||||||
|
inputs_array[gp_thumbstick_left_click].name = XRT_INPUT_XBOX_THUMBSTICK_LEFT_CLICK;
|
||||||
|
inputs_array[gp_thumbstick_right_click].name = XRT_INPUT_XBOX_THUMBSTICK_RIGHT_CLICK;
|
||||||
|
inputs_array[gp_thumbstick_left].name = XRT_INPUT_XBOX_THUMBSTICK_LEFT;
|
||||||
|
inputs_array[gp_thumbstick_right].name = XRT_INPUT_XBOX_THUMBSTICK_RIGHT;
|
||||||
|
inputs_array[gp_trigger_left].name = XRT_INPUT_XBOX_LEFT_TRIGGER_VALUE;
|
||||||
|
inputs_array[gp_trigger_right].name = XRT_INPUT_XBOX_RIGHT_TRIGGER_VALUE;
|
||||||
|
|
||||||
|
outputs_array = {{
|
||||||
|
{.name = XRT_OUTPUT_NAME_XBOX_HAPTIC_LEFT},
|
||||||
|
{.name = XRT_OUTPUT_NAME_XBOX_HAPTIC_RIGHT},
|
||||||
|
{.name = XRT_OUTPUT_NAME_XBOX_HAPTIC_LEFT_TRIGGER},
|
||||||
|
{.name = XRT_OUTPUT_NAME_XBOX_HAPTIC_RIGHT_TRIGGER},
|
||||||
|
}};
|
||||||
|
output_count = outputs_array.size();
|
||||||
|
outputs = outputs_array.data();
|
||||||
|
}
|
||||||
|
|
||||||
|
xrt_result_t wivrn_gamepad::update_inputs()
|
||||||
|
{
|
||||||
|
std::lock_guard lock(mutex);
|
||||||
|
|
||||||
|
const int64_t timestamp = os_monotonic_get_ns();
|
||||||
|
for (size_t i = 0; i < inputs_array.size(); ++i)
|
||||||
|
{
|
||||||
|
inputs_array[i].value = inputs_staging[i].value;
|
||||||
|
inputs_array[i].active = connected;
|
||||||
|
inputs_array[i].timestamp = timestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
return XRT_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
xrt_result_t wivrn_gamepad::get_tracked_pose(xrt_input_name name, int64_t, xrt_space_relation * out_relation)
|
||||||
|
{
|
||||||
|
// A gamepad has no tracked pose.
|
||||||
|
*out_relation = {};
|
||||||
|
U_LOG_XDEV_UNSUPPORTED_INPUT(this, u_log_get_global_level(), name);
|
||||||
|
return XRT_ERROR_INPUT_UNSUPPORTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
void wivrn_gamepad::set_inputs(const from_headset::inputs & inputs)
|
||||||
|
{
|
||||||
|
std::lock_guard lock(mutex);
|
||||||
|
|
||||||
|
for (const auto & value: inputs.values)
|
||||||
|
{
|
||||||
|
auto m = map_gamepad(value.id);
|
||||||
|
if (m.slot == gp_count)
|
||||||
|
continue;
|
||||||
|
auto & v = inputs_staging[m.slot].value;
|
||||||
|
switch (m.kind)
|
||||||
|
{
|
||||||
|
case gp_value::button:
|
||||||
|
case gp_value::dpad:
|
||||||
|
v.boolean = value.value != 0;
|
||||||
|
break;
|
||||||
|
case gp_value::trigger:
|
||||||
|
v.vec1.x = value.value;
|
||||||
|
break;
|
||||||
|
case gp_value::stick_x:
|
||||||
|
v.vec2.x = value.value;
|
||||||
|
break;
|
||||||
|
case gp_value::stick_y:
|
||||||
|
v.vec2.y = value.value;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
xrt_result_t wivrn_gamepad::set_output(xrt_output_name name, const xrt_output_value * value)
|
||||||
|
{
|
||||||
|
device_id id;
|
||||||
|
switch (name)
|
||||||
|
{
|
||||||
|
case XRT_OUTPUT_NAME_XBOX_HAPTIC_LEFT:
|
||||||
|
id = device_id::GAMEPAD_HAPTIC_LEFT;
|
||||||
|
break;
|
||||||
|
case XRT_OUTPUT_NAME_XBOX_HAPTIC_RIGHT:
|
||||||
|
id = device_id::GAMEPAD_HAPTIC_RIGHT;
|
||||||
|
break;
|
||||||
|
case XRT_OUTPUT_NAME_XBOX_HAPTIC_LEFT_TRIGGER:
|
||||||
|
id = device_id::GAMEPAD_HAPTIC_LEFT_TRIGGER;
|
||||||
|
break;
|
||||||
|
case XRT_OUTPUT_NAME_XBOX_HAPTIC_RIGHT_TRIGGER:
|
||||||
|
id = device_id::GAMEPAD_HAPTIC_RIGHT_TRIGGER;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return XRT_ERROR_OUTPUT_UNSUPPORTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
cnx->send_stream(to_headset::haptics{
|
||||||
|
.id = id,
|
||||||
|
.duration = std::chrono::nanoseconds(value->vibration.duration_ns),
|
||||||
|
.frequency = value->vibration.frequency,
|
||||||
|
.amplitude = value->vibration.amplitude});
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
return XRT_ERROR_OUTPUT_REQUEST_FAILURE;
|
||||||
|
}
|
||||||
|
return XRT_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
void wivrn_gamepad::set_connected(bool value)
|
||||||
|
{
|
||||||
|
std::lock_guard lock(mutex);
|
||||||
|
connected = value;
|
||||||
|
if (not connected)
|
||||||
|
for (auto & input: inputs_staging)
|
||||||
|
input.value = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace wivrn
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
/*
|
||||||
|
* WiVRn VR streaming
|
||||||
|
* Copyright (C) 2026 JR Lanteigne <root@dnim.dev>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "wivrn_packets.h"
|
||||||
|
|
||||||
|
#include "xrt/xrt_defines.h"
|
||||||
|
#include "xrt/xrt_device.h"
|
||||||
|
#include "xrt/xrt_tracking.h"
|
||||||
|
|
||||||
|
#include <array>
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
|
namespace wivrn
|
||||||
|
{
|
||||||
|
class wivrn_session;
|
||||||
|
|
||||||
|
// A gamepad forwarded from the headset, exposed as an OpenXR xbox_controller (/user/gamepad).
|
||||||
|
// Inputs stay inactive until the headset reports a gamepad is connected.
|
||||||
|
class wivrn_gamepad : public xrt_device
|
||||||
|
{
|
||||||
|
std::mutex mutex;
|
||||||
|
bool connected = false;
|
||||||
|
|
||||||
|
xrt_tracking_origin origin;
|
||||||
|
std::array<xrt_input, 18> inputs_array;
|
||||||
|
std::array<xrt_input, 18> inputs_staging; // written from the network thread, published by update_inputs
|
||||||
|
std::array<xrt_output, 4> outputs_array;
|
||||||
|
|
||||||
|
wivrn::wivrn_session * cnx;
|
||||||
|
|
||||||
|
public:
|
||||||
|
using base_t = xrt_device;
|
||||||
|
wivrn_gamepad(wivrn::wivrn_session & cnx);
|
||||||
|
|
||||||
|
xrt_result_t update_inputs();
|
||||||
|
xrt_result_t get_tracked_pose(xrt_input_name name, int64_t at_timestamp_ns, xrt_space_relation * out_relation);
|
||||||
|
xrt_result_t set_output(xrt_output_name name, const xrt_output_value * value);
|
||||||
|
|
||||||
|
// Update from a forwarded inputs packet (gamepad device_ids).
|
||||||
|
void set_inputs(const from_headset::inputs &);
|
||||||
|
void set_connected(bool);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace wivrn
|
||||||
@@ -0,0 +1,112 @@
|
|||||||
|
/*
|
||||||
|
* WiVRn VR streaming
|
||||||
|
* Copyright (C) 2026 JR Lanteigne <root@dnim.dev>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "wivrn_packets.h"
|
||||||
|
|
||||||
|
namespace wivrn
|
||||||
|
{
|
||||||
|
enum gp_input
|
||||||
|
{
|
||||||
|
gp_menu,
|
||||||
|
gp_view,
|
||||||
|
gp_a,
|
||||||
|
gp_b,
|
||||||
|
gp_x,
|
||||||
|
gp_y,
|
||||||
|
gp_dpad_down,
|
||||||
|
gp_dpad_right,
|
||||||
|
gp_dpad_up,
|
||||||
|
gp_dpad_left,
|
||||||
|
gp_shoulder_left,
|
||||||
|
gp_shoulder_right,
|
||||||
|
gp_thumbstick_left_click,
|
||||||
|
gp_thumbstick_right_click,
|
||||||
|
gp_thumbstick_left,
|
||||||
|
gp_thumbstick_right,
|
||||||
|
gp_trigger_left,
|
||||||
|
gp_trigger_right,
|
||||||
|
gp_count,
|
||||||
|
};
|
||||||
|
|
||||||
|
enum class gp_value
|
||||||
|
{
|
||||||
|
button,
|
||||||
|
dpad,
|
||||||
|
trigger,
|
||||||
|
stick_x,
|
||||||
|
stick_y,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct gamepad_input
|
||||||
|
{
|
||||||
|
gp_input slot;
|
||||||
|
gp_value kind;
|
||||||
|
};
|
||||||
|
|
||||||
|
inline gamepad_input map_gamepad(device_id id)
|
||||||
|
{
|
||||||
|
switch (id)
|
||||||
|
{
|
||||||
|
case device_id::GAMEPAD_MENU_CLICK:
|
||||||
|
return {gp_menu, gp_value::button};
|
||||||
|
case device_id::GAMEPAD_VIEW_CLICK:
|
||||||
|
return {gp_view, gp_value::button};
|
||||||
|
case device_id::GAMEPAD_A_CLICK:
|
||||||
|
return {gp_a, gp_value::button};
|
||||||
|
case device_id::GAMEPAD_B_CLICK:
|
||||||
|
return {gp_b, gp_value::button};
|
||||||
|
case device_id::GAMEPAD_X_CLICK:
|
||||||
|
return {gp_x, gp_value::button};
|
||||||
|
case device_id::GAMEPAD_Y_CLICK:
|
||||||
|
return {gp_y, gp_value::button};
|
||||||
|
case device_id::GAMEPAD_SHOULDER_LEFT_CLICK:
|
||||||
|
return {gp_shoulder_left, gp_value::button};
|
||||||
|
case device_id::GAMEPAD_SHOULDER_RIGHT_CLICK:
|
||||||
|
return {gp_shoulder_right, gp_value::button};
|
||||||
|
case device_id::GAMEPAD_THUMBSTICK_LEFT_CLICK:
|
||||||
|
return {gp_thumbstick_left_click, gp_value::button};
|
||||||
|
case device_id::GAMEPAD_THUMBSTICK_RIGHT_CLICK:
|
||||||
|
return {gp_thumbstick_right_click, gp_value::button};
|
||||||
|
case device_id::GAMEPAD_DPAD_DOWN_CLICK:
|
||||||
|
return {gp_dpad_down, gp_value::dpad};
|
||||||
|
case device_id::GAMEPAD_DPAD_RIGHT_CLICK:
|
||||||
|
return {gp_dpad_right, gp_value::dpad};
|
||||||
|
case device_id::GAMEPAD_DPAD_UP_CLICK:
|
||||||
|
return {gp_dpad_up, gp_value::dpad};
|
||||||
|
case device_id::GAMEPAD_DPAD_LEFT_CLICK:
|
||||||
|
return {gp_dpad_left, gp_value::dpad};
|
||||||
|
case device_id::GAMEPAD_TRIGGER_LEFT_VALUE:
|
||||||
|
return {gp_trigger_left, gp_value::trigger};
|
||||||
|
case device_id::GAMEPAD_TRIGGER_RIGHT_VALUE:
|
||||||
|
return {gp_trigger_right, gp_value::trigger};
|
||||||
|
case device_id::GAMEPAD_THUMBSTICK_LEFT_X:
|
||||||
|
return {gp_thumbstick_left, gp_value::stick_x};
|
||||||
|
case device_id::GAMEPAD_THUMBSTICK_LEFT_Y:
|
||||||
|
return {gp_thumbstick_left, gp_value::stick_y};
|
||||||
|
case device_id::GAMEPAD_THUMBSTICK_RIGHT_X:
|
||||||
|
return {gp_thumbstick_right, gp_value::stick_x};
|
||||||
|
case device_id::GAMEPAD_THUMBSTICK_RIGHT_Y:
|
||||||
|
return {gp_thumbstick_right, gp_value::stick_y};
|
||||||
|
default:
|
||||||
|
return {gp_count, gp_value::button};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace wivrn
|
||||||
@@ -126,6 +126,11 @@ wivrn::wivrn_session::wivrn_session(std::unique_ptr<wivrn_connection> connection
|
|||||||
static_roles.hand_tracking.unobstructed.right = static_xdevs[right_controller_index] = &right_controller;
|
static_roles.hand_tracking.unobstructed.right = static_xdevs[right_controller_index] = &right_controller;
|
||||||
static_xdevs[right_hand_interaction_index = static_xdev_count++] = &right_hand_interaction;
|
static_xdevs[right_hand_interaction_index = static_xdev_count++] = &right_hand_interaction;
|
||||||
|
|
||||||
|
// Expose a gamepad forwarded from the headset as a native OpenXR device (/user/gamepad).
|
||||||
|
// Always present; inactive until the headset reports a connected gamepad.
|
||||||
|
roles.gamepad = static_xdev_count;
|
||||||
|
static_xdevs[static_xdev_count++] = &gamepad_device.emplace(*this);
|
||||||
|
|
||||||
#if WIVRN_FEATURE_STEAMVR_LIGHTHOUSE
|
#if WIVRN_FEATURE_STEAMVR_LIGHTHOUSE
|
||||||
auto use_steamvr_lh = configuration().use_steamvr_lh || std::getenv("WIVRN_USE_STEAMVR_LH");
|
auto use_steamvr_lh = configuration().use_steamvr_lh || std::getenv("WIVRN_USE_STEAMVR_LH");
|
||||||
xrt_system_devices * lhdevs = NULL;
|
xrt_system_devices * lhdevs = NULL;
|
||||||
@@ -543,6 +548,9 @@ static xrt_device_name get_name(interaction_profile profile)
|
|||||||
|
|
||||||
void wivrn_session::operator()(const from_headset::tracking & tracking)
|
void wivrn_session::operator()(const from_headset::tracking & tracking)
|
||||||
{
|
{
|
||||||
|
if (gamepad_device)
|
||||||
|
gamepad_device->set_connected(tracking.interaction_profiles[2] != interaction_profile::none);
|
||||||
|
|
||||||
auto left = (roles.left == -1 || roles.left == left_controller_index || roles.left == left_hand_interaction_index) ? get_name(tracking.interaction_profiles[0]) : XRT_DEVICE_INVALID;
|
auto left = (roles.left == -1 || roles.left == left_controller_index || roles.left == left_hand_interaction_index) ? get_name(tracking.interaction_profiles[0]) : XRT_DEVICE_INVALID;
|
||||||
auto right = (roles.right == -1 || roles.right == right_controller_index || roles.right == right_hand_interaction_index) ? get_name(tracking.interaction_profiles[1]) : XRT_DEVICE_INVALID;
|
auto right = (roles.right == -1 || roles.right == right_controller_index || roles.right == right_hand_interaction_index) ? get_name(tracking.interaction_profiles[1]) : XRT_DEVICE_INVALID;
|
||||||
if (left != roles.left_profile or right != roles.right_profile)
|
if (left != roles.left_profile or right != roles.right_profile)
|
||||||
@@ -673,6 +681,9 @@ void wivrn_session::operator()(from_headset::inputs && inputs)
|
|||||||
right_hand_interaction.set_inputs(inputs, offset);
|
right_hand_interaction.set_inputs(inputs, offset);
|
||||||
else if (roles.right == right_controller_index)
|
else if (roles.right == right_controller_index)
|
||||||
right_controller.set_inputs(inputs, offset);
|
right_controller.set_inputs(inputs, offset);
|
||||||
|
|
||||||
|
if (gamepad_device)
|
||||||
|
gamepad_device->set_inputs(inputs);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wivrn_session::operator()(from_headset::hid::input && e)
|
void wivrn_session::operator()(from_headset::hid::input && e)
|
||||||
|
|||||||
@@ -30,6 +30,7 @@
|
|||||||
#include "wivrn_controller.h"
|
#include "wivrn_controller.h"
|
||||||
#include "wivrn_eye_tracker.h"
|
#include "wivrn_eye_tracker.h"
|
||||||
#include "wivrn_fb_face2_tracker.h"
|
#include "wivrn_fb_face2_tracker.h"
|
||||||
|
#include "wivrn_gamepad.h"
|
||||||
#include "wivrn_generic_tracker.h"
|
#include "wivrn_generic_tracker.h"
|
||||||
#include "wivrn_hmd.h"
|
#include "wivrn_hmd.h"
|
||||||
#include "wivrn_htc_face_tracker.h"
|
#include "wivrn_htc_face_tracker.h"
|
||||||
@@ -95,6 +96,7 @@ class wivrn_session : public xrt_system_devices
|
|||||||
wivrn_controller right_hand_interaction;
|
wivrn_controller right_hand_interaction;
|
||||||
int32_t right_hand_interaction_index;
|
int32_t right_hand_interaction_index;
|
||||||
std::optional<wivrn_eye_tracker> eye_tracker;
|
std::optional<wivrn_eye_tracker> eye_tracker;
|
||||||
|
std::optional<wivrn_gamepad> gamepad_device;
|
||||||
std::optional<wivrn_android_face_tracker> android_face_tracker;
|
std::optional<wivrn_android_face_tracker> android_face_tracker;
|
||||||
std::optional<wivrn_fb_face2_tracker> fb_face2_tracker;
|
std::optional<wivrn_fb_face2_tracker> fb_face2_tracker;
|
||||||
std::optional<wivrn_htc_face_tracker> htc_face_tracker;
|
std::optional<wivrn_htc_face_tracker> htc_face_tracker;
|
||||||
|
|||||||
Reference in New Issue
Block a user