Skip to content
This repository has been archived by the owner on May 3, 2021. It is now read-only.

Commit

Permalink
Merge pull request #4 from cboulay/master
Browse files Browse the repository at this point in the history
merge back
  • Loading branch information
gb2111 authored Nov 6, 2016
2 parents e42ddad + 6ba9a42 commit fe5f7e0
Show file tree
Hide file tree
Showing 22 changed files with 554 additions and 108 deletions.
68 changes: 53 additions & 15 deletions src/openvr_plugin/driver_psmoveservice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1270,6 +1270,8 @@ CPSMoveControllerLatest::CPSMoveControllerLatest( vr::IServerDriverHost * pDrive
, m_pendingHapticPulseDuration(0)
, m_lastTimeRumbleSent()
, m_lastTimeRumbleSentValid(false)
, m_resetPoseButtonPressTime()
, m_bResetPoseRequestSent(false)
, m_fVirtuallExtendControllersZ(0.0f)
, m_fVirtuallExtendControllersY(0.0f)
, m_bDelayAfterTouchpadPress(false)
Expand Down Expand Up @@ -1700,32 +1702,68 @@ void CPSMoveControllerLatest::UpdateControllerState()
{
const ClientPSMoveView &clientView = m_controller_view->GetPSMoveView();

bool bStartWasPressed = (m_ControllerState.ulButtonPressed & vr::ButtonMaskFromId(psButtonIDToVRButtonID[k_EPSButtonID_Start])) > 0;
bool bSelectWasPressed = (m_ControllerState.ulButtonPressed & vr::ButtonMaskFromId(psButtonIDToVRButtonID[k_EPSButtonID_Select])) > 0;
const bool bStartRealignHMDTriggered =
(clientView.GetButtonStart() == PSMoveButton_PRESSED && clientView.GetButtonSelect() == PSMoveButton_PRESSED) ||
(clientView.GetButtonStart() == PSMoveButton_PRESSED && clientView.GetButtonSelect() == PSMoveButton_DOWN) ||
(clientView.GetButtonStart() == PSMoveButton_DOWN && clientView.GetButtonSelect() == PSMoveButton_PRESSED);

// See if the recenter button has been held for the requisite amount of time
bool bRecenterRequestTriggered = false;
{
PSMoveButtonState resetPoseButtonState = clientView.GetButtonSelect();

bool bSquareWasPressed = (m_ControllerState.ulButtonPressed & vr::ButtonMaskFromId(psButtonIDToVRButtonID[k_EPSButtonID_Square])) > 0;
bool bCrossWasPressed = (m_ControllerState.ulButtonPressed & vr::ButtonMaskFromId(psButtonIDToVRButtonID[k_EPSButtonID_Cross])) > 0;
bool bTriangleWasPressed = (m_ControllerState.ulButtonPressed & vr::ButtonMaskFromId(psButtonIDToVRButtonID[k_EPSButtonID_Triangle])) > 0;
bool bCircleWasPressed = (m_ControllerState.ulButtonPressed & vr::ButtonMaskFromId(psButtonIDToVRButtonID[k_EPSButtonID_Circle])) > 0;
switch (resetPoseButtonState)
{
case PSMoveButtonState::PSMoveButton_DOWN:
{
m_resetPoseButtonPressTime = std::chrono::high_resolution_clock::now();
} break;
case PSMoveButtonState::PSMoveButton_PRESSED:
{
if (!m_bResetPoseRequestSent)
{
const float k_hold_duration_milli = 250.f;
std::chrono::time_point<std::chrono::high_resolution_clock> now = std::chrono::high_resolution_clock::now();
std::chrono::duration<float, std::milli> pressDurationMilli = now - m_resetPoseButtonPressTime;

if (pressDurationMilli.count() >= k_hold_duration_milli)
{
bRecenterRequestTriggered = true;
}
}
} break;
case PSMoveButtonState::PSMoveButton_UP:
{
m_bResetPoseRequestSent = false;
} break;
}
}

// If start was just pressed while and select was held or vice versa,
// recenter the controller orientation pose and start the realignment of the controller to HMD tracking space.
if ((clientView.GetButtonStart() == PSMoveButton_PRESSED && clientView.GetButtonSelect() == PSMoveButton_PRESSED) ||
(clientView.GetButtonStart() == PSMoveButton_PRESSED && clientView.GetButtonSelect() == PSMoveButton_DOWN) ||
(clientView.GetButtonStart() == PSMoveButton_DOWN && clientView.GetButtonSelect() == PSMoveButton_PRESSED) )

if (bStartRealignHMDTriggered)
{
PSMoveFloatVector3 controllerBallPointedUpEuler = PSMoveFloatVector3::create((float)M_PI_2, 0.0f, 0.0f);
PSMoveQuaternion controllerBallPointedUpQuat = PSMoveQuaternion::create(controllerBallPointedUpEuler);

#if LOG_REALIGN_TO_HMD != 0
DriverLog("CPSMoveControllerLatest::UpdateControllerState(): Calling StartRealignHMDTrackingSpace() in response to controller chord.\n");
DriverLog("CPSMoveControllerLatest::UpdateControllerState(): Calling StartRealignHMDTrackingSpace() in response to controller chord.\n");
#endif

PSMoveFloatVector3 controllerBallPointedUpEuler = PSMoveFloatVector3::create((float)M_PI_2, 0.0f, 0.0f);
PSMoveQuaternion controllerBallPointedUpQuat = PSMoveQuaternion::create(controllerBallPointedUpEuler);
ClientPSMoveAPI::reset_pose(m_controller_view, controllerBallPointedUpQuat);
ClientPSMoveAPI::eat_response(ClientPSMoveAPI::reset_pose(m_controller_view, controllerBallPointedUpQuat));
m_bResetPoseRequestSent = true;

StartRealignHMDTrackingSpace();
}
else {
else if (bRecenterRequestTriggered)
{
DriverLog("CPSMoveControllerLatest::UpdateControllerState(): Calling ClientPSMoveAPI::reset_pose() in response to controller button press.\n");

ClientPSMoveAPI::eat_response(ClientPSMoveAPI::reset_pose(m_controller_view, PSMoveQuaternion::identity()));
m_bResetPoseRequestSent = true;
}
else
{
m_touchpadDirectionsUsed = false;
UpdateControllerStateFromPsMoveButtonState(k_EPSButtonID_Circle, clientView.GetButtonCircle(), &NewState);
UpdateControllerStateFromPsMoveButtonState(k_EPSButtonID_Cross, clientView.GetButtonCross(), &NewState);
Expand Down
3 changes: 3 additions & 0 deletions src/openvr_plugin/driver_psmoveservice.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,9 @@ class CPSMoveControllerLatest : public CPSMoveTrackedDeviceLatest, public vr::IV
std::chrono::time_point<std::chrono::high_resolution_clock> m_lastTouchpadPress;
bool m_touchpadDirectionsUsed;

std::chrono::time_point<std::chrono::high_resolution_clock> m_resetPoseButtonPressTime;
bool m_bResetPoseRequestSent;

// Button Remapping
vr::EVRButtonId psButtonIDToVRButtonID[k_EPSButtonID_Count];
eVRTouchpadDirection psButtonIDToVrTouchpadDirection[k_EPSButtonID_Count];
Expand Down
24 changes: 18 additions & 6 deletions src/psmoveconfigtool/AppStage_ControllerSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,9 @@ void AppStage_ControllerSettings::renderUI()
{
case ClientControllerView::eControllerType::PSMove:
{
ImGui::BulletText("Controller Type: PSMove");
//###HipsterSloth $TODO - The HID report for fetching the firmware revision doesn't appear to work
//ImGui::BulletText("Controller Type: PSMove (v%d.%d)", controllerInfo.FirmwareVersion, controllerInfo.FirmwareRevision);
ImGui::BulletText("Controller Type: PSMove");
} break;
case ClientControllerView::eControllerType::PSNavi:
{
Expand All @@ -226,11 +228,18 @@ void AppStage_ControllerSettings::renderUI()

if (controllerInfo.ControllerType == ClientControllerView::eControllerType::PSMove)
{
if (ImGui::Button("Calibrate Magnetometer"))
{
m_app->getAppStage<AppStage_MagnetometerCalibration>()->setBypassCalibrationFlag(false);
m_app->setAppStage(AppStage_MagnetometerCalibration::APP_STAGE_NAME);
}
if (controllerInfo.HasMagnetometer)
{
if (ImGui::Button("Calibrate Magnetometer"))
{
m_app->getAppStage<AppStage_MagnetometerCalibration>()->setBypassCalibrationFlag(false);
m_app->setAppStage(AppStage_MagnetometerCalibration::APP_STAGE_NAME);
}
}
else
{
ImGui::TextDisabled("Magnetometer Disabled");
}

if (ImGui::Button("Calibrate Gyroscope"))
{
Expand Down Expand Up @@ -452,6 +461,9 @@ void AppStage_ControllerSettings::handle_controller_list_response(
ControllerInfo.PairedToHost=
ControllerResponse.assigned_host_serial().length() > 0 &&
ControllerResponse.assigned_host_serial() == thisPtr->m_hostSerial;
ControllerInfo.FirmwareVersion = ControllerResponse.firmware_version();
ControllerInfo.FirmwareRevision = ControllerResponse.firmware_revision();
ControllerInfo.HasMagnetometer = ControllerResponse.has_magnetometer();

// Add the controller to the appropriate connection list
switch (ControllerResponse.connection_type())
Expand Down
3 changes: 3 additions & 0 deletions src/psmoveconfigtool/AppStage_ControllerSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@ class AppStage_ControllerSettings : public AppStage
struct ControllerInfo
{
int ControllerID;
int FirmwareVersion;
int FirmwareRevision;
ClientControllerView::eControllerType ControllerType;
PSMoveTrackingColorType TrackingColorType;
std::string DevicePath;
std::string DeviceSerial;
std::string AssignedHostSerial;
bool PairedToHost;
bool HasMagnetometer;
};

AppStage_ControllerSettings(class App *app);
Expand Down
42 changes: 41 additions & 1 deletion src/psmoveconfigtool/AppStage_GyroscopeCalibration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ AppStage_GyroscopeCalibration::AppStage_GyroscopeCalibration(App *app)
, m_isControllerStreamActive(false)
, m_lastControllerSeqNum(-1)
, m_lastRawGyroscope()
, m_resetPoseButtonPressTime()
, m_bResetPoseRequestSent(false)
, m_errorSamples(new GyroscopeErrorSamples)
, m_scaleSamples(new GyroscopeScaleSamples)
{
Expand Down Expand Up @@ -440,6 +442,37 @@ void AppStage_GyroscopeCalibration::update()
case eCalibrationMenuState::measureComplete:
case eCalibrationMenuState::test:
{
if (m_controllerView->GetControllerViewType() == ClientControllerView::PSMove)
{
PSMoveButtonState resetPoseButtonState= m_controllerView->GetPSMoveView().GetButtonSelect();

switch (resetPoseButtonState)
{
case PSMoveButtonState::PSMoveButton_DOWN:
{
m_resetPoseButtonPressTime= std::chrono::high_resolution_clock::now();
} break;
case PSMoveButtonState::PSMoveButton_PRESSED:
{
if (!m_bResetPoseRequestSent)
{
const float k_hold_duration_milli = 250.f;
std::chrono::time_point<std::chrono::high_resolution_clock> now = std::chrono::high_resolution_clock::now();
std::chrono::duration<float, std::milli> pressDurationMilli = now - m_resetPoseButtonPressTime;

if (pressDurationMilli.count() >= k_hold_duration_milli)
{
ClientPSMoveAPI::eat_response(ClientPSMoveAPI::reset_pose(m_controllerView, PSMoveQuaternion::identity()));
m_bResetPoseRequestSent = true;
}
}
} break;
case PSMoveButtonState::PSMoveButton_UP:
{
m_bResetPoseRequestSent = false;
} break;
}
}
} break;
default:
assert(0 && "unreachable");
Expand Down Expand Up @@ -686,7 +719,7 @@ void AppStage_GyroscopeCalibration::renderUI()
case eCalibrationMenuState::test:
{
ImGui::SetNextWindowPos(ImVec2(ImGui::GetIO().DisplaySize.x / 2.f - k_panel_width / 2.f, 20.f));
ImGui::SetNextWindowSize(ImVec2(k_panel_width, 80));
ImGui::SetNextWindowSize(ImVec2(k_panel_width, 120));
ImGui::Begin(k_window_title, nullptr, window_flags);

if (m_bBypassCalibration)
Expand All @@ -698,6 +731,13 @@ void AppStage_GyroscopeCalibration::renderUI()
ImGui::Text("Calibration of Controller ID #%d complete!", m_controllerView->GetControllerID());
}

if (m_controllerView->GetControllerViewType() == ClientControllerView::PSMove)
{
ImGui::TextWrapped(
"[Hold the Select button with controller pointed forward\n" \
"to recenter the controller]");
}

if (ImGui::Button("Ok"))
{
request_exit_to_app_stage(AppStage_ControllerSettings::APP_STAGE_NAME);
Expand Down
3 changes: 3 additions & 0 deletions src/psmoveconfigtool/AppStage_GyroscopeCalibration.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ class AppStage_GyroscopeCalibration : public AppStage
std::chrono::time_point<std::chrono::high_resolution_clock> m_stableStartTime;
bool m_bIsStable;

std::chrono::time_point<std::chrono::high_resolution_clock> m_resetPoseButtonPressTime;
bool m_bResetPoseRequestSent;

struct GyroscopeErrorSamples *m_errorSamples;
struct GyroscopeScaleSamples *m_scaleSamples;
};
Expand Down
39 changes: 38 additions & 1 deletion src/psmoveconfigtool/AppStage_MagnetometerCalibration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ AppStage_MagnetometerCalibration::AppStage_MagnetometerCalibration(App *app)
, m_led_color_b(0)
, m_stableStartTime()
, m_bIsStable(false)
, m_resetPoseButtonPressTime()
, m_bResetPoseRequestSent(false)
, m_identityPoseMVectorSum()
, m_identityPoseSampleCount(0)
{
Expand Down Expand Up @@ -352,6 +354,37 @@ void AppStage_MagnetometerCalibration::update()
} break;
case eCalibrationMenuState::complete:
{
if (m_controllerView->GetControllerViewType() == ClientControllerView::PSMove)
{
PSMoveButtonState resetPoseButtonState = m_controllerView->GetPSMoveView().GetButtonSelect();

switch (resetPoseButtonState)
{
case PSMoveButtonState::PSMoveButton_DOWN:
{
m_resetPoseButtonPressTime = std::chrono::high_resolution_clock::now();
} break;
case PSMoveButtonState::PSMoveButton_PRESSED:
{
if (!m_bResetPoseRequestSent)
{
const float k_hold_duration_milli = 250.f;
std::chrono::time_point<std::chrono::high_resolution_clock> now = std::chrono::high_resolution_clock::now();
std::chrono::duration<float, std::milli> pressDurationMilli = now - m_resetPoseButtonPressTime;

if (pressDurationMilli.count() >= k_hold_duration_milli)
{
ClientPSMoveAPI::eat_response(ClientPSMoveAPI::reset_pose(m_controllerView, PSMoveQuaternion::identity()));
m_bResetPoseRequestSent = true;
}
}
} break;
case PSMoveButtonState::PSMoveButton_UP:
{
m_bResetPoseRequestSent = false;
} break;
}
}
} break;
case eCalibrationMenuState::pendingExit:
{
Expand Down Expand Up @@ -739,7 +772,7 @@ void AppStage_MagnetometerCalibration::renderUI()
case eCalibrationMenuState::complete:
{
ImGui::SetNextWindowPos(ImVec2(ImGui::GetIO().DisplaySize.x / 2.f - k_panel_width / 2.f, 20.f));
ImGui::SetNextWindowSize(ImVec2(k_panel_width, 80));
ImGui::SetNextWindowSize(ImVec2(k_panel_width, 120));
ImGui::Begin(k_window_title, nullptr, window_flags);

if (m_bBypassCalibration)
Expand All @@ -751,6 +784,10 @@ void AppStage_MagnetometerCalibration::renderUI()
ImGui::Text("Calibration of Controller ID #%d complete!", m_controllerView->GetControllerID());
}

ImGui::TextWrapped(
"[Hold the Select button with controller pointed forward\n" \
"to recenter the controller]");

if (ImGui::Button("Ok"))
{
request_exit_to_app_stage(AppStage_ControllerSettings::APP_STAGE_NAME);
Expand Down
3 changes: 3 additions & 0 deletions src/psmoveconfigtool/AppStage_MagnetometerCalibration.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ class AppStage_MagnetometerCalibration : public AppStage
std::chrono::time_point<std::chrono::high_resolution_clock> m_stableStartTime;
bool m_bIsStable;

std::chrono::time_point<std::chrono::high_resolution_clock> m_resetPoseButtonPressTime;
bool m_bResetPoseRequestSent;

PSMoveIntVector3 m_identityPoseMVectorSum;
int m_identityPoseSampleCount;
};
Expand Down
3 changes: 3 additions & 0 deletions src/psmoveprotocol/PSMoveProtocol.proto
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,9 @@ message Response {
string device_path = 5;
string device_serial = 6;
string assigned_host_serial = 7;
int32 firmware_version = 8;
int32 firmware_revision = 9;
bool has_magnetometer = 10;
}
repeated ControllerInfo controllers = 1;
string host_serial = 2;
Expand Down
6 changes: 6 additions & 0 deletions src/psmoveservice/Device/Manager/ControllerManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "BluetoothQueries.h"
#include "ControllerDeviceEnumerator.h"
#include "OrientationFilter.h"
#include "PSMoveProtocol.pb.h"
#include "ServerLog.h"
#include "ServerControllerView.h"
#include "ServerDeviceView.h"
Expand Down Expand Up @@ -95,6 +96,11 @@ ControllerManager::allocate_device_view(int device_id)
return new ServerControllerView(device_id);
}

int ControllerManager::getListUpdatedResponseType()
{
return PSMoveProtocol::Response_ResponseType_CONTROLLER_LIST_UPDATED;
}

void
ControllerManager::setControllerRumble(
int controller_id,
Expand Down
6 changes: 1 addition & 5 deletions src/psmoveservice/Device/Manager/ControllerManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,7 @@ class ControllerManager : public DeviceTypeManager
class DeviceEnumerator *allocate_device_enumerator() override;
void free_device_enumerator(class DeviceEnumerator *) override;
ServerDeviceView *allocate_device_view(int device_id) override;

const PSMoveProtocol::Response_ResponseType getListUpdatedResponseType() override
{
return ControllerManager::k_list_udpated_response_type;
}
int getListUpdatedResponseType() override;

private:
static const PSMoveProtocol::Response_ResponseType k_list_udpated_response_type = PSMoveProtocol::Response_ResponseType_CONTROLLER_LIST_UPDATED;
Expand Down
3 changes: 2 additions & 1 deletion src/psmoveservice/Device/Manager/DeviceTypeManager.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//-- includes -----
#include "DeviceTypeManager.h"
#include "DeviceEnumerator.h"
#include "PSMoveProtocol.pb.h"
#include "ServerLog.h"
#include "ServerDeviceView.h"
#include "ServerNetworkManager.h"
Expand Down Expand Up @@ -218,7 +219,7 @@ void
DeviceTypeManager::send_device_list_changed_notification()
{
ResponsePtr response(new PSMoveProtocol::Response);
response->set_type(getListUpdatedResponseType());
response->set_type(static_cast<PSMoveProtocol::Response_ResponseType>(getListUpdatedResponseType()));
response->set_request_id(-1);
response->set_result_code(PSMoveProtocol::Response_ResultCode_RESULT_OK);

Expand Down
3 changes: 1 addition & 2 deletions src/psmoveservice/Device/Manager/DeviceTypeManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
//-- includes -----
#include <memory>
#include <chrono>
#include "PSMoveProtocol.pb.h"

//-- typedefs -----
class ServerDeviceView;
Expand Down Expand Up @@ -56,7 +55,7 @@ class DeviceTypeManager

void send_device_list_changed_notification();

virtual const PSMoveProtocol::Response_ResponseType getListUpdatedResponseType() = 0;
virtual int getListUpdatedResponseType() = 0;

int find_first_closed_device_device_id();
int find_open_device_device_id(const class DeviceEnumerator *enumerator);
Expand Down
Loading

0 comments on commit fe5f7e0

Please sign in to comment.