@@ -32,6 +32,8 @@ SlimeVRDriver::VRDriver::Init(vr::IVRDriverContext *pDriverContext) {
3232
3333 logger_->Log (" SlimeVR Driver Loaded Successfully" );
3434
35+ LoadDriverConfig ();
36+
3537 bridge_ = std::make_shared<BridgeClient>(
3638 std::static_pointer_cast<Logger>(std::make_shared<VRLogger>(" Bridge" )),
3739 std::bind (&SlimeVRDriver::VRDriver::OnBridgeMessage, this ,
@@ -478,6 +480,32 @@ bool SlimeVRDriver::VRDriver::AddDevice(std::shared_ptr<IVRDevice> device) {
478480 return true ;
479481}
480482
483+ void SlimeVRDriver::VRDriver::LoadDriverConfig () {
484+ vr::IVRResources *res = vr::VRResources ();
485+ if (!res) return ;
486+ char path[1024 ];
487+ uint32_t len = res->GetResourceFullPath (
488+ " slimevr_driver_config.json" , " " , path, sizeof (path));
489+ if (len == 0 || len >= sizeof (path)) return ;
490+ path[len] = ' \0 ' ;
491+ try {
492+ auto json = simdjson::padded_string::load (path);
493+ simdjson::ondemand::document doc = json_parser_.iterate(json);
494+ auto obj = doc.get_object ();
495+ if (auto v = obj[" external_hand_max_radius_m" ]; !v.error ()) config_external_hand_max_radius_m_ = static_cast <float >(v.get_double ());
496+ if (auto v = obj[" stale_external_pose_frames" ]; !v.error ()) config_stale_external_pose_frames_ = static_cast <int >(v.get_int64 ());
497+ if (auto v = obj[" pose_lerp_speed" ]; !v.error ()) config_pose_lerp_speed_ = static_cast <float >(v.get_double ());
498+ if (auto v = obj[" frozen_pose_position_epsilon_m" ]; !v.error ()) config_frozen_pose_position_epsilon_m_ = static_cast <float >(v.get_double ());
499+ logger_->Log (" Loaded driver config from {}" , path);
500+ } catch (const simdjson::simdjson_error &) {
501+ // Use defaults; config file missing or invalid
502+ }
503+ }
504+
505+ float SlimeVRDriver::VRDriver::GetPoseLerpSpeed () {
506+ return config_pose_lerp_speed_;
507+ }
508+
481509SlimeVRDriver::SettingsValue
482510SlimeVRDriver::VRDriver::GetSettingsValue (std::string key) {
483511 vr::EVRSettingsError err = vr::EVRSettingsError::VRSettingsError_None;
@@ -703,9 +731,8 @@ vr::DriverPose_t SlimeVRDriver::VRDriver::DriverPoseFromTrackedDevicePose(
703731}
704732
705733bool SlimeVRDriver::VRDriver::ExternalPoseEquals (const vr::DriverPose_t &a,
706- const vr::DriverPose_t &b) {
707- // Position only; rotation ignored so small rotation jitter doesn't block frozen detection.
708- const float pos_eps = 0 .005f ; // ~5 mm
734+ const vr::DriverPose_t &b) const {
735+ float pos_eps = config_frozen_pose_position_epsilon_m_;
709736 for (int i = 0 ; i < 3 ; i++) {
710737 if (std::fabs (a.vecPosition [i] - b.vecPosition [i]) > pos_eps)
711738 return false ;
@@ -714,14 +741,15 @@ bool SlimeVRDriver::VRDriver::ExternalPoseEquals(const vr::DriverPose_t &a,
714741}
715742
716743bool SlimeVRDriver::VRDriver::ExternalHandInFrontAndInRadius (
717- const double hand_pos[3 ], const vr::TrackedDevicePose_t &hmd_pose) {
744+ const double hand_pos[3 ], const vr::TrackedDevicePose_t &hmd_pose) const {
718745 if (!hmd_pose.bPoseIsValid )
719746 return false ;
747+ double r = static_cast <double >(config_external_hand_max_radius_m_);
720748 const auto &m = hmd_pose.mDeviceToAbsoluteTracking .m ;
721749 double hx = m[0 ][3 ], hy = m[1 ][3 ], hz = m[2 ][3 ];
722750 double dx = hand_pos[0 ] - hx, dy = hand_pos[1 ] - hy, dz = hand_pos[2 ] - hz;
723751 double dist_sq = dx * dx + dy * dy + dz * dz;
724- if (dist_sq > static_cast < double >( kExternalHandMaxRadius ) * kExternalHandMaxRadius )
752+ if (dist_sq > r * r )
725753 return false ;
726754 // Forward = -Z in OpenVR (third column of rotation)
727755 double fx = -m[0 ][2 ], fy = -m[1 ][2 ], fz = -m[2 ][2 ];
@@ -788,7 +816,7 @@ void SlimeVRDriver::VRDriver::UpdateExternalControllerPoses() {
788816 if (last_external_left_pose_.has_value () &&
789817 ExternalPoseEquals (driver_pose, *last_external_left_pose_)) {
790818 stale_external_left_frames_++;
791- if (stale_external_left_frames_ >= kStaleExternalPoseFrames )
819+ if (stale_external_left_frames_ >= config_stale_external_pose_frames_ )
792820 external_left_pose_ = std::nullopt ; // swap to SlimeVR
793821 else
794822 external_left_pose_ = driver_pose;
@@ -801,7 +829,7 @@ void SlimeVRDriver::VRDriver::UpdateExternalControllerPoses() {
801829 if (last_external_right_pose_.has_value () &&
802830 ExternalPoseEquals (driver_pose, *last_external_right_pose_)) {
803831 stale_external_right_frames_++;
804- if (stale_external_right_frames_ >= kStaleExternalPoseFrames )
832+ if (stale_external_right_frames_ >= config_stale_external_pose_frames_ )
805833 external_right_pose_ = std::nullopt ; // swap to SlimeVR
806834 else
807835 external_right_pose_ = driver_pose;
0 commit comments