Implement Hue Settings Handler to prevent json type conflicts that resulted in a multiply defined linker warning
This commit is contained in:
parent
236e67e46b
commit
a04fe26014
3 changed files with 222 additions and 50 deletions
|
|
@ -24,7 +24,7 @@
|
|||
#include "PhilipsHueEntertainmentController.h"
|
||||
#include "RGBController_PhilipsHue.h"
|
||||
#include "RGBController_PhilipsHueEntertainment.h"
|
||||
#include "SettingsManager.h"
|
||||
#include "PhilipsHueSettingsHandler.h"
|
||||
|
||||
/******************************************************************************************\
|
||||
* *
|
||||
|
|
@ -36,7 +36,7 @@
|
|||
|
||||
void DetectPhilipsHueControllers()
|
||||
{
|
||||
json hue_settings;
|
||||
PhilipsHueSettingsHandler hue_settings;
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Create an HTTP handler |
|
||||
|
|
@ -47,11 +47,6 @@ void DetectPhilipsHueControllers()
|
|||
using SystemHttpHandler = hueplusplus::LinHttpHandler;
|
||||
#endif
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Get Philips Hue settings from settings manager |
|
||||
\*-------------------------------------------------*/
|
||||
hue_settings = ResourceManager::get()->GetSettingsManager()->GetSettings("PhilipsHueDevices");
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Create a finder and find bridges |
|
||||
\*-------------------------------------------------*/
|
||||
|
|
@ -62,24 +57,14 @@ void DetectPhilipsHueControllers()
|
|||
| If no bridges were detected, manually add bridge |
|
||||
| IP and MAC (need to get these from file) |
|
||||
\*-------------------------------------------------*/
|
||||
if(bridges.empty())
|
||||
if(hue_settings.GetBridgeCount() > 0)
|
||||
{
|
||||
if(hue_settings.contains("bridges"))
|
||||
{
|
||||
hueplusplus::BridgeFinder::BridgeIdentification ident;
|
||||
hueplusplus::BridgeFinder::BridgeIdentification ident;
|
||||
|
||||
if(hue_settings["bridges"][0].contains("ip"))
|
||||
{
|
||||
ident.ip = hue_settings["bridges"][0]["ip"];
|
||||
}
|
||||
ident.ip = hue_settings.GetBridgeIP(0);
|
||||
ident.mac = hue_settings.GetBridgeMAC(0);
|
||||
|
||||
if(hue_settings["bridges"][0].contains("mac"))
|
||||
{
|
||||
ident.mac = hue_settings["bridges"][0]["mac"];
|
||||
}
|
||||
|
||||
bridges.push_back(ident);
|
||||
}
|
||||
bridges.push_back(ident);
|
||||
}
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
|
|
@ -95,22 +80,22 @@ void DetectPhilipsHueControllers()
|
|||
/*-------------------------------------------------*\
|
||||
| Check if a saved username exists |
|
||||
\*-------------------------------------------------*/
|
||||
if(hue_settings.contains("bridges"))
|
||||
if(hue_settings.GetBridgeCount() > 0)
|
||||
{
|
||||
/*-------------------------------------------------*\
|
||||
| Add the username if it exists |
|
||||
\*-------------------------------------------------*/
|
||||
if(hue_settings["bridges"][0].contains("username"))
|
||||
if(hue_settings.BridgeHasUsername(0))
|
||||
{
|
||||
finder.addUsername(bridges[0].mac, hue_settings["bridges"][0]["username"]);
|
||||
finder.addUsername(bridges[0].mac, hue_settings.GetBridgeUsername(0));
|
||||
}
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Add the client key if it exists |
|
||||
\*-------------------------------------------------*/
|
||||
if(hue_settings["bridges"][0].contains("clientkey"))
|
||||
if(hue_settings.BridgeHasClientKey(0))
|
||||
{
|
||||
finder.addClientKey(bridges[0].mac, hue_settings["bridges"][0]["clientkey"]);
|
||||
finder.addClientKey(bridges[0].mac, hue_settings.GetBridgeClientKey(0));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -134,11 +119,11 @@ void DetectPhilipsHueControllers()
|
|||
bool use_entertainment = false;
|
||||
bool auto_connect = false;
|
||||
|
||||
if(hue_settings.contains("bridges"))
|
||||
if(hue_settings.GetBridgeCount() > 0)
|
||||
{
|
||||
if(hue_settings["bridges"][0].contains("username"))
|
||||
if(hue_settings.BridgeHasUsername(0))
|
||||
{
|
||||
if(hue_settings["bridges"][0]["username"] != bridge.getUsername())
|
||||
if(hue_settings.GetBridgeUsername(0) != bridge.getUsername())
|
||||
{
|
||||
save_settings = true;
|
||||
}
|
||||
|
|
@ -148,9 +133,9 @@ void DetectPhilipsHueControllers()
|
|||
save_settings = true;
|
||||
}
|
||||
|
||||
if(hue_settings["bridges"][0].contains("clientkey"))
|
||||
if(hue_settings.BridgeHasClientKey(0))
|
||||
{
|
||||
if(hue_settings["bridges"][0]["clientkey"] != bridge.getClientKey())
|
||||
if(hue_settings.GetBridgeClientKey(0) != bridge.getClientKey())
|
||||
{
|
||||
use_entertainment = true;
|
||||
save_settings = true;
|
||||
|
|
@ -167,28 +152,18 @@ void DetectPhilipsHueControllers()
|
|||
\*-------------------------------------------------*/
|
||||
if(save_settings)
|
||||
{
|
||||
hue_settings["bridges"][0]["username"] = bridge.getUsername();
|
||||
hue_settings["bridges"][0]["clientkey"] = bridge.getClientKey();
|
||||
hue_settings["bridges"][0]["entertainment"] = use_entertainment;
|
||||
hue_settings["bridges"][0]["autoconnect"] = auto_connect;
|
||||
|
||||
ResourceManager::get()->GetSettingsManager()->SetSettings("PhilipsHueDevices", hue_settings);
|
||||
|
||||
ResourceManager::get()->GetSettingsManager()->SaveSettings();
|
||||
hue_settings.SetBridgeUsername(0, bridge.getUsername());
|
||||
hue_settings.SetBridgeClientKey(0, bridge.getClientKey());
|
||||
hue_settings.SetBridgeUseEntertainment(0, use_entertainment);
|
||||
hue_settings.SetBridgeAutoconnect(0, auto_connect);
|
||||
hue_settings.SaveSettings();
|
||||
}
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Get entertainment mode settings |
|
||||
| Get entertainment mode settings |
|
||||
\*-------------------------------------------------*/
|
||||
if(hue_settings["bridges"][0].contains("entertainment"))
|
||||
{
|
||||
use_entertainment = hue_settings["bridges"][0]["entertainment"];
|
||||
}
|
||||
|
||||
if(hue_settings["bridges"][0].contains("autoconnect"))
|
||||
{
|
||||
auto_connect = hue_settings["bridges"][0]["autoconnect"];
|
||||
}
|
||||
use_entertainment = hue_settings.GetBridgeUseEntertainment(0);
|
||||
auto_connect = hue_settings.GetBridgeAutoconnect(0);
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Get all groups from the bridge |
|
||||
|
|
|
|||
151
Controllers/PhilipsHueController/PhilipsHueSettingsHandler.cpp
Normal file
151
Controllers/PhilipsHueController/PhilipsHueSettingsHandler.cpp
Normal file
|
|
@ -0,0 +1,151 @@
|
|||
#include "PhilipsHueSettingsHandler.h"
|
||||
#include "ResourceManager.h"
|
||||
#include "SettingsManager.h"
|
||||
|
||||
#define HUE_SETTINGS ((hue_settings_type *)hue_settings)->hue_settings
|
||||
|
||||
typedef struct
|
||||
{
|
||||
json hue_settings;
|
||||
} hue_settings_type;
|
||||
|
||||
PhilipsHueSettingsHandler::PhilipsHueSettingsHandler()
|
||||
{
|
||||
/*-------------------------------------------------*\
|
||||
| Create an object to hold the hue settings json |
|
||||
| This cannot be a class member as json must not |
|
||||
| be included in the header file, so it is held as |
|
||||
| a void pointer instead. |
|
||||
\*-------------------------------------------------*/
|
||||
hue_settings = (void *)(new hue_settings_type);
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Get Philips Hue settings from settings manager |
|
||||
\*-------------------------------------------------*/
|
||||
HUE_SETTINGS = ResourceManager::get()->GetSettingsManager()->GetSettings("PhilipsHueDevices");
|
||||
}
|
||||
|
||||
PhilipsHueSettingsHandler::~PhilipsHueSettingsHandler()
|
||||
{
|
||||
delete (hue_settings_type *)hue_settings;
|
||||
}
|
||||
|
||||
unsigned int PhilipsHueSettingsHandler::GetBridgeCount()
|
||||
{
|
||||
if(HUE_SETTINGS.contains("bridges"))
|
||||
{
|
||||
return(HUE_SETTINGS["bridges"].size());
|
||||
}
|
||||
else
|
||||
{
|
||||
return(0);
|
||||
}
|
||||
}
|
||||
|
||||
std::string PhilipsHueSettingsHandler::GetBridgeIP(unsigned int bridge_idx)
|
||||
{
|
||||
if(HUE_SETTINGS["bridges"][bridge_idx].contains("ip"))
|
||||
{
|
||||
return(HUE_SETTINGS["bridges"][bridge_idx]["ip"]);
|
||||
}
|
||||
else
|
||||
{
|
||||
return("");
|
||||
}
|
||||
}
|
||||
|
||||
std::string PhilipsHueSettingsHandler::GetBridgeMAC(unsigned int bridge_idx)
|
||||
{
|
||||
if(HUE_SETTINGS["bridges"][bridge_idx].contains("mac"))
|
||||
{
|
||||
return(HUE_SETTINGS["bridges"][bridge_idx]["mac"]);
|
||||
}
|
||||
else
|
||||
{
|
||||
return("");
|
||||
}
|
||||
}
|
||||
|
||||
std::string PhilipsHueSettingsHandler::GetBridgeUsername(unsigned int bridge_idx)
|
||||
{
|
||||
if(HUE_SETTINGS["bridges"][bridge_idx].contains("username"))
|
||||
{
|
||||
return(HUE_SETTINGS["bridges"][bridge_idx]["username"]);
|
||||
}
|
||||
else
|
||||
{
|
||||
return("");
|
||||
}
|
||||
}
|
||||
|
||||
std::string PhilipsHueSettingsHandler::GetBridgeClientKey(unsigned int bridge_idx)
|
||||
{
|
||||
if(HUE_SETTINGS["bridges"][bridge_idx].contains("clientkey"))
|
||||
{
|
||||
return(HUE_SETTINGS["bridges"][bridge_idx]["clientkey"]);
|
||||
}
|
||||
else
|
||||
{
|
||||
return("");
|
||||
}
|
||||
}
|
||||
|
||||
bool PhilipsHueSettingsHandler::GetBridgeAutoconnect(unsigned int bridge_idx)
|
||||
{
|
||||
if(HUE_SETTINGS["bridges"][bridge_idx].contains("autoconnect"))
|
||||
{
|
||||
return(HUE_SETTINGS["bridges"][bridge_idx]["autoconnect"]);
|
||||
}
|
||||
else
|
||||
{
|
||||
return(false);
|
||||
}
|
||||
}
|
||||
|
||||
bool PhilipsHueSettingsHandler::GetBridgeUseEntertainment(unsigned int bridge_idx)
|
||||
{
|
||||
if(HUE_SETTINGS["bridges"][bridge_idx].contains("entertainment"))
|
||||
{
|
||||
return(HUE_SETTINGS["bridges"][bridge_idx]["entertainment"]);
|
||||
}
|
||||
else
|
||||
{
|
||||
return(false);
|
||||
}
|
||||
}
|
||||
|
||||
bool PhilipsHueSettingsHandler::BridgeHasUsername(unsigned int bridge_idx)
|
||||
{
|
||||
return(HUE_SETTINGS["bridges"][bridge_idx].contains("username"));
|
||||
}
|
||||
|
||||
bool PhilipsHueSettingsHandler::BridgeHasClientKey(unsigned int bridge_idx)
|
||||
{
|
||||
return(HUE_SETTINGS["bridges"][bridge_idx].contains("clientkey"));
|
||||
}
|
||||
|
||||
void PhilipsHueSettingsHandler::SetBridgeUsername(unsigned int bridge_idx, std::string username)
|
||||
{
|
||||
HUE_SETTINGS["bridges"][bridge_idx]["username"] = username;
|
||||
}
|
||||
|
||||
void PhilipsHueSettingsHandler::SetBridgeClientKey(unsigned int bridge_idx, std::string clientkey)
|
||||
{
|
||||
HUE_SETTINGS["bridges"][bridge_idx]["clientkey"] = clientkey;
|
||||
}
|
||||
|
||||
void PhilipsHueSettingsHandler::SetBridgeAutoconnect(unsigned int bridge_idx, bool auto_connect)
|
||||
{
|
||||
HUE_SETTINGS["bridges"][bridge_idx]["autoconnect"] = auto_connect;
|
||||
}
|
||||
|
||||
void PhilipsHueSettingsHandler::SetBridgeUseEntertainment(unsigned int bridge_idx, bool use_entertainment)
|
||||
{
|
||||
HUE_SETTINGS["bridges"][bridge_idx]["entertainment"] = use_entertainment;
|
||||
}
|
||||
|
||||
void PhilipsHueSettingsHandler::SaveSettings()
|
||||
{
|
||||
ResourceManager::get()->GetSettingsManager()->SetSettings("PhilipsHueDevices", HUE_SETTINGS);
|
||||
ResourceManager::get()->GetSettingsManager()->SaveSettings();
|
||||
}
|
||||
46
Controllers/PhilipsHueController/PhilipsHueSettingsHandler.h
Normal file
46
Controllers/PhilipsHueController/PhilipsHueSettingsHandler.h
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
/*---------------------------------------------------------*\
|
||||
| PhilipsHueSettingsHandler.h |
|
||||
| |
|
||||
| Settings Handler for Philips Hue |
|
||||
| Due to conflict in jsoh.hpp library, hueplusplus and |
|
||||
| SettingsManager should not be included in the same file |
|
||||
| so handle settings in a separate class. |
|
||||
| |
|
||||
| Adam Honse (calcprogrammer1@gmail.com) 17 Jan 2025 |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-only |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
class PhilipsHueSettingsHandler
|
||||
{
|
||||
public:
|
||||
PhilipsHueSettingsHandler();
|
||||
~PhilipsHueSettingsHandler();
|
||||
|
||||
unsigned int GetBridgeCount();
|
||||
|
||||
std::string GetBridgeIP(unsigned int bridge_idx);
|
||||
std::string GetBridgeMAC(unsigned int bridge_idx);
|
||||
std::string GetBridgeUsername(unsigned int bridge_idx);
|
||||
std::string GetBridgeClientKey(unsigned int bridge_idx);
|
||||
bool GetBridgeAutoconnect(unsigned int bridge_idx);
|
||||
bool GetBridgeUseEntertainment(unsigned int bridge_idx);
|
||||
|
||||
bool BridgeHasUsername(unsigned int bridge_idx);
|
||||
bool BridgeHasClientKey(unsigned int bridge_idx);
|
||||
|
||||
void SetBridgeUsername(unsigned int bridge_idx, std::string username);
|
||||
void SetBridgeClientKey(unsigned int bridge_idx, std::string clientkey);
|
||||
void SetBridgeAutoconnect(unsigned int bridge_ip, bool auto_connect);
|
||||
void SetBridgeUseEntertainment(unsigned int bridge_idx, bool use_entertainment);
|
||||
|
||||
void SaveSettings();
|
||||
|
||||
private:
|
||||
void * hue_settings;
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue