Skip to content

Commit 9c9b638

Browse files
committed
HMD Assistant improvement: self enabled & disabled display voids and fixes
1 parent 39cf467 commit 9c9b638

File tree

3 files changed

+64
-18
lines changed

3 files changed

+64
-18
lines changed

HMDAssistant/Unit1.pas

Lines changed: 46 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ TMain = class(TForm)
6565
ConfigPath, EditorPath: string;
6666
HMDMonitor: integer;
6767
MaxResolution, MiddleResolution, LowResolution: string;
68-
ActivateExtendedMode, SetMaxResolution, CloneModeAfterTurnOff, CloseSteamVRAfterTurnOff: boolean;
68+
ActivateExtendedMode, SetMaxResolution, CloseSteamVRAfterTurnOff: boolean;
6969

7070
IDS_RUN, IDS_STOP, IDS_CHANGE_RES, ID_ABOUT_TITLE, ID_LAST_UPDATE: string;
7171

@@ -74,11 +74,47 @@ implementation
7474
{$R *.dfm}
7575

7676
const
77-
SDC_TOPOLOGY_CLONE = $00000002;
78-
SDC_TOPOLOGY_EXTEND = $00000004;
79-
SDC_APPLY = $00000080;
77+
SDC_TOPOLOGY_CLONE = $00000002;
78+
SDC_TOPOLOGY_EXTEND = $00000004;
79+
SDC_APPLY = $00000080;
80+
81+
EDD_GET_DEVICE_INTERFACE_NAME = 1;
82+
ENUM_REGISTRY_SETTINGS = DWORD(-2);
83+
8084
function SetDisplayConfig(numPathArrayElements: integer; pathArray: PDISPLAYCONFIG_PATH_INFO; numModeInfoArrayElements: integer; modeInfoArray: PDISPLAYCONFIG_MODE_INFO; flags: integer): longint; stdcall; external 'user32.dll'; // taken from https://github.com/CMCHTPC/WindowsAPI/blob/master/Units/Win32.WinUser.pas
8185

86+
procedure DisplayEnable(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 DisplayDisable(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+
82118
procedure Tray(ActInd: integer); //1 - Add, 2 - Update, 3 - Remove
83119
var
84120
NIM: TNotifyIconData;
@@ -139,7 +175,6 @@ procedure TMain.FormCreate(Sender: TObject);
139175
LowResBtn.Caption:=LowResolution;
140176
SetMaxResolution:=Ini.ReadBool('Main', 'SetMaxResolution', false);
141177
ActivateExtendedMode:=Ini.ReadBool('Main', 'ActivateExtendedMode', false);
142-
CloneModeAfterTurnOff:=Ini.ReadBool('Main', 'CloneModeAfterTurnOff', false);
143178
CloseSteamVRAfterTurnOff:=Ini.ReadBool('Main', 'CloseSteamVRAfterTurnOff', true);
144179
Ini.Free;
145180
WM_TASKBARCREATED:=RegisterWindowMessage('TaskbarCreated');
@@ -207,17 +242,17 @@ procedure TMain.RunStopBtnClick(Sender: TObject);
207242
if EnabledIcon = false then begin
208243
EnabledIcon:=true;
209244
RunStopBtn.Caption:=IDS_STOP;
210-
ShellExecute(Handle, 'open', PChar(ExtractFilePath(ParamStr(0)) + 'MultiMonitorTool.exe'), PChar('/enable \\.\DISPLAY' + IntToStr(HMDMonitor)), nil, SW_HIDE);
245+
//ShellExecute(Handle, 'open', PChar(ExtractFilePath(ParamStr(0)) + 'MultiMonitorTool.exe'), PChar('/enable \\.\DISPLAY' + IntToStr(HMDMonitor)), nil, SW_HIDE);
246+
DisplayEnable(HMDMonitor - 1);
211247
if ActivateExtendedMode then
212248
ExtendedBtn.Click;
213249
if SetMaxResolution then
214250
ShellExecute(Handle, 'open', PChar(ExtractFilePath(ParamStr(0)) + 'MultiMonitorTool.exe'), PChar('/setmax \\.\DISPLAY' + IntToStr(HMDMonitor)), nil, SW_HIDE);
215251
end else begin
216252
EnabledIcon:=false;
217253
RunStopBtn.Caption:=IDS_RUN;
218-
if CloneModeAfterTurnOff then
219-
CloneBtn.Click;
220-
ShellExecute(Handle, 'open', PChar(ExtractFilePath(ParamStr(0)) + 'MultiMonitorTool.exe'), PChar('/disable \\.\DISPLAY' + IntToStr(HMDMonitor)), nil, SW_HIDE);
254+
DisplayDisable(HMDMonitor - 1);
255+
//ShellExecute(Handle, 'open', PChar(ExtractFilePath(ParamStr(0)) + 'MultiMonitorTool.exe'), PChar('/disable \\.\DISPLAY' + IntToStr(HMDMonitor)), nil, SW_HIDE);
221256
if CloseSteamVRAfterTurnOff then begin
222257
WinExec('taskkill /f /im vrserver.exe', SW_HIDE);
223258
WinExec('taskkill /f /im vrcompositor.exe', SW_HIDE);
@@ -293,8 +328,8 @@ procedure TMain.ExtendedBtnClick(Sender: TObject);
293328

294329
procedure TMain.AboutBtnClick(Sender: TObject);
295330
begin
296-
Application.MessageBox(PChar(Main.Caption + ' 1.2' + #13#10 +
297-
ID_LAST_UPDATE + ' 19.10.2022' + #13#10 +
331+
Application.MessageBox(PChar(Main.Caption + ' 1.3' + #13#10 +
332+
ID_LAST_UPDATE + ' 01.11.2022' + #13#10 +
298333
'https://r57zone.github.io' + #13#10 +
299334
'[email protected]'), PChar(ID_ABOUT_TITLE), MB_ICONINFORMATION);
300335
end;

OpenVR/samples/driver_arduinohmd/driver_arduinohmd.cpp

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,15 @@ class CDeviceDriver : public vr::ITrackedDeviceServerDriver, public vr::IVRDispl
380380

381381
m_crouchOffset = vr::VRSettings()->GetFloat(k_pch_arduinoHMD_Section, k_pch_arduinoHMD_CrouchOffset_Float);
382382

383+
vr::VRSettings()->GetString(k_pch_arduinoHMD_Section, "HMDUpKey", buf, sizeof(buf));
384+
m_hmdUpKey = KeyNameToKeyCode(buf);
385+
386+
vr::VRSettings()->GetString(k_pch_arduinoHMD_Section, "HMDDownKey", buf, sizeof(buf));
387+
m_hmdDownKey = KeyNameToKeyCode(buf);
388+
389+
vr::VRSettings()->GetString(k_pch_arduinoHMD_Section, "HMDResetKey", buf, sizeof(buf));
390+
m_hmdResetKey = KeyNameToKeyCode(buf);
391+
383392
//DriverLog( "driver_arduinohmd: Serial Number: %s\n", m_sSerialNumber.c_str() );
384393
//DriverLog( "driver_arduinohmd: Model Number: %s\n", m_sModelNumber.c_str() );
385394
//DriverLog( "driver_arduinohmd: Window: %d %d %d %d\n", m_nWindowX, m_nWindowY, m_nWindowWidth, m_nWindowHeight );
@@ -608,8 +617,8 @@ class CDeviceDriver : public vr::ITrackedDeviceServerDriver, public vr::IVRDispl
608617
if ((GetAsyncKeyState(VK_NUMPAD4) & 0x8000) != 0) fPos[0] -= StepPos;
609618
if ((GetAsyncKeyState(VK_NUMPAD6) & 0x8000) != 0) fPos[0] += StepPos;
610619

611-
if ((GetAsyncKeyState(VK_PRIOR) & 0x8000) != 0) fPos[1] += StepPos;
612-
if ((GetAsyncKeyState(VK_NEXT) & 0x8000) != 0) fPos[1] -= StepPos;
620+
if ((GetAsyncKeyState(m_hmdDownKey) & 0x8000) != 0) fPos[1] += StepPos;
621+
if ((GetAsyncKeyState(m_hmdUpKey) & 0x8000) != 0) fPos[1] -= StepPos;
613622

614623
// Yaw fixing
615624
if ((GetAsyncKeyState(VK_NUMPAD1) & 0x8000) != 0 && yprOffset[0] < 180) yprOffset[0] += StepRot;
@@ -619,7 +628,7 @@ class CDeviceDriver : public vr::ITrackedDeviceServerDriver, public vr::IVRDispl
619628
if ((GetAsyncKeyState(VK_NUMPAD7) & 0x8000) != 0 && yprOffset[2] < 180) yprOffset[2] += StepRot;
620629
if ((GetAsyncKeyState(VK_NUMPAD9) & 0x8000) != 0 && yprOffset[2] > -180) yprOffset[2] -= StepRot;
621630

622-
if ((GetAsyncKeyState(VK_SUBTRACT) & 0x8000) != 0)
631+
if ((GetAsyncKeyState(m_hmdResetKey) & 0x8000) != 0)
623632
{
624633
fPos[0] = 0;
625634
fPos[1] = 0;
@@ -637,11 +646,10 @@ class CDeviceDriver : public vr::ITrackedDeviceServerDriver, public vr::IVRDispl
637646

638647
//Set head position tracking
639648
pose.vecPosition[0] = fPos[0]; // X
649+
pose.vecPosition[1] = fPos[1]; // Z
640650

641651
if ((GetAsyncKeyState(m_crouchPressKey) & 0x8000) != 0)
642-
pose.vecPosition[1] = fPos[1] - m_crouchOffset; // Z
643-
else
644-
pose.vecPosition[1] = fPos[1]; // Z
652+
pose.vecPosition[1] -= m_crouchOffset;
645653

646654
pose.vecPosition[2] = fPos[2]; // Y
647655
}
@@ -693,6 +701,9 @@ class CDeviceDriver : public vr::ITrackedDeviceServerDriver, public vr::IVRDispl
693701
int32_t m_crouchPressKey;
694702
float m_crouchOffset;
695703
int32_t m_centeringKey;
704+
int32_t m_hmdUpKey;
705+
int32_t m_hmdDownKey;
706+
int32_t m_hmdResetKey;
696707
};
697708

698709
//-----------------------------------------------------------------------------

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Name | Description
3737
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.
3838
CenteringKey | The code of the picture centering key, you can change the key in the configuration file by typing [the desired name code](https://github.com/r57zone/DualShock4-emulator/blob/master/BINDINGS.md)).
3939
CrouchPressKey | The code of the crouch key, you can change the key in the configuration file by typing [the desired name code](https://github.com/r57zone/DualShock4-emulator/blob/master/BINDINGS.md)). 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.
40-
CrouchOffset | The height of the crouch at the touch of a button.
40+
CrouchOffset | The height of the crouch at the press of a button.
4141
DistanceBetweenEyes | The distance between stereo images, the larger the closer.
4242
DistortionK1, DistortionK2 | Lens distortion factors.
4343
ScreenOffsetX | Horizontal image shift.

0 commit comments

Comments
 (0)