mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
Differentiate between LED-Device Enable/Disable and Switch On/Off (#960)
* Switch Off devices, when no input source * Realign Enable/SwitchOn, Disable/SwitchOff * Align to updated LedDevice-Flow * Remove debug statements slipped in * Send last color update after enabling again * Fix WLED getProperties API call * Remove unused signals * LedDevice process flow documentation * LedDevice process flow documentation Co-authored-by: Paulchen Panther <16664240+Paulchen-Panther@users.noreply.github.com>
This commit is contained in:
@@ -28,6 +28,7 @@ LedDevice::LedDevice(const QJsonObject& deviceConfig, QObject* parent)
|
||||
, _isEnabled(false)
|
||||
, _isDeviceInitialised(false)
|
||||
, _isDeviceReady(false)
|
||||
, _isOn(false)
|
||||
, _isDeviceInError(false)
|
||||
, _isInSwitchOff (false)
|
||||
, _lastWriteTime(QDateTime::currentDateTime())
|
||||
@@ -62,14 +63,15 @@ void LedDevice::start()
|
||||
{
|
||||
// Everything is OK -> enable device
|
||||
_isDeviceInitialised = true;
|
||||
setEnable(true);
|
||||
this->enable();
|
||||
}
|
||||
}
|
||||
|
||||
void LedDevice::stop()
|
||||
{
|
||||
setEnable(false);
|
||||
this->disable();
|
||||
this->stopRefreshTimer();
|
||||
Info(_log, " Stopped LedDevice '%s'", QSTRING_CSTR(_activeDeviceType) );
|
||||
}
|
||||
|
||||
int LedDevice::open()
|
||||
@@ -99,27 +101,39 @@ void LedDevice::setInError(const QString& errorMsg)
|
||||
emit enableStateChanged(_isEnabled);
|
||||
}
|
||||
|
||||
void LedDevice::setEnable(bool enable)
|
||||
void LedDevice::enable()
|
||||
{
|
||||
bool isSwitched = false;
|
||||
// switch off device when disabled, default: set black to LEDs when they should go off
|
||||
if ( _isEnabled && !enable)
|
||||
if ( !_isEnabled )
|
||||
{
|
||||
isSwitched = switchOff();
|
||||
}
|
||||
else
|
||||
{
|
||||
// switch on device when enabled
|
||||
if ( !_isEnabled && enable)
|
||||
_isDeviceInError = false;
|
||||
|
||||
if ( ! _isDeviceReady )
|
||||
{
|
||||
isSwitched = switchOn();
|
||||
open();
|
||||
}
|
||||
|
||||
if ( _isDeviceReady )
|
||||
{
|
||||
_isEnabled = true;
|
||||
if ( switchOn() )
|
||||
{
|
||||
emit enableStateChanged(_isEnabled);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( isSwitched )
|
||||
void LedDevice::disable()
|
||||
{
|
||||
if ( _isEnabled )
|
||||
{
|
||||
_isEnabled = enable;
|
||||
emit enableStateChanged(enable);
|
||||
_isEnabled = false;
|
||||
this->stopRefreshTimer();
|
||||
|
||||
switchOff();
|
||||
close();
|
||||
|
||||
emit enableStateChanged(_isEnabled);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,30 +147,11 @@ bool LedDevice::init(const QJsonObject &deviceConfig)
|
||||
Debug(_log, "deviceConfig: [%s]", QString(QJsonDocument(_devConfig).toJson(QJsonDocument::Compact)).toUtf8().constData() );
|
||||
|
||||
_colorOrder = deviceConfig["colorOrder"].toString("RGB");
|
||||
setLedCount(static_cast<unsigned int>( deviceConfig["currentLedCount"].toInt(1) )); // property injected to reflect real led count
|
||||
|
||||
_latchTime_ms =deviceConfig["latchTime"].toInt( _latchTime_ms );
|
||||
_refreshTimerInterval_ms = deviceConfig["rewriteTime"].toInt( _refreshTimerInterval_ms);
|
||||
setLedCount( static_cast<unsigned int>( deviceConfig["currentLedCount"].toInt(1) ) ); // property injected to reflect real led count
|
||||
setLatchTime( deviceConfig["latchTime"].toInt( _latchTime_ms ) );
|
||||
setRewriteTime ( deviceConfig["rewriteTime"].toInt( _refreshTimerInterval_ms) );
|
||||
|
||||
if ( _refreshTimerInterval_ms > 0 )
|
||||
{
|
||||
_isRefreshEnabled = true;
|
||||
|
||||
if (_refreshTimerInterval_ms <= _latchTime_ms )
|
||||
{
|
||||
int new_refresh_timer_interval = _latchTime_ms + 10;
|
||||
Warning(_log, "latchTime(%d) is bigger/equal rewriteTime(%d), set rewriteTime to %dms", _latchTime_ms, _refreshTimerInterval_ms, new_refresh_timer_interval);
|
||||
_refreshTimerInterval_ms = new_refresh_timer_interval;
|
||||
_refreshTimer->setInterval( _refreshTimerInterval_ms );
|
||||
}
|
||||
|
||||
Debug(_log, "Refresh interval = %dms",_refreshTimerInterval_ms );
|
||||
_refreshTimer->setInterval( _refreshTimerInterval_ms );
|
||||
|
||||
_lastWriteTime = QDateTime::currentDateTime();
|
||||
|
||||
this->startRefreshTimer();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -176,9 +171,9 @@ void LedDevice::stopRefreshTimer()
|
||||
int LedDevice::updateLeds(const std::vector<ColorRgb>& ledValues)
|
||||
{
|
||||
int retval = 0;
|
||||
if ( !isEnabled() || !_isDeviceReady || _isDeviceInError )
|
||||
if ( !_isEnabled || !_isOn || !_isDeviceReady || _isDeviceInError )
|
||||
{
|
||||
//std::cout << "LedDevice::updateLeds(), LedDevice NOT ready!" << std::endl;
|
||||
//std::cout << "LedDevice::updateLeds(), LedDevice NOT ready! ";
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
@@ -256,20 +251,20 @@ int LedDevice::writeBlack(int numberOfBlack)
|
||||
bool LedDevice::switchOn()
|
||||
{
|
||||
bool rc = false;
|
||||
if ( _isDeviceInitialised && ! _isDeviceReady && ! _isEnabled )
|
||||
|
||||
if ( _isOn )
|
||||
{
|
||||
_isDeviceInError = false;
|
||||
if ( open() < 0 )
|
||||
{
|
||||
rc = false;
|
||||
}
|
||||
else
|
||||
rc = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( _isEnabled &&_isDeviceInitialised )
|
||||
{
|
||||
storeState();
|
||||
|
||||
if ( powerOn() )
|
||||
{
|
||||
_isEnabled = true;
|
||||
_isOn = true;
|
||||
rc = true;
|
||||
}
|
||||
}
|
||||
@@ -281,38 +276,37 @@ bool LedDevice::switchOff()
|
||||
{
|
||||
bool rc = false;
|
||||
|
||||
if ( _isDeviceInitialised )
|
||||
if ( !_isOn )
|
||||
{
|
||||
// Disable device to ensure no standard Led updates are written/processed
|
||||
_isEnabled = false;
|
||||
_isInSwitchOff = true;
|
||||
|
||||
this->stopRefreshTimer();
|
||||
|
||||
rc = true;
|
||||
|
||||
if ( _isDeviceReady )
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( _isDeviceInitialised )
|
||||
{
|
||||
if ( _isRestoreOrigState )
|
||||
{
|
||||
//Restore devices state
|
||||
restoreState();
|
||||
}
|
||||
else
|
||||
{
|
||||
powerOff();
|
||||
}
|
||||
// Disable device to ensure no standard Led updates are written/processed
|
||||
_isOn = false;
|
||||
_isInSwitchOff = true;
|
||||
|
||||
}
|
||||
if ( close() < 0 )
|
||||
{
|
||||
rc = false;
|
||||
rc = true;
|
||||
|
||||
if ( _isDeviceReady )
|
||||
{
|
||||
if ( _isRestoreOrigState )
|
||||
{
|
||||
//Restore devices state
|
||||
restoreState();
|
||||
}
|
||||
else
|
||||
{
|
||||
powerOff();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
bool LedDevice::powerOff()
|
||||
{
|
||||
bool rc = false;
|
||||
@@ -403,7 +397,33 @@ void LedDevice::setLedCount(unsigned int ledCount)
|
||||
void LedDevice::setLatchTime( int latchTime_ms )
|
||||
{
|
||||
_latchTime_ms = latchTime_ms;
|
||||
Debug(_log, "LatchTime updated to %dms", this->getLatchTime());
|
||||
Debug(_log, "LatchTime updated to %dms", _latchTime_ms);
|
||||
}
|
||||
|
||||
void LedDevice::setRewriteTime( int rewriteTime_ms )
|
||||
{
|
||||
_refreshTimerInterval_ms = rewriteTime_ms;
|
||||
|
||||
if ( _refreshTimerInterval_ms > 0 )
|
||||
{
|
||||
|
||||
_isRefreshEnabled = true;
|
||||
|
||||
if (_refreshTimerInterval_ms <= _latchTime_ms )
|
||||
{
|
||||
int new_refresh_timer_interval = _latchTime_ms + 10;
|
||||
Warning(_log, "latchTime(%d) is bigger/equal rewriteTime(%d), set rewriteTime to %dms", _latchTime_ms, _refreshTimerInterval_ms, new_refresh_timer_interval);
|
||||
_refreshTimerInterval_ms = new_refresh_timer_interval;
|
||||
_refreshTimer->setInterval( _refreshTimerInterval_ms );
|
||||
}
|
||||
|
||||
Debug(_log, "Refresh interval = %dms",_refreshTimerInterval_ms );
|
||||
_refreshTimer->setInterval( _refreshTimerInterval_ms );
|
||||
|
||||
_lastWriteTime = QDateTime::currentDateTime();
|
||||
}
|
||||
|
||||
Debug(_log, "RewriteTime updated to %dms", _refreshTimerInterval_ms);
|
||||
}
|
||||
|
||||
void LedDevice::printLedValues(const std::vector<ColorRgb>& ledValues)
|
||||
|
Reference in New Issue
Block a user