From a37d8e5830024ef0800bd6954cedfc5f8ef799ea Mon Sep 17 00:00:00 2001 From: FrogAi <91348155+FrogAi@users.noreply.github.com> Date: Fri, 12 Jan 2024 22:39:30 -0700 Subject: [PATCH] Retain tethering status between reboots --- common/params.cc | 1 + selfdrive/ui/qt/network/networking.cc | 6 ++++++ selfdrive/ui/qt/widgets/controls.h | 4 ++++ selfdrive/ui/ui.cc | 3 +++ selfdrive/ui/ui.h | 4 ++++ selfdrive/updated.py | 0 6 files changed, 18 insertions(+) mode change 100755 => 100644 selfdrive/updated.py diff --git a/common/params.cc b/common/params.cc index 8fdeef8..37de56a 100644 --- a/common/params.cc +++ b/common/params.cc @@ -316,6 +316,7 @@ std::unordered_map keys = { {"StandardFollow", PERSISTENT}, {"StandardJerk", PERSISTENT}, {"StoppingDistance", PERSISTENT}, + {"TetheringEnabled", PERSISTENT}, {"UnlimitedLength", PERSISTENT}, {"Updated", PERSISTENT}, {"UpdateSchedule", PERSISTENT}, diff --git a/selfdrive/ui/qt/network/networking.cc b/selfdrive/ui/qt/network/networking.cc index 729708e..80c481b 100644 --- a/selfdrive/ui/qt/network/networking.cc +++ b/selfdrive/ui/qt/network/networking.cc @@ -130,6 +130,10 @@ AdvancedNetworking::AdvancedNetworking(QWidget* parent, WifiManager* wifi): QWid tetheringToggle = new ToggleControl(tr("Enable Tethering"), "", "", wifi->isTetheringEnabled()); list->addItem(tetheringToggle); QObject::connect(tetheringToggle, &ToggleControl::toggleFlipped, this, &AdvancedNetworking::toggleTethering); + if (params.getBool("TetheringEnabled")) { + tetheringToggle->setVisualOn(); + uiState()->scene.tethering_enabled = true; + } // Change tethering password ButtonControl *editPasswordButton = new ButtonControl(tr("Tethering Password"), tr("EDIT")); @@ -232,6 +236,8 @@ void AdvancedNetworking::refresh() { void AdvancedNetworking::toggleTethering(bool enabled) { wifi->setTetheringEnabled(enabled); tetheringToggle->setEnabled(false); + params.putBool("TetheringEnabled", enabled); + uiState()->scene.tethering_enabled = enabled; } // WifiUI functions diff --git a/selfdrive/ui/qt/widgets/controls.h b/selfdrive/ui/qt/widgets/controls.h index e4630c6..e3a9ca1 100644 --- a/selfdrive/ui/qt/widgets/controls.h +++ b/selfdrive/ui/qt/widgets/controls.h @@ -127,6 +127,10 @@ public: QObject::connect(&toggle, &Toggle::stateChanged, this, &ToggleControl::toggleFlipped); } + void setVisualOn() { + toggle.togglePosition(); + } + void setEnabled(bool enabled) { toggle.setEnabled(enabled); toggle.update(); diff --git a/selfdrive/ui/ui.cc b/selfdrive/ui/ui.cc index ea13c05..e63c9ae 100644 --- a/selfdrive/ui/ui.cc +++ b/selfdrive/ui/ui.cc @@ -342,6 +342,7 @@ void UIState::updateStatus() { started_prev = scene.started; scene.world_objects_visible = false; emit offroadTransition(!scene.started); + wifi->setTetheringEnabled(scene.started && scene.tethering_enabled); } } @@ -365,6 +366,8 @@ UIState::UIState(QObject *parent) : QObject(parent) { QObject::connect(timer, &QTimer::timeout, this, &UIState::update); timer->start(1000 / UI_FREQ); + wifi = new WifiManager(this); + scene.screen_brightness = params.getInt("ScreenBrightness"); setDefaultParams(); diff --git a/selfdrive/ui/ui.h b/selfdrive/ui/ui.h index ad556d7..7a3b3bc 100644 --- a/selfdrive/ui/ui.h +++ b/selfdrive/ui/ui.h @@ -15,6 +15,7 @@ #include "common/mat.h" #include "common/params.h" #include "common/timing.h" +#include "selfdrive/ui/qt/network/wifi_manager.h" #include "system/hardware/hw.h" const int UI_BORDER_SIZE = 30; @@ -191,6 +192,7 @@ typedef struct UIScene { bool road_name_ui; bool show_driver_camera; bool show_fps; + bool tethering_enabled; bool turn_signal_left; bool turn_signal_right; bool unlimited_road_ui_length; @@ -261,6 +263,8 @@ private: QTimer *timer; bool started_prev = false; PrimeType prime_type = PrimeType::UNKNOWN; + + WifiManager *wifi = nullptr; }; UIState *uiState(); diff --git a/selfdrive/updated.py b/selfdrive/updated.py old mode 100755 new mode 100644