Updated to OpenVR 1.0.5

Added simple alarm clock to utilities page.
Bugfixes and Improvements.
This commit is contained in:
2017-01-05 18:28:54 +01:00
parent 4667165463
commit 2a2f747518
25 changed files with 1824 additions and 234 deletions
+2 -2
View File
@@ -410,7 +410,7 @@ namespace advsettings {
auto leftId = vr::VRSystem()->GetTrackedDeviceIndexForControllerRole(vr::TrackedControllerRole_LeftHand);
if (leftId != vr::k_unTrackedDeviceIndexInvalid) {
vr::VRControllerState_t state;
if (vr::VRSystem()->GetControllerState(leftId, &state)) {
if (vr::VRSystem()->GetControllerState(leftId, &state, sizeof(vr::VRControllerState_t))) {
//logControllerState(state, "Left ");
newState |= handleControllerState(state, m_pttControllerConfigs);
}
@@ -420,7 +420,7 @@ namespace advsettings {
auto rightId = vr::VRSystem()->GetTrackedDeviceIndexForControllerRole(vr::TrackedControllerRole_RightHand);
if (rightId != vr::k_unTrackedDeviceIndexInvalid) {
vr::VRControllerState_t state;
if (vr::VRSystem()->GetControllerState(rightId, &state)) {
if (vr::VRSystem()->GetControllerState(rightId, &state, sizeof(vr::VRControllerState_t))) {
//logControllerState(state, "Right ");
newState |= handleControllerState(state, m_pttControllerConfigs + 1);
}
+10 -10
View File
@@ -44,14 +44,14 @@ void SteamVRTabController::eventLoopTick() {
LOG(DEBUG) << "OpenVR reports a changed compositor supersampling value: " << m_compositorSuperSampling << " => " << css;
setCompositorSuperSampling(css);
}
auto air = vr::VRSettings()->GetBool(vr::k_pch_SteamVR_Section, vrsettings_steamvr_allowInterleavedReprojection, &vrSettingsError);
auto air = vr::VRSettings()->GetBool(vr::k_pch_SteamVR_Section, vr::k_pch_SteamVR_AllowReprojection_Bool, &vrSettingsError);
if (vrSettingsError != vr::VRSettingsError_None) {
LOG(WARNING) << "Could not read \"" << vrsettings_steamvr_allowInterleavedReprojection << "\" setting: " << vr::VRSettings()->GetSettingsErrorNameFromEnum(vrSettingsError);
LOG(WARNING) << "Could not read \"" << vr::k_pch_SteamVR_AllowReprojection_Bool << "\" setting: " << vr::VRSettings()->GetSettingsErrorNameFromEnum(vrSettingsError);
}
setAllowInterleavedReprojection(air);
auto aar = vr::VRSettings()->GetBool(vr::k_pch_SteamVR_Section, vrsettings_steamvr_allowAsyncReprojection, &vrSettingsError);
auto aar = vr::VRSettings()->GetBool(vr::k_pch_SteamVR_Section, vr::k_pch_SteamVR_AllowAsyncReprojection_Bool, &vrSettingsError);
if (vrSettingsError != vr::VRSettingsError_None) {
LOG(WARNING) << "Could not read \"" << vrsettings_steamvr_allowAsyncReprojection << "\" setting: " << vr::VRSettings()->GetSettingsErrorNameFromEnum(vrSettingsError);
LOG(WARNING) << "Could not read \"" << vr::k_pch_SteamVR_AllowAsyncReprojection_Bool << "\" setting: " << vr::VRSettings()->GetSettingsErrorNameFromEnum(vrSettingsError);
}
setAllowAsyncReprojection(aar);
auto fr = vr::VRSettings()->GetBool(vr::k_pch_SteamVR_Section, vr::k_pch_SteamVR_ForceReprojection_Bool, &vrSettingsError);
@@ -127,7 +127,7 @@ bool SteamVRTabController::allowAsyncReprojection() const {
void SteamVRTabController::setAllowInterleavedReprojection(bool value, bool notify) {
if (m_allowInterleavedReprojection != value) {
m_allowInterleavedReprojection = value;
vr::VRSettings()->SetBool(vr::k_pch_SteamVR_Section, vrsettings_steamvr_allowInterleavedReprojection, m_allowInterleavedReprojection);
vr::VRSettings()->SetBool(vr::k_pch_SteamVR_Section, vr::k_pch_SteamVR_AllowReprojection_Bool, m_allowInterleavedReprojection);
vr::VRSettings()->Sync();
if (notify) {
emit allowInterleavedReprojectionChanged(m_allowInterleavedReprojection);
@@ -139,7 +139,7 @@ void SteamVRTabController::setAllowInterleavedReprojection(bool value, bool noti
void SteamVRTabController::setAllowAsyncReprojection(bool value, bool notify) {
if (m_allowAsyncReprojection != value) {
m_allowAsyncReprojection = value;
vr::VRSettings()->SetBool(vr::k_pch_SteamVR_Section, vrsettings_steamvr_allowAsyncReprojection, m_allowAsyncReprojection);
vr::VRSettings()->SetBool(vr::k_pch_SteamVR_Section, vr::k_pch_SteamVR_AllowAsyncReprojection_Bool, m_allowAsyncReprojection);
vr::VRSettings()->Sync();
if (notify) {
emit allowAsyncReprojectionChanged(m_allowAsyncReprojection);
@@ -178,14 +178,14 @@ void SteamVRTabController::reset() {
LOG(WARNING) << "Could not remove \"" << vrsettings_compositor_category << "::" << vr::k_pch_SteamVR_RenderTargetMultiplier_Float << "\" setting: " << vr::VRSettings()->GetSettingsErrorNameFromEnum(vrSettingsError);
}
vr::VRSettings()->RemoveKeyInSection(vr::k_pch_SteamVR_Section, vrsettings_steamvr_allowInterleavedReprojection, &vrSettingsError);
vr::VRSettings()->RemoveKeyInSection(vr::k_pch_SteamVR_Section, vr::k_pch_SteamVR_AllowReprojection_Bool, &vrSettingsError);
if (vrSettingsError != vr::VRSettingsError_None) {
LOG(WARNING) << "Could not remove \"" << vrsettings_steamvr_allowInterleavedReprojection << "\" setting: " << vr::VRSettings()->GetSettingsErrorNameFromEnum(vrSettingsError);
LOG(WARNING) << "Could not remove \"" << vr::k_pch_SteamVR_AllowReprojection_Bool << "\" setting: " << vr::VRSettings()->GetSettingsErrorNameFromEnum(vrSettingsError);
}
vr::VRSettings()->RemoveKeyInSection(vr::k_pch_SteamVR_Section, vrsettings_steamvr_allowAsyncReprojection, &vrSettingsError);
vr::VRSettings()->RemoveKeyInSection(vr::k_pch_SteamVR_Section, vr::k_pch_SteamVR_AllowAsyncReprojection_Bool, &vrSettingsError);
if (vrSettingsError != vr::VRSettingsError_None) {
LOG(WARNING) << "Could not remove \"" << vrsettings_steamvr_allowAsyncReprojection << "\" setting: " << vr::VRSettings()->GetSettingsErrorNameFromEnum(vrSettingsError);
LOG(WARNING) << "Could not remove \"" << vr::k_pch_SteamVR_AllowAsyncReprojection_Bool << "\" setting: " << vr::VRSettings()->GetSettingsErrorNameFromEnum(vrSettingsError);
}
vr::VRSettings()->RemoveKeyInSection(vr::k_pch_SteamVR_Section, vr::k_pch_SteamVR_ForceReprojection_Bool, &vrSettingsError);
+2 -2
View File
@@ -4,8 +4,8 @@
#include <QObject>
// openvr's github repo hasn't been updated yet to reflect changes in beta 1477423729.
static const char* vrsettings_steamvr_allowAsyncReprojection = "allowAsyncReprojection";
static const char* vrsettings_steamvr_allowInterleavedReprojection = "allowInterleavedReprojection";
//static const char* vrsettings_steamvr_allowAsyncReprojection = "allowAsyncReprojection";
//static const char* vrsettings_steamvr_allowInterleavedReprojection = "allowInterleavedReprojection";
static const char* vrsettings_compositor_category = "compositor";
@@ -2,12 +2,21 @@
#include <QQuickWindow>
#include "../overlaycontroller.h"
#include <Windows.h>
#include <thread>
// application namespace
namespace advsettings {
void UtilitiesTabController::initStage1() {
auto settings = OverlayController::appSettings();
settings->beginGroup("utilitiesSettings");
auto qAlarmEnabled = settings->value("alarmEnabled", m_alarmEnabled);
auto qAlarmHour = settings->value("alarmHour", 0);
auto qAlarmMinute = settings->value("alarmMinute", 0);
settings->endGroup();
m_alarmEnabled = qAlarmEnabled.toBool();
m_alarmTime = QTime(qAlarmHour.toInt(), qAlarmMinute.toInt());
}
void UtilitiesTabController::initStage2(OverlayController * parent, QQuickWindow * widget) {
@@ -146,4 +155,171 @@ namespace advsettings {
}
}
bool UtilitiesTabController::alarmEnabled() const {
return m_alarmEnabled;
}
int UtilitiesTabController::alarmTimeHour() const {
return m_alarmTime.hour();
}
int UtilitiesTabController::alarmTimeMinute() const {
return m_alarmTime.minute();
}
void UtilitiesTabController::setAlarmEnabled(bool enabled, bool notify) {
if (m_alarmEnabled != enabled) {
m_alarmEnabled = enabled;
auto settings = OverlayController::appSettings();
settings->beginGroup("utilitiesSettings");
settings->setValue("alarmEnabled", m_alarmEnabled);
settings->endGroup();
settings->sync();
m_alarmLastCheckTime = QTime();
if (notify) {
emit alarmEnabledChanged(m_alarmEnabled);
}
}
}
void UtilitiesTabController::setAlarmTimeHour(int hour, bool notify) {
if (m_alarmTime.hour() != hour) {
if (m_alarmTime.isValid()) {
m_alarmTime = QTime(hour, m_alarmTime.minute());
} else {
m_alarmTime = QTime(hour, 0);
}
auto settings = OverlayController::appSettings();
settings->beginGroup("utilitiesSettings");
settings->setValue("alarmHour", m_alarmTime.hour());
settings->setValue("alarmMinute", m_alarmTime.minute());
settings->endGroup();
settings->sync();
m_alarmLastCheckTime = QTime();
if (notify) {
emit alarmTimeHourChanged(hour);
}
}
}
void UtilitiesTabController::setAlarmTimeMinute(int min, bool notify) {
if (m_alarmTime.minute() != min) {
if (m_alarmTime.isValid()) {
m_alarmTime = QTime(m_alarmTime.hour(), min);
} else {
m_alarmTime = QTime(0, min);
}
auto settings = OverlayController::appSettings();
settings->beginGroup("utilitiesSettings");
settings->setValue("alarmHour", m_alarmTime.hour());
settings->setValue("alarmMinute", m_alarmTime.minute());
settings->endGroup();
settings->sync();
m_alarmLastCheckTime = QTime();
if (notify) {
emit alarmTimeMinuteChanged(min);
}
}
}
void UtilitiesTabController::setAlarmTimeToCurrentTime() {
auto now = QTime::currentTime();
setAlarmTimeHour(now.hour());
setAlarmTimeMinute(now.minute());
}
void UtilitiesTabController::modAlarmTimeHour(int value, bool notify) {
auto h = m_alarmTime.hour();
m_alarmTime = m_alarmTime.addSecs(value * 60 * 60);
auto settings = OverlayController::appSettings();
settings->beginGroup("utilitiesSettings");
settings->setValue("alarmHour", m_alarmTime.hour());
settings->setValue("alarmMinute", m_alarmTime.minute());
settings->endGroup();
settings->sync();
if (h != m_alarmTime.hour()) {
m_alarmLastCheckTime = QTime();
if (notify) {
emit alarmTimeHourChanged(m_alarmTime.hour());
}
}
}
void UtilitiesTabController::modAlarmTimeMinute(int value, bool notify) {
auto h = m_alarmTime.hour();
auto m = m_alarmTime.minute();
m_alarmTime = m_alarmTime.addSecs(value * 60);
auto settings = OverlayController::appSettings();
settings->beginGroup("utilitiesSettings");
settings->setValue("alarmHour", m_alarmTime.hour());
settings->setValue("alarmMinute", m_alarmTime.minute());
settings->endGroup();
settings->sync();
if (m != m_alarmTime.minute() || h != m_alarmTime.hour()) {
m_alarmLastCheckTime = QTime();
if (notify) {
if (h != m_alarmTime.hour()) {
emit alarmTimeHourChanged(m_alarmTime.hour());
}
if (m != m_alarmTime.minute()) {
emit alarmTimeMinuteChanged(m_alarmTime.minute());
}
}
}
}
void UtilitiesTabController::eventLoopTick() {
if (settingsUpdateCounter >= 10) {
if (m_alarmEnabled && m_alarmTime.isValid()) {
auto now = QTime::currentTime();
if (m_alarmLastCheckTime.isValid() && m_alarmLastCheckTime <= m_alarmTime && m_alarmTime <= now) {
setAlarmEnabled(false);
char alarmMessageBuffer[1024];
std::snprintf(alarmMessageBuffer, 1024, "The alarm at %02i:%02i went off.", alarmTimeHour(), alarmTimeMinute());
vr::VRNotificationId notificationId;
vr::EVRInitError eError;
vr::IVRNotifications* vrnotification = (vr::IVRNotifications*)vr::VR_GetGenericInterface(vr::IVRNotifications_Version, &eError);
if (eError != vr::VRInitError_None) {
LOG(ERROR) << "Error while getting IVRNotifications interface" << vr::VR_GetVRInitErrorAsEnglishDescription(eError);
vrnotification = nullptr;
} else {
auto nError = vrnotification->CreateNotification(
parent->overlayThumbnailHandle(), 666, vr::EVRNotificationType_Transient_SystemWithUserValue, alarmMessageBuffer, vr::EVRNotificationStyle_Application, nullptr, &notificationId
);
if (nError != vr::VRNotificationError_OK) {
LOG(ERROR) << "Error while creating notification: " << nError;
vrnotification = nullptr;
}
}
if (!vr::VROverlay()->IsDashboardVisible()) { // message overlay is not shown when the dashboard is visible (see https://github.com/ValveSoftware/openvr/issues/348)
std::thread messageThread([](UtilitiesTabController* parent, std::string message) {
auto res = vr::VROverlay()->ShowMessageOverlay(message.c_str(), "Alarm Clock", "Ok", "+15 min");
if (res == vr::VRMessageOverlayResponse_ButtonPress_1) {
parent->setAlarmTimeToCurrentTime();
parent->modAlarmTimeMinute(15);
parent->setAlarmEnabled(true);
} else if (res >= vr::VRMessageOverlayResponse_CouldntFindSystemOverlay) {
static const char* errorMessages[] = { "CouldntFindSystemOverlay", "CouldntFindOrCreateClientOverlay", "ApplicationQuit" };
int errorCode = res - vr::VRMessageOverlayResponse_CouldntFindSystemOverlay;
if (res < 3) {
LOG(ERROR) << "Could not create Alarm Overlay: " << errorMessages[errorCode];
} else {
LOG(ERROR) << "Could not create Alarm Overlay: Unknown Error";
}
}
}, this, std::string(alarmMessageBuffer));
messageThread.detach();
}
}
m_alarmLastCheckTime = now;
}
settingsUpdateCounter = 0;
} else {
settingsUpdateCounter++;
}
}
} // namespace advconfig
@@ -2,6 +2,7 @@
#pragma once
#include <QObject>
#include <QTime>
class QQuickWindow;
// application namespace
@@ -13,21 +14,46 @@ namespace advsettings {
class UtilitiesTabController : public QObject {
Q_OBJECT
Q_PROPERTY(bool alarmEnabled READ alarmEnabled WRITE setAlarmEnabled NOTIFY alarmEnabledChanged)
Q_PROPERTY(int alarmTimeHour READ alarmTimeHour WRITE setAlarmTimeHour NOTIFY alarmTimeHourChanged)
Q_PROPERTY(int alarmTimeMinute READ alarmTimeMinute WRITE setAlarmTimeMinute NOTIFY alarmTimeMinuteChanged)
private:
OverlayController* parent;
QQuickWindow* widget;
unsigned settingsUpdateCounter = 0;
bool m_alarmEnabled = false;
QTime m_alarmTime;
QTime m_alarmLastCheckTime;
public:
void initStage1();
void initStage2(OverlayController* parent, QQuickWindow* widget);
void eventLoopTick();
bool alarmEnabled() const;
int alarmTimeHour() const;
int alarmTimeMinute() const;
public slots:
void sendKeyboardInput(QString input);
void sendKeyboardEnter();
void sendKeyboardBackspace(int count);
void setAlarmEnabled(bool enabled, bool notify = true);
void setAlarmTimeHour(int hour, bool notify = true);
void setAlarmTimeMinute(int min, bool notify = true);
void setAlarmTimeToCurrentTime();
void modAlarmTimeHour(int value, bool notify = true);
void modAlarmTimeMinute(int value, bool notify = true);
signals:
void alarmEnabledChanged(bool enabled);
void alarmTimeHourChanged(int hour);
void alarmTimeMinuteChanged(int min);
};
} // namespace advsettings