mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-19 21:06:09 +00:00
fix: expose native Quest Touch controls
This commit is contained in:
1 parent
023daf57d2
commit
b60fac6dda
7 files changed
+184
-24
No files matched your search
@@ -20,6 +20,7 @@
|
||||
#include "xr_tracking_file.h"
|
||||
#include "xr_frame_math.h"
|
||||
#include "xr_vsync_timing.h"
|
||||
#include "xr_touch_input.h"
|
||||
|
||||
#define DD_EXPORT extern "C" __attribute__((visibility("default")))
|
||||
|
||||
@@ -385,12 +386,17 @@ public:
|
||||
EVRInitError Activate(uint32_t id) override {
|
||||
id_ = id;
|
||||
PropertyContainerHandle_t c = VRProperties()->TrackedDeviceToPropertyContainer(id_);
|
||||
VRProperties()->SetStringProperty(c, Prop_ModelNumber_String, "DroidDeck Pad Hand");
|
||||
VRProperties()->SetStringProperty(c, Prop_ManufacturerName_String, "DroidDeck");
|
||||
XrTrackingFile tracking;
|
||||
DroidDeckXrTracking packet{};
|
||||
xrMode_ = tracking.Read(&packet) && XrTrackingFile::Fresh(packet);
|
||||
VRProperties()->SetStringProperty(c, Prop_ModelNumber_String, xrMode_ ? "DroidDeck Quest Touch" : "DroidDeck Pad Hand");
|
||||
VRProperties()->SetStringProperty(c, Prop_ManufacturerName_String, xrMode_ ? "Meta" : "DroidDeck");
|
||||
VRProperties()->SetStringProperty(c, Prop_TrackingSystemName_String, "droiddeck");
|
||||
VRProperties()->SetStringProperty(c, Prop_RenderModelName_String, "generic_controller");
|
||||
VRProperties()->SetStringProperty(c, Prop_ControllerType_String, "vive_controller");
|
||||
VRProperties()->SetStringProperty(c, Prop_InputProfilePath_String, "{htc}/input/vive_controller_profile.json");
|
||||
VRProperties()->SetStringProperty(c, Prop_RenderModelName_String, xrMode_ ?
|
||||
(right_ ? "oculus_quest_plus_controller_right" : "oculus_quest_plus_controller_left") : "generic_controller");
|
||||
VRProperties()->SetStringProperty(c, Prop_ControllerType_String, xrMode_ ? "oculus_touch" : "vive_controller");
|
||||
VRProperties()->SetStringProperty(c, Prop_InputProfilePath_String, xrMode_ ?
|
||||
"{oculus}/input/touch_profile.json" : "{htc}/input/vive_controller_profile.json");
|
||||
VRProperties()->SetInt32Property(c, Prop_ControllerRoleHint_Int32,
|
||||
right_ ? TrackedControllerRole_RightHand : TrackedControllerRole_LeftHand);
|
||||
VRProperties()->SetInt32Property(c, Prop_DeviceClass_Int32, TrackedDeviceClass_Controller);
|
||||
@@ -400,12 +406,21 @@ public:
|
||||
in->CreateBooleanComponent(c, "/input/grip/click", &grip_);
|
||||
in->CreateBooleanComponent(c, "/input/trigger/click", &triggerClick_);
|
||||
in->CreateScalarComponent(c, "/input/trigger/value", &trigger_, VRScalarType_Absolute, VRScalarUnits_NormalizedOneSided);
|
||||
in->CreateScalarComponent(c, "/input/trackpad/x", &padX_, VRScalarType_Absolute, VRScalarUnits_NormalizedTwoSided);
|
||||
in->CreateScalarComponent(c, "/input/trackpad/y", &padY_, VRScalarType_Absolute, VRScalarUnits_NormalizedTwoSided);
|
||||
in->CreateBooleanComponent(c, "/input/trackpad/click", &padClick_);
|
||||
in->CreateBooleanComponent(c, "/input/trackpad/touch", &padTouch_);
|
||||
in->CreateScalarComponent(c, xrMode_ ? "/input/joystick/x" : "/input/trackpad/x", &padX_, VRScalarType_Absolute, VRScalarUnits_NormalizedTwoSided);
|
||||
in->CreateScalarComponent(c, xrMode_ ? "/input/joystick/y" : "/input/trackpad/y", &padY_, VRScalarType_Absolute, VRScalarUnits_NormalizedTwoSided);
|
||||
in->CreateBooleanComponent(c, xrMode_ ? "/input/joystick/click" : "/input/trackpad/click", &padClick_);
|
||||
in->CreateBooleanComponent(c, xrMode_ ? "/input/joystick/touch" : "/input/trackpad/touch", &padTouch_);
|
||||
if (xrMode_) {
|
||||
in->CreateScalarComponent(c, "/input/grip/value", &gripValue_, VRScalarType_Absolute, VRScalarUnits_NormalizedOneSided);
|
||||
in->CreateBooleanComponent(c, "/input/trigger/touch", &triggerTouch_);
|
||||
in->CreateBooleanComponent(c, right_ ? "/input/a/click" : "/input/x/click", &primaryClick_);
|
||||
in->CreateBooleanComponent(c, right_ ? "/input/b/click" : "/input/y/click", &secondaryClick_);
|
||||
in->CreateBooleanComponent(c, right_ ? "/input/a/touch" : "/input/x/touch", &primaryTouch_);
|
||||
in->CreateBooleanComponent(c, right_ ? "/input/b/touch" : "/input/y/touch", &secondaryTouch_);
|
||||
in->CreateBooleanComponent(c, "/input/thumbrest/touch", &thumbrestTouch_);
|
||||
}
|
||||
in->CreateHapticComponent(c, "/output/haptic", &haptic_);
|
||||
Log("%s hand activated (game pad)", right_ ? "right" : "left");
|
||||
Log("%s hand activated (%s)", right_ ? "right" : "left", xrMode_ ? "Quest Touch" : "game pad");
|
||||
return VRInitError_None;
|
||||
}
|
||||
void Deactivate() override { id_ = k_unTrackedDeviceIndexInvalid; }
|
||||
@@ -430,16 +445,26 @@ public:
|
||||
pose.result = pose.poseIsValid ? TrackingResult_Running_OK : TrackingResult_Running_OutOfRange;
|
||||
pose_ = pose;
|
||||
VRServerDriverHost()->TrackedDevicePoseUpdated(id_, pose, sizeof(pose));
|
||||
VRDriverInput()->UpdateScalarComponent(trigger_, hand.active ? hand.trigger : 0, 0);
|
||||
VRDriverInput()->UpdateBooleanComponent(triggerClick_, hand.active && hand.trigger > 0.6f, 0);
|
||||
VRDriverInput()->UpdateBooleanComponent(grip_, hand.active && hand.squeeze > 0.6f, 0);
|
||||
VRDriverInput()->UpdateScalarComponent(padX_, hand.active ? hand.stick[0] : 0, 0);
|
||||
VRDriverInput()->UpdateScalarComponent(padY_, hand.active ? hand.stick[1] : 0, 0);
|
||||
VRDriverInput()->UpdateBooleanComponent(padClick_, hand.active && (hand.buttons & 3u), 0);
|
||||
VRDriverInput()->UpdateBooleanComponent(padTouch_, hand.active &&
|
||||
(std::abs(hand.stick[0]) + std::abs(hand.stick[1]) > 0.01f || (hand.buttons & 1u)), 0);
|
||||
VRDriverInput()->UpdateBooleanComponent(menu_, hand.active && (hand.buttons & 12u), 0);
|
||||
VRDriverInput()->UpdateBooleanComponent(system_, hand.active && !right_ && (hand.buttons & 8u), 0);
|
||||
XrTouchInput input = xr_touch_input(hand, right_);
|
||||
auto driverInput = VRDriverInput();
|
||||
driverInput->UpdateScalarComponent(trigger_, input.trigger, 0);
|
||||
driverInput->UpdateBooleanComponent(triggerClick_, input.triggerClick, 0);
|
||||
driverInput->UpdateBooleanComponent(grip_, input.gripClick, 0);
|
||||
driverInput->UpdateScalarComponent(padX_, input.stickX, 0);
|
||||
driverInput->UpdateScalarComponent(padY_, input.stickY, 0);
|
||||
driverInput->UpdateBooleanComponent(padClick_, input.stickClick, 0);
|
||||
driverInput->UpdateBooleanComponent(padTouch_, input.stickTouch, 0);
|
||||
driverInput->UpdateBooleanComponent(menu_, input.menuClick, 0);
|
||||
driverInput->UpdateBooleanComponent(system_, false, 0);
|
||||
if (xrMode_) {
|
||||
driverInput->UpdateScalarComponent(gripValue_, input.grip, 0);
|
||||
driverInput->UpdateBooleanComponent(triggerTouch_, input.triggerTouch, 0);
|
||||
driverInput->UpdateBooleanComponent(primaryClick_, input.primaryClick, 0);
|
||||
driverInput->UpdateBooleanComponent(secondaryClick_, input.secondaryClick, 0);
|
||||
driverInput->UpdateBooleanComponent(primaryTouch_, input.primaryTouch, 0);
|
||||
driverInput->UpdateBooleanComponent(secondaryTouch_, input.secondaryTouch, 0);
|
||||
driverInput->UpdateBooleanComponent(thumbrestTouch_, input.thumbrestTouch, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void Update(const HmdQuaternion_t &head, const PadState *pad) {
|
||||
@@ -479,10 +504,13 @@ public:
|
||||
|
||||
private:
|
||||
bool right_;
|
||||
bool xrMode_ = false;
|
||||
uint32_t id_ = k_unTrackedDeviceIndexInvalid;
|
||||
DriverPose_t pose_ = {};
|
||||
VRInputComponentHandle_t system_ = 0, menu_ = 0, grip_ = 0, triggerClick_ = 0, trigger_ = 0, padX_ = 0, padY_ = 0,
|
||||
padClick_ = 0, padTouch_ = 0, haptic_ = 0;
|
||||
VRInputComponentHandle_t gripValue_ = 0, triggerTouch_ = 0, primaryClick_ = 0, secondaryClick_ = 0,
|
||||
primaryTouch_ = 0, secondaryTouch_ = 0, thumbrestTouch_ = 0;
|
||||
};
|
||||
|
||||
class CardboardHmd : public ITrackedDeviceServerDriver, public IVRDisplayComponent {
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
#pragma once
|
||||
#include "xr_tracking.h"
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
|
||||
struct XrTouchInput {
|
||||
float trigger = 0, grip = 0, stickX = 0, stickY = 0;
|
||||
bool triggerClick = false, gripClick = false, stickClick = false;
|
||||
bool primaryClick = false, secondaryClick = false, menuClick = false;
|
||||
bool triggerTouch = false, stickTouch = false, primaryTouch = false, secondaryTouch = false, thumbrestTouch = false;
|
||||
};
|
||||
|
||||
inline XrTouchInput xr_touch_input(const DroidDeckXrHand &hand, bool right) {
|
||||
XrTouchInput input;
|
||||
if (!hand.active) return input;
|
||||
auto scalar = [](float value, float minimum) { return std::isfinite(value) ? std::clamp(value, minimum, 1.f) : 0.f; };
|
||||
input.trigger = scalar(hand.trigger, 0);
|
||||
input.grip = scalar(hand.squeeze, 0);
|
||||
input.stickX = scalar(hand.stick[0], -1);
|
||||
input.stickY = scalar(hand.stick[1], -1);
|
||||
input.triggerClick = input.trigger > 0.6f;
|
||||
input.gripClick = input.grip > 0.6f;
|
||||
input.stickClick = hand.buttons & DROIDDECK_XR_STICK_CLICK;
|
||||
input.primaryClick = hand.buttons & DROIDDECK_XR_PRIMARY_CLICK;
|
||||
input.secondaryClick = hand.buttons & DROIDDECK_XR_SECONDARY_CLICK;
|
||||
input.menuClick = !right && (hand.buttons & DROIDDECK_XR_MENU_CLICK);
|
||||
input.triggerTouch = hand.buttons & DROIDDECK_XR_TRIGGER_TOUCH;
|
||||
input.stickTouch = hand.buttons & DROIDDECK_XR_STICK_TOUCH;
|
||||
input.primaryTouch = hand.buttons & DROIDDECK_XR_PRIMARY_TOUCH;
|
||||
input.secondaryTouch = hand.buttons & DROIDDECK_XR_SECONDARY_TOUCH;
|
||||
input.thumbrestTouch = hand.buttons & DROIDDECK_XR_THUMBREST_TOUCH;
|
||||
return input;
|
||||
}
|
||||
@@ -4,6 +4,15 @@
|
||||
#define DROIDDECK_XR_MAGIC 0x52584444u
|
||||
#define DROIDDECK_XR_VERSION 1u
|
||||
#define DROIDDECK_XR_FILE "droiddeck-xr-tracking"
|
||||
#define DROIDDECK_XR_STICK_CLICK (1u << 0)
|
||||
#define DROIDDECK_XR_PRIMARY_CLICK (1u << 1)
|
||||
#define DROIDDECK_XR_SECONDARY_CLICK (1u << 2)
|
||||
#define DROIDDECK_XR_MENU_CLICK (1u << 3)
|
||||
#define DROIDDECK_XR_TRIGGER_TOUCH (1u << 4)
|
||||
#define DROIDDECK_XR_STICK_TOUCH (1u << 5)
|
||||
#define DROIDDECK_XR_PRIMARY_TOUCH (1u << 6)
|
||||
#define DROIDDECK_XR_SECONDARY_TOUCH (1u << 7)
|
||||
#define DROIDDECK_XR_THUMBREST_TOUCH (1u << 8)
|
||||
|
||||
struct DroidDeckXrPose {
|
||||
float orientation[4];
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
#include "../src/xr_touch_input.h"
|
||||
#include <cassert>
|
||||
#include <cstdio>
|
||||
#include <limits>
|
||||
|
||||
int main() {
|
||||
DroidDeckXrHand hand{};
|
||||
hand.active = 1;
|
||||
hand.trigger = 0.7f; hand.squeeze = 0.8f;
|
||||
hand.stick[0] = -0.4f; hand.stick[1] = 0.9f;
|
||||
auto input = xr_touch_input(hand, false);
|
||||
assert(input.trigger == hand.trigger && input.grip == hand.squeeze && input.triggerClick && input.gripClick);
|
||||
assert(input.stickX == -0.4f && input.stickY == 0.9f);
|
||||
assert(!input.stickTouch && !input.stickClick && !input.primaryClick && !input.secondaryClick && !input.menuClick);
|
||||
hand.buttons = DROIDDECK_XR_PRIMARY_CLICK;
|
||||
input = xr_touch_input(hand, false);
|
||||
assert(input.primaryClick && !input.secondaryClick && !input.stickClick && !input.menuClick && !input.primaryTouch);
|
||||
hand.buttons = DROIDDECK_XR_SECONDARY_CLICK;
|
||||
input = xr_touch_input(hand, true);
|
||||
assert(input.secondaryClick && !input.primaryClick && !input.menuClick && !input.stickClick);
|
||||
hand.buttons = DROIDDECK_XR_STICK_CLICK;
|
||||
input = xr_touch_input(hand, true);
|
||||
assert(input.stickClick && !input.primaryClick && !input.stickTouch);
|
||||
hand.buttons = DROIDDECK_XR_MENU_CLICK;
|
||||
assert(xr_touch_input(hand, false).menuClick);
|
||||
assert(!xr_touch_input(hand, true).menuClick);
|
||||
hand.buttons = DROIDDECK_XR_TRIGGER_TOUCH | DROIDDECK_XR_STICK_TOUCH | DROIDDECK_XR_PRIMARY_TOUCH |
|
||||
DROIDDECK_XR_SECONDARY_TOUCH | DROIDDECK_XR_THUMBREST_TOUCH;
|
||||
hand.trigger = hand.squeeze = 0;
|
||||
input = xr_touch_input(hand, false);
|
||||
assert(input.triggerTouch && input.stickTouch && input.primaryTouch && input.secondaryTouch && input.thumbrestTouch);
|
||||
assert(!input.triggerClick && !input.gripClick && !input.primaryClick && !input.secondaryClick && !input.stickClick);
|
||||
hand.trigger = 2; hand.squeeze = -2; hand.stick[0] = -3; hand.stick[1] = 3;
|
||||
input = xr_touch_input(hand, false);
|
||||
assert(input.trigger == 1 && input.grip == 0 && input.stickX == -1 && input.stickY == 1);
|
||||
hand.trigger = std::numeric_limits<float>::quiet_NaN();
|
||||
hand.squeeze = std::numeric_limits<float>::infinity();
|
||||
hand.stick[0] = hand.trigger; hand.stick[1] = -hand.squeeze;
|
||||
input = xr_touch_input(hand, false);
|
||||
assert(input.trigger == 0 && input.grip == 0 && input.stickX == 0 && input.stickY == 0);
|
||||
hand.active = 0;
|
||||
hand.buttons = UINT32_MAX;
|
||||
hand.trigger = hand.squeeze = hand.stick[0] = hand.stick[1] = 1;
|
||||
input = xr_touch_input(hand, false);
|
||||
assert(input.trigger == 0 && input.grip == 0 && input.stickX == 0 && input.stickY == 0);
|
||||
assert(!input.triggerClick && !input.gripClick && !input.stickClick && !input.primaryClick && !input.secondaryClick && !input.menuClick);
|
||||
assert(!input.triggerTouch && !input.stickTouch && !input.primaryTouch && !input.secondaryTouch && !input.thumbrestTouch);
|
||||
std::puts("Touch input: independent face/stick/menu, real capacitive touch, analog grip, clamping and inactive reset passed");
|
||||
}
|
||||
Reference in new issue
Block a user