Skip to content

Commit

Permalink
Added firmware calibration back in (#231)
Browse files Browse the repository at this point in the history
  • Loading branch information
MasterOfShred committed Jun 25, 2023
1 parent 0511577 commit 6b131d6
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 22 deletions.
53 changes: 31 additions & 22 deletions driver/src/device/drivers/knuckle_device_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
#include "knuckle_device_driver.h"

#include "device/pose/device_pose.h"
#include "services/driver_external.h"
#include "hand_tracking/hand_tracking.h"
#include "nlohmann/json.hpp"
#include "services/driver_external.h"
#include "util/file_path.h"

static DriverExternalServer &external_server = DriverExternalServer::GetInstance();
Expand All @@ -26,36 +26,45 @@ class KnuckleDeviceDriver::Impl {

device_->ListenForInput([&](og::InputPeripheralData data) {
// clang-format off
hand_tracking_->ComputeBoneTransforms(skeleton_, data, IsRightHand() ? vr::TrackedControllerRole_RightHand : vr::TrackedControllerRole_LeftHand);
vr::VRDriverInput()->UpdateSkeletonComponent(input_components_[kKnuckleDeviceComponentIndex_Skeleton], vr::VRSkeletalMotionRange_WithController, skeleton_, 31);
vr::VRDriverInput()->UpdateSkeletonComponent(input_components_[kKnuckleDeviceComponentIndex_Skeleton], vr::VRSkeletalMotionRange_WithoutController, skeleton_, 31);
hand_tracking_->ComputeBoneTransforms(skeleton_, data, IsRightHand() ? vr::TrackedControllerRole_RightHand : vr::TrackedControllerRole_LeftHand);
vr::VRDriverInput()->UpdateSkeletonComponent(input_components_[kKnuckleDeviceComponentIndex_Skeleton], vr::VRSkeletalMotionRange_WithController, skeleton_, 31);
vr::VRDriverInput()->UpdateSkeletonComponent(input_components_[kKnuckleDeviceComponentIndex_Skeleton], vr::VRSkeletalMotionRange_WithoutController, skeleton_, 31);

vr::VRDriverInput()->UpdateScalarComponent(input_components_[kKnuckleDeviceComponentIndex_ThumbstickX], data.joystick.x, 0);
vr::VRDriverInput()->UpdateScalarComponent(input_components_[kKnuckleDeviceComponentIndex_ThumbstickY], data.joystick.y, 0);
vr::VRDriverInput()->UpdateScalarComponent(input_components_[kKnuckleDeviceComponentIndex_ThumbstickX], data.joystick.x, 0);
vr::VRDriverInput()->UpdateScalarComponent(input_components_[kKnuckleDeviceComponentIndex_ThumbstickY], data.joystick.y, 0);

vr::VRDriverInput()->UpdateBooleanComponent(input_components_[kKnuckleDeviceComponentIndex_ThumbstickClick], data.joystick.pressed, 0);
vr::VRDriverInput()->UpdateBooleanComponent(input_components_[kKnuckleDeviceComponentIndex_ThumbstickTouch], data.joystick.pressed, 0);
vr::VRDriverInput()->UpdateBooleanComponent(input_components_[kKnuckleDeviceComponentIndex_ThumbstickClick], data.joystick.pressed, 0);
vr::VRDriverInput()->UpdateBooleanComponent(input_components_[kKnuckleDeviceComponentIndex_ThumbstickTouch], data.joystick.pressed, 0);

vr::VRDriverInput()->UpdateBooleanComponent(input_components_[kKnuckleDeviceComponentIndex_TriggerClick], data.trigger.pressed, 0);
vr::VRDriverInput()->UpdateScalarComponent(input_components_[kKnuckleDeviceComponentIndex_TriggerValue], data.trigger.value, 0);
vr::VRDriverInput()->UpdateBooleanComponent(input_components_[kKnuckleDeviceComponentIndex_TriggerClick], data.trigger.pressed, 0);
vr::VRDriverInput()->UpdateScalarComponent(input_components_[kKnuckleDeviceComponentIndex_TriggerValue], data.trigger.value, 0);

vr::VRDriverInput()->UpdateBooleanComponent(input_components_[kKnuckleDeviceComponentIndex_AClick], data.A.pressed, 0);
vr::VRDriverInput()->UpdateBooleanComponent(input_components_[kKnuckleDeviceComponentIndex_ATouch], data.A.value > 0.f, 0);
vr::VRDriverInput()->UpdateBooleanComponent(input_components_[kKnuckleDeviceComponentIndex_AClick], data.A.pressed, 0);
vr::VRDriverInput()->UpdateBooleanComponent(input_components_[kKnuckleDeviceComponentIndex_ATouch], data.A.value > 0.f, 0);

vr::VRDriverInput()->UpdateBooleanComponent(input_components_[kKnuckleDeviceComponentIndex_BClick], data.B.pressed, 0);
vr::VRDriverInput()->UpdateBooleanComponent(input_components_[kKnuckleDeviceComponentIndex_BTouch], data.B.value > 0.f, 0);
vr::VRDriverInput()->UpdateBooleanComponent(input_components_[kKnuckleDeviceComponentIndex_BClick], data.B.pressed, 0);
vr::VRDriverInput()->UpdateBooleanComponent(input_components_[kKnuckleDeviceComponentIndex_BTouch], data.B.value > 0.f, 0);

vr::VRDriverInput()->UpdateBooleanComponent(input_components_[kKnuckleDeviceComponentIndex_GripTouch], data.grab.activated, 0);
vr::VRDriverInput()->UpdateScalarComponent(input_components_[kKnuckleDeviceComponentIndex_GripForce], data.grab.activated, 0);
vr::VRDriverInput()->UpdateScalarComponent(input_components_[kKnuckleDeviceComponentIndex_GripValue], data.grab.activated, 0);
vr::VRDriverInput()->UpdateBooleanComponent(input_components_[kKnuckleDeviceComponentIndex_GripTouch], data.grab.activated, 0);
vr::VRDriverInput()->UpdateScalarComponent(input_components_[kKnuckleDeviceComponentIndex_GripForce], data.grab.activated, 0);
vr::VRDriverInput()->UpdateScalarComponent(input_components_[kKnuckleDeviceComponentIndex_GripValue], data.grab.activated, 0);

vr::VRDriverInput()->UpdateBooleanComponent(input_components_[kKnuckleDeviceComponentIndex_SystemClick], data.menu.pressed, 0);
vr::VRDriverInput()->UpdateBooleanComponent(input_components_[kKnuckleDeviceComponentIndex_SystemClick], data.menu.pressed, 0);

vr::VRDriverInput()->UpdateScalarComponent(input_components_[kKnuckleDeviceComponentIndex_FingerIndex], hand_tracking_->GetAverageFingerCurlValue(data.flexion[1]), 0);
vr::VRDriverInput()->UpdateScalarComponent(input_components_[kKnuckleDeviceComponentIndex_FingerMiddle], hand_tracking_->GetAverageFingerCurlValue(data.flexion[2]), 0);
vr::VRDriverInput()->UpdateScalarComponent(input_components_[kKnuckleDeviceComponentIndex_FingerRing], hand_tracking_->GetAverageFingerCurlValue(data.flexion[3]), 0);
vr::VRDriverInput()->UpdateScalarComponent(input_components_[kKnuckleDeviceComponentIndex_FingerPinky], hand_tracking_->GetAverageFingerCurlValue(data.flexion[4]), 0);
vr::VRDriverInput()->UpdateScalarComponent(input_components_[kKnuckleDeviceComponentIndex_FingerIndex], hand_tracking_->GetAverageFingerCurlValue(data.flexion[1]), 0);
vr::VRDriverInput()->UpdateScalarComponent(input_components_[kKnuckleDeviceComponentIndex_FingerMiddle], hand_tracking_->GetAverageFingerCurlValue(data.flexion[2]), 0);
vr::VRDriverInput()->UpdateScalarComponent(input_components_[kKnuckleDeviceComponentIndex_FingerRing], hand_tracking_->GetAverageFingerCurlValue(data.flexion[3]), 0);
vr::VRDriverInput()->UpdateScalarComponent(input_components_[kKnuckleDeviceComponentIndex_FingerPinky], hand_tracking_->GetAverageFingerCurlValue(data.flexion[4]), 0);
// clang-format on

if (data.calibrate.pressed) {
if (!pose_->IsCalibrating()) {
pose_->StartCalibration(kCalibrationMethod_Hardware);
}
}
else if (pose_->IsCalibrating()) {
pose_->CompleteCalibration(kCalibrationMethod_Hardware);
}
});

external_server.RegisterFunctionCallback("force_feedback/" + std::string(IsRightHand() ? "right" : "left"), [&](const std::string &data) {
Expand Down
4 changes: 4 additions & 0 deletions driver/src/device/pose/device_pose.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ void DevicePose::CancelCalibration(CalibrationMethod method) const {
calibration_->CancelCalibration(method);
}

bool DevicePose::IsCalibrating() const {
return calibration_->IsCalibrating();
}

void DevicePose::CompleteCalibration(CalibrationMethod method) {
if (controller_id_ < 0) {
DriverLog("Completed calibration but controller index was invalid");
Expand Down

0 comments on commit 6b131d6

Please sign in to comment.