android - How to detect end of IF loop when using sensorEventListener -


im getting linear acceleration phone , have problem. wanted i=i+1 if acceleration higher 10m/s add 1 once not time readings above 10 m/s. thinking getting moment when values getting down again below 10 , adding +1 i. can me?

for im doing works bad.

 @override public void onsensorchanged(sensorevent event) {      float x = event.values[0];     float y = event.values[1];     float z = event.values[2];     //odczytwyswx.settext(float.tostring(x));     //odczytwyswy.settext(float.tostring(y));     // odczytwyswz.settext(float.tostring(z));      if (event.sensor.gettype() == sensor.type_linear_acceleration) {         gravsensorvals = lowpass(event.values.clone(), gravsensorvals);         grav[0] = event.values[0];         grav[1] = event.values[1];         grav[2] = event.values[2];     }      odczytwyswz.settext(float.tostring(grav[2]));        wychwytywaniegornegotapniecia(); }     void wychwytywaniegornegotapniecia(){     if(grav[2]>10){   i++       } 

try using simple boolean in logic.

private boolean updatevalue; // field on class      if (grav[2] > 10 && updatevalue) {         i++;         updatevalue = false;     }      if (grav[2] < 10) {         updatevalue = true;     } 

Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -