android - Using accelerometer and magnetic sensor to detect the directions -


i working on android project need detect exact directions when user turns (i.e. left or right or bottom or top). have found directions using accelerometer magnetic sensor, couldn't fix maximum values turned.

the problem face this: unable make detect center point/position.

when user turns phone left central position, detects left turn.

however, when return position central position, phone detects 2 movements: both left. understanding this: if sensor had got central position (point of origin) correctly fixed, movements correctly detected. but, because central position not fixed, not happening.

kindly guide me in fixing it. let me know if need further clarifications.

my code below

public void onsensorchanged(sensorevent event) {              azimuth = event.values[0];  // azimuth             pitch = event.values[1];    // pitch             roll = event.values[2];     // roll              if (pitch < -45 && pitch > -135) {                 // top                  currentside = side.top;             } else if (pitch > 45 && pitch < 135) {                 // bottom                 currentside = side.bottom;             } else if (roll > 45) {                 // right                 currentside = side.right;             } else if (roll < -45) {                 // left                 currentside = side.left;             }              if (currentside != null && !currentside.equals(oldside)) {                 switch (currentside) {                     case top :                          listener.ontopup();                         break;                     case bottom :                          listener.onbottomup();                         break;                     case left:                          listener.onleftup();                         break;                     case right:                          listener.onrightup();                         break;                 }                 oldside = currentside;             }              // forwards orientation orientationlistener             listener.onorientationchanged(azimuth, pitch, roll);         } 

thanks helping!


Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -