WVR_TriggerTrackerVibration

WVR_EXPORT WVR_Result WVR_TriggerTrackerVibration(WVR_TrackerId trackerId, uint32_t durationMicroSec = 0, float frequency = 0.0f, float amplitude = 0.0f)

Function to trigger vibration with float amplitude of the tracker device.

Version
API Level 8
Parameters
  • trackerId: Indicates what id of the tracker device. (Refer to WVR_TrackerId.)
  • durationMicroSec: The duration of the vibration in microsecond.
  • frequency: The frequency of the vibration in Hz.
  • amplitude: float intensity of the vibration. Valid interval: [0.0, 1.0].
Return Value
  • WVR_Success: Trigger the vibration of the tracker device successfully.
  • Others: means failure. (Refer to WVR_Result.)

How to use

Here is an example for the function:

  1. Header & global variables.
#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 device capabilities of WVR_TrackerId_0
WVR_TrackerCapabilities_t gCapabilitiesId0;
  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 vibration feature (capability supportsHapticVibration) 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.supportsHapticVibration
}
  1. (Timing 2 - When receiving event WVR_EventType_TrackerConnected) Use function WVR_GetTrackerCapabilities to get tracker capabilities to check whether vibration feature (capability supportsHapticVibration) 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_TriggerTrackerVibration to trigger vibration of tracker device.
if (gRunningTR &&
    gCapabilitiesId0.supportsHapticVibration &&
    WVR_IsTrackerConnected(WVR_TrackerId_0)) {
    uint32_t duration = 1000000; // Microsecond
    float frequency = 1;
    float amplitude = 0.5f;
    WVR_Result ret = WVR_TriggerTrackerVibration(WVR_TrackerId_0, duration, frequency, amplitude);
}

Note

  1. This function works when capability supportsHapticVibration of tracker device is true.