Skip to content

Commit 3d56886

Browse files
committed
Add software based smoothing for non-Lightpack devices
1 parent 2b47de9 commit 3d56886

13 files changed

+281
-265
lines changed

Software/src/AbstractLedDevice.cpp

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@
2929
#include "PrismatikMath.hpp"
3030
#include "Settings.hpp"
3131

32+
void AbstractLedDevice::setSmoothSlowdown(int value) {
33+
m_softSmoothSteps = value;
34+
setColors(m_colorsSaved);
35+
}
36+
3237
void AbstractLedDevice::setGamma(double value) {
3338
m_gamma = value;
3439
setColors(m_colorsSaved);
@@ -55,6 +60,21 @@ void AbstractLedDevice::updateWBAdjustments(const QList<WBAdjustment> &coefs) {
5560
setColors(m_colorsSaved);
5661
}
5762

63+
void AbstractLedDevice::setUsbPowerLedDisabled(bool) {
64+
//Default implementation: not supported / unused
65+
emit commandCompleted(true);
66+
}
67+
68+
void AbstractLedDevice::setRefreshDelay(int) {
69+
//Default implementation: not supported / unused
70+
emit commandCompleted(true);
71+
}
72+
73+
void AbstractLedDevice::setColorDepth(int) {
74+
//Default implementation: not supported / unused
75+
emit commandCompleted(true);
76+
}
77+
5878
void AbstractLedDevice::updateDeviceSettings()
5979
{
6080
using namespace SettingsScope;
@@ -63,6 +83,7 @@ void AbstractLedDevice::updateDeviceSettings()
6383
setLuminosityThreshold(Settings::getLuminosityThreshold());
6484
setMinimumLuminosityThresholdEnabled(Settings::isMinimumLuminosityEnabled());
6585
updateWBAdjustments(Settings::getLedCoefs());
86+
setSmoothSlowdown(Settings::getDeviceSmooth());
6687
}
6788

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

121142
}
143+
144+
void AbstractLedDevice::setColors(const QList<QRgb> & colors) {
145+
if (m_softSmoothSteps == 0) {
146+
setColorsUnsmoothed(colors);
147+
} else {
148+
if (m_colorsSaved.size() != colors.size()) {
149+
for (int i = 0; i < colors.size(); i++) {
150+
m_colorsSaved.append(0);
151+
}
152+
}
153+
154+
m_softSmoothIndex = 0;
155+
m_colorsSmoothStart = m_colorsSaved;
156+
m_colorsSmoothEnd = colors;
157+
158+
setColorsUnsmoothed(m_colorsSaved);
159+
160+
if (!m_softSmoothTimer) {
161+
m_softSmoothTimer = new QTimer(this);
162+
connect(m_softSmoothTimer, SIGNAL(timeout()), this, SLOT(softSmoothTimerTick()));
163+
m_softSmoothTimer->setInterval(20);
164+
}
165+
if (!m_softSmoothTimer->isActive()) {
166+
m_softSmoothTimer->start();
167+
}
168+
}
169+
}
170+
171+
void AbstractLedDevice::softSmoothTimerTick() {
172+
for (int i = 0; i < m_colorsSmoothStart.size(); i++) {
173+
QColor start = m_colorsSmoothStart[i];
174+
QColor end = m_colorsSmoothEnd[i];
175+
m_colorsSaved[i] = qRgb(
176+
start.red() + (end.red() - start.red()) * ((float)m_softSmoothIndex) / m_softSmoothSteps,
177+
start.green() + (end.green() - start.green()) * ((float)m_softSmoothIndex) / m_softSmoothSteps,
178+
start.blue() + (end.blue() - start.blue()) * ((float)m_softSmoothIndex) / m_softSmoothSteps);
179+
}
180+
181+
setColorsUnsmoothed(m_colorsSaved);
182+
183+
if (m_softSmoothIndex == m_softSmoothSteps) {
184+
m_softSmoothTimer->stop();
185+
}
186+
m_softSmoothIndex++;
187+
}

Software/src/AbstractLedDevice.hpp

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ class AbstractLedDevice : public QObject
3838
{
3939
Q_OBJECT
4040
public:
41-
AbstractLedDevice(QObject * parent) : QObject(parent) {}
42-
virtual ~AbstractLedDevice(){}
41+
AbstractLedDevice(QObject * parent) : QObject(parent){};
42+
virtual ~AbstractLedDevice(){};
4343

4444
signals:
4545
void openDeviceSuccess(bool isSuccess);
@@ -58,17 +58,17 @@ class AbstractLedDevice : public QObject
5858
public slots:
5959
virtual const QString name() const = 0;
6060
virtual void open() = 0;
61-
virtual void close() = 0;
62-
virtual void setColors(const QList<QRgb> & colors) = 0;
61+
virtual void close() = 0;
62+
virtual void setColors(const QList<QRgb> & colors);
6363
virtual void switchOffLeds() = 0;
64-
64+
virtual void setUsbPowerLedDisabled(bool);
6565
/*!
6666
\obsolete only form compatibility with Lightpack ver.<=5.5 hardware
6767
PWM timer period.
6868
\param value in millis
6969
*/
70-
virtual void setRefreshDelay(int value) = 0;
71-
virtual void setSmoothSlowdown(int value) = 0;
70+
virtual void setRefreshDelay(int);
71+
virtual void setSmoothSlowdown(int value);
7272
virtual void setGamma(double value);
7373
virtual void setBrightness(int value);
7474
virtual void setColorSequence(QString value) = 0;
@@ -85,11 +85,15 @@ public slots:
8585
\obsolete only form compatibility with Lightpack ver.<=5.5 hardware
8686
\param value bits per channel
8787
*/
88-
virtual void setColorDepth(int value) = 0;
88+
virtual void setColorDepth(int);
8989

9090
protected:
91+
virtual void setColorsUnsmoothed(const QList<QRgb> & colors) = 0;
9192
virtual void applyColorModifications(const QList<QRgb> & inColors, QList<StructRgb> & outColors);
9293

94+
private slots:
95+
void softSmoothTimerTick();
96+
9397
protected:
9498
QString m_colorSequence;
9599
double m_gamma;
@@ -99,6 +103,11 @@ public slots:
99103

100104
QList<WBAdjustment> m_wbAdjustments;
101105

102-
QList<QRgb> m_colorsSaved;
106+
int m_softSmoothIndex;
107+
int m_softSmoothSteps;
108+
QTimer *m_softSmoothTimer = 0;
109+
QList<QRgb> m_colorsSaved;
110+
QList<QRgb> m_colorsSmoothStart;
111+
QList<QRgb> m_colorsSmoothEnd;
103112
QList<StructRgb> m_colorsBuffer;
104113
};

Software/src/LedDeviceAdalight.cpp

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ void LedDeviceAdalight::close()
6565
}
6666
}
6767

68-
void LedDeviceAdalight::setColors(const QList<QRgb> & colors)
68+
void LedDeviceAdalight::setColorsUnsmoothed(const QList<QRgb> & colors)
6969
{
7070
// Save colors for showing changes of the brightness
7171
m_colorsSaved = colors;
@@ -150,21 +150,6 @@ void LedDeviceAdalight::switchOffLeds()
150150
emit commandCompleted(ok);
151151
}
152152

153-
void LedDeviceAdalight::setRefreshDelay(int /*value*/)
154-
{
155-
emit commandCompleted(true);
156-
}
157-
158-
void LedDeviceAdalight::setColorDepth(int /*value*/)
159-
{
160-
emit commandCompleted(true);
161-
}
162-
163-
void LedDeviceAdalight::setSmoothSlowdown(int /*value*/)
164-
{
165-
emit commandCompleted(true);
166-
}
167-
168153
void LedDeviceAdalight::setColorSequence(QString value)
169154
{
170155
DEBUG_LOW_LEVEL << Q_FUNC_INFO << value;

Software/src/LedDeviceAdalight.hpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,16 @@ public slots:
4141
const QString name() const { return "adalight"; }
4242
void open();
4343
void close();
44-
void setColors(const QList<QRgb> & /*colors*/);
4544
void switchOffLeds();
46-
void setRefreshDelay(int /*value*/);
47-
void setColorDepth(int /*value*/);
48-
void setSmoothSlowdown(int /*value*/);
4945
void setColorSequence(QString value);
5046
void requestFirmwareVersion();
5147
void updateDeviceSettings();
5248
int maxLedsCount() { return 255; }
5349
virtual int defaultLedsCount() { return 25; }
5450

51+
protected:
52+
void setColorsUnsmoothed(const QList<QRgb> & colors);
53+
5554
private:
5655
bool writeBuffer(const QByteArray & buff);
5756
void resizeColorsBuffer(int buffSize);

Software/src/LedDeviceAlienFx.cpp

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ LedDeviceAlienFx::~LedDeviceAlienFx()
105105
DEBUG_LOW_LEVEL << Q_FUNC_INFO << "destroy LedDeviceAlienFx : ILedDevice complete";
106106
}
107107

108-
void LedDeviceAlienFx::setColors(const QList<QRgb> & colors)
108+
void LedDeviceAlienFx::setColorsUnsmoothed(const QList<QRgb> & colors)
109109
{
110110
DEBUG_MID_LEVEL << Q_FUNC_INFO;
111111
if (m_isInitialized)
@@ -146,21 +146,6 @@ void LedDeviceAlienFx::switchOffLeds()
146146
setColors(blackColor);
147147
}
148148

149-
void LedDeviceAlienFx::setRefreshDelay(int /*value*/)
150-
{
151-
emit commandCompleted(true);
152-
}
153-
154-
void LedDeviceAlienFx::setColorDepth(int /*value*/)
155-
{
156-
emit commandCompleted(true);
157-
}
158-
159-
void LedDeviceAlienFx::setSmoothSlowdown(int /*value*/)
160-
{
161-
emit commandCompleted(true);
162-
}
163-
164149
void LedDeviceAlienFx::setColorSequence(QString /*value*/)
165150
{
166151
emit commandCompleted(true);

Software/src/LedDeviceAlienFx.hpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,14 @@ public slots:
4343
const QString name() const { return "lightfx"; }
4444
void open();
4545
void close(){};
46-
void setColors(const QList<QRgb> & colors);
4746
void switchOffLeds();
48-
void setRefreshDelay(int /*value*/);
49-
void setColorDepth(int /*value*/);
50-
void setSmoothSlowdown(int /*value*/);
5147
void setColorSequence(QString /*value*/);
5248
void requestFirmwareVersion();
5349
int maxLedsCount() { return 1; }
5450
int defaultLedsCount() { return 1; }
5551

52+
protected:
53+
virtual void setColorsUnsmoothed(const QList<QRgb> & colors);
5654

5755
private:
5856
HINSTANCE m_hLfxLibrary;

Software/src/LedDeviceArdulight.cpp

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ void LedDeviceArdulight::close()
6666
}
6767
}
6868

69-
void LedDeviceArdulight::setColors(const QList<QRgb> & colors)
69+
void LedDeviceArdulight::setColorsUnsmoothed(const QList<QRgb> & colors)
7070
{
7171
DEBUG_MID_LEVEL << Q_FUNC_INFO << colors;
7272

@@ -156,21 +156,6 @@ void LedDeviceArdulight::switchOffLeds()
156156
emit commandCompleted(ok);
157157
}
158158

159-
void LedDeviceArdulight::setRefreshDelay(int /*value*/)
160-
{
161-
emit commandCompleted(true);
162-
}
163-
164-
void LedDeviceArdulight::setColorDepth(int /*value*/)
165-
{
166-
emit commandCompleted(true);
167-
}
168-
169-
void LedDeviceArdulight::setSmoothSlowdown(int /*value*/)
170-
{
171-
emit commandCompleted(true);
172-
}
173-
174159
void LedDeviceArdulight::setColorSequence(QString value)
175160
{
176161
DEBUG_LOW_LEVEL << Q_FUNC_INFO << value;

Software/src/LedDeviceArdulight.hpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,16 @@ public slots:
4141
const QString name() const { return "ardulight"; }
4242
void open();
4343
void close();
44-
void setColors(const QList<QRgb> & /*colors*/);
4544
void switchOffLeds();
46-
void setRefreshDelay(int /*value*/);
47-
void setColorDepth(int /*value*/);
48-
void setSmoothSlowdown(int /*value*/);
4945
void setColorSequence(QString value);
5046
void requestFirmwareVersion();
5147
void updateDeviceSettings();
5248
int maxLedsCount(){ return 255; }
5349
virtual int defaultLedsCount() { return 25; }
5450

51+
protected:
52+
virtual void setColorsUnsmoothed(const QList<QRgb> & colors);
53+
5554
private:
5655
bool writeBuffer(const QByteArray & buff);
5756
void resizeColorsBuffer(int buffSize);

Software/src/LedDeviceLightpack.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,12 @@ void LedDeviceLightpack::setColors(const QList<QRgb> & colors)
127127
emit commandCompleted(ok);
128128
}
129129

130+
void LedDeviceLightpack::setColorsUnsmoothed(const QList<QRgb> & colors) {
131+
Q_UNUSED(colors);
132+
qCritical("Lightpack has hardware smoothing, this should not be called");
133+
throw;
134+
}
135+
130136
int LedDeviceLightpack::maxLedsCount()
131137
{
132138
if (m_devices.size() == 0)

Software/src/LedDeviceLightpack.hpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ class LedDeviceLightpack : public AbstractLedDevice
5252
public slots:
5353
virtual const QString name() const { return "lightpack"; }
5454
virtual void open();
55-
virtual void close();
56-
virtual void setColors(const QList<QRgb> & colors);
55+
virtual void close();
56+
virtual void setColors(const QList<QRgb> & colors);
5757
virtual void switchOffLeds();
58-
virtual void setUsbPowerLedDisabled(bool isDisabled);
58+
virtual void setUsbPowerLedDisabled(bool value);
5959
virtual void setRefreshDelay(int value);
6060
virtual void setColorDepth(int value);
6161
virtual void setSmoothSlowdown(int value);
@@ -66,6 +66,9 @@ public slots:
6666
virtual int defaultLedsCount() { return maxLedsCount(); }
6767
int lightpacksFound() { return m_devices.size(); }
6868

69+
protected:
70+
virtual void setColorsUnsmoothed(const QList<QRgb> & colors);
71+
6972
private:
7073
bool readDataFromDevice();
7174
bool writeBufferToDevice(int command, hid_device *phid_device);

0 commit comments

Comments
 (0)