Skip to content

Commit

Permalink
review response :)
Browse files Browse the repository at this point in the history
  • Loading branch information
barnabwhy committed Sep 10, 2023
1 parent 4c68fed commit 1edab0c
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 25 deletions.
45 changes: 28 additions & 17 deletions alvr/server/src/connection.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
bitrate::BitrateManager,
face_tracking::FaceTrackingSink,
hand_gestures::{trigger_hand_gesture_actions, HandGestureManager},
hand_gestures::{trigger_hand_gesture_actions, HandGestureManager, HAND_GESTURE_PROFILE_INFO},
haptics,
input_mapping::ButtonMappingManager,
sockets::WelcomeSocket,
Expand Down Expand Up @@ -38,7 +38,7 @@ use std::{
io::Write,
net::IpAddr,
process::Command,
ptr::{self},
ptr,
sync::{
atomic::{AtomicBool, Ordering},
mpsc::{self, RecvTimeoutError, SyncSender, TrySendError},
Expand Down Expand Up @@ -643,8 +643,18 @@ fn try_connect(mut client_ips: HashMap<IpAddr, String>) -> ConResult {
thread::spawn(|| ())
};

let tracking_manager = Arc::new(Mutex::new(TrackingManager::new()));
let hand_gesture_manager = Arc::new(Mutex::new(HandGestureManager::new()));
let tracking_manager: Arc<
alvr_common::parking_lot::lock_api::Mutex<
alvr_common::parking_lot::RawMutex,
TrackingManager,
>,
> = Arc::new(Mutex::new(TrackingManager::new()));
let hand_gesture_manager: Arc<
alvr_common::parking_lot::lock_api::Mutex<
alvr_common::parking_lot::RawMutex,
HandGestureManager,
>,
> = Arc::new(Mutex::new(HandGestureManager::new()));

let tracking_receive_thread = thread::spawn({
let tracking_manager = Arc::clone(&tracking_manager);
Expand All @@ -655,10 +665,7 @@ fn try_connect(mut client_ips: HashMap<IpAddr, String>) -> ConResult {
{
if let Switch::Enabled(_) = &config.hand_tracking.use_gestures {
Some(ButtonMappingManager::new_automatic(
&CONTROLLER_PROFILE_INFO
.get(&alvr_common::hash_string(QUEST_CONTROLLER_PROFILE_PATH))
.unwrap()
.button_set,
&HAND_GESTURE_PROFILE_INFO.button_set,
&config.button_mapping_config,
))
} else {
Expand Down Expand Up @@ -693,15 +700,15 @@ fn try_connect(mut client_ips: HashMap<IpAddr, String>) -> ConResult {
return;
};

let data_manager_lock = SERVER_DATA_MANAGER.read();
let config = &data_manager_lock.settings().headset;

let mut tracking_manager_lock = tracking_manager.lock();

let motions;
let left_hand_skeleton;
let right_hand_skeleton;
{
let data_manager_lock = SERVER_DATA_MANAGER.read();
let config = &data_manager_lock.settings().headset;

motions = tracking_manager_lock.transform_motions(
config,
&tracking.device_motions,
Expand All @@ -726,6 +733,7 @@ fn try_connect(mut client_ips: HashMap<IpAddr, String>) -> ConResult {
.unwrap_or_default();

{
let data_manager_lock = SERVER_DATA_MANAGER.read();
if data_manager_lock.settings().logging.log_tracking {
alvr_events::send_event(EventType::Tracking(Box::new(TrackingEvent {
head_motion: motions
Expand Down Expand Up @@ -799,15 +807,18 @@ fn try_connect(mut client_ips: HashMap<IpAddr, String>) -> ConResult {
),
);
}

drop(hand_gesture_manager_lock);
}
}

let mut hand_skeletons_enabled = false;
if let Switch::Enabled(controllers) = &config.controllers {
hand_skeletons_enabled = controllers.hand_tracking.enable_skeleton;
}
let data_manager_lock = SERVER_DATA_MANAGER.read();
let config = &data_manager_lock.settings().headset;

let hand_skeletons_enabled =
if let Switch::Enabled(controllers) = &config.controllers {
controllers.hand_tracking.enable_skeleton
} else {
false
};

unsafe {
crate::SetTracking(
Expand Down
41 changes: 33 additions & 8 deletions alvr/server/src/hand_gestures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,7 @@ use std::{
};

use alvr_common::{
glam::{Vec2, Vec3},
Pose, LEFT_HAND_ID, LEFT_MENU_CLICK_ID, LEFT_SQUEEZE_CLICK_ID, LEFT_SQUEEZE_VALUE_ID,
LEFT_THUMBSTICK_CLICK_ID, LEFT_THUMBSTICK_TOUCH_ID, LEFT_THUMBSTICK_X_ID, LEFT_THUMBSTICK_Y_ID,
LEFT_TRIGGER_CLICK_ID, LEFT_TRIGGER_TOUCH_ID, LEFT_TRIGGER_VALUE_ID, LEFT_X_CLICK_ID,
LEFT_X_TOUCH_ID, LEFT_Y_CLICK_ID, LEFT_Y_TOUCH_ID, RIGHT_A_CLICK_ID, RIGHT_A_TOUCH_ID,
RIGHT_B_CLICK_ID, RIGHT_B_TOUCH_ID, RIGHT_SQUEEZE_CLICK_ID, RIGHT_SQUEEZE_VALUE_ID,
RIGHT_THUMBSTICK_CLICK_ID, RIGHT_THUMBSTICK_TOUCH_ID, RIGHT_THUMBSTICK_X_ID,
RIGHT_THUMBSTICK_Y_ID, RIGHT_TRIGGER_CLICK_ID, RIGHT_TRIGGER_TOUCH_ID, RIGHT_TRIGGER_VALUE_ID,
glam::{Vec2, Vec3}, *, once_cell::sync::Lazy,
};

use alvr_packets::ButtonValue;
Expand All @@ -27,6 +20,38 @@ fn lerp_pose(a: Pose, b: Pose, fac: f32) -> Pose {
}
}

pub static HAND_GESTURE_PROFILE_INFO: Lazy<InteractionProfileInfo> = Lazy::new(|| InteractionProfileInfo {
path: QUEST_CONTROLLER_PROFILE_PATH,
button_set: [
*LEFT_X_CLICK_ID,
*LEFT_X_TOUCH_ID,
*LEFT_Y_CLICK_ID,
*LEFT_Y_TOUCH_ID,
*LEFT_MENU_CLICK_ID,
*LEFT_SQUEEZE_VALUE_ID,
*LEFT_TRIGGER_VALUE_ID,
*LEFT_TRIGGER_TOUCH_ID,
*LEFT_THUMBSTICK_X_ID,
*LEFT_THUMBSTICK_Y_ID,
*LEFT_THUMBSTICK_CLICK_ID,
*LEFT_THUMBSTICK_TOUCH_ID,
*RIGHT_A_CLICK_ID,
*RIGHT_A_TOUCH_ID,
*RIGHT_B_CLICK_ID,
*RIGHT_B_TOUCH_ID,
*RIGHT_SQUEEZE_VALUE_ID,
*RIGHT_TRIGGER_VALUE_ID,
*RIGHT_TRIGGER_TOUCH_ID,
*RIGHT_THUMBSTICK_X_ID,
*RIGHT_THUMBSTICK_Y_ID,
*RIGHT_THUMBSTICK_CLICK_ID,
*RIGHT_THUMBSTICK_TOUCH_ID,
]
.into_iter()
.collect(),
}
);

#[derive(Debug, Clone)]
pub struct HandGesture {
pub id: HandGestureId,
Expand Down

0 comments on commit 1edab0c

Please sign in to comment.