dimanche 21 avril 2019

Code gets executed only once without resetting the variables

Trying to make my Fitbit work with an Android app. It helps detecting falls and send sms notification to family members.

THe way it should work is: Using Fitbit's acceleration, it detects a fall and sends a continuous beep on the smartphone and you have to reset it manually in 10-15 seconds to avoid getting false falls (the algorithm for fall detection is not 100% accurate so it should give you time to reset it). Once manually resetted,it should work again.

How it works: It just beeps once and automatically gets resetted. It works again later,yes it does but still same issue. I was hoping I could either solve it by adding a time delay of 20 seconds although I know that's not the best practice at all.

Tried adding a return inside the last If conditional but didn't change a thing. Thought using a do-while but still nothing

 public void checkFall() {
    int i,j;
    double minAcc, maxAcc;

    long fallWindowSamp = (mFallWindow*mSdData.mSampleFreq)/1000; // Convert ms to samples.
    Log.v(TAG, "check_fall() - fallWindowSamp=" +fallWindowSamp);
    // Move window through sample buffer, checking for fall.
    mSdData.fallAlarmStanding = false;
    if (mFallActive) {
        for (i = 0; i < mSdData.mNsamp - fallWindowSamp; i++) {  // i = window start point
            // Find max and min acceleration within window.
            minAcc = mSdData.rawData[i];
            maxAcc = mSdData.rawData[i];
            for (j = 0; j < fallWindowSamp; j++) {  // j = position within window
                if (mSdData.rawData[i + j] < minAcc) minAcc = mSdData.rawData[i + j];
                if (mSdData.rawData[i + j] > maxAcc) maxAcc = mSdData.rawData[i + j];
            }
            if ((minAcc < mFallThreshMin) && (maxAcc > mFallThreshMax)) {
                Log.d(TAG, "check_fall() - minAcc=" + minAcc + ", maxAcc=" + maxAcc);
                Log.d(TAG, "check_fall() - ****FALL DETECTED****");
                mSdData.fallAlarmStanding = true;
              //  return;
            }
        }
    } else {
        Log.v(TAG,"check_fall - mFallActive is false - doing nothing");
    }
    //if (debug) APP_LOG(APP_LOG_LEVEL_DEBUG,"check_fall() - minAcc=%d, maxAcc=%d",
    //    minAcc,maxAcc);

}

Aucun commentaire:

Enregistrer un commentaire