UI: make wifi network sorting more stable (#29376)

* stable sort

* fix typo,rename to strengthLevel
old-commit-hash: 01089cf4bf
beeps
Dean Lee 2 years ago committed by GitHub
parent 431797307d
commit 25df6335f7
  1. 2
      selfdrive/ui/qt/offroad/networking.cc
  2. 7
      selfdrive/ui/qt/offroad/wifiManager.cc
  3. 1
      selfdrive/ui/qt/offroad/wifiManager.h

@ -295,7 +295,7 @@ void WifiUI::refresh() {
status_icon = lock; status_icon = lock;
} }
bool show_forget_btn = wifi->isKnownConnection(network.ssid) && !is_tethering_enabled; bool show_forget_btn = wifi->isKnownConnection(network.ssid) && !is_tethering_enabled;
QPixmap strength = strengths[std::clamp((int)round(network.strength / 33.), 0, 3)]; QPixmap strength = strengths[strengthLevel(network.strength)];
auto item = getItem(n++); auto item = getItem(n++);
item->setItem(network, status_icon, show_forget_btn, strength); item->setItem(network, status_icon, show_forget_btn, strength);

@ -8,11 +8,8 @@
#include "selfdrive/ui/qt/util.h" #include "selfdrive/ui/qt/util.h"
bool compare_by_strength(const Network &a, const Network &b) { bool compare_by_strength(const Network &a, const Network &b) {
if (a.connected == ConnectedType::CONNECTED) return true; return std::tuple(a.connected, strengthLevel(a.strength), b.ssid) >
if (b.connected == ConnectedType::CONNECTED) return false; std::tuple(b.connected, strengthLevel(b.strength), a.ssid);
if (a.connected == ConnectedType::CONNECTING) return true;
if (b.connected == ConnectedType::CONNECTING) return false;
return a.strength > b.strength;
} }
template <typename T = QDBusMessage, typename... Args> template <typename T = QDBusMessage, typename... Args>

@ -33,6 +33,7 @@ struct Network {
SecurityType security_type; SecurityType security_type;
}; };
bool compare_by_strength(const Network &a, const Network &b); bool compare_by_strength(const Network &a, const Network &b);
inline int strengthLevel(unsigned int strength) { return std::clamp((int)round(strength / 33.), 0, 3); }
class WifiManager : public QObject { class WifiManager : public QObject {
Q_OBJECT Q_OBJECT

Loading…
Cancel
Save