Hello.
I'm very confused about my service app.
I'm using HRM sensor in my service app.
but if Gear S2 screen is turn off, my service app doesn't work on.
static int real_cnt = 0; static int cnt = 0; void _HRM_value(sensor_h sensor, sensor_event_s *sensor_data, void *user_data) { char buf[PATH_MAX]; appdata_s *ad = (appdata_s *) user_data; real_cnt++; if(sensor_data->values[0] > 10) { cnt++; ad->heart_rate += sensor_data->values[0]; } if(real_cnt ==5 ) { sprintf(buf, "%0.1f", ((ad->heart_rate) / cnt)); send_data(buf); cnt = 0; real_cnt = 0; ad->heart_rate = 0; } }
void start_heartrate_sensor(appdata_s *ad) { //start_acceleration_sensor(ad); if (sensor_get_default_sensor(SENSOR_HRM, &(ad->sensor)) == SENSOR_ERROR_NONE) { if (sensor_create_listener(ad->sensor, &(ad->listener)) == SENSOR_ERROR_NONE && sensor_listener_set_event_cb(ad->listener, 1000, _HRM_value, ad) == SENSOR_ERROR_NONE && sensor_listener_set_option(ad->listener, SENSOR_OPTION_ALWAYS_ON) == SENSOR_ERROR_NONE) { //sensor_listener_set_interval(ad->listener, 3000); if (sensor_listener_start(ad->listener) == SENSOR_ERROR_NONE) { //LOGI("Sensor listener started."); } } } }
This is my code in service app.
When Gear S2 Screen off, this code does not work well.
void _HRM_value(sensor_h sensor, sensor_event_s *sensor_data, void *user_data) { char buf[PATH_MAX]; appdata_s *ad = (appdata_s *) user_data; sprintf(buf, "%0.1f", sensor_data->values[0]); send_data(buf); }
void start_heartrate_sensor(appdata_s *ad) { //start_acceleration_sensor(ad); if (sensor_get_default_sensor(SENSOR_HRM, &(ad->sensor)) == SENSOR_ERROR_NONE) { if (sensor_create_listener(ad->sensor, &(ad->listener)) == SENSOR_ERROR_NONE && sensor_listener_set_event_cb(ad->listener, 3000, _HRM_value, ad) == SENSOR_ERROR_NONE && sensor_listener_set_option(ad->listener, SENSOR_OPTION_ALWAYS_ON) == SENSOR_ERROR_NONE) { //sensor_listener_set_interval(ad->listener, 3000); if (sensor_listener_start(ad->listener) == SENSOR_ERROR_NONE) { //LOGI("Sensor listener started."); } } } }
But If I use this code, my service app run fine when Gear S2's screen off.
What should I do ?..