Skip to content

Commit 2fc8a11

Browse files
Comma Devicessysm
authored andcommitted
update entry and gps
1 parent 858b65a commit 2fc8a11

File tree

12 files changed

+158
-14
lines changed

12 files changed

+158
-14
lines changed

cereal/custom.capnp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ $Cxx.namespace("cereal");
1111
# DON'T change the identifier (e.g. @0x81c2f05a394cf4af)
1212

1313
struct CustomReserved0 @0x81c2f05a394cf4af {
14+
dashcamEnable @0 :Bool;
1415
}
1516

1617
struct CustomReserved1 @0xaedffd8f31e7b55d {

cereal/services.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ def __init__(self, should_log: bool, frequency: float, decimation: Optional[int]
9191
"customReservedRawData0": (True, 0.),
9292
"customReservedRawData1": (True, 0.),
9393
"customReservedRawData2": (True, 0.),
94+
95+
"customReserved0": (True, 0.),
9496
}
9597
SERVICE_LIST = {name: Service(*vals) for
9698
idx, (name, vals) in enumerate(_services.items())}

selfdrive/ui/SConscript

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ qt_libs = [widgets, qt_util] + base_libs
2929
qt_src = ["main.cc", "ui.cc", "qt/sidebar.cc", "qt/body.cc",
3030
"qt/window.cc", "qt/home.cc", "qt/offroad/settings.cc",
3131
"qt/offroad/software_settings.cc", "qt/offroad/developer_panel.cc", "qt/offroad/onboarding.cc",
32-
"qt/offroad/driverview.cc", "qt/offroad/experimental_mode.cc",
32+
"qt/offroad/driverview.cc", "qt/offroad/experimental_mode.cc", "qt/offroad/dashcam_mode.cc",
3333
"qt/onroad/onroad_home.cc", "qt/onroad/annotated_camera.cc", "qt/onroad/model.cc",
3434
"qt/onroad/buttons.cc", "qt/onroad/alerts.cc", "qt/onroad/driver_monitoring.cc", "qt/onroad/hud.cc"]
3535

selfdrive/ui/qt/home.cc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <QVBoxLayout>
77

88
#include "selfdrive/ui/qt/offroad/experimental_mode.h"
9+
#include "selfdrive/ui/qt/offroad/dashcam_mode.h"
910
#include "selfdrive/ui/qt/util.h"
1011
#include "selfdrive/ui/qt/widgets/prime.h"
1112

@@ -25,6 +26,7 @@ HomeWindow::HomeWindow(QWidget* parent) : QWidget(parent) {
2526

2627
home = new OffroadHome(this);
2728
QObject::connect(home, &OffroadHome::openSettings, this, &HomeWindow::openSettings);
29+
QObject::connect(home, &OffroadHome::toggleDashcam, this, &HomeWindow::toggleDashcam);
2830
slayout->addWidget(home);
2931

3032
onroad = new OnroadWindow(this);
@@ -44,6 +46,15 @@ HomeWindow::HomeWindow(QWidget* parent) : QWidget(parent) {
4446
QObject::connect(uiState(), &UIState::offroadTransition, sidebar, &Sidebar::offroadTransition);
4547
}
4648

49+
void HomeWindow::toggleDashcam(){
50+
MessageBuilder msg;
51+
printf("Toggle dashcam\n");
52+
this->enableDashcam = !this->enableDashcam;
53+
auto cr0 = msg.initEvent().initCustomReserved0();
54+
cr0.setDashcamEnable(this->enableDashcam);
55+
uiState()->pm->send("customReserved0", msg);
56+
}
57+
4758
void HomeWindow::showSidebar(bool show) {
4859
sidebar->setVisible(show);
4960
}
@@ -168,6 +179,10 @@ OffroadHome::OffroadHome(QWidget* parent) : QFrame(parent) {
168179
QObject::connect(experimental_mode, &ExperimentalModeButton::openSettings, this, &OffroadHome::openSettings);
169180
right_column->addWidget(experimental_mode, 1);
170181

182+
DashcamModeButton *dashcam_button = new DashcamModeButton(this);
183+
QObject::connect(dashcam_button, &DashcamModeButton::toggleDashcam, this, &OffroadHome::toggleDashcam);
184+
right_column->addWidget(dashcam_button,1);
185+
171186
SetupWidget *setup_widget = new SetupWidget;
172187
QObject::connect(setup_widget, &SetupWidget::openSettings, this, &OffroadHome::openSettings);
173188
right_column->addWidget(setup_widget, 1);

selfdrive/ui/qt/home.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class OffroadHome : public QFrame {
2424

2525
signals:
2626
void openSettings(int index = 0, const QString &param = "");
27+
void toggleDashcam();
2728

2829
private:
2930
void showEvent(QShowEvent *event) override;
@@ -55,6 +56,7 @@ public slots:
5556
void offroadTransition(bool offroad);
5657
void showDriverView(bool show);
5758
void showSidebar(bool show);
59+
void toggleDashcam();
5860

5961
protected:
6062
void mousePressEvent(QMouseEvent* e) override;
@@ -68,6 +70,8 @@ public slots:
6870
DriverViewWindow *driver_view;
6971
QStackedLayout *slayout;
7072

73+
bool enableDashcam;
74+
7175
private slots:
7276
void updateState(const UIState &s);
7377
};
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#include "selfdrive/ui/qt/offroad/dashcam_mode.h"
2+
3+
#include <QDebug>
4+
#include <QHBoxLayout>
5+
#include <QPainter>
6+
#include <QPainterPath>
7+
#include <QStyle>
8+
9+
#include "selfdrive/ui/ui.h"
10+
11+
DashcamModeButton::DashcamModeButton(QWidget *parent) : QPushButton(parent) {
12+
// go to toggles and expand experimental mode description
13+
connect(this, &QPushButton::clicked, [=]() { emit toggleDashcam(); });
14+
15+
setFixedHeight(125);
16+
QHBoxLayout *main_layout = new QHBoxLayout;
17+
main_layout->setContentsMargins(horizontal_padding, 0, horizontal_padding, 0);
18+
19+
mode_label = new QLabel;
20+
mode_icon = new QLabel;
21+
mode_icon->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
22+
23+
main_layout->addWidget(mode_label, 1, Qt::AlignLeft);
24+
main_layout->addWidget(mode_icon, 0, Qt::AlignRight);
25+
26+
setLayout(main_layout);
27+
28+
setStyleSheet(R"(
29+
QPushButton {
30+
border: none;
31+
}
32+
33+
QLabel {
34+
font-size: 45px;
35+
font-weight: 300;
36+
text-align: left;
37+
font-family: JetBrainsMono;
38+
color: #000000;
39+
}
40+
)");
41+
}
42+
43+
void DashcamModeButton::paintEvent(QPaintEvent *event) {
44+
QPainter p(this);
45+
p.setPen(Qt::NoPen);
46+
p.setRenderHint(QPainter::Antialiasing);
47+
48+
QPainterPath path;
49+
path.addRoundedRect(rect(), 10, 10);
50+
51+
// gradient
52+
bool pressed = isDown();
53+
QLinearGradient gradient(rect().left(), 0, rect().right(), 0);
54+
gradient.setColorAt(0, QColor(20, 255, 171, pressed ? 0xcc : 0xff));
55+
gradient.setColorAt(1, QColor(35, 149, 255, pressed ? 0xcc : 0xff));
56+
p.fillPath(path, gradient);
57+
}
58+
59+
void DashcamModeButton::showEvent(QShowEvent *event) {
60+
// experimental_mode = params.getBool("ExperimentalMode");
61+
// mode_icon->setPixmap(experimental_mode ? experimental_pixmap : chill_pixmap);
62+
mode_label->setText("Launch Dashcam Mode");
63+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#pragma once
2+
3+
#include <QLabel>
4+
#include <QPushButton>
5+
6+
#include "common/params.h"
7+
8+
class DashcamModeButton : public QPushButton {
9+
Q_OBJECT
10+
11+
public:
12+
explicit DashcamModeButton(QWidget* parent = 0);
13+
14+
signals:
15+
void toggleDashcam();
16+
17+
private:
18+
void showEvent(QShowEvent *event) override;
19+
20+
Params params;
21+
int img_width = 100;
22+
int horizontal_padding = 30;
23+
QLabel *mode_label;
24+
QLabel *mode_icon;
25+
26+
protected:
27+
void paintEvent(QPaintEvent *event) override;
28+
};

selfdrive/ui/qt/offroad/settings.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "selfdrive/ui/qt/widgets/prime.h"
1515
#include "selfdrive/ui/qt/widgets/scrollview.h"
1616
#include "selfdrive/ui/qt/offroad/developer_panel.h"
17+
#include "selfdrive/ui/qt/home.h"
1718

1819
TogglesPanel::TogglesPanel(SettingsWindow *parent) : ListWidget(parent) {
1920
// param, title, desc, icon
@@ -266,6 +267,11 @@ DevicePanel::DevicePanel(SettingsWindow *parent) : ListWidget(parent) {
266267
power_layout->addWidget(poweroff_btn);
267268
QObject::connect(poweroff_btn, &QPushButton::clicked, this, &DevicePanel::poweroff);
268269

270+
// QPushButton *dashcam_toggle = new QPushButton("Toggle Dashcam");
271+
// dashcam_toggle->setObjectName("dashcam_toggle");
272+
// power_layout->addWidget(dashcam_toggle);
273+
// QObject::connect(dashcam_toggle, &QPushButton::clicked, &HomeWindow::toggleDashcam);
274+
269275
if (!Hardware::PC()) {
270276
connect(uiState(), &UIState::offroadTransition, poweroff_btn, &QPushButton::setVisible);
271277
}
@@ -275,6 +281,8 @@ DevicePanel::DevicePanel(SettingsWindow *parent) : ListWidget(parent) {
275281
#reboot_btn:pressed { background-color: #4a4a4a; }
276282
#poweroff_btn { height: 120px; border-radius: 15px; background-color: #E22C2C; }
277283
#poweroff_btn:pressed { background-color: #FF2424; }
284+
#dashcam_toggle { height: 120px; border-radius: 15px; background-color: #393939; }
285+
#dashcam_toggle:pressed { background-color: #4a4a4a; }
278286
)");
279287
addItem(power_layout);
280288
}

selfdrive/ui/ui.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ UIState::UIState(QObject *parent) : QObject(parent) {
9595
"pandaStates", "carParams", "driverMonitoringState", "carState", "driverStateV2",
9696
"wideRoadCameraState", "managerState", "selfdriveState", "longitudinalPlan",
9797
});
98+
pm = std::make_unique<PubMaster>(std::vector<const char*> {
99+
"customReserved0"
100+
});
98101
prime_state = new PrimeState(this);
99102
language = QString::fromStdString(Params().get("LanguageSetting"));
100103

selfdrive/ui/ui.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ class UIState : public QObject {
7373
}
7474

7575
std::unique_ptr<SubMaster> sm;
76+
std::unique_ptr<PubMaster> pm;
7677
UIStatus status;
7778
UIScene scene = {};
7879
QString language;

0 commit comments

Comments
 (0)