Initial prototype of settings manager loads JSON settings file and E1.31 detector uses JSON data to detect devices
This commit is contained in:
parent
5b15251d46
commit
5b68efd09f
6 changed files with 275 additions and 204 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
#include "Detector.h"
|
#include "Detector.h"
|
||||||
#include "RGBController.h"
|
#include "RGBController.h"
|
||||||
#include "RGBController_E131.h"
|
#include "RGBController_E131.h"
|
||||||
|
#include "SettingsManager.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
@ -11,18 +12,6 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#ifndef WIN32
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <dirent.h>
|
|
||||||
#else
|
|
||||||
#include <windows.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef WIN32
|
|
||||||
#define LPSTR char *
|
|
||||||
#define strtok_s strtok_r
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/******************************************************************************************\
|
/******************************************************************************************\
|
||||||
* *
|
* *
|
||||||
* DetectE131Controllers *
|
* DetectE131Controllers *
|
||||||
|
|
@ -33,223 +22,206 @@
|
||||||
|
|
||||||
void DetectE131Controllers(std::vector<RGBController*> &rgb_controllers)
|
void DetectE131Controllers(std::vector<RGBController*> &rgb_controllers)
|
||||||
{
|
{
|
||||||
RGBController_E131* new_controller;
|
json e131_settings;
|
||||||
|
|
||||||
std::ifstream infile;
|
|
||||||
char arg1[64];
|
|
||||||
|
|
||||||
std::vector<std::vector<E131Device>> device_lists;
|
std::vector<std::vector<E131Device>> device_lists;
|
||||||
E131Device dev;
|
E131Device dev;
|
||||||
|
|
||||||
bool new_device = false;
|
|
||||||
|
|
||||||
//Clear E131 device data
|
/*-------------------------------------------------*\
|
||||||
dev.name = "";
|
| Get E1.31 settings from settings manager |
|
||||||
dev.type = ZONE_TYPE_SINGLE;
|
\*-------------------------------------------------*/
|
||||||
dev.num_leds = 0;
|
e131_settings = ResourceManager::get()->GetSettingsManager()->GetSettings("Setting_E131Devices");
|
||||||
dev.rgb_order = E131_RGB_ORDER_RBG;
|
|
||||||
dev.matrix_order = E131_MATRIX_ORDER_HORIZONTAL_TOP_LEFT;
|
|
||||||
dev.matrix_width = 0;
|
|
||||||
dev.matrix_height = 0;
|
|
||||||
|
|
||||||
//Open settings file
|
|
||||||
infile.open("e131.txt");
|
|
||||||
|
|
||||||
if (infile.good())
|
/*-------------------------------------------------*\
|
||||||
|
| If the E1.31 settings contains devices, process |
|
||||||
|
\*-------------------------------------------------*/
|
||||||
|
if(e131_settings.contains("devices"))
|
||||||
{
|
{
|
||||||
for (std::string line; std::getline(infile, line); )
|
for(unsigned int device_idx = 0; device_idx < e131_settings["devices"].size(); device_idx++)
|
||||||
{
|
{
|
||||||
if (new_device)
|
/*-------------------------------------------------*\
|
||||||
|
| Clear E1.31 device data |
|
||||||
|
\*-------------------------------------------------*/
|
||||||
|
dev.name = "";
|
||||||
|
dev.type = ZONE_TYPE_SINGLE;
|
||||||
|
dev.num_leds = 0;
|
||||||
|
dev.rgb_order = E131_RGB_ORDER_RBG;
|
||||||
|
dev.matrix_order = E131_MATRIX_ORDER_HORIZONTAL_TOP_LEFT;
|
||||||
|
dev.matrix_width = 0;
|
||||||
|
dev.matrix_height = 0;
|
||||||
|
dev.start_channel = 1;
|
||||||
|
dev.start_universe = 1;
|
||||||
|
|
||||||
|
if(e131_settings["devices"][device_idx].contains("name"))
|
||||||
{
|
{
|
||||||
dev.name = line;
|
dev.name = e131_settings["devices"][device_idx]["name"];
|
||||||
new_device = false;
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (line == "")
|
if(e131_settings["devices"][device_idx].contains("num_leds"))
|
||||||
{
|
{
|
||||||
continue;
|
dev.num_leds = e131_settings["devices"][device_idx]["num_leds"];
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((line[0] != ';') && (line[0] != '#') && (line[0] != '/'))
|
if(e131_settings["devices"][device_idx].contains("start_universe"))
|
||||||
{
|
{
|
||||||
char * argument;
|
dev.start_universe = e131_settings["devices"][device_idx]["start_universe"];
|
||||||
char * value;
|
}
|
||||||
|
|
||||||
value = (char *)line.c_str();
|
if(e131_settings["devices"][device_idx].contains("start_channel"))
|
||||||
|
{
|
||||||
|
dev.start_channel = e131_settings["devices"][device_idx]["start_channel"];
|
||||||
|
}
|
||||||
|
|
||||||
argument = strtok_s(value, "=", &value);
|
if(e131_settings["devices"][device_idx].contains("matrix_order"))
|
||||||
|
{
|
||||||
|
std::string matrix_order_val = e131_settings["devices"][device_idx]["matrix_order"];
|
||||||
|
|
||||||
//Strip off new line characters if present
|
if(matrix_order_val == "HORIZONTAL_TOP_LEFT")
|
||||||
argument = strtok(argument, "\r\n");
|
|
||||||
value = strtok(value, "\r\n");
|
|
||||||
|
|
||||||
if(argument)
|
|
||||||
{
|
{
|
||||||
if (strcmp(argument, "e131_device_start") == 0)
|
dev.matrix_order = E131_MATRIX_ORDER_HORIZONTAL_TOP_LEFT;
|
||||||
{
|
}
|
||||||
new_device = true;
|
else if(matrix_order_val == "HORIZONTAL_TOP_RIGHT")
|
||||||
}
|
{
|
||||||
else if(strcmp(argument, "num_leds") == 0)
|
dev.matrix_order = E131_MATRIX_ORDER_HORIZONTAL_TOP_RIGHT;
|
||||||
{
|
}
|
||||||
dev.num_leds = atoi(value);
|
else if(matrix_order_val == "HORIZONTAL_BOTTOM_LEFT")
|
||||||
}
|
{
|
||||||
else if(strcmp(argument, "start_universe") == 0)
|
dev.matrix_order = E131_MATRIX_ORDER_HORIZONTAL_BOTTOM_LEFT;
|
||||||
{
|
}
|
||||||
dev.start_universe = atoi(value);
|
else if(matrix_order_val == "HORIZONTAL_BOTTOM_RIGHT")
|
||||||
}
|
{
|
||||||
else if(strcmp(argument, "start_channel") == 0)
|
dev.matrix_order = E131_MATRIX_ORDER_HORIZONTAL_BOTTOM_RIGHT;
|
||||||
{
|
}
|
||||||
dev.start_channel = atoi(value);
|
else if(matrix_order_val == "VERTICAL_TOP_LEFT")
|
||||||
}
|
{
|
||||||
else if(strcmp(argument, "keepalive_time") == 0)
|
dev.matrix_order = E131_MATRIX_ORDER_VERTICAL_TOP_LEFT;
|
||||||
{
|
}
|
||||||
dev.keepalive_time = atoi(value);
|
else if(matrix_order_val == "VERTICAL_TOP_RIGHT")
|
||||||
}
|
{
|
||||||
else if(strcmp(argument, "rgb_order") == 0)
|
dev.matrix_order = E131_MATRIX_ORDER_VERTICAL_TOP_RIGHT;
|
||||||
{
|
}
|
||||||
if(strcmp(value, "RGB") == 0)
|
else if(matrix_order_val == "VERTICAL_BOTTOM_LEFT")
|
||||||
{
|
{
|
||||||
dev.rgb_order = E131_RGB_ORDER_RGB;
|
dev.matrix_order = E131_MATRIX_ORDER_VERTICAL_BOTTOM_LEFT;
|
||||||
}
|
}
|
||||||
else if(strcmp(value, "RBG") == 0)
|
else if(matrix_order_val == "VERTICAL_BOTTOM_RIGHT")
|
||||||
{
|
{
|
||||||
dev.rgb_order = E131_RGB_ORDER_RBG;
|
dev.matrix_order = E131_MATRIX_ORDER_VERTICAL_BOTTOM_RIGHT;
|
||||||
}
|
}
|
||||||
else if(strcmp(value, "GRB") == 0)
|
else
|
||||||
{
|
{
|
||||||
dev.rgb_order = E131_RGB_ORDER_GRB;
|
dev.matrix_order = e131_settings["devices"][device_idx]["matrix_order"];
|
||||||
}
|
}
|
||||||
else if(strcmp(value, "GBR") == 0)
|
}
|
||||||
{
|
|
||||||
dev.rgb_order = E131_RGB_ORDER_GBR;
|
|
||||||
}
|
|
||||||
else if(strcmp(value, "BRG") == 0)
|
|
||||||
{
|
|
||||||
dev.rgb_order = E131_RGB_ORDER_BRG;
|
|
||||||
}
|
|
||||||
else if(strcmp(value, "BGR") == 0)
|
|
||||||
{
|
|
||||||
dev.rgb_order = E131_RGB_ORDER_BGR;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
dev.rgb_order = atoi(value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if(strcmp(argument, "matrix_order") == 0)
|
|
||||||
{
|
|
||||||
if(strcmp(value, "HORIZONTAL_TOP_LEFT") == 0)
|
|
||||||
{
|
|
||||||
dev.matrix_order = E131_MATRIX_ORDER_HORIZONTAL_TOP_LEFT;
|
|
||||||
}
|
|
||||||
else if(strcmp(value, "HORIZONTAL_TOP_RIGHT") == 0)
|
|
||||||
{
|
|
||||||
dev.matrix_order = E131_MATRIX_ORDER_HORIZONTAL_TOP_RIGHT;
|
|
||||||
}
|
|
||||||
else if(strcmp(value, "HORIZONTAL_BOTTOM_LEFT") == 0)
|
|
||||||
{
|
|
||||||
dev.matrix_order = E131_MATRIX_ORDER_HORIZONTAL_BOTTOM_LEFT;
|
|
||||||
}
|
|
||||||
else if(strcmp(value, "HORIZONTAL_BOTTOM_RIGHT") == 0)
|
|
||||||
{
|
|
||||||
dev.matrix_order = E131_MATRIX_ORDER_HORIZONTAL_BOTTOM_RIGHT;
|
|
||||||
}
|
|
||||||
else if(strcmp(value, "VERTICAL_TOP_LEFT") == 0)
|
|
||||||
{
|
|
||||||
dev.matrix_order = E131_MATRIX_ORDER_VERTICAL_TOP_LEFT;
|
|
||||||
}
|
|
||||||
else if(strcmp(value, "VERTICAL_TOP_RIGHT") == 0)
|
|
||||||
{
|
|
||||||
dev.matrix_order = E131_MATRIX_ORDER_VERTICAL_TOP_RIGHT;
|
|
||||||
}
|
|
||||||
else if(strcmp(value, "VERTICAL_BOTTOM_LEFT") == 0)
|
|
||||||
{
|
|
||||||
dev.matrix_order = E131_MATRIX_ORDER_VERTICAL_BOTTOM_LEFT;
|
|
||||||
}
|
|
||||||
else if(strcmp(value, "VERTICAL_BOTTOM_RIGHT") == 0)
|
|
||||||
{
|
|
||||||
dev.matrix_order = E131_MATRIX_ORDER_VERTICAL_BOTTOM_RIGHT;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
dev.matrix_order = atoi(value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if(strcmp(argument, "matrix_width") == 0)
|
|
||||||
{
|
|
||||||
dev.matrix_width = atoi(value);
|
|
||||||
}
|
|
||||||
else if(strcmp(argument, "matrix_height") == 0)
|
|
||||||
{
|
|
||||||
dev.matrix_height = atoi(value);
|
|
||||||
}
|
|
||||||
else if(strcmp(argument, "type") == 0)
|
|
||||||
{
|
|
||||||
if(strcmp(value, "SINGLE") == 0)
|
|
||||||
{
|
|
||||||
dev.type = ZONE_TYPE_SINGLE;
|
|
||||||
}
|
|
||||||
else if(strcmp(value, "LINEAR") == 0)
|
|
||||||
{
|
|
||||||
dev.type = ZONE_TYPE_LINEAR;
|
|
||||||
}
|
|
||||||
else if(strcmp(value, "MATRIX") == 0)
|
|
||||||
{
|
|
||||||
dev.type = ZONE_TYPE_MATRIX;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
dev.type = atoi(value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if(strcmp(argument, "e131_device_end") == 0)
|
|
||||||
{
|
|
||||||
/*---------------------------------------------------------*\
|
|
||||||
| Determine whether to create a new list or add this device |
|
|
||||||
| to an existing list. A device is added to an existing |
|
|
||||||
| list if both devices share one or more universes for the |
|
|
||||||
| same output destination |
|
|
||||||
\*---------------------------------------------------------*/
|
|
||||||
bool device_added_to_existing_list = false;
|
|
||||||
|
|
||||||
for(unsigned int list_idx = 0; list_idx < device_lists.size(); list_idx++)
|
if(e131_settings["devices"][device_idx].contains("rgb_order"))
|
||||||
{
|
{
|
||||||
for(unsigned int device_idx = 0; device_idx < device_lists[list_idx].size(); device_idx++)
|
std::string rgb_order_val = e131_settings["devices"][device_idx]["rgb_order"];
|
||||||
{
|
|
||||||
/*---------------------------------------------------------*\
|
|
||||||
| Check if any universes used by this new device exist in |
|
|
||||||
| the existing device. If so, add the new device to the |
|
|
||||||
| existing list. |
|
|
||||||
\*---------------------------------------------------------*/
|
|
||||||
if(dev.start_universe == device_lists[list_idx][device_idx].start_universe)
|
|
||||||
{
|
|
||||||
device_lists[list_idx].push_back(dev);
|
|
||||||
device_added_to_existing_list = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(device_added_to_existing_list)
|
if(rgb_order_val == "RGB")
|
||||||
{
|
{
|
||||||
break;
|
dev.rgb_order = E131_RGB_ORDER_RGB;
|
||||||
}
|
}
|
||||||
}
|
else if(rgb_order_val == "RBG")
|
||||||
|
{
|
||||||
|
dev.rgb_order = E131_RGB_ORDER_RBG;
|
||||||
|
}
|
||||||
|
else if(rgb_order_val == "GRB")
|
||||||
|
{
|
||||||
|
dev.rgb_order = E131_RGB_ORDER_GRB;
|
||||||
|
}
|
||||||
|
else if(rgb_order_val == "GBR")
|
||||||
|
{
|
||||||
|
dev.rgb_order = E131_RGB_ORDER_GBR;
|
||||||
|
}
|
||||||
|
else if(rgb_order_val == "BRG")
|
||||||
|
{
|
||||||
|
dev.rgb_order = E131_RGB_ORDER_BGR;
|
||||||
|
}
|
||||||
|
else if(rgb_order_val == "BGR")
|
||||||
|
{
|
||||||
|
dev.rgb_order = E131_RGB_ORDER_BGR;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dev.rgb_order = e131_settings["devices"][device_idx]["rgb_order"];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*---------------------------------------------------------*\
|
if(e131_settings["devices"][device_idx].contains("matrix_width"))
|
||||||
| If the device did not overlap with existing devices, |
|
{
|
||||||
| create a new list for it |
|
dev.matrix_width = e131_settings["devices"][device_idx]["matrix_width"];
|
||||||
\*---------------------------------------------------------*/
|
}
|
||||||
if(!device_added_to_existing_list)
|
|
||||||
{
|
|
||||||
std::vector<E131Device> new_list;
|
|
||||||
|
|
||||||
new_list.push_back(dev);
|
if(e131_settings["devices"][device_idx].contains("matrix_height"))
|
||||||
|
{
|
||||||
|
dev.matrix_height = e131_settings["devices"][device_idx]["matrix_height"];
|
||||||
|
}
|
||||||
|
|
||||||
|
if(e131_settings["devices"][device_idx].contains("type"))
|
||||||
|
{
|
||||||
|
std::string type_val = e131_settings["devices"][device_idx]["type"];
|
||||||
|
|
||||||
device_lists.push_back(new_list);
|
if(type_val == "SINGLE")
|
||||||
}
|
{
|
||||||
|
dev.type = ZONE_TYPE_SINGLE;
|
||||||
|
}
|
||||||
|
else if(type_val == "LINEAR")
|
||||||
|
{
|
||||||
|
dev.type = ZONE_TYPE_LINEAR;
|
||||||
|
}
|
||||||
|
else if(type_val == "MATRIX")
|
||||||
|
{
|
||||||
|
dev.type = ZONE_TYPE_MATRIX;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dev.type = e131_settings["devices"][device_idx]["type"];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*---------------------------------------------------------*\
|
||||||
|
| Determine whether to create a new list or add this device |
|
||||||
|
| to an existing list. A device is added to an existing |
|
||||||
|
| list if both devices share one or more universes for the |
|
||||||
|
| same output destination |
|
||||||
|
\*---------------------------------------------------------*/
|
||||||
|
bool device_added_to_existing_list = false;
|
||||||
|
|
||||||
|
for(unsigned int list_idx = 0; list_idx < device_lists.size(); list_idx++)
|
||||||
|
{
|
||||||
|
for(unsigned int device_idx = 0; device_idx < device_lists[list_idx].size(); device_idx++)
|
||||||
|
{
|
||||||
|
/*---------------------------------------------------------*\
|
||||||
|
| Check if any universes used by this new device exist in |
|
||||||
|
| the existing device. If so, add the new device to the |
|
||||||
|
| existing list. |
|
||||||
|
\*---------------------------------------------------------*/
|
||||||
|
if(dev.start_universe == device_lists[list_idx][device_idx].start_universe)
|
||||||
|
{
|
||||||
|
device_lists[list_idx].push_back(dev);
|
||||||
|
device_added_to_existing_list = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(device_added_to_existing_list)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*---------------------------------------------------------*\
|
||||||
|
| If the device did not overlap with existing devices, |
|
||||||
|
| create a new list for it |
|
||||||
|
\*---------------------------------------------------------*/
|
||||||
|
if(!device_added_to_existing_list)
|
||||||
|
{
|
||||||
|
std::vector<E131Device> new_list;
|
||||||
|
|
||||||
|
new_list.push_back(dev);
|
||||||
|
|
||||||
|
device_lists.push_back(new_list);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -113,6 +113,7 @@ HEADERS +=
|
||||||
NetworkServer.h \
|
NetworkServer.h \
|
||||||
ProfileManager.h \
|
ProfileManager.h \
|
||||||
ResourceManager.h \
|
ResourceManager.h \
|
||||||
|
SettingsManager.h \
|
||||||
Detector.h \
|
Detector.h \
|
||||||
DeviceDetector.h \
|
DeviceDetector.h \
|
||||||
qt/OpenRGBClientInfoPage.h \
|
qt/OpenRGBClientInfoPage.h \
|
||||||
|
|
@ -280,6 +281,7 @@ SOURCES +=
|
||||||
NetworkServer.cpp \
|
NetworkServer.cpp \
|
||||||
ProfileManager.cpp \
|
ProfileManager.cpp \
|
||||||
ResourceManager.cpp \
|
ResourceManager.cpp \
|
||||||
|
SettingsManager.cpp \
|
||||||
qt/OpenRGBClientInfoPage.cpp \
|
qt/OpenRGBClientInfoPage.cpp \
|
||||||
qt/OpenRGBDeviceInfoPage.cpp \
|
qt/OpenRGBDeviceInfoPage.cpp \
|
||||||
qt/OpenRGBDevicePage.cpp \
|
qt/OpenRGBDevicePage.cpp \
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,12 @@ ResourceManager::ResourceManager()
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
profile_manager = new ProfileManager(rgb_controllers);
|
profile_manager = new ProfileManager(rgb_controllers);
|
||||||
rgb_controllers_sizes = profile_manager->LoadProfileToList("sizes.ors");
|
rgb_controllers_sizes = profile_manager->LoadProfileToList("sizes.ors");
|
||||||
|
|
||||||
|
/*-------------------------------------------------------------------------*\
|
||||||
|
| Load settings from file |
|
||||||
|
\*-------------------------------------------------------------------------*/
|
||||||
|
settings_manager = new SettingsManager();
|
||||||
|
settings_manager->LoadSettings("OpenRGB.json");
|
||||||
}
|
}
|
||||||
|
|
||||||
ResourceManager::~ResourceManager()
|
ResourceManager::~ResourceManager()
|
||||||
|
|
@ -195,6 +201,11 @@ ProfileManager* ResourceManager::GetProfileManager()
|
||||||
return(profile_manager);
|
return(profile_manager);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SettingsManager* ResourceManager::GetSettingsManager()
|
||||||
|
{
|
||||||
|
return(settings_manager);
|
||||||
|
}
|
||||||
|
|
||||||
unsigned int ResourceManager::GetDetectionPercent()
|
unsigned int ResourceManager::GetDetectionPercent()
|
||||||
{
|
{
|
||||||
return (detection_percent.load());
|
return (detection_percent.load());
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@
|
||||||
#include "NetworkServer.h"
|
#include "NetworkServer.h"
|
||||||
#include "ProfileManager.h"
|
#include "ProfileManager.h"
|
||||||
#include "RGBController.h"
|
#include "RGBController.h"
|
||||||
|
#include "SettingsManager.h"
|
||||||
|
|
||||||
typedef std::function<void(std::vector<i2c_smbus_interface*>&)> I2CBusDetectorFunction;
|
typedef std::function<void(std::vector<i2c_smbus_interface*>&)> I2CBusDetectorFunction;
|
||||||
typedef std::function<void(std::vector<RGBController*>&)> DeviceDetectorFunction;
|
typedef std::function<void(std::vector<RGBController*>&)> DeviceDetectorFunction;
|
||||||
|
|
@ -58,6 +59,7 @@ public:
|
||||||
NetworkServer* GetServer();
|
NetworkServer* GetServer();
|
||||||
|
|
||||||
ProfileManager* GetProfileManager();
|
ProfileManager* GetProfileManager();
|
||||||
|
SettingsManager* GetSettingsManager();
|
||||||
|
|
||||||
void DeviceListChanged();
|
void DeviceListChanged();
|
||||||
void DetectionProgressChanged();
|
void DetectionProgressChanged();
|
||||||
|
|
@ -80,6 +82,11 @@ private:
|
||||||
\*-------------------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------------------*/
|
||||||
ProfileManager* profile_manager;
|
ProfileManager* profile_manager;
|
||||||
|
|
||||||
|
/*-------------------------------------------------------------------------------------*\
|
||||||
|
| Settings Manager |
|
||||||
|
\*-------------------------------------------------------------------------------------*/
|
||||||
|
SettingsManager* settings_manager;
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------------------*\
|
||||||
| I2C/SMBus Interfaces |
|
| I2C/SMBus Interfaces |
|
||||||
\*-------------------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------------------*/
|
||||||
|
|
|
||||||
49
SettingsManager.cpp
Normal file
49
SettingsManager.cpp
Normal file
|
|
@ -0,0 +1,49 @@
|
||||||
|
/*-----------------------------------------*\
|
||||||
|
| SettingsManager.cpp |
|
||||||
|
| |
|
||||||
|
| OpenRGB Settings Manager maintains a list|
|
||||||
|
| of application settings in JSON format. |
|
||||||
|
| Other components may register settings |
|
||||||
|
| with this class and store/load values. |
|
||||||
|
| |
|
||||||
|
| Adam Honse (CalcProgrammer1) 11/4/2020 |
|
||||||
|
\*-----------------------------------------*/
|
||||||
|
|
||||||
|
#include "SettingsManager.h"
|
||||||
|
|
||||||
|
#include <fstream>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
SettingsManager::SettingsManager()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
SettingsManager::~SettingsManager()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
json SettingsManager::GetSettings(std::string settings_key)
|
||||||
|
{
|
||||||
|
if(settings_data.contains(settings_key))
|
||||||
|
{
|
||||||
|
return(settings_data[settings_key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SettingsManager::LoadSettings(std::string filename)
|
||||||
|
{
|
||||||
|
/*---------------------------------------------------------*\
|
||||||
|
| Open input file in binary mode |
|
||||||
|
\*---------------------------------------------------------*/
|
||||||
|
std::ifstream settings_file(filename, std::ios::in | std::ios::binary);
|
||||||
|
|
||||||
|
/*---------------------------------------------------------*\
|
||||||
|
| Read settings into JSON store |
|
||||||
|
\*---------------------------------------------------------*/
|
||||||
|
if(settings_file)
|
||||||
|
{
|
||||||
|
settings_file >> settings_data;
|
||||||
|
}
|
||||||
|
}
|
||||||
30
SettingsManager.h
Normal file
30
SettingsManager.h
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
/*-----------------------------------------*\
|
||||||
|
| SettingsManager.h |
|
||||||
|
| |
|
||||||
|
| OpenRGB Settings Manager maintains a list|
|
||||||
|
| of application settings in JSON format. |
|
||||||
|
| Other components may register settings |
|
||||||
|
| with this class and store/load values. |
|
||||||
|
| |
|
||||||
|
| Adam Honse (CalcProgrammer1) 11/4/2020 |
|
||||||
|
\*-----------------------------------------*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "json.hpp"
|
||||||
|
|
||||||
|
using json = nlohmann::json;
|
||||||
|
|
||||||
|
class SettingsManager
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
SettingsManager();
|
||||||
|
~SettingsManager();
|
||||||
|
|
||||||
|
json GetSettings(std::string settings_key);
|
||||||
|
void LoadSettings(std::string filename);
|
||||||
|
|
||||||
|
private:
|
||||||
|
json settings_data;
|
||||||
|
json settings_prototype;
|
||||||
|
};
|
||||||
Loading…
Add table
Add a link
Reference in a new issue