mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-08-08 19:25:42 +08:00
Refactor and enhance UI state and device classes for both base and sunny pilot
Various improvements have been made to UI state and device classes in both base and sunny pilot. This includes better organization of code, addition of new functionalities and removal of unused code and libraries. Each UI state update now also updates the sockets and the state itself. Conditions for brightness updates in deviceSP's methods are also simplified. This results in a more streamlined update process. Changes have been made to update the device brightness according to the specified parameters. If the screen is expected to be off, the brightness is set to 0. Otherwise, the brightness is set to a level according to the onroadScreenOffBrightness parameter. The rest of the changes involve cleaning up redundant code, updating includes, and removing unnecessary typecasts and conversions. The parameters updating are now handled more succinctly. Overall, the updated code provides a cleaner, more efficient implementation of the UI and devices.
This commit is contained in:
@@ -15,18 +15,6 @@ void drawIcon(QPainter &p, const QPoint ¢er, const QPixmap &img, const QBrus
|
||||
p.setOpacity(1.0);
|
||||
}
|
||||
|
||||
static void drawCustomButtonIcon(QPainter &p, const int btn_size_x, const int btn_size_y, const QPixmap &img, const QBrush &bg, float opacity) {
|
||||
QPoint center(btn_size_x / 2, btn_size_y / 2);
|
||||
p.setRenderHint(QPainter::Antialiasing);
|
||||
p.setOpacity(1.0); // bg dictates opacity of ellipse
|
||||
p.setPen(Qt::NoPen);
|
||||
p.setBrush(bg);
|
||||
p.drawEllipse(center, btn_size_x / 2, btn_size_y / 2);
|
||||
p.setOpacity(opacity);
|
||||
p.drawPixmap(center - QPoint(img.width() / 2, img.height() / 2), img);
|
||||
p.setOpacity(1.0);
|
||||
}
|
||||
|
||||
// ExperimentalButton
|
||||
ExperimentalButton::ExperimentalButton(QWidget *parent) : experimental_mode(false), engageable(false), QPushButton(parent) {
|
||||
setFixedSize(btn_size, btn_size);
|
||||
@@ -59,49 +47,4 @@ void ExperimentalButton::paintEvent(QPaintEvent *event) {
|
||||
QPainter p(this);
|
||||
QPixmap img = experimental_mode ? experimental_img : engage_img;
|
||||
drawIcon(p, QPoint(btn_size / 2, btn_size / 2), img, QColor(0, 0, 0, 166), (isDown() || !engageable) ? 0.6 : 1.0);
|
||||
}
|
||||
|
||||
|
||||
// MapSettingsButton
|
||||
MapSettingsButton::MapSettingsButton(QWidget *parent) : QPushButton(parent) {
|
||||
// btn_size: 192 * 80% ~= 152
|
||||
// img_size: (152 / 4) * 3 = 114
|
||||
setFixedSize(152, 152);
|
||||
settings_img = loadPixmap("../assets/navigation/icon_directions_outlined.svg", {114, 114});
|
||||
|
||||
// hidden by default, made visible if map is created (has prime or mapbox token)
|
||||
setVisible(false);
|
||||
setEnabled(false);
|
||||
}
|
||||
|
||||
void MapSettingsButton::paintEvent(QPaintEvent *event) {
|
||||
QPainter p(this);
|
||||
drawCustomButtonIcon(p, 152, 152, settings_img, QColor(0, 0, 0, 166), isDown() ? 0.6 : 1.0);
|
||||
}
|
||||
|
||||
|
||||
// OnroadSettingsButton
|
||||
OnroadSettingsButton::OnroadSettingsButton(QWidget *parent) : QPushButton(parent) {
|
||||
// btn_size: 192 * 80% ~= 152
|
||||
// img_size: (152 / 4) * 3 = 114
|
||||
setFixedSize(152, 152);
|
||||
settings_img = loadPixmap("../assets/navigation/icon_settings.svg", {114, 114});
|
||||
|
||||
// hidden by default, made visible if Driving Personality / GAC, DLP, DEC, or SLC is enabled
|
||||
setVisible(false);
|
||||
setEnabled(false);
|
||||
}
|
||||
|
||||
void OnroadSettingsButton::paintEvent(QPaintEvent *event) {
|
||||
QPainter p(this);
|
||||
drawCustomButtonIcon(p, 152, 152, settings_img, QColor(0, 0, 0, 166), isDown() ? 0.6 : 1.0);
|
||||
}
|
||||
|
||||
void OnroadSettingsButton::updateState(const UIState &s) {
|
||||
const auto cp = (*s.sm)["carParams"].getCarParams();
|
||||
auto dlp_enabled = s.scene.driving_model_generation == cereal::ModelGeneration::ONE;
|
||||
bool allow_btn = s.scene.onroad_settings_toggle && (dlp_enabled || hasLongitudinalControl(cp) || !cp.getPcmCruiseSpeed());
|
||||
|
||||
setVisible(allow_btn);
|
||||
setEnabled(allow_btn);
|
||||
}
|
||||
}
|
||||
@@ -26,30 +26,4 @@ private:
|
||||
};
|
||||
|
||||
|
||||
class MapSettingsButton : public QPushButton {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit MapSettingsButton(QWidget *parent = 0);
|
||||
|
||||
private:
|
||||
void paintEvent(QPaintEvent *event) override;
|
||||
|
||||
QPixmap settings_img;
|
||||
};
|
||||
|
||||
|
||||
class OnroadSettingsButton : public QPushButton {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit OnroadSettingsButton(QWidget *parent = 0);
|
||||
void updateState(const UIState &s);
|
||||
|
||||
private:
|
||||
void paintEvent(QPaintEvent *event) override;
|
||||
|
||||
QPixmap settings_img;
|
||||
};
|
||||
|
||||
void drawIcon(QPainter &p, const QPoint ¢er, const QPixmap &img, const QBrush &bg, float opacity);
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include "selfdrive/ui/qt/onroad/annotated_camera.h"
|
||||
#include "selfdrive/ui/qt/onroad/alerts.h"
|
||||
|
||||
#if SUNNYPILOT
|
||||
#include "selfdrive/ui/sunnypilot/qt/onroad/sp_priv_annotated_camera.h"
|
||||
#define AnnotatedCameraWidget AnnotatedCameraWidgetSP
|
||||
// #define AnnotatedCameraWidget AnnotatedCameraWidgetSP
|
||||
#else
|
||||
#include "selfdrive/ui/qt/onroad/annotated_camera.h"
|
||||
#endif
|
||||
|
||||
@@ -27,7 +27,7 @@ signals:
|
||||
|
||||
public slots:
|
||||
void offroadTransition(bool offroad);
|
||||
virtual void updateState(const UIState &s);
|
||||
void updateState(const UIState &s);
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *event) override;
|
||||
|
||||
@@ -76,8 +76,9 @@ void MainWindow::closeSettings() {
|
||||
if (uiState()->scene.started) {
|
||||
homeWindow->showSidebar(false);
|
||||
#ifdef SUNNYPILOT
|
||||
// TODO: validate this and move it away if valid to move
|
||||
// Map is always shown when using navigate on openpilot
|
||||
if (uiState()->scene.navigate_on_openpilot_deprecated) {
|
||||
if (uiStateSP()->scene.navigate_on_openpilot_deprecated) {
|
||||
homeWindow->showMapPanel(true);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -39,11 +39,12 @@ qt_src = [
|
||||
"sunnypilot/qt/sp_priv_sidebar.cc",
|
||||
"sunnypilot/qt/offroad/settings/sp_priv_device_panel.cc",
|
||||
"sunnypilot/qt/offroad/settings/sp_priv_settings.cc",
|
||||
"sunnypilot/qt/onroad/sp_priv_onroad_settings.cc",
|
||||
"sunnypilot/qt/onroad/sp_priv_onroad_settings_panel.cc",
|
||||
"sunnypilot/qt/onroad/sp_priv_buttons.cc",
|
||||
"sunnypilot/qt/onroad/sp_priv_onroad_home.cc",
|
||||
"sunnypilot/qt/onroad/sp_priv_onroad_settings.cc",
|
||||
"sunnypilot/qt/onroad/sp_priv_annotated_camera.cc",
|
||||
"sunnypilot/qt/onroad/developer_ui/sp_priv_developer_ui.cc"
|
||||
"sunnypilot/qt/onroad/sp_priv_onroad_settings_panel.cc",
|
||||
"sunnypilot/qt/onroad/developer_ui/sp_priv_developer_ui.cc",
|
||||
]
|
||||
|
||||
sp_widgets_src = widgets_src + network_src
|
||||
|
||||
@@ -5,9 +5,9 @@
|
||||
|
||||
void MapWindowSP::initLayers() {
|
||||
if (!m_map->layerExists("navLayer")) {
|
||||
m_map->setPaintProperty("navLayer", "line-color", getNavPathColor(uiState()->scene.navigate_on_openpilot_deprecated));
|
||||
m_map->setPaintProperty("navLayer", "line-color", getNavPathColor(uiStateSP()->scene.navigate_on_openpilot_deprecated));
|
||||
}
|
||||
if ((!m_map->layerExists("buildingsLayer")) && uiState()->scene.map_3d_buildings) { // Could put this behind the cellular metered toggle in case it increases data usage
|
||||
if ((!m_map->layerExists("buildingsLayer")) && uiStateSP()->scene.map_3d_buildings) { // Could put this behind the cellular metered toggle in case it increases data usage
|
||||
qDebug() << "Initializing buildingsLayer";
|
||||
QVariantMap buildings;
|
||||
buildings["id"] = "buildingsLayer";
|
||||
@@ -53,7 +53,7 @@ void MapWindowSP::initLayers() {
|
||||
}
|
||||
|
||||
void MapWindowSP::updateState(const UIState &s) {
|
||||
if (!uiState()->scene.started) {
|
||||
if (!uiStateSP()->scene.started) {
|
||||
return;
|
||||
}
|
||||
const SubMaster &sm = *(s.sm);
|
||||
@@ -72,7 +72,7 @@ void MapWindowSP::updateState(const UIState &s) {
|
||||
auto car_control = sm["carControl"].getCarControl();
|
||||
bool nav_enabled = sm["modelV2"].getModelV2().getNavEnabledDEPRECATED() &&
|
||||
(sm["controlsState"].getControlsState().getEnabled() || car_control.getLatActive() || car_control.getLongActive());
|
||||
if (nav_enabled != uiState()->scene.navigate_on_openpilot_deprecated) {
|
||||
if (nav_enabled != uiStateSP()->scene.navigate_on_openpilot_deprecated) {
|
||||
if (loaded_once) {
|
||||
m_map->setPaintProperty("navLayer", "line-color", getNavPathColor(nav_enabled));
|
||||
}
|
||||
@@ -80,7 +80,7 @@ void MapWindowSP::updateState(const UIState &s) {
|
||||
emit requestVisible(true);
|
||||
}
|
||||
}
|
||||
uiState()->scene.navigate_on_openpilot_deprecated = nav_enabled;
|
||||
uiStateSP()->scene.navigate_on_openpilot_deprecated = nav_enabled;
|
||||
}
|
||||
|
||||
MapWindow::initLayers();
|
||||
@@ -88,7 +88,7 @@ void MapWindowSP::updateState(const UIState &s) {
|
||||
|
||||
void MapWindowSP::offroadTransition(bool offroad) {
|
||||
if (offroad) {
|
||||
uiState()->scene.navigate_on_openpilot_deprecated = false;
|
||||
uiStateSP()->scene.navigate_on_openpilot_deprecated = false;
|
||||
}
|
||||
|
||||
MapWindow::offroadTransition(offroad);
|
||||
|
||||
@@ -25,5 +25,5 @@ void RoleService::handleResponse(const QString &response, bool success) {
|
||||
}
|
||||
|
||||
emit rolesReady(roles);
|
||||
uiState()->setSunnylinkRoles(roles);
|
||||
uiStateSP()->setSunnylinkRoles(roles);
|
||||
}
|
||||
|
||||
@@ -27,5 +27,5 @@ void UserService::handleResponse(const QString &response, bool success) {
|
||||
}
|
||||
|
||||
emit usersReady(users);
|
||||
uiState()->setSunnylinkDeviceUsers(users);
|
||||
uiStateSP()->setSunnylinkDeviceUsers(users);
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ DevicePanelSP::DevicePanelSP(SettingsWindow *parent) : DevicePanel(parent) {
|
||||
});
|
||||
AddWidgetAt(6, resetParamsBtn);
|
||||
|
||||
QObject::connect(uiState(), &UIState::offroadTransition, [=](bool offroad) {
|
||||
QObject::connect(uiStateSP(), &UIStateSP::offroadTransition, [=](bool offroad) {
|
||||
for (auto btn : findChildren<ButtonControl *>()) {
|
||||
if (btn != pair_device && btn != errorBtn) {
|
||||
btn->setEnabled(offroad);
|
||||
@@ -118,18 +118,18 @@ void DevicePanelSP::refreshPin() {
|
||||
}
|
||||
|
||||
void DevicePanelSP::forceoffroad() {
|
||||
if (!uiState()->engaged()) {
|
||||
if (!uiStateSP()->engaged()) {
|
||||
if (params.getBool("ForceOffroad")) {
|
||||
if (ConfirmationDialog::confirm(tr("Are you sure you want to unforce offroad?"), tr("Unforce"), this)) {
|
||||
// Check engaged again in case it changed while the dialog was open
|
||||
if (!uiState()->engaged()) {
|
||||
if (!uiStateSP()->engaged()) {
|
||||
params.remove("ForceOffroad");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (ConfirmationDialog::confirm(tr("Are you sure you want to force offroad?"), tr("Force"), this)) {
|
||||
// Check engaged again in case it changed while the dialog was open
|
||||
if (!uiState()->engaged()) {
|
||||
if (!uiStateSP()->engaged()) {
|
||||
params.putBool("ForceOffroad", true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ OsmPanel::OsmPanel(QWidget *parent) : QFrame(parent) {
|
||||
list->addItem(setupOsmDownloadButton(parent));
|
||||
list->addItem(setupUsStatesButton(parent));
|
||||
|
||||
connect(uiState(), &UIState::offroadTransition, [=](bool offroad) {
|
||||
connect(uiStateSP(), &UIStateSP::offroadTransition, [=](bool offroad) {
|
||||
updateLabels();
|
||||
});
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ private:
|
||||
Params mem_params{ Hardware::PC() ? "": "/dev/shm/params"};
|
||||
std::map<std::string, ParamControlSP*> toggles;
|
||||
std::optional<QFuture<quint64>> mapSizeFuture;
|
||||
const SubMaster &sm = *uiState()->sm;
|
||||
const SubMaster &sm = *uiStateSP()->sm;
|
||||
|
||||
|
||||
bool is_onroad = false;
|
||||
|
||||
@@ -125,7 +125,7 @@ TogglesPanelSP::TogglesPanelSP(SettingsWindow *parent) : TogglesPanel(parent) {
|
||||
accel_personality_setting->showDescription();
|
||||
|
||||
// set up uiState update for personality setting
|
||||
QObject::connect(uiState(), &UIState::uiUpdate, this, &TogglesPanelSP::updateState);
|
||||
QObject::connect(uiStateSP(), &UIStateSP::uiUpdate, this, &TogglesPanelSP::updateState);
|
||||
|
||||
for (auto &[param, title, desc, icon] : toggle_defs) {
|
||||
auto toggle = new ParamControlSP(param, title, desc, icon, this);
|
||||
@@ -163,7 +163,7 @@ TogglesPanelSP::TogglesPanelSP(SettingsWindow *parent) : TogglesPanel(parent) {
|
||||
});
|
||||
}
|
||||
|
||||
void TogglesPanelSP::updateState(const UIState &s) {
|
||||
void TogglesPanelSP::updateState(const UIStateSP &s) {
|
||||
const SubMaster &sm = *(s.sm);
|
||||
|
||||
if (sm.updated("controlsState")) {
|
||||
@@ -171,7 +171,7 @@ void TogglesPanelSP::updateState(const UIState &s) {
|
||||
if (personality != s.scene.personality && s.scene.started && isVisible()) {
|
||||
long_personality_setting->setCheckedButton(static_cast<int>(personality));
|
||||
}
|
||||
uiState()->scene.personality = personality;
|
||||
uiStateSP()->scene.personality = personality;
|
||||
}
|
||||
|
||||
if (sm.updated("controlsStateSP")) {
|
||||
@@ -179,7 +179,7 @@ void TogglesPanelSP::updateState(const UIState &s) {
|
||||
if (accel_personality != s.scene.accel_personality && s.scene.started && isVisible()) {
|
||||
accel_personality_setting->setCheckedButton(static_cast<int>(accel_personality));
|
||||
}
|
||||
uiState()->scene.accel_personality = accel_personality;
|
||||
uiStateSP()->scene.accel_personality = accel_personality;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ public:
|
||||
void showEvent(QShowEvent *event) override;
|
||||
|
||||
private slots:
|
||||
void updateState(const UIState &s) override;
|
||||
void updateState(const UIStateSP &s);
|
||||
|
||||
private:
|
||||
std::map<std::string, ParamControlSP*> toggles;
|
||||
|
||||
@@ -256,7 +256,7 @@ void SoftwarePanelSP::handleCurrentModelLblBtnClicked() {
|
||||
}
|
||||
|
||||
void SoftwarePanelSP::checkNetwork() {
|
||||
const SubMaster &sm = *(uiState()->sm);
|
||||
const SubMaster &sm = *(uiStateSP()->sm);
|
||||
const auto device_state = sm["deviceState"].getDeviceState();
|
||||
const auto network_type = device_state.getNetworkType();
|
||||
is_wifi = network_type == cereal::DeviceState::NetworkType::WIFI;
|
||||
|
||||
@@ -17,8 +17,8 @@ SunnylinkPanel::SunnylinkPanel(QWidget* parent) : QFrame(parent) {
|
||||
});
|
||||
|
||||
is_sunnylink_enabled = Params().getBool("SunnylinkEnabled");
|
||||
connect(uiState(), &UIState::sunnylinkRolesChanged, this, &SunnylinkPanel::updateLabels);
|
||||
connect(uiState(), &UIState::sunnylinkDeviceUsersChanged, this, &SunnylinkPanel::updateLabels);
|
||||
connect(uiStateSP(), &UIStateSP::sunnylinkRolesChanged, this, &SunnylinkPanel::updateLabels);
|
||||
connect(uiStateSP(), &UIStateSP::sunnylinkDeviceUsersChanged, this, &SunnylinkPanel::updateLabels);
|
||||
|
||||
auto list = new ListWidgetSP(this, false);
|
||||
sunnylinkEnabledBtn = new ParamControlSP(
|
||||
@@ -126,7 +126,7 @@ SunnylinkPanel::SunnylinkPanel(QWidget* parent) : QFrame(parent) {
|
||||
settings_layout->setAlignment(Qt::AlignLeft);
|
||||
list->addItem(settings_layout);
|
||||
|
||||
connect(uiState(), &UIState::offroadTransition, [=](bool offroad) {
|
||||
connect(uiStateSP(), &UIStateSP::offroadTransition, [=](bool offroad) {
|
||||
is_onroad = !offroad;
|
||||
updateLabels();
|
||||
});
|
||||
@@ -187,12 +187,12 @@ void SunnylinkPanel::updateLabels() {
|
||||
|
||||
is_sunnylink_enabled = Params().getBool("SunnylinkEnabled");
|
||||
const auto sunnylinkDongleId = getSunnylinkDongleId().value_or(tr("N/A"));
|
||||
bool is_sub = uiState()->isSunnylinkSponsor() && is_sunnylink_enabled;
|
||||
auto max_current_sponsor_rule = uiState()->sunnylinkSponsorRole();
|
||||
bool is_sub = uiStateSP()->isSunnylinkSponsor() && is_sunnylink_enabled;
|
||||
auto max_current_sponsor_rule = uiStateSP()->sunnylinkSponsorRole();
|
||||
auto role_name = max_current_sponsor_rule.getSponsorTierString();
|
||||
std::optional role_color = max_current_sponsor_rule.getSponsorTierColor();
|
||||
bool is_paired = uiState()->isSunnylinkPaired();
|
||||
auto paired_users = uiState()->sunnylinkDeviceUsers();
|
||||
bool is_paired = uiStateSP()->isSunnylinkPaired();
|
||||
auto paired_users = uiStateSP()->sunnylinkDeviceUsers();
|
||||
|
||||
//little easter egg for Panda :D
|
||||
if (sunnylinkDongleId == "d689627422cefcbc") {
|
||||
|
||||
@@ -329,7 +329,7 @@ SunnypilotPanel::SunnypilotPanel(QWidget *parent) : QFrame(parent) {
|
||||
// trigger offroadTransition when going onroad/offroad
|
||||
for (const auto& offroadName : toggleOffroad) {
|
||||
if (toggles.find(offroadName) != toggles.end()) {
|
||||
connect(uiState(), &UIState::offroadTransition, [=](bool offroad) {
|
||||
connect(uiStateSP(), &UIStateSP::offroadTransition, [=](bool offroad) {
|
||||
toggles[offroadName]->setEnabled(offroad);
|
||||
});
|
||||
}
|
||||
@@ -359,7 +359,7 @@ SunnypilotPanel::SunnypilotPanel(QWidget *parent) : QFrame(parent) {
|
||||
customOffsetsSettings->setEnabled(toggles["CustomOffsets"]->isToggled());
|
||||
|
||||
// update "FRICTION" and "LAT_ACCEL_FACTOR" titles when going onroad/offroad
|
||||
connect(uiState(), &UIState::offroadTransition, [=](bool offroad) {
|
||||
connect(uiStateSP(), &UIStateSP::offroadTransition, [=](bool offroad) {
|
||||
friction->setEnabled(offroad || toggles["TorquedOverride"]->isToggled());
|
||||
lat_accel_factor->setEnabled(offroad || toggles["TorquedOverride"]->isToggled());
|
||||
|
||||
|
||||
@@ -173,7 +173,7 @@ SPVehiclesTogglesPanel::SPVehiclesTogglesPanel(VehiclePanel *parent) : ListWidge
|
||||
addItem(volkswagenCCOnly);
|
||||
|
||||
// trigger offroadTransition when going onroad/offroad
|
||||
connect(uiState(), &UIState::offroadTransition, [=](bool offroad) {
|
||||
connect(uiStateSP(), &UIStateSP::offroadTransition, [=](bool offroad) {
|
||||
is_onroad = !offroad;
|
||||
hkgSmoothStop->setEnabled(offroad);
|
||||
toyotaTss2LongTune->setEnabled(offroad);
|
||||
|
||||
@@ -117,7 +117,7 @@ VisualsPanel::VisualsPanel(QWidget *parent) : ListWidgetSP(parent) {
|
||||
addItem(sidebar_temp_setting);
|
||||
|
||||
// trigger offroadTransition when going onroad/offroad
|
||||
connect(uiState(), &UIState::offroadTransition, [=](bool offroad) {
|
||||
connect(uiStateSP(), &UIStateSP::offroadTransition, [=](bool offroad) {
|
||||
});
|
||||
|
||||
QObject::connect(toggles["MapboxFullScreen"], &ToggleControl::toggleFlipped, [=](bool state) {
|
||||
|
||||
@@ -53,11 +53,11 @@ MadsSettings::MadsSettings(QWidget* parent) : QWidget(parent) {
|
||||
toggles[param.toStdString()] = toggle;
|
||||
|
||||
// trigger offroadTransition when going onroad/offroad
|
||||
connect(uiState(), &UIState::offroadTransition, toggle, &ParamControlSP::setEnabled);
|
||||
connect(uiStateSP(), &UIStateSP::offroadTransition, toggle, &ParamControlSP::setEnabled);
|
||||
}
|
||||
|
||||
// trigger offroadTransition when going onroad/offroad
|
||||
connect(uiState(), &UIState::offroadTransition, dlob_settings, &ButtonParamControlSP::setEnabled);
|
||||
connect(uiStateSP(), &UIStateSP::offroadTransition, dlob_settings, &ButtonParamControlSP::setEnabled);
|
||||
|
||||
main_layout->addWidget(new ScrollViewSP(list, this));
|
||||
}
|
||||
@@ -71,7 +71,7 @@ void MadsSettings::updateToggles() {
|
||||
return;
|
||||
}
|
||||
|
||||
const bool is_offroad = !uiState()->scene.started;
|
||||
const bool is_offroad = !uiStateSP()->scene.started;
|
||||
const bool enable_mads = params.getBool("EnableMads");
|
||||
const bool enabled = is_offroad && enable_mads;
|
||||
|
||||
|
||||
@@ -57,8 +57,8 @@ AnnotatedCameraWidgetSP::AnnotatedCameraWidgetSP(VisionStreamType type, QWidget*
|
||||
void AnnotatedCameraWidgetSP::mousePressEvent(QMouseEvent* e) {
|
||||
bool propagate_event = true;
|
||||
|
||||
UIState *s = uiState();
|
||||
UIScene &scene = s->scene;
|
||||
UIStateSP *s = uiStateSP();
|
||||
UISceneSP &scene = s->scene;
|
||||
const SubMaster &sm = *(s->sm);
|
||||
const auto longitudinal_plan_sp = sm["longitudinalPlanSP"].getLongitudinalPlanSP();
|
||||
|
||||
@@ -103,7 +103,7 @@ void AnnotatedCameraWidgetSP::updateButtonsLayout(bool is_rhd) {
|
||||
}
|
||||
}
|
||||
|
||||
void AnnotatedCameraWidgetSP::updateState(const UIState &s) {
|
||||
void AnnotatedCameraWidgetSP::updateState(const UIStateSP &s) {
|
||||
const int SET_SPEED_NA = 255;
|
||||
const SubMaster &sm = *(s.sm);
|
||||
|
||||
@@ -1096,7 +1096,7 @@ void AnnotatedCameraWidgetSP::initializeGL() {
|
||||
|
||||
void AnnotatedCameraWidgetSP::updateFrameMat() {
|
||||
CameraWidget::updateFrameMat();
|
||||
UIState *s = uiState();
|
||||
UIStateSP *s = uiStateSP();
|
||||
int w = width(), h = height();
|
||||
|
||||
s->fb_w = w;
|
||||
@@ -1112,10 +1112,10 @@ void AnnotatedCameraWidgetSP::updateFrameMat() {
|
||||
.translate(-intrinsic_matrix.v[2], -intrinsic_matrix.v[5]);
|
||||
}
|
||||
|
||||
void AnnotatedCameraWidgetSP::drawLaneLines(QPainter &painter, const UIState *s) {
|
||||
void AnnotatedCameraWidgetSP::drawLaneLines(QPainter &painter, const UIStateSP *s) {
|
||||
painter.save();
|
||||
|
||||
const UIScene &scene = s->scene;
|
||||
const UISceneSP &scene = s->scene;
|
||||
SubMaster &sm = *(s->sm);
|
||||
|
||||
const auto car_state = sm["carState"].getCarState();
|
||||
@@ -1216,7 +1216,7 @@ void AnnotatedCameraWidgetSP::drawLaneLines(QPainter &painter, const UIState *s)
|
||||
painter.restore();
|
||||
}
|
||||
|
||||
void AnnotatedCameraWidgetSP::drawDriverState(QPainter &painter, const UIState *s) {
|
||||
void AnnotatedCameraWidgetSP::drawDriverState(QPainter &painter, const UIStateSP *s) {
|
||||
const UIScene &scene = s->scene;
|
||||
|
||||
painter.save();
|
||||
@@ -1271,7 +1271,7 @@ void AnnotatedCameraWidgetSP::rocketFuel(QPainter &p) {
|
||||
t[dim_n] = 1.0;
|
||||
t[(int)(ct/ct_n)] = 1.0;
|
||||
|
||||
UIState *s = uiState();
|
||||
UIStateSP *s = uiStateSP();
|
||||
float vc_accel0 = (*s->sm)["carState"].getCarState().getAEgo();
|
||||
static float vc_accel;
|
||||
vc_accel = vc_accel + (vc_accel0 - vc_accel) / 5;
|
||||
@@ -1374,7 +1374,7 @@ void AnnotatedCameraWidgetSP::paintGL() {
|
||||
}
|
||||
|
||||
void AnnotatedCameraWidgetSP::paintEvent(QPaintEvent *event) {
|
||||
UIState *s = uiState();
|
||||
UIStateSP *s = uiStateSP();
|
||||
SubMaster &sm = *(s->sm);
|
||||
const double start_draw_t = millis_since_boot();
|
||||
const cereal::ModelDataV2::Reader &model = sm["modelV2"].getModelV2();
|
||||
@@ -1501,6 +1501,6 @@ void AnnotatedCameraWidgetSP::paintEvent(QPaintEvent *event) {
|
||||
void AnnotatedCameraWidgetSP::showEvent(QShowEvent *event) {
|
||||
CameraWidget::showEvent(event);
|
||||
|
||||
ui_update_params(uiState());
|
||||
ui_update_params(uiStateSP());
|
||||
prev_draw_t = millis_since_boot();
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
#include "selfdrive/ui/qt/onroad/buttons.h"
|
||||
#include "selfdrive/ui/qt/widgets/cameraview.h"
|
||||
#include "selfdrive/ui/sunnypilot/qt/onroad/sp_priv_buttons.h"
|
||||
#include "selfdrive/ui/sunnypilot/qt/onroad/developer_ui/sp_priv_developer_ui.h"
|
||||
|
||||
const int subsign_img_size = 35;
|
||||
@@ -16,7 +17,7 @@ class AnnotatedCameraWidgetSP : public CameraWidget {
|
||||
|
||||
public:
|
||||
explicit AnnotatedCameraWidgetSP(VisionStreamType type, QWidget* parent = 0);
|
||||
void updateState(const UIState &s);
|
||||
void updateState(const UIStateSP &s);
|
||||
|
||||
MapSettingsButton *map_settings_btn;
|
||||
OnroadSettingsButton *onroad_settings_btn;
|
||||
@@ -187,11 +188,11 @@ protected:
|
||||
void initializeGL() override;
|
||||
void showEvent(QShowEvent *event) override;
|
||||
void updateFrameMat() override;
|
||||
void drawLaneLines(QPainter &painter, const UIState *s);
|
||||
void drawLaneLines(QPainter &painter, const UIStateSP *s);
|
||||
void drawLead(QPainter &painter, const cereal::RadarState::LeadData::Reader &lead_data, const QPointF &vd,
|
||||
int num, const cereal::CarState::Reader &car_data, int chevron_data);
|
||||
void drawHud(QPainter &p);
|
||||
void drawDriverState(QPainter &painter, const UIState *s);
|
||||
void drawDriverState(QPainter &painter, const UIStateSP *s);
|
||||
inline QColor redColor(int alpha = 255) { return QColor(201, 34, 49, alpha); }
|
||||
inline QColor whiteColor(int alpha = 255) { return QColor(255, 255, 255, alpha); }
|
||||
inline QColor blackColor(int alpha = 255) { return QColor(0, 0, 0, alpha); }
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
#include "selfdrive/ui/sunnypilot/qt/onroad/sp_priv_buttons.h"
|
||||
#include "selfdrive/ui/qt/util.h"
|
||||
|
||||
|
||||
static void drawCustomButtonIcon(QPainter &p, const int btn_size_x, const int btn_size_y, const QPixmap &img, const QBrush &bg, float opacity) {
|
||||
QPoint center(btn_size_x / 2, btn_size_y / 2);
|
||||
p.setRenderHint(QPainter::Antialiasing);
|
||||
p.setOpacity(1.0); // bg dictates opacity of ellipse
|
||||
p.setPen(Qt::NoPen);
|
||||
p.setBrush(bg);
|
||||
p.drawEllipse(center, btn_size_x / 2, btn_size_y / 2);
|
||||
p.setOpacity(opacity);
|
||||
p.drawPixmap(center - QPoint(img.width() / 2, img.height() / 2), img);
|
||||
p.setOpacity(1.0);
|
||||
}
|
||||
|
||||
|
||||
// OnroadSettingsButton
|
||||
OnroadSettingsButton::OnroadSettingsButton(QWidget *parent) : QPushButton(parent) {
|
||||
// btn_size: 192 * 80% ~= 152
|
||||
// img_size: (152 / 4) * 3 = 114
|
||||
setFixedSize(152, 152);
|
||||
settings_img = loadPixmap("../assets/navigation/icon_settings.svg", {114, 114});
|
||||
|
||||
// hidden by default, made visible if Driving Personality / GAC, DLP, DEC, or SLC is enabled
|
||||
setVisible(false);
|
||||
setEnabled(false);
|
||||
}
|
||||
|
||||
void OnroadSettingsButton::paintEvent(QPaintEvent *event) {
|
||||
QPainter p(this);
|
||||
drawCustomButtonIcon(p, 152, 152, settings_img, QColor(0, 0, 0, 166), isDown() ? 0.6 : 1.0);
|
||||
}
|
||||
|
||||
void OnroadSettingsButton::updateState(const UIStateSP &s) {
|
||||
const auto cp = (*s.sm)["carParams"].getCarParams();
|
||||
auto dlp_enabled = s.scene.driving_model_generation == cereal::ModelGeneration::ONE;
|
||||
bool allow_btn = s.scene.onroad_settings_toggle && (dlp_enabled || hasLongitudinalControl(cp) || !cp.getPcmCruiseSpeed());
|
||||
|
||||
setVisible(allow_btn);
|
||||
setEnabled(allow_btn);
|
||||
}
|
||||
|
||||
// MapSettingsButton
|
||||
MapSettingsButton::MapSettingsButton(QWidget *parent) : QPushButton(parent) {
|
||||
// btn_size: 192 * 80% ~= 152
|
||||
// img_size: (152 / 4) * 3 = 114
|
||||
setFixedSize(152, 152);
|
||||
settings_img = loadPixmap("../assets/navigation/icon_directions_outlined.svg", {114, 114});
|
||||
|
||||
// hidden by default, made visible if map is created (has prime or mapbox token)
|
||||
setVisible(false);
|
||||
setEnabled(false);
|
||||
}
|
||||
|
||||
void MapSettingsButton::paintEvent(QPaintEvent *event) {
|
||||
QPainter p(this);
|
||||
drawCustomButtonIcon(p, 152, 152, settings_img, QColor(0, 0, 0, 166), isDown() ? 0.6 : 1.0);
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
#include <QPushButton>
|
||||
#include "selfdrive/ui/sunnypilot/sp_priv_ui.h"
|
||||
|
||||
#include "selfdrive/ui/ui.h"
|
||||
|
||||
class OnroadSettingsButton : public QPushButton {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit OnroadSettingsButton(QWidget *parent = 0);
|
||||
void updateState(const UIStateSP &s);
|
||||
|
||||
private:
|
||||
void paintEvent(QPaintEvent *event) override;
|
||||
|
||||
QPixmap settings_img;
|
||||
};
|
||||
|
||||
|
||||
class MapSettingsButton : public QPushButton {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit MapSettingsButton(QWidget *parent = 0);
|
||||
|
||||
private:
|
||||
void paintEvent(QPaintEvent *event) override;
|
||||
|
||||
QPixmap settings_img;
|
||||
};
|
||||
@@ -19,10 +19,10 @@ OnroadWindowSP::OnroadWindowSP(QWidget *parent) : OnroadWindow(parent) {
|
||||
CameraWidget *map_render = new CameraWidget("navd", VISION_STREAM_MAP, false, this);
|
||||
split->insertWidget(0, map_render); //TODO: We MIGHT to override the split variable because it is added on onroad_home.cc and we need to access it before. I am not sure so we will need to test it before
|
||||
}
|
||||
QObject::connect(uiState(), &UIState::primeChanged, this, &OnroadWindowSP::primeChanged);
|
||||
QObject::connect(uiStateSP(), &UIStateSP::primeChanged, this, &OnroadWindowSP::primeChanged);
|
||||
}
|
||||
|
||||
void OnroadWindowSP::updateState(const UIState &s) {
|
||||
void OnroadWindowSP::updateState(const UIStateSP &s) {
|
||||
if (!s.scene.started) {
|
||||
return;
|
||||
}
|
||||
@@ -39,13 +39,13 @@ void OnroadWindowSP::updateState(const UIState &s) {
|
||||
|
||||
void OnroadWindowSP::mousePressEvent(QMouseEvent* e) {
|
||||
#ifdef ENABLE_MAPS
|
||||
UIState *s = uiState();
|
||||
UIState *s = uiStateSP();
|
||||
UIScene &scene = s->scene;
|
||||
if (map != nullptr && !isOnroadSettingsVisible()) {
|
||||
if (wakeScreenTimeout()) {
|
||||
// Switch between map and sidebar when using navigate on openpilot
|
||||
bool sidebarVisible = geometry().x() > 0;
|
||||
bool show_map = uiState()->scene.navigate_on_openpilot_deprecated ? sidebarVisible : !sidebarVisible;
|
||||
bool show_map = uiStateSP()->scene.navigate_on_openpilot_deprecated ? sidebarVisible : !sidebarVisible;
|
||||
updateMapSize(scene);
|
||||
map->setVisible(show_map && !map->isVisible());
|
||||
}
|
||||
@@ -72,7 +72,7 @@ void OnroadWindowSP::createMapWidget() {
|
||||
QObject::connect(nvg->map_settings_btn, &MapSettingsButton::clicked, m, &MapPanel::toggleMapSettings);
|
||||
nvg->map_settings_btn->setEnabled(true);
|
||||
|
||||
m->setFixedWidth(uiState()->scene.mapbox_fullscreen ? topWidget(this)->width() :
|
||||
m->setFixedWidth(uiStateSP()->scene.mapbox_fullscreen ? topWidget(this)->width() :
|
||||
topWidget(this)->width() / 2 - UI_BORDER_SIZE);
|
||||
split->insertWidget(0, m);
|
||||
|
||||
@@ -102,7 +102,7 @@ void OnroadWindowSP::createOnroadSettingsWidget() {
|
||||
void OnroadWindowSP::offroadTransition(bool offroad) {
|
||||
if (!offroad) {
|
||||
#ifdef ENABLE_MAPS
|
||||
if (map == nullptr && (uiState()->hasPrime() || !MAPBOX_TOKEN.isEmpty())) {
|
||||
if (map == nullptr && (uiStateSP()->hasPrime() || !MAPBOX_TOKEN.isEmpty())) {
|
||||
createMapWidget();
|
||||
}
|
||||
#endif
|
||||
@@ -114,7 +114,7 @@ void OnroadWindowSP::offroadTransition(bool offroad) {
|
||||
OnroadWindow::offroadTransition(offroad); // Carry on with the parent class offroadTransition method
|
||||
}
|
||||
|
||||
void OnroadWindowSP::updateMapSize(const UIScene &scene) {
|
||||
void OnroadWindowSP::updateMapSize(const UISceneSP &scene) {
|
||||
map->setFixedWidth(scene.mapbox_fullscreen ? topWidget(this)->width() :
|
||||
topWidget(this)->width() / 2 - UI_BORDER_SIZE);
|
||||
split->insertWidget(0, map);
|
||||
|
||||
@@ -21,8 +21,8 @@ public:
|
||||
void onroadSettingsPanelNotRequested() { if (onroad_settings) onroad_settings->setVisible(false); }
|
||||
|
||||
bool wakeScreenTimeout() {
|
||||
if ((uiState()->scene.sleep_btn != 0 && uiState()->scene.sleep_btn_opacity != 0) ||
|
||||
(uiState()->scene.sleep_time != 0 && uiState()->scene.onroadScreenOff != -2)) {
|
||||
if ((uiStateSP()->scene.sleep_btn != 0 && uiStateSP()->scene.sleep_btn_opacity != 0) ||
|
||||
(uiStateSP()->scene.sleep_time != 0 && uiStateSP()->scene.onroadScreenOff != -2)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -36,7 +36,7 @@ private:
|
||||
void createMapWidget();
|
||||
void createOnroadSettingsWidget();
|
||||
void mousePressEvent(QMouseEvent* e) override;
|
||||
// AnnotatedCameraWidget *nvg; //TODO: override? this is defined on onroad_home.h
|
||||
AnnotatedCameraWidgetSP *nvg;
|
||||
QWidget *map = nullptr;
|
||||
QWidget *onroad_settings = nullptr;
|
||||
|
||||
@@ -44,7 +44,7 @@ private:
|
||||
|
||||
protected slots:
|
||||
void offroadTransition(bool offroad) override;
|
||||
void updateState(const UIState &s) override;
|
||||
void updateState(const UIStateSP &s);
|
||||
void primeChanged(bool prime);
|
||||
void updateMapSize(const UIScene &scene);
|
||||
void updateMapSize(const UISceneSP &scene);
|
||||
};
|
||||
|
||||
@@ -120,7 +120,7 @@ OnroadSettings::OnroadSettings(bool closeable, QWidget *parent) : QFrame(parent)
|
||||
}
|
||||
|
||||
void OnroadSettings::changeDynamicLaneProfile() {
|
||||
UIScene &scene = uiState()->scene;
|
||||
UISceneSP &scene = uiStateSP()->scene;
|
||||
bool can_change = scene.driving_model_generation == cereal::ModelGeneration::ONE;
|
||||
if (can_change) {
|
||||
scene.dynamic_lane_profile++;
|
||||
@@ -131,8 +131,8 @@ void OnroadSettings::changeDynamicLaneProfile() {
|
||||
}
|
||||
|
||||
void OnroadSettings::changeGapAdjustCruise() {
|
||||
UIScene &scene = uiState()->scene;
|
||||
const auto cp = (*uiState()->sm)["carParams"].getCarParams();
|
||||
UISceneSP &scene = uiStateSP()->scene;
|
||||
const auto cp = (*uiStateSP()->sm)["carParams"].getCarParams();
|
||||
bool can_change = hasLongitudinalControl(cp);
|
||||
if (can_change) {
|
||||
scene.longitudinal_personality--;
|
||||
@@ -143,8 +143,8 @@ void OnroadSettings::changeGapAdjustCruise() {
|
||||
}
|
||||
|
||||
void OnroadSettings::changeAccelerationPersonality() {
|
||||
UIScene &scene = uiState()->scene;
|
||||
const auto cp = (*uiState()->sm)["carParams"].getCarParams();
|
||||
UISceneSP &scene = uiStateSP()->scene;
|
||||
const auto cp = (*uiStateSP()->sm)["carParams"].getCarParams();
|
||||
bool can_change = hasLongitudinalControl(cp);
|
||||
if (can_change) {
|
||||
scene.longitudinal_accel_personality--;
|
||||
@@ -155,8 +155,8 @@ void OnroadSettings::changeAccelerationPersonality() {
|
||||
}
|
||||
|
||||
void OnroadSettings::changeDynamicPersonality() {
|
||||
UIScene &scene = uiState()->scene;
|
||||
const auto cp = (*uiState()->sm)["carParams"].getCarParams();
|
||||
UISceneSP &scene = uiStateSP()->scene;
|
||||
const auto cp = (*uiStateSP()->sm)["carParams"].getCarParams();
|
||||
bool can_change = hasLongitudinalControl(cp);
|
||||
if (can_change) {
|
||||
scene.dynamic_personality = !scene.dynamic_personality;
|
||||
@@ -166,8 +166,8 @@ void OnroadSettings::changeDynamicPersonality() {
|
||||
}
|
||||
|
||||
void OnroadSettings::changeDynamicExperimentalControl() {
|
||||
UIScene &scene = uiState()->scene;
|
||||
const auto cp = (*uiState()->sm)["carParams"].getCarParams();
|
||||
UISceneSP &scene = uiStateSP()->scene;
|
||||
const auto cp = (*uiStateSP()->sm)["carParams"].getCarParams();
|
||||
bool can_change = hasLongitudinalControl(cp);
|
||||
if (can_change) {
|
||||
scene.dynamic_experimental_control = !scene.dynamic_experimental_control;
|
||||
@@ -177,8 +177,8 @@ void OnroadSettings::changeDynamicExperimentalControl() {
|
||||
}
|
||||
|
||||
void OnroadSettings::changeSpeedLimitControl() {
|
||||
UIScene &scene = uiState()->scene;
|
||||
const auto cp = (*uiState()->sm)["carParams"].getCarParams();
|
||||
UISceneSP &scene = uiStateSP()->scene;
|
||||
const auto cp = (*uiStateSP()->sm)["carParams"].getCarParams();
|
||||
bool can_change = hasLongitudinalControl(cp) || !cp.getPcmCruiseSpeed();
|
||||
int max_policy = SpeedLimitPolicySettings::speed_limit_policy_texts.size() - 1;
|
||||
|
||||
@@ -213,7 +213,7 @@ void OnroadSettings::refresh() {
|
||||
param_watcher->addParam("DynamicExperimentalControl");
|
||||
param_watcher->addParam("EnableSlc");
|
||||
|
||||
UIScene &scene = uiState()->scene;
|
||||
UISceneSP &scene = uiStateSP()->scene;
|
||||
// Update live params on Feature Status on camera view
|
||||
scene.dynamic_lane_profile = std::atoi(params.get("DynamicLaneProfile").c_str());
|
||||
scene.longitudinal_personality = std::atoi(params.get("LongitudinalPersonality").c_str());
|
||||
@@ -227,7 +227,7 @@ void OnroadSettings::refresh() {
|
||||
|
||||
setUpdatesEnabled(false);
|
||||
|
||||
const auto cp = (*uiState()->sm)["carParams"].getCarParams();
|
||||
const auto cp = (*uiStateSP()->sm)["carParams"].getCarParams();
|
||||
|
||||
// Dynamic Lane Profile
|
||||
dlp_widget->updateDynamicLaneProfile("DynamicLaneProfile");
|
||||
|
||||
@@ -22,22 +22,22 @@ void HomeWindowSP::showMapPanel(bool show) {
|
||||
void HomeWindowSP::updateState(const UIState &s) { //OVERRIDE
|
||||
HomeWindow::updateState(s);
|
||||
|
||||
uiState()->scene.map_visible = onroad->isMapVisible();
|
||||
uiState()->scene.onroad_settings_visible = onroad->isOnroadSettingsVisible();
|
||||
uiStateSP()->scene.map_visible = onroad->isMapVisible();
|
||||
uiStateSP()->scene.onroad_settings_visible = onroad->isOnroadSettingsVisible();
|
||||
}
|
||||
|
||||
void HomeWindowSP::mousePressEvent(QMouseEvent* e) {
|
||||
HomeWindow::mousePressEvent(e); // We call it first so that we could potentially override whatever was done by parent
|
||||
|
||||
if (uiState()->scene.started) {
|
||||
if (uiState()->scene.onroadScreenOff != -2) {
|
||||
uiState()->scene.touched2 = true;
|
||||
QTimer::singleShot(500, []() { uiState()->scene.touched2 = false; });
|
||||
if (uiStateSP()->scene.started) {
|
||||
if (uiStateSP()->scene.onroadScreenOff != -2) {
|
||||
uiStateSP()->scene.touched2 = true;
|
||||
QTimer::singleShot(500, []() { uiStateSP()->scene.touched2 = false; });
|
||||
}
|
||||
if (uiState()->scene.button_auto_hide) {
|
||||
uiState()->scene.touch_to_wake = true;
|
||||
uiState()->scene.sleep_btn_fading_in = true;
|
||||
QTimer::singleShot(500, []() { uiState()->scene.touch_to_wake = false; });
|
||||
if (uiStateSP()->scene.button_auto_hide) {
|
||||
uiStateSP()->scene.touch_to_wake = true;
|
||||
uiStateSP()->scene.sleep_btn_fading_in = true;
|
||||
QTimer::singleShot(500, []() { uiStateSP()->scene.touch_to_wake = false; });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,8 +17,8 @@ void OffroadHomeSP::replaceLeftWidget(){
|
||||
new_left_widget->addWidget(new PrimeAdWidget);
|
||||
|
||||
new_left_widget->setStyleSheet("border-radius: 10px;");
|
||||
new_left_widget->setCurrentIndex((uiState()->hasPrime() || custom_mapbox) ? 0 : 1);
|
||||
connect(uiState(), &UIState::primeChanged, [=](bool prime) {
|
||||
new_left_widget->setCurrentIndex((uiStateSP()->hasPrime() || custom_mapbox) ? 0 : 1);
|
||||
connect(uiStateSP(), &UIStateSP::primeChanged, [=](bool prime) {
|
||||
new_left_widget->setCurrentIndex((prime || custom_mapbox) ? 0 : 1);
|
||||
});
|
||||
ReplaceWidget(left_widget, new_left_widget);
|
||||
|
||||
@@ -8,9 +8,13 @@
|
||||
#include "common/params.h"
|
||||
|
||||
|
||||
SidebarSP::SidebarSP(QWidget *parent) : Sidebar(parent) {}
|
||||
SidebarSP::SidebarSP(QWidget *parent) : Sidebar(parent) {
|
||||
// Because I know that stock sidebar makes this connection, I will disconnect it and connect it to the new updateState function
|
||||
QObject::disconnect(uiState(), &UIState::uiUpdate, this, &Sidebar::updateState);
|
||||
QObject::connect(uiStateSP(), &UIStateSP::uiUpdate, this, &SidebarSP::updateState);
|
||||
}
|
||||
|
||||
void SidebarSP::updateState(const UIState &s) {
|
||||
void SidebarSP::updateState(const UIStateSP &s) {
|
||||
if (!isVisible()) return;
|
||||
Sidebar::updateState(s);
|
||||
auto &sm = *(s.sm);
|
||||
|
||||
@@ -17,7 +17,7 @@ public:
|
||||
explicit SidebarSP(QWidget* parent = 0);
|
||||
|
||||
public slots:
|
||||
void updateState(const UIState &s) override;
|
||||
void updateState(const UIStateSP &s);
|
||||
|
||||
protected:
|
||||
const QColor progress_color = QColor(3, 132, 252);
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
#pragma once
|
||||
#include "selfdrive/ui/ui.h"
|
||||
|
||||
const float DRIVING_PATH_WIDE = 0.9;
|
||||
const float DRIVING_PATH_NARROW = 0.25;
|
||||
|
||||
typedef struct UISceneSP : public UIScene {
|
||||
cereal::ControlsState::Reader controlsState;
|
||||
|
||||
// Debug UI
|
||||
bool show_debug_ui;
|
||||
|
||||
// Speed limit control
|
||||
bool speed_limit_control_enabled;
|
||||
int speed_limit_control_policy;
|
||||
double last_speed_limit_sign_tap;
|
||||
|
||||
QPolygonF track_edge_vertices;
|
||||
QPolygonF lane_barrier_vertices[2];
|
||||
|
||||
bool navigate_on_openpilot_deprecated = false;
|
||||
cereal::AccelerationPersonality accel_personality;
|
||||
|
||||
bool map_on_left;
|
||||
|
||||
int dynamic_lane_profile;
|
||||
bool dynamic_lane_profile_status = true;
|
||||
|
||||
bool visual_brake_lights;
|
||||
|
||||
int onroadScreenOff, osoTimer, brightness, onroadScreenOffBrightness, awake;
|
||||
bool onroadScreenOffEvent;
|
||||
int sleep_time = -1;
|
||||
bool touched2 = false;
|
||||
|
||||
bool stand_still_timer;
|
||||
|
||||
bool hide_vego_ui, true_vego_ui;
|
||||
|
||||
int chevron_data;
|
||||
|
||||
bool gac;
|
||||
int longitudinal_personality;
|
||||
int longitudinal_accel_personality;
|
||||
|
||||
bool map_visible;
|
||||
int dev_ui_info;
|
||||
bool live_torque_toggle;
|
||||
|
||||
bool touch_to_wake = false;
|
||||
int sleep_btn = -1;
|
||||
bool sleep_btn_fading_in = false;
|
||||
int sleep_btn_opacity = 20;
|
||||
bool button_auto_hide;
|
||||
|
||||
bool reverse_dm_cam;
|
||||
|
||||
bool e2e_long_alert_light, e2e_long_alert_lead, e2e_long_alert_ui;
|
||||
float e2eX[13] = {0};
|
||||
|
||||
int sidebar_temp_options;
|
||||
|
||||
float mads_path_scale = DRIVING_PATH_WIDE - DRIVING_PATH_NARROW;
|
||||
float mads_path_range = DRIVING_PATH_WIDE - DRIVING_PATH_NARROW; // 0.9 - 0.25 = 0.65
|
||||
|
||||
bool onroad_settings_visible;
|
||||
|
||||
bool map_3d_buildings;
|
||||
|
||||
bool torqued_override;
|
||||
|
||||
bool dynamic_experimental_control;
|
||||
|
||||
int speed_limit_control_engage_type;
|
||||
|
||||
bool mapbox_fullscreen;
|
||||
|
||||
bool speed_limit_warning_flash;
|
||||
int speed_limit_warning_type;
|
||||
int speed_limit_warning_value_offset;
|
||||
|
||||
bool custom_driving_model_valid;
|
||||
cereal::ModelGeneration driving_model_generation;
|
||||
uint32_t driving_model_capabilities;
|
||||
|
||||
bool feature_status_toggle;
|
||||
bool onroad_settings_toggle;
|
||||
|
||||
bool dynamic_personality;
|
||||
} UISceneSP;
|
||||
@@ -1,32 +1,30 @@
|
||||
#include "selfdrive/ui/sunnypilot/sp_priv_ui.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <cmath>
|
||||
|
||||
#include <QtConcurrent>
|
||||
|
||||
#include "common/transformations/orientation.hpp"
|
||||
#include "common/params.h"
|
||||
#include "common/swaglog.h"
|
||||
#include "common/util.h"
|
||||
#include "common/watchdog.h"
|
||||
#include "selfdrive/ui/sunnypilot/qt/network/sunnylink/models/sp_priv_role_model.h"
|
||||
#include "system/hardware/hw.h"
|
||||
|
||||
#define BACKLIGHT_DT 0.05
|
||||
#define BACKLIGHT_TS 10.00
|
||||
|
||||
// Projects a point in car to space to the corresponding point in full frame
|
||||
// image space.
|
||||
static bool calib_frame_to_full_frame(const UIState *s, float in_x, float in_y, float in_z, QPointF *out) {
|
||||
const float margin = 1000.0f;
|
||||
const QRectF clip_region{-margin, -margin, s->fb_w + 2 * margin, s->fb_h + 2 * margin};
|
||||
|
||||
const vec3 pt = (vec3){{in_x, in_y, in_z}};
|
||||
const vec3 Ep = matvecmul3(s->scene.wide_cam ? s->scene.view_from_wide_calib : s->scene.view_from_calib, pt);
|
||||
const vec3 KEp = matvecmul3(s->scene.wide_cam ? ECAM_INTRINSIC_MATRIX : FCAM_INTRINSIC_MATRIX, Ep);
|
||||
|
||||
// Project.
|
||||
QPointF point = s->car_space_transform.map(QPointF{KEp.v[0] / KEp.v[2], KEp.v[1] / KEp.v[2]});
|
||||
if (clip_region.contains(point)) {
|
||||
*out = point;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
static bool sp_calib_frame_to_full_frame(const UIStateSP *s, float in_x, float in_y, float in_z, QPointF *out) {
|
||||
return calib_frame_to_full_frame(s, in_x, in_y, in_z, out, 1000.0f);
|
||||
}
|
||||
|
||||
void update_line_data(const UIState *s, const cereal::XYZTData::Reader &line,
|
||||
//todo: revisit, we could reuse from OG update_model. But this is an overload in this case.
|
||||
void update_line_data(const UIStateSP *s, const cereal::XYZTData::Reader &line,
|
||||
float y_off, float z_off_left, float z_off_right, QPolygonF *pvd, int max_idx, bool allow_invert=true) {
|
||||
const auto line_x = line.getX(), line_y = line.getY(), line_z = line.getZ();
|
||||
QPointF left, right;
|
||||
@@ -35,8 +33,8 @@ void update_line_data(const UIState *s, const cereal::XYZTData::Reader &line,
|
||||
// highly negative x positions are drawn above the frame and cause flickering, clip to zy plane of camera
|
||||
if (line_x[i] < 0) continue;
|
||||
|
||||
bool l = calib_frame_to_full_frame(s, line_x[i], line_y[i] - y_off, line_z[i] + z_off_left, &left);
|
||||
bool r = calib_frame_to_full_frame(s, line_x[i], line_y[i] + y_off, line_z[i] + z_off_right, &right);
|
||||
bool l = sp_calib_frame_to_full_frame(s, line_x[i], line_y[i] - y_off, line_z[i] + z_off_left, &left);
|
||||
bool r = sp_calib_frame_to_full_frame(s, line_x[i], line_y[i] + y_off, line_z[i] + z_off_right, &right);
|
||||
if (l && r) {
|
||||
// For wider lines the drawn polygon will "invert" when going over a hill and cause artifacts
|
||||
if (!allow_invert && pvd->size() && left.y() > pvd->back().y()) {
|
||||
@@ -48,9 +46,9 @@ void update_line_data(const UIState *s, const cereal::XYZTData::Reader &line,
|
||||
}
|
||||
}
|
||||
|
||||
void update_model(UIStateSP *s,
|
||||
const cereal::ModelDataV2::Reader &model) {
|
||||
UISceneSP &scene = s->scene_sp;
|
||||
//todo: revisit, we could reuse from OG update_model
|
||||
void sp_update_model(UIStateSP *s, const cereal::ModelDataV2::Reader &model) {
|
||||
UISceneSP &scene = s->scene;
|
||||
auto model_position = model.getPosition();
|
||||
float max_distance = std::clamp(*(model_position.getX().end() - 1),
|
||||
MIN_DRAW_DISTANCE, MAX_DRAW_DISTANCE);
|
||||
@@ -89,13 +87,12 @@ void update_model(UIStateSP *s,
|
||||
update_line_data(s, model_position, 1.0 - scene.mads_path_range * scene.mads_path_scale - 0.1 * scene.mads_path_scale, 1.22, 1.22, &scene.track_edge_vertices, max_idx, false);
|
||||
}
|
||||
|
||||
static void update_state(UIStateSP *s) {
|
||||
static void sp_update_state(UIStateSP *s) {
|
||||
update_state(s);
|
||||
SubMaster &sm = *(s->sm);
|
||||
UISceneSP &scene = s->scene_sp;
|
||||
UISceneSP &scene = s->scene;
|
||||
auto params = Params();
|
||||
|
||||
scene.started = sm["deviceState"].getDeviceState().getStarted() && scene.ignition && !params.getBool("ForceOffroad");
|
||||
|
||||
// TODO: SP - Set this dynamically on init with manual toggle or driving model selection
|
||||
if (sm.updated("lateralPlanSPDEPRECATED")) {
|
||||
scene.dynamic_lane_profile_status = sm["lateralPlanSPDEPRECATED"].getLateralPlanSPDEPRECATED().getDynamicLaneProfileStatus();
|
||||
@@ -116,64 +113,61 @@ static void update_state(UIStateSP *s) {
|
||||
}
|
||||
}
|
||||
|
||||
void ui_update_params(UIStateSP *s) {
|
||||
UISceneSP &scene = s->scene_sp;
|
||||
void sp_ui_update_params(UIStateSP *s) {
|
||||
ui_update_params(s);
|
||||
auto params = Params();
|
||||
scene.map_on_left = params.getBool("NavSettingLeftSide");
|
||||
s->scene.map_on_left = params.getBool("NavSettingLeftSide");
|
||||
|
||||
scene.visual_brake_lights = params.getBool("BrakeLights");
|
||||
scene.onroadScreenOff = std::atoi(params.get("OnroadScreenOff").c_str());
|
||||
scene.onroadScreenOffBrightness = std::atoi(params.get("OnroadScreenOffBrightness").c_str());
|
||||
scene.onroadScreenOffEvent = params.getBool("OnroadScreenOffEvent");
|
||||
scene.stand_still_timer = params.getBool("StandStillTimer");
|
||||
scene.show_debug_ui = params.getBool("ShowDebugUI");
|
||||
scene.hide_vego_ui = params.getBool("HideVEgoUi");
|
||||
scene.true_vego_ui = params.getBool("TrueVEgoUi");
|
||||
scene.chevron_data = std::atoi(params.get("ChevronInfo").c_str());
|
||||
scene.dev_ui_info = std::atoi(params.get("DevUIInfo").c_str());
|
||||
scene.button_auto_hide = params.getBool("ButtonAutoHide");
|
||||
scene.reverse_dm_cam = params.getBool("ReverseDmCam");
|
||||
scene.e2e_long_alert_light = params.getBool("EndToEndLongAlertLight");
|
||||
scene.e2e_long_alert_lead = params.getBool("EndToEndLongAlertLead");
|
||||
scene.e2e_long_alert_ui = params.getBool("EndToEndLongAlertUI");
|
||||
scene.map_3d_buildings = params.getBool("Map3DBuildings");
|
||||
scene.live_torque_toggle = params.getBool("LiveTorque");
|
||||
scene.torqued_override = params.getBool("TorquedOverride");
|
||||
scene.speed_limit_control_engage_type = std::atoi(params.get("SpeedLimitEngageType").c_str());
|
||||
scene.mapbox_fullscreen = params.getBool("MapboxFullScreen");
|
||||
scene.speed_limit_warning_flash = params.getBool("SpeedLimitWarningFlash");
|
||||
scene.speed_limit_warning_type = std::atoi(params.get("SpeedLimitWarningType").c_str());
|
||||
scene.speed_limit_warning_value_offset = std::atoi(params.get("SpeedLimitWarningValueOffset").c_str());
|
||||
scene.speed_limit_control_enabled = params.getBool("EnableSlc");
|
||||
scene.feature_status_toggle = params.getBool("FeatureStatus");
|
||||
scene.onroad_settings_toggle = params.getBool("OnroadSettings");
|
||||
s->scene.visual_brake_lights = params.getBool("BrakeLights");
|
||||
s->scene.onroadScreenOff = std::atoi(params.get("OnroadScreenOff").c_str());
|
||||
s->scene.onroadScreenOffBrightness = std::atoi(params.get("OnroadScreenOffBrightness").c_str());
|
||||
s->scene.onroadScreenOffEvent = params.getBool("OnroadScreenOffEvent");
|
||||
s->scene.stand_still_timer = params.getBool("StandStillTimer");
|
||||
s->scene.show_debug_ui = params.getBool("ShowDebugUI");
|
||||
s->scene.hide_vego_ui = params.getBool("HideVEgoUi");
|
||||
s->scene.true_vego_ui = params.getBool("TrueVEgoUi");
|
||||
s->scene.chevron_data = std::atoi(params.get("ChevronInfo").c_str());
|
||||
s->scene.dev_ui_info = std::atoi(params.get("DevUIInfo").c_str());
|
||||
s->scene.button_auto_hide = params.getBool("ButtonAutoHide");
|
||||
s->scene.reverse_dm_cam = params.getBool("ReverseDmCam");
|
||||
s->scene.e2e_long_alert_light = params.getBool("EndToEndLongAlertLight");
|
||||
s->scene.e2e_long_alert_lead = params.getBool("EndToEndLongAlertLead");
|
||||
s->scene.e2e_long_alert_ui = params.getBool("EndToEndLongAlertUI");
|
||||
s->scene.map_3d_buildings = params.getBool("Map3DBuildings");
|
||||
s->scene.live_torque_toggle = params.getBool("LiveTorque");
|
||||
s->scene.torqued_override = params.getBool("TorquedOverride");
|
||||
s->scene.speed_limit_control_engage_type = std::atoi(params.get("SpeedLimitEngageType").c_str());
|
||||
s->scene.mapbox_fullscreen = params.getBool("MapboxFullScreen");
|
||||
s->scene.speed_limit_warning_flash = params.getBool("SpeedLimitWarningFlash");
|
||||
s->scene.speed_limit_warning_type = std::atoi(params.get("SpeedLimitWarningType").c_str());
|
||||
s->scene.speed_limit_warning_value_offset = std::atoi(params.get("SpeedLimitWarningValueOffset").c_str());
|
||||
s->scene.speed_limit_control_enabled = params.getBool("EnableSlc");
|
||||
s->scene.feature_status_toggle = params.getBool("FeatureStatus");
|
||||
s->scene.onroad_settings_toggle = params.getBool("OnroadSettings");
|
||||
|
||||
// Handle Onroad Screen Off params
|
||||
if (scene.onroadScreenOff > 0) {
|
||||
scene.osoTimer = scene.onroadScreenOff * 60 * UI_FREQ;
|
||||
} else if (scene.onroadScreenOff == 0) {
|
||||
scene.osoTimer = 30 * UI_FREQ;
|
||||
} else if (scene.onroadScreenOff == -1) {
|
||||
scene.osoTimer = 15 * UI_FREQ;
|
||||
if (s->scene.onroadScreenOff > 0) {
|
||||
s->scene.osoTimer = s->scene.onroadScreenOff * 60 * UI_FREQ;
|
||||
} else if (s->scene.onroadScreenOff == 0) {
|
||||
s->scene.osoTimer = 30 * UI_FREQ;
|
||||
} else if (s->scene.onroadScreenOff == -1) {
|
||||
s->scene.osoTimer = 15 * UI_FREQ;
|
||||
} else {
|
||||
scene.osoTimer = -1;
|
||||
s->scene.osoTimer = -1;
|
||||
}
|
||||
}
|
||||
|
||||
void UIStateSP::updateStatus() {
|
||||
UIState::updateStatus();
|
||||
auto params = Params();
|
||||
if (scene_sp.started && sm->updated("controlsState")) {
|
||||
auto controls_state = (*sm)["controlsState"].getControlsState();
|
||||
auto car_control = (*sm)["carControl"].getCarControl();
|
||||
auto car_state = (*sm)["carState"].getCarState();
|
||||
auto mads_enabled = car_state.getMadsEnabled();
|
||||
auto state = controls_state.getState();
|
||||
if (state == cereal::ControlsState::OpenpilotState::PRE_ENABLED || state == cereal::ControlsState::OpenpilotState::OVERRIDING) {
|
||||
status_sp = STATUS_OVERRIDE_SP;
|
||||
} else {
|
||||
status_sp = car_state.getMadsEnabled() ? car_control.getLongActive() ? STATUS_ENGAGED_SP : STATUS_MADS_SP : STATUS_DISENGAGED_SP;
|
||||
auto car_control = (*sm)["carControl"].getCarControl();
|
||||
auto car_state = (*sm)["carState"].getCarState();
|
||||
auto mads_enabled = car_state.getMadsEnabled();
|
||||
if (scene.started && sm->updated("controlsState")) {
|
||||
if (status != STATUS_OVERRIDE) {
|
||||
status = car_state.getMadsEnabled() ? car_control.getLongActive() ? STATUS_ENGAGED : STATUS_MADS : STATUS_DISENGAGED;
|
||||
}
|
||||
|
||||
|
||||
if (mads_enabled != last_mads_enabled) {
|
||||
mads_path_state = true;
|
||||
}
|
||||
@@ -191,79 +185,104 @@ void UIStateSP::updateStatus() {
|
||||
}
|
||||
}
|
||||
}
|
||||
scene_sp.mads_path_scale = mads_path_count * (1 / mads_path_timestep);
|
||||
scene.mads_path_scale = mads_path_count * (1 / mads_path_timestep);
|
||||
}
|
||||
|
||||
if (scene_sp.started) {
|
||||
if (scene.started) {
|
||||
// Auto hide UI button state machine
|
||||
{
|
||||
if (scene_sp.button_auto_hide) {
|
||||
if (scene_sp.touch_to_wake) {
|
||||
scene_sp.sleep_btn = 30 * UI_FREQ;
|
||||
} else if (scene_sp.sleep_btn > 0) {
|
||||
scene_sp.sleep_btn--;
|
||||
} else if (scene_sp.sleep_btn == -1) {
|
||||
scene_sp.sleep_btn = 30 * UI_FREQ;
|
||||
if (scene.button_auto_hide) {
|
||||
if (scene.touch_to_wake) {
|
||||
scene.sleep_btn = 30 * UI_FREQ;
|
||||
} else if (scene.sleep_btn > 0) {
|
||||
scene.sleep_btn--;
|
||||
} else if (scene.sleep_btn == -1) {
|
||||
scene.sleep_btn = 30 * UI_FREQ;
|
||||
}
|
||||
// Check if the sleep button should be fading in
|
||||
if (scene_sp.sleep_btn_fading_in) {
|
||||
if (scene.sleep_btn_fading_in) {
|
||||
// Increase the opacity of the sleep button by a small amount
|
||||
if (scene_sp.sleep_btn_opacity < 20) {
|
||||
scene_sp.sleep_btn_opacity+= 10;
|
||||
if (scene.sleep_btn_opacity < 20) {
|
||||
scene.sleep_btn_opacity+= 10;
|
||||
}
|
||||
if (scene_sp.sleep_btn_opacity >= 20) {
|
||||
if (scene.sleep_btn_opacity >= 20) {
|
||||
// If the opacity has reached its maximum value, stop fading in
|
||||
scene_sp.sleep_btn_fading_in = false;
|
||||
scene_sp.sleep_btn_opacity = 20;
|
||||
scene.sleep_btn_fading_in = false;
|
||||
scene.sleep_btn_opacity = 20;
|
||||
}
|
||||
} else if (scene_sp.sleep_btn == 0) {
|
||||
} else if (scene.sleep_btn == 0) {
|
||||
// Fade out the sleep button as before
|
||||
if (scene_sp.sleep_btn_opacity > 0) {
|
||||
scene_sp.sleep_btn_opacity-= 2;
|
||||
if (scene.sleep_btn_opacity > 0) {
|
||||
scene.sleep_btn_opacity-= 2;
|
||||
}
|
||||
} else {
|
||||
// Set the opacity of the sleep button to its maximum value
|
||||
scene_sp.sleep_btn_opacity = 20;
|
||||
scene.sleep_btn_opacity = 20;
|
||||
}
|
||||
} else {
|
||||
scene_sp.sleep_btn_opacity = 20;
|
||||
scene.sleep_btn_opacity = 20;
|
||||
}
|
||||
}
|
||||
|
||||
// Onroad Screen Off Brightness + Timer + Global Brightness
|
||||
{
|
||||
if (scene_sp.onroadScreenOff != -2 && scene_sp.touched2) {
|
||||
scene_sp.sleep_time = scene_sp.osoTimer;
|
||||
} else if (scene_sp.onroadScreenOff != -2 &&
|
||||
((scene_sp.controlsState.getAlertSize() != cereal::ControlsState::AlertSize::NONE) &&
|
||||
((scene_sp.controlsState.getAlertStatus() == cereal::ControlsState::AlertStatus::NORMAL && scene_sp.onroadScreenOffEvent) ||
|
||||
(scene_sp.controlsState.getAlertStatus() != cereal::ControlsState::AlertStatus::NORMAL)))) {
|
||||
scene_sp.sleep_time = scene_sp.osoTimer;
|
||||
} else if (scene_sp.sleep_time > 0 && scene_sp.onroadScreenOff != -2) {
|
||||
scene_sp.sleep_time--;
|
||||
} else if (scene_sp.sleep_time == -1 && scene_sp.onroadScreenOff != -2) {
|
||||
scene_sp.sleep_time = scene_sp.osoTimer;
|
||||
if (scene.onroadScreenOff != -2 && scene.touched2) {
|
||||
scene.sleep_time = scene.osoTimer;
|
||||
} else if (scene.onroadScreenOff != -2 &&
|
||||
((scene.controlsState.getAlertSize() != cereal::ControlsState::AlertSize::NONE) &&
|
||||
((scene.controlsState.getAlertStatus() == cereal::ControlsState::AlertStatus::NORMAL && scene.onroadScreenOffEvent) ||
|
||||
(scene.controlsState.getAlertStatus() != cereal::ControlsState::AlertStatus::NORMAL)))) {
|
||||
scene.sleep_time = scene.osoTimer;
|
||||
} else if (scene.sleep_time > 0 && scene.onroadScreenOff != -2) {
|
||||
scene.sleep_time--;
|
||||
} else if (scene.sleep_time == -1 && scene.onroadScreenOff != -2) {
|
||||
scene.sleep_time = scene.osoTimer;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (sm->frame % UI_FREQ == 0) { // Update every 1 Hz
|
||||
scene_sp.sidebar_temp_options = std::atoi(params.get("SidebarTemperatureOptions").c_str());
|
||||
scene.sidebar_temp_options = std::atoi(params.get("SidebarTemperatureOptions").c_str());
|
||||
}
|
||||
|
||||
scene_sp.brightness = std::atoi(params.get("BrightnessControl").c_str());
|
||||
scene.brightness = std::atoi(params.get("BrightnessControl").c_str());
|
||||
}
|
||||
|
||||
UIStateSP::UIStateSP(QObject *parent) : UIState(parent) {
|
||||
// todo: Can we simply append to SM?
|
||||
sm = std::make_unique<SubMaster, const std::initializer_list<const char *>>({
|
||||
"modelV2", "controlsState", "liveCalibration", "radarState", "deviceState",
|
||||
"pandaStates", "carParams", "driverMonitoringState", "carState", "liveLocationKalman", "driverStateV2",
|
||||
"wideRoadCameraState", "managerState", "navInstruction", "navRoute", "clocks", "longitudinalPlanSP", "liveMapDataSP",
|
||||
"carControl", "lateralPlanSPDEPRECATED", "gpsLocation", "gpsLocationExternal", "liveParameters", "liveTorqueParameters",
|
||||
"controlsStateSP", "modelV2SP"
|
||||
});
|
||||
|
||||
Params params;
|
||||
language = QString::fromStdString(params.get("LanguageSetting"));
|
||||
auto prime_value = params.get("PrimeType");
|
||||
if (!prime_value.empty()) {
|
||||
prime_type = static_cast<PrimeType>(std::atoi(prime_value.c_str()));
|
||||
}
|
||||
|
||||
// update timer
|
||||
timer = new QTimer(this);
|
||||
QObject::connect(timer, &QTimer::timeout, this, &UIStateSP::update);
|
||||
timer->start(1000 / UI_FREQ);
|
||||
}
|
||||
|
||||
void UIStateSP::update() {
|
||||
update_state(this);
|
||||
update_sockets(this);
|
||||
sp_update_state(this);
|
||||
updateStatus();
|
||||
UIState::update();
|
||||
|
||||
if (sm->frame % UI_FREQ == 0) {
|
||||
watchdog_kick(nanos_since_boot());
|
||||
}
|
||||
emit uiUpdate(*this);
|
||||
}
|
||||
|
||||
|
||||
void UIStateSP::setSunnylinkRoles(const std::vector<RoleModel>& roles) {
|
||||
sunnylinkRoles = roles;
|
||||
emit sunnylinkRolesChanged(roles);
|
||||
@@ -274,39 +293,19 @@ void UIStateSP::setSunnylinkDeviceUsers(const std::vector<UserModel>& users) {
|
||||
emit sunnylinkDeviceUsersChanged(users);
|
||||
}
|
||||
|
||||
DeviceSP::DeviceSP(QObject *parent) : Device(parent) {
|
||||
QObject::connect(uiStateSP(), &UIStateSP::uiUpdate, this, &DeviceSP::update);
|
||||
}
|
||||
|
||||
void DeviceSP::update(const UIStateSP &s) {
|
||||
updateBrightness(s);
|
||||
updateWakefulness(s);
|
||||
DeviceSP::DeviceSP(QObject *parent) : Device(parent){
|
||||
}
|
||||
|
||||
//todo: revisit this
|
||||
void DeviceSP::updateBrightness(const UIStateSP &s) {
|
||||
UISceneSP scene = s.scene_sp;
|
||||
float clipped_brightness = offroad_brightness;
|
||||
if (scene.started && scene.light_sensor > 0) {
|
||||
clipped_brightness = scene.light_sensor;
|
||||
|
||||
// CIE 1931 - https://www.photonstophotos.net/GeneralTopics/Exposure/Psychometric_Lightness_and_Gamma.htm
|
||||
if (clipped_brightness <= 8) {
|
||||
clipped_brightness = (clipped_brightness / 903.3);
|
||||
} else {
|
||||
clipped_brightness = std::pow((clipped_brightness + 16.0) / 116.0, 3.0);
|
||||
}
|
||||
|
||||
// Scale back to 10% to 100%
|
||||
clipped_brightness = std::clamp(100.0f * clipped_brightness, 10.0f, 100.0f);
|
||||
}
|
||||
|
||||
Device::updateBrightness(s);
|
||||
int brightness = brightness_filter.update(clipped_brightness);
|
||||
if (!awake) {
|
||||
brightness = 0;
|
||||
} else if (scene.started && scene.sleep_time == 0 && scene.onroadScreenOff != -2) {
|
||||
brightness = scene.onroadScreenOffBrightness * 0.01 * brightness;
|
||||
} else if (scene.brightness) {
|
||||
brightness = scene.brightness * 0.99;
|
||||
} else if (s.scene.started && s.scene.sleep_time == 0 && s.scene.onroadScreenOff != -2) {
|
||||
brightness = s.scene.onroadScreenOffBrightness * 0.01 * brightness;
|
||||
} else if (s.scene.brightness) {
|
||||
brightness = s.scene.brightness * 0.99;
|
||||
}
|
||||
|
||||
if (brightness != last_brightness) {
|
||||
@@ -318,11 +317,11 @@ void DeviceSP::updateBrightness(const UIStateSP &s) {
|
||||
}
|
||||
|
||||
UIStateSP *uiStateSP() {
|
||||
static UIStateSP ui_state_sp;
|
||||
return &ui_state_sp;
|
||||
static UIStateSP ui_state;
|
||||
return &ui_state;
|
||||
}
|
||||
|
||||
DeviceSP *deviceSP() {
|
||||
static DeviceSP _device_sp;
|
||||
return &_device_sp;
|
||||
}
|
||||
static DeviceSP _device;
|
||||
return &_device;
|
||||
}
|
||||
@@ -1,15 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
#include "selfdrive/ui/ui.h"
|
||||
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
|
||||
#include <QColor>
|
||||
|
||||
#include "selfdrive/ui/sunnypilot/qt/network/sunnylink/models/sp_priv_role_model.h"
|
||||
#include "selfdrive/ui/sunnypilot/qt/network/sunnylink/models/sp_priv_sponsor_role_model.h"
|
||||
#include "selfdrive/ui/sunnypilot/qt/network/sunnylink/models/sp_priv_user_model.h"
|
||||
#include "cereal/messaging/messaging.h"
|
||||
#include "common/timing.h"
|
||||
#include "qt/network/sunnylink/models/sp_priv_role_model.h"
|
||||
#include "qt/network/sunnylink/models/sp_priv_sponsor_role_model.h"
|
||||
#include "qt/network/sunnylink/models/sp_priv_user_model.h"
|
||||
#include "selfdrive/ui/sunnypilot/qt/sp_priv_ui_scene.h"
|
||||
#include "system/hardware/hw.h"
|
||||
|
||||
const int UI_ROAD_NAME_MARGIN_X = 14;
|
||||
|
||||
@@ -25,23 +28,15 @@ struct FeatureStatusColor {
|
||||
const QStringList slc_list_color = { "#ffffff", "#ffffff", "#fcff4b", "#4bff66", "#fcff4b" };
|
||||
};
|
||||
|
||||
const float DRIVING_PATH_WIDE = 0.9;
|
||||
const float DRIVING_PATH_NARROW = 0.25;
|
||||
|
||||
typedef enum UIStatusSP {
|
||||
STATUS_DISENGAGED_SP = STATUS_DISENGAGED,
|
||||
STATUS_OVERRIDE_SP = STATUS_OVERRIDE,
|
||||
STATUS_ENGAGED_SP = STATUS_ENGAGED,
|
||||
STATUS_MADS_SP,
|
||||
} UIStatusSP;
|
||||
|
||||
const QColor bg_colors_sp [] = {
|
||||
[STATUS_DISENGAGED_SP] = QColor(0x17, 0x33, 0x49, 0xc8),
|
||||
[STATUS_OVERRIDE_SP] = QColor(0x91, 0x9b, 0x95, 0xf1),
|
||||
[STATUS_ENGAGED_SP] = QColor(0x00, 0xc8, 0x00, 0xf1),
|
||||
[STATUS_MADS_SP] = QColor(0x00, 0xc8, 0xc8, 0xf1),
|
||||
const QColor sp_bg_colors [] = {
|
||||
[STATUS_DISENGAGED] = bg_colors[STATUS_DISENGAGED],
|
||||
[STATUS_OVERRIDE] = bg_colors[STATUS_OVERRIDE],
|
||||
[STATUS_ENGAGED] = QColor(0x00, 0xc8, 0x00, 0xf1),
|
||||
[STATUS_MADS] = QColor(0x00, 0xc8, 0xc8, 0xf1),
|
||||
};
|
||||
|
||||
|
||||
const QColor tcs_colors [] = {
|
||||
[int(cereal::LongitudinalPlanSP::VisionTurnControllerState::DISABLED)] = QColor(0x0, 0x0, 0x0, 0xff),
|
||||
[int(cereal::LongitudinalPlanSP::VisionTurnControllerState::ENTERING)] = QColor(0xC9, 0x22, 0x31, 0xf1),
|
||||
@@ -49,101 +44,18 @@ const QColor tcs_colors [] = {
|
||||
[int(cereal::LongitudinalPlanSP::VisionTurnControllerState::LEAVING)] = QColor(0x17, 0x86, 0x44, 0xf1),
|
||||
};
|
||||
|
||||
typedef struct UISceneSP : UIScene {
|
||||
cereal::ControlsState::Reader controlsState;
|
||||
|
||||
// Debug UI
|
||||
bool show_debug_ui;
|
||||
|
||||
// Speed limit control
|
||||
bool speed_limit_control_enabled;
|
||||
int speed_limit_control_policy;
|
||||
double last_speed_limit_sign_tap;
|
||||
|
||||
// modelV2
|
||||
QPolygonF track_edge_vertices;
|
||||
QPolygonF lane_barrier_vertices[2];
|
||||
|
||||
bool navigate_on_openpilot_deprecated = false;
|
||||
cereal::AccelerationPersonality accel_personality;
|
||||
|
||||
bool map_on_left;
|
||||
|
||||
int dynamic_lane_profile;
|
||||
bool dynamic_lane_profile_status = true;
|
||||
|
||||
bool visual_brake_lights;
|
||||
|
||||
int onroadScreenOff, osoTimer, brightness, onroadScreenOffBrightness, awake;
|
||||
bool onroadScreenOffEvent;
|
||||
int sleep_time = -1;
|
||||
bool touched2 = false;
|
||||
|
||||
bool stand_still_timer;
|
||||
|
||||
bool hide_vego_ui, true_vego_ui;
|
||||
|
||||
int chevron_data;
|
||||
|
||||
bool gac;
|
||||
int longitudinal_personality;
|
||||
int longitudinal_accel_personality;
|
||||
|
||||
bool map_visible;
|
||||
int dev_ui_info;
|
||||
bool live_torque_toggle;
|
||||
|
||||
bool touch_to_wake = false;
|
||||
int sleep_btn = -1;
|
||||
bool sleep_btn_fading_in = false;
|
||||
int sleep_btn_opacity = 20;
|
||||
bool button_auto_hide;
|
||||
|
||||
bool reverse_dm_cam;
|
||||
|
||||
bool e2e_long_alert_light, e2e_long_alert_lead, e2e_long_alert_ui;
|
||||
float e2eX[13] = {0};
|
||||
|
||||
int sidebar_temp_options;
|
||||
|
||||
float mads_path_scale = DRIVING_PATH_WIDE - DRIVING_PATH_NARROW;
|
||||
float mads_path_range = DRIVING_PATH_WIDE - DRIVING_PATH_NARROW; // 0.9 - 0.25 = 0.65
|
||||
|
||||
bool onroad_settings_visible;
|
||||
|
||||
bool map_3d_buildings;
|
||||
|
||||
bool torqued_override;
|
||||
|
||||
bool dynamic_experimental_control;
|
||||
|
||||
int speed_limit_control_engage_type;
|
||||
|
||||
bool mapbox_fullscreen;
|
||||
|
||||
bool speed_limit_warning_flash;
|
||||
int speed_limit_warning_type;
|
||||
int speed_limit_warning_value_offset;
|
||||
|
||||
bool custom_driving_model_valid;
|
||||
cereal::ModelGeneration driving_model_generation;
|
||||
uint32_t driving_model_capabilities;
|
||||
|
||||
bool feature_status_toggle;
|
||||
bool onroad_settings_toggle;
|
||||
|
||||
bool dynamic_personality;
|
||||
} UISceneSP;
|
||||
|
||||
class UIStateSP : public UIState {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
UIStateSP(QObject* parent = nullptr);
|
||||
void updateStatus();
|
||||
UIStateSP(QObject* parent = 0);
|
||||
void updateStatus() override;
|
||||
|
||||
void setSunnylinkRoles(const std::vector<RoleModel> &roles);
|
||||
void setSunnylinkDeviceUsers(const std::vector<UserModel> &users);
|
||||
|
||||
UISceneSP scene = {};
|
||||
|
||||
inline std::vector<RoleModel> sunnylinkDeviceRoles() const { return sunnylinkRoles; }
|
||||
inline bool isSunnylinkAdmin() const {
|
||||
return std::any_of(sunnylinkRoles.begin(), sunnylinkRoles.end(), [](const RoleModel &role) {
|
||||
@@ -158,9 +70,9 @@ public:
|
||||
inline SponsorRoleModel sunnylinkSponsorRole() const {
|
||||
std::optional<SponsorRoleModel> sponsorRoleWithHighestTier = std::nullopt;
|
||||
for (const auto &role : sunnylinkRoles) {
|
||||
if (role.roleType != RoleType::Sponsor)
|
||||
if(role.roleType != RoleType::Sponsor)
|
||||
continue;
|
||||
|
||||
|
||||
if (auto sponsorRole = role.as<SponsorRoleModel>(); !sponsorRoleWithHighestTier.has_value() || sponsorRoleWithHighestTier->roleTier < sponsorRole.roleTier) {
|
||||
sponsorRoleWithHighestTier = sponsorRole;
|
||||
}
|
||||
@@ -177,17 +89,15 @@ public:
|
||||
});
|
||||
}
|
||||
|
||||
UIStatusSP status_sp;
|
||||
UISceneSP scene_sp = {};
|
||||
|
||||
signals:
|
||||
void uiUpdate(const UIStateSP &s);
|
||||
void sunnylinkRoleChanged(bool subscriber);
|
||||
void sunnylinkRolesChanged(std::vector<RoleModel> roles);
|
||||
void sunnylinkDeviceUsersChanged(std::vector<UserModel> users);
|
||||
void uiUpdate(const UIStateSP &s);
|
||||
|
||||
private slots:
|
||||
void update();
|
||||
void update() override;
|
||||
|
||||
|
||||
private:
|
||||
std::vector<RoleModel> sunnylinkRoles = {};
|
||||
@@ -197,30 +107,21 @@ private:
|
||||
bool mads_path_state = false;
|
||||
float mads_path_timestep = 4; // UI runs at 20 Hz, therefore 0.2 second is [0.2 second / (1 / 20 Hz) = 4]
|
||||
float mads_path_count = 4; // UI runs at 20 Hz, therefore 0.2 second is [0.2 second / (1 / 20 Hz) = 4]
|
||||
|
||||
public slots:
|
||||
void update(const UIStateSP &s);
|
||||
};
|
||||
|
||||
//TODO: maybe need to redeclare but the sp?
|
||||
UIStateSP *uiStateSP();
|
||||
|
||||
// device management class
|
||||
class DeviceSP : public Device {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
DeviceSP(QObject *parent = nullptr);
|
||||
void updateBrightness(const UIStateSP &s);
|
||||
|
||||
DeviceSP(QObject *parent = 0);
|
||||
protected:
|
||||
void updateBrightness(const UIState &s);
|
||||
|
||||
public slots:
|
||||
void update(const UIStateSP &s);
|
||||
void updateBrightness(const UIStateSP &s);
|
||||
};
|
||||
|
||||
DeviceSP *deviceSP();
|
||||
|
||||
void update_model(UIState *s,
|
||||
const cereal::ModelDataV2::Reader &model);
|
||||
void update_line_data(const UIState *s, const cereal::XYZTData::Reader &line,
|
||||
void sp_update_model(UIStateSP *s, const cereal::ModelDataV2::Reader &model);
|
||||
void update_line_data(const UIStateSP *s, const cereal::XYZTData::Reader &line,
|
||||
float y_off, float z_off_left, float z_off_right, QPolygonF *pvd, int max_idx, bool allow_invert);
|
||||
|
||||
+10
-11
@@ -11,7 +11,6 @@
|
||||
#include "common/swaglog.h"
|
||||
#include "common/util.h"
|
||||
#include "common/watchdog.h"
|
||||
#include "qt/util.h"
|
||||
#include "system/hardware/hw.h"
|
||||
|
||||
#define BACKLIGHT_DT 0.05
|
||||
@@ -19,8 +18,7 @@
|
||||
|
||||
// Projects a point in car to space to the corresponding point in full frame
|
||||
// image space.
|
||||
static bool calib_frame_to_full_frame(const UIState *s, float in_x, float in_y, float in_z, QPointF *out) {
|
||||
const float margin = 500.0f;
|
||||
bool calib_frame_to_full_frame(const UIState *s, float in_x, float in_y, float in_z, QPointF *out, const float margin) {
|
||||
const QRectF clip_region{-margin, -margin, s->fb_w + 2 * margin, s->fb_h + 2 * margin};
|
||||
|
||||
const vec3 pt = (vec3){{in_x, in_y, in_z}};
|
||||
@@ -146,11 +144,11 @@ void update_dmonitoring(UIState *s, const cereal::DriverStateV2::Reader &drivers
|
||||
}
|
||||
}
|
||||
|
||||
static void update_sockets(UIState *s) {
|
||||
void update_sockets(UIState *s) {
|
||||
s->sm->update(0);
|
||||
}
|
||||
|
||||
static void update_state(UIState *s) {
|
||||
void update_state(UIState *s) {
|
||||
SubMaster &sm = *(s->sm);
|
||||
UIScene &scene = s->scene;
|
||||
|
||||
@@ -244,9 +242,7 @@ UIState::UIState(QObject *parent) : QObject(parent) {
|
||||
sm = std::make_unique<SubMaster, const std::initializer_list<const char *>>({
|
||||
"modelV2", "controlsState", "liveCalibration", "radarState", "deviceState",
|
||||
"pandaStates", "carParams", "driverMonitoringState", "carState", "liveLocationKalman", "driverStateV2",
|
||||
"wideRoadCameraState", "managerState", "navInstruction", "navRoute", "clocks", "longitudinalPlanSP", "liveMapDataSP",
|
||||
"carControl", "lateralPlanSPDEPRECATED", "gpsLocation", "gpsLocationExternal", "liveParameters", "liveTorqueParameters",
|
||||
"controlsStateSP", "modelV2SP"
|
||||
"wideRoadCameraState", "managerState", "clocks",
|
||||
});
|
||||
|
||||
Params params;
|
||||
@@ -267,6 +263,10 @@ void UIState::update() {
|
||||
update_state(this);
|
||||
updateStatus();
|
||||
|
||||
if (std::getenv("PRIME_TYPE")) {
|
||||
setPrimeType((PrimeType)atoi(std::getenv("PRIME_TYPE")));
|
||||
}
|
||||
|
||||
if (sm->frame % UI_FREQ == 0) {
|
||||
watchdog_kick(nanos_since_boot());
|
||||
}
|
||||
@@ -292,7 +292,6 @@ Device::Device(QObject *parent) : brightness_filter(BACKLIGHT_OFFROAD, BACKLIGHT
|
||||
setAwake(true);
|
||||
resetInteractiveTimeout();
|
||||
|
||||
RETURN_IF_SUNNYPILOT
|
||||
QObject::connect(uiState(), &UIState::uiUpdate, this, &Device::update);
|
||||
}
|
||||
|
||||
@@ -318,7 +317,7 @@ void Device::resetInteractiveTimeout(int timeout) {
|
||||
}
|
||||
|
||||
void Device::updateBrightness(const UIState &s) {
|
||||
float clipped_brightness = offroad_brightness;
|
||||
clipped_brightness = offroad_brightness;
|
||||
if (s.scene.started && s.scene.light_sensor > 0) {
|
||||
clipped_brightness = s.scene.light_sensor;
|
||||
|
||||
@@ -367,4 +366,4 @@ UIState *uiState() {
|
||||
Device *device() {
|
||||
static Device _device;
|
||||
return &_device;
|
||||
}
|
||||
}
|
||||
+21
-5
@@ -45,13 +45,22 @@ constexpr vec3 default_face_kpts_3d[] = {
|
||||
{18.02, -49.14, 8.00}, {6.36, -51.20, 8.00}, {-5.98, -51.20, 8.00},
|
||||
};
|
||||
|
||||
//Example of a macro
|
||||
#ifdef SUNNYPILOT
|
||||
#define EXTRA_UI_STATES STATUS_MADS, STATUS_LA
|
||||
#else
|
||||
#define EXTRA_UI_STATES
|
||||
#endif
|
||||
|
||||
typedef enum UIStatus {
|
||||
STATUS_DISENGAGED,
|
||||
STATUS_OVERRIDE,
|
||||
STATUS_ENGAGED,
|
||||
EXTRA_UI_STATES
|
||||
} UIStatus;
|
||||
|
||||
|
||||
|
||||
enum PrimeType {
|
||||
UNKNOWN = -2,
|
||||
UNPAIRED = -1,
|
||||
@@ -108,7 +117,7 @@ class UIState : public QObject {
|
||||
|
||||
public:
|
||||
UIState(QObject* parent = 0);
|
||||
void updateStatus();
|
||||
virtual void updateStatus();
|
||||
inline bool engaged() const {
|
||||
return scene.started && (*sm)["controlsState"].getControlsState().getEnabled();
|
||||
}
|
||||
@@ -135,12 +144,14 @@ signals:
|
||||
void primeTypeChanged(PrimeType prime_type);
|
||||
|
||||
protected slots:
|
||||
void update();
|
||||
virtual void update();
|
||||
|
||||
private:
|
||||
protected:
|
||||
QTimer *timer;
|
||||
bool started_prev = false;
|
||||
PrimeType prime_type = PrimeType::UNKNOWN;
|
||||
|
||||
private:
|
||||
bool started_prev = false;
|
||||
};
|
||||
|
||||
UIState *uiState();
|
||||
@@ -166,9 +177,10 @@ protected:
|
||||
FirstOrderFilter brightness_filter;
|
||||
QFuture<void> brightness_future;
|
||||
|
||||
void updateBrightness(const UIState &s);
|
||||
virtual void updateBrightness(const UIState &s);
|
||||
void updateWakefulness(const UIState &s);
|
||||
void setAwake(bool on);
|
||||
float clipped_brightness;
|
||||
|
||||
signals:
|
||||
void displayPowerChanged(bool on);
|
||||
@@ -189,3 +201,7 @@ void update_dmonitoring(UIState *s, const cereal::DriverStateV2::Reader &drivers
|
||||
void update_leads(UIState *s, const cereal::RadarState::Reader &radar_state, const cereal::XYZTData::Reader &line);
|
||||
void update_line_data(const UIState *s, const cereal::XYZTData::Reader &line,
|
||||
float y_off, float z_off, QPolygonF *pvd, int max_idx, bool allow_invert);
|
||||
|
||||
bool calib_frame_to_full_frame(const UIState *s, float in_x, float in_y, float in_z, QPointF *out, float margin=500.0f);
|
||||
void update_state(UIState *s);
|
||||
void update_sockets(UIState *s);
|
||||
Reference in New Issue
Block a user