Skip to content

Commit d5d6051

Browse files
committed
Improvement: button names instead of codes
1 parent e896a9e commit d5d6051

File tree

3 files changed

+132
-7
lines changed

3 files changed

+132
-7
lines changed

OpenVR/samples/driver_arduinohmd/driver_arduinohmd.cpp

Lines changed: 129 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <vector>
99
#include <thread>
1010
#include <chrono>
11+
#include <algorithm>
1112

1213
#if defined( _WINDOWS )
1314
#include <windows.h>
@@ -83,8 +84,8 @@ static const char * const k_pch_arduinoHMD_DebugMode_Bool = "DebugMode";
8384
static const char * const k_pch_arduinoHMD_Section = "arduinohmd";
8485
static const char * const k_pch_arduinoHMD_ArduinoRequire_Bool = "ArduinoRequire";
8586
static const char * const k_pch_arduinoHMD_COM_port_Int32 = "COMPort";
86-
static const char * const k_pch_arduinoHMD_CenteringKey_Int32 = "CenteringKey";
87-
static const char * const k_pch_arduinoHMD_CrouchPressKey_Int32 = "CrouchPressKey";
87+
static const char * const k_pch_arduinoHMD_CenteringKey_String = "CenteringKey";
88+
static const char * const k_pch_arduinoHMD_CrouchPressKey_String = "CrouchPressKey";
8889
static const char * const k_pch_arduinoHMD_CrouchOffset_Float = "CrouchOffset";
8990

9091
HANDLE hSerial;
@@ -211,6 +212,126 @@ void ArduinoIMUStart() {
211212
}
212213
}
213214

215+
int KeyNameToKeyCode(std::string KeyName) {
216+
std::transform(KeyName.begin(), KeyName.end(), KeyName.begin(), ::toupper);
217+
218+
if (KeyName == "NONE") return 0;
219+
220+
else if (KeyName == "MOUSE-LEFT-BTN") return VK_LBUTTON;
221+
else if (KeyName == "MOUSE-RIGHT-BTN") return VK_RBUTTON;
222+
else if (KeyName == "MOUSE-MIDDLE-BTN") return VK_MBUTTON;
223+
else if (KeyName == "MOUSE-SIDE1-BTN") return VK_XBUTTON1;
224+
else if (KeyName == "MOUSE-SIDE2-BTN") return VK_XBUTTON2;
225+
226+
else if (KeyName == "ESCAPE") return VK_ESCAPE;
227+
else if (KeyName == "F1") return VK_F1;
228+
else if (KeyName == "F2") return VK_F2;
229+
else if (KeyName == "F3") return VK_F3;
230+
else if (KeyName == "F4") return VK_F4;
231+
else if (KeyName == "F5") return VK_F5;
232+
else if (KeyName == "F6") return VK_F6;
233+
else if (KeyName == "F7") return VK_F7;
234+
else if (KeyName == "F8") return VK_F8;
235+
else if (KeyName == "F9") return VK_F9;
236+
else if (KeyName == "F10") return VK_F10;
237+
else if (KeyName == "F11") return VK_F11;
238+
else if (KeyName == "F12") return VK_F12;
239+
240+
else if (KeyName == "~") return 192;
241+
else if (KeyName == "1") return '1';
242+
else if (KeyName == "2") return '2';
243+
else if (KeyName == "3") return '3';
244+
else if (KeyName == "4") return '4';
245+
else if (KeyName == "5") return '5';
246+
else if (KeyName == "6") return '6';
247+
else if (KeyName == "7") return '7';
248+
else if (KeyName == "8") return '8';
249+
else if (KeyName == "9") return '9';
250+
else if (KeyName == "0") return '0';
251+
else if (KeyName == "-") return 189;
252+
else if (KeyName == "=") return 187;
253+
254+
else if (KeyName == "TAB") return VK_TAB;
255+
else if (KeyName == "CAPS-LOCK") return VK_CAPITAL;
256+
else if (KeyName == "SHIFT") return VK_SHIFT;
257+
else if (KeyName == "CTRL") return VK_CONTROL;
258+
else if (KeyName == "WIN") return VK_LWIN;
259+
else if (KeyName == "ALT") return VK_MENU;
260+
else if (KeyName == "SPACE") return VK_SPACE;
261+
else if (KeyName == "ENTER") return VK_RETURN;
262+
else if (KeyName == "BACKSPACE") return VK_BACK;
263+
264+
else if (KeyName == "Q") return 'Q';
265+
else if (KeyName == "W") return 'W';
266+
else if (KeyName == "E") return 'E';
267+
else if (KeyName == "R") return 'R';
268+
else if (KeyName == "T") return 'T';
269+
else if (KeyName == "Y") return 'Y';
270+
else if (KeyName == "U") return 'U';
271+
else if (KeyName == "I") return 'I';
272+
else if (KeyName == "O") return 'O';
273+
else if (KeyName == "P") return 'P';
274+
else if (KeyName == "[") return '[';
275+
else if (KeyName == "]") return ']';
276+
else if (KeyName == "A") return 'A';
277+
else if (KeyName == "S") return 'S';
278+
else if (KeyName == "D") return 'D';
279+
else if (KeyName == "F") return 'F';
280+
else if (KeyName == "G") return 'G';
281+
else if (KeyName == "H") return 'H';
282+
else if (KeyName == "J") return 'J';
283+
else if (KeyName == "K") return 'K';
284+
else if (KeyName == "L") return 'L';
285+
else if (KeyName == ";") return 186;
286+
else if (KeyName == "'") return 222;
287+
else if (KeyName == "\\") return 220;
288+
else if (KeyName == "Z") return 'Z';
289+
else if (KeyName == "X") return 'X';
290+
else if (KeyName == "C") return 'C';
291+
else if (KeyName == "V") return 'V';
292+
else if (KeyName == "B") return 'B';
293+
else if (KeyName == "N") return 'N';
294+
else if (KeyName == "M") return 'M';
295+
else if (KeyName == "<") return 188;
296+
else if (KeyName == ">") return 190;
297+
else if (KeyName == "?") return 191;
298+
299+
else if (KeyName == "PRINTSCREEN") return VK_SNAPSHOT;
300+
else if (KeyName == "SCROLL-LOCK") return VK_SCROLL;
301+
else if (KeyName == "PAUSE") return VK_PAUSE;
302+
else if (KeyName == "INSERT") return VK_INSERT;
303+
else if (KeyName == "HOME") return VK_HOME;
304+
else if (KeyName == "PAGE-UP") return VK_NEXT;
305+
else if (KeyName == "DELETE") return VK_DELETE;
306+
else if (KeyName == "END") return VK_END;
307+
else if (KeyName == "PAGE-DOWN") return VK_PRIOR;
308+
309+
else if (KeyName == "UP") return VK_UP;
310+
else if (KeyName == "DOWN") return VK_DOWN;
311+
else if (KeyName == "LEFT") return VK_LEFT;
312+
else if (KeyName == "RIGHT") return VK_RIGHT;
313+
314+
else if (KeyName == "NUM-LOCK") return VK_NUMLOCK;
315+
else if (KeyName == "NUMPAD0") return VK_NUMPAD0;
316+
else if (KeyName == "NUMPAD1") return VK_NUMPAD1;
317+
else if (KeyName == "NUMPAD2") return VK_NUMPAD2;
318+
else if (KeyName == "NUMPAD3") return VK_NUMPAD3;
319+
else if (KeyName == "NUMPAD4") return VK_NUMPAD4;
320+
else if (KeyName == "NUMPAD5") return VK_NUMPAD5;
321+
else if (KeyName == "NUMPAD6") return VK_NUMPAD6;
322+
else if (KeyName == "NUMPAD7") return VK_NUMPAD7;
323+
else if (KeyName == "NUMPAD8") return VK_NUMPAD8;
324+
else if (KeyName == "NUMPAD9") return VK_NUMPAD9;
325+
326+
else if (KeyName == "NUMPAD-DIVIDE") return VK_DIVIDE;
327+
else if (KeyName == "NUMPAD-MULTIPLY") return VK_MULTIPLY;
328+
else if (KeyName == "NUMPAD-MINUS") return VK_SUBTRACT;
329+
else if (KeyName == "NUMPAD-PLUS") return VK_ADD;
330+
else if (KeyName == "NUMPAD-DEL") return VK_DECIMAL;
331+
332+
else return 0;
333+
}
334+
214335
//-----------------------------------------------------------------------------
215336
// Purpose:
216337
//-----------------------------------------------------------------------------
@@ -251,9 +372,13 @@ class CDeviceDriver : public vr::ITrackedDeviceServerDriver, public vr::IVRDispl
251372
m_bStereoMode = vr::VRSettings()->GetBool(k_pch_steamvr_Section, k_pch_arduinoHMD_Stereo_Bool);
252373
m_bDebugMode = vr::VRSettings()->GetBool(k_pch_steamvr_Section, k_pch_arduinoHMD_DebugMode_Bool);
253374

254-
m_centeringKey = vr::VRSettings()->GetInt32(k_pch_arduinoHMD_Section, k_pch_arduinoHMD_CenteringKey_Int32);
375+
vr::VRSettings()->GetString(k_pch_steamvr_Section, k_pch_arduinoHMD_CenteringKey_String, buf, sizeof(buf));
376+
m_centeringKey = KeyNameToKeyCode(buf);
377+
378+
vr::VRSettings()->GetString(k_pch_steamvr_Section, k_pch_arduinoHMD_CrouchPressKey_String, buf, sizeof(buf));
379+
m_crouchPressKey = KeyNameToKeyCode(buf);
380+
255381
m_crouchOffset = vr::VRSettings()->GetFloat(k_pch_arduinoHMD_Section, k_pch_arduinoHMD_CrouchOffset_Float);
256-
m_crouchPressKey = vr::VRSettings()->GetInt32(k_pch_arduinoHMD_Section, k_pch_arduinoHMD_CrouchPressKey_Int32);
257382

258383
//DriverLog( "driver_arduinohmd: Serial Number: %s\n", m_sSerialNumber.c_str() );
259384
//DriverLog( "driver_arduinohmd: Model Number: %s\n", m_sModelNumber.c_str() );

README.RU.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
## Настройка
88
1. Подключите второй VR дисплей и установите расширенный режим в настройках мониторов.
99
2. Установите [SteamVR](https://store.steampowered.com/app/250820/SteamVR/).
10-
3. Распаковать драйвер в папку "...\Steam\steamapps\common\SteamVR\drivers". Настройте необходимые параметры (`windowX`, `windowY`, `windowWidth`, `windowHeight` и другие), в файле конфигурации "...\Steam\steamapps\common\SteamVR\drivers\arduinohmd\resources\settings\default.vrsettings".
10+
3. Распакуйте драйвер в папку "...\Steam\steamapps\common\SteamVR\drivers". Настройте необходимые параметры (`windowX`, `windowY`, `windowWidth`, `windowHeight` и другие), в файле конфигурации "...\Steam\steamapps\common\SteamVR\drivers\arduinohmd\resources\settings\default.vrsettings".
1111
4. Запустите SteamVR и окне статуса SteamVR нажать -> Настройки комнаты -> Маленькая комната -> Калибровка -> 170 см. SteamVR демонстрация может быть закрыта, а запуск SteamVR Home может быть отключен в настройках SteamVR.
12-
5. Наденьте шлем, при необходимости отцентрируйте его, с помощью клавиши (по умолчанию "Numpad 5" или "CTRL + ALT + R", изменить кнопку можно в файле конфигурации, вписав [нужный код кнопки](https://github.com/r57zone/Half-Life-Alyx-novr/blob/master/BINDINGS.RU.md#%D0%BA%D0%BE%D0%B4%D1%8B)).
12+
5. Наденьте шлем, при необходимости отцентрируйте его, с помощью клавиши (по умолчанию `Numpad 5` или `CTRL + ALT + R`, изменить кнопку можно в файле конфигурации, вписав [нужнное название кнопки](https://github.com/r57zone/DualShock4-emulator/blob/master/BINDINGS.RU.md)).
1313

1414
Если вы используете Android смартфон, то вероятно будет удобнее использовать [OpenTrack драйвер](https://github.com/r57zone/OpenVR-OpenTrack), там же можно прочитать инструкции о стриминге изображения на смартфон.
1515

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Driver for OpenVR / SteamVR, which allows to track the head, using any Arduino r
99
2. Install [SteamVR](https://store.steampowered.com/app/250820/SteamVR/).
1010
3. Unpack the driver to a folder "...\Steam\steamapps\common\SteamVR\drivers". Configure the necessary parameters (`windowX`, `windowY`, `windowWidth`, `windowHeight` and others), in the configuration file "...\Steam\steamapps\common\SteamVR\drivers\arduinohmd\resources\settings\default.vrsettings".
1111
4. Launch SteamVR and in the SteamVR status window click -> Room Settings -> Small Room -> Calibration -> 170 cm. The SteamVR demo can be closed, and the launch of SteamVR Home can be disabled in the SteamVR settings.
12-
5. Put on the HMD, if necessary, centering them with key (by default, "Numpad 5" or "CTRL + ALT + R", 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)).
12+
5. Put on the HMD, if necessary, centering them with key (by default, `Numpad 5` or `CTRL + ALT + R`, can change the key in the configuration file by typing [the desired key name](https://github.com/r57zone/DualShock4-emulator/blob/master/BINDINGS.md)).
1313

1414
If you are using an Android smartphone, then it will probably be easier to use [OpenTrack driver](https://github.com/r57zone/OpenVR-OpenTrack), there you can also read instructions about streaming images to your smartphone.
1515

0 commit comments

Comments
 (0)