diff --git a/common/text_window.py b/common/text_window.py index 1aa3b885ea..af7d9bbfcb 100755 --- a/common/text_window.py +++ b/common/text_window.py @@ -6,17 +6,16 @@ from common.basedir import BASEDIR class TextWindow: - def __init__(self, s, noop=False): + def __init__(self, text): # text window is only implemented for android currently self.text_proc = None - if not noop: - try: - self.text_proc = subprocess.Popen(["./text", s], - stdin=subprocess.PIPE, - cwd=os.path.join(BASEDIR, "selfdrive", "ui", "text"), - close_fds=True) - except OSError: - self.text_proc = None + try: + self.text_proc = subprocess.Popen(["./text", text], + stdin=subprocess.PIPE, + cwd=os.path.join(BASEDIR, "selfdrive", "ui"), + close_fds=True) + except OSError: + self.text_proc = None def get_status(self): if self.text_proc is not None: diff --git a/release/files_common b/release/files_common index 2c62cc6b8b..dcc5d30926 100644 --- a/release/files_common +++ b/release/files_common @@ -348,9 +348,9 @@ selfdrive/ui/spinner/Makefile selfdrive/ui/spinner/spinner selfdrive/ui/spinner/spinner.c -selfdrive/ui/text/Makefile -selfdrive/ui/text/text -selfdrive/ui/text/text.c +selfdrive/ui/android/text/Makefile +selfdrive/ui/android/text/text +selfdrive/ui/android/text/text.c selfdrive/ui/qt/*.cc selfdrive/ui/qt/*.hpp diff --git a/selfdrive/manager.py b/selfdrive/manager.py index c95d4f778c..959ea5d9ed 100755 --- a/selfdrive/manager.py +++ b/selfdrive/manager.py @@ -140,7 +140,7 @@ if not prebuilt: # Show TextWindow no_ui = __name__ != "__main__" or not ANDROID error_s = "\n \n".join(["\n".join(textwrap.wrap(e, 65)) for e in errors]) - with TextWindow("openpilot failed to build\n \n" + error_s, noop=no_ui) as t: + with TextWindow("openpilot failed to build\n \n" + error_s) as t: t.wait_for_exit() exit(1) diff --git a/selfdrive/ui/.gitignore b/selfdrive/ui/.gitignore index 27a652ceed..a765635392 100644 --- a/selfdrive/ui/.gitignore +++ b/selfdrive/ui/.gitignore @@ -1 +1,2 @@ moc_* +qt/text diff --git a/selfdrive/ui/SConscript b/selfdrive/ui/SConscript index 83c4d58c84..00f7d9c017 100644 --- a/selfdrive/ui/SConscript +++ b/selfdrive/ui/SConscript @@ -71,3 +71,6 @@ else: qt_src = ["qt/ui.cc", "qt/window.cc", "qt/qt_sound.cc", "qt/offroad/settings.cc", "qt/offroad/onboarding.cc"] + src qt_env.Program("_ui", qt_src, LIBS=qt_libs + libs) + + # text window + qt_env.Program("qt/text", ["qt/text.cc"], LIBS=qt_libs + libs) diff --git a/selfdrive/ui/text/Makefile b/selfdrive/ui/android/text/Makefile similarity index 84% rename from selfdrive/ui/text/Makefile rename to selfdrive/ui/android/text/Makefile index ac0d720d57..3401cae0ff 100644 --- a/selfdrive/ui/text/Makefile +++ b/selfdrive/ui/android/text/Makefile @@ -1,7 +1,8 @@ CC = clang CXX = clang++ -PHONELIBS = ../../../phonelibs +PHONELIBS = ../../../../phonelibs +COMMON = ../../../common WARN_FLAGS = -Werror=implicit-function-declaration \ -Werror=incompatible-pointer-types \ @@ -19,9 +20,9 @@ OPENGL_LIBS = -lGLESv3 FRAMEBUFFER_LIBS = -lutils -lgui -lEGL OBJS = text.o \ - ../../common/framebuffer.o \ - ../../common/util.o \ - ../../../selfdrive/common/touch.o \ + $(COMMON)/framebuffer.o \ + $(COMMON)/util.o \ + $(COMMON)/touch.o \ $(PHONELIBS)/nanovg/nanovg.o \ opensans_regular.o \ @@ -39,7 +40,7 @@ text: $(OBJS) $(OPENGL_LIBS) \ -lm -llog -opensans_regular.o: ../../assets/fonts/opensans_regular.ttf +opensans_regular.o: ../../../assets/fonts/opensans_regular.ttf @echo "[ bin2o ] $@" cd '$(dir $<)' && ld -r -b binary '$(notdir $<)' -o '$(abspath $@)' @@ -47,7 +48,7 @@ opensans_regular.o: ../../assets/fonts/opensans_regular.ttf mkdir -p $(@D) @echo "[ CC ] $@" $(CC) $(CPPFLAGS) $(CFLAGS) \ - -I../.. \ + -I../../.. \ -I$(PHONELIBS)/android_frameworks_native/include \ -I$(PHONELIBS)/android_system_core/include \ -I$(PHONELIBS)/android_hardware_libhardware/include \ @@ -58,8 +59,8 @@ opensans_regular.o: ../../assets/fonts/opensans_regular.ttf mkdir -p $(@D) @echo "[ CXX ] $@" $(CXX) $(CPPFLAGS) $(CXXFLAGS) \ - -I../../selfdrive \ - -I../../ \ + -I../../../selfdrive \ + -I../../../ \ -I$(PHONELIBS)/android_frameworks_native/include \ -I$(PHONELIBS)/android_system_core/include \ -I$(PHONELIBS)/android_hardware_libhardware/include \ diff --git a/selfdrive/ui/text/text b/selfdrive/ui/android/text/text similarity index 100% rename from selfdrive/ui/text/text rename to selfdrive/ui/android/text/text diff --git a/selfdrive/ui/text/text.c b/selfdrive/ui/android/text/text.c similarity index 100% rename from selfdrive/ui/text/text.c rename to selfdrive/ui/android/text/text.c diff --git a/selfdrive/ui/qt/text.cc b/selfdrive/ui/qt/text.cc new file mode 100644 index 0000000000..ab7d9f4c4b --- /dev/null +++ b/selfdrive/ui/qt/text.cc @@ -0,0 +1,90 @@ +#include + +#include +#include +#include +#include +#include +#include +#include + +#ifdef QCOM2 +#include +#include +#include +#endif + + +int main(int argc, char *argv[]) { + QApplication a(argc, argv); + QWidget *window = new QWidget(); + + // TODO: get size from QScreen, doesn't work on tici +#ifdef QCOM2 + int w = 2160, h = 1080; +#else + int w = 1920, h = 1080; +#endif + window->setFixedSize(w, h); + + QVBoxLayout *main_layout = new QVBoxLayout(); + + QString text = ""; + for (int i = 1; i < argc; i++) { + if (i > 1) { + text.append(" "); + } + text.append(argv[i]); + } + + QLabel *label = new QLabel(text); + label->setAlignment(Qt::AlignTop); + main_layout->addWidget(label); + + QPushButton *btn = new QPushButton(); +#ifdef __aarch64__ + btn->setText("Reboot"); + QObject::connect(btn, &QPushButton::released, [=]() { + std::system("sudo reboot"); + }); +#else + btn->setText("Exit"); + QObject::connect(btn, SIGNAL(released()), &a, SLOT(quit())); +#endif + main_layout->addWidget(btn); + + window->setLayout(main_layout); + window->setStyleSheet(R"( + QWidget { + margin: 60px; + background-color: black; + } + QLabel { + color: white; + font-size: 60px; + } + QPushButton { + color: white; + font-size: 50px; + padding: 60px; + margin-left: 1500px; + border-color: white; + border-width: 2px; + border-style: solid; + border-radius: 20px; + } + )"); + + window->show(); + + +#ifdef QCOM2 + QPlatformNativeInterface *native = QGuiApplication::platformNativeInterface(); + wl_surface *s = reinterpret_cast(native->nativeResourceForWindow("surface", window->windowHandle())); + wl_surface_set_buffer_transform(s, WL_OUTPUT_TRANSFORM_270); + wl_surface_commit(s); + window->showFullScreen(); +#endif + + return a.exec(); +} diff --git a/selfdrive/ui/text b/selfdrive/ui/text new file mode 100755 index 0000000000..76bffc136d --- /dev/null +++ b/selfdrive/ui/text @@ -0,0 +1,8 @@ +#!/bin/sh + +if [ -f /EON ]; then + export LD_LIBRARY_PATH="/system/lib64:$LD_LIBRARY_PATH" + exec ./android/text/text "$1" +else + exec ./qt/text "$1" +fi