apexer
apexer

Reputation: 143

What are the possible input values of numLevels Wifimanager.calculateSignalLevel method?

/** * Calculates the level of the signal. This should be used any time a signal * is being shown. * * @param rssi The power of the signal measured in RSSI. * @param numLevels The number of levels to consider in the calculated * level. * @return A level of the signal, given in the range of 0 to numLevels-1 * (both inclusive). */

public static int calculateSignalLevel(int rssi, int numLevels) {
    if (rssi <= MIN_RSSI) {
        return 0;
    } else if (rssi >= MAX_RSSI) {
        return numLevels - 1;
    } else {
        float inputRange = (MAX_RSSI - MIN_RSSI);
        float outputRange = (numLevels - 1);
        return (int)((float)(rssi - MIN_RSSI) * outputRange / inputRange);
    }
}

Could any anyone please explain me that what is the input of numLevels param? I need to show the Wifi Signal Strength like "good,better,best" based on the output of this method.please help me !!

Upvotes: 1

Views: 2072

Answers (1)

nderjung
nderjung

Reputation: 1617

numLevels is literally the number of levels you wish to evaluate the strength of the wifi signal. For instance, a choice of

int numLevels = 5;
int strength = calculateSignalLevel(rssi, numLevels);

will give you an output range from 0 to 4 (as numbLevels - 1 = 4), where 4 is the strongest.

Since you want to evaluate the signal strength on a 'good', 'better', and 'best' scale, you should input 3 as your numLevels parameter.

Upvotes: 2

Related Questions