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

Method

Description

Supported in Emulator

enableDualPairing

Enables or disables dual-pairing mode. 

No

sensor/getSensorData

Subscribes the sensor data from the magic remote.

No

sensor/resetQuaternion

Resets the magic remote's quaternion data.

No

 

Open All


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.

Syntax

enableDualPairing(Boolean enable)

Parameters

Name

Required

Type

Description

enable

Required

Boolean

Flag 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

Name

Required

Type

Description

returnValue

Required

Boolean

Flag that indicates success/failure of the request.

  • true: Success

  • false: Failure

errorCode

Optional

Number

errorCode 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.

errorText

Optional

String

errorText 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 Code

Error Message

1001

Undefined parameter

1002

Missing 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.

Syntax

sensor/getSensorData(number callbackInterval, boolean subscribe)

Parameters

Name

Required

Type

Description

callbackInterval

Required

Number

Callback interval:

  • 1: 100 pkt/sec

  • 2: 50 pkt/sec

  • 3: 33 pkt/sec

  • 4: 10 pkt/sec

subscribe

Required

Boolean

Flag that decides whether to subscribe or not.

  • true: Subscribe

  • false: Do not subscribe. Call the method only once. (Default)

Do not set this to false, one-time calling does not work correctly now. 

 

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.

For more detailed information about webOS TV version, see Spec and Version.

Call Returns

Name

Required

Type

Description

returnValue

Required

Boolean

 Flag that indicates success/failure of the request.

  • true: Success

  • false: Failure

errorCode

Optional

Number

errorCode 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.

errorText

Optional

String

errorText 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.

subscribed

Optional

Boolean

Flag 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 Code

Error Text

1001

Magic remote is not ready

1002

Undefined callback interval

1003

Subscription add fail

1004

invalid parameter

Subscription Returns

Name

Required

Type

Description

returnValue

Required

Boolean

 Flag that indicates success/failure of the request.

  • true: Success

  • false: Failure

deviceId

Required

String

Magic remote device ID

coordinate

Required

Object

Coordinates information object

gyroscope

Required

Object

Gyroscope sensor information object

acceleration

Required

Object

Accelerometer sensor information object

quaternion

Required

Object

Quaternion 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.

Syntax

sensor/resetQuaternion()

Parameters

None

Call Returns

Name

Required

Type

Description

returnValue

Required

Boolean

Flag that indicates success/failure of the request.

  • true: Success

  • false: Failure

errorCode

Optional

Number

errorCode 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.

errorText

Optional

String

errorText 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 Code

Error Text

1001

Magic remote is not ready

1003

MotionEngine is not ready

1004

Device is no added to the MotionEngine

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
}

Name

Required

Type

Description

x

Required

number

X coordinate

y

Required number Y coordinate

gyroscope Object

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

{
    "x": number,
    "y": number,
    "z": number
} 

Name

Required

Type

Description

x

Required

number

X-axis value

y

Required

number

Y-axis value

z

Required number Z-axis value

acceleration Object

Object that holds the acceleration sensor information from magic remote.

{
    "x": number,
    "y": number,
    "z": number
} 

Name

Required

Type

Description

x

Required

number

X-axis value

y

Required

number

Y-axis value

z

Required number Z-axis value

quaternion Object

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

{
    "q0": number,
    "q1": number,
    "q2": number,
    "q3": number
} 

Name

Required

Type

Description

q0

Required

number

x value

q1

Required

number

y value

q2

Required

number

z value

q3

Required

number

w value



Navigation