From 592b90cf5a1b09aa1ddc8ef8e2147a08fc82a40a Mon Sep 17 00:00:00 2001 From: FrogAi <91348155+FrogAi@users.noreply.github.com> Date: Sat, 8 Jun 2024 13:31:48 -0700 Subject: [PATCH] Controls - Experimental Mode Activation - Double Tap the UI Enable/disable 'Experimental Mode' by double tapping the onroad UI within a 0.5 second time frame. --- selfdrive/ui/qt/onroad/onroad_home.cc | 25 +++++++++++++++++++++++++ selfdrive/ui/qt/onroad/onroad_home.h | 4 ++++ selfdrive/ui/ui.cc | 2 ++ selfdrive/ui/ui.h | 1 + 4 files changed, 32 insertions(+) diff --git a/selfdrive/ui/qt/onroad/onroad_home.cc b/selfdrive/ui/qt/onroad/onroad_home.cc index 9060724c7..829e8cec6 100644 --- a/selfdrive/ui/qt/onroad/onroad_home.cc +++ b/selfdrive/ui/qt/onroad/onroad_home.cc @@ -1,5 +1,6 @@ #include "selfdrive/ui/qt/onroad/onroad_home.h" +#include #include #include @@ -48,6 +49,13 @@ OnroadWindow::OnroadWindow(QWidget *parent) : QWidget(parent) { QObject::connect(uiState(), &UIState::uiUpdate, this, &OnroadWindow::updateState); QObject::connect(uiState(), &UIState::offroadTransition, this, &OnroadWindow::offroadTransition); QObject::connect(uiState(), &UIState::primeChanged, this, &OnroadWindow::primeChanged); + + // FrogPilot variables + QObject::connect(&clickTimer, &QTimer::timeout, this, [this]() { + clickTimer.stop(); + QMouseEvent *event = new QMouseEvent(QEvent::MouseButtonPress, timeoutPoint, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier); + QApplication::postEvent(this, event); + }); } void OnroadWindow::updateState(const UIState &s) { @@ -89,6 +97,23 @@ void OnroadWindow::mousePressEvent(QMouseEvent* e) { // FrogPilot clickable widgets QPoint pos = e->pos(); + if (scene.experimental_mode_via_screen && pos != timeoutPoint) { + if (clickTimer.isActive()) { + clickTimer.stop(); + + if (scene.conditional_experimental) { + int override_value = (scene.conditional_status >= 1 && scene.conditional_status <= 6) ? 0 : (scene.conditional_status >= 7 ? 5 : 6); + paramsMemory.putIntNonBlocking("CEStatus", override_value); + } else { + params.putBoolNonBlocking("ExperimentalMode", !params.getBool("ExperimentalMode")); + } + + } else { + clickTimer.start(500); + } + return; + } + #ifdef ENABLE_MAPS if (map != nullptr) { // Switch between map and sidebar when using navigate on openpilot diff --git a/selfdrive/ui/qt/onroad/onroad_home.h b/selfdrive/ui/qt/onroad/onroad_home.h index 518ac9cc2..c903c36cf 100644 --- a/selfdrive/ui/qt/onroad/onroad_home.h +++ b/selfdrive/ui/qt/onroad/onroad_home.h @@ -25,6 +25,10 @@ private: QHBoxLayout* split; // FrogPilot variables + QPoint timeoutPoint = QPoint(420, 69); + + QTimer clickTimer; + Params params; Params paramsMemory{"/dev/shm/params"}; diff --git a/selfdrive/ui/ui.cc b/selfdrive/ui/ui.cc index 28876cf14..b5322e9e0 100644 --- a/selfdrive/ui/ui.cc +++ b/selfdrive/ui/ui.cc @@ -282,6 +282,8 @@ void ui_update_frogpilot_params(UIState *s, Params ¶ms) { scene.onroad_distance_button = driving_personalities && params.getBool("OnroadDistanceButton"); scene.use_kaofui_icons = scene.onroad_distance_button && params.getBool("KaofuiIcons"); + scene.experimental_mode_via_screen = scene.longitudinal_control && params.getBool("ExperimentalModeActivation") && params.getBool("ExperimentalModeViaTap"); + scene.tethering_config = params.getInt("TetheringEnabled"); if (scene.tethering_config == 2) { WifiManager(s).setTetheringEnabled(true); diff --git a/selfdrive/ui/ui.h b/selfdrive/ui/ui.h index 2cf2cc625..80ee915ce 100644 --- a/selfdrive/ui/ui.h +++ b/selfdrive/ui/ui.h @@ -124,6 +124,7 @@ typedef struct UIScene { bool conditional_experimental; bool enabled; bool experimental_mode; + bool experimental_mode_via_screen; bool map_open; bool online; bool onroad_distance_button;