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 |
---|---|---|
sensor/getSensorData | Subscribes the sensor data from the magic remote. | No |
sensor/resetQuaternion | Resets the magic remote's quaternion data. | No |
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
Name | Required | Type | Description |
---|---|---|---|
callbackInterval | Required | Number | Callback interval:
|
subscribe | Required | Boolean | Flag that decides whether to subscribe or not.
Caution Do not set this to false, one-time calling does not work correctly now. |
- sleep: true
- autoAlign: false
Call returns
Name | Required | Type | Description |
---|---|---|---|
returnValue | Required | Boolean | Flag that indicates success/failure of the request.
|
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.
|
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.
|
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.
Parameters
None
Call returns
Name | Required | Type | Description |
---|---|---|---|
returnValue | Required | Boolean | Flag that indicates success/failure of the request.
|
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 |
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 |