VRDevice

VRDevice provides a common interface for the device service of all devices. These are the basic functions defined in VRDevice.

List

Configure

setupConfig returns the device configuration data before it is connected. It provides the driver information to the DeviceService. Check VRDevice.Config.

@Override
public Config setupConfig() {
    Config configure = new Config();
    configure.trackingSystemName = "Mobile Emulator";
    return configure;
}
  • See Configure in Tracked Device to learn more about setupConfig of the tracked device.
  • See Configure in Head Mounted Display (HMD) to learn more about setupConfig of the HMD.
  • See Configure in Controller to learn more about setupConfig of the controller.

Note

This is an abstract function and must be implemented.

Configure List

Hardware Recenter Supported/Unsupported

Use containsRecenter to set up the “hardware (HW) recenter supported/unsupported” for the HMD and controller.

Set to true:
  • Device supports hardware (HW) recenter.
  • HW recenter procedure should be implemented in the function onRecenter() of the class TrackedDevice.
  • See Recenter in Tracked Device to learn more about the HW recenter procedure in onRecenter().
Set to false:
  • Device supports software (SW) recenter.
  • SW recenter procedure has already implemented in the app. Do nothing for SW recenter in the device service.

Set up “HW recenter supported/unsupported” for the HMD and controller by:

@Override
public Config setupConfig() {
    Config configure = new Config();
    // Set up "HW recenter supported/unsupported" for device
    // configure.containsRecenter = true; // Support HW recenter
    configure.containsRecenter = false; // Not support HW recenter, use SW recenter.
    return configure;
}

Tracking Mode

Use contains6Dof to set up the default “Tracking Mode of pose system” for the HMD and controller.

Set to true:
  • Device supports 6DoF tracking mode.
  • 6DoF tracking mode: Pose of the device includes position (x, y, z) on 3 coordinates and rotation (yaw, pitch, roll) on 3 coordinates.
Set to false:
  • Device only supports 3DoF tracking mode.
  • 3DoF tracking mode: Pose of the device only includes rotation (yaw, pitch, roll) on 3 coordinates.

Set up the default “Tracking Mode of pose system” for the HMD and controller by:

// Variable mLastTrackMode is used to record the last Tracking Mode for onRecenter() and onTrackingModeChanged() of class TrackedDevice.
// mLastTrackMode should record default tracking mode in setupConfig().
private int mLastTrackMode = 0; // 0: 3 Dof, 1: 6 Dof

@Override
public Config setupConfig() {
    Config configure = new Config();

    // Set up "Tracking Mode" for device
    configure.contains6Dof = true; // 6 Dof Tracking Mode
    mLastTrackMode = 1; // Record default Tracking Mode (1: 6 Dof)

    //configure.contains6Dof = false; // 3 Dof Tracking Mode
    //mLastTrackMode = 0; // Record default Tracking Mode (0: 3 Dof)

    return configure;
}
  • See Pose, Recenter and “Notification of Current/Changed Tracking Mode” on Tracked Device page.

Position Prediction Supported/Unsupported

Use supportedPositionPrediction to set up “position prediction supported/unsupported” for the HMD and controller.

Set to true:
  • Device supports position prediction.
  • Device service must supply stable and correct linear velocity.
Set to false:
  • Device cannot support position prediction.

Set up “position prediction supported/unsupported” for the HMD and controller by:

@Override
public Config setupConfig() {
    Config configure = new Config();
    // Set up "position prediction supported/unsupported" for device
    // configure.supportedPositionPrediction = false; // Do not support position prediction.
    configure.supportedPositionPrediction = true; // Support position prediction
    return configure;
}

Rotation Prediction Supported/Unsupported

Use supportedRotationPrediction to set up “rotation prediction supported/unsupported” for the controller.

Set to true:
  • Controller supports rotation prediction.
  • Controller device service must supply stable and correct angular velocity.
Set to false:
  • Controller can not support rotation prediction.

Set up “rotation prediction supported/unsupported” for the controller by:

@Override
public Config setupConfig() {
    Config configure = new Config();
    // Set up "rotation prediction supported/unsupported" for controller
    // configure.supportedRotationPrediction = false; // Do not support rotation prediction.
    configure.supportedRotationPrediction = true; // Support rotation prediction
    return configure;
}

Lifecycle

onStart()

onStart() should always be called before any display or tracking methods. If APIs such as updatePose(), setButtonPress(), setButtonTouch() and updateAnalog() are called before onStart(), it will cause unexpected results.

@Override
public void onStart() {
    // connected with the server
}

onStop()

onStop() is called when there is no app in the background and foreground. The VRDevice object should clear all memory buffers used and stop all data transmissions. If APIs such as updatePose(), setButtonPress(), setButtonTouch() and updateAnalog() are called after onStop(), it will cause unexpected results.

@Override
public void onStop() {
    // disconnected with the server
}

onPause()

onPause() is called when the app goes to the background. This method is typically used to commit unsaved changes to persistent data, stop data transmission, things that may be consuming CPU resources, and more. Make sure when onPause() is called, all events for the device (e.g.tracker thread) will wait for the onResume() function to be called.

@Override
public void onPause() {
    // no vr app in foreground. stop or continue data transmission depends on the device
}

onResume()

onResume() is called when the app goes to the foreground. When called, all data transmissions to the server will be restarted. Make sure when onResume() is called, all events for the device are be resumed.

@Override
public void onResume() {
    // must start data transmission
}

Attribute

Define what value you expect to get from different attribute values.

Integer-typed Attribute

getInt() returns an integer attribute. If the attribute is not supported by the device, the device service should return 0 and set the return error type AttributeError.NotSupported.

@Override
public long getInt(int Attr,AttributeError error) {
    switch(Attr)
    {
        case WVR.Attr_BatteryStatus_Int32:
        return WVR.BatteryStatus_Normal;
        //Define the integer attribute return value,
        //when assigned attribute will be called
    }
    error.setResult(AttributeError.NotSupported);
    return 0;
}

Float-typed Attribute

getFloat() returns a float attribute. If the attribute is not supported by the device, the device service should return 0 and set the return error type AttributeError.NotSupported.

@Overriden
public float getFloat(int Attr,AttributeError error) {
    switch(Attr)
    {
        case WVR.Attr_BatteryTemperature_Float:
        return 10f;
        //Define the Float attribute return value,
        //when assigned attribute will be called
    }
    error.setResult(AttributeError.NotSupported);
    return 0;
}

Update Attribute

updateAttribute() is called when the device is activated to notify the server if the DeviceService attribute changes.

//If Attr_BatteryTemperatureStatus_Int32 returned value changed,
//call this function.
updateAttribute(WVR.Attr_BatteryTemperatureStatus_Int32);

Attribute return error type

Used to return different types of errors that occur when reading attributes.

Attribute Error
AttributeError.SUCCESS
AttributeError.Unknown
AttributeError.NotSupported

List of Attributes which is Must or Optional

Attribute Must or Optional
Attr_DeviceBatteryPercentage_Float Must
Attr_UserIpdMeters_Float Optional
Attr_BatteryStatus_Int32 Must
Attr_ChargeStatus_Int32 Must
Attr_BatteryTemperature_Float Must
Attr_BatteryTemperatureStatus_Int32 Must
Attr_6DofWorkArea_Uint64 Must
Attr_ThresholdNear_Int32 Optional
Attr_ThresholdFar_Int32 Optional

DeviceError

setErrorState is called to enable/disable the abnormal states of the device, and deliver to the server.

Also see DeviceErrorState.

// If the battery is too hot, turn on the abnormal state.
if (!setErrorState(WVR.DeviceErrorState.BatteryOverheat, true)) {
    // do something for setting failed.
}

// Once the temperature of battery is down and not too hot, shut down the state.
if (setErrorState(WVR.DeviceErrorState.BatteryOverheat, false)) {
    // do something for setting is failed.
}

getErrorStatus is called to get the abnormal states that the device is currently experiencing.

Also see DeviceErrorState.

// The developer wants to get the abnormal states the device is experiencing.
long state = getErrorStatus();
if (state && (1 << (WVR.DeviceErrorState.BatteryOverheat - 1))) {
    // do something for battery overheat.
} else if (state && (1 << (WVR.DeviceErrorState.BatteryOvervoltage - 1))) {
    // do something for battery overvoltage.
} else if (state && (1 << (WVR.DeviceErrorState.DeviceConnectFail - 1))) {
    // do something for connection between device and server is failed.
} else if (state && (1 << (WVR.DeviceErrorState.DeviceLostTracking - 1))) {
    // do something for lost tracking.
} else if (state && (1 << (WVR.DeviceErrorState.ChargeFail - 1))) {
    // do something for charging failed.
} else {
    // device is good.
}

DeviceErrorState

Abnormal State Description
WVR.DeviceErrorState.None The device working normally.
WVR.DeviceErrorState.BatteryOverheat The temperature of the battery is too hot.
WVR.DeviceErrorState.BatteryOvervoltage The battery is over voltage when charging.
WVR.DeviceErrorState.DeviceConnectFail The device service failed to connect to the device.
WVR.DeviceErrorState.DeviceLostTracking The tracked device might be out of range.
WVR.DeviceErrorState.ChargeFail The consumed voltage is larger than the charged voltage.

setDeviceErrorStatus is called to add/remove the device error code to the server.

Also see DeviceError.

//If device error occur, call this function.
//DeviceService will send an event to notify the server.
setDeviceErrorStatus(WVR.DeviceError_DeviceConnectFail);

DeviceError

The following table describes the device error statuses.

Device Error Status Description
WVR.DeviceError_None The device working normally.
WVR.DeviceError_BatteryOverheat The battery temperature is too hot.
WVR.DeviceError_BatteryOverheatRestore Battery temperature has cooled down.
WVR.DeviceError_BatteryOvervoltage The battery is over voltage when charging.
WVR.DeviceError_BatteryOvervoltageRestore Over voltage has been fixed.
WVR.DeviceError_DeviceConnectFail The error status failed to connect to the USB device.
WVR.DeviceError_DeviceConnectRestore Connection failure has been fixed.
WVR.DeviceError_DeviceLostTracking The tracking device might be out of range.
WVR.DeviceError_DeviceLostTrackingRestore Lost tracking has been fixed.
WVR.DeviceError_ChargeFail The device is charging, but the consume voltage is larger than the charge voltage.
WVR.DeviceError_ChargeRestore Charging failure has been fixed.

Parameter

setParameters() is used to set a parameter string to the device service. App developers can use the WVR_SetParameters function to communicate with the DeviceService.

Also, see WVR_SetParameters.

@Override
 public void setParameters(String keyValue) {
     Debug.Log("setParameters " + keyValue);
     switch (keyValue) {
         case "camera=true":
             Debug.Log("device is support camera " );
             break;
     }
 }

getParameters() is used to get a parameter string from the device service. A developers can use the WVR_GetParameters function to communicate with the DeviceService.

Also, see WVR_GetParameters.

@Override
public String getParameters(String keyValue) {
    Debug.Log("getParameters " + keyValue);
    switch (keyValue) {
        case "IsDeviceSupportCamera":
            return "true";
     }
    return " ";
}