Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions Software/src/AbstractLedDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -55,6 +60,21 @@ void AbstractLedDevice::updateWBAdjustments(const QList<WBAdjustment> &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;
Expand All @@ -63,6 +83,7 @@ void AbstractLedDevice::updateDeviceSettings()
setLuminosityThreshold(Settings::getLuminosityThreshold());
setMinimumLuminosityThresholdEnabled(Settings::isMinimumLuminosityEnabled());
updateWBAdjustments(Settings::getLedCoefs());
setSmoothSlowdown(Settings::getDeviceSmooth());
}

/*!
Expand Down Expand Up @@ -119,3 +140,48 @@ void AbstractLedDevice::applyColorModifications(const QList<QRgb> &inColors, QLi
}

}

void AbstractLedDevice::setColors(const QList<QRgb> & 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++;
}
27 changes: 18 additions & 9 deletions Software/src/AbstractLedDevice.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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<QRgb> & colors) = 0;
virtual void close() = 0;
virtual void setColors(const QList<QRgb> & 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;
Expand All @@ -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<QRgb> & colors) = 0;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like there is something wrong with indentation.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. This thing is not merge-ready. It is a PR so my CI builds it automatically for testing, but this approach seems to be too much for the device to handle. Additionally, the smoothing algorithm (which I took from the LP firmware) behaves differently when the number of updates is different. I'm still looking for a good solution

virtual void applyColorModifications(const QList<QRgb> & inColors, QList<StructRgb> & outColors);

private slots:
void softSmoothTimerTick();

protected:
QString m_colorSequence;
double m_gamma;
Expand All @@ -99,6 +103,11 @@ public slots:

QList<WBAdjustment> m_wbAdjustments;

QList<QRgb> m_colorsSaved;
int m_softSmoothIndex;
int m_softSmoothSteps;
QTimer *m_softSmoothTimer = 0;
QList<QRgb> m_colorsSaved;
QList<QRgb> m_colorsSmoothStart;
QList<QRgb> m_colorsSmoothEnd;
QList<StructRgb> m_colorsBuffer;
};
17 changes: 1 addition & 16 deletions Software/src/LedDeviceAdalight.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ void LedDeviceAdalight::close()
}
}

void LedDeviceAdalight::setColors(const QList<QRgb> & colors)
void LedDeviceAdalight::setColorsUnsmoothed(const QList<QRgb> & colors)
{
// Save colors for showing changes of the brightness
m_colorsSaved = colors;
Expand Down Expand Up @@ -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;
Expand Down
7 changes: 3 additions & 4 deletions Software/src/LedDeviceAdalight.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,16 @@ public slots:
const QString name() const { return "adalight"; }
void open();
void close();
void setColors(const QList<QRgb> & /*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<QRgb> & colors);

private:
bool writeBuffer(const QByteArray & buff);
void resizeColorsBuffer(int buffSize);
Expand Down
17 changes: 1 addition & 16 deletions Software/src/LedDeviceAlienFx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ LedDeviceAlienFx::~LedDeviceAlienFx()
DEBUG_LOW_LEVEL << Q_FUNC_INFO << "destroy LedDeviceAlienFx : ILedDevice complete";
}

void LedDeviceAlienFx::setColors(const QList<QRgb> & colors)
void LedDeviceAlienFx::setColorsUnsmoothed(const QList<QRgb> & colors)
{
DEBUG_MID_LEVEL << Q_FUNC_INFO;
if (m_isInitialized)
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 2 additions & 4 deletions Software/src/LedDeviceAlienFx.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,14 @@ public slots:
const QString name() const { return "lightfx"; }
void open();
void close(){};
void setColors(const QList<QRgb> & 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<QRgb> & colors);

private:
HINSTANCE m_hLfxLibrary;
Expand Down
17 changes: 1 addition & 16 deletions Software/src/LedDeviceArdulight.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void LedDeviceArdulight::close()
}
}

void LedDeviceArdulight::setColors(const QList<QRgb> & colors)
void LedDeviceArdulight::setColorsUnsmoothed(const QList<QRgb> & colors)
{
DEBUG_MID_LEVEL << Q_FUNC_INFO << colors;

Expand Down Expand Up @@ -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;
Expand Down
7 changes: 3 additions & 4 deletions Software/src/LedDeviceArdulight.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,16 @@ public slots:
const QString name() const { return "ardulight"; }
void open();
void close();
void setColors(const QList<QRgb> & /*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<QRgb> & colors);

private:
bool writeBuffer(const QByteArray & buff);
void resizeColorsBuffer(int buffSize);
Expand Down
6 changes: 6 additions & 0 deletions Software/src/LedDeviceLightpack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ void LedDeviceLightpack::setColors(const QList<QRgb> & colors)
emit commandCompleted(ok);
}

void LedDeviceLightpack::setColorsUnsmoothed(const QList<QRgb> & colors) {
Q_UNUSED(colors);
qCritical("Lightpack has hardware smoothing, this should not be called");
throw;
}

int LedDeviceLightpack::maxLedsCount()
{
if (m_devices.size() == 0)
Expand Down
9 changes: 6 additions & 3 deletions Software/src/LedDeviceLightpack.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<QRgb> & colors);
virtual void close();
virtual void setColors(const QList<QRgb> & 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);
Expand All @@ -66,6 +66,9 @@ public slots:
virtual int defaultLedsCount() { return maxLedsCount(); }
int lightpacksFound() { return m_devices.size(); }

protected:
virtual void setColorsUnsmoothed(const QList<QRgb> & colors);

private:
bool readDataFromDevice();
bool writeBufferToDevice(int command, hid_device *phid_device);
Expand Down
17 changes: 1 addition & 16 deletions Software/src/LedDeviceVirtual.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ LedDeviceVirtual::LedDeviceVirtual(QObject * parent) : AbstractLedDevice(parent)
m_brightness = Settings::getDeviceBrightness();
}

void LedDeviceVirtual::setColors(const QList<QRgb> & colors)
void LedDeviceVirtual::setColorsUnsmoothed(const QList<QRgb> & colors)
{
if(colors.size()> 0)
{
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 2 additions & 4 deletions Software/src/LedDeviceVirtual.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,16 @@ public slots:
const QString name() const { return "virtual"; }
void open();
void close(){}
void setColors(const QList<QRgb> & 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);
void requestFirmwareVersion();
int maxLedsCount() { return 255; }
int defaultLedsCount() { return 10; }

protected:
virtual void setColorsUnsmoothed(const QList<QRgb> & colors);

private:
void resizeColorsBuffer(int buffSize);
Expand Down
Loading