WVR_GetTrackerInputTouchState

WVR_EXPORT bool WVR_GetTrackerInputTouchState(WVR_TrackerId trackerId, WVR_InputId inputId)

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

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

How to use

  • Here is an example for the function:
  1. Header & global variables.
    • The size 20 of array gButtonSupportTouchId0 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 gButtonSupportTouchId0[20] = {false}; // Supports touch/untouch 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_Touch) to check whether the button element supports touch & untouch features or not.
if (gRunningTR &&
    gCapabilitiesId0.supportsInputDevice &&
    WVR_IsTrackerConnected(WVR_TrackerId_0)) {
    int32_t touchCap = 0;
    // Get the bit map of supporting touch & untouch features for all buttons.
    touchCap = WVR_GetTrackerInputDeviceCapability(WVR_TrackerId_0, WVR_InputType_Touch);

    int32_t triggerBit17Value = 1 << 17;
    if (touchCap & triggerBit17Value) {
        // Trigger supports touch & untouch features
        gButtonSupportTouchId0[WVR_InputId_Alias1_Trigger] = 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_GetTrackerInputTouchState to actively get current touched / untouched 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) &&
    gButtonSupportTouchId0[WVR_InputId_Alias1_Trigger]) {
    // Check Trigger button remains touched(true) or untouched(false) currently.
    bool touched = WVR_GetTrackerInputTouchState(WVR_TrackerId_0, WVR_InputId_Alias1_Trigger);
}

Tracker Button Events

  • There are four tracker button events (which will 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 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_TrackerTouchUntapped) {
            LOGI("The button %d of tracker %d has just been untouched.", event.input.inputId, event.tracker.trackerId);
        }
    }
}