diff --git a/selfdrive/ui/qt/network/networking.cc b/selfdrive/ui/qt/network/networking.cc index d7cdddff4..64863a85a 100644 --- a/selfdrive/ui/qt/network/networking.cc +++ b/selfdrive/ui/qt/network/networking.cc @@ -127,9 +127,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")); @@ -221,9 +224,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 9b6af005e..1c9c535d0 100644 --- a/selfdrive/ui/qt/network/networking.h +++ b/selfdrive/ui/qt/network/networking.h @@ -7,6 +7,8 @@ #include "selfdrive/ui/qt/widgets/ssh_keys.h" #include "selfdrive/ui/qt/widgets/toggle.h" +#include "selfdrive/frogpilot/ui/qt/widgets/frogpilot_controls.h" + class WifiItem : public QWidget { Q_OBJECT public: @@ -59,7 +61,7 @@ public: private: LabelControl* ipLabel; - ToggleControl* tetheringToggle; + FrogPilotButtonParamControl* tetheringToggle; ToggleControl* roamingToggle; ButtonControl* editApnButton; ButtonControl* hiddenNetworkButton; @@ -72,7 +74,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 030eb964b..c4f6bdb34 100644 --- a/selfdrive/ui/ui.cc +++ b/selfdrive/ui/ui.cc @@ -267,6 +267,11 @@ void ui_update_frogpilot_params(UIState *s) { cereal::CarParams::Reader CP = cmsg.getRoot(); scene.longitudinal_control = CP.getOpenpilotLongitudinalControl() && !params.getBool("DisableOpenpilotLongitudinal"); } + + scene.tethering_config = params.getInt("TetheringEnabled"); + if (scene.tethering_config == 2) { + WifiManager(s).setTetheringEnabled(true); + } } void UIState::updateStatus() { @@ -289,6 +294,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); + } } } @@ -314,6 +322,8 @@ UIState::UIState(QObject *parent) : QObject(parent) { timer->start(1000 / UI_FREQ); // FrogPilot variables + wifi = new WifiManager(this); + ui_update_frogpilot_params(this); } diff --git a/selfdrive/ui/ui.h b/selfdrive/ui/ui.h index 93b8962bf..941332234 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 "system/hardware/hw.h" #include "selfdrive/frogpilot/ui/qt/widgets/frogpilot_controls.h" @@ -120,8 +121,10 @@ typedef struct UIScene { bool online; bool parked; bool right_hand_drive; + bool tethering_enabled; int alert_size; + int tethering_config; } UIScene; @@ -150,6 +153,9 @@ public: QTransform car_space_transform; + // FrogPilot variables + WifiManager *wifi = nullptr; + signals: void uiUpdate(const UIState &s); void offroadTransition(bool offroad);