diff --git a/IVRInput/action_manifest.json b/IVRInput/action_manifest.json new file mode 100644 index 0000000..7accc3a --- /dev/null +++ b/IVRInput/action_manifest.json @@ -0,0 +1,30 @@ +{ + "default_bindings": [ + { + "controller_type": "vive_controller", + "binding_url": "legacy_actions.json" + } + ], + "actions": [ + { + "name": "/actions/main/in/PlayNextTrack", + "requirement": "optional", + "type": "boolean" + } + ], + "action_sets": [ + { + "name": "/actions/main", + "usage": "leftright" + } + ], + "localization" : [ + { + "language_tag": "en", + + "/actions/main" : "My Game Actions", + + "/actions/main/in/PlayNextTrack" : "Play Next Track" + } + ] +} \ No newline at end of file diff --git a/IVRInput/legacy_actions.json b/IVRInput/legacy_actions.json new file mode 100644 index 0000000..3e2094c --- /dev/null +++ b/IVRInput/legacy_actions.json @@ -0,0 +1,42 @@ +{ + "alias_info" : {}, + "app_key" : "matzman666.advancedsettings", + "bindings" : { + "/actions/main" : { + "sources" : [ + { + "inputs" : { + "click" : { + "output" : "/actions/main/in/playnexttrack" + } + }, + "mode" : "button", + "path" : "/user/hand/left/input/application_menu" + }, + { + "inputs" : { + "click" : { + "output" : "/actions/main/in/playnexttrack" + } + }, + "mode" : "button", + "path" : "/user/hand/right/input/application_menu" + }, + { + "inputs" : { + "click" : { + "output" : "/actions/main/in/playnexttrack" + } + }, + "mode" : "button", + "path" : "/user/hand/right/input/grip" + } + ] + } + }, + "controller_type" : "vive_controller", + "description" : "", + "name" : "My My Test configuration for Vive Controller", + "options" : {}, + "simulated_actions" : [] +} diff --git a/advancedSettings.pro b/advancedSettings.pro index e9d529d..9ed0a57 100644 --- a/advancedSettings.pro +++ b/advancedSettings.pro @@ -58,8 +58,8 @@ SOURCES += src/main.cpp\ src/utils/ChaperoneUtils.cpp \ src/tabcontrollers/audiomanager/AudioManagerDummy.cpp \ src/tabcontrollers/keyboardinput/KeyboardInputDummy.cpp \ - src/overlaycontroller/openvr_init.cpp - + src/overlaycontroller/openvr_init.cpp \ + src/steamivrinput.cpp HEADERS += src/overlaycontroller.h \ src/tabcontrollers/AudioTabController.h \ @@ -79,7 +79,8 @@ HEADERS += src/overlaycontroller.h \ src/utils/ChaperoneUtils.h \ src/tabcontrollers/audiomanager/AudioManagerDummy.h \ src/tabcontrollers/keyboardinput/KeyboardInputDummy.h \ - src/overlaycontroller/openvr_init.h + src/overlaycontroller/openvr_init.h \ + src/steamivrinput.h win32 { SOURCES += src/tabcontrollers/audiomanager/AudioManagerWindows.cpp \ diff --git a/src/overlaycontroller.cpp b/src/overlaycontroller.cpp index b8cd84b..170cdba 100644 --- a/src/overlaycontroller.cpp +++ b/src/overlaycontroller.cpp @@ -118,7 +118,7 @@ OverlayController::OverlayController( bool desktopMode, nullptr, "OpenVR Advanced Settings Overlay", "Is OpenVR running?" ); throw std::runtime_error( std::string( "No Overlay interface" ) ); } - + m_actions.Init( false ); // Init controllers m_steamVRTabController.initStage1(); m_chaperoneTabController.initStage1(); @@ -477,6 +477,13 @@ void OverlayController::OnTimeoutPumpEvents() if ( !vr::VRSystem() ) return; + m_actions.Loop(); + + if ( m_actions.nextSongSet() ) + { + LOG( INFO ) << "NEXT SONG SET!"; + } + vr::VREvent_t vrEvent; bool chaperoneDataAlreadyUpdated = false; while ( pollNextEvent( m_ulOverlayHandle, &vrEvent ) ) diff --git a/src/overlaycontroller.h b/src/overlaycontroller.h index 9cefa65..9442b06 100644 --- a/src/overlaycontroller.h +++ b/src/overlaycontroller.h @@ -39,6 +39,8 @@ #include "tabcontrollers/UtilitiesTabController.h" #include "tabcontrollers/AccessibilityTabController.h" +#include "steamivrinput.h" + // application namespace namespace advsettings { @@ -90,6 +92,7 @@ private: public: // I know it's an ugly hack to make them public to enable external // access, but I am too lazy to implement getters. + SteamIVRInput m_actions; SteamVRTabController m_steamVRTabController; ChaperoneTabController m_chaperoneTabController; MoveCenterTabController m_moveCenterTabController; diff --git a/src/steamivrinput.cpp b/src/steamivrinput.cpp new file mode 100644 index 0000000..d8269dc --- /dev/null +++ b/src/steamivrinput.cpp @@ -0,0 +1,75 @@ +#include "steamivrinput.h" +#include +#include + +void SteamIVRInput::Init( const bool init ) +{ + if ( init ) + { + auto initError = vr::VRInitError_None; + vr::VR_Init( &initError, vr::VRApplication_Overlay ); + if ( initError != vr::VRInitError_None ) + { + std::cout << "SteamVR init error."; + } + } + + auto error + = vr::VRInput()->SetActionManifestPath( m_actionManifestPath.c_str() ); + if ( error != vr::EVRInputError::VRInputError_None ) + { + std::cout << "Action manifest error\n"; + } + + // Get action handle + error = vr::VRInput()->GetActionHandle( "/actions/main/in/PlayNextTrack", + &m_nextSongHandler ); + if ( error != vr::EVRInputError::VRInputError_None ) + { + std::cout << "Handle error.\n"; + } + + error = vr::VRInput()->GetActionSetHandle( "/actions/main", + &m_mainSetHandler ); + if ( error != vr::EVRInputError::VRInputError_None ) + { + std::cout << "Handle error.\n"; + } + + m_activeActionSet.ulActionSet = m_mainSetHandler; + m_activeActionSet.ulRestrictedToDevice = vr::k_ulInvalidInputValueHandle; + m_activeActionSet.nPriority = 0; +} + +bool SteamIVRInput::nextSongSet() +{ + auto e = vr::VRInput()->GetDigitalActionData( + m_nextSongHandler, + &m_nextSongData, + sizeof( m_nextSongData ), + vr::k_ulInvalidInputValueHandle ); + + if ( e != vr::EVRInputError::VRInputError_None ) + { + std::cout << e; + std::cout << "GetDigitalAction error.\n"; + } + + if ( m_nextSongData.bActive ) + { + std::cout << "Action Set Active!\n"; + } + + return m_nextSongData.bState; +} + +void SteamIVRInput::Loop() +{ + auto error = vr::VRInput()->UpdateActionState( + &m_activeActionSet, sizeof( m_activeActionSet ), 1 ); + + if ( error != vr::EVRInputError::VRInputError_None ) + { + std::cout << "Loop error.\n"; + } +} diff --git a/src/steamivrinput.h b/src/steamivrinput.h new file mode 100644 index 0000000..dea0dac --- /dev/null +++ b/src/steamivrinput.h @@ -0,0 +1,22 @@ +#ifndef STEAMIVRINPUT_H +#define STEAMIVRINPUT_H + +#include + +class SteamIVRInput +{ +public: + void Init( const bool init ); + void Loop(); + bool nextSongSet(); + +private: + const std::string m_actionManifestPath + = "YOUR_PATH_HERE\\action_manifest.json"; + vr::VRActionHandle_t m_nextSongHandler = {}; + vr::VRActionSetHandle_t m_mainSetHandler = {}; + vr::VRActiveActionSet_t m_activeActionSet = {}; + vr::InputDigitalActionData_t m_nextSongData = {}; +}; + +#endif // STEAMIVRINPUT_H