From 147200154f2e9046cbb6f5608fe6bf6a3e7922a2 Mon Sep 17 00:00:00 2001 From: r57zone Date: Mon, 19 Sep 2022 13:57:06 +0400 Subject: [PATCH] Improvements: arduino require option & new hmd icon --- .../driver_arduinohmd/driver_arduinohmd.cpp | 64 +++++++++---------- README.RU.md | 10 +-- README.md | 10 +-- 3 files changed, 43 insertions(+), 41 deletions(-) diff --git a/OpenVR/samples/driver_arduinohmd/driver_arduinohmd.cpp b/OpenVR/samples/driver_arduinohmd/driver_arduinohmd.cpp index 9b9181c..e97097e 100644 --- a/OpenVR/samples/driver_arduinohmd/driver_arduinohmd.cpp +++ b/OpenVR/samples/driver_arduinohmd/driver_arduinohmd.cpp @@ -81,6 +81,7 @@ static const char * const k_pch_arduinoHMD_DebugMode_Bool = "DebugMode"; // arduino hmd settings static const char * const k_pch_arduinoHMD_Section = "arduinohmd"; +static const char * const k_pch_arduinoHMD_ArduinoRequire_Bool = "ArduinoRequire"; static const char * const k_pch_arduinoHMD_COM_port_Int32 = "COMPort"; static const char * const k_pch_arduinoHMD_CenteringKey_Int32 = "CenteringKey"; static const char * const k_pch_arduinoHMD_CrouchPressKey_Int32 = "CrouchPressKey"; @@ -88,7 +89,7 @@ static const char * const k_pch_arduinoHMD_CrouchOffset_Float = "CrouchOffset"; HANDLE hSerial; int32_t comPortNumber; -bool HMDConnected = false, HMDInitCentring = false; +bool HMDConnected = false, HMDInitCentring = false, ArduinoNotRequire = false; float ArduinoIMU[3] = { 0, 0, 0 }, yprOffset[3] = { 0, 0, 0 }; // Yaw, Pitch, Roll float LastArduinoIMU[3] = { 0, 0, 0 }; double fPos[3] = { 0, 0, 0 }; @@ -254,13 +255,13 @@ class CDeviceDriver : public vr::ITrackedDeviceServerDriver, public vr::IVRDispl m_crouchOffset = vr::VRSettings()->GetFloat(k_pch_arduinoHMD_Section, k_pch_arduinoHMD_CrouchOffset_Float); m_crouchPressKey = vr::VRSettings()->GetInt32(k_pch_arduinoHMD_Section, k_pch_arduinoHMD_CrouchPressKey_Int32); - /*DriverLog( "driver_arduinohmd: Serial Number: %s\n", m_sSerialNumber.c_str() ); - DriverLog( "driver_arduinohmd: Model Number: %s\n", m_sModelNumber.c_str() ); - DriverLog( "driver_arduinohmd: Window: %d %d %d %d\n", m_nWindowX, m_nWindowY, m_nWindowWidth, m_nWindowHeight ); - DriverLog( "driver_arduinohmd: Render Target: %d %d\n", m_nRenderWidth, m_nRenderHeight ); - DriverLog( "driver_arduinohmd: Seconds from Vsync to Photons: %f\n", m_flSecondsFromVsyncToPhotons ); - DriverLog( "driver_arduinohmd: Display Frequency: %f\n", m_flDisplayFrequency ); - DriverLog( "driver_arduinohmd: IPD: %f\n", m_flIPD );*/ + //DriverLog( "driver_arduinohmd: Serial Number: %s\n", m_sSerialNumber.c_str() ); + //DriverLog( "driver_arduinohmd: Model Number: %s\n", m_sModelNumber.c_str() ); + //DriverLog( "driver_arduinohmd: Window: %d %d %d %d\n", m_nWindowX, m_nWindowY, m_nWindowWidth, m_nWindowHeight ); + //DriverLog( "driver_arduinohmd: Render Target: %d %d\n", m_nRenderWidth, m_nRenderHeight ); + //DriverLog( "driver_arduinohmd: Seconds from Vsync to Photons: %f\n", m_flSecondsFromVsyncToPhotons ); + //DriverLog( "driver_arduinohmd: Display Frequency: %f\n", m_flDisplayFrequency ); + //DriverLog( "driver_arduinohmd: IPD: %f\n", m_flIPD ); } virtual ~CDeviceDriver() @@ -287,7 +288,7 @@ class CDeviceDriver : public vr::ITrackedDeviceServerDriver, public vr::IVRDispl vr::VRProperties()->SetBoolProperty( m_ulPropertyContainer, Prop_IsOnDesktop_Bool, false ); // debug mode activate Windowed Mode (borderless fullscreen), lock to 30 FPS - vr::VRProperties()->SetBoolProperty(m_ulPropertyContainer, Prop_DisplayDebugMode_Bool, m_bDebugMode); + vr::VRProperties()->SetBoolProperty( m_ulPropertyContainer, Prop_DisplayDebugMode_Bool, m_bDebugMode ); // Icons can be configured in code or automatically configured by an external file "drivername\resources\driver.vrresources". // Icon properties NOT configured in code (post Activate) are then auto-configured by the optional presence of a driver's "drivername\resources\driver.vrresources". @@ -312,20 +313,14 @@ class CDeviceDriver : public vr::ITrackedDeviceServerDriver, public vr::IVRDispl // Thus "Prop_NamedIconPathDeviceAlertLow_String" in each model's block represent a specialization specific for that "model". // Keys in "Model-v Defaults" are an example of mapping to the same states, and here all map to "Prop_NamedIconPathDeviceOff_String". // - /*bool bSetupIconUsingExternalResourceFile = true; - if ( !bSetupIconUsingExternalResourceFile ) - { - // Setup properties directly in code. - // Path values are of the form {drivername}\icons\some_icon_filename.png - vr::VRProperties()->SetStringProperty( m_ulPropertyContainer, vr::Prop_NamedIconPathDeviceOff_String, "{sample}/icons/headset_sample_status_off.png" ); - vr::VRProperties()->SetStringProperty( m_ulPropertyContainer, vr::Prop_NamedIconPathDeviceSearching_String, "{sample}/icons/headset_sample_status_searching.gif" ); - vr::VRProperties()->SetStringProperty( m_ulPropertyContainer, vr::Prop_NamedIconPathDeviceSearchingAlert_String, "{sample}/icons/headset_sample_status_searching_alert.gif" ); - vr::VRProperties()->SetStringProperty( m_ulPropertyContainer, vr::Prop_NamedIconPathDeviceReady_String, "{sample}/icons/headset_sample_status_ready.png" ); - vr::VRProperties()->SetStringProperty( m_ulPropertyContainer, vr::Prop_NamedIconPathDeviceReadyAlert_String, "{sample}/icons/headset_sample_status_ready_alert.png" ); - vr::VRProperties()->SetStringProperty( m_ulPropertyContainer, vr::Prop_NamedIconPathDeviceNotReady_String, "{sample}/icons/headset_sample_status_error.png" ); - vr::VRProperties()->SetStringProperty( m_ulPropertyContainer, vr::Prop_NamedIconPathDeviceStandby_String, "{sample}/icons/headset_sample_status_standby.png" ); - vr::VRProperties()->SetStringProperty( m_ulPropertyContainer, vr::Prop_NamedIconPathDeviceAlertLow_String, "{sample}/icons/headset_sample_status_ready_low.png" ); - }*/ + vr::VRProperties()->SetStringProperty( m_ulPropertyContainer, vr::Prop_NamedIconPathDeviceOff_String, "{indexhmd}/icons/headset_status_off.png" ); + vr::VRProperties()->SetStringProperty( m_ulPropertyContainer, vr::Prop_NamedIconPathDeviceSearching_String, "{indexhmd}/icons/headset_status_searching.gif" ); + vr::VRProperties()->SetStringProperty( m_ulPropertyContainer, vr::Prop_NamedIconPathDeviceSearchingAlert_String, "{indexhmd}/icons/headset_status_searching_alert.gif" ); + vr::VRProperties()->SetStringProperty( m_ulPropertyContainer, vr::Prop_NamedIconPathDeviceReady_String, "{indexhmd}/icons/headset_status_ready.png" ); + vr::VRProperties()->SetStringProperty( m_ulPropertyContainer, vr::Prop_NamedIconPathDeviceReadyAlert_String, "{indexhmd}/icons/headset_status_ready_alert.png" ); + vr::VRProperties()->SetStringProperty( m_ulPropertyContainer, vr::Prop_NamedIconPathDeviceNotReady_String, "{indexhmd}/icons/headset_status_error.png" ); + vr::VRProperties()->SetStringProperty( m_ulPropertyContainer, vr::Prop_NamedIconPathDeviceStandby_String, "{indexhmd}/icons/headset_status_standby.png" ); + vr::VRProperties()->SetStringProperty( m_ulPropertyContainer, vr::Prop_NamedIconPathDeviceAlertLow_String, "{indexhmd}/icons/headset_status_standby.png" ); //headset_status_ready_low.png return VRInitError_None; } @@ -466,13 +461,11 @@ class CDeviceDriver : public vr::ITrackedDeviceServerDriver, public vr::IVRDispl { DriverPose_t pose = { 0 }; - if (HMDConnected) { + if (HMDConnected || ArduinoNotRequire) { pose.poseIsValid = true; pose.result = TrackingResult_Running_OK; pose.deviceIsConnected = true; - } - else - { + } else { pose.poseIsValid = false; pose.result = TrackingResult_Uninitialized; pose.deviceIsConnected = false; @@ -481,7 +474,7 @@ class CDeviceDriver : public vr::ITrackedDeviceServerDriver, public vr::IVRDispl pose.qWorldFromDriverRotation = HmdQuaternion_Init(1, 0, 0, 0); pose.qDriverFromHeadRotation = HmdQuaternion_Init(1, 0, 0, 0); - if (HMDConnected) { + if (HMDConnected || ArduinoNotRequire) { // Pos if ((GetAsyncKeyState(VK_NUMPAD8) & 0x8000) != 0) fPos[2] -= StepPos; @@ -518,14 +511,14 @@ class CDeviceDriver : public vr::ITrackedDeviceServerDriver, public vr::IVRDispl DegToRad( OffsetYPR(ArduinoIMU[1], yprOffset[1]) * -1 )); //Set head position tracking - pose.vecPosition[0] = fPos[0]; //X + pose.vecPosition[0] = fPos[0]; // X if ((GetAsyncKeyState(m_crouchPressKey) & 0x8000) != 0) - pose.vecPosition[1] = fPos[1] - m_crouchOffset; //Z + pose.vecPosition[1] = fPos[1] - m_crouchOffset; // Z else - pose.vecPosition[1] = fPos[1]; //Z + pose.vecPosition[1] = fPos[1]; // Z - pose.vecPosition[2] = fPos[2]; //Y + pose.vecPosition[2] = fPos[2]; // Y } return pose; @@ -591,6 +584,7 @@ class CServerDriver: public IServerTrackedDeviceProvider virtual void EnterStandby() {} virtual void LeaveStandby() {} + private: CDeviceDriver *m_pNullHmdLatest = nullptr; }; @@ -603,10 +597,12 @@ EVRInitError CServerDriver::Init( vr::IVRDriverContext *pDriverContext ) VR_INIT_SERVER_DRIVER_CONTEXT( pDriverContext ); //InitDriverLog( vr::VRDriverLog() ); + ArduinoNotRequire = !vr::VRSettings()->GetInt32(k_pch_arduinoHMD_Section, k_pch_arduinoHMD_ArduinoRequire_Bool); comPortNumber = vr::VRSettings()->GetInt32(k_pch_arduinoHMD_Section, k_pch_arduinoHMD_COM_port_Int32); + ArduinoIMUStart(); - if (HMDConnected) + if (HMDConnected || ArduinoNotRequire) { m_pNullHmdLatest = new CDeviceDriver(); vr::VRServerDriverHost()->TrackedDeviceAdded(m_pNullHmdLatest->GetSerialNumber().c_str(), vr::TrackedDeviceClass_HMD, m_pNullHmdLatest); @@ -625,7 +621,9 @@ void CServerDriver::Cleanup() delete pArduinoReadThread; pArduinoReadThread = nullptr; CloseHandle(hSerial); + } + if (HMDConnected || ArduinoNotRequire) { delete m_pNullHmdLatest; m_pNullHmdLatest = NULL; } diff --git a/README.RU.md b/README.RU.md index 2465c1e..458969b 100644 --- a/README.RU.md +++ b/README.RU.md @@ -30,10 +30,11 @@ ![](https://user-images.githubusercontent.com/9499881/52521728-e200dc80-2c94-11e9-9628-68ea3ef3dacd.png) Скорость должна быть изменена на `115200`, если по умолчанию задана другая. + ## Параметры файла конфигурации Название | Описание ------------ | ------------- -COMPort | Номер COM порта Arduino, можно посмотреть в диспетчере устройств. Используйте порты от 1 до 9, измените при необходимости его в свойствах устройства. +COMPort | Номер COM порта Arduino, можно посмотреть в диспетчере устройств. Используйте порты от `1` до `9`, измените при необходимости его в свойствах устройства. CenteringKey | Код кнопки центрирования изображения, изменить кнопку можно в файле конфигурации, вписав [нужный код кнопки](https://github.com/r57zone/Half-Life-Alyx-novr/blob/master/BINDINGS.RU.md#%D0%BA%D0%BE%D0%B4%D1%8B)). CrouchPressKey | Код кнопки приседания, изменить кнопку можно в файле конфигурации, вписав [нужный код кнопки](https://github.com/r57zone/Half-Life-Alyx-novr/blob/master/BINDINGS.RU.md#%D0%BA%D0%BE%D0%B4%D1%8B)). Необходимо для связи с другими драйверами, например, используя контроллеры Razer Hydra и используя [этот драйвер](https://github.com/r57zone/Razer-Hydra-SteamVR-driver) можно приседать. CrouchOffset | Высота приседания по нажатию кнопки. @@ -46,7 +47,8 @@ displayFrequency | Частота обновления экрана. renderWidth, renderHeight | Разрешение рендера изображения для одного глаза. windowWidth, windowHeight | Высота и ширина выводимого окна. windowX, windowY | Смещение окна, требуется для отображения на других мониторах (расширенных). Например, для отображения на втором дисплее, который отображается справа, нужно указать значение 1920 (при условии, что первый дисплей имеет разрешение 1920 на 1080). Точные данные можно просмотреть, с помощью [MultiMonitorTool утилиты](https://www.nirsoft.net/utils/multi_monitor_tool.html), которая также может выключать и включить второй монитор, через bat-файл. -DebugMode | Режим отладки, заблокирован на 30 FPS. Рекомендуется после проверки отключить (поставить false). +DebugMode | Режим отладки, заблокирован на 30 FPS. Рекомендуется после проверки отключить (поставить `false`). +ArduinoRequire | Требование подключенного Arduino, для запуска драйвера. Параметр необходим для быстрых тестов контроллеров, чтобы не подключать и одевать шлем для тестов. Для отключения измените на `false`. ## Горячие клавиши Название | Описание @@ -54,8 +56,8 @@ DebugMode | Режим отладки, заблокирован на 30 FPS. Р Numpad 5, CTRL + ALT + R | Центрирование изображения. Page Up, Page Down | Подняться или опуститься. Numpad 8, 2, 4, 6 | Перемещение вперед, назад, влево, вправо. -Numpad 1, 3 | Изменить Yaw (Рысканье). -Numpad 7, 9 | Изменить Roll (Крен). +Numpad 1, 3 | Изменить yaw (рысканье). +Numpad 7, 9 | Изменить roll (крен). Numpad - | Сброс перемещений и поднятия. ## Известные проблемы diff --git a/README.md b/README.md index 8a7aa74..a62dff4 100644 --- a/README.md +++ b/README.md @@ -30,10 +30,11 @@ There is a ready-made Arduino firmware for [MPU 6050 GY-521](http://ali.pub/2oy7 ![](https://user-images.githubusercontent.com/9499881/52521728-e200dc80-2c94-11e9-9628-68ea3ef3dacd.png) The speed should be changed to `115200` if a different one is set by default. + ## Configuration file options Name | Description ------------ | ------------- -COMPort | The number of the Arduino COM port can be found in the Devices Manager. Use ports from 1 to 9, change it in the device properties if necessary. +COMPort | The number of the Arduino COM port can be found in the Devices Manager. Use ports from `1` to `9`, change it in the device properties if necessary. CenteringKey | The code of the picture centering key, you can change the key in the configuration file by typing [the desired key code](https://github.com/r57zone/Half-Life-Alyx-novr/blob/master/BINDINGS.md#codes)). CrouchPressKey | The code of the crouch key, you can change the key in the configuration file by typing [the desired key code](https://github.com/r57zone/Half-Life-Alyx-novr/blob/master/BINDINGS.md#codes)). It is necessary for communication with other drivers, for example, using Razer Hydra controllers and using [this driver](https://github.com/r57zone/Razer-Hydra-SteamVR-driver) you can crouch. CrouchOffset | The height of the crouch at the touch of a button. @@ -46,7 +47,8 @@ displayFrequency | Screen refresh rate. renderWidth, renderHeight | Image rendering resolution for one eye. windowWidth, windowHeight | Height and width of the displayed window. windowX, windowY | Window offset is required for display on other monitors. For example, to display on the second display, which is displayed on the right, you need to specify the value 1920 (provided that the first display has a resolution of 1920 by 1080). The exact data can be viewed using the [MultiMonitorTool utility](https://www.nirsoft.net/utils/multi_monitor_tool.html), and also with it you can turn off and turn on the second monitor via a bat file. -DebugMode | Debug mode, locked at 30 FPS. After checking, it is recommended to set it to false (disable). +DebugMode | Debug mode, locked at 30 FPS. After checking, it is recommended to set it to `false` (disable). +ArduinoRequire | Requires a connected Arduino to start the driver. The parameter is necessary for quick tests of controllers, so as not to connect and put on a hmd for tests. To disable, change to `false`. ## Hotkeys Name | Description @@ -54,8 +56,8 @@ Name | Description Numpad 5, CTRL + ALT + R | Centering the picture. Page Up, Page Down | Rise or decline. Numpad 8, 2, 4, 6 | Move forward, backward, left, right. -Numpad 1, 3 | Change Yaw. -Numpad 7, 9 | Change Roll. +Numpad 1, 3 | Change yaw. +Numpad 7, 9 | Change roll. Numpad - | Resetting movements and lifting. ## Known Issues