public void onSensorChanged(long timestamp,float values[]){
  if (Math.abs(timestamp - mLastTimestamp) > MAX_PERMITTED_TIME_BETWEEN_SAMPLES_NANOS) {
    clearEnergySamplesList();
    if (DEBUG) {
      Log.v("threeDSensorTapDetector","Discontinuity in input time");
    }
    if (mCurrentState != SensorDetectorState.TOO_NOISY) {
      changeToNewCurrentState(timestamp,SensorDetectorState.TOO_NOISY);
    }
  }
  mLastTimestamp=timestamp;
  mLastConditionedMagnitudeSq=0f;
  for (int i=0; i < NUMBER_OF_DIMENSIONS; ++i) {
    mLastFilterOutput[i]=mDetectorType.filterNum[0] * values[i] + mDetectorType.filterNum[1] * mLastInput[i] - mDetectorType.filterDen[1] * mLastFilterOutput[i];
    mLastInput[i]=values[i];
    mLastConditionedMagnitudeSq+=mLastFilterOutput[i] * mLastFilterOutput[i];
  }
  mConditionedSignalEnergy+=mLastConditionedMagnitudeSq;
  mEnergySamplesList.addLast(new EnergySamplePair(timestamp,mLastConditionedMagnitudeSq));
  while (mEnergySamplesList.getFirst().mTime <= timestamp - ENERGY_HISTORY_LENGTH_NANOS) {
    mConditionedSignalEnergy-=mEnergySamplesList.getFirst().mValue;
    mEnergySamplesList.removeFirst();
  }
  if (DEBUG) {
    Log.v("threeDSensorTapDetector",String.format("State %s, CurrentEnergy %f, size %d, limit %f, signal %f",mCurrentState.name(),mConditionedSignalEnergy,mEnergySamplesList.size(),mEnergySamplesList.size() * mDetectorType.energyPerSampleNoiseLimit,mLastConditionedMagnitudeSq));
  }
switch (mCurrentState) {
case NO_TAP:
    stateMachineNoTap(timestamp);
  break;
case PROCESSING_CANDIDATE_DEFINITE_TAP:
stateMachineProcessingDefiniteTap(timestamp);
break;
case PROCESSING_CANDIDATE_POSSIBLE_TAP:
stateMachineProcessingPossibleTap(timestamp);
break;
case TOO_NOISY:
stateMachineTooNoisy(timestamp);
break;
case DEFINITE_TAP:
case POSSIBLE_TAP:
changeToNewCurrentState(timestamp,SensorDetectorState.TOO_NOISY);
break;
default :
}
}

public void onSensorChanged ( long timestamp , float values [ ] ) { if ( Math . abs ( timestamp - mLastTimestamp ) > MAX_PERMITTED_TIME_BETWEEN_SAMPLES_NANOS ) { clearEnergySamplesList ( ) ; if ( DEBUG ) { Log . v ( "threeDSensorTapDetector" , "Discontinuity in input time" ) ; } if ( mCurrentState != SensorDetectorState . TOO_NOISY ) { changeToNewCurrentState ( timestamp , SensorDetectorState . TOO_NOISY ) ; } } mLastTimestamp = timestamp ; mLastConditionedMagnitudeSq = 0f ; for ( int i = 0 ; i < NUMBER_OF_DIMENSIONS ; ++ i ) { mLastFilterOutput [ i ] = mDetectorType . filterNum [ 0 ] * values [ i ] + mDetectorType . filterNum [ 1 ] * mLastInput [ i ] - mDetectorType . filterDen [ 1 ] * mLastFilterOutput [ i ] ; mLastInput [ i ] = values [ i ] ; mLastConditionedMagnitudeSq += mLastFilterOutput [ i ] * mLastFilterOutput [ i ] ; } mConditionedSignalEnergy += mLastConditionedMagnitudeSq ; mEnergySamplesList . addLast ( new EnergySamplePair ( timestamp , mLastConditionedMagnitudeSq ) ) ; while ( mEnergySamplesList . getFirst ( ) . mTime <= timestamp - ENERGY_HISTORY_LENGTH_NANOS ) { mConditionedSignalEnergy -= mEnergySamplesList . getFirst ( ) . mValue ; mEnergySamplesList . removeFirst ( ) ; } if ( DEBUG ) { Log . v ( "threeDSensorTapDetector" , String . format ( "State %s, CurrentEnergy %f, size %d, limit %f, signal %f" , mCurrentState . name ( ) , mConditionedSignalEnergy , mEnergySamplesList . size ( ) , mEnergySamplesList . size ( ) * mDetectorType . energyPerSampleNoiseLimit , mLastConditionedMagnitudeSq ) ) ; } switch ( mCurrentState ) { case NO_TAP : stateMachineNoTap ( timestamp ) ; break ; case PROCESSING_CANDIDATE_DEFINITE_TAP : stateMachineProcessingDefiniteTap ( timestamp ) ; break ; case PROCESSING_CANDIDATE_POSSIBLE_TAP : stateMachineProcessingPossibleTap ( timestamp ) ; break ; case TOO_NOISY : stateMachineTooNoisy ( timestamp ) ; break ; case DEFINITE_TAP : case POSSIBLE_TAP : changeToNewCurrentState ( timestamp , SensorDetectorState . TOO_NOISY ) ; break ; default : } }
call with updates from accelerometer sensor . parameters are from the sensorevent .
