Skip to content

Commit fd90a20

Browse files
authored
New features: disable LEDs/components on startup, stop processing when user has locked the system (#737)
* Disable on user lock screen (Windows) * Fix * Add feature to disable components on startup
1 parent 83c1f62 commit fd90a20

22 files changed

+187
-35
lines changed

Diff for: include/base/ComponentController.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class ComponentController : public QObject
1515
Q_OBJECT
1616

1717
public:
18-
ComponentController(HyperHdrInstance* hyperhdr);
18+
ComponentController(HyperHdrInstance* hyperhdr, bool disableOnStartup);
1919
virtual ~ComponentController();
2020

2121
int isComponentEnabled(hyperhdr::Components comp) const;
@@ -35,4 +35,5 @@ private slots:
3535
Logger* _log;
3636
std::map<hyperhdr::Components, bool> _componentStates;
3737
std::map<hyperhdr::Components, bool> _prevComponentStates;
38+
bool _disableOnStartup;
3839
};

Diff for: include/base/HyperHdrInstance.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class HyperHdrInstance : public QObject
5151
Q_OBJECT
5252

5353
public:
54-
HyperHdrInstance(quint8 instance, bool readonlyMode, QString name);
54+
HyperHdrInstance(quint8 instance, bool readonlyMode, bool disableOnstartup, QString name);
5555
~HyperHdrInstance();
5656

5757
quint8 getInstanceIndex() const { return _instIndex; }
@@ -158,6 +158,7 @@ private slots:
158158
QString _name;
159159

160160
bool _readOnlyMode;
161+
bool _disableOnStartup;
161162

162163
static std::atomic<bool> _signalTerminate;
163164
static std::atomic<int> _totalRunningCount;

Diff for: include/base/HyperHdrManager.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public slots:
5454

5555
QVector<QVariantMap> getInstanceData() const;
5656

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

5959
bool stopInstance(quint8 inst);
6060

@@ -97,7 +97,7 @@ private slots:
9797

9898
HyperHdrManager(const QString& rootPath, bool readonlyMode);
9999

100-
void startAll();
100+
void startAll(bool disableOnStartup);
101101

102102
void stopAllonExit();
103103

Diff for: include/leddevice/LedDevice.h

+2
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public slots:
7070
void blinking(QJsonObject params);
7171
void smoothingRestarted(int newSmoothingInterval);
7272
int hasLedClock();
73+
void pauseRetryTimer(bool mode);
7374

7475
signals:
7576
void SignalEnableStateChanged(bool newState);
@@ -155,4 +156,5 @@ protected slots:
155156
int _blinkIndex;
156157
qint64 _blinkTime;
157158
int _instanceIndex;
159+
int _pauseRetryTimer;
158160
};

Diff for: include/leddevice/LedDeviceWrapper.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class LedDeviceWrapper : public QObject
2222
explicit LedDeviceWrapper(HyperHdrInstance* ownerInstance);
2323
virtual ~LedDeviceWrapper();
2424

25-
void createLedDevice(QJsonObject config, int smoothingInterval);
25+
void createLedDevice(QJsonObject config, int smoothingInterval, bool disableOnStartup);
2626
static QJsonObject getLedDeviceSchemas();
2727
static int addToDeviceMap(QString name, LedDeviceCreateFuncType funcPtr);
2828
static const LedDeviceRegistry& getDeviceMap();

Diff for: sources/base/ComponentController.cpp

+11-4
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88

99
using namespace hyperhdr;
1010

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

2829
connect(this, &ComponentController::SignalRequestComponent, hyperhdr, &HyperHdrInstance::SignalRequestComponent);
2930
connect(hyperhdr, &HyperHdrInstance::SignalRequestComponent, this, &ComponentController::handleCompStateChangeRequest);
30-
Debug(_log, "ComponentController is initialized");
31+
Debug(_log, "ComponentController is initialized. Components are %s", (_disableOnStartup) ? "DISABLED" : "ENABLED");
3132
}
3233

3334
ComponentController::~ComponentController()
@@ -41,11 +42,17 @@ void ComponentController::handleCompStateChangeRequest(hyperhdr::Components comp
4142
{
4243
if (!activated && _prevComponentStates.empty())
4344
{
45+
bool disableLeds = _disableOnStartup && !isComponentEnabled(COMP_ALL) && _prevComponentStates.empty();
46+
4447
Debug(_log, "Disabling HyperHDR instance: saving current component states first");
4548
for (const auto& comp : _componentStates)
4649
if (comp.first != COMP_ALL)
4750
{
48-
_prevComponentStates.emplace(comp.first, comp.second);
51+
if (disableLeds && comp.first == COMP_LEDDEVICE)
52+
_prevComponentStates.emplace(comp.first, true);
53+
else
54+
_prevComponentStates.emplace(comp.first, comp.second);
55+
4956
if (comp.second)
5057
{
5158
emit SignalRequestComponent(comp.first, false);

Diff for: sources/base/HyperHdrInstance.cpp

+20-9
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
std::atomic<bool> HyperHdrInstance::_signalTerminate(false);
6868
std::atomic<int> HyperHdrInstance::_totalRunningCount(0);
6969

70-
HyperHdrInstance::HyperHdrInstance(quint8 instance, bool readonlyMode, QString name)
70+
HyperHdrInstance::HyperHdrInstance(quint8 instance, bool readonlyMode, bool disableOnStartup, QString name)
7171
: QObject()
7272
, _instIndex(instance)
7373
, _bootEffect(QTime::currentTime().addSecs(5))
@@ -90,6 +90,7 @@ HyperHdrInstance::HyperHdrInstance(quint8 instance, bool readonlyMode, QString n
9090
, _currentLedColors()
9191
, _name((name.isEmpty()) ? QString("INSTANCE%1").arg(instance) : name)
9292
, _readOnlyMode(readonlyMode)
93+
, _disableOnStartup(disableOnStartup)
9394
{
9495
_totalRunningCount++;
9596
}
@@ -142,7 +143,7 @@ void HyperHdrInstance::start()
142143
Info(_log, "Starting the instance");
143144

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

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

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

226+
if (_disableOnStartup)
227+
{
228+
_componentController->setNewComponentState(hyperhdr::COMP_ALL, false);
229+
Warning(_log, "The user has disabled LEDs auto-start in the configuration (interface: 'General' tab)");
230+
}
231+
225232
// exit
226233
Info(_log, "The instance is running");
227234
}
@@ -295,9 +302,7 @@ void HyperHdrInstance::handleSettingsUpdate(settings::type type, const QJsonDocu
295302

296303
// do always reinit until the led devices can handle dynamic changes
297304
dev["currentLedCount"] = _hwLedCount; // Inject led count info
298-
_ledDeviceWrapper->createLedDevice(dev, _smoothing->GetSuggestedInterval());
299-
300-
// TODO: Check, if framegrabber frequency is lower than latchtime..., if yes, stop
305+
_ledDeviceWrapper->createLedDevice(dev, _smoothing->GetSuggestedInterval(), false);
301306
}
302307
else if (type == settings::type::BGEFFECT || type == settings::type::FGEFFECT)
303308
{
@@ -684,9 +689,15 @@ void HyperHdrInstance::handlePriorityChangedLedDevice(const quint8& priority)
684689
if (previousPriority == Muxer::LOWEST_PRIORITY)
685690
{
686691
Info(_log, "New source available -> switch LED-Device on");
687-
688-
emit SignalRequestComponent(hyperhdr::COMP_LEDDEVICE, true);
689-
emit GlobalSignals::getInstance()->SignalPerformanceStateChanged(true, hyperhdr::PerformanceReportType::INSTANCE, getInstanceIndex(), _name);
692+
if (!isComponentEnabled(hyperhdr::Components::COMP_ALL))
693+
{
694+
Warning(_log, "Components are disabled: ignoring switching LED-Device on");
695+
}
696+
else
697+
{
698+
emit SignalRequestComponent(hyperhdr::COMP_LEDDEVICE, true);
699+
emit GlobalSignals::getInstance()->SignalPerformanceStateChanged(true, hyperhdr::PerformanceReportType::INSTANCE, getInstanceIndex(), _name);
700+
}
690701
}
691702
}
692703
}

Diff for: sources/base/HyperHdrManager.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,15 @@ bool HyperHdrManager::areInstancesReady()
102102
return (--_fireStarter == 0);
103103
}
104104

105-
void HyperHdrManager::startAll()
105+
void HyperHdrManager::startAll(bool disableOnStartup)
106106
{
107107
auto instanceList = _instanceTable->getAllInstances(true);
108108

109109
_fireStarter = instanceList.count();
110110

111111
for (const auto& entry : instanceList)
112112
{
113-
startInstance(entry["instance"].toInt());
113+
startInstance(entry["instance"].toInt(), nullptr, 0, disableOnStartup);
114114
}
115115
}
116116

@@ -179,7 +179,7 @@ void HyperHdrManager::hibernate(bool wakeUp)
179179
}
180180
}
181181

182-
bool HyperHdrManager::startInstance(quint8 inst, QObject* caller, int tan)
182+
bool HyperHdrManager::startInstance(quint8 inst, QObject* caller, int tan, bool disableOnStartup)
183183
{
184184
if (_instanceTable->instanceExist(inst))
185185
{
@@ -191,6 +191,7 @@ bool HyperHdrManager::startInstance(quint8 inst, QObject* caller, int tan)
191191
auto hyperhdr = std::shared_ptr<HyperHdrInstance>(
192192
new HyperHdrInstance(inst,
193193
_readonlyMode,
194+
disableOnStartup,
194195
_instanceTable->getNamebyIndex(inst)),
195196
[](HyperHdrInstance* oldInstance) {
196197
THREAD_REMOVER(QString("HyperHDR instance at index = %1").arg(oldInstance->getInstanceIndex()),

Diff for: sources/base/schema/schema-general.json

+18
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,24 @@
3232
"hidden":true
3333
},
3434
"propertyOrder" : 4
35+
},
36+
"disableOnLocked" :
37+
{
38+
"type" : "boolean",
39+
"format": "checkbox",
40+
"title" : "edt_conf_gen_disableOnLocked_title",
41+
"default" : false,
42+
"required" : true,
43+
"propertyOrder" : 5
44+
},
45+
"disableLedsStartup" :
46+
{
47+
"type" : "boolean",
48+
"format": "checkbox",
49+
"title" : "edt_conf_gen_disableLedsStartup_title",
50+
"default" : false,
51+
"required" : true,
52+
"propertyOrder" : 6
3553
}
3654

3755
},

Diff for: sources/grabber/DX/DxGrabber.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,8 @@ void DxGrabber::stop()
313313
_timer->stop();
314314
Info(_log, "Stopped");
315315
}
316+
317+
_retryTimer->stop();
316318
}
317319

318320
bool DxGrabber::initDirectX(QString selectedDeviceName)

Diff for: sources/hyperhdr/HyperHdrDaemon.cpp

+13-2
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ HyperHdrDaemon::HyperHdrDaemon(const QString& rootPath, QApplication* parent, bo
8282
, _rootPath(rootPath)
8383
, _params(params)
8484
, _isGuiApp(isGuiApp)
85+
, _disableOnStart(false)
8586
{
8687

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

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

178181
// power management
179182
#if defined(HAVE_POWER_MANAGEMENT)
180-
_suspendHandler = std::unique_ptr<SuspendHandler>(new SuspendHandler());
183+
bool lockedEnable = genConfig["disableOnLocked"].toBool(false);
184+
185+
_suspendHandler = std::unique_ptr<SuspendHandler>(new SuspendHandler(lockedEnable));
181186
connect(_suspendHandler.get(), &SuspendHandler::SignalHibernate, _instanceManager.get(), &HyperHdrManager::hibernate);
182187

183188
#ifdef _WIN32
@@ -223,6 +228,12 @@ void HyperHdrDaemon::instanceStateChangedHandler(InstanceState state, quint8 ins
223228
{
224229
_networkThread->start();
225230
}
231+
232+
if (_disableOnStart)
233+
{
234+
Warning(_log, "The user has disabled LEDs auto-start in the configuration (interface: 'General' tab)");
235+
_instanceManager->toggleStateAllInstances(false);
236+
}
226237
}
227238
}
228239
}

Diff for: sources/hyperhdr/HyperHdrDaemon.h

+1
Original file line numberDiff line numberDiff line change
@@ -170,5 +170,6 @@ public slots:
170170
bool _readonlyMode;
171171
QStringList _params;
172172
bool _isGuiApp;
173+
bool _disableOnStart;
173174
};
174175

Diff for: sources/hyperhdr/SuspendHandlerLinux.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ namespace {
4646
const QString UPOWER_INTER = QStringLiteral("org.freedesktop.login1.Manager");
4747
}
4848

49-
SuspendHandler::SuspendHandler()
49+
SuspendHandler::SuspendHandler(bool sessionLocker)
5050
{
5151
QDBusConnection bus = QDBusConnection::systemBus();
5252

Diff for: sources/hyperhdr/SuspendHandlerLinux.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class SuspendHandler : public QObject {
3737
void SignalHibernate(bool wakeUp);
3838

3939
public:
40-
SuspendHandler();
40+
SuspendHandler(bool sessionLocker = false);
4141
~SuspendHandler();
4242

4343
public slots:

Diff for: sources/hyperhdr/SuspendHandlerMacOS.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,6 @@ class SuspendHandler : public QObject {
3737
void SignalHibernate(bool wakeUp);
3838

3939
public:
40-
SuspendHandler();
40+
SuspendHandler(bool sessionLocker = false);
4141
~SuspendHandler();
4242
};

Diff for: sources/hyperhdr/SuspendHandlerMacOS.mm

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ - (void)goingWake: (NSNotification*)note
8989

9090
@end
9191

92-
SuspendHandler::SuspendHandler()
92+
SuspendHandler::SuspendHandler(bool sessionLocker)
9393
{
9494
_macSuspendHandlerInstance = [MacSuspendHandler new];
9595
_suspendHandler = this;

0 commit comments

Comments
 (0)