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 |
Supported in Simulator |
---|---|---|---|
Enables or disables dual-pairing mode. |
No |
No |
|
Subscribes the sensor data from the magic remote. |
No |
Yes |
|
Resets the magic remote's quaternion data. |
No |
No |
-
Open All
-
- 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
Required
Object
Coordinates information object
Required
Object
Gyroscope sensor information object
Required
Object
Accelerometer sensor information object
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
-