refactor: ♻️ Make OpenVR props setting format more concise

This commit is contained in:
Riccardo Zaglia 2023-09-07 17:06:01 +08:00
parent a0200df7df
commit 2e928913b3
4 changed files with 336 additions and 324 deletions

View File

@ -568,8 +568,7 @@ fn try_connect(mut client_ips: HashMap<IpAddr, String>) -> ConResult {
crate::SetOpenvrProperty(
*alvr_common::HEAD_ID,
crate::openvr_props::to_ffi_openvr_prop(
alvr_session::OpenvrPropertyKey::AudioDefaultPlaybackDeviceId,
alvr_session::OpenvrPropValue::String(id),
alvr_session::OpenvrProperty::AudioDefaultPlaybackDeviceId(id),
),
)
}
@ -595,8 +594,7 @@ fn try_connect(mut client_ips: HashMap<IpAddr, String>) -> ConResult {
crate::SetOpenvrProperty(
*alvr_common::HEAD_ID,
crate::openvr_props::to_ffi_openvr_prop(
alvr_session::OpenvrPropertyKey::AudioDefaultPlaybackDeviceId,
alvr_session::OpenvrPropValue::String(id),
alvr_session::OpenvrProperty::AudioDefaultPlaybackDeviceId(id),
),
)
}
@ -621,8 +619,7 @@ fn try_connect(mut client_ips: HashMap<IpAddr, String>) -> ConResult {
crate::SetOpenvrProperty(
*alvr_common::HEAD_ID,
crate::openvr_props::to_ffi_openvr_prop(
alvr_session::OpenvrPropertyKey::AudioDefaultRecordingDeviceId,
alvr_session::OpenvrPropValue::String(id),
alvr_session::OpenvrProperty::AudioDefaultRecordingDeviceId(id),
),
)
}

View File

@ -5,15 +5,16 @@
use crate::{FfiOpenvrProperty, FfiOpenvrPropertyValue, SERVER_DATA_MANAGER};
use alvr_common::{info, settings_schema::Switch, HEAD_ID, LEFT_HAND_ID, RIGHT_HAND_ID};
use alvr_session::{
ControllersEmulationMode, HeadsetEmulationMode, OpenvrPropValue,
OpenvrPropertyKey::{self, *},
ControllersEmulationMode, HeadsetEmulationMode, OpenvrPropValue, OpenvrProperty,
};
use std::{
ffi::{c_char, CString},
ptr,
};
pub fn to_ffi_openvr_prop(key: OpenvrPropertyKey, value: OpenvrPropValue) -> FfiOpenvrProperty {
pub fn to_ffi_openvr_prop(prop: OpenvrProperty) -> FfiOpenvrProperty {
let (key, value) = prop.into_key_value();
let type_ = match value {
OpenvrPropValue::Bool(_) => crate::FfiOpenvrPropertyType_Bool,
OpenvrPropValue::Float(_) => crate::FfiOpenvrPropertyType_Float,
@ -49,11 +50,7 @@ pub fn to_ffi_openvr_prop(key: OpenvrPropertyKey, value: OpenvrPropValue) -> Ffi
}
};
FfiOpenvrProperty {
key: key as u32,
type_,
value,
}
FfiOpenvrProperty { key, type_, value }
}
fn serial_number(device_id: u64) -> String {
@ -106,106 +103,96 @@ pub extern "C" fn get_serial_number(device_id: u64, out_str: *mut c_char) -> u64
#[no_mangle]
pub extern "C" fn set_device_openvr_props(device_id: u64) {
use OpenvrProperty::*;
let data_manager_lock = SERVER_DATA_MANAGER.read();
let settings = data_manager_lock.settings();
if device_id == *HEAD_ID {
fn set_prop(key: OpenvrPropertyKey, value: OpenvrPropValue) {
info!("Setting head OpenVR prop: {key:?} => {value:?}");
fn set_prop(prop: OpenvrProperty) {
info!("Setting head OpenVR prop: {prop:?}");
unsafe {
crate::SetOpenvrProperty(*HEAD_ID, to_ffi_openvr_prop(key, value));
crate::SetOpenvrProperty(*HEAD_ID, to_ffi_openvr_prop(prop));
}
}
fn set_string(key: OpenvrPropertyKey, value: &str) {
set_prop(key, OpenvrPropValue::String(value.into()));
}
match &settings.headset.emulation_mode {
HeadsetEmulationMode::RiftS => {
set_string(TrackingSystemName, "oculus");
set_string(ModelNumber, "Oculus Rift S");
set_string(ManufacturerName, "Oculus");
set_string(RenderModelName, "generic_hmd");
set_string(RegisteredDeviceType, "oculus/1WMGH000XX0000");
set_string(DriverVersion, "1.42.0");
set_prop(TrackingSystemName("oculus".into()));
set_prop(ModelNumber("Oculus Rift S".into()));
set_prop(ManufacturerName("Oculus".into()));
set_prop(RenderModelName("generic_hmd".into()));
set_prop(RegisteredDeviceType("oculus/1WMGH000XX0000".into()));
set_prop(DriverVersion("1.42.0".into()));
}
HeadsetEmulationMode::Vive => {
set_string(TrackingSystemName, "Vive Tracker");
set_string(ModelNumber, "ALVR driver server");
set_string(ManufacturerName, "HTC");
set_string(RenderModelName, "generic_hmd");
set_string(RegisteredDeviceType, "vive");
set_string(DriverVersion, "");
set_prop(TrackingSystemName("Vive Tracker".into()));
set_prop(ModelNumber("ALVR driver server".into()));
set_prop(ManufacturerName("HTC".into()));
set_prop(RenderModelName("generic_hmd".into()));
set_prop(RegisteredDeviceType("vive".into()));
set_prop(DriverVersion("".into()));
}
HeadsetEmulationMode::Quest2 => {
set_string(TrackingSystemName, "oculus");
set_string(ModelNumber, "Miramar");
set_string(ManufacturerName, "Oculus");
set_string(RenderModelName, "generic_hmd");
set_string(RegisteredDeviceType, "oculus/1WMHH000X00000");
set_string(DriverVersion, "1.55.0");
set_prop(TrackingSystemName("oculus".into()));
set_prop(ModelNumber("Miramar".into()));
set_prop(ManufacturerName("Oculus".into()));
set_prop(RenderModelName("generic_hmd".into()));
set_prop(RegisteredDeviceType("oculus/1WMHH000X00000".into()));
set_prop(DriverVersion("1.55.0".into()));
}
HeadsetEmulationMode::Custom { props, .. } => {
for prop in props {
set_prop(prop.key, prop.value.clone());
set_prop(prop.clone());
}
}
}
set_prop(UserIpdMeters, OpenvrPropValue::Float(0.063));
set_prop(UserHeadToEyeDepthMeters, OpenvrPropValue::Float(0.0));
set_prop(SecondsFromVsyncToPhotons, OpenvrPropValue::Float(0.0));
set_prop(UserIpdMeters(0.063));
set_prop(UserHeadToEyeDepthMeters(0.0));
set_prop(SecondsFromVsyncToPhotons(0.0));
// return a constant that's not 0 (invalid) or 1 (reserved for Oculus)
set_prop(CurrentUniverseId, OpenvrPropValue::Uint64(2));
set_prop(CurrentUniverseId(2));
if cfg!(windows) {
// avoid "not fullscreen" warnings from vrmonitor
set_prop(IsOnDesktop, OpenvrPropValue::Bool(false));
set_prop(IsOnDesktop(false));
// We let SteamVR handle VSyncs. We just wait in PostPresent().
set_prop(
DriverDirectModeSendsVsyncEvents,
OpenvrPropValue::Bool(false),
);
set_prop(DriverDirectModeSendsVsyncEvents(false));
}
set_prop(DeviceProvidesBatteryStatus, OpenvrPropValue::Bool(true));
set_prop(ContainsProximitySensor, OpenvrPropValue::Bool(true));
set_prop(DeviceProvidesBatteryStatus(true));
set_prop(ContainsProximitySensor(true));
// todo: set different strings for each emulation mode
set_string(
NamedIconPathDeviceOff,
"{oculus}/icons/quest_headset_off.png",
);
set_string(
NamedIconPathDeviceSearching,
"{oculus}/icons/quest_headset_searching.gif",
);
set_string(
NamedIconPathDeviceSearchingAlert,
"{oculus}/icons/quest_headset_alert_searching.gif",
);
set_string(
NamedIconPathDeviceReady,
"{oculus}/icons/quest_headset_ready.png",
);
set_string(
NamedIconPathDeviceReadyAlert,
"{oculus}/icons/quest_headset_ready_alert.png",
);
set_string(
NamedIconPathDeviceStandby,
"{oculus}/icons/quest_headset_standby.png",
);
set_prop(NamedIconPathDeviceOff(
"{oculus}/icons/quest_headset_off.png".into(),
));
set_prop(NamedIconPathDeviceSearching(
"{oculus}/icons/quest_headset_searching.gif".into(),
));
set_prop(NamedIconPathDeviceSearchingAlert(
"{oculus}/icons/quest_headset_alert_searching.gif".into(),
));
set_prop(NamedIconPathDeviceReady(
"{oculus}/icons/quest_headset_ready.png".into(),
));
set_prop(NamedIconPathDeviceReadyAlert(
"{oculus}/icons/quest_headset_ready_alert.png".into(),
));
set_prop(NamedIconPathDeviceStandby(
"{oculus}/icons/quest_headset_standby.png".into(),
));
for prop in &settings.headset.extra_openvr_props {
set_prop(prop.key, prop.value.clone());
set_prop(prop.clone());
}
} else if device_id == *LEFT_HAND_ID || device_id == *RIGHT_HAND_ID {
if let Switch::Enabled(config) = &settings.headset.controllers {
let set_prop = |key, value| {
let set_prop = |prop| {
info!(
"Setting {} controller OpenVR prop: {key:?} => {value:?}",
"Setting {} controller OpenVR prop: {prop:?}",
if device_id == *LEFT_HAND_ID {
"left"
} else {
@ -213,168 +200,144 @@ pub extern "C" fn set_device_openvr_props(device_id: u64) {
}
);
unsafe {
crate::SetOpenvrProperty(device_id, to_ffi_openvr_prop(key, value));
crate::SetOpenvrProperty(device_id, to_ffi_openvr_prop(prop));
}
};
let set_bool = |key, value| {
set_prop(key, OpenvrPropValue::Bool(value));
};
let set_int32 = |key, value| {
set_prop(key, OpenvrPropValue::Int32(value));
};
let set_uint64 = |key, value| {
set_prop(key, OpenvrPropValue::Uint64(value));
};
let set_string = |key, value: &str| {
set_prop(key, OpenvrPropValue::String(value.into()));
};
match config.emulation_mode {
ControllersEmulationMode::Quest2Touch => {
set_string(TrackingSystemName, "oculus");
set_string(ManufacturerName, "Oculus");
set_prop(TrackingSystemName("oculus".into()));
set_prop(ManufacturerName("Oculus".into()));
if device_id == *LEFT_HAND_ID {
set_string(ModelNumber, "Miramar (Left Controller)");
set_string(RenderModelName, "oculus_quest2_controller_left");
set_string(
RegisteredDeviceType,
"oculus/1WMHH000X00000_Controller_Left",
);
set_prop(ModelNumber("Miramar (Left Controller)".into()));
set_prop(RenderModelName("oculus_quest2_controller_left".into()));
set_prop(RegisteredDeviceType(
"oculus/1WMHH000X00000_Controller_Left".into(),
));
} else if device_id == *RIGHT_HAND_ID {
set_string(ModelNumber, "Miramar (Right Controller)");
set_string(RenderModelName, "oculus_quest2_controller_right");
set_string(
RegisteredDeviceType,
"oculus/1WMHH000X00000_Controller_Right",
);
set_prop(ModelNumber("Miramar (Right Controller)".into()));
set_prop(RenderModelName("oculus_quest2_controller_right".into()));
set_prop(RegisteredDeviceType(
"oculus/1WMHH000X00000_Controller_Right".into(),
));
}
set_string(ControllerType, "oculus_touch");
set_string(InputProfilePath, "{oculus}/input/touch_profile.json");
set_prop(ControllerType("oculus_touch".into()));
set_prop(InputProfilePath("{oculus}/input/touch_profile.json".into()));
if device_id == *LEFT_HAND_ID {
set_string(
NamedIconPathDeviceOff,
"{oculus}/icons/rifts_left_controller_off.png",
);
set_string(
NamedIconPathDeviceSearching,
"{oculus}/icons/rifts_left_controller_searching.gif",
);
set_string(
NamedIconPathDeviceSearchingAlert,
"{oculus}/icons/rifts_left_controller_searching_alert.gif",
);
set_string(
NamedIconPathDeviceReady,
"{oculus}/icons/rifts_left_controller_ready.png",
);
set_string(
NamedIconPathDeviceReadyAlert,
"{oculus}/icons/rifts_left_controller_ready_alert.png",
);
set_string(
NamedIconPathDeviceAlertLow,
"{oculus}/icons/rifts_left_controller_ready_low.png",
);
set_prop(NamedIconPathDeviceOff(
"{oculus}/icons/rifts_left_controller_off.png".into(),
));
set_prop(NamedIconPathDeviceSearching(
"{oculus}/icons/rifts_left_controller_searching.gif".into(),
));
set_prop(NamedIconPathDeviceSearchingAlert(
"{oculus}/icons/rifts_left_controller_searching_alert.gif".into(),
));
set_prop(NamedIconPathDeviceReady(
"{oculus}/icons/rifts_left_controller_ready.png".into(),
));
set_prop(NamedIconPathDeviceReadyAlert(
"{oculus}/icons/rifts_left_controller_ready_alert.png".into(),
));
set_prop(NamedIconPathDeviceAlertLow(
"{oculus}/icons/rifts_left_controller_ready_low.png".into(),
));
} else if device_id == *RIGHT_HAND_ID {
set_string(
NamedIconPathDeviceOff,
"{oculus}/icons/rifts_right_controller_off.png",
);
set_string(
NamedIconPathDeviceSearching,
"{oculus}/icons/rifts_right_controller_searching.gif",
);
set_string(
NamedIconPathDeviceSearchingAlert,
"{oculus}/icons/rifts_right_controller_searching_alert.gif",
);
set_string(
NamedIconPathDeviceReady,
"{oculus}/icons/rifts_right_controller_ready.png",
);
set_string(
NamedIconPathDeviceReadyAlert,
"{oculus}/icons/rifts_right_controller_ready_alert.png",
);
set_string(
NamedIconPathDeviceAlertLow,
"{oculus}/icons/rifts_right_controller_ready_low.png",
);
set_prop(NamedIconPathDeviceOff(
"{oculus}/icons/rifts_right_controller_off.png".into(),
));
set_prop(NamedIconPathDeviceSearching(
"{oculus}/icons/rifts_right_controller_searching.gif".into(),
));
set_prop(NamedIconPathDeviceSearchingAlert(
"{oculus}/icons/rifts_right_controller_searching_alert.gif".into(),
));
set_prop(NamedIconPathDeviceReady(
"{oculus}/icons/rifts_right_controller_ready.png".into(),
));
set_prop(NamedIconPathDeviceReadyAlert(
"{oculus}/icons/rifts_right_controller_ready_alert.png".into(),
));
set_prop(NamedIconPathDeviceAlertLow(
"{oculus}/icons/rifts_right_controller_ready_low.png".into(),
));
}
}
ControllersEmulationMode::ValveIndex => {
set_string(TrackingSystemName, "indexcontroller");
set_string(ManufacturerName, "Valve");
set_prop(TrackingSystemName("indexcontroller".into()));
set_prop(ManufacturerName("Valve".into()));
if device_id == *LEFT_HAND_ID {
set_string(ModelNumber, "Knuckles (Left Controller)");
set_string(
RenderModelName,
"{indexcontroller}valve_controller_knu_1_0_left",
);
set_string(
RegisteredDeviceType,
"valve/index_controllerLHR-E217CD00_Left",
);
set_prop(ModelNumber("Knuckles (Left Controller)".into()));
set_prop(RenderModelName(
"{indexcontroller}valve_controller_knu_1_0_left".into(),
));
set_prop(RegisteredDeviceType(
"valve/index_controllerLHR-E217CD00_Left".into(),
));
} else if device_id == *RIGHT_HAND_ID {
set_string(ModelNumber, "Knuckles (Right Controller)");
set_string(
RenderModelName,
"{indexcontroller}valve_controller_knu_1_0_right",
);
set_string(
RegisteredDeviceType,
"valve/index_controllerLHR-E217CD00_Right",
);
set_prop(ModelNumber("Knuckles (Right Controller)".into()));
set_prop(RenderModelName(
"{indexcontroller}valve_controller_knu_1_0_right".into(),
));
set_prop(RegisteredDeviceType(
"valve/index_controllerLHR-E217CD00_Right".into(),
));
}
set_string(ControllerType, "knuckles");
set_string(
InputProfilePath,
"{indexcontroller}/input/index_controller_profile.json",
);
set_prop(ControllerType("knuckles".into()));
set_prop(InputProfilePath(
"{indexcontroller}/input/index_controller_profile.json".into(),
));
}
ControllersEmulationMode::ViveWand => {
set_string(TrackingSystemName, "htc");
set_string(ManufacturerName, "HTC");
set_string(RenderModelName, "vr_controller_vive_1_5");
set_prop(TrackingSystemName("htc".into()));
set_prop(ManufacturerName("HTC".into()));
set_prop(RenderModelName("vr_controller_vive_1_5".into()));
if device_id == *LEFT_HAND_ID {
set_string(ModelNumber, "ALVR Remote Controller (Left Controller)");
set_string(RegisteredDeviceType, "vive_controller_Left");
set_prop(ModelNumber(
"ALVR Remote Controller (Left Controller)".into(),
));
set_prop(RegisteredDeviceType("vive_controller_Left".into()));
} else if device_id == *RIGHT_HAND_ID {
set_string(ModelNumber, "ALVR Remote Controller (Right Controller)");
set_string(RegisteredDeviceType, "oculus/vive_controller_Right");
set_prop(ModelNumber(
"ALVR Remote Controller (Right Controller)".into(),
));
set_prop(RegisteredDeviceType("oculus/vive_controller_Right".into()));
}
set_string(ControllerType, "vive_controller");
set_string(InputProfilePath, "{oculus}/input/touch_profile.json");
set_prop(ControllerType("vive_controller".into()));
set_prop(InputProfilePath("{oculus}/input/touch_profile.json".into()));
}
ControllersEmulationMode::ViveTracker => {
set_string(TrackingSystemName, "lighthouse");
set_string(RenderModelName, "{htc}vr_tracker_vive_1_0");
set_prop(TrackingSystemName("lighthouse".into()));
set_prop(RenderModelName("{htc}vr_tracker_vive_1_0".into()));
if device_id == *LEFT_HAND_ID {
set_string(ModelNumber, "Vive Tracker Pro MV (Left Controller)");
set_string(RegisteredDeviceType, "ALVR/tracker/left_foot");
set_string(ControllerType, "vive_tracker_left_foot");
set_prop(ModelNumber("Vive Tracker Pro MV (Left Controller)".into()));
set_prop(RegisteredDeviceType("ALVR/tracker/left_foot".into()));
set_prop(ControllerType("vive_tracker_left_foot".into()));
} else if device_id == *RIGHT_HAND_ID {
set_string(ModelNumber, "Vive Tracker Pro MV (Right Controller)");
set_string(RegisteredDeviceType, "ALVR/tracker/right_foot");
set_string(ControllerType, "vive_tracker_right_foot");
set_prop(ModelNumber("Vive Tracker Pro MV (Right Controller)".into()));
set_prop(RegisteredDeviceType("ALVR/tracker/right_foot".into()));
set_prop(ControllerType("vive_tracker_right_foot".into()));
}
set_string(InputProfilePath, "{htc}/input/vive_tracker_profile.json");
set_prop(InputProfilePath(
"{htc}/input/vive_tracker_profile.json".into(),
));
// All of these property values were dumped from real a vive tracker via
// https://github.com/SDraw/openvr_dumper and were copied from
// https://github.com/SDraw/driver_kinectV2
set_string(ResourceRoot, "htc");
set_bool(WillDriftInYaw, false);
set_string(TrackingFirmwareVersion, "1541800000 RUNNER-WATCHMAN$runner-watchman@runner-watchman 2018-01-01 FPGA 512(2.56/0/0) BL 0 VRC 1541800000 Radio 1518800000");
set_string(
HardwareRevisionString,
"product 128 rev 2.5.6 lot 2000/0/0 0",
);
set_string(ConnectedWirelessDongle, "D0000BE000");
set_bool(DeviceIsWireless, true);
set_bool(DeviceIsCharging, false);
set_int32(ControllerHandSelectionPriority, -1);
set_prop(ResourceRoot("htc".into()));
set_prop(WillDriftInYaw(false));
set_prop(TrackingFirmwareVersion(
"1541800000 RUNNER-WATCHMAN$runner-watchman@runner-watchman 2018-01-01 FPGA 512(2.56/0/0) BL 0 VRC 1541800000 Radio 1518800000".into(),
));
set_prop(HardwareRevisionString(
"product 128 rev 2.5.6 lot 2000/0/0 0".into(),
));
set_prop(ConnectedWirelessDongle("D0000BE000".into()));
set_prop(DeviceIsWireless(true));
set_prop(DeviceIsCharging(false));
set_prop(ControllerHandSelectionPriority(-1));
// vr::HmdMatrix34_t l_transform = {
// {{-1.f, 0.f, 0.f, 0.f}, {0.f, 0.f, -1.f, 0.f}, {0.f, -1.f, 0.f, 0.f}}};
// vr_properties->SetProperty(this->prop_container,
@ -382,86 +345,81 @@ pub extern "C" fn set_device_openvr_props(device_id: u64) {
// &l_transform,
// sizeof(vr::HmdMatrix34_t),
// vr::k_unHmdMatrix34PropertyTag);
set_bool(FirmwareUpdateAvailable, false);
set_bool(FirmwareManualUpdate, false);
set_string(
FirmwareManualUpdateURL,
"https://developer.valvesoftware.com/wiki/SteamVR/HowTo_Update_Firmware",
);
set_uint64(HardwareRevisionUint64, 2214720000);
set_uint64(FirmwareVersion, 1541800000);
set_uint64(FPGAVersion, 512);
set_uint64(VRCVersion, 1514800000);
set_uint64(RadioVersion, 1518800000);
set_uint64(DongleVersion, 8933539758);
set_bool(DeviceCanPowerOff, true);
set_prop(FirmwareUpdateAvailable(false));
set_prop(FirmwareManualUpdate(false));
set_prop(FirmwareManualUpdateURL(
"https://developer.valvesoftware.com/wiki/SteamVR/HowTo_Update_Firmware"
.into(),
));
set_prop(HardwareRevisionUint64(2214720000));
set_prop(FirmwareVersion(1541800000));
set_prop(FPGAVersion(512));
set_prop(VRCVersion(1514800000));
set_prop(RadioVersion(1518800000));
set_prop(DongleVersion(8933539758));
set_prop(DeviceCanPowerOff(true));
// vr_properties->SetStringProperty(this->prop_container,
// vr::Prop_Firmware_ProgrammingTarget_String,
// GetSerialNumber().c_str());
set_bool(FirmwareForceUpdateRequired, false);
set_bool(FirmwareRemindUpdate, false);
set_bool(HasDisplayComponent, false);
set_bool(HasCameraComponent, false);
set_bool(HasDriverDirectModeComponent, false);
set_bool(HasVirtualDisplayComponent, false);
set_prop(FirmwareForceUpdateRequired(false));
set_prop(FirmwareRemindUpdate(false));
set_prop(HasDisplayComponent(false));
set_prop(HasCameraComponent(false));
set_prop(HasDriverDirectModeComponent(false));
set_prop(HasVirtualDisplayComponent(false));
// icons
set_string(NamedIconPathDeviceOff, "{htc}/icons/tracker_status_off.png");
set_string(
NamedIconPathDeviceSearching,
"{htc}/icons/tracker_status_searching.gif",
);
set_string(
NamedIconPathDeviceSearchingAlert,
"{htc}/icons/tracker_status_searching_alert.gif",
);
set_string(
NamedIconPathDeviceReady,
"{htc}/icons/tracker_status_ready.png",
);
set_string(
NamedIconPathDeviceReadyAlert,
"{htc}/icons/tracker_status_ready_alert.png",
);
set_string(
NamedIconPathDeviceNotReady,
"{htc}/icons/tracker_status_error.png",
);
set_string(
NamedIconPathDeviceStandby,
"{htc}/icons/tracker_status_standby.png",
);
set_string(
NamedIconPathDeviceAlertLow,
"{htc}/icons/tracker_status_ready_low.png",
);
set_prop(NamedIconPathDeviceOff(
"{htc}/icons/tracker_status_off.png".into(),
));
set_prop(NamedIconPathDeviceSearching(
"{htc}/icons/tracker_status_searching.gif".into(),
));
set_prop(NamedIconPathDeviceSearchingAlert(
"{htc}/icons/tracker_status_searching_alert.gif".into(),
));
set_prop(NamedIconPathDeviceReady(
"{htc}/icons/tracker_status_ready.png".into(),
));
set_prop(NamedIconPathDeviceReadyAlert(
"{htc}/icons/tracker_status_ready_alert.png".into(),
));
set_prop(NamedIconPathDeviceNotReady(
"{htc}/icons/tracker_status_error.png".into(),
));
set_prop(NamedIconPathDeviceStandby(
"{htc}/icons/tracker_status_standby.png".into(),
));
set_prop(NamedIconPathDeviceAlertLow(
"{htc}/icons/tracker_status_ready_low.png".into(),
));
}
}
set_string(SerialNumber, &serial_number(device_id));
set_string(AttachedDeviceId, &serial_number(device_id));
set_prop(SerialNumber(serial_number(device_id)));
set_prop(AttachedDeviceId(serial_number(device_id)));
set_uint64(SupportedButtons, 0xFFFFFFFFFFFFFFFF);
set_prop(SupportedButtons(0xFFFFFFFFFFFFFFFF));
// OpenXR does not support controller battery
set_bool(DeviceProvidesBatteryStatus, false);
set_prop(DeviceProvidesBatteryStatus(false));
// k_eControllerAxis_Joystick = 2
set_prop(Axis0Type, OpenvrPropValue::Int32(2));
set_prop(Axis0Type(2));
if matches!(config.emulation_mode, ControllersEmulationMode::ViveTracker) {
// TrackedControllerRole_Invalid
set_int32(ControllerRoleHint, 0);
set_prop(ControllerRoleHint(0));
} else if device_id == *LEFT_HAND_ID {
// TrackedControllerRole_LeftHand
set_int32(ControllerRoleHint, 1);
set_prop(ControllerRoleHint(1));
} else if device_id == *RIGHT_HAND_ID {
// TrackedControllerRole_RightHand
set_int32(ControllerRoleHint, 2);
set_prop(ControllerRoleHint(2));
}
for prop in &config.extra_openvr_props {
set_prop(prop.key, prop.value.clone());
set_prop(prop.clone());
}
}
}

View File

@ -6,36 +6,125 @@ fn main() {
fs::read_to_string("../server/cpp/openvr/headers/openvr_driver.h").unwrap();
let property_finder = Regex::new(
r"\tProp_([A-Za-z\d_]+)_(?:Bool|Int32|Uint64|Float|String|Vector3)[\t ]+= ([0-9]+)",
r"\tProp_([A-Za-z\d_]+)_(Bool|Int32|Uint64|Float|String|Vector3)[\t ]+= ([0-9]+)",
)
.unwrap();
let mut mappings_fn_string: String = String::from(
r"#[repr(u32)]
#[derive(SettingsSchema, Serialize, Deserialize, Clone, Copy, Debug)]
pub enum OpenvrPropertyKey {",
);
for entry in property_finder.captures_iter(&openvr_driver_header_string) {
// exclude repeated property
if &entry[1] != "HardwareRevision" {
write!(
mappings_fn_string,
r"
{} = {},",
&entry[1].replace('_', ""),
&entry[2]
)
.unwrap();
}
struct PropInfo {
name: String,
ty: String,
code: String,
}
let prop_info = property_finder
.captures_iter(&openvr_driver_header_string)
.map(|cap| {
let code = cap[3].into();
let mut name = cap[1].replace('_', "");
if code == "1007" {
name = "HardwareRevisionString".into();
} else if code == "1017" {
name = "HardwareRevisionUint64".into();
}
PropInfo {
name,
ty: cap[2].into(),
code,
}
})
.collect::<Vec<_>>();
let mut mappings_fn_string: String = String::from(
r"#[repr(u32)]
#[derive(SettingsSchema, Serialize, Deserialize, Clone, Debug)]
pub enum OpenvrProperty {",
);
for info in &prop_info {
let ty = match info.ty.as_str() {
"Bool" => "bool",
"Int32" => "i32",
"Uint64" => "u64",
"Float" => "f32",
"String" => "String",
"Vector3" => "[f32; 3]",
_ => "()",
};
write!(
mappings_fn_string,
r"
{}({}) = {},",
&info.name, ty, &info.code
)
.unwrap();
}
// Fix duplicated property
mappings_fn_string.push_str(
r"
HardwareRevisionString = 1007,
HardwareRevisionUint64 = 1017,
}",
}
#[derive(Clone, Debug)]
pub enum OpenvrPropValue {
Bool(bool),
Float(f32),
Int32(i32),
Uint64(u64),
Vector3([f32; 3]),
Double(f64),
String(String),
}
impl OpenvrProperty {
pub fn into_key_value(self) -> (u32, OpenvrPropValue) {
match self {",
);
for info in &prop_info {
write!(
mappings_fn_string,
r"
OpenvrProperty::{}(value) => ({}, OpenvrPropValue::{}(value)),",
&info.name, info.code, info.ty,
)
.unwrap();
}
mappings_fn_string.push_str(
r"
}
}
}
static OPENVR_PROPS_DEFAULT: alvr_common::once_cell::sync::Lazy<OpenvrPropertyDefault> =
alvr_common::once_cell::sync::Lazy::new(|| OpenvrPropertyDefault {",
);
for info in &prop_info {
let default = match info.ty.as_str() {
"Bool" => "false",
"Int32" => "0",
"Uint64" => "0",
"Float" => "0.0",
"String" => "String::new()",
"Vector3" => "[0.0, 0.0, 0.0]",
_ => "()",
};
write!(
mappings_fn_string,
r"
{}: {},",
&info.name, default
)
.unwrap();
}
mappings_fn_string.push_str(
r"
variant: OpenvrPropertyDefaultVariant::TrackingSystemName,
});
",
);
fs::write(

View File

@ -546,23 +546,6 @@ pub struct AudioConfig {
pub microphone: Switch<MicrophoneConfig>,
}
#[derive(SettingsSchema, Serialize, Deserialize, Clone, Debug)]
pub enum OpenvrPropValue {
Bool(bool),
Float(f32),
Int32(i32),
Uint64(u64),
Vector3([f32; 3]),
Double(f64),
String(String),
}
#[derive(SettingsSchema, Serialize, Deserialize, Clone, Debug)]
pub struct OpenvrPropEntry {
pub key: OpenvrPropertyKey,
pub value: OpenvrPropValue,
}
#[derive(SettingsSchema, Serialize, Deserialize, Clone)]
pub enum HeadsetEmulationMode {
#[schema(strings(display_name = "Rift S"))]
@ -572,7 +555,7 @@ pub enum HeadsetEmulationMode {
Quest2,
Custom {
serial_number: String,
props: Vec<OpenvrPropEntry>,
props: Vec<OpenvrProperty>,
},
}
@ -650,7 +633,7 @@ pub struct ControllersConfig {
pub emulation_mode: ControllersEmulationMode,
#[schema(flag = "steamvr-restart")]
pub extra_openvr_props: Vec<OpenvrPropEntry>,
pub extra_openvr_props: Vec<OpenvrProperty>,
pub button_mapping_config: AutomaticButtonMappingConfig,
@ -718,7 +701,7 @@ pub struct HeadsetConfig {
pub emulation_mode: HeadsetEmulationMode,
#[schema(flag = "steamvr-restart")]
pub extra_openvr_props: Vec<OpenvrPropEntry>,
pub extra_openvr_props: Vec<OpenvrProperty>,
#[schema(flag = "steamvr-restart")]
pub tracking_ref_only: bool,
@ -939,22 +922,7 @@ pub fn session_settings_default() -> SettingsDefault {
variant: CustomAudioDeviceConfigDefaultVariant::NameSubstring,
};
let default_custom_openvr_props = VectorDefault {
element: OpenvrPropEntryDefault {
gui_collapsed: false,
key: OpenvrPropertyKeyDefault {
variant: OpenvrPropertyKeyDefaultVariant::TrackingSystemName,
},
value: OpenvrPropValueDefault {
Bool: false,
Float: 0.0,
Int32: 0,
Uint64: 0,
Vector3: [0.0, 0.0, 0.0],
Double: 0.0,
String: "".into(),
variant: OpenvrPropValueDefaultVariant::String,
},
},
element: OPENVR_PROPS_DEFAULT.clone(),
content: vec![],
};
let socket_buffer = SocketBufferSizeDefault {