mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
817dabae8c
* add --sourceOff to hyperion-remote - this will select "off" source and set all leds to black refactor new json stuff make schema checker not so strict, do not require values that have defaults (not finished yet) initialEffect config: effect is always an array, regardless if it is a color or an effect name * make off source visible in active priority list * transform initialeffect to qjson (except part of effect-args, this needs effectengine transformed to qjson) * remove unneeded comment * add web ui for source selection. call http://hyperion_host:8099/select/index.html current example needed json server on port 19444
98 lines
2.2 KiB
C++
98 lines
2.2 KiB
C++
|
|
// STL includes
|
|
#include <algorithm>
|
|
#include <stdexcept>
|
|
|
|
// Hyperion includes
|
|
#include <hyperion/PriorityMuxer.h>
|
|
|
|
PriorityMuxer::PriorityMuxer(int ledCount)
|
|
: _currentPriority(LOWEST_PRIORITY)
|
|
, _activeInputs()
|
|
, _lowestPriorityInfo()
|
|
{
|
|
_lowestPriorityInfo.priority = LOWEST_PRIORITY;
|
|
_lowestPriorityInfo.timeoutTime_ms = -1;
|
|
_lowestPriorityInfo.ledColors = std::vector<ColorRgb>(ledCount, {0, 0, 0});
|
|
|
|
_activeInputs[_currentPriority] = _lowestPriorityInfo;
|
|
}
|
|
|
|
PriorityMuxer::~PriorityMuxer()
|
|
{
|
|
// empty
|
|
}
|
|
|
|
int PriorityMuxer::getCurrentPriority() const
|
|
{
|
|
return _currentPriority;
|
|
}
|
|
|
|
QList<int> PriorityMuxer::getPriorities() const
|
|
{
|
|
return _activeInputs.keys();
|
|
}
|
|
|
|
bool PriorityMuxer::hasPriority(const int priority) const
|
|
{
|
|
return (priority == LOWEST_PRIORITY) ? true : _activeInputs.contains(priority);
|
|
}
|
|
|
|
const PriorityMuxer::InputInfo& PriorityMuxer::getInputInfo(const int priority) const
|
|
{
|
|
auto elemIt = _activeInputs.find(priority);
|
|
if (elemIt == _activeInputs.end())
|
|
{
|
|
throw std::runtime_error("HYPERION (prioritymuxer) ERROR: no such priority");
|
|
}
|
|
return elemIt.value();
|
|
}
|
|
|
|
void PriorityMuxer::setInput(const int priority, const std::vector<ColorRgb>& ledColors, const int64_t timeoutTime_ms)
|
|
{
|
|
InputInfo& input = _activeInputs[priority];
|
|
input.priority = priority;
|
|
input.timeoutTime_ms = timeoutTime_ms;
|
|
input.ledColors = ledColors;
|
|
|
|
_currentPriority = std::min(_currentPriority, priority);
|
|
}
|
|
|
|
void PriorityMuxer::clearInput(const int priority)
|
|
{
|
|
if (priority < LOWEST_PRIORITY)
|
|
{
|
|
_activeInputs.remove(priority);
|
|
if (_currentPriority == priority)
|
|
{
|
|
QList<int> keys = _activeInputs.keys();
|
|
_currentPriority = *std::min_element(keys.begin(), keys.end());
|
|
}
|
|
}
|
|
}
|
|
|
|
void PriorityMuxer::clearAll()
|
|
{
|
|
_activeInputs.clear();
|
|
_currentPriority = LOWEST_PRIORITY;
|
|
_activeInputs[_currentPriority] = _lowestPriorityInfo;
|
|
}
|
|
|
|
void PriorityMuxer::setCurrentTime(const int64_t& now)
|
|
{
|
|
_currentPriority = LOWEST_PRIORITY;
|
|
|
|
for (auto infoIt = _activeInputs.begin(); infoIt != _activeInputs.end();)
|
|
{
|
|
if (infoIt->timeoutTime_ms != -1 && infoIt->timeoutTime_ms <= now)
|
|
{
|
|
infoIt = _activeInputs.erase(infoIt);
|
|
}
|
|
else
|
|
{
|
|
_currentPriority = std::min(_currentPriority, infoIt->priority);
|
|
++infoIt;
|
|
}
|
|
}
|
|
}
|