Languages

Menu
Sites
Language
how to get gyro and hrm sensor

i saw manual in this site

but i can`t understand 2 more sensro at once 

please help to see sample code

Responses

10 Replies
Armaan-Ul- Islam

Seems to me You want to read from both HRM and Gyro Sensor at a time from your Tizen Native application, Right?

# No complications here, Just merge Codes to read Individual Sensor data.

# Add 'healthinfo' privilege in your tizen-manifest.xml.

I am sharing a sample code for you printing both HRM and Gyro sensor data on device log.

 

#include <sensor.h>
#include<stdbool.h>

bool checkSupport(sensor_type_e type){
	bool support;
	sensor_is_supported(type,&support);
	return support;
}

void sensorEventCallBackHRM(sensor_h sensorHanlder, sensor_event_s *event, void *user_data){
	 dlog_print(DLOG_DEBUG, LOG_TAG, "SENSOR_HRM data: %.2f", event->values[0]);
}

void sensorEventCallBackGYRO(sensor_h sensorHanlder, sensor_event_s *event, void *user_data){
	 dlog_print(DLOG_DEBUG, LOG_TAG, "SENSOR_GYROSCOPE data: X:%.2f Y:%.2f Z:%.2f", event->values[0], event->values[1], event->values[2]);
}

void logPrintSensorData(){

	if(checkSupport(SENSOR_HRM)){

			sensor_h sensorHanlderHRM;
			sensor_get_default_sensor(SENSOR_HRM, &sensorHanlderHRM);

			sensor_listener_h sensorListenerHRM;
			sensor_create_listener(sensorHanlderHRM,&sensorListenerHRM);

			sensor_listener_set_event_cb(sensorListenerHRM,10000, sensorEventCallBackHRM, NULL);
			sensor_listener_set_option(sensorListenerHRM,SENSOR_OPTION_DEFAULT);
			sensor_listener_start(sensorListenerHRM);

			/* Once Data is read*/
			//sensor_listener_stop(sensorListener);

		}

		else {
			dlog_print(DLOG_ERROR, LOG_TAG, "SENSOR_HRM is not supported");
		}

	if(checkSupport(SENSOR_GYROSCOPE)){

			sensor_h sensorHanlderGYRO;
			sensor_get_default_sensor(SENSOR_GYROSCOPE, &sensorHanlderGYRO);

			sensor_listener_h sensorListenerGYRO;
			sensor_create_listener(sensorHanlderGYRO,&sensorListenerGYRO);

			sensor_listener_set_event_cb(sensorListenerGYRO,10000, sensorEventCallBackGYRO, NULL);
			sensor_listener_set_option(sensorListenerGYRO,SENSOR_OPTION_DEFAULT);
			sensor_listener_start(sensorListenerGYRO);

			/* Once Data is read*/
			//sensor_listener_stop(sensorListener);

		}

		else {
			dlog_print(DLOG_ERROR, LOG_TAG, "SENSOR_GYROSCOPE is not supported");
		}

	}

 

 

Call the 'logPrintSensorData()' function from your main() or create_base_gui().

Hope it helps !!!!

 

 

Cho

thank you 

i use this code but 

Hrm sensor is not working 

i use gear s2 

Armaan-Ul- Islam

# Run Wearable Emulator, Mouse Right click over the Emulator screen > Control Panel > Click Next on the bottom right > Click on Heart Rate.

# Change the bpm while the app is running and observe the change in log.

# When Using Real device instead of emulator, Clean the HRM sensor on the watch back. Make sure you have tighthen the watch belt, thus the gear is having strong and constant connection with your wrist. Don't move your hand much, try to keep it constant while sensor is reading HRM data.

# You will see the LED light blinking on your gear back while it is reading HRM data. If the light remains off while the app is running, then the issue is with your gear s2 HRM sensor only, The app may run fine on other devices. Please 'Mark as answer' if the info helps, Thanks.
 

Cho

i am using samrt watch (gear s2)

clean hrm sensor and led light is blinking 

if i use other hrm sensor app 

this code can get hrm sensor value but running at first cannot get sensor vlaue like image above 

Armaan-Ul- Islam

In that case, Your code is okay, No need to worry, You're good to go...

HRM Sensor doesn't provide data instantly on demand. Rather when HRM sensor is requested it initiates reading and analyzing data, after a certain period of time (Suppose 10 Secs) it comes on a conclusion and sends the data. So you have to keep patience and wait for the 'bpm'.

 

Now question arises, how other apps shows instant data?? They don't, Rather you see a data stored in database/variable from previous reading. When you will request current Heart rate, the app would start scanning and show result after few seconds. You should also try this trick.

 

Now as you said "if i use other hrm sensor app    this code can get hrm sensor value but running at first cannot". The scenario happening here is the first app is initiating the HRM sensor to read data, and you are getting that data on the log of second app (on your app) after a period of time. I am sharing screenshot of my Gear S2 log. Check it out, after a few seconds it starts showing HRM data. Make sure you are wearing the smartwatch tight and steady.

 

Cho

 

start 07-26-10-00-33 

sensor_listener_set_event_cb(sensor_info.sensor_listener, 1000, _new_sensor_value, ad);

in 5 min i can`t get hrm sensor value

Armaan-Ul- Islam

# Please Create a new Project: Template > Wearable 2.3.2 >  Basic UI. Then paste the Code snippet above and call 'logPrintSensorData()' function from create_base_gui(). (Just to reproduce same scenario as mine) and then deploy adding 'healthinfo' privilege in your tizen-manifest.xml

 

# Please share the log for the Wearable 2.3.2 Emulator. Is the code working fine or your Emulator ???

Cho

i got sensor value but may be 30~50%

Armaan-Ul- Islam

Good to know. On Emulator or Samsung Gear S2 ?

Cho

samsung gear S2