diff --git a/Software/src/AbstractLedDevice.cpp b/Software/src/AbstractLedDevice.cpp index 3ad5143f6..83208e945 100644 --- a/Software/src/AbstractLedDevice.cpp +++ b/Software/src/AbstractLedDevice.cpp @@ -29,6 +29,11 @@ #include "PrismatikMath.hpp" #include "Settings.hpp" +void AbstractLedDevice::setSmoothSlowdown(int value) { + m_softSmoothSteps = value; + setColors(m_colorsSaved); +} + void AbstractLedDevice::setGamma(double value) { m_gamma = value; setColors(m_colorsSaved); @@ -55,6 +60,21 @@ void AbstractLedDevice::updateWBAdjustments(const QList &coefs) { setColors(m_colorsSaved); } +void AbstractLedDevice::setUsbPowerLedDisabled(bool) { + //Default implementation: not supported / unused + emit commandCompleted(true); +} + +void AbstractLedDevice::setRefreshDelay(int) { + //Default implementation: not supported / unused + emit commandCompleted(true); +} + +void AbstractLedDevice::setColorDepth(int) { + //Default implementation: not supported / unused + emit commandCompleted(true); +} + void AbstractLedDevice::updateDeviceSettings() { using namespace SettingsScope; @@ -63,6 +83,7 @@ void AbstractLedDevice::updateDeviceSettings() setLuminosityThreshold(Settings::getLuminosityThreshold()); setMinimumLuminosityThresholdEnabled(Settings::isMinimumLuminosityEnabled()); updateWBAdjustments(Settings::getLedCoefs()); + setSmoothSlowdown(Settings::getDeviceSmooth()); } /*! @@ -119,3 +140,48 @@ void AbstractLedDevice::applyColorModifications(const QList &inColors, QLi } } + +void AbstractLedDevice::setColors(const QList & colors) { + if (m_softSmoothSteps == 0) { + setColorsUnsmoothed(colors); + } else { + if (m_colorsSaved.size() != colors.size()) { + for (int i = 0; i < colors.size(); i++) { + m_colorsSaved.append(0); + } + } + + m_softSmoothIndex = 0; + m_colorsSmoothStart = m_colorsSaved; + m_colorsSmoothEnd = colors; + + setColorsUnsmoothed(m_colorsSaved); + + if (!m_softSmoothTimer) { + m_softSmoothTimer = new QTimer(this); + connect(m_softSmoothTimer, SIGNAL(timeout()), this, SLOT(softSmoothTimerTick())); + m_softSmoothTimer->setInterval(5); + } + if (!m_softSmoothTimer->isActive()) { + m_softSmoothTimer->start(); + } + } +} + +void AbstractLedDevice::softSmoothTimerTick() { + for (int i = 0; i < m_colorsSmoothStart.size(); i++) { + QColor start = m_colorsSmoothStart[i]; + QColor end = m_colorsSmoothEnd[i]; + m_colorsSaved[i] = qRgb( + start.red() + (end.red() - start.red()) * ((float)m_softSmoothIndex) / m_softSmoothSteps, + start.green() + (end.green() - start.green()) * ((float)m_softSmoothIndex) / m_softSmoothSteps, + start.blue() + (end.blue() - start.blue()) * ((float)m_softSmoothIndex) / m_softSmoothSteps); + } + + setColorsUnsmoothed(m_colorsSaved); + + if (m_softSmoothIndex >= m_softSmoothSteps) { + m_softSmoothTimer->stop(); + } + m_softSmoothIndex++; +} \ No newline at end of file diff --git a/Software/src/AbstractLedDevice.hpp b/Software/src/AbstractLedDevice.hpp index ff4313846..cdb1d1871 100644 --- a/Software/src/AbstractLedDevice.hpp +++ b/Software/src/AbstractLedDevice.hpp @@ -38,8 +38,8 @@ class AbstractLedDevice : public QObject { Q_OBJECT public: - AbstractLedDevice(QObject * parent) : QObject(parent) {} - virtual ~AbstractLedDevice(){} + AbstractLedDevice(QObject * parent) : QObject(parent){}; + virtual ~AbstractLedDevice(){}; signals: void openDeviceSuccess(bool isSuccess); @@ -58,17 +58,17 @@ class AbstractLedDevice : public QObject public slots: virtual const QString name() const = 0; virtual void open() = 0; - virtual void close() = 0; - virtual void setColors(const QList & colors) = 0; + virtual void close() = 0; + virtual void setColors(const QList & colors); virtual void switchOffLeds() = 0; - + virtual void setUsbPowerLedDisabled(bool); /*! \obsolete only form compatibility with Lightpack ver.<=5.5 hardware PWM timer period. \param value in millis */ - virtual void setRefreshDelay(int value) = 0; - virtual void setSmoothSlowdown(int value) = 0; + virtual void setRefreshDelay(int); + virtual void setSmoothSlowdown(int value); virtual void setGamma(double value); virtual void setBrightness(int value); virtual void setColorSequence(QString value) = 0; @@ -85,11 +85,15 @@ public slots: \obsolete only form compatibility with Lightpack ver.<=5.5 hardware \param value bits per channel */ - virtual void setColorDepth(int value) = 0; + virtual void setColorDepth(int); protected: + virtual void setColorsUnsmoothed(const QList & colors) = 0; virtual void applyColorModifications(const QList & inColors, QList & outColors); +private slots: + void softSmoothTimerTick(); + protected: QString m_colorSequence; double m_gamma; @@ -99,6 +103,11 @@ public slots: QList m_wbAdjustments; - QList m_colorsSaved; + int m_softSmoothIndex; + int m_softSmoothSteps; + QTimer *m_softSmoothTimer = 0; + QList m_colorsSaved; + QList m_colorsSmoothStart; + QList m_colorsSmoothEnd; QList m_colorsBuffer; }; diff --git a/Software/src/LedDeviceAdalight.cpp b/Software/src/LedDeviceAdalight.cpp index 9ff7ad89d..946f1194f 100644 --- a/Software/src/LedDeviceAdalight.cpp +++ b/Software/src/LedDeviceAdalight.cpp @@ -65,7 +65,7 @@ void LedDeviceAdalight::close() } } -void LedDeviceAdalight::setColors(const QList & colors) +void LedDeviceAdalight::setColorsUnsmoothed(const QList & colors) { // Save colors for showing changes of the brightness m_colorsSaved = colors; @@ -150,21 +150,6 @@ void LedDeviceAdalight::switchOffLeds() emit commandCompleted(ok); } -void LedDeviceAdalight::setRefreshDelay(int /*value*/) -{ - emit commandCompleted(true); -} - -void LedDeviceAdalight::setColorDepth(int /*value*/) -{ - emit commandCompleted(true); -} - -void LedDeviceAdalight::setSmoothSlowdown(int /*value*/) -{ - emit commandCompleted(true); -} - void LedDeviceAdalight::setColorSequence(QString value) { DEBUG_LOW_LEVEL << Q_FUNC_INFO << value; diff --git a/Software/src/LedDeviceAdalight.hpp b/Software/src/LedDeviceAdalight.hpp index c2e7ca9b3..e87b73205 100644 --- a/Software/src/LedDeviceAdalight.hpp +++ b/Software/src/LedDeviceAdalight.hpp @@ -41,17 +41,16 @@ public slots: const QString name() const { return "adalight"; } void open(); void close(); - void setColors(const QList & /*colors*/); void switchOffLeds(); - void setRefreshDelay(int /*value*/); - void setColorDepth(int /*value*/); - void setSmoothSlowdown(int /*value*/); void setColorSequence(QString value); void requestFirmwareVersion(); void updateDeviceSettings(); int maxLedsCount() { return 255; } virtual int defaultLedsCount() { return 25; } +protected: + void setColorsUnsmoothed(const QList & colors); + private: bool writeBuffer(const QByteArray & buff); void resizeColorsBuffer(int buffSize); diff --git a/Software/src/LedDeviceAlienFx.cpp b/Software/src/LedDeviceAlienFx.cpp index 4260e71c4..16e683314 100644 --- a/Software/src/LedDeviceAlienFx.cpp +++ b/Software/src/LedDeviceAlienFx.cpp @@ -105,7 +105,7 @@ LedDeviceAlienFx::~LedDeviceAlienFx() DEBUG_LOW_LEVEL << Q_FUNC_INFO << "destroy LedDeviceAlienFx : ILedDevice complete"; } -void LedDeviceAlienFx::setColors(const QList & colors) +void LedDeviceAlienFx::setColorsUnsmoothed(const QList & colors) { DEBUG_MID_LEVEL << Q_FUNC_INFO; if (m_isInitialized) @@ -146,21 +146,6 @@ void LedDeviceAlienFx::switchOffLeds() setColors(blackColor); } -void LedDeviceAlienFx::setRefreshDelay(int /*value*/) -{ - emit commandCompleted(true); -} - -void LedDeviceAlienFx::setColorDepth(int /*value*/) -{ - emit commandCompleted(true); -} - -void LedDeviceAlienFx::setSmoothSlowdown(int /*value*/) -{ - emit commandCompleted(true); -} - void LedDeviceAlienFx::setColorSequence(QString /*value*/) { emit commandCompleted(true); diff --git a/Software/src/LedDeviceAlienFx.hpp b/Software/src/LedDeviceAlienFx.hpp index 211ad381b..63d7d6561 100644 --- a/Software/src/LedDeviceAlienFx.hpp +++ b/Software/src/LedDeviceAlienFx.hpp @@ -43,16 +43,14 @@ public slots: const QString name() const { return "lightfx"; } void open(); void close(){}; - void setColors(const QList & colors); void switchOffLeds(); - void setRefreshDelay(int /*value*/); - void setColorDepth(int /*value*/); - void setSmoothSlowdown(int /*value*/); void setColorSequence(QString /*value*/); void requestFirmwareVersion(); int maxLedsCount() { return 1; } int defaultLedsCount() { return 1; } +protected: + virtual void setColorsUnsmoothed(const QList & colors); private: HINSTANCE m_hLfxLibrary; diff --git a/Software/src/LedDeviceArdulight.cpp b/Software/src/LedDeviceArdulight.cpp index a074e9154..a35e22eb3 100644 --- a/Software/src/LedDeviceArdulight.cpp +++ b/Software/src/LedDeviceArdulight.cpp @@ -66,7 +66,7 @@ void LedDeviceArdulight::close() } } -void LedDeviceArdulight::setColors(const QList & colors) +void LedDeviceArdulight::setColorsUnsmoothed(const QList & colors) { DEBUG_MID_LEVEL << Q_FUNC_INFO << colors; @@ -156,21 +156,6 @@ void LedDeviceArdulight::switchOffLeds() emit commandCompleted(ok); } -void LedDeviceArdulight::setRefreshDelay(int /*value*/) -{ - emit commandCompleted(true); -} - -void LedDeviceArdulight::setColorDepth(int /*value*/) -{ - emit commandCompleted(true); -} - -void LedDeviceArdulight::setSmoothSlowdown(int /*value*/) -{ - emit commandCompleted(true); -} - void LedDeviceArdulight::setColorSequence(QString value) { DEBUG_LOW_LEVEL << Q_FUNC_INFO << value; diff --git a/Software/src/LedDeviceArdulight.hpp b/Software/src/LedDeviceArdulight.hpp index ad2e477ae..11aaa356b 100644 --- a/Software/src/LedDeviceArdulight.hpp +++ b/Software/src/LedDeviceArdulight.hpp @@ -41,17 +41,16 @@ public slots: const QString name() const { return "ardulight"; } void open(); void close(); - void setColors(const QList & /*colors*/); void switchOffLeds(); - void setRefreshDelay(int /*value*/); - void setColorDepth(int /*value*/); - void setSmoothSlowdown(int /*value*/); void setColorSequence(QString value); void requestFirmwareVersion(); void updateDeviceSettings(); int maxLedsCount(){ return 255; } virtual int defaultLedsCount() { return 25; } +protected: + virtual void setColorsUnsmoothed(const QList & colors); + private: bool writeBuffer(const QByteArray & buff); void resizeColorsBuffer(int buffSize); diff --git a/Software/src/LedDeviceLightpack.cpp b/Software/src/LedDeviceLightpack.cpp index 40f954203..fcfeaac21 100644 --- a/Software/src/LedDeviceLightpack.cpp +++ b/Software/src/LedDeviceLightpack.cpp @@ -127,6 +127,12 @@ void LedDeviceLightpack::setColors(const QList & colors) emit commandCompleted(ok); } +void LedDeviceLightpack::setColorsUnsmoothed(const QList & colors) { + Q_UNUSED(colors); + qCritical("Lightpack has hardware smoothing, this should not be called"); + throw; +} + int LedDeviceLightpack::maxLedsCount() { if (m_devices.size() == 0) diff --git a/Software/src/LedDeviceLightpack.hpp b/Software/src/LedDeviceLightpack.hpp index 7fa91b219..9a2defec2 100644 --- a/Software/src/LedDeviceLightpack.hpp +++ b/Software/src/LedDeviceLightpack.hpp @@ -52,10 +52,10 @@ class LedDeviceLightpack : public AbstractLedDevice public slots: virtual const QString name() const { return "lightpack"; } virtual void open(); - virtual void close(); - virtual void setColors(const QList & colors); + virtual void close(); + virtual void setColors(const QList & colors); virtual void switchOffLeds(); - virtual void setUsbPowerLedDisabled(bool isDisabled); + virtual void setUsbPowerLedDisabled(bool value); virtual void setRefreshDelay(int value); virtual void setColorDepth(int value); virtual void setSmoothSlowdown(int value); @@ -66,6 +66,9 @@ public slots: virtual int defaultLedsCount() { return maxLedsCount(); } int lightpacksFound() { return m_devices.size(); } +protected: + virtual void setColorsUnsmoothed(const QList & colors); + private: bool readDataFromDevice(); bool writeBufferToDevice(int command, hid_device *phid_device); diff --git a/Software/src/LedDeviceVirtual.cpp b/Software/src/LedDeviceVirtual.cpp index 67abc165b..1b97264b3 100644 --- a/Software/src/LedDeviceVirtual.cpp +++ b/Software/src/LedDeviceVirtual.cpp @@ -40,7 +40,7 @@ LedDeviceVirtual::LedDeviceVirtual(QObject * parent) : AbstractLedDevice(parent) m_brightness = Settings::getDeviceBrightness(); } -void LedDeviceVirtual::setColors(const QList & colors) +void LedDeviceVirtual::setColorsUnsmoothed(const QList & colors) { if(colors.size()> 0) { @@ -74,21 +74,6 @@ void LedDeviceVirtual::switchOffLeds() emit commandCompleted(true); } -void LedDeviceVirtual::setRefreshDelay(int /*value*/) -{ - emit commandCompleted(true); -} - -void LedDeviceVirtual::setColorDepth(int /*value*/) -{ - emit commandCompleted(true); -} - -void LedDeviceVirtual::setSmoothSlowdown(int /*value*/) -{ - emit commandCompleted(true); -} - void LedDeviceVirtual::setColorSequence(QString /*value*/) { emit commandCompleted(true); diff --git a/Software/src/LedDeviceVirtual.hpp b/Software/src/LedDeviceVirtual.hpp index 2ed6eea08..974dbb062 100644 --- a/Software/src/LedDeviceVirtual.hpp +++ b/Software/src/LedDeviceVirtual.hpp @@ -40,11 +40,7 @@ public slots: const QString name() const { return "virtual"; } void open(); void close(){} - void setColors(const QList & colors); void switchOffLeds(); - void setRefreshDelay(int /*value*/); - void setColorDepth(int /*value*/); - void setSmoothSlowdown(int /*value*/); void setColorSequence(QString /*value*/); void setGamma(double value); void setBrightness(int value); @@ -52,6 +48,8 @@ public slots: int maxLedsCount() { return 255; } int defaultLedsCount() { return 10; } +protected: + virtual void setColorsUnsmoothed(const QList & colors); private: void resizeColorsBuffer(int buffSize); diff --git a/Software/src/SettingsWindow.ui b/Software/src/SettingsWindow.ui index 2ffece624..4bdf21ea9 100644 --- a/Software/src/SettingsWindow.ui +++ b/Software/src/SettingsWindow.ui @@ -1072,6 +1072,25 @@ 20 + + + + + 0 + 0 + + + + + 0 + 0 + + + + Keep lights ON after exit + + + @@ -1099,8 +1118,8 @@ - - + + 0 @@ -1108,7 +1127,20 @@ - Overall brightness: + Gamma correction: + + + + + + + margin:0px; + + + % + + + Qt::AlignCenter @@ -1143,42 +1175,6 @@ - - - - - 0 - 0 - - - - margin:0px; - - - - - - - :/icons/help.png:/icons/help.png - - - true - - - - - - - margin:0px; - - - % - - - Qt::AlignCenter - - - @@ -1210,25 +1206,6 @@ - - - - 0 - - - 100 - - - 1 - - - 100 - - - Qt::Horizontal - - - @@ -1263,26 +1240,62 @@ - - + + 0 0 - - - 0 - 0 - + + margin:0px; - Keep lights ON after exit + + + + + :/icons/help.png:/icons/help.png + + + true - + + + + + 0 + 0 + + + + Overall brightness: + + + + + + + 0 + + + 100 + + + 1 + + + 100 + + + Qt::Horizontal + + + + Qt::Vertical @@ -1295,20 +1308,21 @@ - - - - - 0 - 0 - + + + + Keep lights ON after suspend + + + + - Gamma correction: + Keep lights ON after lock computer - + @@ -1417,42 +1431,6 @@ - - - - - 0 - 0 - - - - Smoothness: - - - - - - - - 0 - 0 - - - - margin:0px; - - - - - - - :/icons/help.png:/icons/help.png - - - true - - - @@ -1519,59 +1497,6 @@ - - - - <h4>Smoothness</h4> It defines how many steps will be color changed in - - - 0 - - - 255 - - - 1 - - - 100 - - - Qt::Horizontal - - - - - - - - 0 - 0 - - - - - 50 - 0 - - - - - 60 - 16777215 - - - - 0 - - - 255 - - - 100 - - - @@ -1680,17 +1605,92 @@ - - + + + + + 0 + 0 + + - Keep lights ON after lock computer + Smoothness: - - + + + + <h4>Smoothness</h4> Defines in how many steps the color will be changed + + + 0 + + + 255 + + + 1 + + + 100 + + + Qt::Horizontal + + + + + + + + 0 + 0 + + + + + 50 + 0 + + + + + 60 + 16777215 + + + + 0 + + + 255 + + + 100 + + + + + + + + 0 + 0 + + + + margin:0px; + - Keep lights ON after suspend + + + + + :/icons/help.png:/icons/help.png + + + true @@ -2828,8 +2828,6 @@ checkBox_KeepLightsOnAfterExit spinBox_DeviceBrightness doubleSpinBox_DeviceGamma - horizontalSlider_DeviceSmooth - spinBox_DeviceSmooth comboBox_Profiles radioButton_GrabX11 radioButton_GrabMacCoreGraphics