mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
refactor: Led layout, clearAll (#703)
* add SSDP name field * YALL - yet another led layout * led layout migration * add initial vscode config * merge clearAll with clear, rename Hyperion::compStateChange * simpler components api * Corrected code formatting + triggered PR build * fix: regression from #636 * Support for color patterns Co-authored-by: Paulchen Panther <16664240+Paulchen-Panther@users.noreply.github.com>
This commit is contained in:
@@ -16,51 +16,20 @@ ComponentRegister::ComponentRegister(Hyperion* hyperion)
|
||||
{
|
||||
_componentStates.emplace(e, ((e == COMP_ALL) ? true : false));
|
||||
}
|
||||
|
||||
connect(_hyperion, &Hyperion::compStateChangeRequest, this, &ComponentRegister::handleCompStateChangeRequest);
|
||||
}
|
||||
|
||||
ComponentRegister::~ComponentRegister()
|
||||
{
|
||||
}
|
||||
|
||||
bool ComponentRegister::setHyperionEnable(const bool& state)
|
||||
{
|
||||
if(!state && _prevComponentStates.empty())
|
||||
{
|
||||
Debug(_log,"Disable Hyperion, store current component states");
|
||||
for(const auto comp : _componentStates)
|
||||
{
|
||||
// save state
|
||||
_prevComponentStates.emplace(comp.first, comp.second);
|
||||
// disable if enabled
|
||||
if(comp.second)
|
||||
_hyperion->setComponentState(comp.first, false);
|
||||
}
|
||||
componentStateChanged(COMP_ALL, false);
|
||||
return true;
|
||||
}
|
||||
else if(state && !_prevComponentStates.empty())
|
||||
{
|
||||
Debug(_log,"Enable Hyperion, recover previous component states");
|
||||
for(const auto comp : _prevComponentStates)
|
||||
{
|
||||
// if comp was enabled, enable again
|
||||
if(comp.second)
|
||||
_hyperion->setComponentState(comp.first, true);
|
||||
|
||||
}
|
||||
_prevComponentStates.clear();
|
||||
componentStateChanged(COMP_ALL, true);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int ComponentRegister::isComponentEnabled(const hyperion::Components& comp) const
|
||||
{
|
||||
return (_componentStates.count(comp)) ? _componentStates.at(comp) : -1;
|
||||
}
|
||||
|
||||
void ComponentRegister::componentStateChanged(const hyperion::Components comp, const bool activated)
|
||||
void ComponentRegister::setNewComponentState(const hyperion::Components comp, const bool activated)
|
||||
{
|
||||
if(_componentStates[comp] != activated)
|
||||
{
|
||||
@@ -70,3 +39,38 @@ void ComponentRegister::componentStateChanged(const hyperion::Components comp, c
|
||||
emit updatedComponentState(comp, activated);
|
||||
}
|
||||
}
|
||||
|
||||
void ComponentRegister::handleCompStateChangeRequest(const hyperion::Components comp, const bool activated)
|
||||
{
|
||||
if(comp == COMP_ALL && !_inProgress)
|
||||
{
|
||||
_inProgress = true;
|
||||
if(!activated && _prevComponentStates.empty())
|
||||
{
|
||||
Debug(_log,"Disable Hyperion, store current component states");
|
||||
for(const auto comp : _componentStates)
|
||||
{
|
||||
// save state
|
||||
_prevComponentStates.emplace(comp.first, comp.second);
|
||||
// disable if enabled
|
||||
if(comp.second)
|
||||
emit _hyperion->compStateChangeRequest(comp.first, false);
|
||||
}
|
||||
setNewComponentState(COMP_ALL, false);
|
||||
}
|
||||
else if(activated && !_prevComponentStates.empty())
|
||||
{
|
||||
Debug(_log,"Enable Hyperion, recover previous component states");
|
||||
for(const auto comp : _prevComponentStates)
|
||||
{
|
||||
// if comp was enabled, enable again
|
||||
if(comp.second)
|
||||
emit _hyperion->compStateChangeRequest(comp.first, true);
|
||||
|
||||
}
|
||||
_prevComponentStates.clear();
|
||||
setNewComponentState(COMP_ALL, true);
|
||||
}
|
||||
_inProgress = false;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user