mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
clear and clear all implemented
This commit is contained in:
parent
638d5aa424
commit
1766212b70
@ -29,7 +29,13 @@ public:
|
|||||||
|
|
||||||
unsigned getLedCount() const;
|
unsigned getLedCount() const;
|
||||||
|
|
||||||
void setValue(int priority, std::vector<RgbColor> &ledColors, const int timeout_ms);
|
void setColor(int priority, RgbColor &ledColor, const int timeout_ms);
|
||||||
|
|
||||||
|
void setColors(int priority, std::vector<RgbColor> &ledColors, const int timeout_ms);
|
||||||
|
|
||||||
|
void clear(int priority);
|
||||||
|
|
||||||
|
void clearall();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void update();
|
void update();
|
||||||
@ -37,15 +43,15 @@ private slots:
|
|||||||
private:
|
private:
|
||||||
void applyTransform(std::vector<RgbColor>& colors) const;
|
void applyTransform(std::vector<RgbColor>& colors) const;
|
||||||
|
|
||||||
LedString mLedString;
|
LedString _ledString;
|
||||||
|
|
||||||
PriorityMuxer mMuxer;
|
PriorityMuxer _muxer;
|
||||||
|
|
||||||
hyperion::ColorTransform* mRedTransform;
|
hyperion::ColorTransform* _redTransform;
|
||||||
hyperion::ColorTransform* mGreenTransform;
|
hyperion::ColorTransform* _greenTransform;
|
||||||
hyperion::ColorTransform* mBlueTransform;
|
hyperion::ColorTransform* _blueTransform;
|
||||||
|
|
||||||
LedDevice* mDevice;
|
LedDevice* _device;
|
||||||
|
|
||||||
QTimer _timer;
|
QTimer _timer;
|
||||||
};
|
};
|
||||||
|
@ -26,7 +26,7 @@ public:
|
|||||||
std::vector<RgbColor> ledColors;
|
std::vector<RgbColor> ledColors;
|
||||||
};
|
};
|
||||||
|
|
||||||
PriorityMuxer();
|
PriorityMuxer(int ledCount);
|
||||||
|
|
||||||
~PriorityMuxer();
|
~PriorityMuxer();
|
||||||
|
|
||||||
@ -47,9 +47,11 @@ public:
|
|||||||
void setCurrentTime(const int64_t& now);
|
void setCurrentTime(const int64_t& now);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int mCurrentPriority;
|
int _currentPriority;
|
||||||
|
|
||||||
QMap<int, InputInfo> mActiveInputs;
|
QMap<int, InputInfo> _activeInputs;
|
||||||
|
|
||||||
const static int MAX_PRIORITY = std::numeric_limits<int>::max();
|
InputInfo _lowestPriorityInfo;
|
||||||
|
|
||||||
|
const static int LOWEST_PRIORITY = std::numeric_limits<int>::max();
|
||||||
};
|
};
|
||||||
|
@ -53,7 +53,7 @@ void DispmanxWrapper::action()
|
|||||||
|
|
||||||
_processor->process(_image, _ledColors);
|
_processor->process(_image, _ledColors);
|
||||||
|
|
||||||
_hyperion->setValue(_priority, _ledColors, _timeout_ms);
|
_hyperion->setColors(_priority, _ledColors, _timeout_ms);
|
||||||
}
|
}
|
||||||
void DispmanxWrapper::stop()
|
void DispmanxWrapper::stop()
|
||||||
{
|
{
|
||||||
|
@ -76,74 +76,108 @@ LedString Hyperion::createLedString(const Json::Value& ledsConfig)
|
|||||||
}
|
}
|
||||||
|
|
||||||
Hyperion::Hyperion(const Json::Value &jsonConfig) :
|
Hyperion::Hyperion(const Json::Value &jsonConfig) :
|
||||||
mLedString(createLedString(jsonConfig["leds"])),
|
_ledString(createLedString(jsonConfig["leds"])),
|
||||||
mRedTransform( createColorTransform(jsonConfig["color"]["red"])),
|
_muxer(_ledString.leds().size()),
|
||||||
mGreenTransform(createColorTransform(jsonConfig["color"]["green"])),
|
_redTransform(createColorTransform(jsonConfig["color"]["red"])),
|
||||||
mBlueTransform( createColorTransform(jsonConfig["color"]["blue"])),
|
_greenTransform(createColorTransform(jsonConfig["color"]["green"])),
|
||||||
mDevice(constructDevice(jsonConfig["device"])),
|
_blueTransform(createColorTransform(jsonConfig["color"]["blue"])),
|
||||||
|
_device(constructDevice(jsonConfig["device"])),
|
||||||
_timer()
|
_timer()
|
||||||
{
|
{
|
||||||
ImageProcessorFactory::getInstance().init(mLedString);
|
ImageProcessorFactory::getInstance().init(_ledString);
|
||||||
|
|
||||||
_timer.setSingleShot(true);
|
_timer.setSingleShot(true);
|
||||||
QObject::connect(&_timer, SIGNAL(timeout()), this, SLOT(update()));
|
QObject::connect(&_timer, SIGNAL(timeout()), this, SLOT(update()));
|
||||||
|
|
||||||
|
// initialize the leds
|
||||||
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Hyperion::~Hyperion()
|
Hyperion::~Hyperion()
|
||||||
{
|
{
|
||||||
// Delete the Led-String
|
// Delete the Led-String
|
||||||
delete mDevice;
|
delete _device;
|
||||||
|
|
||||||
// Delete the color-transform
|
// Delete the color-transform
|
||||||
delete mBlueTransform;
|
delete _blueTransform;
|
||||||
delete mGreenTransform;
|
delete _greenTransform;
|
||||||
delete mRedTransform;
|
delete _redTransform;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned Hyperion::getLedCount() const
|
unsigned Hyperion::getLedCount() const
|
||||||
{
|
{
|
||||||
return mLedString.leds().size();
|
return _ledString.leds().size();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Hyperion::setValue(int priority, std::vector<RgbColor>& ledColors, const int timeout_ms)
|
void Hyperion::setColor(int priority, RgbColor & color, const int timeout_ms)
|
||||||
|
{
|
||||||
|
// create led output
|
||||||
|
std::vector<RgbColor> ledColors(_ledString.leds().size(), color);
|
||||||
|
|
||||||
|
// set colors
|
||||||
|
setColors(priority, ledColors, timeout_ms);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Hyperion::setColors(int priority, std::vector<RgbColor>& ledColors, const int timeout_ms)
|
||||||
{
|
{
|
||||||
// Apply the transform to each led and color-channel
|
// Apply the transform to each led and color-channel
|
||||||
for (RgbColor& color : ledColors)
|
for (RgbColor& color : ledColors)
|
||||||
{
|
{
|
||||||
color.red = mRedTransform->transform(color.red);
|
color.red = _redTransform->transform(color.red);
|
||||||
color.green = mGreenTransform->transform(color.green);
|
color.green = _greenTransform->transform(color.green);
|
||||||
color.blue = mBlueTransform->transform(color.blue);
|
color.blue = _blueTransform->transform(color.blue);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (timeout_ms > 0)
|
if (timeout_ms > 0)
|
||||||
{
|
{
|
||||||
const uint64_t timeoutTime = QDateTime::currentMSecsSinceEpoch() + timeout_ms;
|
const uint64_t timeoutTime = QDateTime::currentMSecsSinceEpoch() + timeout_ms;
|
||||||
mMuxer.setInput(priority, ledColors, timeoutTime);
|
_muxer.setInput(priority, ledColors, timeoutTime);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mMuxer.setInput(priority, ledColors);
|
_muxer.setInput(priority, ledColors);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (priority == mMuxer.getCurrentPriority())
|
if (priority == _muxer.getCurrentPriority())
|
||||||
{
|
{
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Hyperion::clear(int priority)
|
||||||
|
{
|
||||||
|
if (_muxer.hasPriority(priority))
|
||||||
|
{
|
||||||
|
_muxer.clearInput(priority);
|
||||||
|
|
||||||
|
// update leds if necessary
|
||||||
|
if (priority < _muxer.getCurrentPriority());
|
||||||
|
{
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Hyperion::clearall()
|
||||||
|
{
|
||||||
|
_muxer.clearAll();
|
||||||
|
|
||||||
|
// update leds
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
void Hyperion::update()
|
void Hyperion::update()
|
||||||
{
|
{
|
||||||
// Update the muxer, cleaning obsolete priorities
|
// Update the muxer, cleaning obsolete priorities
|
||||||
mMuxer.setCurrentTime(QDateTime::currentMSecsSinceEpoch());
|
_muxer.setCurrentTime(QDateTime::currentMSecsSinceEpoch());
|
||||||
|
|
||||||
// Obtain the current priority channel
|
// Obtain the current priority channel
|
||||||
int priority = mMuxer.getCurrentPriority();
|
int priority = _muxer.getCurrentPriority();
|
||||||
const PriorityMuxer::InputInfo & priorityInfo = mMuxer.getInputInfo(priority);
|
const PriorityMuxer::InputInfo & priorityInfo = _muxer.getInputInfo(priority);
|
||||||
|
|
||||||
// Write the data to the device
|
// Write the data to the device
|
||||||
mDevice->write(priorityInfo.ledColors);
|
_device->write(priorityInfo.ledColors);
|
||||||
|
|
||||||
// Start the timeout-timer
|
// Start the timeout-timer
|
||||||
if (priorityInfo.timeoutTime_ms == -1)
|
if (priorityInfo.timeoutTime_ms == -1)
|
||||||
|
@ -6,10 +6,14 @@
|
|||||||
// Hyperion includes
|
// Hyperion includes
|
||||||
#include <hyperion/PriorityMuxer.h>
|
#include <hyperion/PriorityMuxer.h>
|
||||||
|
|
||||||
PriorityMuxer::PriorityMuxer() :
|
PriorityMuxer::PriorityMuxer(int ledCount) :
|
||||||
mCurrentPriority(MAX_PRIORITY)
|
_currentPriority(LOWEST_PRIORITY),
|
||||||
|
_activeInputs(),
|
||||||
|
_lowestPriorityInfo()
|
||||||
{
|
{
|
||||||
// empty
|
_lowestPriorityInfo.priority = LOWEST_PRIORITY;
|
||||||
|
_lowestPriorityInfo.timeoutTime_ms = -1;
|
||||||
|
_lowestPriorityInfo.ledColors = std::vector<RgbColor>(ledCount, {0, 0, 0});
|
||||||
}
|
}
|
||||||
|
|
||||||
PriorityMuxer::~PriorityMuxer()
|
PriorityMuxer::~PriorityMuxer()
|
||||||
@ -19,23 +23,28 @@ PriorityMuxer::~PriorityMuxer()
|
|||||||
|
|
||||||
int PriorityMuxer::getCurrentPriority() const
|
int PriorityMuxer::getCurrentPriority() const
|
||||||
{
|
{
|
||||||
return mCurrentPriority;
|
return _currentPriority;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<int> PriorityMuxer::getPriorities() const
|
QList<int> PriorityMuxer::getPriorities() const
|
||||||
{
|
{
|
||||||
return mActiveInputs.keys();
|
return _activeInputs.keys();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PriorityMuxer::hasPriority(const int priority) const
|
bool PriorityMuxer::hasPriority(const int priority) const
|
||||||
{
|
{
|
||||||
return mActiveInputs.contains(priority);
|
return _activeInputs.contains(priority);
|
||||||
}
|
}
|
||||||
|
|
||||||
const PriorityMuxer::InputInfo& PriorityMuxer::getInputInfo(const int priority) const
|
const PriorityMuxer::InputInfo& PriorityMuxer::getInputInfo(const int priority) const
|
||||||
{
|
{
|
||||||
auto elemIt = mActiveInputs.find(priority);
|
if (priority == LOWEST_PRIORITY)
|
||||||
if (elemIt == mActiveInputs.end())
|
{
|
||||||
|
return _lowestPriorityInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto elemIt = _activeInputs.find(priority);
|
||||||
|
if (elemIt == _activeInputs.end())
|
||||||
{
|
{
|
||||||
throw std::runtime_error("no such priority");
|
throw std::runtime_error("no such priority");
|
||||||
}
|
}
|
||||||
@ -44,50 +53,50 @@ const PriorityMuxer::InputInfo& PriorityMuxer::getInputInfo(const int priority)
|
|||||||
|
|
||||||
void PriorityMuxer::setInput(const int priority, const std::vector<RgbColor>& ledColors, const int64_t timeoutTime_ms)
|
void PriorityMuxer::setInput(const int priority, const std::vector<RgbColor>& ledColors, const int64_t timeoutTime_ms)
|
||||||
{
|
{
|
||||||
InputInfo& input = mActiveInputs[priority];
|
InputInfo& input = _activeInputs[priority];
|
||||||
input.priority = priority;
|
input.priority = priority;
|
||||||
input.timeoutTime_ms = timeoutTime_ms;
|
input.timeoutTime_ms = timeoutTime_ms;
|
||||||
input.ledColors = ledColors;
|
input.ledColors = ledColors;
|
||||||
|
|
||||||
mCurrentPriority = std::min(mCurrentPriority, priority);
|
_currentPriority = std::min(_currentPriority, priority);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PriorityMuxer::clearInput(const int priority)
|
void PriorityMuxer::clearInput(const int priority)
|
||||||
{
|
{
|
||||||
mActiveInputs.remove(priority);
|
_activeInputs.remove(priority);
|
||||||
if (mCurrentPriority == priority)
|
if (_currentPriority == priority)
|
||||||
{
|
{
|
||||||
if (mActiveInputs.empty())
|
if (_activeInputs.empty())
|
||||||
{
|
{
|
||||||
mCurrentPriority = MAX_PRIORITY;
|
_currentPriority = LOWEST_PRIORITY;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
QList<int> keys = mActiveInputs.keys();
|
QList<int> keys = _activeInputs.keys();
|
||||||
mCurrentPriority = *std::min_element(keys.begin(), keys.end());
|
_currentPriority = *std::min_element(keys.begin(), keys.end());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PriorityMuxer::clearAll()
|
void PriorityMuxer::clearAll()
|
||||||
{
|
{
|
||||||
mActiveInputs.clear();
|
_activeInputs.clear();
|
||||||
mCurrentPriority = MAX_PRIORITY;
|
_currentPriority = LOWEST_PRIORITY;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PriorityMuxer::setCurrentTime(const int64_t& now)
|
void PriorityMuxer::setCurrentTime(const int64_t& now)
|
||||||
{
|
{
|
||||||
mCurrentPriority = MAX_PRIORITY;
|
_currentPriority = LOWEST_PRIORITY;
|
||||||
|
|
||||||
for (auto infoIt = mActiveInputs.begin(); infoIt != mActiveInputs.end();)
|
for (auto infoIt = _activeInputs.begin(); infoIt != _activeInputs.end();)
|
||||||
{
|
{
|
||||||
if (infoIt->timeoutTime_ms != -1 && infoIt->timeoutTime_ms <= now)
|
if (infoIt->timeoutTime_ms != -1 && infoIt->timeoutTime_ms <= now)
|
||||||
{
|
{
|
||||||
infoIt = mActiveInputs.erase(infoIt);
|
infoIt = _activeInputs.erase(infoIt);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mCurrentPriority = std::min(mCurrentPriority, infoIt->priority);
|
_currentPriority = std::min(_currentPriority, infoIt->priority);
|
||||||
++infoIt;
|
++infoIt;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -76,7 +76,7 @@ void JsonClientConnection::handleMessage(const std::string &messageString)
|
|||||||
|
|
||||||
// check specific message
|
// check specific message
|
||||||
const std::string command = message["command"].asString();
|
const std::string command = message["command"].asString();
|
||||||
if (!checkJson(message, QString("schema-%1").arg(QString::fromStdString(command)), errors))
|
if (!checkJson(message, QString(":schema-%1").arg(QString::fromStdString(command)), errors))
|
||||||
{
|
{
|
||||||
sendErrorReply("Error while validating json: " + errors);
|
sendErrorReply("Error while validating json: " + errors);
|
||||||
return;
|
return;
|
||||||
@ -104,14 +104,10 @@ void JsonClientConnection::handleColorCommand(const Json::Value &message)
|
|||||||
// extract parameters
|
// extract parameters
|
||||||
int priority = message["priority"].asInt();
|
int priority = message["priority"].asInt();
|
||||||
int duration = message.get("duration", -1).asInt();
|
int duration = message.get("duration", -1).asInt();
|
||||||
RgbColor color = {message["color"][0u].asInt(), message["color"][1u].asInt(), message["color"][2u].asInt()};
|
RgbColor color = {uint8_t(message["color"][0u].asInt()), uint8_t(message["color"][1u].asInt()), uint8_t(message["color"][2u].asInt())};
|
||||||
|
|
||||||
|
|
||||||
// create led output
|
|
||||||
std::vector<RgbColor> ledColors(_hyperion->getLedCount(), color);
|
|
||||||
|
|
||||||
// set output
|
// set output
|
||||||
_hyperion->setValue(priority, ledColors, duration);
|
_hyperion->setColor(priority, color, duration);
|
||||||
|
|
||||||
// send reply
|
// send reply
|
||||||
sendSuccessReply();
|
sendSuccessReply();
|
||||||
@ -129,12 +125,23 @@ void JsonClientConnection::handleServerInfoCommand(const Json::Value &message)
|
|||||||
|
|
||||||
void JsonClientConnection::handleClearCommand(const Json::Value &message)
|
void JsonClientConnection::handleClearCommand(const Json::Value &message)
|
||||||
{
|
{
|
||||||
handleNotImplemented();
|
// extract parameters
|
||||||
|
int priority = message["priority"].asInt();
|
||||||
|
|
||||||
|
// clear priority
|
||||||
|
_hyperion->clear(priority);
|
||||||
|
|
||||||
|
// send reply
|
||||||
|
sendSuccessReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
void JsonClientConnection::handleClearallCommand(const Json::Value &message)
|
void JsonClientConnection::handleClearallCommand(const Json::Value &)
|
||||||
{
|
{
|
||||||
handleNotImplemented();
|
// clear priority
|
||||||
|
_hyperion->clearall();
|
||||||
|
|
||||||
|
// send reply
|
||||||
|
sendSuccessReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
void JsonClientConnection::handleTransformCommand(const Json::Value &message)
|
void JsonClientConnection::handleTransformCommand(const Json::Value &message)
|
||||||
|
@ -44,7 +44,7 @@ int main(int argc, char * argv[])
|
|||||||
ImageParameter & argImage = parameters.add<ImageParameter> ('i', "image" , "Set the leds to the colors according to the given image file");
|
ImageParameter & argImage = parameters.add<ImageParameter> ('i', "image" , "Set the leds to the colors according to the given image file");
|
||||||
SwitchParameter<> & argServerInfo = parameters.add<SwitchParameter<> >('s', "info" , "List server info");
|
SwitchParameter<> & argServerInfo = parameters.add<SwitchParameter<> >('s', "info" , "List server info");
|
||||||
SwitchParameter<> & argClear = parameters.add<SwitchParameter<> >('x', "clear" , "Clear data for the priority channel provided by the -p option");
|
SwitchParameter<> & argClear = parameters.add<SwitchParameter<> >('x', "clear" , "Clear data for the priority channel provided by the -p option");
|
||||||
SwitchParameter<> & argClearAll = parameters.add<SwitchParameter<> >(0x0, "clear-all" , "Clear data for all priority channels");
|
SwitchParameter<> & argClearAll = parameters.add<SwitchParameter<> >(0x0, "clearall" , "Clear data for all active priority channels");
|
||||||
TransformParameter & argGamma = parameters.add<TransformParameter>('g', "gamma" , "Set the gamma of the leds (requires 3 space seperated values)");
|
TransformParameter & argGamma = parameters.add<TransformParameter>('g', "gamma" , "Set the gamma of the leds (requires 3 space seperated values)");
|
||||||
TransformParameter & argThreshold = parameters.add<TransformParameter>('t', "threshold" , "Set the threshold of the leds (requires 3 space seperated values between 0.0 and 1.0)");
|
TransformParameter & argThreshold = parameters.add<TransformParameter>('t', "threshold" , "Set the threshold of the leds (requires 3 space seperated values between 0.0 and 1.0)");
|
||||||
TransformParameter & argBlacklevel = parameters.add<TransformParameter>('b', "blacklevel", "Set the blacklevel of the leds (requires 3 space seperated values which are normally between 0.0 and 1.0)");
|
TransformParameter & argBlacklevel = parameters.add<TransformParameter>('b', "blacklevel", "Set the blacklevel of the leds (requires 3 space seperated values which are normally between 0.0 and 1.0)");
|
||||||
|
Loading…
Reference in New Issue
Block a user