From 7e1630fce2f021e4e7222cdcbc78d2570048648a Mon Sep 17 00:00:00 2001 From: Markus Kalkbrenner Date: Wed, 9 Apr 2025 15:16:27 +0200 Subject: [PATCH] expose config ini parsing to clients --- include/DMDUtil/Config.h | 1 + src/Config.cpp | 26 +++++++++++++++++++++++++- src/dmdServer.cpp | 22 +--------------------- 3 files changed, 27 insertions(+), 22 deletions(-) diff --git a/include/DMDUtil/Config.h b/include/DMDUtil/Config.h index 7d476303..7fbc9d62 100644 --- a/include/DMDUtil/Config.h +++ b/include/DMDUtil/Config.h @@ -36,6 +36,7 @@ class DMDUTILAPI Config { public: static Config* GetInstance(); + void parseConfigFile(const char* path); bool IsAltColor() const { return m_altColor; } void SetAltColor(bool altColor) { m_altColor = altColor; } void SetAltColorPath(const char* path) { m_altColorPath = path; } diff --git a/src/Config.cpp b/src/Config.cpp index c9001596..94b9cb65 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -1,6 +1,6 @@ #include "DMDUtil/Config.h" -#include +#include "ini.h" namespace DMDUtil { @@ -37,4 +37,28 @@ Config::Config() memset(&m_pupTriggerCallbackContext, 0, sizeof(m_pupTriggerCallbackContext)); } +void Config::parseConfigFile(const char* path) +{ + inih::INIReader r{path}; + + SetDMDServerAddr(r.Get("DMDServer", "Addr", "localhost").c_str()); + SetDMDServerPort(r.Get("DMDServer", "Port", 6789)); + SetAltColor(r.Get("DMDServer", "AltColor", true)); + SetAltColorPath(r.Get("DMDServer", "AltColorPath", "").c_str()); + SetPUPCapture(r.Get("DMDServer", "PUPCapture", false)); + SetPUPVideosPath(r.Get("DMDServer", "PUPVideosPath", "").c_str()); + SetPUPExactColorMatch(r.Get("DMDServer", "PUPExactColorMatch", false)); + // ZeDMD + SetZeDMD(r.Get("ZeDMD", "Enabled", true)); + SetZeDMDDevice(r.Get("ZeDMD", "Device", "").c_str()); + SetZeDMDDebug(r.Get("ZeDMD", "Debug", false)); + SetZeDMDBrightness(r.Get("ZeDMD", "Brightness", -1)); + // ZeDMD WiFi + SetZeDMDWiFiEnabled(r.Get("ZeDMD-WiFi", "Enabled", false)); + SetZeDMDWiFiAddr(r.Get("ZeDMD-WiFi", "WiFiAddr", "").c_str()); + // Pixelcade + SetPixelcade(r.Get("Pixelcade", "Enabled", true)); + SetPixelcadeDevice(r.Get("Pixelcade", "Device", "").c_str()); +} + } // namespace DMDUtil diff --git a/src/dmdServer.cpp b/src/dmdServer.cpp index 69bf2746..7663baf9 100644 --- a/src/dmdServer.cpp +++ b/src/dmdServer.cpp @@ -9,7 +9,6 @@ #include "DMDUtil/DMDUtil.h" #include "Logger.h" #include "cargs.h" -#include "ini.h" #include "sockpp/tcp_acceptor.h" #define DMDSERVER_MAX_WIDTH 256 @@ -271,26 +270,7 @@ int main(int argc, char* argv[]) char identifier = cag_option_get_identifier(&cag_context); if (identifier == 'c') { - inih::INIReader r{cag_option_get_value(&cag_context)}; - pConfig->SetDMDServerAddr(r.Get("DMDServer", "Addr", "localhost").c_str()); - pConfig->SetDMDServerPort(r.Get("DMDServer", "Port", 6789)); - pConfig->SetAltColor(r.Get("DMDServer", "AltColor", true)); - pConfig->SetAltColorPath(r.Get("DMDServer", "AltColorPath", "").c_str()); - pConfig->SetPUPCapture(r.Get("DMDServer", "PUPCapture", false)); - pConfig->SetPUPVideosPath(r.Get("DMDServer", "PUPVideosPath", "").c_str()); - pConfig->SetPUPExactColorMatch(r.Get("DMDServer", "PUPExactColorMatch", false)); - // ZeDMD - pConfig->SetZeDMD(r.Get("ZeDMD", "Enabled", true)); - pConfig->SetZeDMDDevice(r.Get("ZeDMD", "Device", "").c_str()); - pConfig->SetZeDMDDebug(r.Get("ZeDMD", "Debug", false)); - pConfig->SetZeDMDBrightness(r.Get("ZeDMD", "Brightness", -1)); - // ZeDMD WiFi - pConfig->SetZeDMDWiFiEnabled(r.Get("ZeDMD-WiFi", "Enabled", false)); - pConfig->SetZeDMDWiFiAddr(r.Get("ZeDMD-WiFi", "WiFiAddr", "").c_str()); - // Pixelcade - pConfig->SetPixelcade(r.Get("Pixelcade", "Enabled", true)); - pConfig->SetPixelcadeDevice(r.Get("Pixelcade", "Device", "").c_str()); - + pConfig->parseConfigFile(cag_option_get_value(&cag_context)); if (opt_verbose) DMDUtil::Log(DMDUtil_LogLevel_INFO, "Loaded config file"); } else if (identifier == 'o')