I've built a simple watchface for a Samsung Galaxy Active 2 using Tizen Studio, native app. I have added some of the "health" info to the face: pedometer and heartrate monitor.
Q: I know how to setup a listener and callback so that I can get notified when the heartrate (or step count) changes, but I cannot find how to just read the current / last read HRM value. I know this must be possible since other watchfaces do this ... just don't know how.
Code for the listener/callback method:
sensor_get_default_sensor(SENSOR_HRM, &sensor);
ret = sensor_create_listener(sensor, &hrmSensorListener);
if( ret != SENSOR_ERROR_NONE)
dlog_print(DLOG_ERROR, LOG_TAG, "failed to get hrm sensor. err = %d", ret);
ret = sensor_listener_set_event_cb(hrmSensorListener, 20000, hrm_sensor_callback, face);
if( ret != SENSOR_ERROR_NONE)
dlog_print(DLOG_ERROR, LOG_TAG, "failed to set hrm sensor listener. err = %d", ret);
sensor_listener_set_option(hrmSensorListener, SENSOR_OPTION_DEFAULT);
sensor_listener_start(hrmSensorListener);
This means that when the watchface starts, there is a period when the HRM or step count is not updated, and this is a bit annoying.
How do I read the current value of the sensor?
Please try use sensor_listener_read_data method. According to documentation this method gets sensor data. You may follow tutorial published on Tizen site.
sensor_get_default_sensor(SENSOR_HRM, &sensor);
ret = sensor_create_listener(sensor, &hrmSensorListener);
if( ret != SENSOR_ERROR_NONE)
dlog_print(DLOG_ERROR, LOG_TAG, "failed to get hrm sensor. err = %d", ret);
ret = sensor_listener_set_event_cb(hrmSensorListener, 20000, hrm_sensor_callback, face);
if( ret != SENSOR_ERROR_NONE)
dlog_print(DLOG_ERROR, LOG_TAG, "failed to set hrm sensor listener. err = %d", ret);
sensor_listener_set_option(hrmSensorListener, SENSOR_OPTION_DEFAULT);
sensor_listener_start(hrmSensorListener);
sensor_event_s event;
sensor_listener_read_data(hrmSensorListener, &event);
I think code above should help you