From 246f5e3ac270f1709f9beac2e49af6ab6f7ccfb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Szczodrzy=C5=84ski?= Date: Tue, 6 Feb 2024 19:52:23 +0100 Subject: [PATCH] Only enable SDL2 driver with USE_MONITOR --- include/hasp_conf.h | 4 ++++ src/dev/win32/hasp_win32.cpp | 8 +++++++- src/dev/win32/hasp_win32.h | 2 +- src/drv/tft/tft_driver.h | 2 +- src/drv/tft/tft_driver_sdl2.cpp | 4 ++-- src/drv/tft/tft_driver_sdl2.h | 2 +- src/hasp_gui.cpp | 2 +- src/main_pc.cpp | 18 +++++++++++------- 8 files changed, 28 insertions(+), 14 deletions(-) diff --git a/include/hasp_conf.h b/include/hasp_conf.h index 448b66a3..ef832b69 100644 --- a/include/hasp_conf.h +++ b/include/hasp_conf.h @@ -371,7 +371,9 @@ static WiFiSpiClass WiFi; #include #include #include +#if USE_MONITOR #include +#endif #define snprintf_P snprintf #define memcpy_P memcpy @@ -380,7 +382,9 @@ static WiFiSpiClass WiFi; #define strcpy_P strcpy #define strstr_P strstr #define halRestartMcu() +#if USE_MONITOR #define millis SDL_GetTicks +#endif #define DEC 10 #define HEX 16 diff --git a/src/dev/win32/hasp_win32.cpp b/src/dev/win32/hasp_win32.cpp index 61fce87d..f089307c 100644 --- a/src/dev/win32/hasp_win32.cpp +++ b/src/dev/win32/hasp_win32.cpp @@ -11,7 +11,9 @@ #include "hasp_conf.h" #include "hasp_debug.h" +#if USE_MONITOR #include "display/monitor.h" +#endif namespace dev { @@ -48,8 +50,10 @@ const char* Win32Device::get_hostname() void Win32Device::set_hostname(const char* hostname) { _hostname = hostname; +#if USE_MONITOR monitor_title(hostname); // SDL_SetWindowTitle(monitor.window, hostname); +#endif } const char* Win32Device::get_core_version() { @@ -112,7 +116,9 @@ void Win32Device::update_backlight() { uint8_t level = _backlight_power ? _backlight_level : 0; if(_backlight_invert) level = 255 - level; +#if USE_MONITOR monitor_backlight(level); +#endif } size_t Win32Device::get_free_max_block() @@ -152,4 +158,4 @@ long Win32Device::get_uptime() dev::Win32Device haspDevice; -#endif // WINDOWS \ No newline at end of file +#endif // WINDOWS diff --git a/src/dev/win32/hasp_win32.h b/src/dev/win32/hasp_win32.h index 3c2edb23..0c64e1f9 100644 --- a/src/dev/win32/hasp_win32.h +++ b/src/dev/win32/hasp_win32.h @@ -96,4 +96,4 @@ extern dev::Win32Device haspDevice; #endif // WINDOWS -#endif // HASP_DEVICE_WINDOWS_H \ No newline at end of file +#endif // HASP_DEVICE_WINDOWS_H diff --git a/src/drv/tft/tft_driver.h b/src/drv/tft/tft_driver.h index 913be18f..0c0d5814 100644 --- a/src/drv/tft/tft_driver.h +++ b/src/drv/tft/tft_driver.h @@ -77,7 +77,7 @@ class BaseTft { #elif defined(STM32F7) #warning Building for STM32F7xx Tfts #include "tft_driver_tftespi.h" -#elif defined(WINDOWS) || defined(POSIX) +#elif USE_MONITOR && (defined(WINDOWS) || defined(POSIX)) // #warning Building for SDL2 #include "tft_driver_sdl2.h" #else diff --git a/src/drv/tft/tft_driver_sdl2.cpp b/src/drv/tft/tft_driver_sdl2.cpp index a2b44233..98461f5b 100644 --- a/src/drv/tft/tft_driver_sdl2.cpp +++ b/src/drv/tft/tft_driver_sdl2.cpp @@ -1,7 +1,7 @@ /* MIT License - Copyright (c) 2019-2022 Francis Van Roie For full license information read the LICENSE file in the project folder */ -#if defined(WINDOWS) || defined(POSIX) +#if USE_MONITOR && (defined(WINDOWS) || defined(POSIX)) #include "hasplib.h" #include "lvgl.h" @@ -115,4 +115,4 @@ const char* TftSdl::get_tft_model() dev::TftSdl haspTft; -#endif // WINDOWS || POSIX \ No newline at end of file +#endif // WINDOWS || POSIX diff --git a/src/drv/tft/tft_driver_sdl2.h b/src/drv/tft/tft_driver_sdl2.h index 85b32ee0..d0aaa114 100644 --- a/src/drv/tft/tft_driver_sdl2.h +++ b/src/drv/tft/tft_driver_sdl2.h @@ -6,7 +6,7 @@ #include "tft_driver.h" -#if defined(WINDOWS) || defined(POSIX) +#if USE_MONITOR && (defined(WINDOWS) || defined(POSIX)) // #warning Building H driver TFT SDL2 #include "lvgl.h" diff --git a/src/hasp_gui.cpp b/src/hasp_gui.cpp index b69a1ee5..5fc3eb74 100644 --- a/src/hasp_gui.cpp +++ b/src/hasp_gui.cpp @@ -309,7 +309,7 @@ void guiSetup() static lv_indev_drv_t indev_drv; lv_indev_drv_init(&indev_drv); indev_drv.type = LV_INDEV_TYPE_POINTER; -#if defined(WINDOWS) || defined(POSIX) +#if USE_MONITOR && (defined(WINDOWS) || defined(POSIX)) indev_drv.read_cb = mouse_read; #else indev_drv.read_cb = gui_touch_read; diff --git a/src/main_pc.cpp b/src/main_pc.cpp index d2942333..4a32377d 100644 --- a/src/main_pc.cpp +++ b/src/main_pc.cpp @@ -25,7 +25,9 @@ #include "hasplib.h" // #include "app_hal.h" +#if USE_MONITOR #include "display/monitor.h" +#endif #include "hasp_debug.h" #include "hasp_gui.h" @@ -258,12 +260,14 @@ int main(int argc, char* argv[]) } #endif - SDL_Init(0); // Needs to be initialized for GetPerfPath char buf[4096]; // never know how much is needed std::cout << "CWD: " << cwd(buf, sizeof buf) << std::endl; +#if USE_MONITOR + SDL_Init(0); // Needs to be initialized for GetPerfPath cd(SDL_GetPrefPath("hasp", "hasp")); - std::cout << "CWD changed to: " << cwd(buf, sizeof buf) << std::endl; SDL_Quit(); // We'll properly init later +#endif + std::cout << "CWD changed to: " << cwd(buf, sizeof buf) << std::endl; // Change to preferences dir std::cout << "\nCommand-line arguments:\n"; @@ -376,11 +380,11 @@ int main(int argc, char* argv[]) LOG_TRACE(TAG_MAIN, "main loop completed"); #if defined(WINDOWS) - WriteConsole(std_out, "bye\n\n", 3, NULL, NULL); - std::cout << std::endl << std::flush; - fflush(stdout); - FreeConsole(); - exit(0); + WriteConsole(std_out, "bye\n\n", 3, NULL, NULL); + std::cout << std::endl << std::flush; + fflush(stdout); + FreeConsole(); + exit(0); #endif return 0;