Android accelerometer stability -


i trying use accelerometer detect flipping phone in 4 different angles face down (left, right, right side up, upside down) , whether done fast or slow. want stop checking after 30 degrees of flipping phone.

my problem getting stability. work once in while , not work.

@override public void oncreate(bundle savedinstancestate) {      super.oncreate(savedinstancestate);      ...      msensormanager = (sensormanager) getsystemservice(sensor_service);      maccelerometer = msensormanager.getdefaultsensor(sensor.type_accelerometer);  }  @override protected void onresume() {     super.onresume();      ...      msensormanager.registerlistener(this, maccelerometer, sensormanager.sensor_delay_ui); }  @override public void onsensorchanged(sensorevent event) {      prets = ts;     prex = x;     prey = y;     prez = z;      realx = event.values[0];     realy = event.values[1];     realz = event.values[2];      x = math.abs(event.values[0]);     y = math.abs(event.values[1]);     z = math.abs(event.values[2]);     ts = event.timestamp;      if (x < 2 && y < 1) {          npsx = ((ts - prets) * math.abs(x - prex)) / 100000;         npsy = ((ts - prets) * math.abs(y - prey)) / 100000;         npsz = ((ts - prets) * math.abs(z - prez)) / 100000;     }      maxx = (maxx > npsx) ? maxx : npsx;     maxy = (maxy > npsy) ? maxy : npsy;     maxz = (maxz > npsz) ? maxz : npsz;      if(x < 1 && y < 1 && z > 9) {          maxx = 0;         maxy = 0;         maxz = 0;         dir = "";         speed = "";     }      if (objects.equals(dir, "") || objects.equals(speed, "")) {          if (realx >= 2) {              dir = "left";          } else if (realx <= -2) {              dir = "right";          } else if (realy >= 2) {              dir = "up";          } else if (realy <= -2) {              dir = "down";         }          if (maxx > 250 || maxy > 250 || maxz > 250)              speed = "fast";          else              speed = "slow";     }      log.i("ma", (int) maxx + " " + (int) maxy + " " + (int) maxz + " " + x + " " + y + " " +             z + " " + speed + " " + dir + " " + realx + " " + realy + " " + realz);  } 


Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -