Skip to content

Commit

Permalink
mui
Browse files Browse the repository at this point in the history
  • Loading branch information
adeebshihadeh committed Dec 18, 2021
1 parent fc7d152 commit 646fe7d
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
1 change: 1 addition & 0 deletions selfdrive/ui/.gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
moc_*
*.moc

_mui
watch3
installer/installers/*
replay/replay
Expand Down
3 changes: 3 additions & 0 deletions selfdrive/ui/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
51 changes: 51 additions & 0 deletions selfdrive/ui/mui.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#include <QApplication>
#include <QtWidgets>
#include <QTimer>

#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();
}

0 comments on commit 646fe7d

Please sign in to comment.