feat(network): add signal strength percentage
parent
aab9625182
commit
c52b0c5f03
|
@ -31,6 +31,7 @@ namespace waybar::modules {
|
||||||
Json::Value _config;
|
Json::Value _config;
|
||||||
std::size_t _ifid;
|
std::size_t _ifid;
|
||||||
std::string _essid;
|
std::string _essid;
|
||||||
|
int _signalStrengthdBm;
|
||||||
int _signalStrength;
|
int _signalStrength;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
},
|
},
|
||||||
"network": {
|
"network": {
|
||||||
"interface": "wlp2s0",
|
"interface": "wlp2s0",
|
||||||
"format": "{essid} ({signalStrength}dBm) "
|
"format": "{essid} ({signalStrength}%) "
|
||||||
},
|
},
|
||||||
"pulseaudio": {
|
"pulseaudio": {
|
||||||
"format": "{}% ",
|
"format": "{}% ",
|
||||||
|
|
|
@ -18,6 +18,7 @@ auto waybar::modules::Network::update() -> void
|
||||||
auto format = _config["format"] ? _config["format"].asString() : "{}";
|
auto format = _config["format"] ? _config["format"].asString() : "{}";
|
||||||
_label.set_text(fmt::format(format,
|
_label.set_text(fmt::format(format,
|
||||||
fmt::arg("essid", _essid),
|
fmt::arg("essid", _essid),
|
||||||
|
fmt::arg("signaldBm", _signalStrengthdBm),
|
||||||
fmt::arg("signalStrength", _signalStrength)
|
fmt::arg("signalStrength", _signalStrength)
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
@ -75,8 +76,14 @@ void waybar::modules::Network::_parseEssid(struct nlattr **bss)
|
||||||
void waybar::modules::Network::_parseSignal(struct nlattr **bss) {
|
void waybar::modules::Network::_parseSignal(struct nlattr **bss) {
|
||||||
if (bss[NL80211_BSS_SIGNAL_MBM] != nullptr) {
|
if (bss[NL80211_BSS_SIGNAL_MBM] != nullptr) {
|
||||||
// signalstrength in dBm
|
// signalstrength in dBm
|
||||||
_signalStrength =
|
_signalStrengthdBm =
|
||||||
static_cast<int>(nla_get_u32(bss[NL80211_BSS_SIGNAL_MBM])) / 100;
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue