Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Formatting and arrays #74

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Relativty_Driver/include/Relativty_EmbeddedPython.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Expand All @@ -14,6 +14,6 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.

#pragma once
#pragma warning(disable:4996)
#pragma warning(disable : 4996)

void startPythonTrackingClient_threaded(std::string PyPath);
void startPythonTrackingClient_threaded(std::string PyPath);
29 changes: 16 additions & 13 deletions Relativty_Driver/include/Relativty_HMDDriver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Expand All @@ -14,20 +14,21 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.

#pragma once
#include <thread>

#include <atomic>
#include <array>
#include <thread>
#include <shared_mutex>
#include <WinSock2.h>
#include "hidapi/hidapi.h"
#include "openvr_driver.h"
#include "Relativty_components.h"
#include "Relativty_base_device.h"

namespace Relativty {
class HMDDriver : public RelativtyDevice<false>
{
class HMDDriver : public RelativtyDevice<false> {
public:
HMDDriver(std::string myserial);
~HMDDriver() = default;
HMDDriver(const std::string &myserial);

void frameUpdate();
inline void setProperties();
Expand All @@ -48,21 +49,23 @@ namespace Relativty {
float HeadToEyeDepth;

vr::DriverPose_t lastPose = {0};
hid_device* handle;
hid_device *handle;

std::atomic<float> quat[4];
std::shared_timed_mutex quatMutex;
std::array<float, 4> quat = { 0.0f, 0.0f, 0.0f, 0.0f };
std::atomic<bool> retrieve_quaternion_isOn = false;
std::atomic<bool> new_quaternion_avaiable = false;
std::atomic<bool> new_quaternion_available = false;

std::atomic<float> qconj[4] = {1, 0, 0, 0};
std::array<float, 4> qconj = { 1.0f, 0.0f, 0.0f, 0.0f };
void calibrate_quaternion();

std::thread retrieve_quaternion_thread_worker;
void retrieve_device_quaternion_packet_threaded();

std::atomic<float> vector_xyz[3];
std::shared_timed_mutex vectorMutex;
std::array<float, 3> vector_xyz = { 0.0f, 0.0f, 0.0f };
std::atomic<bool> retrieve_vector_isOn = false;
std::atomic<bool> new_vector_avaiable = false;
std::atomic<bool> new_vector_available = false;
bool start_tracking_server = false;
SOCKET sock, sock_receive;
float upperBound;
Expand Down Expand Up @@ -94,4 +97,4 @@ namespace Relativty {
std::string PyPath;
std::thread startPythonTrackingClient_worker;
};
}
} // namespace Relativty
19 changes: 9 additions & 10 deletions Relativty_Driver/include/Relativty_ServerDriver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,36 @@
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

#pragma once
#ifndef RELATIVTY_SERVERDRIVER_H
#define RELATIVTY_SERVERDRIVER_H

#include "openvr_driver.h"
#include "Relativty_HMDDriver.hpp"

namespace Relativty {
class ServerDriver : public vr::IServerTrackedDeviceProvider
{
class ServerDriver : public vr::IServerTrackedDeviceProvider {
public:
virtual vr::EVRInitError Init(vr::IVRDriverContext* DriverContext) override;
virtual vr::EVRInitError Init(vr::IVRDriverContext *DriverContext) override;
virtual void Cleanup() override;
virtual const char* const* GetInterfaceVersions() override;
virtual const char *const *GetInterfaceVersions() override;
virtual void RunFrame() override;
virtual bool ShouldBlockStandbyMode() override;
virtual void EnterStandby() override;
virtual void LeaveStandby() override;

static void Log(std::string log);
static void Log(const std::string &log);

private:
HMDDriver* HMDDriver = nullptr;
HMDDriver *m_HMDDriver = nullptr;
};
}
} // namespace Relativty

#endif // RELATIVTY_SERVERDRIVER_H
#endif // RELATIVTY_SERVERDRIVER_H
94 changes: 44 additions & 50 deletions Relativty_Driver/include/Relativty_base_device.h
Original file line number Diff line number Diff line change
@@ -1,46 +1,43 @@
#pragma once
// Copyright (C) 2020 Max Coutte, Gabriel Combe
// Copyright (C) 2020 Relativty.com
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

#ifndef VR_DEVICE_BASE_H
#define VR_DEVICE_BASE_H

#include "driverlog.h"


#include "Relativty_components.h"

namespace Relativty {
inline vr::HmdQuaternion_t HmdQuaternion_Init(double w, double x, double y,
double z) {
vr::HmdQuaternion_t quat;
quat.w = w;
quat.x = x;
quat.y = y;
quat.z = z;
return quat;
}

static const char *const k_pch_Driver_Section = "driver_Relativty";
static const char *const k_pch_Driver_PoseTimeOffset_Float = "PoseTimeOffset";
static const char *const k_pch_Driver_UpdateUrl_String = "ManualUpdateURL";

// for now this will never signal for updates, this same function will be executed for all derived device classes on Activate
// for now this will never signal for updates, this same function will be executed for all derived device classes on Activate
// you can implement your own version/update check here
inline bool _checkForDeviceUpdates(std::string deviceSerial) {
return false; // true steamvr will signal an update, false not
}

// should be publicly inherited
template<bool UseHaptics>
class RelativtyDevice: public vr::ITrackedDeviceServerDriver {
template <bool UseHaptics>
class RelativtyDevice : public vr::ITrackedDeviceServerDriver {
public:
RelativtyDevice(std::string myserial, std::string deviceBreed): m_sSerialNumber(myserial) {
RelativtyDevice(const std::string &myserial, const std::string &deviceBreed) : m_unObjectId(vr::k_unTrackedDeviceIndexInvalid), m_ulPropertyContainer(vr::k_ulInvalidPropertyContainer), m_sSerialNumber(myserial), m_sModelNumber(deviceBreed + myserial) {
// boilerplate

m_unObjectId = vr::k_unTrackedDeviceIndexInvalid;
m_ulPropertyContainer = vr::k_ulInvalidPropertyContainer;

m_sModelNumber = deviceBreed + m_sSerialNumber;

m_fPoseTimeOffset = vr::VRSettings()->GetFloat(k_pch_Driver_Section, k_pch_Driver_PoseTimeOffset_Float);
char buff[1024];
vr::VRSettings()->GetString(k_pch_Driver_Section, k_pch_Driver_UpdateUrl_String, buff, sizeof(buff));
Expand All @@ -55,18 +52,17 @@ namespace Relativty {
m_Pose.poseTimeOffset = (double)m_fPoseTimeOffset;
m_Pose.poseIsValid = true;
m_Pose.deviceIsConnected = true;
m_Pose.qWorldFromDriverRotation = HmdQuaternion_Init(1, 0, 0, 0);
m_Pose.qDriverFromHeadRotation = HmdQuaternion_Init(1, 0, 0, 0);
m_Pose.qRotation = HmdQuaternion_Init(1, 0, 0, 0);
m_Pose.qWorldFromDriverRotation = {1, 0, 0, 0};
m_Pose.qDriverFromHeadRotation = {1, 0, 0, 0};
m_Pose.qRotation = {1, 0, 0, 0};
m_Pose.vecPosition[0] = 0.;
m_Pose.vecPosition[1] = 0.;
m_Pose.vecPosition[2] = 0.;
m_Pose.willDriftInYaw = true;
}

~RelativtyDevice(){
virtual ~RelativtyDevice() {
DriverLog("device with serial %s yeeted out of existence\n", m_sSerialNumber.c_str());

}

virtual vr::EVRInitError Activate(vr::TrackedDeviceIndex_t unObjectId) {
Expand All @@ -93,18 +89,18 @@ namespace Relativty {
DriverLog("device render model: \"%s\"\n", m_sRenderModelPath.c_str());
DriverLog("device input binding: \"%s\"\n", m_sBindPath.c_str());

if constexpr(UseHaptics) {
if constexpr (UseHaptics) {
DriverLog("device haptics added\n");
vr::VRDriverInput()->CreateHapticComponent(m_ulPropertyContainer,
"/output/haptic", &m_compHaptic);
"/output/haptic", &m_compHaptic);
}

vr::VRProperties()->SetBoolProperty(
m_ulPropertyContainer, vr::Prop_Identifiable_Bool, UseHaptics);

vr::VRProperties()->SetStringProperty(
m_ulPropertyContainer, vr::Prop_Firmware_ManualUpdateURL_String,
m_sUpdateUrl.c_str());
m_ulPropertyContainer, vr::Prop_Firmware_ManualUpdateURL_String,
m_sUpdateUrl.c_str());

bool shouldUpdate = _checkForDeviceUpdates(m_sSerialNumber);

Expand All @@ -116,7 +112,6 @@ namespace Relativty {
vr::VRProperties()->SetBoolProperty(m_ulPropertyContainer,
vr::Prop_Firmware_ManualUpdate_Bool, shouldUpdate);


return vr::VRInitError_None;
}

Expand All @@ -130,7 +125,7 @@ namespace Relativty {

virtual void PowerOff() {}

// debug request from the client, TODO: uh... actually implement this?
// debug request from the client, TODO: uh... actually implement this?
virtual void DebugRequest(const char *pchRequest, char *pchResponseBuffer,
uint32_t unResponseBufferSize) {
DriverLog("device serial \"%s\", got debug request: \"%s\"", m_sSerialNumber.c_str(), pchRequest);
Expand All @@ -143,7 +138,7 @@ namespace Relativty {
void *GetComponent(const char *pchComponentNameAndVersion) {
// don't touch this
DriverLog("device serial \"%s\", got request for \"%s\" component\n", m_sSerialNumber.c_str(), pchComponentNameAndVersion);
if (!_stricmp(pchComponentNameAndVersion, vr::IVRDisplayComponent_Version) && m_spExtDisplayComp != nullptr){
if (!_stricmp(pchComponentNameAndVersion, vr::IVRDisplayComponent_Version) && m_spExtDisplayComp != nullptr) {
DriverLog("component found, responding...\n");
return m_spExtDisplayComp.get();
}
Expand All @@ -156,42 +151,41 @@ namespace Relativty {

// processes events, reacts to haptics only
void ProcessEvent(const vr::VREvent_t &vrEvent) {
if constexpr(UseHaptics)
{
if constexpr (UseHaptics) {
switch (vrEvent.eventType) {
case vr::VREvent_Input_HapticVibration: {
if (vrEvent.data.hapticVibration.componentHandle == m_compHaptic) {
// haptic!
DriverLog("%s haptic event: %f, %f, %f\n", m_sSerialNumber, vrEvent.data.hapticVibration.fDurationSeconds,
vrEvent.data.hapticVibration.fFrequency, vrEvent.data.hapticVibration.fAmplitude);
}
} break;
case vr::VREvent_Input_HapticVibration: {
if (vrEvent.data.hapticVibration.componentHandle == m_compHaptic) {
// haptic!
DriverLog("%s haptic event: %f, %f, %f\n", m_sSerialNumber, vrEvent.data.hapticVibration.fDurationSeconds,
vrEvent.data.hapticVibration.fFrequency, vrEvent.data.hapticVibration.fAmplitude);
}
}
break;
}
}
}

protected:
// openvr api stuff
vr::TrackedDeviceIndex_t m_unObjectId; // DO NOT TOUCH THIS, parent will handle this, use it as read only!
vr::TrackedDeviceIndex_t m_unObjectId; // DO NOT TOUCH THIS, parent will handle this, use it as read only!
vr::PropertyContainerHandle_t m_ulPropertyContainer; // THIS EITHER, use it as read only!


std::string m_sRenderModelPath; // path to the device's render model, should be populated in the constructor of the derived class
std::string m_sBindPath; // path to the device's input bindings, should be populated in the constructor of the derived class
std::string m_sBindPath; // path to the device's input bindings, should be populated in the constructor of the derived class

vr::DriverPose_t m_Pose; // device's pose, use this at runtime

std::shared_ptr<RelativtyExtendedDisplayComponent> m_spExtDisplayComp;

private:
// openvr api stuff that i don't trust you with
float m_fPoseTimeOffset; // time offset of the pose, set trough the config
float m_fPoseTimeOffset; // time offset of the pose, set trough the config
vr::VRInputComponentHandle_t m_compHaptic; // haptics, used if UseHaptics is true

std::string m_sUpdateUrl; // url to which steamvr will redirect if checkForDeviceUpdates returns true on Activate, set trough the config
std::string m_sUpdateUrl; // url to which steamvr will redirect if checkForDeviceUpdates returns true on Activate, set trough the config
std::string m_sSerialNumber; // steamvr uses this to identify devices, no need for you to touch this after init
std::string m_sModelNumber; // steamvr uses this to identify devices, no need for you to touch this after init
std::string m_sModelNumber; // steamvr uses this to identify devices, no need for you to touch this after init
};
}
} // namespace Relativty

#endif // VR_DEVICE_BASE_H
#endif // VR_DEVICE_BASE_H
Loading