From 81b6614520bf56625ebdd398ccac935242a8a97e Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Thu, 11 Mar 2021 21:06:19 +0100 Subject: [PATCH] Add bootscreen and pages.jsonl --- hal/sdl2/app_hal.c | 2 +- src/drv/tft_driver_sdl2.cpp | 2 +- src/hasp/hasp.cpp | 15 +++++++++++++++ src/hasp/hasp_dispatch.cpp | 2 +- src/hasp/hasp_dispatch.h | 2 +- src/main_sdl2.cpp | 37 ++++++++++++++++++++++++------------- 6 files changed, 43 insertions(+), 17 deletions(-) diff --git a/hal/sdl2/app_hal.c b/hal/sdl2/app_hal.c index 72ba9bba..fd062ada 100644 --- a/hal/sdl2/app_hal.c +++ b/hal/sdl2/app_hal.c @@ -33,7 +33,7 @@ void hal_setup(void) /* Add a display * Use the 'monitor' driver which creates window on PC's monitor to simulate a display*/ - monitor_init(); + monitor_init(MONITOR_HOR_RES, MONITOR_VER_RES); /* Add the mouse as input device * Use the 'mouse' driver which reads the PC's mouse*/ diff --git a/src/drv/tft_driver_sdl2.cpp b/src/drv/tft_driver_sdl2.cpp index 86acce44..eb02c0ad 100644 --- a/src/drv/tft_driver_sdl2.cpp +++ b/src/drv/tft_driver_sdl2.cpp @@ -49,7 +49,7 @@ void TftSdl::init(int w, int h) /* Add a display * Use the 'monitor' driver which creates window on PC's monitor to simulate a display*/ - monitor_init(); + monitor_init(MONITOR_HOR_RES, MONITOR_VER_RES); monitor_title(haspDevice.get_hostname()); /* Add the mouse as input device diff --git a/src/hasp/hasp.cpp b/src/hasp/hasp.cpp index 63635ecd..eaecd32d 100644 --- a/src/hasp/hasp.cpp +++ b/src/hasp/hasp.cpp @@ -5,6 +5,12 @@ #include "ArduinoLog.h" #endif +#if defined(WINDOWS) || defined(POSIX) +#include +#include +#include +#endif + #include "ArduinoJson.h" #if HASP_USE_EEPROM > 0 @@ -601,6 +607,15 @@ void haspLoadPage(const char* pagesfile) LOG_INFO(TAG_HASP, F("Loaded jsonl from EEPROM")); #endif + std::ifstream ifs("pages.json", std::ifstream::in); + if(ifs) { + LOG_TRACE(TAG_HASP, F("Loading file %s"), pagesfile); + dispatch_parse_jsonl(ifs); + LOG_INFO(TAG_HASP, F("File %s loaded"), pagesfile); + } else { + LOG_ERROR(TAG_HASP, F("Non existing file %s"), pagesfile); + } + #endif } diff --git a/src/hasp/hasp_dispatch.cpp b/src/hasp/hasp_dispatch.cpp index 3f6a7da7..aa409c3e 100644 --- a/src/hasp/hasp_dispatch.cpp +++ b/src/hasp/hasp_dispatch.cpp @@ -768,7 +768,7 @@ void dispatch_parse_json(const char*, const char* payload) #ifdef ARDUINO void dispatch_parse_jsonl(Stream& stream) #else -void dispatch_parse_jsonl(std::istringstream& stream) +void dispatch_parse_jsonl(std::istream& stream) #endif { uint8_t savedPage = haspGetPage(); diff --git a/src/hasp/hasp_dispatch.h b/src/hasp/hasp_dispatch.h index 5f6b837b..2a9e44ee 100644 --- a/src/hasp/hasp_dispatch.h +++ b/src/hasp/hasp_dispatch.h @@ -41,7 +41,7 @@ void dispatch_text_line(const char* cmnd); #ifdef ARDUINO void dispatch_parse_jsonl(Stream& stream); #else -void dispatch_parse_jsonl(std::istringstream& stream); +void dispatch_parse_jsonl(std::istream& stream); #endif void dispatch_clear_page(const char* page); diff --git a/src/main_sdl2.cpp b/src/main_sdl2.cpp index 096906fb..cc181187 100644 --- a/src/main_sdl2.cpp +++ b/src/main_sdl2.cpp @@ -4,11 +4,19 @@ #if defined(WINDOWS) || defined(POSIX) #if defined(WINDOWS) + #include +#include +// MSDN recommends against using getcwd & chdir names +#define cwd _getcwd +#define cd _chdir #endif + #if defined(POSIX) #include #include +#define cwd getcwd +#define cd chdir #endif #include @@ -170,7 +178,6 @@ void loop() // delay(6); } - void usage(char* progName) { std::cout << progName << " [options]" << std::endl @@ -201,16 +208,9 @@ int main(int argc, char* argv[]) { bool showhelp = false; int count; -#ifdef WINDOWS - InitializeConsoleOutput(); -#endif - - // Display each command-line argument. - std::cout << "\nCommand-line arguments:\n"; - for(count = 0; count < argc; count++) - std::cout << " argv[" << count << "] " << argv[count] << "\n" << std::endl << std::flush; #if defined(WINDOWS) + InitializeConsoleOutput(); SetConsoleCP(65001); // 65001 = UTF-8 static const char s[] = "tränenüberströmt™\n"; DWORD slen = lstrlen(s); @@ -218,13 +218,25 @@ int main(int argc, char* argv[]) HANDLE std_out = GetStdHandle(STD_OUTPUT_HANDLE); if(std_out == INVALID_HANDLE_VALUE) { - // return 66; + return 66; } - if(!WriteConsole(std_out, "Hello World!", 12, NULL, NULL)) { - // return 67; + if(!WriteConsole(std_out, "Hello World!\n", 13, NULL, NULL)) { + return 67; } #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; + cd(SDL_GetPrefPath("hasp", "hasp")); + std::cout << "CWD changed to: " << cwd(buf, sizeof buf) << std::endl; + SDL_Quit(); // We'll properly init later + + // Change to preferences dir + std::cout << "\nCommand-line arguments:\n"; + for(count = 0; count < argc; count++) + std::cout << " argv[" << count << "] " << argv[count] << "\n" << std::endl << std::flush; + for(count = 0; count < argc; count++) { if(argv[count][0] == '-') { @@ -272,5 +284,4 @@ int main(int argc, char* argv[]) return 0; } - #endif