Skip to content

Commit 1472001

Browse files
committed
Improvements: arduino require option & new hmd icon
1 parent 610440c commit 1472001

File tree

3 files changed

+43
-41
lines changed

3 files changed

+43
-41
lines changed

OpenVR/samples/driver_arduinohmd/driver_arduinohmd.cpp

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,15 @@ static const char * const k_pch_arduinoHMD_DebugMode_Bool = "DebugMode";
8181

8282
// arduino hmd settings
8383
static const char * const k_pch_arduinoHMD_Section = "arduinohmd";
84+
static const char * const k_pch_arduinoHMD_ArduinoRequire_Bool = "ArduinoRequire";
8485
static const char * const k_pch_arduinoHMD_COM_port_Int32 = "COMPort";
8586
static const char * const k_pch_arduinoHMD_CenteringKey_Int32 = "CenteringKey";
8687
static const char * const k_pch_arduinoHMD_CrouchPressKey_Int32 = "CrouchPressKey";
8788
static const char * const k_pch_arduinoHMD_CrouchOffset_Float = "CrouchOffset";
8889

8990
HANDLE hSerial;
9091
int32_t comPortNumber;
91-
bool HMDConnected = false, HMDInitCentring = false;
92+
bool HMDConnected = false, HMDInitCentring = false, ArduinoNotRequire = false;
9293
float ArduinoIMU[3] = { 0, 0, 0 }, yprOffset[3] = { 0, 0, 0 }; // Yaw, Pitch, Roll
9394
float LastArduinoIMU[3] = { 0, 0, 0 };
9495
double fPos[3] = { 0, 0, 0 };
@@ -254,13 +255,13 @@ class CDeviceDriver : public vr::ITrackedDeviceServerDriver, public vr::IVRDispl
254255
m_crouchOffset = vr::VRSettings()->GetFloat(k_pch_arduinoHMD_Section, k_pch_arduinoHMD_CrouchOffset_Float);
255256
m_crouchPressKey = vr::VRSettings()->GetInt32(k_pch_arduinoHMD_Section, k_pch_arduinoHMD_CrouchPressKey_Int32);
256257

257-
/*DriverLog( "driver_arduinohmd: Serial Number: %s\n", m_sSerialNumber.c_str() );
258-
DriverLog( "driver_arduinohmd: Model Number: %s\n", m_sModelNumber.c_str() );
259-
DriverLog( "driver_arduinohmd: Window: %d %d %d %d\n", m_nWindowX, m_nWindowY, m_nWindowWidth, m_nWindowHeight );
260-
DriverLog( "driver_arduinohmd: Render Target: %d %d\n", m_nRenderWidth, m_nRenderHeight );
261-
DriverLog( "driver_arduinohmd: Seconds from Vsync to Photons: %f\n", m_flSecondsFromVsyncToPhotons );
262-
DriverLog( "driver_arduinohmd: Display Frequency: %f\n", m_flDisplayFrequency );
263-
DriverLog( "driver_arduinohmd: IPD: %f\n", m_flIPD );*/
258+
//DriverLog( "driver_arduinohmd: Serial Number: %s\n", m_sSerialNumber.c_str() );
259+
//DriverLog( "driver_arduinohmd: Model Number: %s\n", m_sModelNumber.c_str() );
260+
//DriverLog( "driver_arduinohmd: Window: %d %d %d %d\n", m_nWindowX, m_nWindowY, m_nWindowWidth, m_nWindowHeight );
261+
//DriverLog( "driver_arduinohmd: Render Target: %d %d\n", m_nRenderWidth, m_nRenderHeight );
262+
//DriverLog( "driver_arduinohmd: Seconds from Vsync to Photons: %f\n", m_flSecondsFromVsyncToPhotons );
263+
//DriverLog( "driver_arduinohmd: Display Frequency: %f\n", m_flDisplayFrequency );
264+
//DriverLog( "driver_arduinohmd: IPD: %f\n", m_flIPD );
264265
}
265266

266267
virtual ~CDeviceDriver()
@@ -287,7 +288,7 @@ class CDeviceDriver : public vr::ITrackedDeviceServerDriver, public vr::IVRDispl
287288
vr::VRProperties()->SetBoolProperty( m_ulPropertyContainer, Prop_IsOnDesktop_Bool, false );
288289

289290
// debug mode activate Windowed Mode (borderless fullscreen), lock to 30 FPS
290-
vr::VRProperties()->SetBoolProperty(m_ulPropertyContainer, Prop_DisplayDebugMode_Bool, m_bDebugMode);
291+
vr::VRProperties()->SetBoolProperty( m_ulPropertyContainer, Prop_DisplayDebugMode_Bool, m_bDebugMode );
291292

292293
// Icons can be configured in code or automatically configured by an external file "drivername\resources\driver.vrresources".
293294
// 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
312313
// Thus "Prop_NamedIconPathDeviceAlertLow_String" in each model's block represent a specialization specific for that "model".
313314
// Keys in "Model-v Defaults" are an example of mapping to the same states, and here all map to "Prop_NamedIconPathDeviceOff_String".
314315
//
315-
/*bool bSetupIconUsingExternalResourceFile = true;
316-
if ( !bSetupIconUsingExternalResourceFile )
317-
{
318-
// Setup properties directly in code.
319-
// Path values are of the form {drivername}\icons\some_icon_filename.png
320-
vr::VRProperties()->SetStringProperty( m_ulPropertyContainer, vr::Prop_NamedIconPathDeviceOff_String, "{sample}/icons/headset_sample_status_off.png" );
321-
vr::VRProperties()->SetStringProperty( m_ulPropertyContainer, vr::Prop_NamedIconPathDeviceSearching_String, "{sample}/icons/headset_sample_status_searching.gif" );
322-
vr::VRProperties()->SetStringProperty( m_ulPropertyContainer, vr::Prop_NamedIconPathDeviceSearchingAlert_String, "{sample}/icons/headset_sample_status_searching_alert.gif" );
323-
vr::VRProperties()->SetStringProperty( m_ulPropertyContainer, vr::Prop_NamedIconPathDeviceReady_String, "{sample}/icons/headset_sample_status_ready.png" );
324-
vr::VRProperties()->SetStringProperty( m_ulPropertyContainer, vr::Prop_NamedIconPathDeviceReadyAlert_String, "{sample}/icons/headset_sample_status_ready_alert.png" );
325-
vr::VRProperties()->SetStringProperty( m_ulPropertyContainer, vr::Prop_NamedIconPathDeviceNotReady_String, "{sample}/icons/headset_sample_status_error.png" );
326-
vr::VRProperties()->SetStringProperty( m_ulPropertyContainer, vr::Prop_NamedIconPathDeviceStandby_String, "{sample}/icons/headset_sample_status_standby.png" );
327-
vr::VRProperties()->SetStringProperty( m_ulPropertyContainer, vr::Prop_NamedIconPathDeviceAlertLow_String, "{sample}/icons/headset_sample_status_ready_low.png" );
328-
}*/
316+
vr::VRProperties()->SetStringProperty( m_ulPropertyContainer, vr::Prop_NamedIconPathDeviceOff_String, "{indexhmd}/icons/headset_status_off.png" );
317+
vr::VRProperties()->SetStringProperty( m_ulPropertyContainer, vr::Prop_NamedIconPathDeviceSearching_String, "{indexhmd}/icons/headset_status_searching.gif" );
318+
vr::VRProperties()->SetStringProperty( m_ulPropertyContainer, vr::Prop_NamedIconPathDeviceSearchingAlert_String, "{indexhmd}/icons/headset_status_searching_alert.gif" );
319+
vr::VRProperties()->SetStringProperty( m_ulPropertyContainer, vr::Prop_NamedIconPathDeviceReady_String, "{indexhmd}/icons/headset_status_ready.png" );
320+
vr::VRProperties()->SetStringProperty( m_ulPropertyContainer, vr::Prop_NamedIconPathDeviceReadyAlert_String, "{indexhmd}/icons/headset_status_ready_alert.png" );
321+
vr::VRProperties()->SetStringProperty( m_ulPropertyContainer, vr::Prop_NamedIconPathDeviceNotReady_String, "{indexhmd}/icons/headset_status_error.png" );
322+
vr::VRProperties()->SetStringProperty( m_ulPropertyContainer, vr::Prop_NamedIconPathDeviceStandby_String, "{indexhmd}/icons/headset_status_standby.png" );
323+
vr::VRProperties()->SetStringProperty( m_ulPropertyContainer, vr::Prop_NamedIconPathDeviceAlertLow_String, "{indexhmd}/icons/headset_status_standby.png" ); //headset_status_ready_low.png
329324

330325
return VRInitError_None;
331326
}
@@ -466,13 +461,11 @@ class CDeviceDriver : public vr::ITrackedDeviceServerDriver, public vr::IVRDispl
466461
{
467462
DriverPose_t pose = { 0 };
468463

469-
if (HMDConnected) {
464+
if (HMDConnected || ArduinoNotRequire) {
470465
pose.poseIsValid = true;
471466
pose.result = TrackingResult_Running_OK;
472467
pose.deviceIsConnected = true;
473-
}
474-
else
475-
{
468+
} else {
476469
pose.poseIsValid = false;
477470
pose.result = TrackingResult_Uninitialized;
478471
pose.deviceIsConnected = false;
@@ -481,7 +474,7 @@ class CDeviceDriver : public vr::ITrackedDeviceServerDriver, public vr::IVRDispl
481474
pose.qWorldFromDriverRotation = HmdQuaternion_Init(1, 0, 0, 0);
482475
pose.qDriverFromHeadRotation = HmdQuaternion_Init(1, 0, 0, 0);
483476

484-
if (HMDConnected) {
477+
if (HMDConnected || ArduinoNotRequire) {
485478

486479
// Pos
487480
if ((GetAsyncKeyState(VK_NUMPAD8) & 0x8000) != 0) fPos[2] -= StepPos;
@@ -518,14 +511,14 @@ class CDeviceDriver : public vr::ITrackedDeviceServerDriver, public vr::IVRDispl
518511
DegToRad( OffsetYPR(ArduinoIMU[1], yprOffset[1]) * -1 ));
519512

520513
//Set head position tracking
521-
pose.vecPosition[0] = fPos[0]; //X
514+
pose.vecPosition[0] = fPos[0]; // X
522515

523516
if ((GetAsyncKeyState(m_crouchPressKey) & 0x8000) != 0)
524-
pose.vecPosition[1] = fPos[1] - m_crouchOffset; //Z
517+
pose.vecPosition[1] = fPos[1] - m_crouchOffset; // Z
525518
else
526-
pose.vecPosition[1] = fPos[1]; //Z
519+
pose.vecPosition[1] = fPos[1]; // Z
527520

528-
pose.vecPosition[2] = fPos[2]; //Y
521+
pose.vecPosition[2] = fPos[2]; // Y
529522
}
530523

531524
return pose;
@@ -591,6 +584,7 @@ class CServerDriver: public IServerTrackedDeviceProvider
591584
virtual void EnterStandby() {}
592585
virtual void LeaveStandby() {}
593586

587+
594588
private:
595589
CDeviceDriver *m_pNullHmdLatest = nullptr;
596590
};
@@ -603,10 +597,12 @@ EVRInitError CServerDriver::Init( vr::IVRDriverContext *pDriverContext )
603597
VR_INIT_SERVER_DRIVER_CONTEXT( pDriverContext );
604598
//InitDriverLog( vr::VRDriverLog() );
605599

600+
ArduinoNotRequire = !vr::VRSettings()->GetInt32(k_pch_arduinoHMD_Section, k_pch_arduinoHMD_ArduinoRequire_Bool);
606601
comPortNumber = vr::VRSettings()->GetInt32(k_pch_arduinoHMD_Section, k_pch_arduinoHMD_COM_port_Int32);
602+
607603
ArduinoIMUStart();
608604

609-
if (HMDConnected)
605+
if (HMDConnected || ArduinoNotRequire)
610606
{
611607
m_pNullHmdLatest = new CDeviceDriver();
612608
vr::VRServerDriverHost()->TrackedDeviceAdded(m_pNullHmdLatest->GetSerialNumber().c_str(), vr::TrackedDeviceClass_HMD, m_pNullHmdLatest);
@@ -625,7 +621,9 @@ void CServerDriver::Cleanup()
625621
delete pArduinoReadThread;
626622
pArduinoReadThread = nullptr;
627623
CloseHandle(hSerial);
624+
}
628625

626+
if (HMDConnected || ArduinoNotRequire) {
629627
delete m_pNullHmdLatest;
630628
m_pNullHmdLatest = NULL;
631629
}

README.RU.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@
3030
![](https://user-images.githubusercontent.com/9499881/52521728-e200dc80-2c94-11e9-9628-68ea3ef3dacd.png)
3131

3232
Скорость должна быть изменена на `115200`, если по умолчанию задана другая.
33+
3334
## Параметры файла конфигурации
3435
Название | Описание
3536
------------ | -------------
36-
COMPort | Номер COM порта Arduino, можно посмотреть в диспетчере устройств. Используйте порты от 1 до 9, измените при необходимости его в свойствах устройства.
37+
COMPort | Номер COM порта Arduino, можно посмотреть в диспетчере устройств. Используйте порты от `1` до `9`, измените при необходимости его в свойствах устройства.
3738
CenteringKey | Код кнопки центрирования изображения, изменить кнопку можно в файле конфигурации, вписав [нужный код кнопки](https://github.com/r57zone/Half-Life-Alyx-novr/blob/master/BINDINGS.RU.md#%D0%BA%D0%BE%D0%B4%D1%8B)).
3839
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) можно приседать.
3940
CrouchOffset | Высота приседания по нажатию кнопки.
@@ -46,16 +47,17 @@ displayFrequency | Частота обновления экрана.
4647
renderWidth, renderHeight | Разрешение рендера изображения для одного глаза.
4748
windowWidth, windowHeight | Высота и ширина выводимого окна.
4849
windowX, windowY | Смещение окна, требуется для отображения на других мониторах (расширенных). Например, для отображения на втором дисплее, который отображается справа, нужно указать значение 1920 (при условии, что первый дисплей имеет разрешение 1920 на 1080). Точные данные можно просмотреть, с помощью [MultiMonitorTool утилиты](https://www.nirsoft.net/utils/multi_monitor_tool.html), которая также может выключать и включить второй монитор, через bat-файл.
49-
DebugMode | Режим отладки, заблокирован на 30 FPS. Рекомендуется после проверки отключить (поставить false).
50+
DebugMode | Режим отладки, заблокирован на 30 FPS. Рекомендуется после проверки отключить (поставить `false`).
51+
ArduinoRequire | Требование подключенного Arduino, для запуска драйвера. Параметр необходим для быстрых тестов контроллеров, чтобы не подключать и одевать шлем для тестов. Для отключения измените на `false`.
5052

5153
## Горячие клавиши
5254
Название | Описание
5355
------------ | -------------
5456
Numpad 5, CTRL + ALT + R | Центрирование изображения.
5557
Page Up, Page Down | Подняться или опуститься.
5658
Numpad 8, 2, 4, 6 | Перемещение вперед, назад, влево, вправо.
57-
Numpad 1, 3 | Изменить Yaw (Рысканье).
58-
Numpad 7, 9 | Изменить Roll (Крен).
59+
Numpad 1, 3 | Изменить yaw (рысканье).
60+
Numpad 7, 9 | Изменить roll (крен).
5961
Numpad - | Сброс перемещений и поднятия.
6062

6163
## Известные проблемы

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@ There is a ready-made Arduino firmware for [MPU 6050 GY-521](http://ali.pub/2oy7
3030
![](https://user-images.githubusercontent.com/9499881/52521728-e200dc80-2c94-11e9-9628-68ea3ef3dacd.png)
3131

3232
The speed should be changed to `115200` if a different one is set by default.
33+
3334
## Configuration file options
3435
Name | Description
3536
------------ | -------------
36-
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.
37+
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.
3738
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)).
3839
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.
3940
CrouchOffset | The height of the crouch at the touch of a button.
@@ -46,16 +47,17 @@ displayFrequency | Screen refresh rate.
4647
renderWidth, renderHeight | Image rendering resolution for one eye.
4748
windowWidth, windowHeight | Height and width of the displayed window.
4849
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.
49-
DebugMode | Debug mode, locked at 30 FPS. After checking, it is recommended to set it to false (disable).
50+
DebugMode | Debug mode, locked at 30 FPS. After checking, it is recommended to set it to `false` (disable).
51+
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`.
5052

5153
## Hotkeys
5254
Name | Description
5355
------------ | -------------
5456
Numpad 5, CTRL + ALT + R | Centering the picture.
5557
Page Up, Page Down | Rise or decline.
5658
Numpad 8, 2, 4, 6 | Move forward, backward, left, right.
57-
Numpad 1, 3 | Change Yaw.
58-
Numpad 7, 9 | Change Roll.
59+
Numpad 1, 3 | Change yaw.
60+
Numpad 7, 9 | Change roll.
5961
Numpad - | Resetting movements and lifting.
6062

6163
## Known Issues

0 commit comments

Comments
 (0)