Skip to content

Commit

Permalink
add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
KimYoungBean committed Nov 29, 2017
1 parent 0780471 commit 459f88d
Showing 1 changed file with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ protected void onCreate(Bundle savedInstanceState) {

textView = (TextView) findViewById(R.id.tv_step);
}

/* start accelometerSensor listener */
@Override
public void onStart() {
super.onStart();
Expand All @@ -82,25 +82,28 @@ public void onDestroy() {
Log.e("LOG", "onDestroy()");
mSensorManager.unregisterListener(this);
}

/*
if accelerometer change, it occurs.
shake control
*/
@Override
public void onSensorChanged(SensorEvent event) {
if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
long currentTime = System.currentTimeMillis();
long gabOfTime = (currentTime - lastTime);
long currentTime = System.currentTimeMillis(); //current Time (per milliseconds)
long gabOfTime = (currentTime - lastTime); // gap of current and last time
if (gabOfTime > 100) {
lastTime = currentTime;
x = event.values[SensorManager.DATA_X];
y = event.values[SensorManager.DATA_Y];
z = event.values[SensorManager.DATA_Z];

speed = Math.abs(x + y + z - lastX - lastY - lastZ) / gabOfTime * 10000;

speed = Math.abs(x + y + z - lastX - lastY - lastZ) / gabOfTime * 10000; // abs(sum of values)
//SHAKE_THRESHOLD = 300
if (speed > SHAKE_THRESHOLD) {
//이벤트발생!!
isStep = false;
//event occured!!
isStep = false; // No count
} else {
isStep = true;
isStep = true; // count
}
lastX = event.values[DATA_X];
lastY = event.values[DATA_Y];
Expand Down

0 comments on commit 459f88d

Please sign in to comment.