Wearable Web

Motion

You can access the motion data of a wearable device using the Motion API.

The main features of the Motion API include:

  • Monitoring motion changes

    You can activate the motion notifications by registering a listener for the motion change events using the start() method of the MotionManager interface.

    When the notifications are no longer needed, you can unregister the listener by using the stop() method of the MotionManager interface.

  • Retrieving current motion data

    You can retrieve the current motion data using the getMotionInfo() method of the MotionManager interface.

The following table lists the supported motion types.

Table: Motion types
Type Description
PEDOMETER Provides pedometer information, such as current step status, cumulative distance, calories burned, and total step count.
WRIST_UP Provides a notification when the user lifts a wrist to look at the watch device.
HRM Provides HRM information, such as the heart rate and R-R interval of the watch user.
GPS Provides GPS information, such as latitude, longitude, and speed.
PALM_TOUCH Provides a notification when the user touches the screen in the palm of their hand.
ACTIVITY_RECOGNITION Provides activity recognition information, such as the Stationary, Walking, and Running state.
Note
The PEDOMETER, WRIST_UP, HRM, and GPS motion types are deprecated since Tizen 2.3. Use the Tizen public Human Activity Monitor API (tizen.humanactivitymonitor since Tizen 2.3) instead.

Monitoring Motion Changes

Learning how to activate motion notifications for getting updated motion data is a basic motion management skill:

  • To monitor pedometer changes:
    1. Define the action to be taken when the pedometer data changes. In the following example, the changed values are recorded in the console log:
      function onchangedCB(pedometerInfo)
      {
         console.log("Step status: " + pedometerInfo.stepStatus);
         console.log("Cumulative calories: " + pedometerInfo.cumulativeCalorie);
         console.log("Cumulative distance: " + pedometerInfo.cumulativeDistance);
         console.log("Cumulative total step count: " + pedometerInfo.cumulativeTotalStepCount);
      }
      
    2. To start listening to changes in the pedometer data, use the start() method to register the onchangedCB listener:
      webapis.motion.start("PEDOMETER", onchangedCB);
      
    3. To stop listening to the pedometer data changes, use the stop() method:
      webapis.motion.stop("PEDOMETER");
      
  • To monitor wrist-up actions:
    1. Define the action to be taken when the user lifts a wrist to look at the watch device. In the following example, the changed values are recorded in the console log:
      function onchangedCB()
      {
         console.log("Wrist-up");
      }
      
    2. To start listening to wrist-up events, use the start() method to register the onchangedCB listener:
      webapis.motion.start("WRIST_UP", onchangedCB);
      
    3. To stop listening to wrist-up events, use the stop() method:
      webapis.motion.stop("WRIST_UP");
      
  • To monitor HRM changes:
    1. Define the action to be taken when HRM data changes. In the following example, the heart rate and R-R interval of user are recorded in the console log:
      function onchangedCB(hrmInfo)
      {
         console.log("Heart rate: " + hrmInfo.heartRate);
         console.log("R-R interval: " + hrmInfo.rRInterval);
      }
      
    2. To start listening to HRM data changes, use the start() method to register the onchangedCB listener:
      webapis.motion.start("HRM", onchangedCB);
      
    3. To stop listening to HRM data changes, use the stop() method:
      webapis.motion.stop("HRM");
      
  • To monitor GPS changes:
    1. Define the action to be taken when GPS data changes. In the following example, latitude, longitude, and altitude of the user are recorded in the console log:
      function onchangedCB(resultSet) 
      {
         var index = 0;
         for (index=0; index < resultSet.gpsInfo.length; index++)
         {
            console.log("\n" + index + " [ " + resultSet.gpsInfo[index].latitude 
                        + " , " + resultSet.gpsInfo[index].longitude + " , " 
                        + resultSet.gpsInfo[index].altitude + " ] ");
         }
      }
      
    2. To start listening to GPS data changes, use the start() method to register the onchangedCB listener:
      webapis.motion.start("GPS", onchangedCB);
      
    3. To stop listening to GPS data changes, use the stop() method:
      webapis.motion.stop("GPS");
      
  • To monitor palm touches:
    1. Define the action to be taken when the user touches the screen in the palm of their hand. In the following example, the changed values are recorded in the console log:
      function onchangedCB() 
      {
         console.log("Palm touch");
      }
      
    2. To start listening to palm touch events, use the start() method to register the onchangedCB listener:
      webapis.motion.start("PALM_TOUCH", onchangedCB);
      
    3. To stop listening to palm touch events, use the stop() method:
      webapis.motion.stop("PALM_TOUCH");
      

Getting Motion Data

Learning how to retrieve the current motion data is a basic motion management skill:

  1. To get the current motion data, use the getMotionInfo() method:
    webapis.motion.getMotionInfo("PEDOMETER", onsuccessCB, onerrorCB);
    
  2. Use the success and error event handlers to define what to do with the data:
    function onsuccessCB(pedometerInfo)
    {
       console.log("Step status: " + pedometerInfo.stepStatus);
       console.log("Cumulative calories: " + pedometerInfo.cumulativeCalorie);
       console.log("Cumulative distance: " + pedometerInfo.cumulativeDistance);
       console.log("Cumulative total step count: " + pedometerInfo.cumulativeTotalStepCount);
    }
    
    function onerrorCB(error)
    {
       console.log("Error occurs");
    }
    
Go to top