private double calculateAccuracy( int rssi) {
if (rssi == 0) {
return -1.0; // if we cannot determine accuracy, return -1.
}
double ratio = rssi * 1.0 / 55;
if (ratio < 1.0) {
return changeTwoDecimal_f(Math.pow(ratio, 10));
} else {
double accuracy = (0.89976) * Math.pow(ratio, 7.7095) + 0.111;
return changeTwoDecimal_f(accuracy);
}
}
private double changeTwoDecimal_f(double floatvar) {
double i = Math.round(floatvar * 100);
double f_x = i / 100;
String s_x = f_x + "";
int pos_decimal = s_x.indexOf('.');
if (pos_decimal < 0) {
pos_decimal = s_x.length();
s_x += '.';
}
while (s_x.length() <= pos_decimal + 2) {
s_x += "0";
}
return Double.parseDouble(s_x);
}
蓝牙计算距离
最新推荐文章于 2022-10-18 17:51:46 发布