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:
@@ -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/grasp_ext/value", device_id::RIGHT_GRASP_VALUE},
|
||||
{"/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
|
||||
|
||||
@@ -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::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::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)
|
||||
{
|
||||
|
||||
@@ -76,7 +76,7 @@ private:
|
||||
std::unique_ptr<wivrn_session> network_session;
|
||||
std::thread network_thread;
|
||||
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<XrTime> scheduled_derived_pose = 0; // Tracking thread will compute derived pose when time is reached
|
||||
std::atomic<bool> recenter_requested = false;
|
||||
|
||||
@@ -443,6 +443,7 @@ void scenes::stream::tracking()
|
||||
tracking.interaction_profiles = {
|
||||
interaction_profiles[0].load(),
|
||||
interaction_profiles[1].load(),
|
||||
interaction_profiles[2].load(),
|
||||
};
|
||||
|
||||
tracking.production_timestamp = t0;
|
||||
@@ -664,6 +665,7 @@ void scenes::stream::on_interaction_profile_changed(const XrEventDataInteraction
|
||||
std::array path = {
|
||||
"/user/hand/left",
|
||||
"/user/hand/right",
|
||||
"/user/gamepad",
|
||||
};
|
||||
#define DO_PROFILE(vendor, name) \
|
||||
if (profile == "/interaction_profiles/" #vendor "/" #name) \
|
||||
@@ -672,7 +674,7 @@ void scenes::stream::on_interaction_profile_changed(const XrEventDataInteraction
|
||||
continue; \
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < 2; ++i)
|
||||
for (size_t i = 0; i < path.size(); ++i)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user