mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02: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:
parent
fbd8167458
commit
4aabe175cd
@ -1263,7 +1263,7 @@ function startWizardWLED(e)
|
|||||||
var hostAddress = conf_editor.getEditor("root.specificOptions.host").getValue();
|
var hostAddress = conf_editor.getEditor("root.specificOptions.host").getValue();
|
||||||
if(hostAddress != "")
|
if(hostAddress != "")
|
||||||
{
|
{
|
||||||
getProperties_wled(hostAddress);
|
getProperties_wled(hostAddress,"info");
|
||||||
identify_wled(hostAddress)
|
identify_wled(hostAddress)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
1
docs/development/LedDevice_Flows.drawio
Normal file
1
docs/development/LedDevice_Flows.drawio
Normal file
File diff suppressed because one or more lines are too long
BIN
docs/development/LedDevice_Flows.png
Normal file
BIN
docs/development/LedDevice_Flows.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 389 KiB |
@ -473,6 +473,9 @@ private slots:
|
|||||||
///
|
///
|
||||||
void handleNewVideoMode(VideoMode mode) { _currVideoMode = mode; }
|
void handleNewVideoMode(VideoMode mode) { _currVideoMode = mode; }
|
||||||
|
|
||||||
|
|
||||||
|
void handlPriorityChangedLedDevice(const quint8& priority);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class HyperionDaemon;
|
friend class HyperionDaemon;
|
||||||
friend class HyperionIManager;
|
friend class HyperionIManager;
|
||||||
|
@ -109,6 +109,13 @@ public:
|
|||||||
///
|
///
|
||||||
int getCurrentPriority() const { return _currentPriority; }
|
int getCurrentPriority() const { return _currentPriority; }
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Returns the previous priority before current priority
|
||||||
|
///
|
||||||
|
/// @return The previous priority
|
||||||
|
///
|
||||||
|
int getPreviousPriority() const { return _previousPriority; }
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Returns the state (enabled/disabled) of a specific priority channel
|
/// Returns the state (enabled/disabled) of a specific priority channel
|
||||||
/// @param priority The priority channel
|
/// @param priority The priority channel
|
||||||
@ -193,13 +200,6 @@ signals:
|
|||||||
///
|
///
|
||||||
void timeRunner();
|
void timeRunner();
|
||||||
|
|
||||||
///
|
|
||||||
/// @brief A priority has been added (registerInput()) or deleted, method clear or timeout clear
|
|
||||||
/// @param priority The priority which has changed
|
|
||||||
/// @param state If true it was added else it was removed!
|
|
||||||
///
|
|
||||||
void priorityChanged(quint8 priority, bool state);
|
|
||||||
|
|
||||||
///
|
///
|
||||||
/// @brief Emits whenever the visible priority has changed
|
/// @brief Emits whenever the visible priority has changed
|
||||||
/// @param priority The new visible priority
|
/// @param priority The new visible priority
|
||||||
@ -261,6 +261,9 @@ private:
|
|||||||
/// The current priority (lowest value in _activeInputs)
|
/// The current priority (lowest value in _activeInputs)
|
||||||
int _currentPriority;
|
int _currentPriority;
|
||||||
|
|
||||||
|
/// The previous priority before current priority
|
||||||
|
int _previousPriority;
|
||||||
|
|
||||||
/// The manual select priority set with setPriority
|
/// The manual select priority set with setPriority
|
||||||
int _manualSelectedPriority;
|
int _manualSelectedPriority;
|
||||||
|
|
||||||
|
@ -64,13 +64,6 @@ public:
|
|||||||
///
|
///
|
||||||
void setLedCount(unsigned int ledCount);
|
void setLedCount(unsigned int ledCount);
|
||||||
|
|
||||||
///
|
|
||||||
/// @brief Check, if the device is enabled.
|
|
||||||
///
|
|
||||||
/// @return True, if enabled
|
|
||||||
///
|
|
||||||
bool isEnabled() const { return _isEnabled; }
|
|
||||||
|
|
||||||
///
|
///
|
||||||
/// @brief Set a device's latch time.
|
/// @brief Set a device's latch time.
|
||||||
///
|
///
|
||||||
@ -81,6 +74,15 @@ public:
|
|||||||
///
|
///
|
||||||
void setLatchTime(int latchTime_ms);
|
void setLatchTime(int latchTime_ms);
|
||||||
|
|
||||||
|
///
|
||||||
|
/// @brief Set a device's rewrite time.
|
||||||
|
///
|
||||||
|
/// Rewrite time is the time frame a devices requires to be refreshed, if no updated happened in the meantime.
|
||||||
|
///
|
||||||
|
/// @param[in] rewriteTime_ms Rewrite time in milliseconds
|
||||||
|
///
|
||||||
|
void setRewriteTime(int rewriteTime_ms);
|
||||||
|
|
||||||
///
|
///
|
||||||
/// @brief Discover devices of this type available (for configuration).
|
/// @brief Discover devices of this type available (for configuration).
|
||||||
/// @note Mainly used for network devices. Allows to find devices, e.g. via ssdp, mDNS or cloud ways.
|
/// @note Mainly used for network devices. Allows to find devices, e.g. via ssdp, mDNS or cloud ways.
|
||||||
@ -172,15 +174,6 @@ public slots:
|
|||||||
///
|
///
|
||||||
virtual int updateLeds(const std::vector<ColorRgb>& ledValues);
|
virtual int updateLeds(const std::vector<ColorRgb>& ledValues);
|
||||||
|
|
||||||
///
|
|
||||||
/// @brief Enables/disables the device for output.
|
|
||||||
///
|
|
||||||
/// If the device is not ready, it will not be enabled.
|
|
||||||
///
|
|
||||||
/// @param[in] enable The new state of the device
|
|
||||||
///
|
|
||||||
void setEnable(bool enable);
|
|
||||||
|
|
||||||
///
|
///
|
||||||
/// @brief Get the currently defined LatchTime.
|
/// @brief Get the currently defined LatchTime.
|
||||||
///
|
///
|
||||||
@ -188,6 +181,13 @@ public slots:
|
|||||||
///
|
///
|
||||||
int getLatchTime() const { return _latchTime_ms; }
|
int getLatchTime() const { return _latchTime_ms; }
|
||||||
|
|
||||||
|
///
|
||||||
|
/// @brief Get the currently defined RewriteTime.
|
||||||
|
///
|
||||||
|
/// @return Rewrite time in milliseconds
|
||||||
|
///
|
||||||
|
int getRewriteTime() const { return _refreshTimerInterval_ms; }
|
||||||
|
|
||||||
///
|
///
|
||||||
/// @brief Get the number of LEDs supported by the device.
|
/// @brief Get the number of LEDs supported by the device.
|
||||||
///
|
///
|
||||||
@ -212,7 +212,46 @@ public slots:
|
|||||||
///
|
///
|
||||||
/// @return True, if enabled
|
/// @return True, if enabled
|
||||||
///
|
///
|
||||||
inline bool componentState() const { return isEnabled(); }
|
inline bool componentState() const { return _isEnabled; }
|
||||||
|
|
||||||
|
///
|
||||||
|
/// @brief Enables the device for output.
|
||||||
|
///
|
||||||
|
/// If the device is not ready, it will not be enabled.
|
||||||
|
///
|
||||||
|
void enable();
|
||||||
|
|
||||||
|
///
|
||||||
|
/// @brief Disables the device for output.
|
||||||
|
///
|
||||||
|
void disable();
|
||||||
|
|
||||||
|
///
|
||||||
|
/// @brief Switch the LEDs on.
|
||||||
|
///
|
||||||
|
/// Takes care that the device is opened and powered-on.
|
||||||
|
/// Depending on the configuration, the device may store its current state for later restore.
|
||||||
|
/// @see powerOn, storeState
|
||||||
|
///
|
||||||
|
/// @return True, if success
|
||||||
|
///
|
||||||
|
virtual bool switchOn();
|
||||||
|
|
||||||
|
///
|
||||||
|
/// @brief Switch the LEDs off.
|
||||||
|
///
|
||||||
|
/// Takes care that the LEDs and device are switched-off and device is closed.
|
||||||
|
/// Depending on the configuration, the device may be powered-off or restored to its previous state.
|
||||||
|
/// @see powerOff, restoreState
|
||||||
|
///
|
||||||
|
/// @return True, if success
|
||||||
|
///
|
||||||
|
virtual bool switchOff();
|
||||||
|
|
||||||
|
bool switchOnOff(bool onState)
|
||||||
|
{
|
||||||
|
return onState == true ? switchOn() : switchOff();
|
||||||
|
}
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
///
|
///
|
||||||
@ -264,28 +303,6 @@ protected:
|
|||||||
///
|
///
|
||||||
virtual int writeBlack(int numberOfBlack=1);
|
virtual int writeBlack(int numberOfBlack=1);
|
||||||
|
|
||||||
///
|
|
||||||
/// @brief Switch the LEDs on.
|
|
||||||
///
|
|
||||||
/// Takes care that the device is opened and powered-on.
|
|
||||||
/// Depending on the configuration, the device may store its current state for later restore.
|
|
||||||
/// @see powerOn, storeState
|
|
||||||
///
|
|
||||||
/// @return True, if success
|
|
||||||
///
|
|
||||||
virtual bool switchOn();
|
|
||||||
|
|
||||||
///
|
|
||||||
/// @brief Switch the LEDs off.
|
|
||||||
///
|
|
||||||
/// Takes care that the LEDs and device are switched-off and device is closed.
|
|
||||||
/// Depending on the configuration, the device may be powered-off or restored to its previous state.
|
|
||||||
/// @see powerOff, restoreState
|
|
||||||
///
|
|
||||||
/// @return True, if success
|
|
||||||
///
|
|
||||||
virtual bool switchOff();
|
|
||||||
|
|
||||||
///
|
///
|
||||||
/// @brief Power-/turn on the LED-device.
|
/// @brief Power-/turn on the LED-device.
|
||||||
///
|
///
|
||||||
@ -378,6 +395,9 @@ protected:
|
|||||||
/// Is the device ready for processing?
|
/// Is the device ready for processing?
|
||||||
bool _isDeviceReady;
|
bool _isDeviceReady;
|
||||||
|
|
||||||
|
/// Is the device switched on?
|
||||||
|
bool _isOn;
|
||||||
|
|
||||||
/// Is the device in error state and stopped?
|
/// Is the device in error state and stopped?
|
||||||
bool _isDeviceInError;
|
bool _isDeviceInError;
|
||||||
|
|
||||||
|
@ -90,8 +90,27 @@ signals:
|
|||||||
///
|
///
|
||||||
int updateLeds(const std::vector<ColorRgb>& ledValues);
|
int updateLeds(const std::vector<ColorRgb>& ledValues);
|
||||||
|
|
||||||
void setEnable(bool enable);
|
///
|
||||||
void closeLedDevice();
|
/// @brief Enables the LED-Device.
|
||||||
|
///
|
||||||
|
void enable();
|
||||||
|
|
||||||
|
///
|
||||||
|
/// @brief Disables the LED-Device.
|
||||||
|
///
|
||||||
|
void disable();
|
||||||
|
|
||||||
|
///
|
||||||
|
/// @brief Switch the LEDs on.
|
||||||
|
///
|
||||||
|
void switchOn();
|
||||||
|
|
||||||
|
///
|
||||||
|
/// @brief Switch the LEDs off.
|
||||||
|
///
|
||||||
|
void switchOff();
|
||||||
|
|
||||||
|
void stopLedDevice();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
///
|
///
|
||||||
|
@ -87,6 +87,7 @@ void Hyperion::start()
|
|||||||
|
|
||||||
// connect Hyperion::update with Muxer visible priority changes as muxer updates independent
|
// 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::update);
|
||||||
|
connect(&_muxer, &PriorityMuxer::visiblePriorityChanged, this, &Hyperion::handlPriorityChangedLedDevice);
|
||||||
connect(&_muxer, &PriorityMuxer::visibleComponentChanged, this, &Hyperion::handleVisibleComponentChanged);
|
connect(&_muxer, &PriorityMuxer::visibleComponentChanged, this, &Hyperion::handleVisibleComponentChanged);
|
||||||
|
|
||||||
// listens for ComponentRegister changes of COMP_ALL to perform core enable/disable actions
|
// listens for ComponentRegister changes of COMP_ALL to perform core enable/disable actions
|
||||||
@ -530,6 +531,26 @@ void Hyperion::handleVisibleComponentChanged(hyperion::Components comp)
|
|||||||
_raw2ledAdjustment->setBacklightEnabled((comp != hyperion::COMP_COLOR && comp != hyperion::COMP_EFFECT));
|
_raw2ledAdjustment->setBacklightEnabled((comp != hyperion::COMP_COLOR && comp != hyperion::COMP_EFFECT));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Hyperion::handlPriorityChangedLedDevice(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()
|
void Hyperion::update()
|
||||||
{
|
{
|
||||||
// Obtain the current priority channel
|
// Obtain the current priority channel
|
||||||
|
@ -18,6 +18,7 @@ PriorityMuxer::PriorityMuxer(int ledCount, QObject * parent)
|
|||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
, _log(Logger::getInstance("HYPERION"))
|
, _log(Logger::getInstance("HYPERION"))
|
||||||
, _currentPriority(PriorityMuxer::LOWEST_PRIORITY)
|
, _currentPriority(PriorityMuxer::LOWEST_PRIORITY)
|
||||||
|
, _previousPriority(_currentPriority)
|
||||||
, _manualSelectedPriority(256)
|
, _manualSelectedPriority(256)
|
||||||
, _activeInputs()
|
, _activeInputs()
|
||||||
, _lowestPriorityInfo()
|
, _lowestPriorityInfo()
|
||||||
@ -156,7 +157,6 @@ void PriorityMuxer::registerInput(int priority, hyperion::Components component,
|
|||||||
if(newInput)
|
if(newInput)
|
||||||
{
|
{
|
||||||
Debug(_log,"Register new input '%s/%s' with priority %d as inactive", QSTRING_CSTR(origin), hyperion::componentToIdString(component), priority);
|
Debug(_log,"Register new input '%s/%s' with priority %d as inactive", QSTRING_CSTR(origin), hyperion::componentToIdString(component), priority);
|
||||||
emit priorityChanged(priority, true);
|
|
||||||
emit prioritiesChanged();
|
emit prioritiesChanged();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -255,7 +255,6 @@ bool PriorityMuxer::clearInput(uint8_t priority)
|
|||||||
Debug(_log,"Removed source priority %d",priority);
|
Debug(_log,"Removed source priority %d",priority);
|
||||||
// on clear success update _currentPriority
|
// on clear success update _currentPriority
|
||||||
setCurrentTime();
|
setCurrentTime();
|
||||||
emit priorityChanged(priority, false);
|
|
||||||
emit prioritiesChanged();
|
emit prioritiesChanged();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -266,6 +265,7 @@ void PriorityMuxer::clearAll(bool forceClearAll)
|
|||||||
{
|
{
|
||||||
if (forceClearAll)
|
if (forceClearAll)
|
||||||
{
|
{
|
||||||
|
_previousPriority = _currentPriority;
|
||||||
_activeInputs.clear();
|
_activeInputs.clear();
|
||||||
_currentPriority = PriorityMuxer::LOWEST_PRIORITY;
|
_currentPriority = PriorityMuxer::LOWEST_PRIORITY;
|
||||||
_activeInputs[_currentPriority] = _lowestPriorityInfo;
|
_activeInputs[_currentPriority] = _lowestPriorityInfo;
|
||||||
@ -296,7 +296,6 @@ void PriorityMuxer::setCurrentTime()
|
|||||||
quint8 tPrio = infoIt->priority;
|
quint8 tPrio = infoIt->priority;
|
||||||
infoIt = _activeInputs.erase(infoIt);
|
infoIt = _activeInputs.erase(infoIt);
|
||||||
Debug(_log,"Timeout clear for priority %d",tPrio);
|
Debug(_log,"Timeout clear for priority %d",tPrio);
|
||||||
emit priorityChanged(tPrio, false);
|
|
||||||
emit prioritiesChanged();
|
emit prioritiesChanged();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -329,6 +328,7 @@ void PriorityMuxer::setCurrentTime()
|
|||||||
// apply & emit on change (after apply!)
|
// apply & emit on change (after apply!)
|
||||||
if (_currentPriority != newPriority)
|
if (_currentPriority != newPriority)
|
||||||
{
|
{
|
||||||
|
_previousPriority = _currentPriority;
|
||||||
_currentPriority = newPriority;
|
_currentPriority = newPriority;
|
||||||
Debug(_log, "Set visible priority to %d", newPriority);
|
Debug(_log, "Set visible priority to %d", newPriority);
|
||||||
emit visiblePriorityChanged(newPriority);
|
emit visiblePriorityChanged(newPriority);
|
||||||
|
@ -28,6 +28,7 @@ LedDevice::LedDevice(const QJsonObject& deviceConfig, QObject* parent)
|
|||||||
, _isEnabled(false)
|
, _isEnabled(false)
|
||||||
, _isDeviceInitialised(false)
|
, _isDeviceInitialised(false)
|
||||||
, _isDeviceReady(false)
|
, _isDeviceReady(false)
|
||||||
|
, _isOn(false)
|
||||||
, _isDeviceInError(false)
|
, _isDeviceInError(false)
|
||||||
, _isInSwitchOff (false)
|
, _isInSwitchOff (false)
|
||||||
, _lastWriteTime(QDateTime::currentDateTime())
|
, _lastWriteTime(QDateTime::currentDateTime())
|
||||||
@ -62,14 +63,15 @@ void LedDevice::start()
|
|||||||
{
|
{
|
||||||
// Everything is OK -> enable device
|
// Everything is OK -> enable device
|
||||||
_isDeviceInitialised = true;
|
_isDeviceInitialised = true;
|
||||||
setEnable(true);
|
this->enable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LedDevice::stop()
|
void LedDevice::stop()
|
||||||
{
|
{
|
||||||
setEnable(false);
|
this->disable();
|
||||||
this->stopRefreshTimer();
|
this->stopRefreshTimer();
|
||||||
|
Info(_log, " Stopped LedDevice '%s'", QSTRING_CSTR(_activeDeviceType) );
|
||||||
}
|
}
|
||||||
|
|
||||||
int LedDevice::open()
|
int LedDevice::open()
|
||||||
@ -99,27 +101,39 @@ void LedDevice::setInError(const QString& errorMsg)
|
|||||||
emit enableStateChanged(_isEnabled);
|
emit enableStateChanged(_isEnabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LedDevice::setEnable(bool enable)
|
void LedDevice::enable()
|
||||||
{
|
{
|
||||||
bool isSwitched = false;
|
if ( !_isEnabled )
|
||||||
// switch off device when disabled, default: set black to LEDs when they should go off
|
|
||||||
if ( _isEnabled && !enable)
|
|
||||||
{
|
{
|
||||||
isSwitched = switchOff();
|
_isDeviceInError = false;
|
||||||
}
|
|
||||||
else
|
if ( ! _isDeviceReady )
|
||||||
{
|
|
||||||
// switch on device when enabled
|
|
||||||
if ( !_isEnabled && enable)
|
|
||||||
{
|
{
|
||||||
isSwitched = switchOn();
|
open();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( _isDeviceReady )
|
||||||
|
{
|
||||||
|
_isEnabled = true;
|
||||||
|
if ( switchOn() )
|
||||||
|
{
|
||||||
|
emit enableStateChanged(_isEnabled);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ( isSwitched )
|
void LedDevice::disable()
|
||||||
|
{
|
||||||
|
if ( _isEnabled )
|
||||||
{
|
{
|
||||||
_isEnabled = enable;
|
_isEnabled = false;
|
||||||
emit enableStateChanged(enable);
|
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() );
|
Debug(_log, "deviceConfig: [%s]", QString(QJsonDocument(_devConfig).toJson(QJsonDocument::Compact)).toUtf8().constData() );
|
||||||
|
|
||||||
_colorOrder = deviceConfig["colorOrder"].toString("RGB");
|
_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 );
|
setLedCount( static_cast<unsigned int>( deviceConfig["currentLedCount"].toInt(1) ) ); // property injected to reflect real led count
|
||||||
_refreshTimerInterval_ms = deviceConfig["rewriteTime"].toInt( _refreshTimerInterval_ms);
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -176,9 +171,9 @@ void LedDevice::stopRefreshTimer()
|
|||||||
int LedDevice::updateLeds(const std::vector<ColorRgb>& ledValues)
|
int LedDevice::updateLeds(const std::vector<ColorRgb>& ledValues)
|
||||||
{
|
{
|
||||||
int retval = 0;
|
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;
|
return -1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -256,20 +251,20 @@ int LedDevice::writeBlack(int numberOfBlack)
|
|||||||
bool LedDevice::switchOn()
|
bool LedDevice::switchOn()
|
||||||
{
|
{
|
||||||
bool rc = false;
|
bool rc = false;
|
||||||
if ( _isDeviceInitialised && ! _isDeviceReady && ! _isEnabled )
|
|
||||||
|
if ( _isOn )
|
||||||
{
|
{
|
||||||
_isDeviceInError = false;
|
rc = true;
|
||||||
if ( open() < 0 )
|
}
|
||||||
{
|
else
|
||||||
rc = false;
|
{
|
||||||
}
|
if ( _isEnabled &&_isDeviceInitialised )
|
||||||
else
|
|
||||||
{
|
{
|
||||||
storeState();
|
storeState();
|
||||||
|
|
||||||
if ( powerOn() )
|
if ( powerOn() )
|
||||||
{
|
{
|
||||||
_isEnabled = true;
|
_isOn = true;
|
||||||
rc = true;
|
rc = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -281,38 +276,37 @@ bool LedDevice::switchOff()
|
|||||||
{
|
{
|
||||||
bool rc = false;
|
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;
|
rc = true;
|
||||||
|
}
|
||||||
if ( _isDeviceReady )
|
else
|
||||||
|
{
|
||||||
|
if ( _isDeviceInitialised )
|
||||||
{
|
{
|
||||||
if ( _isRestoreOrigState )
|
// Disable device to ensure no standard Led updates are written/processed
|
||||||
{
|
_isOn = false;
|
||||||
//Restore devices state
|
_isInSwitchOff = true;
|
||||||
restoreState();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
powerOff();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
rc = true;
|
||||||
if ( close() < 0 )
|
|
||||||
{
|
if ( _isDeviceReady )
|
||||||
rc = false;
|
{
|
||||||
|
if ( _isRestoreOrigState )
|
||||||
|
{
|
||||||
|
//Restore devices state
|
||||||
|
restoreState();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
powerOff();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool LedDevice::powerOff()
|
bool LedDevice::powerOff()
|
||||||
{
|
{
|
||||||
bool rc = false;
|
bool rc = false;
|
||||||
@ -403,7 +397,33 @@ void LedDevice::setLedCount(unsigned int ledCount)
|
|||||||
void LedDevice::setLatchTime( int latchTime_ms )
|
void LedDevice::setLatchTime( int latchTime_ms )
|
||||||
{
|
{
|
||||||
_latchTime_ms = 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)
|
void LedDevice::printLedValues(const std::vector<ColorRgb>& ledValues)
|
||||||
|
@ -52,14 +52,19 @@ void LedDeviceWrapper::createLedDevice(const QJsonObject& config)
|
|||||||
thread->setObjectName("LedDeviceThread");
|
thread->setObjectName("LedDeviceThread");
|
||||||
_ledDevice = LedDeviceFactory::construct(config);
|
_ledDevice = LedDeviceFactory::construct(config);
|
||||||
_ledDevice->moveToThread(thread);
|
_ledDevice->moveToThread(thread);
|
||||||
|
|
||||||
// setup thread management
|
// setup thread management
|
||||||
connect(thread, &QThread::started, _ledDevice, &LedDevice::start);
|
connect(thread, &QThread::started, _ledDevice, &LedDevice::start);
|
||||||
|
|
||||||
// further signals
|
// further signals
|
||||||
connect(this, &LedDeviceWrapper::updateLeds, _ledDevice, &LedDevice::updateLeds, Qt::QueuedConnection);
|
connect(this, &LedDeviceWrapper::updateLeds, _ledDevice, &LedDevice::updateLeds, Qt::QueuedConnection);
|
||||||
connect(this, &LedDeviceWrapper::setEnable, _ledDevice, &LedDevice::setEnable);
|
|
||||||
connect(this, &LedDeviceWrapper::closeLedDevice, _ledDevice, &LedDevice::stop, Qt::BlockingQueuedConnection);
|
connect(this, &LedDeviceWrapper::enable, _ledDevice, &LedDevice::enable);
|
||||||
|
connect(this, &LedDeviceWrapper::disable, _ledDevice, &LedDevice::disable);
|
||||||
|
|
||||||
|
connect(this, &LedDeviceWrapper::switchOn, _ledDevice, &LedDevice::switchOn);
|
||||||
|
connect(this, &LedDeviceWrapper::switchOff, _ledDevice, &LedDevice::switchOff);
|
||||||
|
|
||||||
|
connect(this, &LedDeviceWrapper::stopLedDevice, _ledDevice, &LedDevice::stop, Qt::BlockingQueuedConnection);
|
||||||
|
|
||||||
connect(_ledDevice, &LedDevice::enableStateChanged, this, &LedDeviceWrapper::handleInternalEnableState, Qt::QueuedConnection);
|
connect(_ledDevice, &LedDevice::enableStateChanged, this, &LedDeviceWrapper::handleInternalEnableState, Qt::QueuedConnection);
|
||||||
|
|
||||||
@ -155,7 +160,14 @@ void LedDeviceWrapper::handleComponentState(hyperion::Components component, bool
|
|||||||
{
|
{
|
||||||
if(component == hyperion::COMP_LEDDEVICE)
|
if(component == hyperion::COMP_LEDDEVICE)
|
||||||
{
|
{
|
||||||
emit setEnable(state);
|
if ( state )
|
||||||
|
{
|
||||||
|
emit enable();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
emit disable();
|
||||||
|
}
|
||||||
|
|
||||||
//Get device's state, considering situations where it is not ready
|
//Get device's state, considering situations where it is not ready
|
||||||
bool deviceState = false;
|
bool deviceState = false;
|
||||||
@ -169,13 +181,17 @@ void LedDeviceWrapper::handleInternalEnableState(bool newState)
|
|||||||
{
|
{
|
||||||
_hyperion->setNewComponentState(hyperion::COMP_LEDDEVICE, newState);
|
_hyperion->setNewComponentState(hyperion::COMP_LEDDEVICE, newState);
|
||||||
_enabled = newState;
|
_enabled = newState;
|
||||||
|
|
||||||
|
if (_enabled)
|
||||||
|
{
|
||||||
|
_hyperion->update();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LedDeviceWrapper::stopDeviceThread()
|
void LedDeviceWrapper::stopDeviceThread()
|
||||||
{
|
{
|
||||||
// turns the LEDs off & stop refresh timers
|
// turns the LEDs off & stop refresh timers
|
||||||
emit closeLedDevice();
|
emit stopLedDevice();
|
||||||
std::cout << "[hyperiond LedDeviceWrapper] <INFO> LedDevice \'" << QSTRING_CSTR(getActiveDeviceType()) << "\' closed" << std::endl;
|
|
||||||
|
|
||||||
// get current thread
|
// get current thread
|
||||||
QThread* oldThread = _ledDevice->thread();
|
QThread* oldThread = _ledDevice->thread();
|
||||||
|
@ -116,11 +116,12 @@ LedDeviceNanoleaf::~LedDeviceNanoleaf()
|
|||||||
bool LedDeviceNanoleaf::init(const QJsonObject &deviceConfig)
|
bool LedDeviceNanoleaf::init(const QJsonObject &deviceConfig)
|
||||||
{
|
{
|
||||||
// Overwrite non supported/required features
|
// Overwrite non supported/required features
|
||||||
_devConfig["latchTime"] = 0;
|
setLatchTime(0);
|
||||||
|
setRewriteTime(0);
|
||||||
|
|
||||||
if (deviceConfig["rewriteTime"].toInt(0) > 0)
|
if (deviceConfig["rewriteTime"].toInt(0) > 0)
|
||||||
{
|
{
|
||||||
Info (_log, "Device Nanoleaf does not require rewrites. Refresh time is ignored.");
|
Info (_log, "Device Nanoleaf does not require rewrites. Refresh time is ignored.");
|
||||||
_devConfig["rewriteTime"] = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DebugIf(verbose, _log, "deviceConfig: [%s]", QString(QJsonDocument(_devConfig).toJson(QJsonDocument::Compact)).toUtf8().constData() );
|
DebugIf(verbose, _log, "deviceConfig: [%s]", QString(QJsonDocument(_devConfig).toJson(QJsonDocument::Compact)).toUtf8().constData() );
|
||||||
@ -133,7 +134,7 @@ bool LedDeviceNanoleaf::init(const QJsonObject &deviceConfig)
|
|||||||
Debug(_log, "DeviceType : %s", QSTRING_CSTR( this->getActiveDeviceType() ));
|
Debug(_log, "DeviceType : %s", QSTRING_CSTR( this->getActiveDeviceType() ));
|
||||||
Debug(_log, "LedCount : %u", configuredLedCount);
|
Debug(_log, "LedCount : %u", configuredLedCount);
|
||||||
Debug(_log, "ColorOrder : %s", QSTRING_CSTR( this->getColorOrder() ));
|
Debug(_log, "ColorOrder : %s", QSTRING_CSTR( this->getColorOrder() ));
|
||||||
Debug(_log, "RefreshTime : %d", _refreshTimerInterval_ms);
|
Debug(_log, "RewriteTime : %d", this->getRewriteTime());
|
||||||
Debug(_log, "LatchTime : %d", this->getLatchTime());
|
Debug(_log, "LatchTime : %d", this->getLatchTime());
|
||||||
|
|
||||||
// Read panel organisation configuration
|
// Read panel organisation configuration
|
||||||
@ -356,8 +357,6 @@ int LedDeviceNanoleaf::open()
|
|||||||
int retval = -1;
|
int retval = -1;
|
||||||
_isDeviceReady = false;
|
_isDeviceReady = false;
|
||||||
|
|
||||||
// Set Nanoleaf to External Control (UDP) mode
|
|
||||||
Debug(_log, "Set Nanoleaf to External Control (UDP) streaming mode");
|
|
||||||
QJsonDocument responseDoc = changeToExternalControlMode();
|
QJsonDocument responseDoc = changeToExternalControlMode();
|
||||||
// Resolve port for Light Panels
|
// Resolve port for Light Panels
|
||||||
QJsonObject jsonStreamControllInfo = responseDoc.object();
|
QJsonObject jsonStreamControllInfo = responseDoc.object();
|
||||||
@ -488,6 +487,8 @@ bool LedDeviceNanoleaf::powerOn()
|
|||||||
{
|
{
|
||||||
if ( _isDeviceReady)
|
if ( _isDeviceReady)
|
||||||
{
|
{
|
||||||
|
changeToExternalControlMode();
|
||||||
|
|
||||||
//Power-on Nanoleaf device
|
//Power-on Nanoleaf device
|
||||||
_restApi->setPath(API_STATE);
|
_restApi->setPath(API_STATE);
|
||||||
_restApi->put( getOnOffRequest(true) );
|
_restApi->put( getOnOffRequest(true) );
|
||||||
@ -514,6 +515,7 @@ QString LedDeviceNanoleaf::getOnOffRequest(bool isOn) const
|
|||||||
|
|
||||||
QJsonDocument LedDeviceNanoleaf::changeToExternalControlMode()
|
QJsonDocument LedDeviceNanoleaf::changeToExternalControlMode()
|
||||||
{
|
{
|
||||||
|
Debug(_log, "Set Nanoleaf to External Control (UDP) streaming mode");
|
||||||
_extControlVersion = EXTCTRLVER_V2;
|
_extControlVersion = EXTCTRLVER_V2;
|
||||||
//Enable UDP Mode v2
|
//Enable UDP Mode v2
|
||||||
|
|
||||||
|
@ -215,15 +215,10 @@ QJsonObject LedDeviceWled::getProperties(const QJsonObject& params)
|
|||||||
apiPort = API_DEFAULT_PORT;
|
apiPort = API_DEFAULT_PORT;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( filter.startsWith("/") )
|
|
||||||
filter.remove(0,1);
|
|
||||||
|
|
||||||
initRestAPI(apiHost, apiPort);
|
initRestAPI(apiHost, apiPort);
|
||||||
_restApi->setPath(API_PATH_INFO);
|
_restApi->setPath(filter);
|
||||||
|
|
||||||
// Perform request
|
httpResponse response = _restApi->get();
|
||||||
// TODO: WLED::getProperties - Check, if filter is supported
|
|
||||||
httpResponse response = _restApi->put(filter);
|
|
||||||
if ( response.error() )
|
if ( response.error() )
|
||||||
{
|
{
|
||||||
Warning (_log, "%s get properties failed with error: '%s'", QSTRING_CSTR(_activeDeviceType), QSTRING_CSTR(response.getErrorReason()));
|
Warning (_log, "%s get properties failed with error: '%s'", QSTRING_CSTR(_activeDeviceType), QSTRING_CSTR(response.getErrorReason()));
|
||||||
|
@ -997,10 +997,11 @@ LedDevice* LedDeviceYeelight::construct(const QJsonObject &deviceConfig)
|
|||||||
bool LedDeviceYeelight::init(const QJsonObject &deviceConfig)
|
bool LedDeviceYeelight::init(const QJsonObject &deviceConfig)
|
||||||
{
|
{
|
||||||
// Overwrite non supported/required features
|
// Overwrite non supported/required features
|
||||||
|
setRewriteTime(0);
|
||||||
|
|
||||||
if (deviceConfig["rewriteTime"].toInt(0) > 0)
|
if (deviceConfig["rewriteTime"].toInt(0) > 0)
|
||||||
{
|
{
|
||||||
Info (_log, "Yeelights do not require rewrites. Refresh time is ignored.");
|
Info (_log, "Yeelights do not require rewrites. Refresh time is ignored.");
|
||||||
_devConfig["rewriteTime"] = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DebugIf(verbose, _log, "deviceConfig: [%s]", QString(QJsonDocument(_devConfig).toJson(QJsonDocument::Compact)).toUtf8().constData() );
|
DebugIf(verbose, _log, "deviceConfig: [%s]", QString(QJsonDocument(_devConfig).toJson(QJsonDocument::Compact)).toUtf8().constData() );
|
||||||
@ -1012,7 +1013,7 @@ bool LedDeviceYeelight::init(const QJsonObject &deviceConfig)
|
|||||||
Debug(_log, "DeviceType : %s", QSTRING_CSTR( this->getActiveDeviceType() ));
|
Debug(_log, "DeviceType : %s", QSTRING_CSTR( this->getActiveDeviceType() ));
|
||||||
Debug(_log, "LedCount : %u", this->getLedCount());
|
Debug(_log, "LedCount : %u", this->getLedCount());
|
||||||
Debug(_log, "ColorOrder : %s", QSTRING_CSTR( this->getColorOrder() ));
|
Debug(_log, "ColorOrder : %s", QSTRING_CSTR( this->getColorOrder() ));
|
||||||
Debug(_log, "RefreshTime : %d", _refreshTimerInterval_ms);
|
Debug(_log, "RewriteTime : %d", this->getRewriteTime());
|
||||||
Debug(_log, "LatchTime : %d", this->getLatchTime());
|
Debug(_log, "LatchTime : %d", this->getLatchTime());
|
||||||
|
|
||||||
//Get device specific configuration
|
//Get device specific configuration
|
||||||
|
@ -193,7 +193,7 @@ void ProviderRs232::setInError(const QString& errorMsg)
|
|||||||
|
|
||||||
int ProviderRs232::writeBytes(const qint64 size, const uint8_t *data)
|
int ProviderRs232::writeBytes(const qint64 size, const uint8_t *data)
|
||||||
{
|
{
|
||||||
DebugIf(_isInSwitchOff, _log, "_inClosing [%d], enabled [%d], _deviceReady [%d], _frameDropCounter [%d]", _isInSwitchOff, this->isEnabled(), _isDeviceReady, _frameDropCounter);
|
DebugIf(_isInSwitchOff, _log, "_inClosing [%d], enabled [%d], _deviceReady [%d], _frameDropCounter [%d]", _isInSwitchOff, _isEnabled, _isDeviceReady, _frameDropCounter);
|
||||||
|
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
if (!_rs232Port.isOpen())
|
if (!_rs232Port.isOpen())
|
||||||
@ -249,7 +249,7 @@ int ProviderRs232::writeBytes(const qint64 size, const uint8_t *data)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DebugIf(_isInSwitchOff, _log, "[%d], _inClosing[%d], enabled [%d], _deviceReady [%d]", rc, _isInSwitchOff, this->isEnabled(), _isDeviceReady);
|
DebugIf(_isInSwitchOff, _log, "[%d], _inClosing[%d], enabled [%d], _deviceReady [%d]", rc, _isInSwitchOff, _isEnabled, _isDeviceReady);
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user