Last active
August 22, 2019 03:28
-
-
Save ChristophHaag/8d2f7c3e5cecd34452520eb78268796a to your computer and use it in GitHub Desktop.
print right trigger button bState and bChanged
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// g++ actions.cpp -o actions -lopenvr_api | |
#include <stdio.h> | |
#include <openvr/openvr.h> | |
#include <chrono> | |
#include <thread> | |
using namespace vr; | |
void check_error(int line, EVRInitError error) { if (error != 0) printf("%d: error %s\n", line, VR_GetVRInitErrorAsSymbol(error)); } | |
void check_input_error(int line, EVRInputError error) { if (error != EVRInputError::VRInputError_None) { printf("Input error at %d: %d\n", line, error); exit (1); } } | |
int main(int argc, char **argv) { | |
if (argc < 2) { | |
printf("Usage:\n\t%s /path/to/actions.json", argv[0]); | |
return 1; | |
} | |
const char *manifest_path = argv[1]; | |
EVRInitError error; | |
VR_Init(&error, vr::VRApplication_Overlay); | |
check_error(__LINE__, error); | |
EVRInputError inputerr = VRInput()->SetActionManifestPath(manifest_path); | |
if (inputerr != EVRInputError::VRInputError_None) printf("Input error %d: %d\n", __LINE__, inputerr); | |
VRActionSetHandle_t set_handle = 0; | |
inputerr = VRInput()->GetActionSetHandle ("/actions/test", &set_handle); | |
check_input_error(__LINE__, inputerr); | |
VRActionHandle_t trigger_handle = 0; | |
inputerr = VRInput()->GetActionHandle ("/actions/test/in/trigger", &trigger_handle); | |
check_input_error(__LINE__, inputerr); | |
VRInputValueHandle_t right_hand_handle = 0; | |
inputerr =VRInput()->GetInputSourceHandle ("/user/hand/right", &right_hand_handle); | |
check_input_error(__LINE__, inputerr); | |
struct VRActiveActionSet_t active_action_set = {}; | |
active_action_set.ulActionSet = set_handle; | |
while (true) { | |
inputerr = VRInput()->UpdateActionState(&active_action_set, sizeof(active_action_set), 1); | |
check_input_error(__LINE__, inputerr); | |
InputDigitalActionData_t data; | |
inputerr = VRInput()->GetDigitalActionData (trigger_handle, &data, sizeof(data), right_hand_handle); | |
check_input_error(__LINE__, inputerr); | |
printf("Right Trigger State: %d, Changed: %d\n", data.bState, data.bChanged); | |
std::this_thread::sleep_for(std::chrono::milliseconds(100)); | |
} | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"default_bindings":[ | |
{ | |
"controller_type":"vive_controller", | |
"binding_url":"bindings_vive_controller.json" | |
}, | |
{ | |
"controller_type": "knuckles", | |
"binding_url": "bindings_vive_controller.json" | |
} | |
], | |
"actions":[ | |
{ | |
"name":"/actions/test/in/trigger", | |
"type":"boolean" | |
} | |
], | |
"action_sets": [ | |
{ | |
"name": "/actions/test", | |
"usage": "leftright" | |
} | |
], | |
"localization":[ | |
{ | |
"language_tag":"en_US", | |
"/actions/test/in/trigger":"Trigger" | |
} | |
] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"bindings" : { | |
"/actions/test" : { | |
"sources" : [ | |
{ | |
"path": "/user/hand/right/input/trigger", | |
"mode": "button", | |
"inputs": { | |
"click": { | |
"output": "/actions/test/in/trigger" | |
} | |
} | |
} | |
] | |
} | |
}, | |
"controller_type": "vive_controller", | |
"description" : "Test bindings", | |
"name" : "Vive Controller" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment