언어 설정

Menu
Sites
Language
Using the Wear On sensor

Hi guys, We want to use the Wear On sensor to determine if the watch is currently worn or not, but we noticed it was removed from the official API reference.

We work with this sensor in the same way as with other sensors (accelerometer, heart rate and etc).

Please refer to the code snippet and advise if this API is the best way to know the device is on the wrist or not.

If not, сould you please let me know what would be the best practice to know the device is on the wrist or not?

void wear_on_sensor_callback(sensor_h sensor, sensor_event_s *event, void *data)
{
       bool is_wear_on = event->values[0] == 1.0;

       dlog_print(DLOG_ERROR, "ZebraNative", "is_wear_on: %d", is_wear_on);

       // use is_wear_on to start/stop sensors
}

static const int WEAR_ON_SENSOR = 0x2001;
int create_wear_on_sensor()
{
       int ret = sensor_get_default_sensor(WEAR_ON_SENSOR, &sensor);
       if (ret != SENSOR_ERROR_NONE)
       {
              return ret;
       }

       ret = sensor_create_listener(sensor, &listener);
       if (ret != SENSOR_ERROR_NONE)
       {
              return ret;
       }

       ret = sensor_listener_start(listener);
       if (ret != SENSOR_ERROR_NONE)
       {
              return ret;
       }

       ret = sensor_listener_set_event_cb(listener, 1000, wear_on_sensor_callback, NULL);
       if (ret != SENSOR_ERROR_NONE)
       {
              return ret;
       }

       return ret;
}

 

Thank you, Maksim