Languages

Menu
Sites
Language
Detect phone is turned 360 degrees around

How do i know when the phone is turned 360 degrees from the position it is at. Suppose the phone is currently \ slanting. And then i turned it in a way that the back side is facing. There can be many scenerios but the key difference is that the mobile is turned arouned facing back from initial wayit is held in hand. The initial position can be slanting need not be flat horiontally or even vertical.

Think that i am taking a pick of an object using rear camera and then again using the front facing camera. This is the way the phone is fliped.

 

Aashish

Responses

4 Replies
Shaswati Saha

Hello,
So far I could understand you can detect the device orientation upto 270 degrees. Please go through the Function Documentation section of the link below:

https://developer.tizen.org/zh-hans/development/api-references/native-application?redirect=/dev-guide/2.3.1/org.tizen.native.mobile.apireference/group__CAPI__APP__COMMON__MODULE.html#gab311ebf53f6f3d68118f93797c05b7eb

Thanks.

Ashish Patil

Well it is not orientation that i want to know. And i am sorry if you dint undestand my requirements.

 

Aashish

Shaswati Saha

 Hello,

In that case you may use Accelerometer Sensor to detect a flip. When you are taking a pick of an object using rear camera Z component of accelerometer returns a positive(+) value and when again using the front facing camera Z component of accelerometer returns a negative (-) value. Now you can try this trick...

#include <sensor.h>
float z1=0    //previous data
float z2;		 //present data
//sensor event callback - invoked whenever a change in sensor data occur
void accelerometer _event_callback(sensor_h sensor, sensor_event_s *event, void *user_data) {
	z2= event->values[2];   //current z index value
	if(z1==0)  //first reading
		z1=z2;
	else {	//previous data exists
		if (z1*z2<0) {	//A flip occurred  -previous and present data 1 positive & 1 negative 
		if(z2=>0){
//currently front facing
}
else if(z2<0){
//currently rear facing
}
}
else{
	//not a flip
}
}
  }
// Initial setup
sensor_h sensor;      sensor_listener_h listener;
sensor_type_e  type = SENSOR_ACCELEROMETER;
sensor_get_default_sensor(type, &sensor); 
sensor_create_listener(sensor, &listener);
sensor_listener_set_event_cb(listener, 100, accelerometer _event_callback, NULL);
 sensor_listener_start(listener) ;

/*Stop the sensor after the task  is done*/
//sensor_listener_stop(listener);
//sensor_destroy_listener(listener);

If you want to check some basics on ‘how to work with sensor data’ in tizen native application development you may go through the sensor guide or sensor API references.
https://developer.tizen.org/development/guides/native-application/location-and-sensors/sensors

https://developer.tizen.org/development/api-references/native-application?redirect=https://developer.tizen.org/dev-guide/2.4.0/org.tizen.native.mobile.apireference/group__CAPI__SYSTEM__SENSOR__MODULE.html

Thanks.

Ashish Patil

Hi Shaswati Saha,

I was aware that accelemeter can be used here. The tip worked well.

 

Thanks