From 646fe7de4b48901ed1be4998fcd5848997c9740e Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Sat, 18 Dec 2021 15:10:41 -0800 Subject: [PATCH] mui --- selfdrive/ui/.gitignore | 1 + selfdrive/ui/SConscript | 3 +++ selfdrive/ui/mui.cc | 51 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+) create mode 100644 selfdrive/ui/mui.cc diff --git a/selfdrive/ui/.gitignore b/selfdrive/ui/.gitignore index 5d656f889..5f8a96edf 100644 --- a/selfdrive/ui/.gitignore +++ b/selfdrive/ui/.gitignore @@ -1,6 +1,7 @@ moc_* *.moc +_mui watch3 installer/installers/* replay/replay diff --git a/selfdrive/ui/SConscript b/selfdrive/ui/SConscript index d33e57669..62f93c13a 100644 --- a/selfdrive/ui/SConscript +++ b/selfdrive/ui/SConscript @@ -73,6 +73,9 @@ if GetOption('extras'): # buidl updater UI qt_env.Program("qt/setup/updater", ["qt/setup/updater.cc", asset_obj], LIBS=qt_libs) + # build mui + qt_env.Program("_mui", ["mui.cc"], LIBS=qt_libs) + # build installers senv = qt_env.Clone() senv['LINKFLAGS'].append('-Wl,-strip-debug') diff --git a/selfdrive/ui/mui.cc b/selfdrive/ui/mui.cc new file mode 100644 index 000000000..a10ead8e0 --- /dev/null +++ b/selfdrive/ui/mui.cc @@ -0,0 +1,51 @@ +#include +#include +#include + +#include "cereal/messaging/messaging.h" +#include "selfdrive/ui/ui.h" +#include "selfdrive/ui/qt/qt_window.h" + +int main(int argc, char *argv[]) { + QApplication a(argc, argv); + QWidget w; + setMainWindow(&w); + + w.setStyleSheet("background-color: black;"); + + // our beautiful UI + QVBoxLayout *layout = new QVBoxLayout(&w); + QLabel *label = new QLabel("〇"); + layout->addWidget(label, 0, Qt::AlignCenter); + + QTimer timer; + QObject::connect(&timer, &QTimer::timeout, [=]() { + static SubMaster sm({"deviceState", "controlsState"}); + + bool onroad_prev = sm.allAliveAndValid({"deviceState"}) && + sm["deviceState"].getDeviceState().getStarted(); + sm.update(0); + + bool onroad = sm.allAliveAndValid({"deviceState"}) && + sm["deviceState"].getDeviceState().getStarted(); + + if (onroad) { + auto cs = sm["controlsState"].getControlsState(); + UIStatus status = cs.getEnabled() ? STATUS_ENGAGED : STATUS_DISENGAGED; + if (cs.getAlertStatus() == cereal::ControlsState::AlertStatus::USER_PROMPT) { + status = STATUS_WARNING; + } else if (cs.getAlertStatus() == cereal::ControlsState::AlertStatus::CRITICAL) { + status = STATUS_ALERT; + } + label->setStyleSheet(QString("color: %1; font-size: 250px;").arg(bg_colors[status].name())); + } + + if ((onroad != onroad_prev) || sm.frame < 2) { + Hardware::set_brightness(50); + Hardware::set_display_power(onroad); + } + }); + timer.start(50); + + return a.exec(); +}