From 9b3c88492ce37dd6d9fd472530177ae2dbd82657 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Szczodrzy=C5=84ski?= Date: Mon, 12 Feb 2024 16:32:38 +0100 Subject: [PATCH] Switch to tty7 on POSIX fbdev --- src/dev/posix/hasp_posix.cpp | 2 +- src/drv/tft/tft_driver_posix_fbdev.cpp | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/dev/posix/hasp_posix.cpp b/src/dev/posix/hasp_posix.cpp index e5f1b173..ad020e4b 100644 --- a/src/dev/posix/hasp_posix.cpp +++ b/src/dev/posix/hasp_posix.cpp @@ -203,7 +203,7 @@ void PosixDevice::update_backlight() f << brightness; f.close(); } else { - perror("Brightness write failed"); + perror("Brightness write failed (are you root?)"); } } #endif diff --git a/src/drv/tft/tft_driver_posix_fbdev.cpp b/src/drv/tft/tft_driver_posix_fbdev.cpp index 2961b728..7abafa58 100644 --- a/src/drv/tft/tft_driver_posix_fbdev.cpp +++ b/src/drv/tft/tft_driver_posix_fbdev.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #if USE_BSD_EVDEV #include @@ -83,6 +84,15 @@ static void* gui_entrypoint(void* arg) void TftFbdevDrv::init(int32_t w, int h) { + // try to switch the active tty to tty7 + int tty_fd = open("/dev/tty0", O_WRONLY); + if(tty_fd == -1) { + perror("Couldn't open /dev/tty0 (try running as root)"); + } else { + if(ioctl(tty_fd, VT_ACTIVATE, 7) == -1) perror("Couldn't change active tty"); + } + close(tty_fd); + // check active tty std::ifstream f; f.open("/sys/class/tty/tty0/active"); @@ -92,9 +102,9 @@ void TftFbdevDrv::init(int32_t w, int h) f.close(); // try to hide the cursor - int tty_fd = open(tty.c_str(), O_WRONLY); + tty_fd = open(tty.c_str(), O_WRONLY); if(tty_fd == -1) { - perror("Couldn't open tty"); + perror("Couldn't open active tty (try running as root)"); } else { write(tty_fd, "\033[?25l", 6); }