Skip to content

Commit 5ee7b1e

Browse files
authored
expose config ini parsing to clients (#68)
1 parent e72aea1 commit 5ee7b1e

File tree

3 files changed

+27
-22
lines changed

3 files changed

+27
-22
lines changed

include/DMDUtil/Config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class DMDUTILAPI Config
3636
{
3737
public:
3838
static Config* GetInstance();
39+
void parseConfigFile(const char* path);
3940
bool IsAltColor() const { return m_altColor; }
4041
void SetAltColor(bool altColor) { m_altColor = altColor; }
4142
void SetAltColorPath(const char* path) { m_altColorPath = path; }

src/Config.cpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "DMDUtil/Config.h"
22

3-
#include <cstring>
3+
#include "ini.h"
44

55
namespace DMDUtil
66
{
@@ -37,4 +37,28 @@ Config::Config()
3737
memset(&m_pupTriggerCallbackContext, 0, sizeof(m_pupTriggerCallbackContext));
3838
}
3939

40+
void Config::parseConfigFile(const char* path)
41+
{
42+
inih::INIReader r{path};
43+
44+
SetDMDServerAddr(r.Get<std::string>("DMDServer", "Addr", "localhost").c_str());
45+
SetDMDServerPort(r.Get<int>("DMDServer", "Port", 6789));
46+
SetAltColor(r.Get<bool>("DMDServer", "AltColor", true));
47+
SetAltColorPath(r.Get<std::string>("DMDServer", "AltColorPath", "").c_str());
48+
SetPUPCapture(r.Get<bool>("DMDServer", "PUPCapture", false));
49+
SetPUPVideosPath(r.Get<std::string>("DMDServer", "PUPVideosPath", "").c_str());
50+
SetPUPExactColorMatch(r.Get<bool>("DMDServer", "PUPExactColorMatch", false));
51+
// ZeDMD
52+
SetZeDMD(r.Get<bool>("ZeDMD", "Enabled", true));
53+
SetZeDMDDevice(r.Get<std::string>("ZeDMD", "Device", "").c_str());
54+
SetZeDMDDebug(r.Get<bool>("ZeDMD", "Debug", false));
55+
SetZeDMDBrightness(r.Get<int>("ZeDMD", "Brightness", -1));
56+
// ZeDMD WiFi
57+
SetZeDMDWiFiEnabled(r.Get<bool>("ZeDMD-WiFi", "Enabled", false));
58+
SetZeDMDWiFiAddr(r.Get<std::string>("ZeDMD-WiFi", "WiFiAddr", "").c_str());
59+
// Pixelcade
60+
SetPixelcade(r.Get<bool>("Pixelcade", "Enabled", true));
61+
SetPixelcadeDevice(r.Get<std::string>("Pixelcade", "Device", "").c_str());
62+
}
63+
4064
} // namespace DMDUtil

src/dmdServer.cpp

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include "DMDUtil/DMDUtil.h"
1010
#include "Logger.h"
1111
#include "cargs.h"
12-
#include "ini.h"
1312
#include "sockpp/tcp_acceptor.h"
1413

1514
#define DMDSERVER_MAX_WIDTH 256
@@ -271,26 +270,7 @@ int main(int argc, char* argv[])
271270
char identifier = cag_option_get_identifier(&cag_context);
272271
if (identifier == 'c')
273272
{
274-
inih::INIReader r{cag_option_get_value(&cag_context)};
275-
pConfig->SetDMDServerAddr(r.Get<string>("DMDServer", "Addr", "localhost").c_str());
276-
pConfig->SetDMDServerPort(r.Get<int>("DMDServer", "Port", 6789));
277-
pConfig->SetAltColor(r.Get<bool>("DMDServer", "AltColor", true));
278-
pConfig->SetAltColorPath(r.Get<string>("DMDServer", "AltColorPath", "").c_str());
279-
pConfig->SetPUPCapture(r.Get<bool>("DMDServer", "PUPCapture", false));
280-
pConfig->SetPUPVideosPath(r.Get<string>("DMDServer", "PUPVideosPath", "").c_str());
281-
pConfig->SetPUPExactColorMatch(r.Get<bool>("DMDServer", "PUPExactColorMatch", false));
282-
// ZeDMD
283-
pConfig->SetZeDMD(r.Get<bool>("ZeDMD", "Enabled", true));
284-
pConfig->SetZeDMDDevice(r.Get<string>("ZeDMD", "Device", "").c_str());
285-
pConfig->SetZeDMDDebug(r.Get<bool>("ZeDMD", "Debug", false));
286-
pConfig->SetZeDMDBrightness(r.Get<int>("ZeDMD", "Brightness", -1));
287-
// ZeDMD WiFi
288-
pConfig->SetZeDMDWiFiEnabled(r.Get<bool>("ZeDMD-WiFi", "Enabled", false));
289-
pConfig->SetZeDMDWiFiAddr(r.Get<string>("ZeDMD-WiFi", "WiFiAddr", "").c_str());
290-
// Pixelcade
291-
pConfig->SetPixelcade(r.Get<bool>("Pixelcade", "Enabled", true));
292-
pConfig->SetPixelcadeDevice(r.Get<string>("Pixelcade", "Device", "").c_str());
293-
273+
pConfig->parseConfigFile(cag_option_get_value(&cag_context));
294274
if (opt_verbose) DMDUtil::Log(DMDUtil_LogLevel_INFO, "Loaded config file");
295275
}
296276
else if (identifier == 'o')

0 commit comments

Comments
 (0)