Skip to content

Commit cd34c7b

Browse files
committed
Added auto enable and disable VR display
1 parent 084cc94 commit cd34c7b

File tree

6 files changed

+108
-14
lines changed

6 files changed

+108
-14
lines changed

Library/README.RU.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ qW, qX, qY, qZ - кватернион.<br>
5151
Параметр **"ScreenIndex"** отвечает за номер дисплея. Например, 1 это основной дисплей, а 2 это VR шлем.
5252

5353

54+
Параметр **"ScreenControl"** отвечает за автоматическое включение и отключения VR дисплея. Включение опции - 1, выключение - 0.
55+
56+
5457
Параметр **"Scale"** отвечает за маштабирование изображения. Если параметр имеет значение "True", то изображение с длинной "UserWidth" и высотой "UserHeight" растягивается на весь дисплей "ScreenIndex".
5558
Если параметр имеет значение "False", то изображение не маштабируется и отображается в центре окна, пустые области окна имеют черный фон. Параметр необходим для устранения слепых зон в VR шлеме.
5659

Library/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ All parameters are in the registry branch **"HKEY_CURRENT_USER\Software\TrueOpen
5151
The **"ScreenIndex"** parameter is responsible for the display number. For example, 1 is the main display, and 2 is the VR headset.
5252

5353

54+
The **"ScreenControl"** parameter is responsible for the auto enable and disable VR display. Enable option - 1, disable - 0.
55+
56+
5457
The **"Scale"** parameter is responsible for scaling the image. If the parameter is set to "True", then the image with width "UserWidth" and height of "UserHeight" is stretched to the entire display "ScreenIndex".
5558
If the parameter is set to "False", the image is not scaled and displayed in the center of the window, empty areas of the window have a black background. The parameter is necessary to eliminate blind areas in the VR headset.
5659

README.RU.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ TrueOpenVR -
1212

1313
- Для разработчиков драйверов VR устройств: [готовые и демострационные драйверы](https://github.com/TrueOpenVR/TrueOpenVR-Drivers).
1414

15-
- Присылайте ваши исправления, патчи, демонстрационные примеры и так далее.
15+
- Присылайте ваши исправления, патчи, демонстрационные примеры, переводы и так далее.
1616

1717
- Пишите ваши предложения или запросы новой функциональности через "Issue" или почту.
1818

@@ -28,15 +28,14 @@ TrueOpenVR -
2828
- Поддержка самодельных VR устройств.
2929

3030
## Планы на будущее:
31-
- Включение и выключение VR дисплея шлема, при открытии и закрытии TOVR приложения (опционально).
3231

3332
- Создание быстрого VR плеера, VR просмотрщика фотографий и демонстрационной VR игры.
3433

35-
- Поддержка VR шлемов (Oculus DK1, DK2, CV1, PS VR, HTC Vive, OSVR HDK и так далее).
34+
- Поддержка VR шлемов (PS VR, Oculus CV1, DK1, DK2, OSVR HDK, HTC Vive и так далее).
3635

3736
- Поддержка трекеров (Aruco Paper, Point tracker и так далее) для самодельных VR шлемов.
3837

39-
- Поддержка контроллеров (Razer Hydra, PS Move, Oculus, HTC Vive, Nolo, Daydream, Gear), а также разработка и поддержка "бумажного" контроллера (веб-камера + Aruco маркеры + Arduino или веб-камера + Aruco marker + Daydream).
38+
- Поддержка контроллеров (Razer Hydra, PS Move, Oculus, Nolo, HTC Vive, Daydream, Gear VR), а также разработка и поддержка "бумажного" контроллера (веб-камера + Aruco маркеры + Arduino или веб-камера + Aruco marker + Daydream).
4039

4140
## Загрузка
4241
>Версия для Windows 7, 8.1, 10

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ TrueOpenVR is an open VR standard, made in accordance with the concept of "Plug
1212

1313
- For developers drivers for VR devices: [sample and ready drivers](https://github.com/TrueOpenVR/TrueOpenVR-Drivers).
1414

15-
- Send your fixes, patches, samples, demos or etc.
15+
- Send your fixes, patches, samples, demos, translations or etc.
1616

1717
- Write your proposals or feature requests through "Issue" or email.
1818

@@ -28,15 +28,14 @@ TrueOpenVR is an open VR standard, made in accordance with the concept of "Plug
2828
- Support for DIY VR devices.
2929

3030
## Future plans:
31-
- Turn on and off VR headset display, when opening and closing the TOVR application (optional).
3231

3332
- Create a fast VR player, VR photo viewer and VR game demo.
3433

35-
- Support VR headsets (Oculus DK1, DK2, CV1, PS VR, HTC Vive, OSVR HDK and etc).
34+
- Support VR headsets (PS VR, Oculus CV1, DK1, DK2, OSVR HDK, HTC Vive and etc).
3635

3736
- Trackers support (Aruco Paper, Point tracker and etc) for DIY VR headset.
3837

39-
- Support controllers (Razer Hydra, PS Move, Oculus, HTC Vive, Nolo, Daydream, Gear), and the development and support of a "paper" controller (webcam + Aruco markers + Arduino or webcam + Aruco marker + Daydream).
38+
- Support controllers (Razer Hydra, PS Move, Oculus, Nolo, HTC Vive, Daydream, Gear VR), development and support of a "paper" controller (webcam + Aruco markers + Arduino or webcam + Aruco marker + Daydream).
4039

4140
## Download
4241
>Version for Windows 7, 8.1, 10

TOVR/C++/TOVR/TOVR.cpp

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,43 @@ DLLEXPORT DWORD __stdcall SetControllerData(__in INT dwIndex, __in DWORD MotorSp
4646
DLLEXPORT DWORD __stdcall SetCentering(__in int dwIndex);
4747

4848
HMODULE hDll;
49+
DWORD ScreenIndex;
50+
DWORD ScreenControl;
4951

50-
void DriverAttach() {
52+
void ScreenEnable(int dwIndex)
53+
{
54+
DISPLAY_DEVICE Display;
55+
DEVMODE DevMode;
56+
57+
Display.cb = sizeof(DISPLAY_DEVICE);
58+
EnumDisplayDevices(NULL, dwIndex, &Display, EDD_GET_DEVICE_INTERFACE_NAME);
59+
EnumDisplaySettings((LPCSTR)Display.DeviceName, ENUM_REGISTRY_SETTINGS, &DevMode);
60+
DevMode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFREQUENCY | DM_DISPLAYFLAGS | DM_POSITION;
61+
if (!(Display.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE)) {
62+
ChangeDisplaySettingsEx((LPCSTR)Display.DeviceName, &DevMode, 0, CDS_UPDATEREGISTRY | CDS_NORESET, NULL);
63+
ChangeDisplaySettingsEx(NULL, NULL, NULL, NULL, NULL);
64+
}
65+
}
66+
67+
68+
void ScreenDisable(int dwIndex)
69+
{
70+
DISPLAY_DEVICE Display;
71+
DEVMODE DevMode;
72+
ZeroMemory(&DevMode, sizeof(DEVMODE));
73+
74+
Display.cb = sizeof(DISPLAY_DEVICE);
75+
DevMode.dmSize = sizeof(DEVMODE);
76+
DevMode.dmBitsPerPel = 32;
77+
DevMode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFREQUENCY | DM_DISPLAYFLAGS | DM_POSITION;
78+
EnumDisplayDevices(NULL, dwIndex, &Display, EDD_GET_DEVICE_INTERFACE_NAME);
79+
if (!(Display.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE)) {
80+
ChangeDisplaySettingsEx((LPCSTR)Display.DeviceName, &DevMode, 0, CDS_UPDATEREGISTRY | CDS_NORESET, NULL);
81+
ChangeDisplaySettingsEx(NULL, NULL, NULL, NULL, NULL);
82+
}
83+
}
84+
85+
void Init() {
5186
CRegKey key;
5287
TCHAR _driversPath[MAX_PATH];
5388
TCHAR _driverName[MAX_PATH];
@@ -63,6 +98,10 @@ void DriverAttach() {
6398
regSize = sizeof(_driversPath);
6499
status = key.QueryStringValue(_T("Drivers"), _driversPath, &regSize);
65100
}
101+
102+
key.QueryDWORDValue(_T("ScreenControl"), ScreenControl);
103+
key.QueryDWORDValue(_T("ScreenIndex"), ScreenIndex);
104+
ScreenIndex -= 1;
66105
}
67106
key.Close();
68107

@@ -80,6 +119,9 @@ void DriverAttach() {
80119
DriverGetControllersData = (_GetControllersData)GetProcAddress(hDll, "GetControllersData");
81120
DriverSetControllerData = (_SetControllerData)GetProcAddress(hDll, "SetControllerData");
82121
DriverSetCentering = (_SetCentering)GetProcAddress(hDll, "SetCentering");
122+
123+
if (ScreenControl == TRUE)
124+
ScreenEnable(ScreenIndex);
83125
}
84126
}
85127
}
@@ -90,14 +132,16 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReser
90132
switch (ul_reason_for_call)
91133
{
92134
case DLL_PROCESS_ATTACH: {
93-
DriverAttach();
135+
Init();
94136
break;
95137
}
96138

97139
case DLL_PROCESS_DETACH: {
98140
if (hDll != NULL) {
99141
FreeLibrary(hDll);
100142
hDll = nullptr;
143+
if (ScreenControl == TRUE)
144+
ScreenDisable(ScreenIndex);
101145
}
102146
break;
103147
}

TOVR/Delphi/TOVR.dpr

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ end;
3636

3737
var
3838
DriverPath: string;
39+
ScreenIndex: integer;
40+
ScreenControl: boolean;
3941
DllHandle: HMODULE;
4042

4143
DriverGetHMDData: function(out myHMD: THMD): DWORD; stdcall;
@@ -77,7 +79,43 @@ begin
7779
Result:=0;
7880
end;
7981

80-
procedure GetDriverPath;
82+
const
83+
EDD_GET_DEVICE_INTERFACE_NAME = 1;
84+
ENUM_REGISTRY_SETTINGS = DWORD(-2);
85+
86+
procedure ScreenEnable(dwIndex: integer);
87+
var
88+
Display: TDisplayDevice;
89+
DevMode: TDevMode;
90+
begin
91+
Display.cb:=SizeOf(TDisplayDevice);
92+
EnumDisplayDevices(nil, dwIndex, Display, EDD_GET_DEVICE_INTERFACE_NAME);
93+
EnumDisplaySettings(PChar(@Display.DeviceName[0]), ENUM_REGISTRY_SETTINGS, DevMode);
94+
DevMode.dmFields:=DM_BITSPERPEL or DM_PELSWIDTH or DM_PELSHEIGHT or DM_DISPLAYFREQUENCY or DM_DISPLAYFLAGS or DM_POSITION;
95+
if (Display.StateFlags and DISPLAY_DEVICE_PRIMARY_DEVICE) <> DISPLAY_DEVICE_PRIMARY_DEVICE then begin
96+
ChangeDisplaySettingsEx(PChar(@Display.DeviceName[0]), DevMode, 0, CDS_UPDATEREGISTRY or CDS_NORESET, nil);
97+
ChangeDisplaySettingsEx(nil, PDevMode(nil)^, 0, 0, nil);
98+
end;
99+
end;
100+
101+
procedure ScreenDisable(dwIndex: integer);
102+
var
103+
Display: TDisplayDevice;
104+
DevMode: TDevMode;
105+
begin
106+
Display.cb:=SizeOf(TDisplayDevice);
107+
EnumDisplayDevices(nil, dwIndex, Display, EDD_GET_DEVICE_INTERFACE_NAME);
108+
ZeroMemory(@DevMode, SizeOf(TDevMode));
109+
DevMode.dmSize:=SizeOf(TDevMode);
110+
DevMode.dmBitsPerPel:=32;
111+
DevMode.dmFields:=DM_BITSPERPEL or DM_PELSWIDTH or DM_PELSHEIGHT or DM_DISPLAYFREQUENCY or DM_DISPLAYFLAGS or DM_POSITION;
112+
if (Display.StateFlags and DISPLAY_DEVICE_PRIMARY_DEVICE) <> DISPLAY_DEVICE_PRIMARY_DEVICE then begin
113+
ChangeDisplaySettingsEx(PChar(@Display.DeviceName[0]), DevMode, 0, CDS_UPDATEREGISTRY or CDS_NORESET, nil);
114+
ChangeDisplaySettingsEx(nil, PDevMode(nil)^, 0, 0, nil);
115+
end;
116+
end;
117+
118+
procedure GetRegValues;
81119
var
82120
Reg: TRegistry;
83121
begin
@@ -87,7 +125,9 @@ begin
87125
if FileExists(Reg.ReadString('Drivers') + Reg.ReadString('Driver')) then
88126
DriverPath:=Reg.ReadString('Drivers') + Reg.ReadString('Driver')
89127
else
90-
DriverPath:='';
128+
DriverPath:='';
129+
ScreenIndex:=Reg.ReadInteger('ScreenIndex') - 1;
130+
ScreenControl:=Reg.ReadBool('ScreenControl');
91131
end;
92132
Reg.CloseKey;
93133
Reg.Free;
@@ -98,18 +138,24 @@ begin
98138
case Reason of
99139
DLL_PROCESS_ATTACH:
100140
begin
101-
GetDriverPath;
141+
GetRegValues;
102142
if DriverPath <> '' then begin
103143
DllHandle:=LoadLibrary(PChar(DriverPath));
104144
@DriverGetHMDData:=GetProcAddress(DllHandle, 'GetHMDData');
105145
@DriverGetControllersData:=GetProcAddress(DllHandle, 'GetControllersData');
106146
@DriverSetControllerData:=GetProcAddress(DllHandle, 'SetControllerData');
107147
@DriverSetCentering:=GetProcAddress(DllHandle, 'SetCentering');
148+
if (ScreenControl) and (ScreenIndex <> 0) then
149+
ScreenEnable(ScreenIndex);
108150
end;
109151
end;
110152

111153
DLL_PROCESS_DETACH:
112-
FreeLibrary(DllHandle);
154+
if DllHandle <> 0 then begin
155+
FreeLibrary(DllHandle);
156+
if (ScreenControl) and (ScreenIndex <> 0) then
157+
ScreenDisable(ScreenIndex);
158+
end;
113159
end;
114160
end;
115161

0 commit comments

Comments
 (0)