Cleanup PC entrypoint, remove MQTT CLI options

This commit is contained in:
Kuba Szczodrzyński 2024-02-07 16:33:52 +01:00
parent 0e87f52c1f
commit cb1d860635
No known key found for this signature in database
GPG Key ID: 43037AC62A600562
6 changed files with 63 additions and 164 deletions

View File

@ -43,6 +43,7 @@ void Win32Device::show_info()
LOG_VERBOSE(0, F("Processor : %s"), vendor); LOG_VERBOSE(0, F("Processor : %s"), vendor);
LOG_VERBOSE(0, F("CPU freq. : %i MHz"), get_cpu_frequency()); LOG_VERBOSE(0, F("CPU freq. : %i MHz"), get_cpu_frequency());
LOG_VERBOSE(0, F("OS Version : %s"), get_core_version());
} }
const char* Win32Device::get_hostname() const char* Win32Device::get_hostname()

View File

@ -43,7 +43,7 @@ class Win32Device : public BaseDevice {
if(dwVersion < 0x80000000) dwBuild = (DWORD)(HIWORD(dwVersion)); if(dwVersion < 0x80000000) dwBuild = (DWORD)(HIWORD(dwVersion));
char version[128]; char version[128];
snprintf(version, sizeof(version), "Windows %d.%d-%d", dwMajorVersion, dwMinorVersion, dwBuild); snprintf(version, sizeof(version), "Windows %d.%d.%d", dwMajorVersion, dwMinorVersion, dwBuild);
_core_version = version; _core_version = version;
// _backlight_pin = -1; // _backlight_pin = -1;

View File

@ -68,13 +68,7 @@ void TftWin32Drv::show_info()
{ {
splashscreen(); splashscreen();
unsigned long version = GetVersion(); LOG_VERBOSE(TAG_TFT, F("Driver : Win32Drv"));
unsigned long major = LOBYTE(LOWORD(version));
unsigned long minor = HIBYTE(LOWORD(version));
unsigned long build = 0;
if(version < 0x80000000) build = HIWORD(version);
LOG_VERBOSE(TAG_TFT, F("Driver : Win32Drv"));
LOG_VERBOSE(TAG_TFT, F("Windows Version: %d.%d.%d"), major, minor, build);
} }
void TftWin32Drv::splashscreen() void TftWin32Drv::splashscreen()

View File

@ -121,23 +121,19 @@ void setup()
configSetup(); configSetup();
#endif #endif
haspDevice.init(); // hardware setup haspDevice.init(); // hardware setup
haspDevice.show_info(); // debug info
// hal_setup(); // hal_setup();
guiSetup(); guiSetup();
LOG_DEBUG(TAG_MAIN, "%s %d", __FILE__, __LINE__);
dispatchSetup(); // for hasp and oobe dispatchSetup(); // for hasp and oobe
haspSetup(); haspSetup();
#if HASP_USE_MQTT > 0 #if HASP_USE_MQTT > 0
LOG_DEBUG(TAG_MAIN, "%s %d", __FILE__, __LINE__);
mqttSetup(); // Hasp must be running mqttSetup(); // Hasp must be running
mqttStart(); mqttStart();
#endif #endif
#if HASP_USE_GPIO > 0 #if HASP_USE_GPIO > 0
LOG_DEBUG(TAG_MAIN, "%s %d", __FILE__, __LINE__);
gpioSetup(); gpioSetup();
#endif #endif
@ -146,7 +142,6 @@ void setup()
#endif #endif
mainLastLoopTime = millis(); // - 1000; // reset loop counter mainLastLoopTime = millis(); // - 1000; // reset loop counter
LOG_DEBUG(TAG_MAIN, "%s %d", __FILE__, __LINE__);
// delay(250); // delay(250);
} }
@ -191,7 +186,9 @@ void loop()
if(mainLoopCounter == 0 || mainLoopCounter == 5) { if(mainLoopCounter == 0 || mainLoopCounter == 5) {
haspDevice.loop_5s(); haspDevice.loop_5s();
#if HASP_USE_GPIO > 0
gpioEvery5Seconds(); gpioEvery5Seconds();
#endif
#if HASP_USE_MQTT #if HASP_USE_MQTT
mqttEvery5Seconds(true); mqttEvery5Seconds(true);
@ -215,175 +212,86 @@ void loop()
void usage(const char* progName, const char* version) void usage(const char* progName, const char* version)
{ {
std::cout << "\n\n" std::cout
<< progName << " " << version << " [options]" << std::endl << "\n"
<< std::endl << progName << " " << version << " [options]" << std::endl
<< "Options:" << std::endl << std::endl
<< " -? | --help Print this help" << std::endl << "Options:" << std::endl
<< " -w | --width Width of the window" << std::endl << " -h | --help Print this help" << std::endl
<< " -h | --height Height of the window" << std::endl << " -W | --width Width of the window" << std::endl
<< " --mqttname MQTT device name topic (default: computer hostname)" << std::endl << " -H | --height Height of the window" << std::endl
<< " --mqtthost MQTT broker hostname or IP address" << std::endl << " -C | --config Configuration directory (default: '~/.local/share/hasp' or 'AppData\\hasp\\hasp')"
<< " --mqttport MQTT broker port (default: 1883)" << std::endl << std::endl
<< " --mqttuser MQTT username" << std::endl << std::endl;
<< " --mqttpass MQTT password" << std::endl
<< " --mqttgroup MQTT groupname (default: plates)" << std::endl
<< std::endl
// << " -t | --topic Base topic of the mqtt messages (default: hasp)" << std::endl
// << std::endl
// << " -f | --fullscreen Open the application fullscreen" << std::endl
// << " -v | --verbose Verbosity level" << std::endl
<< std::endl;
fflush(stdout); fflush(stdout);
#if defined(WINDOWS)
static const char s[] = "\n";
DWORD slen = lstrlen(s);
WriteConsoleA(GetStdHandle(STD_OUTPUT_HANDLE), s, slen, &slen, NULL);
#endif
} }
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
bool showhelp = false; bool showhelp = false;
int count; bool console = true;
char config[PATH_MAX] = {'\0'};
#if defined(WINDOWS) #if defined(WINDOWS)
InitializeConsoleOutput(); InitializeConsoleOutput();
SetConsoleCP(65001); // 65001 = UTF-8 SetConsoleCP(65001); // 65001 = UTF-8
static const char s[] = "tränenüberströmt™\n";
DWORD slen = lstrlen(s);
WriteConsoleA(GetStdHandle(STD_OUTPUT_HANDLE), s, slen, &slen, NULL);
HANDLE std_out = GetStdHandle(STD_OUTPUT_HANDLE);
if(std_out == INVALID_HANDLE_VALUE) {
return 66;
}
if(!WriteConsole(std_out, "Hello World!\n", 13, NULL, NULL)) {
return 67;
}
#endif #endif
char buf[4096]; // never know how much is needed for(int arg = 1; arg < argc; arg++) {
std::cout << "CWD: " << cwd(buf, sizeof buf) << std::endl; if(strncmp(argv[arg], "--help", 6) == 0 || strncmp(argv[arg], "-h", 2) == 0) {
#if USE_MONITOR showhelp = true;
SDL_Init(0); // Needs to be initialized for GetPerfPath } else if(strncmp(argv[arg], "--width", 7) == 0 || strncmp(argv[arg], "-W", 2) == 0) {
cd(SDL_GetPrefPath("hasp", "hasp")); if(arg + 1 < argc) {
SDL_Quit(); // We'll properly init later int w = atoi(argv[arg + 1]);
#elif USE_WIN32DRV if(w > 0) tft_width = w;
if(SUCCEEDED(SHGetFolderPath(NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE, NULL, 0, buf))) { arg++;
PathAppendA(buf, "hasp"); } else {
PathAppendA(buf, "hasp"); std::cout << "Missing width value" << std::endl;
cd(buf);
}
#endif
std::cout << "CWD changed to: " << cwd(buf, sizeof buf) << std::endl;
// Change to preferences dir
std::cout << "\nCommand-line arguments:\n";
for(count = 0; count < argc; count++)
std::cout << " argv[" << count << "] " << argv[count] << std::endl << std::flush;
StaticJsonDocument<1024> settings;
for(count = 0; count < argc; count++) {
if(argv[count][0] == '-') {
if(strncmp(argv[count], "--help", 6) == 0 || strncmp(argv[count], "-?", 2) == 0) {
showhelp = true; showhelp = true;
} }
} else if(strncmp(argv[arg], "--height", 8) == 0 || strncmp(argv[arg], "-H", 2) == 0) {
if(strncmp(argv[count], "--width", 7) == 0 || strncmp(argv[count], "-w", 2) == 0) { if(arg + 1 < argc) {
int w = atoi(argv[count + 1]); int h = atoi(argv[arg + 1]);
if(w > 0) tft_width = w;
}
if(strncmp(argv[count], "--height", 8) == 0 || strncmp(argv[count], "-h", 2) == 0) {
int h = atoi(argv[count + 1]);
if(h > 0) tft_height = h; if(h > 0) tft_height = h;
arg++;
} else {
std::cout << "Missing height value" << std::endl;
showhelp = true;
} }
} else if(strncmp(argv[arg], "--config", 8) == 0 || strncmp(argv[arg], "-C", 2) == 0) {
if(strncmp(argv[count], "--mqttname", 10) == 0 || strncmp(argv[count], "-n", 2) == 0) { if(arg + 1 < argc) {
std::cout << " argv[" << count << "] " << argv[count] << std::endl << std::flush; strcpy(config, argv[arg + 1]);
fflush(stdout); arg++;
if(count + 1 < argc) { } else {
haspDevice.set_hostname(argv[count + 1]); std::cout << "Missing config directory" << std::endl;
settings["mqtt"]["name"] = argv[count + 1]; showhelp = true;
} else {
showhelp = true;
}
}
if(strncmp(argv[count], "--mqtthost", 10) == 0) {
std::cout << " argv[" << count << "] " << argv[count] << std::endl << std::flush;
fflush(stdout);
if(count + 1 < argc) {
settings["mqtt"]["host"] = argv[count + 1];
} else {
showhelp = true;
}
}
if(strncmp(argv[count], "--mqttport", 10) == 0) {
std::cout << " argv[" << count << "] " << argv[count] << std::endl << std::flush;
fflush(stdout);
if(count + 1 < argc) {
settings["mqtt"]["port"] = atoi(argv[count + 1]);
} else {
showhelp = true;
}
}
if(strncmp(argv[count], "--mqttuser", 10) == 0) {
std::cout << " argv[" << count << "] " << argv[count] << std::endl << std::flush;
fflush(stdout);
if(count + 1 < argc) {
settings["mqtt"]["user"] = argv[count + 1];
} else {
showhelp = true;
}
}
if(strncmp(argv[count], "--mqttpass", 10) == 0) {
std::cout << " argv[" << count << "] " << argv[count] << std::endl << std::flush;
fflush(stdout);
if(count + 1 < argc) {
settings["mqtt"]["pass"] = argv[count + 1];
} else {
showhelp = true;
}
} }
} else {
std::cout << "Unrecognized command line parameter: " << argv[arg] << std::endl;
showhelp = true;
} }
} }
if(showhelp) { if(showhelp) {
usage("openHASP", haspDevice.get_version()); usage("openHASP", haspDevice.get_version());
goto end;
#if defined(WINDOWS)
WriteConsole(std_out, "bye\n\n", 3, NULL, NULL);
std::cout << std::endl << std::flush;
fflush(stdout);
FreeConsole();
exit(0);
#endif
return 0;
} }
char buffer[2048]; if(config[0] == '\0') {
serializeJson(settings, buffer, sizeof(buffer)); #if USE_MONITOR
std::cout << buffer << std::endl << std::flush; SDL_Init(0); // Needs to be initialized for GetPerfPath
fflush(stdout); strcpy(config, SDL_GetPrefPath("hasp", "hasp"));
#if HASP_USE_MQTT SDL_Quit(); // We'll properly init later
mqttSetConfig(settings["mqtt"]); #elif USE_WIN32DRV
if(SUCCEEDED(SHGetFolderPath(NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE, NULL, 0, config))) {
PathAppendA(config, "hasp");
PathAppendA(config, "hasp");
}
#endif #endif
// printf("%s %d\n", __FILE__, __LINE__); }
// fflush(stdout); cd(config);
debugPrintHaspHeader(stdout);
LOG_INFO(TAG_MAIN, "resolution %d x %d", tft_width, tft_height);
LOG_INFO(TAG_MAIN, "pre setup");
setup(); setup();
#if USE_MONITOR #if USE_MONITOR
while(1) { while(1) {
loop(); loop();
@ -395,14 +303,13 @@ int main(int argc, char* argv[])
} }
#endif #endif
end:
#if defined(WINDOWS) #if defined(WINDOWS)
WriteConsole(std_out, "bye\n\n", 3, NULL, NULL);
std::cout << std::endl << std::flush; std::cout << std::endl << std::flush;
fflush(stdout); fflush(stdout);
FreeConsole(); FreeConsole();
exit(0); exit(0);
#endif #endif
return 0; return 0;
} }

View File

@ -1,7 +1,6 @@
[env:windows_gdi_64bits] [env:windows_gdi_64bits]
platform = native@^1.1.4 platform = native@^1.1.4
extra_scripts = extra_scripts =
tools/sdl2_build_extra.py
tools/windows_build_extra.py tools/windows_build_extra.py
build_flags = build_flags =
${env.build_flags} ${env.build_flags}
@ -65,13 +64,12 @@ build_flags =
-lrpcrt4 -lrpcrt4
-lcrypt32 -lcrypt32
-lmingw32 -lmingw32
-mwindows
-lm -lm
-ldinput8 -ldinput8
;-ldxguid ;-ldxguid
;-ldxerr8 ;-ldxerr8
;-luser32 ;-luser32
;-lgdi32 -lgdi32
-lwinmm -lwinmm
-limm32 -limm32
-lole32 -lole32

View File

@ -72,13 +72,12 @@ build_flags =
-lmingw32 -lmingw32
-lSDL2main -lSDL2main
-lSDL2 -lSDL2
-mwindows
-lm -lm
-ldinput8 -ldinput8
;-ldxguid ;-ldxguid
;-ldxerr8 ;-ldxerr8
;-luser32 ;-luser32
;-lgdi32 -lgdi32
-lwinmm -lwinmm
-limm32 -limm32
-lole32 -lole32