Skip to content

Commit

Permalink
New features: disable LEDs/components on startup, stop processing whe…
Browse files Browse the repository at this point in the history
…n user has locked the system (#737)

* Disable on user lock screen (Windows)

* Fix

* Add feature to disable components on startup
  • Loading branch information
awawa-dev authored Jan 19, 2024
1 parent 83c1f62 commit fd90a20
Show file tree
Hide file tree
Showing 22 changed files with 187 additions and 35 deletions.
3 changes: 2 additions & 1 deletion include/base/ComponentController.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ComponentController : public QObject
Q_OBJECT

public:
ComponentController(HyperHdrInstance* hyperhdr);
ComponentController(HyperHdrInstance* hyperhdr, bool disableOnStartup);
virtual ~ComponentController();

int isComponentEnabled(hyperhdr::Components comp) const;
Expand All @@ -35,4 +35,5 @@ private slots:
Logger* _log;
std::map<hyperhdr::Components, bool> _componentStates;
std::map<hyperhdr::Components, bool> _prevComponentStates;
bool _disableOnStartup;
};
3 changes: 2 additions & 1 deletion include/base/HyperHdrInstance.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class HyperHdrInstance : public QObject
Q_OBJECT

public:
HyperHdrInstance(quint8 instance, bool readonlyMode, QString name);
HyperHdrInstance(quint8 instance, bool readonlyMode, bool disableOnstartup, QString name);
~HyperHdrInstance();

quint8 getInstanceIndex() const { return _instIndex; }
Expand Down Expand Up @@ -158,6 +158,7 @@ private slots:
QString _name;

bool _readOnlyMode;
bool _disableOnStartup;

static std::atomic<bool> _signalTerminate;
static std::atomic<int> _totalRunningCount;
Expand Down
4 changes: 2 additions & 2 deletions include/base/HyperHdrManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public slots:

QVector<QVariantMap> getInstanceData() const;

bool startInstance(quint8 inst, QObject* caller = nullptr, int tan = 0);
bool startInstance(quint8 inst, QObject* caller = nullptr, int tan = 0, bool disableOnStartup = false);

bool stopInstance(quint8 inst);

Expand Down Expand Up @@ -97,7 +97,7 @@ private slots:

HyperHdrManager(const QString& rootPath, bool readonlyMode);

void startAll();
void startAll(bool disableOnStartup);

void stopAllonExit();

Expand Down
2 changes: 2 additions & 0 deletions include/leddevice/LedDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public slots:
void blinking(QJsonObject params);
void smoothingRestarted(int newSmoothingInterval);
int hasLedClock();
void pauseRetryTimer(bool mode);

signals:
void SignalEnableStateChanged(bool newState);
Expand Down Expand Up @@ -155,4 +156,5 @@ protected slots:
int _blinkIndex;
qint64 _blinkTime;
int _instanceIndex;
int _pauseRetryTimer;
};
2 changes: 1 addition & 1 deletion include/leddevice/LedDeviceWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class LedDeviceWrapper : public QObject
explicit LedDeviceWrapper(HyperHdrInstance* ownerInstance);
virtual ~LedDeviceWrapper();

void createLedDevice(QJsonObject config, int smoothingInterval);
void createLedDevice(QJsonObject config, int smoothingInterval, bool disableOnStartup);
static QJsonObject getLedDeviceSchemas();
static int addToDeviceMap(QString name, LedDeviceCreateFuncType funcPtr);
static const LedDeviceRegistry& getDeviceMap();
Expand Down
15 changes: 11 additions & 4 deletions sources/base/ComponentController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@

using namespace hyperhdr;

ComponentController::ComponentController(HyperHdrInstance* hyperhdr)
: _log(Logger::getInstance(QString("COMPONENTCTRL%1").arg(hyperhdr->getInstanceIndex())))
ComponentController::ComponentController(HyperHdrInstance* hyperhdr, bool disableOnStartup):
_log(Logger::getInstance(QString("COMPONENTCTRL%1").arg(hyperhdr->getInstanceIndex()))),
_disableOnStartup(disableOnStartup)
{
// init all comps to false
QVector<hyperhdr::Components> vect;
Expand All @@ -27,7 +28,7 @@ ComponentController::ComponentController(HyperHdrInstance* hyperhdr)

connect(this, &ComponentController::SignalRequestComponent, hyperhdr, &HyperHdrInstance::SignalRequestComponent);
connect(hyperhdr, &HyperHdrInstance::SignalRequestComponent, this, &ComponentController::handleCompStateChangeRequest);
Debug(_log, "ComponentController is initialized");
Debug(_log, "ComponentController is initialized. Components are %s", (_disableOnStartup) ? "DISABLED" : "ENABLED");
}

ComponentController::~ComponentController()
Expand All @@ -41,11 +42,17 @@ void ComponentController::handleCompStateChangeRequest(hyperhdr::Components comp
{
if (!activated && _prevComponentStates.empty())
{
bool disableLeds = _disableOnStartup && !isComponentEnabled(COMP_ALL) && _prevComponentStates.empty();

Debug(_log, "Disabling HyperHDR instance: saving current component states first");
for (const auto& comp : _componentStates)
if (comp.first != COMP_ALL)
{
_prevComponentStates.emplace(comp.first, comp.second);
if (disableLeds && comp.first == COMP_LEDDEVICE)
_prevComponentStates.emplace(comp.first, true);
else
_prevComponentStates.emplace(comp.first, comp.second);

if (comp.second)
{
emit SignalRequestComponent(comp.first, false);
Expand Down
29 changes: 20 additions & 9 deletions sources/base/HyperHdrInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
std::atomic<bool> HyperHdrInstance::_signalTerminate(false);
std::atomic<int> HyperHdrInstance::_totalRunningCount(0);

HyperHdrInstance::HyperHdrInstance(quint8 instance, bool readonlyMode, QString name)
HyperHdrInstance::HyperHdrInstance(quint8 instance, bool readonlyMode, bool disableOnStartup, QString name)
: QObject()
, _instIndex(instance)
, _bootEffect(QTime::currentTime().addSecs(5))
Expand All @@ -90,6 +90,7 @@ HyperHdrInstance::HyperHdrInstance(quint8 instance, bool readonlyMode, QString n
, _currentLedColors()
, _name((name.isEmpty()) ? QString("INSTANCE%1").arg(instance) : name)
, _readOnlyMode(readonlyMode)
, _disableOnStartup(disableOnStartup)
{
_totalRunningCount++;
}
Expand Down Expand Up @@ -142,7 +143,7 @@ void HyperHdrInstance::start()
Info(_log, "Starting the instance");

_instanceConfig = std::unique_ptr<InstanceConfig>(new InstanceConfig(false, _instIndex, this, _readOnlyMode));
_componentController = std::unique_ptr<ComponentController>(new ComponentController(this));
_componentController = std::unique_ptr<ComponentController>(new ComponentController(this, _disableOnStartup));
connect(_componentController.get(), &ComponentController::SignalComponentStateChanged, this, &HyperHdrInstance::SignalComponentStateChanged);
_ledString = LedString::createLedString(getSetting(settings::type::LEDS).array(), LedString::createColorOrder(getSetting(settings::type::DEVICE).object()));
_muxer = std::unique_ptr<Muxer>(new Muxer(_instIndex, static_cast<int>(_ledString.leds().size()), this));
Expand Down Expand Up @@ -184,7 +185,7 @@ void HyperHdrInstance::start()

_ledDeviceWrapper = std::unique_ptr<LedDeviceWrapper>(new LedDeviceWrapper(this));
connect(this, &HyperHdrInstance::SignalRequestComponent, _ledDeviceWrapper.get(), &LedDeviceWrapper::handleComponentState);
_ledDeviceWrapper->createLedDevice(ledDevice, _smoothing->GetSuggestedInterval());
_ledDeviceWrapper->createLedDevice(ledDevice, _smoothing->GetSuggestedInterval(), _disableOnStartup);

// create the effect engine; needs to be initialized after smoothing!
_effectEngine = std::unique_ptr<EffectEngine>(new EffectEngine(this));
Expand Down Expand Up @@ -222,6 +223,12 @@ void HyperHdrInstance::start()
// instance initiated, enter thread event loop
emit SignalInstanceJustStarted();

if (_disableOnStartup)
{
_componentController->setNewComponentState(hyperhdr::COMP_ALL, false);
Warning(_log, "The user has disabled LEDs auto-start in the configuration (interface: 'General' tab)");
}

// exit
Info(_log, "The instance is running");
}
Expand Down Expand Up @@ -295,9 +302,7 @@ void HyperHdrInstance::handleSettingsUpdate(settings::type type, const QJsonDocu

// do always reinit until the led devices can handle dynamic changes
dev["currentLedCount"] = _hwLedCount; // Inject led count info
_ledDeviceWrapper->createLedDevice(dev, _smoothing->GetSuggestedInterval());

// TODO: Check, if framegrabber frequency is lower than latchtime..., if yes, stop
_ledDeviceWrapper->createLedDevice(dev, _smoothing->GetSuggestedInterval(), false);
}
else if (type == settings::type::BGEFFECT || type == settings::type::FGEFFECT)
{
Expand Down Expand Up @@ -684,9 +689,15 @@ void HyperHdrInstance::handlePriorityChangedLedDevice(const quint8& priority)
if (previousPriority == Muxer::LOWEST_PRIORITY)
{
Info(_log, "New source available -> switch LED-Device on");

emit SignalRequestComponent(hyperhdr::COMP_LEDDEVICE, true);
emit GlobalSignals::getInstance()->SignalPerformanceStateChanged(true, hyperhdr::PerformanceReportType::INSTANCE, getInstanceIndex(), _name);
if (!isComponentEnabled(hyperhdr::Components::COMP_ALL))
{
Warning(_log, "Components are disabled: ignoring switching LED-Device on");
}
else
{
emit SignalRequestComponent(hyperhdr::COMP_LEDDEVICE, true);
emit GlobalSignals::getInstance()->SignalPerformanceStateChanged(true, hyperhdr::PerformanceReportType::INSTANCE, getInstanceIndex(), _name);
}
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions sources/base/HyperHdrManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,15 @@ bool HyperHdrManager::areInstancesReady()
return (--_fireStarter == 0);
}

void HyperHdrManager::startAll()
void HyperHdrManager::startAll(bool disableOnStartup)
{
auto instanceList = _instanceTable->getAllInstances(true);

_fireStarter = instanceList.count();

for (const auto& entry : instanceList)
{
startInstance(entry["instance"].toInt());
startInstance(entry["instance"].toInt(), nullptr, 0, disableOnStartup);
}
}

Expand Down Expand Up @@ -179,7 +179,7 @@ void HyperHdrManager::hibernate(bool wakeUp)
}
}

bool HyperHdrManager::startInstance(quint8 inst, QObject* caller, int tan)
bool HyperHdrManager::startInstance(quint8 inst, QObject* caller, int tan, bool disableOnStartup)
{
if (_instanceTable->instanceExist(inst))
{
Expand All @@ -191,6 +191,7 @@ bool HyperHdrManager::startInstance(quint8 inst, QObject* caller, int tan)
auto hyperhdr = std::shared_ptr<HyperHdrInstance>(
new HyperHdrInstance(inst,
_readonlyMode,
disableOnStartup,
_instanceTable->getNamebyIndex(inst)),
[](HyperHdrInstance* oldInstance) {
THREAD_REMOVER(QString("HyperHDR instance at index = %1").arg(oldInstance->getInstanceIndex()),
Expand Down
18 changes: 18 additions & 0 deletions sources/base/schema/schema-general.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,24 @@
"hidden":true
},
"propertyOrder" : 4
},
"disableOnLocked" :
{
"type" : "boolean",
"format": "checkbox",
"title" : "edt_conf_gen_disableOnLocked_title",
"default" : false,
"required" : true,
"propertyOrder" : 5
},
"disableLedsStartup" :
{
"type" : "boolean",
"format": "checkbox",
"title" : "edt_conf_gen_disableLedsStartup_title",
"default" : false,
"required" : true,
"propertyOrder" : 6
}

},
Expand Down
2 changes: 2 additions & 0 deletions sources/grabber/DX/DxGrabber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,8 @@ void DxGrabber::stop()
_timer->stop();
Info(_log, "Stopped");
}

_retryTimer->stop();
}

bool DxGrabber::initDirectX(QString selectedDeviceName)
Expand Down
15 changes: 13 additions & 2 deletions sources/hyperhdr/HyperHdrDaemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ HyperHdrDaemon::HyperHdrDaemon(const QString& rootPath, QApplication* parent, bo
, _rootPath(rootPath)
, _params(params)
, _isGuiApp(isGuiApp)
, _disableOnStart(false)
{

// Register metas for thread queued connection
Expand Down Expand Up @@ -166,7 +167,9 @@ HyperHdrDaemon::HyperHdrDaemon(const QString& rootPath, QApplication* parent, bo
// spawn all Hyperhdr instances (non blocking)
settingsChangedHandler(settings::type::VIDEOGRABBER, getSetting(settings::type::VIDEOGRABBER));
settingsChangedHandler(settings::type::SYSTEMGRABBER, getSetting(settings::type::SYSTEMGRABBER));
_instanceManager->startAll();
QJsonObject genConfig = getSetting(settings::type::GENERAL).object();
_disableOnStart = genConfig["disableLedsStartup"].toBool(false);
_instanceManager->startAll(_disableOnStart);

//Cleaning up Hyperhdr before quit
connect(parent, &QCoreApplication::aboutToQuit, this, &HyperHdrDaemon::freeObjects);
Expand All @@ -177,7 +180,9 @@ HyperHdrDaemon::HyperHdrDaemon(const QString& rootPath, QApplication* parent, bo

// power management
#if defined(HAVE_POWER_MANAGEMENT)
_suspendHandler = std::unique_ptr<SuspendHandler>(new SuspendHandler());
bool lockedEnable = genConfig["disableOnLocked"].toBool(false);

_suspendHandler = std::unique_ptr<SuspendHandler>(new SuspendHandler(lockedEnable));
connect(_suspendHandler.get(), &SuspendHandler::SignalHibernate, _instanceManager.get(), &HyperHdrManager::hibernate);

#ifdef _WIN32
Expand Down Expand Up @@ -223,6 +228,12 @@ void HyperHdrDaemon::instanceStateChangedHandler(InstanceState state, quint8 ins
{
_networkThread->start();
}

if (_disableOnStart)
{
Warning(_log, "The user has disabled LEDs auto-start in the configuration (interface: 'General' tab)");
_instanceManager->toggleStateAllInstances(false);
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions sources/hyperhdr/HyperHdrDaemon.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,5 +170,6 @@ public slots:
bool _readonlyMode;
QStringList _params;
bool _isGuiApp;
bool _disableOnStart;
};

2 changes: 1 addition & 1 deletion sources/hyperhdr/SuspendHandlerLinux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace {
const QString UPOWER_INTER = QStringLiteral("org.freedesktop.login1.Manager");
}

SuspendHandler::SuspendHandler()
SuspendHandler::SuspendHandler(bool sessionLocker)
{
QDBusConnection bus = QDBusConnection::systemBus();

Expand Down
2 changes: 1 addition & 1 deletion sources/hyperhdr/SuspendHandlerLinux.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class SuspendHandler : public QObject {
void SignalHibernate(bool wakeUp);

public:
SuspendHandler();
SuspendHandler(bool sessionLocker = false);
~SuspendHandler();

public slots:
Expand Down
2 changes: 1 addition & 1 deletion sources/hyperhdr/SuspendHandlerMacOS.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ class SuspendHandler : public QObject {
void SignalHibernate(bool wakeUp);

public:
SuspendHandler();
SuspendHandler(bool sessionLocker = false);
~SuspendHandler();
};
2 changes: 1 addition & 1 deletion sources/hyperhdr/SuspendHandlerMacOS.mm
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ - (void)goingWake: (NSNotification*)note

@end

SuspendHandler::SuspendHandler()
SuspendHandler::SuspendHandler(bool sessionLocker)
{
_macSuspendHandlerInstance = [MacSuspendHandler new];
_suspendHandler = this;
Expand Down
Loading

0 comments on commit fd90a20

Please sign in to comment.