hyperion.ng/libsrc/hyperion/Hyperion.cpp

640 lines
18 KiB
C++
Raw Normal View History

// STL includes
#include <exception>
#include <sstream>
// QT includes
#include <QString>
#include <QStringList>
#include <QThread>
// hyperion include
#include <hyperion/Hyperion.h>
2018-12-27 23:11:32 +01:00
#include <hyperion/MessageForwarder.h>
#include <hyperion/ImageProcessor.h>
#include <hyperion/ColorAdjustment.h>
2018-12-27 23:11:32 +01:00
// utils
#include <utils/hyperion.h>
#include <utils/GlobalSignals.h>
2020-08-02 10:44:42 +02:00
#include <utils/Logger.h>
2018-12-27 23:11:32 +01:00
// Leddevice includes
#include <leddevice/LedDeviceWrapper.h>
2018-12-27 23:11:32 +01:00
#include <hyperion/MultiColorAdjustment.h>
#include "LinearColorSmoothing.h"
// effect engine includes
#include <effectengine/EffectEngine.h>
2018-12-27 23:11:32 +01:00
// settingsManagaer
#include <hyperion/SettingsManager.h>
// BGEffectHandler
#include <hyperion/BGEffectHandler.h>
// CaptureControl (Daemon capture)
#include <hyperion/CaptureCont.h>
// Boblight
#include <boblightserver/BoblightServer.h>
2020-08-08 13:09:15 +02:00
Hyperion::Hyperion(quint8 instance)
: QObject()
, _instIndex(instance)
, _settingsManager(new SettingsManager(instance, this))
2018-12-27 23:11:32 +01:00
, _componentRegister(this)
, _ledString(hyperion::createLedString(getSetting(settings::LEDS).array(), hyperion::createColorOrder(getSetting(settings::DEVICE).object())))
, _imageProcessor(new ImageProcessor(_ledString, this))
, _muxer(_ledString.leds().size(), this)
2018-12-27 23:11:32 +01:00
, _raw2ledAdjustment(hyperion::createLedColorsAdjustment(_ledString.leds().size(), getSetting(settings::COLOR).object()))
, _effectEngine(nullptr)
, _messageForwarder(nullptr)
2018-12-27 23:11:32 +01:00
, _log(Logger::getInstance("HYPERION"))
, _hwLedCount()
, _ledGridSize(hyperion::getLedLayoutGridSize(getSetting(settings::LEDS).array()))
, _ledBuffer(_ledString.leds().size(), ColorRgb::BLACK)
{
}
Hyperion::~Hyperion()
{
freeObjects();
}
void Hyperion::start()
{
// forward settings changed to Hyperion
connect(_settingsManager, &SettingsManager::settingsChanged, this, &Hyperion::settingsChanged);
// get newVideoMode from HyperionIManager
connect(this, &Hyperion::newVideoMode, this, &Hyperion::handleNewVideoMode);
if (!_raw2ledAdjustment->verifyAdjustments())
{
2018-12-27 23:11:32 +01:00
Warning(_log, "At least one led has no color calibration, please add all leds from your led layout to an 'LED index' field!");
}
2018-12-27 23:11:32 +01:00
// handle hwLedCount
_hwLedCount = qMax(unsigned(getSetting(settings::DEVICE).object()["hardwareLedCount"].toInt(getLedCount())), getLedCount());
2018-12-27 23:11:32 +01:00
// init colororder vector
2020-08-02 10:44:42 +02:00
for (const Led& led : _ledString.leds())
2018-12-27 23:11:32 +01:00
{
_ledStringColorOrder.push_back(led.colorOrder);
}
// connect Hyperion::update with Muxer visible priority changes as muxer updates independent
connect(&_muxer, &PriorityMuxer::visiblePriorityChanged, this, &Hyperion::update);
connect(&_muxer, &PriorityMuxer::visiblePriorityChanged, this, &Hyperion::handlePriorityChangedLedDevice);
connect(&_muxer, &PriorityMuxer::visibleComponentChanged, this, &Hyperion::handleVisibleComponentChanged);
2018-12-27 23:11:32 +01:00
// listens for ComponentRegister changes of COMP_ALL to perform core enable/disable actions
// connect(&_componentRegister, &ComponentRegister::updatedComponentState, this, &Hyperion::updatedComponentState);
2018-12-27 23:11:32 +01:00
// listen for settings updates of this instance (LEDS & COLOR)
connect(_settingsManager, &SettingsManager::settingsChanged, this, &Hyperion::handleSettingsUpdate);
2018-12-27 23:11:32 +01:00
// set color correction activity state
const QJsonObject color = getSetting(settings::COLOR).object();
2018-12-27 23:11:32 +01:00
// initialize leddevices
QJsonObject ledDevice = getSetting(settings::DEVICE).object();
2018-12-27 23:11:32 +01:00
ledDevice["currentLedCount"] = int(_hwLedCount); // Inject led count info
_ledDeviceWrapper = new LedDeviceWrapper(this);
connect(this, &Hyperion::compStateChangeRequest, _ledDeviceWrapper, &LedDeviceWrapper::handleComponentState);
Disentangle LedDevice/LinearColorSmoothing, Bug Fixes & Test support (#654) * Handle Exceptions in main & Pythoninit * Have SSDPDiscover generic again * Have SSDPDiscover generic again * Change Info- to Debug logs as technical service messages * Nanoleaf - When switched on, ensure UDP mode * Include SQL Database in Cross-Compile instructions * Fix Clazy (QT code checker) and clang Warnings * Stop LedDevice:write for disabled device * Nanoleaf: Fix uint printfs * NanoLeaf: Fix indents to tabs * NanoLeaf - Add debug verbosity switches * Device switchability support, FileDevice with timestamp support * Nanoleaf Light Panels now support External Control V2 * Enhance LedDeviceFile by Timestamp + fix readyness * Stop color stream, if LedDevice disabled * Nanoleaf - remove switchability * Fix MultiColorAdjustment, if led-range is greater lednum * Fix logging * LedFileDevice/LedDevice - add testing support * New "Led Test" effect * LedDeviceFile - Add chrono include + Allow Led rewrites for testing * Stabilize Effects for LedDevices where latchtime = 0 * Update LedDeviceFile, allow latchtime = 0 * Distangle LinearColorSmoothing and LEDDevice, Fix Effect configuration updates * Updates LedDeviceFile - Initialize via Open * Updates LedDeviceNanoleaf - Initialize via Open, Remove throwing exceptions * Updates ProviderUDP - Remove throwing exceptions * Framebuffer - Use precise timer * TestSpi - Align to LedDevice updates * Pretty Print CrossCompileHowTo as markdown-file * Ensure that output is only written when LedDevice is ready * Align APA102 Device to new device staging * Logger - Remove clang warnings on extra semicolon * Devices SPI - Align to Device stages and methods * Fix cppcheck and clang findings * Add Code-Template for new Devices * Align devices to stages and methods, clean-up some code * Allow to reopen LedDevice without restart * Revert change "Remove Connect (PriorityMuxer::visiblePriorityChanged -> Hyperion::update) due to double writes" * Remove visiblePriorityChanged from LedDevice to decouple LedDevice from hyperion logic * Expose LedDevice getLedCount and align signedness
2020-02-10 15:21:58 +01:00
connect(this, &Hyperion::ledDeviceData, _ledDeviceWrapper, &LedDeviceWrapper::updateLeds);
_ledDeviceWrapper->createLedDevice(ledDevice);
// smoothing
_deviceSmooth = new LinearColorSmoothing(getSetting(settings::SMOOTHING), this);
connect(this, &Hyperion::settingsChanged, _deviceSmooth, &LinearColorSmoothing::handleSettingsUpdate);
2018-12-27 23:11:32 +01:00
// create the message forwarder only on main instance
if (_instIndex == 0)
_messageForwarder = new MessageForwarder(this);
// create the effect engine; needs to be initialized after smoothing!
2018-12-31 15:48:29 +01:00
_effectEngine = new EffectEngine(this);
2018-12-27 23:11:32 +01:00
connect(_effectEngine, &EffectEngine::effectListUpdated, this, &Hyperion::effectListUpdated);
2018-12-27 23:11:32 +01:00
// initial startup effect
hyperion::handleInitialEffect(this, getSetting(settings::FGEFFECT).object());
2018-12-27 23:11:32 +01:00
// handle background effect
_BGEffectHandler = new BGEffectHandler(this);
2018-12-27 23:11:32 +01:00
// create the Daemon capture interface
_captureCont = new CaptureCont(this);
// forwards global signals to the corresponding slots
connect(GlobalSignals::getInstance(), &GlobalSignals::registerGlobalInput, this, &Hyperion::registerInput);
connect(GlobalSignals::getInstance(), &GlobalSignals::clearGlobalInput, this, &Hyperion::clear);
connect(GlobalSignals::getInstance(), &GlobalSignals::setGlobalColor, this, &Hyperion::setColor);
connect(GlobalSignals::getInstance(), &GlobalSignals::setGlobalImage, this, &Hyperion::setInputImage);
2018-12-27 23:11:32 +01:00
// if there is no startup / background eff and no sending capture interface we probably want to push once BLACK (as PrioMuxer won't emit a prioritiy change)
2013-08-18 13:33:56 +02:00
update();
// boblight, can't live in global scope as it depends on layout
_boblightServer = new BoblightServer(this, getSetting(settings::BOBLSERVER));
connect(this, &Hyperion::settingsChanged, _boblightServer, &BoblightServer::handleSettingsUpdate);
// instance inited, enter thread event loop
emit started();
}
void Hyperion::stop()
{
emit finished();
thread()->wait();
}
void Hyperion::freeObjects()
{
// switch off all leds
clear(-1,true);
// delete components on exit of hyperion core
delete _boblightServer;
2018-12-27 23:11:32 +01:00
delete _captureCont;
delete _effectEngine;
delete _raw2ledAdjustment;
delete _messageForwarder;
2018-12-27 23:11:32 +01:00
delete _settingsManager;
delete _ledDeviceWrapper;
}
2020-08-08 13:09:15 +02:00
void Hyperion::handleSettingsUpdate(settings::type type, const QJsonDocument& config)
{
Disentangle LedDevice/LinearColorSmoothing, Bug Fixes & Test support (#654) * Handle Exceptions in main & Pythoninit * Have SSDPDiscover generic again * Have SSDPDiscover generic again * Change Info- to Debug logs as technical service messages * Nanoleaf - When switched on, ensure UDP mode * Include SQL Database in Cross-Compile instructions * Fix Clazy (QT code checker) and clang Warnings * Stop LedDevice:write for disabled device * Nanoleaf: Fix uint printfs * NanoLeaf: Fix indents to tabs * NanoLeaf - Add debug verbosity switches * Device switchability support, FileDevice with timestamp support * Nanoleaf Light Panels now support External Control V2 * Enhance LedDeviceFile by Timestamp + fix readyness * Stop color stream, if LedDevice disabled * Nanoleaf - remove switchability * Fix MultiColorAdjustment, if led-range is greater lednum * Fix logging * LedFileDevice/LedDevice - add testing support * New "Led Test" effect * LedDeviceFile - Add chrono include + Allow Led rewrites for testing * Stabilize Effects for LedDevices where latchtime = 0 * Update LedDeviceFile, allow latchtime = 0 * Distangle LinearColorSmoothing and LEDDevice, Fix Effect configuration updates * Updates LedDeviceFile - Initialize via Open * Updates LedDeviceNanoleaf - Initialize via Open, Remove throwing exceptions * Updates ProviderUDP - Remove throwing exceptions * Framebuffer - Use precise timer * TestSpi - Align to LedDevice updates * Pretty Print CrossCompileHowTo as markdown-file * Ensure that output is only written when LedDevice is ready * Align APA102 Device to new device staging * Logger - Remove clang warnings on extra semicolon * Devices SPI - Align to Device stages and methods * Fix cppcheck and clang findings * Add Code-Template for new Devices * Align devices to stages and methods, clean-up some code * Allow to reopen LedDevice without restart * Revert change "Remove Connect (PriorityMuxer::visiblePriorityChanged -> Hyperion::update) due to double writes" * Remove visiblePriorityChanged from LedDevice to decouple LedDevice from hyperion logic * Expose LedDevice getLedCount and align signedness
2020-02-10 15:21:58 +01:00
// std::cout << "Hyperion::handleSettingsUpdate" << std::endl;
// std::cout << config.toJson().toStdString() << std::endl;
2018-12-27 23:11:32 +01:00
if(type == settings::COLOR)
{
const QJsonObject obj = config.object();
// change in color recreate ledAdjustments
delete _raw2ledAdjustment;
_raw2ledAdjustment = hyperion::createLedColorsAdjustment(_ledString.leds().size(), obj);
if (!_raw2ledAdjustment->verifyAdjustments())
{
Warning(_log, "At least one led has no color calibration, please add all leds from your led layout to an 'LED index' field!");
}
}
else if(type == settings::LEDS)
{
const QJsonArray leds = config.array();
// stop and cache all running effects, as effects depend heavily on ledlayout
_effectEngine->cacheRunningEffects();
// ledstring, img processor, muxer, ledGridSize (eff engine image based effects), _ledBuffer and ByteOrder of ledstring
2018-12-27 23:11:32 +01:00
_ledString = hyperion::createLedString(leds, hyperion::createColorOrder(getSetting(settings::DEVICE).object()));
_imageProcessor->setLedString(_ledString);
_muxer.updateLedColorsLength(_ledString.leds().size());
_ledGridSize = hyperion::getLedLayoutGridSize(leds);
std::vector<ColorRgb> color(_ledString.leds().size(), ColorRgb{0,0,0});
_ledBuffer = color;
_ledStringColorOrder.clear();
2020-08-02 10:44:42 +02:00
for (const Led& led : _ledString.leds())
2018-12-27 23:11:32 +01:00
{
_ledStringColorOrder.push_back(led.colorOrder);
}
// handle hwLedCount update
_hwLedCount = qMax(unsigned(getSetting(settings::DEVICE).object()["hardwareLedCount"].toInt(getLedCount())), getLedCount());
// change in leds are also reflected in adjustment
delete _raw2ledAdjustment;
_raw2ledAdjustment = hyperion::createLedColorsAdjustment(_ledString.leds().size(), getSetting(settings::COLOR).object());
// start cached effects
_effectEngine->startCachedEffects();
}
else if(type == settings::DEVICE)
{
QJsonObject dev = config.object();
2018-12-27 23:11:32 +01:00
// handle hwLedCount update
_hwLedCount = qMax(unsigned(dev["hardwareLedCount"].toInt(getLedCount())), getLedCount());
// force ledString update, if device ByteOrder changed
if(_ledDeviceWrapper->getColorOrder() != dev["colorOrder"].toString("rgb"))
2018-12-27 23:11:32 +01:00
{
_ledString = hyperion::createLedString(getSetting(settings::LEDS).array(), hyperion::createColorOrder(dev));
_imageProcessor->setLedString(_ledString);
_ledStringColorOrder.clear();
2020-08-02 10:44:42 +02:00
for (const Led& led : _ledString.leds())
{
_ledStringColorOrder.push_back(led.colorOrder);
}
2018-12-27 23:11:32 +01:00
}
// do always reinit until the led devices can handle dynamic changes
2018-12-27 23:11:32 +01:00
dev["currentLedCount"] = int(_hwLedCount); // Inject led count info
_ledDeviceWrapper->createLedDevice(dev);
Disentangle LedDevice/LinearColorSmoothing, Bug Fixes & Test support (#654) * Handle Exceptions in main & Pythoninit * Have SSDPDiscover generic again * Have SSDPDiscover generic again * Change Info- to Debug logs as technical service messages * Nanoleaf - When switched on, ensure UDP mode * Include SQL Database in Cross-Compile instructions * Fix Clazy (QT code checker) and clang Warnings * Stop LedDevice:write for disabled device * Nanoleaf: Fix uint printfs * NanoLeaf: Fix indents to tabs * NanoLeaf - Add debug verbosity switches * Device switchability support, FileDevice with timestamp support * Nanoleaf Light Panels now support External Control V2 * Enhance LedDeviceFile by Timestamp + fix readyness * Stop color stream, if LedDevice disabled * Nanoleaf - remove switchability * Fix MultiColorAdjustment, if led-range is greater lednum * Fix logging * LedFileDevice/LedDevice - add testing support * New "Led Test" effect * LedDeviceFile - Add chrono include + Allow Led rewrites for testing * Stabilize Effects for LedDevices where latchtime = 0 * Update LedDeviceFile, allow latchtime = 0 * Distangle LinearColorSmoothing and LEDDevice, Fix Effect configuration updates * Updates LedDeviceFile - Initialize via Open * Updates LedDeviceNanoleaf - Initialize via Open, Remove throwing exceptions * Updates ProviderUDP - Remove throwing exceptions * Framebuffer - Use precise timer * TestSpi - Align to LedDevice updates * Pretty Print CrossCompileHowTo as markdown-file * Ensure that output is only written when LedDevice is ready * Align APA102 Device to new device staging * Logger - Remove clang warnings on extra semicolon * Devices SPI - Align to Device stages and methods * Fix cppcheck and clang findings * Add Code-Template for new Devices * Align devices to stages and methods, clean-up some code * Allow to reopen LedDevice without restart * Revert change "Remove Connect (PriorityMuxer::visiblePriorityChanged -> Hyperion::update) due to double writes" * Remove visiblePriorityChanged from LedDevice to decouple LedDevice from hyperion logic * Expose LedDevice getLedCount and align signedness
2020-02-10 15:21:58 +01:00
// TODO: Check, if framegrabber frequency is lower than latchtime..., if yes, stop
}
else if(type == settings::SMOOTHING)
{
_deviceSmooth->handleSettingsUpdate( type, config);
2018-12-27 23:11:32 +01:00
}
// update once to push single color sets / adjustments/ ledlayout resizes and update ledBuffer color
2018-12-27 23:11:32 +01:00
update();
}
2020-08-08 13:09:15 +02:00
QJsonDocument Hyperion::getSetting(settings::type type) const
2013-08-14 10:54:49 +02:00
{
2018-12-27 23:11:32 +01:00
return _settingsManager->getSetting(type);
2013-08-14 10:54:49 +02:00
}
bool Hyperion::saveSettings(const QJsonObject& config, bool correct)
{
2018-12-27 23:11:32 +01:00
return _settingsManager->saveSettings(config, correct);
}
2018-12-27 23:11:32 +01:00
int Hyperion::getLatchTime() const
{
2020-08-02 10:44:42 +02:00
return _ledDeviceWrapper->getLatchTime();
}
2018-12-27 23:11:32 +01:00
unsigned Hyperion::addSmoothingConfig(int settlingTime_ms, double ledUpdateFrequency_hz, unsigned updateDelay)
{
2018-12-27 23:11:32 +01:00
return _deviceSmooth->addConfig(settlingTime_ms, ledUpdateFrequency_hz, updateDelay);
}
Disentangle LedDevice/LinearColorSmoothing, Bug Fixes & Test support (#654) * Handle Exceptions in main & Pythoninit * Have SSDPDiscover generic again * Have SSDPDiscover generic again * Change Info- to Debug logs as technical service messages * Nanoleaf - When switched on, ensure UDP mode * Include SQL Database in Cross-Compile instructions * Fix Clazy (QT code checker) and clang Warnings * Stop LedDevice:write for disabled device * Nanoleaf: Fix uint printfs * NanoLeaf: Fix indents to tabs * NanoLeaf - Add debug verbosity switches * Device switchability support, FileDevice with timestamp support * Nanoleaf Light Panels now support External Control V2 * Enhance LedDeviceFile by Timestamp + fix readyness * Stop color stream, if LedDevice disabled * Nanoleaf - remove switchability * Fix MultiColorAdjustment, if led-range is greater lednum * Fix logging * LedFileDevice/LedDevice - add testing support * New "Led Test" effect * LedDeviceFile - Add chrono include + Allow Led rewrites for testing * Stabilize Effects for LedDevices where latchtime = 0 * Update LedDeviceFile, allow latchtime = 0 * Distangle LinearColorSmoothing and LEDDevice, Fix Effect configuration updates * Updates LedDeviceFile - Initialize via Open * Updates LedDeviceNanoleaf - Initialize via Open, Remove throwing exceptions * Updates ProviderUDP - Remove throwing exceptions * Framebuffer - Use precise timer * TestSpi - Align to LedDevice updates * Pretty Print CrossCompileHowTo as markdown-file * Ensure that output is only written when LedDevice is ready * Align APA102 Device to new device staging * Logger - Remove clang warnings on extra semicolon * Devices SPI - Align to Device stages and methods * Fix cppcheck and clang findings * Add Code-Template for new Devices * Align devices to stages and methods, clean-up some code * Allow to reopen LedDevice without restart * Revert change "Remove Connect (PriorityMuxer::visiblePriorityChanged -> Hyperion::update) due to double writes" * Remove visiblePriorityChanged from LedDevice to decouple LedDevice from hyperion logic * Expose LedDevice getLedCount and align signedness
2020-02-10 15:21:58 +01:00
unsigned Hyperion::updateSmoothingConfig(unsigned id, int settlingTime_ms, double ledUpdateFrequency_hz, unsigned updateDelay)
{
return _deviceSmooth->updateConfig(id, settlingTime_ms, ledUpdateFrequency_hz, updateDelay);
}
2018-12-27 23:11:32 +01:00
unsigned Hyperion::getLedCount() const
{
2018-12-27 23:11:32 +01:00
return _ledString.leds().size();
}
2020-08-08 13:09:15 +02:00
void Hyperion::setSourceAutoSelect(bool state)
{
_muxer.setSourceAutoSelectEnabled(state);
}
2020-08-08 13:09:15 +02:00
bool Hyperion::setVisiblePriority(int priority)
{
2018-12-27 23:11:32 +01:00
return _muxer.setPriority(priority);
}
bool Hyperion::sourceAutoSelectEnabled() const
2018-12-27 23:11:32 +01:00
{
return _muxer.isSourceAutoSelectEnabled();
}
2020-08-08 13:09:15 +02:00
void Hyperion::setNewComponentState(hyperion::Components component, bool state)
{
_componentRegister.setNewComponentState(component, state);
}
2020-08-02 10:44:42 +02:00
std::map<hyperion::Components, bool> Hyperion::getAllComponents() const
{
return _componentRegister.getRegister();
}
int Hyperion::isComponentEnabled(hyperion::Components comp) const
{
return _componentRegister.isComponentEnabled(comp);
}
2020-08-08 13:09:15 +02:00
void Hyperion::registerInput(int priority, hyperion::Components component, const QString& origin, const QString& owner, unsigned smooth_cfg)
{
2018-12-27 23:11:32 +01:00
_muxer.registerInput(priority, component, origin, owner, smooth_cfg);
2013-08-18 13:33:56 +02:00
}
2020-08-08 13:09:15 +02:00
bool Hyperion::setInput(int priority, const std::vector<ColorRgb>& ledColors, int timeout_ms, bool clearEffect)
{
2018-12-27 23:11:32 +01:00
if(_muxer.setInput(priority, ledColors, timeout_ms))
{
2018-12-27 23:11:32 +01:00
// clear effect if this call does not come from an effect
if(clearEffect)
_effectEngine->channelCleared(priority);
2018-12-27 23:11:32 +01:00
// if this priority is visible, update immediately
if(priority == _muxer.getCurrentPriority())
Disentangle LedDevice/LinearColorSmoothing, Bug Fixes & Test support (#654) * Handle Exceptions in main & Pythoninit * Have SSDPDiscover generic again * Have SSDPDiscover generic again * Change Info- to Debug logs as technical service messages * Nanoleaf - When switched on, ensure UDP mode * Include SQL Database in Cross-Compile instructions * Fix Clazy (QT code checker) and clang Warnings * Stop LedDevice:write for disabled device * Nanoleaf: Fix uint printfs * NanoLeaf: Fix indents to tabs * NanoLeaf - Add debug verbosity switches * Device switchability support, FileDevice with timestamp support * Nanoleaf Light Panels now support External Control V2 * Enhance LedDeviceFile by Timestamp + fix readyness * Stop color stream, if LedDevice disabled * Nanoleaf - remove switchability * Fix MultiColorAdjustment, if led-range is greater lednum * Fix logging * LedFileDevice/LedDevice - add testing support * New "Led Test" effect * LedDeviceFile - Add chrono include + Allow Led rewrites for testing * Stabilize Effects for LedDevices where latchtime = 0 * Update LedDeviceFile, allow latchtime = 0 * Distangle LinearColorSmoothing and LEDDevice, Fix Effect configuration updates * Updates LedDeviceFile - Initialize via Open * Updates LedDeviceNanoleaf - Initialize via Open, Remove throwing exceptions * Updates ProviderUDP - Remove throwing exceptions * Framebuffer - Use precise timer * TestSpi - Align to LedDevice updates * Pretty Print CrossCompileHowTo as markdown-file * Ensure that output is only written when LedDevice is ready * Align APA102 Device to new device staging * Logger - Remove clang warnings on extra semicolon * Devices SPI - Align to Device stages and methods * Fix cppcheck and clang findings * Add Code-Template for new Devices * Align devices to stages and methods, clean-up some code * Allow to reopen LedDevice without restart * Revert change "Remove Connect (PriorityMuxer::visiblePriorityChanged -> Hyperion::update) due to double writes" * Remove visiblePriorityChanged from LedDevice to decouple LedDevice from hyperion logic * Expose LedDevice getLedCount and align signedness
2020-02-10 15:21:58 +01:00
{
2018-12-27 23:11:32 +01:00
update();
Disentangle LedDevice/LinearColorSmoothing, Bug Fixes & Test support (#654) * Handle Exceptions in main & Pythoninit * Have SSDPDiscover generic again * Have SSDPDiscover generic again * Change Info- to Debug logs as technical service messages * Nanoleaf - When switched on, ensure UDP mode * Include SQL Database in Cross-Compile instructions * Fix Clazy (QT code checker) and clang Warnings * Stop LedDevice:write for disabled device * Nanoleaf: Fix uint printfs * NanoLeaf: Fix indents to tabs * NanoLeaf - Add debug verbosity switches * Device switchability support, FileDevice with timestamp support * Nanoleaf Light Panels now support External Control V2 * Enhance LedDeviceFile by Timestamp + fix readyness * Stop color stream, if LedDevice disabled * Nanoleaf - remove switchability * Fix MultiColorAdjustment, if led-range is greater lednum * Fix logging * LedFileDevice/LedDevice - add testing support * New "Led Test" effect * LedDeviceFile - Add chrono include + Allow Led rewrites for testing * Stabilize Effects for LedDevices where latchtime = 0 * Update LedDeviceFile, allow latchtime = 0 * Distangle LinearColorSmoothing and LEDDevice, Fix Effect configuration updates * Updates LedDeviceFile - Initialize via Open * Updates LedDeviceNanoleaf - Initialize via Open, Remove throwing exceptions * Updates ProviderUDP - Remove throwing exceptions * Framebuffer - Use precise timer * TestSpi - Align to LedDevice updates * Pretty Print CrossCompileHowTo as markdown-file * Ensure that output is only written when LedDevice is ready * Align APA102 Device to new device staging * Logger - Remove clang warnings on extra semicolon * Devices SPI - Align to Device stages and methods * Fix cppcheck and clang findings * Add Code-Template for new Devices * Align devices to stages and methods, clean-up some code * Allow to reopen LedDevice without restart * Revert change "Remove Connect (PriorityMuxer::visiblePriorityChanged -> Hyperion::update) due to double writes" * Remove visiblePriorityChanged from LedDevice to decouple LedDevice from hyperion logic * Expose LedDevice getLedCount and align signedness
2020-02-10 15:21:58 +01:00
}
2018-12-27 23:11:32 +01:00
return true;
}
2018-12-27 23:11:32 +01:00
return false;
}
2020-08-08 13:09:15 +02:00
bool Hyperion::setInputImage(int priority, const Image<ColorRgb>& image, int64_t timeout_ms, bool clearEffect)
{
if (!_muxer.hasPriority(priority))
{
emit GlobalSignals::getInstance()->globalRegRequired(priority);
return false;
}
2018-12-27 23:11:32 +01:00
if(_muxer.setInputImage(priority, image, timeout_ms))
{
2018-12-27 23:11:32 +01:00
// clear effect if this call does not come from an effect
if(clearEffect)
_effectEngine->channelCleared(priority);
// if this priority is visible, update immediately
if(priority == _muxer.getCurrentPriority())
Disentangle LedDevice/LinearColorSmoothing, Bug Fixes & Test support (#654) * Handle Exceptions in main & Pythoninit * Have SSDPDiscover generic again * Have SSDPDiscover generic again * Change Info- to Debug logs as technical service messages * Nanoleaf - When switched on, ensure UDP mode * Include SQL Database in Cross-Compile instructions * Fix Clazy (QT code checker) and clang Warnings * Stop LedDevice:write for disabled device * Nanoleaf: Fix uint printfs * NanoLeaf: Fix indents to tabs * NanoLeaf - Add debug verbosity switches * Device switchability support, FileDevice with timestamp support * Nanoleaf Light Panels now support External Control V2 * Enhance LedDeviceFile by Timestamp + fix readyness * Stop color stream, if LedDevice disabled * Nanoleaf - remove switchability * Fix MultiColorAdjustment, if led-range is greater lednum * Fix logging * LedFileDevice/LedDevice - add testing support * New "Led Test" effect * LedDeviceFile - Add chrono include + Allow Led rewrites for testing * Stabilize Effects for LedDevices where latchtime = 0 * Update LedDeviceFile, allow latchtime = 0 * Distangle LinearColorSmoothing and LEDDevice, Fix Effect configuration updates * Updates LedDeviceFile - Initialize via Open * Updates LedDeviceNanoleaf - Initialize via Open, Remove throwing exceptions * Updates ProviderUDP - Remove throwing exceptions * Framebuffer - Use precise timer * TestSpi - Align to LedDevice updates * Pretty Print CrossCompileHowTo as markdown-file * Ensure that output is only written when LedDevice is ready * Align APA102 Device to new device staging * Logger - Remove clang warnings on extra semicolon * Devices SPI - Align to Device stages and methods * Fix cppcheck and clang findings * Add Code-Template for new Devices * Align devices to stages and methods, clean-up some code * Allow to reopen LedDevice without restart * Revert change "Remove Connect (PriorityMuxer::visiblePriorityChanged -> Hyperion::update) due to double writes" * Remove visiblePriorityChanged from LedDevice to decouple LedDevice from hyperion logic * Expose LedDevice getLedCount and align signedness
2020-02-10 15:21:58 +01:00
{
2018-12-27 23:11:32 +01:00
update();
Disentangle LedDevice/LinearColorSmoothing, Bug Fixes & Test support (#654) * Handle Exceptions in main & Pythoninit * Have SSDPDiscover generic again * Have SSDPDiscover generic again * Change Info- to Debug logs as technical service messages * Nanoleaf - When switched on, ensure UDP mode * Include SQL Database in Cross-Compile instructions * Fix Clazy (QT code checker) and clang Warnings * Stop LedDevice:write for disabled device * Nanoleaf: Fix uint printfs * NanoLeaf: Fix indents to tabs * NanoLeaf - Add debug verbosity switches * Device switchability support, FileDevice with timestamp support * Nanoleaf Light Panels now support External Control V2 * Enhance LedDeviceFile by Timestamp + fix readyness * Stop color stream, if LedDevice disabled * Nanoleaf - remove switchability * Fix MultiColorAdjustment, if led-range is greater lednum * Fix logging * LedFileDevice/LedDevice - add testing support * New "Led Test" effect * LedDeviceFile - Add chrono include + Allow Led rewrites for testing * Stabilize Effects for LedDevices where latchtime = 0 * Update LedDeviceFile, allow latchtime = 0 * Distangle LinearColorSmoothing and LEDDevice, Fix Effect configuration updates * Updates LedDeviceFile - Initialize via Open * Updates LedDeviceNanoleaf - Initialize via Open, Remove throwing exceptions * Updates ProviderUDP - Remove throwing exceptions * Framebuffer - Use precise timer * TestSpi - Align to LedDevice updates * Pretty Print CrossCompileHowTo as markdown-file * Ensure that output is only written when LedDevice is ready * Align APA102 Device to new device staging * Logger - Remove clang warnings on extra semicolon * Devices SPI - Align to Device stages and methods * Fix cppcheck and clang findings * Add Code-Template for new Devices * Align devices to stages and methods, clean-up some code * Allow to reopen LedDevice without restart * Revert change "Remove Connect (PriorityMuxer::visiblePriorityChanged -> Hyperion::update) due to double writes" * Remove visiblePriorityChanged from LedDevice to decouple LedDevice from hyperion logic * Expose LedDevice getLedCount and align signedness
2020-02-10 15:21:58 +01:00
}
2018-12-27 23:11:32 +01:00
return true;
}
2018-12-27 23:11:32 +01:00
return false;
}
2020-08-08 13:09:15 +02:00
bool Hyperion::setInputInactive(quint8 priority)
{
return _muxer.setInputInactive(priority);
}
2020-08-08 13:09:15 +02:00
void Hyperion::setColor(int priority, const std::vector<ColorRgb> &ledColors, int timeout_ms, const QString &origin, bool clearEffects)
2018-12-27 23:11:32 +01:00
{
// clear effect if this call does not come from an effect
if (clearEffects)
2018-12-27 23:11:32 +01:00
_effectEngine->channelCleared(priority);
// create full led vector from single/multiple colors
2020-07-27 20:00:36 +02:00
size_t size = _ledString.leds().size();
std::vector<ColorRgb> newLedColors;
2020-07-27 20:00:36 +02:00
while (true)
{
for (const auto &entry : ledColors)
{
newLedColors.emplace_back(entry);
if (newLedColors.size() == size)
goto end;
}
}
end:
2018-12-27 23:11:32 +01:00
if (getPriorityInfo(priority).componentId != hyperion::COMP_COLOR)
clear(priority);
2018-12-27 23:11:32 +01:00
// register color
registerInput(priority, hyperion::COMP_COLOR, origin);
// write color to muxer & queuePush
setInput(priority, newLedColors, timeout_ms);
if (timeout_ms <= 0)
_muxer.queuePush();
}
QStringList Hyperion::getAdjustmentIds() const
{
return _raw2ledAdjustment->getAdjustmentIds();
}
2020-08-02 10:44:42 +02:00
ColorAdjustment * Hyperion::getAdjustment(const QString& id) const
{
return _raw2ledAdjustment->getAdjustment(id);
}
void Hyperion::adjustmentsUpdated()
{
2018-12-27 23:11:32 +01:00
emit adjustmentChanged();
update();
}
2020-08-08 13:09:15 +02:00
bool Hyperion::clear(int priority, bool forceClearAll)
2013-08-18 13:33:56 +02:00
{
if (priority < 0)
{
_muxer.clearAll(forceClearAll);
2018-12-27 23:11:32 +01:00
// send clearall signal to the effect engine
_effectEngine->allChannelsCleared();
2018-12-27 23:11:32 +01:00
return true;
}
else
{
// send clear signal to the effect engine
// (outside the check so the effect gets cleared even when the effect is not sending colors)
_effectEngine->channelCleared(priority);
2018-12-27 23:11:32 +01:00
if (_muxer.clearInput(priority))
return true;
}
2018-12-27 23:11:32 +01:00
return false;
2013-08-18 13:33:56 +02:00
}
int Hyperion::getCurrentPriority() const
{
2018-12-27 23:11:32 +01:00
return _muxer.getCurrentPriority();
}
2020-08-08 13:09:15 +02:00
bool Hyperion::isCurrentPriority(int priority) const
{
return getCurrentPriority() == priority;
}
QList<int> Hyperion::getActivePriorities() const
{
return _muxer.getPriorities();
}
2020-08-08 13:09:15 +02:00
Hyperion::InputInfo Hyperion::getPriorityInfo(int priority) const
{
return _muxer.getInputInfo(priority);
}
QString Hyperion::saveEffect(const QJsonObject& obj)
2018-12-31 15:48:29 +01:00
{
return _effectEngine->saveEffect(obj);
2018-12-31 15:48:29 +01:00
}
QString Hyperion::deleteEffect(const QString& effectName)
{
return _effectEngine->deleteEffect(effectName);
}
std::list<EffectDefinition> Hyperion::getEffects() const
{
return _effectEngine->getEffects();
}
std::list<ActiveEffectDefinition> Hyperion::getActiveEffects() const
{
return _effectEngine->getActiveEffects();
}
std::list<EffectSchema> Hyperion::getEffectSchemas() const
{
return _effectEngine->getEffectSchemas();
}
QJsonObject Hyperion::getQJsonConfig() const
2018-12-27 23:11:32 +01:00
{
return _settingsManager->getSettings();
}
int Hyperion::setEffect(const QString &effectName, int priority, int timeout, const QString & origin)
{
return _effectEngine->runEffect(effectName, priority, timeout, origin);
}
int Hyperion::setEffect(const QString &effectName, const QJsonObject &args, int priority, int timeout, const QString &pythonScript, const QString &origin, const QString &imageData)
{
return _effectEngine->runEffect(effectName, args, priority, timeout, pythonScript, origin, 0, imageData);
}
2020-08-08 13:09:15 +02:00
void Hyperion::setLedMappingType(int mappingType)
2018-12-27 23:11:32 +01:00
{
if(mappingType != _imageProcessor->getUserLedMappingType())
{
_imageProcessor->setLedMappingType(mappingType);
emit imageToLedsMappingChanged(mappingType);
}
}
2020-08-02 10:44:42 +02:00
int Hyperion::getLedMappingType() const
{
2018-12-27 23:11:32 +01:00
return _imageProcessor->getUserLedMappingType();
}
2020-08-08 13:09:15 +02:00
void Hyperion::setVideoMode(VideoMode mode)
{
emit videoMode(mode);
}
2020-08-02 10:44:42 +02:00
VideoMode Hyperion::getCurrentVideoMode() const
2018-12-27 23:11:32 +01:00
{
return _currVideoMode;
2018-12-27 23:11:32 +01:00
}
2020-08-02 10:44:42 +02:00
QString Hyperion::getActiveDeviceType() const
{
return _ledDeviceWrapper->getActiveDeviceType();
2018-12-27 23:11:32 +01:00
}
2020-08-08 13:09:15 +02:00
void Hyperion::handleVisibleComponentChanged(hyperion::Components comp)
2018-12-27 23:11:32 +01:00
{
_imageProcessor->setBlackbarDetectDisable((comp == hyperion::COMP_EFFECT));
_imageProcessor->setHardLedMappingType((comp == hyperion::COMP_EFFECT) ? 0 : -1);
_raw2ledAdjustment->setBacklightEnabled((comp != hyperion::COMP_COLOR && comp != hyperion::COMP_EFFECT));
}
void Hyperion::handlePriorityChangedLedDevice(const quint8& priority)
{
quint8 previousPriority = _muxer.getPreviousPriority();
Debug(_log,"priority[%u], previousPriority[%u]", priority, previousPriority);
if ( priority == PriorityMuxer::LOWEST_PRIORITY)
{
Debug(_log,"No source left -> switch LED-Device off");
emit _ledDeviceWrapper->switchOff();
}
else
{
if ( previousPriority == PriorityMuxer::LOWEST_PRIORITY )
{
Debug(_log,"new source available -> switch LED-Device on");
emit _ledDeviceWrapper->switchOn();
}
}
}
void Hyperion::update()
{
2018-12-27 23:11:32 +01:00
// Obtain the current priority channel
int priority = _muxer.getCurrentPriority();
const PriorityMuxer::InputInfo priorityInfo = _muxer.getInputInfo(priority);
2018-12-20 15:12:45 +01:00
2018-12-27 23:11:32 +01:00
// copy image & process OR copy ledColors from muxer
Image<ColorRgb> image = priorityInfo.image;
if(image.size() > 3)
{
2018-12-27 23:11:32 +01:00
emit currentImage(image);
_ledBuffer = _imageProcessor->process(image);
}
2018-12-27 23:11:32 +01:00
else
2020-08-02 10:44:42 +02:00
{
2018-12-27 23:11:32 +01:00
_ledBuffer = priorityInfo.ledColors;
2020-08-02 10:44:42 +02:00
}
2018-12-31 15:48:29 +01:00
// emit rawLedColors before transform
emit rawLedColors(_ledBuffer);
2018-12-27 23:11:32 +01:00
_raw2ledAdjustment->applyAdjustment(_ledBuffer);
int i = 0;
for (ColorRgb& color : _ledBuffer)
{
// correct the color byte order
switch (_ledStringColorOrder.at(i))
{
case ColorOrder::ORDER_RGB:
// leave as it is
break;
case ColorOrder::ORDER_BGR:
std::swap(color.red, color.blue);
break;
case ColorOrder::ORDER_RBG:
std::swap(color.green, color.blue);
break;
case ColorOrder::ORDER_GRB:
std::swap(color.red, color.green);
break;
case ColorOrder::ORDER_GBR:
std::swap(color.red, color.green);
std::swap(color.green, color.blue);
break;
case ColorOrder::ORDER_BRG:
std::swap(color.red, color.blue);
std::swap(color.green, color.blue);
break;
}
i++;
}
// fill additional hw leds with black
if ( _hwLedCount > _ledBuffer.size() )
{
_ledBuffer.resize(_hwLedCount, ColorRgb::BLACK);
}
// Write the data to the device
if (_ledDeviceWrapper->enabled())
{
// Smoothing is disabled
if (! _deviceSmooth->enabled())
{
Disentangle LedDevice/LinearColorSmoothing, Bug Fixes & Test support (#654) * Handle Exceptions in main & Pythoninit * Have SSDPDiscover generic again * Have SSDPDiscover generic again * Change Info- to Debug logs as technical service messages * Nanoleaf - When switched on, ensure UDP mode * Include SQL Database in Cross-Compile instructions * Fix Clazy (QT code checker) and clang Warnings * Stop LedDevice:write for disabled device * Nanoleaf: Fix uint printfs * NanoLeaf: Fix indents to tabs * NanoLeaf - Add debug verbosity switches * Device switchability support, FileDevice with timestamp support * Nanoleaf Light Panels now support External Control V2 * Enhance LedDeviceFile by Timestamp + fix readyness * Stop color stream, if LedDevice disabled * Nanoleaf - remove switchability * Fix MultiColorAdjustment, if led-range is greater lednum * Fix logging * LedFileDevice/LedDevice - add testing support * New "Led Test" effect * LedDeviceFile - Add chrono include + Allow Led rewrites for testing * Stabilize Effects for LedDevices where latchtime = 0 * Update LedDeviceFile, allow latchtime = 0 * Distangle LinearColorSmoothing and LEDDevice, Fix Effect configuration updates * Updates LedDeviceFile - Initialize via Open * Updates LedDeviceNanoleaf - Initialize via Open, Remove throwing exceptions * Updates ProviderUDP - Remove throwing exceptions * Framebuffer - Use precise timer * TestSpi - Align to LedDevice updates * Pretty Print CrossCompileHowTo as markdown-file * Ensure that output is only written when LedDevice is ready * Align APA102 Device to new device staging * Logger - Remove clang warnings on extra semicolon * Devices SPI - Align to Device stages and methods * Fix cppcheck and clang findings * Add Code-Template for new Devices * Align devices to stages and methods, clean-up some code * Allow to reopen LedDevice without restart * Revert change "Remove Connect (PriorityMuxer::visiblePriorityChanged -> Hyperion::update) due to double writes" * Remove visiblePriorityChanged from LedDevice to decouple LedDevice from hyperion logic * Expose LedDevice getLedCount and align signedness
2020-02-10 15:21:58 +01:00
//std::cout << "Hyperion::update()> Non-Smoothing - "; LedDevice::printLedValues ( _ledBuffer);
emit ledDeviceData(_ledBuffer);
}
Disentangle LedDevice/LinearColorSmoothing, Bug Fixes & Test support (#654) * Handle Exceptions in main & Pythoninit * Have SSDPDiscover generic again * Have SSDPDiscover generic again * Change Info- to Debug logs as technical service messages * Nanoleaf - When switched on, ensure UDP mode * Include SQL Database in Cross-Compile instructions * Fix Clazy (QT code checker) and clang Warnings * Stop LedDevice:write for disabled device * Nanoleaf: Fix uint printfs * NanoLeaf: Fix indents to tabs * NanoLeaf - Add debug verbosity switches * Device switchability support, FileDevice with timestamp support * Nanoleaf Light Panels now support External Control V2 * Enhance LedDeviceFile by Timestamp + fix readyness * Stop color stream, if LedDevice disabled * Nanoleaf - remove switchability * Fix MultiColorAdjustment, if led-range is greater lednum * Fix logging * LedFileDevice/LedDevice - add testing support * New "Led Test" effect * LedDeviceFile - Add chrono include + Allow Led rewrites for testing * Stabilize Effects for LedDevices where latchtime = 0 * Update LedDeviceFile, allow latchtime = 0 * Distangle LinearColorSmoothing and LEDDevice, Fix Effect configuration updates * Updates LedDeviceFile - Initialize via Open * Updates LedDeviceNanoleaf - Initialize via Open, Remove throwing exceptions * Updates ProviderUDP - Remove throwing exceptions * Framebuffer - Use precise timer * TestSpi - Align to LedDevice updates * Pretty Print CrossCompileHowTo as markdown-file * Ensure that output is only written when LedDevice is ready * Align APA102 Device to new device staging * Logger - Remove clang warnings on extra semicolon * Devices SPI - Align to Device stages and methods * Fix cppcheck and clang findings * Add Code-Template for new Devices * Align devices to stages and methods, clean-up some code * Allow to reopen LedDevice without restart * Revert change "Remove Connect (PriorityMuxer::visiblePriorityChanged -> Hyperion::update) due to double writes" * Remove visiblePriorityChanged from LedDevice to decouple LedDevice from hyperion logic * Expose LedDevice getLedCount and align signedness
2020-02-10 15:21:58 +01:00
else
{
_deviceSmooth->selectConfig(priorityInfo.smooth_cfg);
// feed smoothing in pause mode to maintain a smooth transistion back to smooth mode
if (_deviceSmooth->enabled() || _deviceSmooth->pause())
{
_deviceSmooth->updateLedValues(_ledBuffer);
}
}
}
Disentangle LedDevice/LinearColorSmoothing, Bug Fixes & Test support (#654) * Handle Exceptions in main & Pythoninit * Have SSDPDiscover generic again * Have SSDPDiscover generic again * Change Info- to Debug logs as technical service messages * Nanoleaf - When switched on, ensure UDP mode * Include SQL Database in Cross-Compile instructions * Fix Clazy (QT code checker) and clang Warnings * Stop LedDevice:write for disabled device * Nanoleaf: Fix uint printfs * NanoLeaf: Fix indents to tabs * NanoLeaf - Add debug verbosity switches * Device switchability support, FileDevice with timestamp support * Nanoleaf Light Panels now support External Control V2 * Enhance LedDeviceFile by Timestamp + fix readyness * Stop color stream, if LedDevice disabled * Nanoleaf - remove switchability * Fix MultiColorAdjustment, if led-range is greater lednum * Fix logging * LedFileDevice/LedDevice - add testing support * New "Led Test" effect * LedDeviceFile - Add chrono include + Allow Led rewrites for testing * Stabilize Effects for LedDevices where latchtime = 0 * Update LedDeviceFile, allow latchtime = 0 * Distangle LinearColorSmoothing and LEDDevice, Fix Effect configuration updates * Updates LedDeviceFile - Initialize via Open * Updates LedDeviceNanoleaf - Initialize via Open, Remove throwing exceptions * Updates ProviderUDP - Remove throwing exceptions * Framebuffer - Use precise timer * TestSpi - Align to LedDevice updates * Pretty Print CrossCompileHowTo as markdown-file * Ensure that output is only written when LedDevice is ready * Align APA102 Device to new device staging * Logger - Remove clang warnings on extra semicolon * Devices SPI - Align to Device stages and methods * Fix cppcheck and clang findings * Add Code-Template for new Devices * Align devices to stages and methods, clean-up some code * Allow to reopen LedDevice without restart * Revert change "Remove Connect (PriorityMuxer::visiblePriorityChanged -> Hyperion::update) due to double writes" * Remove visiblePriorityChanged from LedDevice to decouple LedDevice from hyperion logic * Expose LedDevice getLedCount and align signedness
2020-02-10 15:21:58 +01:00
//else
//{
// /LEDDevice is disabled
// Debug(_log, "LEDDevice is disabled - no update required");
//}
}