fix(net): Convert dBm to percentage

Fixes #249
This commit is contained in:
Michael Carlberg 2016-12-23 08:13:32 +01:00
parent e551dbfea9
commit 7ecd132610
2 changed files with 6 additions and 4 deletions

View File

@ -13,6 +13,7 @@
#include "common.hpp"
#include "config.hpp"
#include "errors.hpp"
#include "utils/math.hpp"
POLYBAR_NS
@ -30,9 +31,10 @@ namespace net {
int max{0};
int percentage() const {
if (max < 0)
return 2 * (val + 100);
return static_cast<float>(val) / max * 100.0f + 0.5f;
if (val < 0) {
return std::max(std::min(std::abs(math_util::percentage(val, max, -20)), 100), 0);
}
return std::max(std::min(math_util::percentage(val, 0, max), 100), 0);
}
};

View File

@ -392,7 +392,7 @@ namespace net {
// Check if the values are defined in dBm
if (stats.qual.level > range.max_qual.level) {
m_signalstrength.val -= 0x100;
m_signalstrength.max -= 0x100;
m_signalstrength.max = (stats.qual.level - range.max_qual.level) - 0x100;
}
}
}