feat(network): add signal strength percentage

This commit is contained in:
Alexis 2018-08-10 10:45:13 +02:00
parent aab9625182
commit c52b0c5f03
3 changed files with 10 additions and 2 deletions

View File

@ -31,6 +31,7 @@ namespace waybar::modules {
Json::Value _config;
std::size_t _ifid;
std::string _essid;
int _signalStrengthdBm;
int _signalStrength;
};

View File

@ -12,7 +12,7 @@
},
"network": {
"interface": "wlp2s0",
"format": "{essid} ({signalStrength}dBm) "
"format": "{essid} ({signalStrength}%) "
},
"pulseaudio": {
"format": "{}% ",

View File

@ -18,6 +18,7 @@ auto waybar::modules::Network::update() -> void
auto format = _config["format"] ? _config["format"].asString() : "{}";
_label.set_text(fmt::format(format,
fmt::arg("essid", _essid),
fmt::arg("signaldBm", _signalStrengthdBm),
fmt::arg("signalStrength", _signalStrength)
));
}
@ -75,8 +76,14 @@ void waybar::modules::Network::_parseEssid(struct nlattr **bss)
void waybar::modules::Network::_parseSignal(struct nlattr **bss) {
if (bss[NL80211_BSS_SIGNAL_MBM] != nullptr) {
// signalstrength in dBm
_signalStrength =
_signalStrengthdBm =
static_cast<int>(nla_get_u32(bss[NL80211_BSS_SIGNAL_MBM])) / 100;
// WiFi-hardware usually operates in the range -90 to -20dBm.
const int hardwareMax = -20;
const int hardwareMin = -90;
_signalStrength = ((double)(_signalStrengthdBm - hardwareMin)
/ (double)(hardwareMax - hardwareMin)) * 100;
}
}