From 1636233047e5b8a29f5565feb110dfa39f3927ce Mon Sep 17 00:00:00 2001 From: FrogAi <91348155+FrogAi@users.noreply.github.com> Date: Sat, 15 Jun 2024 04:13:53 -0700 Subject: [PATCH] FrogPilot features - Enable tethering when going onroad / all the time --- selfdrive/ui/qt/network/networking.cc | 12 ++++++++---- selfdrive/ui/qt/network/networking.h | 6 ++++-- selfdrive/ui/ui.cc | 10 ++++++++++ selfdrive/ui/ui.h | 6 ++++++ 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/selfdrive/ui/qt/network/networking.cc b/selfdrive/ui/qt/network/networking.cc index f09589492..e2b3c2b66 100644 --- a/selfdrive/ui/qt/network/networking.cc +++ b/selfdrive/ui/qt/network/networking.cc @@ -126,9 +126,12 @@ AdvancedNetworking::AdvancedNetworking(QWidget* parent, WifiManager* wifi): QWid ListWidget *list = new ListWidget(this); // Enable tethering layout - tetheringToggle = new ToggleControl(tr("Enable Tethering"), "", "", wifi->isTetheringEnabled()); + std::vector tetheringSelection{tr("Off"), tr("Only Onroad"), tr("Always")}; + tetheringToggle = new FrogPilotButtonParamControl("TetheringEnabled", "Enable Tethering", "", "", tetheringSelection); list->addItem(tetheringToggle); - QObject::connect(tetheringToggle, &ToggleControl::toggleFlipped, this, &AdvancedNetworking::toggleTethering); + QObject::connect(tetheringToggle, &FrogPilotButtonParamControl::buttonClicked, [this](int id) { + toggleTethering(id); + }); // Change tethering password ButtonControl *editPasswordButton = new ButtonControl(tr("Tethering Password"), tr("EDIT")); @@ -220,9 +223,10 @@ void AdvancedNetworking::refresh() { update(); } -void AdvancedNetworking::toggleTethering(bool enabled) { - wifi->setTetheringEnabled(enabled); +void AdvancedNetworking::toggleTethering(int id) { + wifi->setTetheringEnabled(id == 2); tetheringToggle->setEnabled(false); + updateFrogPilotToggles(); } // WifiUI functions diff --git a/selfdrive/ui/qt/network/networking.h b/selfdrive/ui/qt/network/networking.h index b835de50d..3fcc307c0 100644 --- a/selfdrive/ui/qt/network/networking.h +++ b/selfdrive/ui/qt/network/networking.h @@ -8,6 +8,8 @@ #include "selfdrive/ui/qt/widgets/toggle.h" #include "selfdrive/ui/ui.h" +#include "selfdrive/frogpilot/ui/qt/widgets/frogpilot_controls.h" + class WifiItem : public QWidget { Q_OBJECT public: @@ -63,7 +65,7 @@ public: private: LabelControl* ipLabel; - ToggleControl* tetheringToggle; + FrogPilotButtonParamControl* tetheringToggle; ToggleControl* roamingToggle; ButtonControl* editApnButton; ButtonControl* hiddenNetworkButton; @@ -76,7 +78,7 @@ signals: void requestWifiScreen(); public slots: - void toggleTethering(bool enabled); + void toggleTethering(int id); void refresh(); }; diff --git a/selfdrive/ui/ui.cc b/selfdrive/ui/ui.cc index 120d051e2..dfcaa2295 100644 --- a/selfdrive/ui/ui.cc +++ b/selfdrive/ui/ui.cc @@ -268,6 +268,11 @@ void ui_update_frogpilot_params(UIState *s, Params ¶ms) { cereal::CarParams::Reader CP = cmsg.getRoot(); scene.longitudinal_control = hasLongitudinalControl(CP); } + + scene.tethering_config = params.getInt("TetheringEnabled"); + if (scene.tethering_config == 2) { + WifiManager(s).setTetheringEnabled(true); + } } void UIState::updateStatus() { @@ -290,6 +295,9 @@ void UIState::updateStatus() { started_prev = scene.started; scene.world_objects_visible = false; emit offroadTransition(!scene.started); + if (scene.tethering_config == 1) { + wifi->setTetheringEnabled(scene.started); + } } } @@ -315,6 +323,8 @@ UIState::UIState(QObject *parent) : QObject(parent) { timer->start(1000 / UI_FREQ); // FrogPilot variables + wifi = new WifiManager(this); + ui_update_params(this); } diff --git a/selfdrive/ui/ui.h b/selfdrive/ui/ui.h index 382faba80..414d2478a 100644 --- a/selfdrive/ui/ui.h +++ b/selfdrive/ui/ui.h @@ -14,6 +14,7 @@ #include "common/mat.h" #include "common/params.h" #include "common/timing.h" +#include "selfdrive/ui/qt/network/wifi_manager.h" #include "selfdrive/ui/qt/util.h" #include "system/hardware/hw.h" @@ -121,8 +122,10 @@ typedef struct UIScene { bool online; bool parked; bool right_hand_drive; + bool tethering_enabled; int alert_size; + int tethering_config; } UIScene; @@ -151,6 +154,9 @@ public: QTransform car_space_transform; + // FrogPilot variables + WifiManager *wifi = nullptr; + signals: void uiUpdate(const UIState &s); void offroadTransition(bool offroad);