WVR_GetTrackerInputButtonState

WVR_EXPORT bool WVR_GetTrackerInputButtonState(WVR_TrackerId trackerId, WVR_InputId inputId)

Function to get the button state of a specific input id of the tracker device.

Return
bool, true for pressed and false means unpressed.
Version
API Level 8
Parameters
  • trackerId: Indicates what id of the tracker device. (Refer to WVR_TrackerId.)
  • inputId: One of WVR_InputId. Indicates which button is pressed or unpressed.

How to use

  • Here is an example for the function:
  1. Header & global variables.
    • The size 20 of array gButtonSupportPressId0 is based on button definition (enum WVR_InputId on Types in wvr.h).
#include <wvr/wvr.h> // for enum WVR_SupportedFeature
#include <wvr/wvr_events.h>
#include <wvr/wvr_tracker.h>
#include <wvr/wvr_types.h>

bool gRunningTR = false;

// Global variables for WVR_TrackerId_0
WVR_TrackerCapabilities_t gCapabilitiesId0; // device capabilities
bool gButtonSupportPressId0[20] = {false}; // Supports press/unpress feature or not for all 20 buttons
  1. Start tracker feature first if it has not been started yet. (See also WVR Supported Features)
    • And (Timing 1 - After starting tracker feature successfully) use function WVR_GetTrackerCapabilities to get tracker capabilities to check whether button feature (capability supportsInputDevice) is supported or not.
if (WVR_GetSupportedFeatures() & WVR_SupportedFeature_Tracker) { // the tracker feature is supported or not
    WVR_Result res = WVR_StartTracker();
    if (res == WVR_Success) gRunningTR = true;
}

// Timing 1: Update the tracker capabilities after WVR_StartTracker for the tracker device which has been connected before.
if (gRunningTR && WVR_IsTrackerConnected(WVR_TrackerId_0)) {
    WVR_Result ret = WVR_GetTrackerCapabilities(WVR_TrackerId_0, &gCapabilitiesId0);
    // Needs gCapabilitiesId0.supportsInputDevice
}
  1. (Timing 2 - When receiving event WVR_EventType_TrackerConnected) Use function WVR_GetTrackerCapabilities to get tracker capabilities to check whether button feature (capability supportsInputDevice) is supported or not.
void ProcessEvent() {
    WVR_Event_t event;
    while(WVR_PollEventQueue(&event)) {
        switch (event.common.type) {
            /* Timing 2: Update tracker capabilities when tracker device has just been connected.*/
            case WVR_EventType_TrackerConnected:
                {
                    if (gRunningTR && event.tracker.trackerId == WVR_TrackerId_0) {
                        WVR_Result ret = WVR_GetTrackerCapabilities(event.tracker.trackerId, &gCapabilitiesId0);
                        LOGI("TrackerId_%d, capabilities(ret: %d): %d, %d, %d, %d, %d, %d",
                            event.tracker.trackerId, ret,
                            gCapabilitiesId0.supportsOrientationTracking,
                            gCapabilitiesId0.supportsPositionTracking,
                            gCapabilitiesId0.supportsInputDevice,
                            gCapabilitiesId0.supportsHapticVibration,
                            gCapabilitiesId0.supportsBatteryLevel,
                            gCapabilitiesId0.supportsExtendedData);
                    }
                }
                break;
            default:
                break;
        }
    }
}
  1. Use function WVR_GetTrackerInputDeviceCapability (with parameter WVR_InputType_Button) to check whether the button element supports press & unpress features or not.
if (gRunningTR &&
    gCapabilitiesId0.supportsInputDevice &&
    WVR_IsTrackerConnected(WVR_TrackerId_0)) {
    int32_t clickCap = 0;
    // 1. Get the bit map of supporting press & unpress features for all buttons.
    clickCap = WVR_GetTrackerInputDeviceCapability(WVR_TrackerId_0, WVR_InputType_Button);

    int32_t menuBit1Value = 1 << 1;
    if (clickCap & menuBit1Value) {
        // Menu button supports press & unpress features
        gButtonSupportPressId0[WVR_InputId_Alias1_Menu] = true;
    }
}

/*
Button                               bitMap  bitValue
-----------------------------------------------------
WVR_InputId_Alias1_System            0       1
WVR_InputId_Alias1_Menu              1       1 << 1
WVR_InputId_Alias1_Grip              2       1 << 2
WVR_InputId_Alias1_DPad_Left         3       1 << 3
WVR_InputId_Alias1_DPad_Up           4       1 << 4
WVR_InputId_Alias1_DPad_Right        5       1 << 5
WVR_InputId_Alias1_DPad_Down         6       1 << 6
WVR_InputId_Alias1_Volume_Up         7       1 << 7
WVR_InputId_Alias1_Volume_Down       8       1 << 8
WVR_InputId_Alias1_Bumper            9       1 << 9
WVR_InputId_Alias1_A                 10      1 << 10
WVR_InputId_Alias1_B                 11      1 << 11
WVR_InputId_Alias1_X                 12      1 << 12
WVR_InputId_Alias1_Y                 13      1 << 13
WVR_InputId_Alias1_Back              14      1 << 14
WVR_InputId_Alias1_Enter             15      1 << 15
WVR_InputId_Alias1_Touchpad          16      1 << 16
WVR_InputId_Alias1_Trigger           17      1 << 17
WVR_InputId_Alias1_Thumbstick        18      1 << 18
WVR_InputId_Alias1_Parking           19      1 << 19
*/
  1. Use function WVR_GetTrackerInputButtonState to actively get current pressed / unpressed state of button.

Note

  1. This function works when capability supportsInputDevice of tracker device is true.
if (gRunningTR &&
    gCapabilitiesId0.supportsInputDevice &&
    WVR_IsTrackerConnected(WVR_TrackerId_0) &&
    gButtonSupportPressId0[WVR_InputId_Alias1_Menu]) {
    // Check Menu button remains pressed(true) or unpressed(false) currently.
    bool pressed = WVR_GetTrackerInputButtonState(WVR_TrackerId_0, WVR_InputId_Alias1_Menu);
}

Tracker Button Events

  • There are four tracker button events (which can be passively received on app side) for button feature.
    • WVR_EventType_TrackerButtonPressed
    • WVR_EventType_TrackerButtonUnpressed
    • WVR_EventType_TrackerTouchTapped
    • WVR_EventType_TrackerTouchUntapped
  1. If the button supports press & unpress features, these four events would be recieved on app side. In general, the buttons which support press & unpress features will also include touch & untouch events. (See also WVR_GetTrackerInputDeviceCapability with parameter WVR_InputType_Button)

    • When user presses the button, the following two events would be passively recieved by order on app side.

      • Recieves WVR_EventType_TrackerTouchTapped first.
      • Then recieves WVR_EventType_TrackerButtonPressed.
    • When user unpresses the button, the following two events would be passively recieved by order on app side.

      • Recieves WVR_EventType_TrackerButtonUnpressed first.
      • Then recieves WVR_EventType_TrackerTouchUntapped.
  2. If the button supports analog data feature (like touchpad, trigger, thumbstick) or only touch & untouch features (like parking), the touched / untouched event would be recieved independently (without pressed / unpressed event). (See also WVR_GetTrackerInputDeviceCapability with parameter WVR_InputType_Analog & WVR_InputType_Touch)

    • When user touches the button, event WVR_EventType_TrackerTouchTapped would be passively recieved on app side.
    • When user untouches the button, event WVR_EventType_TrackerTouchUntapped would be passively recieved on app side.
void ProcessEvent() {
    WVR_Event_t event;
    while(WVR_PollEventQueue(&event)) {
        if(event.common.type == WVR_EventType_TrackerTouchTapped) {
            LOGI("The button %d of tracker %d has just been touched.", event.input.inputId, event.tracker.trackerId);
        }

        if(event.common.type == WVR_EventType_TrackerButtonPressed) {
            LOGI("The button %d of tracker %d has just been pressed.", event.input.inputId, event.tracker.trackerId);
        }

        if(event.common.type == WVR_EventType_TrackerButtonUnpressed) {
            LOGI("The button %d of tracker %d has just been unpressed.", event.input.inputId, event.tracker.trackerId);
        }

        if(event.common.type == WVR_EventType_TrackerTouchUntapped) {
            LOGI("The button %d of tracker %d has just been untouched.", event.input.inputId, event.tracker.trackerId);
        }
    }
}