From 6661c4dd8934033b1111b8c0851e1868bf33fe13 Mon Sep 17 00:00:00 2001 From: FrogAi <91348155+FrogAi@users.noreply.github.com> Date: Tue, 27 Feb 2024 16:34:47 -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 ++++ 5 files changed, 18 insertions(+) diff --git a/common/params.cc b/common/params.cc index fece057..84120e5 100644 --- a/common/params.cc +++ b/common/params.cc @@ -352,6 +352,7 @@ std::unordered_map keys = { {"StandardJerk", PERSISTENT}, {"StockTune", PERSISTENT}, {"StoppingDistance", PERSISTENT}, + {"TetheringEnabled", PERSISTENT}, {"UnlimitedLength", PERSISTENT}, {"UpdateSchedule", PERSISTENT}, {"UpdateTime", PERSISTENT}, diff --git a/selfdrive/ui/qt/network/networking.cc b/selfdrive/ui/qt/network/networking.cc index 5354a01..9f4598f 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->refresh(); + uiState()->scene.tethering_enabled = true; + } // Change tethering password ButtonControl *editPasswordButton = new ButtonControl(tr("Tethering Password"), tr("EDIT")); @@ -224,6 +228,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 8c4f06f..366376f 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 27cad0d..6c71546 100644 --- a/selfdrive/ui/ui.cc +++ b/selfdrive/ui/ui.cc @@ -370,6 +370,7 @@ void UIState::updateStatus() { started_prev = scene.started; scene.world_objects_visible = false; emit offroadTransition(!scene.started); + wifi->setTetheringEnabled(scene.started && scene.tethering_enabled); } } @@ -393,6 +394,8 @@ UIState::UIState(QObject *parent) : QObject(parent) { QObject::connect(timer, &QTimer::timeout, this, &UIState::update); timer->start(1000 / UI_FREQ); + wifi = new WifiManager(this); + ui_update_frogpilot_params(this); } diff --git a/selfdrive/ui/ui.h b/selfdrive/ui/ui.h index 43a5aa1..8d29556 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; @@ -206,6 +207,7 @@ typedef struct UIScene { bool road_name_ui; bool show_driver_camera; bool standstill; + bool tethering_enabled; bool turn_signal_left; bool turn_signal_right; bool unlimited_road_ui_length; @@ -264,6 +266,8 @@ public: QTransform car_space_transform; + WifiManager *wifi = nullptr; + signals: void uiUpdate(const UIState &s); void offroadTransition(bool offroad);