© 2014 Samsung Electronics Co., Ltd. All rights reserved.
This API defines interfaces and methods to manage motion data from various sensors on the device.
The following motion functionalities are provided:
Interface | Method |
---|---|
MotionManagerObject | |
MotionManager | void getMotionInfo(MotionType type, MotionInfoSuccessCallback successCallback, ErrorCallback? errorCallback) void start(MotionType type, MotionInfoSuccessCallback? successCallback) void stop(MotionType type) void setAccumulativePedometerListener(MotionInfoSuccessCallback changeCallback) void unsetAccumulativePedometerListener() |
MotionInfo | |
MotionPedometerInfo | |
MotionAccumulativePedometerInfo | |
MotionInfoSuccessCallback | void onsuccess(MotionInfo? motionInfo) |
Supported motion types.
enum MotionType { "PEDOMETER", "WRIST_UP" };
The motion types defined by this enumerator are:
Step status of the pedometer user.
enum PedometerStepStatus { "NOT_MOVING", "WALKING", "RUNNING" };
The MotionManagerObject interface defines what is instantiated by the WebAPIs object. The webapis.motion object allows access to the motion data.
[NoInterfaceObject] interface MotionManagerObject { readonly attribute MotionManager motion; };
WebAPIs implements MotionManagerObject;
The MotionManagerObject interface provides methods to access motion data.
[NoInterfaceObject] interface MotionManager { void getMotionInfo(MotionType type, MotionInfoSuccessCallback successCallback, optional ErrorCallback? errorCallback ); void start(MotionType type, optional MotionInfoSuccessCallback? successCallback); void stop(MotionType type); void setAccumulativePedometerListener(MotionInfoSuccessCallback changeCallback); void unsetAccumulativePedometerListener(); };
getMotionInfo
Gets the current motion data for the requested type.
void getMotionInfo(MotionType type, MotionInfoSuccessCallback successCallback, optional ErrorCallback? errorCallback);
Note that the getMotionInfo method only supports the PEDOMETER type. When MotionType is not equal to PEDOMETER, TypeMismtatchError is thrown.
The start method should be called before calling the getMotionInfo method for turning on the pedometer sensor.
The ErrorCallback is launched with these error types:
with error type NotSupportedError, if this feature is not supported.
with error type UnknownError, if registering the success callback fails because of an unknown error.
with error type TypeMismatchError, if any input parameter is not compatible with the expected type for that parameter.
function onsuccessCB(pedometerInfo) { console.log("Step status : " + pedometerInfo.stepStatus); console.log("Cumulative total step count : " + pedometerInfo.cumulativeTotalStepCount); } function onerrorCB(error) { console.log("Error occurs"); } webapis.motion.getMotionInfo("PEDOMETER", onsuccessCB, onerrorCB);
start
Starts and registers a change listener to be called when the motion data for a given motion type changes.
void start(MotionType type, optional MotionInfoSuccessCallback? successCallback);
with error type NotSupportedError, if the feature is not supported.
with error type UnknownError, if registering the listener fails because of an unknown error.
with error type TypeMismatchError, if any input parameter is not compatible with the expected type for that parameter.
function onchangedCB(pedometerInfo) { console.log("Step status : " + pedometerInfo.stepStatus); console.log("Cumulative total step count : " + pedometerInfo.cumulativeTotalStepCount); } webapis.motion.start("PEDOMETER", onchangedCB);
stop
Stops and unregisters a previously registered listener for changed motion data.
void stop(MotionType type);
with error type NotSupportedError, if this feature is not supported.
with error type UnknownError, if unregistering the listener fails because of an unknown error.
with error type TypeMismatchError, if any input parameter is not compatible with the expected type for that parameter.
webapis.motion.stop("PEDOMETER");
setAccumulativePedometerListener
Registers a listener to be called when the accumulative pedometer data changes.
void setAccumulativePedometerListener(MotionInfoSuccessCallback changeCallback);
Note that setAccumulativePedometerListener method don't need to call the start method of a motion sensor
with error type NotSupportedError, if the feature is not supported.
with error type UnknownError, if registering the listener fails because of an unknown error.
with error type TypeMismatchError, if any input parameter is not compatible with the expected type for that parameter.
function onchangedCB(pedometerInfo) { console.log("Step status : " + pedometerInfo.stepStatus); console.log("Accumulative total step count : " + pedometerInfo.accumulativeTotalStepCount); } webapis.motion.setAccumulativePedometerListener(onchangedCB);
unsetAccumulativePedometerListener
Unregisters a previously registered listener for the accumulative pedometer data.
void unsetAccumulativePedometerListener();
with error type NotSupportedError, if this feature is not supported.
with error type UnknownError, if unregistering the listener fails because of an unknown error.
with error type TypeMismatchError, if any input parameter is not compatible with the expected type for that parameter.
webapis.motion.unsetAccumulativePedometerListener();
The MotionInfo interface is a common abstract interface used by different types of motion information objects.
[NoInterfaceObject] interface MotionInfo { };
The MotionPedometerInfo interface represents pedometer motion data.
[NoInterfaceObject] interface MotionPedometerInfo : MotionInfo { readonly attribute PedometerStepStatus stepStatus; readonly attribute double speed; readonly attribute double walkingFrequency; readonly attribute double cumulativeDistance; readonly attribute double cumulativeCalorie; readonly attribute double cumulativeTotalStepCount; readonly attribute double cumulativeWalkStepCount; readonly attribute double cumulativeRunStepCount; };
readonly
PedometerStepStatus stepStatus
An attribute to indicate the status of current steps.
readonly
double speed
An attribute to indicate the current speed in km/h.
readonly
double walkingFrequency
An attribute to indicate the step count per second.
readonly
double cumulativeDistance
An attribute to indicate the cumulative distance traveled since the last start method call in meters.
readonly
double cumulativeCalorie
An attribute to indicate the cumulative calories burned since the last start method call in kcal.
readonly
double cumulativeTotalStepCount
An attribute to indicate the cumulative step count of a walk and the run since the last start method call. The value is the sum of all below step counts.
readonly
double cumulativeWalkStepCount
An attribute to indicate the cumulative walk step count since the last start method call.
readonly
double cumulativeRunStepCount
An attribute to indicate the cumulative run step count since the last start method call.
The MotionAccumulativePedometerInfo interface represents pedometer motion data since the device booing.
[NoInterfaceObject] interface MotionAccumulativePedometerInfo : MotionInfo { readonly attribute PedometerStepStatus stepStatus; readonly attribute double speed; readonly attribute double walkingFrequency; readonly attribute double accumulativeDistance; readonly attribute double accumulativeCalorie; readonly attribute double accumulativeTotalStepCount; readonly attribute double accumulativeWalkStepCount; readonly attribute double accumulativeRunStepCount; };
readonly
PedometerStepStatus stepStatus
An attribute to indicate the status of current steps.
readonly
double speed
An attribute to indicate the current speed in km/h.
readonly
double walkingFrequency
An attribute to indicate the step count per second.
readonly
double accumulativeDistance
An attribute to indicate the accumulative distance traveled since the device booting in meters.
readonly
double accumulativeCalorie
An attribute to indicate the accumulative calories burned since the device booting in kcal.
readonly
double accumulativeTotalStepCount
An attribute to indicate the accumulative step count of a walk and the run since the device booting. The value is the sum of accumulativeWalkStepCount and accumulativeRunStepCount.
readonly
double accumulativeWalkStepCount
An attribute to indicate the accumulative walk step count since the device booting.
readonly
double accumulativeRunStepCount
An attribute to indicate the accumulative run step count since the device booting.
The MotionInfoSuccessCallback interface is a callback interface that is invoked when the motion data has changed. For example, see MotionManager interface
[Callback=FunctionOnly, NoInterfaceObject] interface MotionInfoSuccessCallback { void onsuccess(optional MotionInfo? motionInfo); };
onsuccess
Called when the motion data has changed.
void onsuccess(optional MotionInfo? motionInfo);
This is the list of URIs used to declare this API's features, for use in the widget config.xml. For each URL, the list of functions covered is provided.
To guarantee the running of this application on a device with pedometer, define the following requirements in the config file:
To guarantee the running of this application on a device with wrist up, define the following requirements in the config file:
module Motion { enum MotionType { "PEDOMETER", "WRIST_UP" }; enum PedometerStepStatus { "NOT_MOVING", "WALKING", "RUNNING" }; [NoInterfaceObject] interface MotionManagerObject { readonly attribute MotionManager motion; }; WebAPIs implements MotionManagerObject; [NoInterfaceObject] interface MotionManager { void getMotionInfo(MotionType type, MotionInfoSuccessCallback successCallback, optional ErrorCallback? errorCallback ); void start(MotionType type, optional MotionInfoSuccessCallback? successCallback); void stop(MotionType type); void setAccumulativePedometerListener(MotionInfoSuccessCallback changeCallback); void unsetAccumulativePedometerListener(); }; [NoInterfaceObject] interface MotionInfo { }; [NoInterfaceObject] interface MotionPedometerInfo : MotionInfo { readonly attribute PedometerStepStatus stepStatus; readonly attribute double speed; readonly attribute double walkingFrequency; readonly attribute double cumulativeDistance; readonly attribute double cumulativeCalorie; readonly attribute double cumulativeTotalStepCount; readonly attribute double cumulativeWalkStepCount; readonly attribute double cumulativeRunStepCount; }; [NoInterfaceObject] interface MotionAccumulativePedometerInfo : MotionInfo { readonly attribute PedometerStepStatus stepStatus; readonly attribute double speed; readonly attribute double walkingFrequency; readonly attribute double accumulativeDistance; readonly attribute double accumulativeCalorie; readonly attribute double accumulativeTotalStepCount; readonly attribute double accumulativeWalkStepCount; readonly attribute double accumulativeRunStepCount; }; [Callback=FunctionOnly, NoInterfaceObject] interface MotionInfoSuccessCallback { void onsuccess(optional MotionInfo? motionInfo); }; };