10#include <QQmlParserStatus>
12#include <linux/spi/spidev.h>
19#define LED_MAX_BRIGHTNESS 0x1F
44class LedStrip :
public QObject,
public QQmlParserStatus
47 Q_INTERFACES(QQmlParserStatus)
169 Q_FLAG(RestoreOptions)
177 explicit LedStrip(QObject *parent =
nullptr);
394 Q_INVOKABLE QColor
color(
int index)
const;
402 Q_INVOKABLE QColor
colorAverage(
int first,
int last)
const;
419 Q_INVOKABLE
bool setColor(
int first,
int last,
const QColor &
color);
465 Q_INVOKABLE
bool clear();
475 Q_INVOKABLE
bool clear(
int first,
int last);
487 Q_INVOKABLE
bool show();
496 Q_INVOKABLE
void save();
527 Q_INVOKABLE
bool restore(RestoreOptions options);
605 void updateData(
int count);
607 void clearInternal(uint32_t *data,
int first,
int last);
611 QString m_deviceName;
618 bool m_gammaCorrection;
621 uint32_t *m_gammaCorrectedData;
623 bool m_hsvBrightness;
624 uint32_t *m_brightnessCorrectedData;
627 spi_ioc_transfer m_message[3];
631 uint32_t *m_savedData;
638Q_DECLARE_OPERATORS_FOR_FLAGS(LedStrip::RestoreOptions)
Connects to and performs painting operations on a strip of SK9822/APA102 LEDs.
Definition ledstrip.h:45
int frequency
Clock frequency in Hz used for SPI communication with the LEDs.
Definition ledstrip.h:79
Q_INVOKABLE QColor color(int index) const
Retrieves the color of a specific LED.
Definition ledstrip.cpp:278
Q_INVOKABLE bool reverse()
Reverse the LED strip data.
Definition ledstrip.cpp:483
RestoreOption
Used as parameters to restore to choose what saved strip state to restore.
Definition ledstrip.h:164
@ RestoreColor
Restore the color data from the saved strip state.
Definition ledstrip.h:165
@ RestoreBrightness
Restore the brightness data from the saved strip state.
Definition ledstrip.h:166
void frequencyChanged() const
The clock frequency in Hz used for SPI communication with the LEDs has changed.
bool enabled
Toggle SPI-based communication with the LED strip.
Definition ledstrip.h:59
void canRestoreChanged()
Whether there is saved strip data that can be restored has changed.
~LedStrip() override
Cleanup on destruction.
Definition ledstrip.cpp:57
void setGamma(qreal gamma)
Set the gamma correction value.
Definition ledstrip.cpp:190
void setDeviceName(const QString &deviceName)
Set the SPI device filename used to communicate with the LED strip.
Definition ledstrip.cpp:97
Q_INVOKABLE bool clear()
Clear the LED strip.
Definition ledstrip.cpp:509
void classBegin() override
Implements the QQmlParserStatus interface.
Definition ledstrip.cpp:658
void setGammaCorrection(bool gammaCorrection)
Turn gamma correction on or off.
Definition ledstrip.cpp:168
void setFrequency(int frequency)
Set the clock frequency in Hz used for SPI communication with the LEDs.
Definition ledstrip.cpp:115
bool gammaCorrection
Toggle optional gamma correction using embedded LUT.
Definition ledstrip.h:117
bool connected
Whether there is an open SPI connection to the LED strip.
Definition ledstrip.h:88
int count
Number of LEDs in the strip.
Definition ledstrip.h:97
Q_INVOKABLE int brightness(int index) const
Retrieves the brightness of a specific LED.
Definition ledstrip.cpp:382
void deviceNameChanged()
The SPI device filename used to communicate with the LED strip has changed.
void setCount(int leds)
Set the number of LEDs in the strip.
Definition ledstrip.cpp:138
Q_INVOKABLE QColor colorAverage(int first, int last) const
Retrieves the average color of a range of LEDs.
Definition ledstrip.cpp:289
QString deviceName
SPI device filename used to communicate with the LED strip.
Definition ledstrip.h:69
Q_INVOKABLE bool fill(int first, int last, const QColor &color, int brightness=LED_MAX_BRIGHTNESS)
Change a range of LEDs.
Definition ledstrip.cpp:250
void hsvBrightnessChanged()
Whether brightness is based on color HSV value components has changed.
void gammaChanged()
The gamma correction value has changed.
Q_INVOKABLE bool restore(RestoreOptions options)
Restore saved strip data if available.
Definition ledstrip.cpp:624
void componentComplete() override
Implements the QQmlParserStatus interface.
Definition ledstrip.cpp:663
Q_INVOKABLE void save()
Save current strip state for later restoration.
Definition ledstrip.cpp:594
Q_INVOKABLE bool setBrightness(int index, int brightness)
Set the brightness of a specific LED.
Definition ledstrip.cpp:440
Q_INVOKABLE bool show()
Write latest state to the LED strip.
Definition ledstrip.cpp:533
void countChanged() const
The number of LEDs in the strip has changed.
void gammaCorrectionChanged()
Whether gamma correction is turned on has changed.
Q_INVOKABLE void forgetSavedData()
Forget saved strip data.
Definition ledstrip.cpp:612
bool canRestore
Whether there is saved strip state that can be restored by calling restore().
Definition ledstrip.h:160
void setHsvBrightness(bool hsvBrightness)
Set whether brightness is based on color HSV value components.
Definition ledstrip.cpp:212
bool hsvBrightness
Toggle brightness based on color HSV value component.
Definition ledstrip.h:151
Q_INVOKABLE int brightnessAverage(int first, int last) const
Retrieves the average brightness of a range of LEDs.
Definition ledstrip.cpp:393
Q_INVOKABLE bool setLed(int index, const QColor &color, int brightness)
Changes a specific LED.
Definition ledstrip.cpp:229
void connectedChanged()
Whether there is an open SPI connection to the LED strip has changed.
void setEnabled(bool enabled)
Turn SPI-based communication with the LED strip on or off.
Definition ledstrip.cpp:77
Q_INVOKABLE bool setColor(int index, const QColor &color)
Set the color of a specific LED.
Definition ledstrip.cpp:345
void enabledChanged() const
SPI-based communication with the LED strip has turned on or off.
qreal gamma
Gamma correction value.
Definition ledstrip.h:129
#define LED_MAX_BRIGHTNESS
Definition ledstrip.h:19