mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-02-19 20:33:53 +08:00
ui: gc experiments
This commit is contained in:
@@ -83,9 +83,6 @@ if GetOption('extras') and arch != "Darwin":
|
||||
# build 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')
|
||||
|
||||
@@ -1,50 +0,0 @@
|
||||
#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) {
|
||||
label->setText("〇");
|
||||
auto cs = sm["controlsState"].getControlsState();
|
||||
UIStatus status = cs.getEnabled() ? STATUS_ENGAGED : STATUS_DISENGAGED;
|
||||
label->setStyleSheet(QString("color: %1; font-size: 250px;").arg(bg_colors[status].name()));
|
||||
} else {
|
||||
label->setText("offroad");
|
||||
label->setStyleSheet("color: grey; font-size: 40px;");
|
||||
}
|
||||
|
||||
if ((onroad != onroad_prev) || sm.frame < 2) {
|
||||
Hardware::set_brightness(50);
|
||||
Hardware::set_display_power(onroad);
|
||||
}
|
||||
});
|
||||
timer.start(50);
|
||||
|
||||
return a.exec();
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
import os
|
||||
import signal
|
||||
|
||||
signal.signal(signal.SIGINT, signal.SIG_DFL)
|
||||
|
||||
import cereal.messaging as messaging
|
||||
from openpilot.system.hardware import HARDWARE
|
||||
|
||||
from PyQt5.QtCore import Qt, QTimer
|
||||
from PyQt5.QtWidgets import QLabel, QWidget, QVBoxLayout, QStackedLayout, QApplication
|
||||
from openpilot.selfdrive.ui.qt.python_helpers import set_main_window
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app = QApplication([])
|
||||
win = QWidget()
|
||||
set_main_window(win)
|
||||
|
||||
bg = QLabel("", alignment=Qt.AlignCenter)
|
||||
|
||||
alert1 = QLabel()
|
||||
alert2 = QLabel()
|
||||
vlayout = QVBoxLayout()
|
||||
vlayout.addWidget(alert1, alignment=Qt.AlignCenter)
|
||||
vlayout.addWidget(alert2, alignment=Qt.AlignCenter)
|
||||
|
||||
tmp = QWidget()
|
||||
tmp.setLayout(vlayout)
|
||||
|
||||
stack = QStackedLayout(win)
|
||||
stack.addWidget(tmp)
|
||||
stack.addWidget(bg)
|
||||
stack.setStackingMode(QStackedLayout.StackAll)
|
||||
|
||||
win.setObjectName("win")
|
||||
win.setStyleSheet("""
|
||||
#win {
|
||||
background-color: black;
|
||||
}
|
||||
QLabel {
|
||||
color: white;
|
||||
font-size: 40px;
|
||||
}
|
||||
""")
|
||||
|
||||
sm = messaging.SubMaster(['deviceState', 'controlsState'])
|
||||
|
||||
def update():
|
||||
sm.update(0)
|
||||
|
||||
onroad = sm.all_checks(['deviceState']) and sm['deviceState'].started
|
||||
if onroad:
|
||||
cs = sm['controlsState']
|
||||
color = ("grey" if str(cs.state) in ("overriding", "preEnabled") else "green") if cs.enabled else "blue"
|
||||
bg.setText("\U0001F44D" if cs.engageable else "\U0001F6D1")
|
||||
bg.setStyleSheet(f"font-size: 100px; background-color: {color};")
|
||||
bg.show()
|
||||
|
||||
alert1.setText(cs.alertText1)
|
||||
alert2.setText(cs.alertText2)
|
||||
|
||||
if not sm.alive['controlsState']:
|
||||
alert1.setText("waiting for controls...")
|
||||
else:
|
||||
bg.hide()
|
||||
alert1.setText("")
|
||||
alert2.setText("offroad")
|
||||
|
||||
HARDWARE.set_screen_brightness(100 if onroad else 40)
|
||||
os.system("echo 0 > /sys/class/backlight/panel0-backlight/bl_power")
|
||||
|
||||
timer = QTimer()
|
||||
timer.timeout.connect(update)
|
||||
timer.start(50)
|
||||
|
||||
app.exec_()
|
||||
Reference in New Issue
Block a user