Magic Remote

Service URI - luna://com.webos.service.mrcu

Provides methods related to the magic remote sensor. This is used to check the sensor data from the magic remote or to stop receiving sensor data from the magic remote.

Methods

MethodDescriptionSupported in Emulator
enableDualPairingEnables or disables dual-pairing mode.No
sensor/getSensorDataSubscribes the sensor data from the magic remote.No
sensor/resetQuaternionResets the magic remote's quaternion data.No

enableDualPairing

Description

Enables or disables Dual Pairing mode. In Dual Pairing mode, you can pair two magic remotes with one webOS TV at the same time. You can use this dual-pairing mode for such as playing games.

Parameters

NameRequiredTypeDescription
enableRequiredBooleanFlag that decides whether to enable or disable the Dual Pairing mode.
  • To enable Dual Pairing mode, set this parameter to true.
  • To disable Dual Pairing mode, set this parameter to false.
  • The default value is false.

Call returns

NameRequiredTypeDescription
returnValueRequiredBooleanFlag that indicates success/failure of the request.
  • true: Success
  • false: Failure
errorCodeOptionalNumbererrorCode contains the error code if the method fails. The method will return errorCode only if it fails.
See the Error Codes Reference of this method for more details.
errorTextOptionalStringerrorText contains the error text if the method fails. The method will return errorText only if it fails.
See the Error Codes Reference of this method for more details.

Error reference

Error CodeError Message
1001Undefined parameter
1002Missing required parameter

Example

var request = webOS.service.request('luna://com.webos.service.mrcu', {
  method: 'enableDualPairing',
  parameters: { enable: true },
  onSuccess: function (inResponse) {
    console.log('Result: ' + JSON.stringify(inResponse));
    // To-Do something
  },
  onFailure: function (inError) {
    console.log('Failed to enable Dual Pairing mode');
    console.log('[' + inError.errorCode + ']: ' + inError.errorText);
    // To-Do something
    return;
  },
});

See also

sensor/getSensorData

Description

Subscribes the sensor data from the magic remote. The data includes point coordinates, gyroscope sensor, accelerometer sensor and quaternion value. You can get the sensor data by subscribing a callback function with specified intervals.

Parameters

NameRequiredTypeDescription
callbackIntervalRequiredNumberCallback interval:
  • 1: 100 pkt/sec
  • 2: 50 pkt/sec
  • 3: 33 pkt/sec
  • 4: 10 pkt/sec
subscribeRequiredBooleanFlag that decides whether to subscribe or not.
  • true: Subscribe
  • false: Do not subscribe. Call the method only once. (Default)
Caution
Do not set this to false, one-time calling does not work correctly now.
Note

In webOS TV 1.x, sensor/getSensorData method requires more parameters, which are sleep and autoAlign. If you use sensor/getSensorData method in webOS TV 1.x, set sleep and autoAlign parameters as below:

  • sleep: true
  • autoAlign: false

You can find out webOS TV version that user uses via getSystemInfo() method.

Call returns

NameRequiredTypeDescription
returnValueRequiredBooleanFlag that indicates success/failure of the request.
  • true: Success
  • false: Failure
errorCodeOptionalNumbererrorCode contains the error code if the method fails. The method will return errorCode only if it fails.
See the Error Codes Reference of this method for more details.
errorTextOptionalStringerrorText contains the error text if the method fails. The method will return errorText only if it fails.
See the Error Codes Reference of this method for more details.
subscribedOptionalBooleanFlag that indicates whether the subscription is enabled or not.
  • true: Enabled
  • false: Disabled

Remarks

Subscription is disabled if this interface returns false. So, to keep the subscription, subscribe the sensor data again. This service provides "subscribe " for the subscription.

Error reference

Error CodeError Text
1001Magic remote is not ready
1002Undefined callback interval
1003Subscription add fail
1004invalid parameter

Subscription Returns

NameRequiredTypeDescription
returnValueRequiredBooleanFlag that indicates success/failure of the request.
  • true: Success
  • false: Failure
deviceIdRequiredStringMagic remote device ID
coordinateRequiredObjectCoordinates information object
gyroscopeRequiredObjectGyroscope sensor information object
accelerationRequiredObjectAccelerometer sensor information object
quaternionRequiredObjectQuaternion sensor information object

Example

var subscriptionHandle;

var webOSTVVersion = "2.0.0";

// Get webOS TV version
var request = webOS.service.request("luna://com.webos.service.tv.systemproperty", {
    method: "getSystemInfo",
    parameters: { "keys":["sdkVersion"] },
    onSuccess: function (inResponse) {
		webOSTVVersion = inResponse.sdkVersion;
		console.log("webOS TV Version: " + inResponse.sdkVersion);
		//To-Do something
		return true;
    },
	onFailure: function (inError) {
		console.log("Failed to get webOS TV Version: " + inResponse.errorText);
		console.log("[" + inError.errorCode + "]: " + inError.errorText);
		// To-Do something
		return;
	}
});

// Set parameters by webOS TV version
var options;
if( webOSTVVersion == "2.0.0") {
    options.callbackInterval = 1;
    options.subscribe = true;
} else {
    options.callbackInterval = 1;
    options.subscribe = true;
    options.sleep = true;
    options.autoAlign = false;
}

// Call sensor/getSensorData with subscription
subscriptionHandle = webOS.service.request("luna://com.webos.service.mrcu", {
    method: "sensor/getSensorData",
    parameters: options,
    onSuccess: function (inResponse) {
		if (inResponse.subscribed == true) {
            console.log("Subscription Enabled");
            // To-Do something
        }

        console.log("Result: " + JSON.stringify(inResponse));
		// To-Do something
		return true;
    },
	onFailure: function (inError) {
		console.log("Failed to get sensor data");
		console.log("[" + inError.errorCode + "]: " + inError.errorText);
		// To-Do something
		return;
	}
);

...
// If you need to unsubscribe the data, use cancel() method as below
subscriptionHandle.cancel();

Return example

// When subscription enabled
{
  "subscribed": true,
  "returnValue": true
}

// Subscription return
{
  "deviceId": 0,
  "coordinate": {
      "x": 1101,
      "y": 518
  },
  "gyroscope": {
      "z": -1.682723,
      "x": 0.304100,
      "y": -0.582472
  },
  "acceleration": {
      "z": 12.035406,
      "x": 9.713932,
      "y": 5.446675
  },
  "returnValue": true,
  "quaternion": {
      "q0": 0.042376,
      "q1": 0.088355,
      "q2": 0.937461,
      "q3": 0.334014
  }
}

See also

sensor/resetQuaternion

Description

Resets the quaternion sensor of the magic remote. Sometimes you need to reset the sensor before the user action, such as when a game starts or magic remote wakes up from sleep mode.

Parameters

None

Call returns

NameRequiredTypeDescription
returnValueRequiredBooleanFlag that indicates success/failure of the request.
  • true: Success
  • false: Failure
errorCodeOptionalNumbererrorCode contains the error code if the method fails. The method will return errorCode only if it fails.
See the Error Codes Reference of this method for more details.
errorTextOptionalStringerrorText contains the error text if the method fails. The method will return errorText only if it fails.
See the Error Codes Reference of this method for more details.

Error reference

Error CodeError Text
1001Magic remote is not ready
1003MotionEngine is not ready
1004Device is no added to the MotionEngine
Note
MotionEngine calculates numeric data from the sensor data of magic remote.

Example

var request = webOS.service.request('luna://com.webos.service.mrcu', {
  method: 'sensor/resetQuaternion',
  onSuccess: function (inResponse) {
    console.log('Succeeded to reset the quaternion sensor');
    // To-Do something
    return true;
  },
  onFailure: function (inError) {
    console.log('Failed to reset sensor: ' + inResponse.errorText);
    console.log('[' + inError.errorCode + ']: ' + inError.errorText);
    // To-Do something
    return;
  },
});

See also

Object

coordinate object

The object that holds the coordinates information from the magic remote.

{
  "x": number,
  "y": number
}
NameRequiredTypeDescription
xRequirednumberX coordinate
yRequirednumberY coordinate

gyroscope object

The object that holds the gyroscope sensor information from the magic remote.

{
  "x": number,
  "y": number,
  "z": number
} 
NameRequiredTypeDescription
xRequirednumberX-axis value
yRequirednumberY-axis value
zRequirednumberZ-axis value

acceleration object

Object that holds the acceleration sensor information from magic remote.


{
  "x": number,
  "y": number,
  "z": number
} 
NameRequiredTypeDescription
xRequirednumberX-axis value
yRequirednumberY-axis value
zRequirednumberZ-axis value

quaternion object

The object that holds the quaternion sensor information from the magic remote.

{
    "q0": number,
    "q1": number,
    "q2": number,
    "q3": number
} 
NameRequiredTypeDescription
q0Requirednumberx value
q1Requirednumbery value
q2Requirednumberz value
q3Requirednumberw value
No Headings