Hyelicht 2.0
Controller application for the Hyelicht shelf. Paint on the shelf with colors, turn on the fireplace mode, and more.
|
Connects to and performs painting operations on a strip of SK9822/APA102 LEDs. More...
#include <ledstrip.h>
Public Types | |
enum | RestoreOption { RestoreColor = 0x1 , RestoreBrightness = 0x2 } |
Used as parameters to restore to choose what saved strip state to restore. More... | |
Signals | |
void | enabledChanged () const |
SPI-based communication with the LED strip has turned on or off. | |
void | deviceNameChanged () |
The SPI device filename used to communicate with the LED strip has changed. | |
void | frequencyChanged () const |
The clock frequency in Hz used for SPI communication with the LEDs has changed. | |
void | connectedChanged () |
Whether there is an open SPI connection to the LED strip has changed. | |
void | countChanged () const |
The number of LEDs in the strip has changed. | |
void | gammaCorrectionChanged () |
Whether gamma correction is turned on has changed. | |
void | gammaChanged () |
The gamma correction value has changed. | |
void | hsvBrightnessChanged () |
Whether brightness is based on color HSV value components has changed. | |
void | canRestoreChanged () |
Whether there is saved strip data that can be restored has changed. | |
Public Member Functions | |
LedStrip (QObject *parent=nullptr) | |
Create a strip of default length. | |
LedStrip (int count, QObject *parent=nullptr) | |
Create a strip of specific length. | |
~LedStrip () override | |
Cleanup on destruction. | |
bool | enabled () const |
Whether SPI-based communication with the LED strip is enabled. | |
void | setEnabled (bool enabled) |
Turn SPI-based communication with the LED strip on or off. | |
QString | deviceName () const |
The SPI device filename used to communicate with the LED strip. | |
void | setDeviceName (const QString &deviceName) |
Set the SPI device filename used to communicate with the LED strip. | |
int | frequency () const |
Clock frequency in Hz used for SPI communication with the LEDs. | |
void | setFrequency (int frequency) |
Set the clock frequency in Hz used for SPI communication with the LEDs. | |
bool | connected () const |
Whether there is an open SPI connection to the LED strip. | |
int | count () const |
The number of LEDs in the strip. | |
void | setCount (int leds) |
Set the number of LEDs in the strip. | |
bool | gammaCorrection () const |
Whether gamma correction is turned on. | |
void | setGammaCorrection (bool gammaCorrection) |
Turn gamma correction on or off. | |
qreal | gamma () const |
The gamma correction value. | |
void | setGamma (qreal gamma) |
Set the gamma correction value. | |
bool | hsvBrightness () const |
Whether brightness is based on color HSV value components. | |
void | setHsvBrightness (bool hsvBrightness) |
Set whether brightness is based on color HSV value components. | |
Q_INVOKABLE bool | setLed (int index, const QColor &color, int brightness) |
Changes a specific LED. | |
Q_INVOKABLE bool | fill (int first, int last, const QColor &color, int brightness=LED_MAX_BRIGHTNESS) |
Change a range of LEDs. | |
Q_INVOKABLE QColor | color (int index) const |
Retrieves the color of a specific LED. | |
Q_INVOKABLE QColor | colorAverage (int first, int last) const |
Retrieves the average color of a range of LEDs. | |
Q_INVOKABLE bool | setColor (int index, const QColor &color) |
Set the color of a specific LED. | |
Q_INVOKABLE bool | setColor (int first, int last, const QColor &color) |
Set the color of a range of LEDs. | |
Q_INVOKABLE int | brightness (int index) const |
Retrieves the brightness of a specific LED. | |
Q_INVOKABLE int | brightnessAverage (int first, int last) const |
Retrieves the average brightness of a range of LEDs. | |
Q_INVOKABLE bool | setBrightness (int index, int brightness) |
Set the brightness of a specific LED. | |
Q_INVOKABLE bool | setBrightness (int first, int last, int brightness) |
Set the brightness of a range of LEDs. | |
Q_INVOKABLE bool | reverse () |
Reverse the LED strip data. | |
Q_INVOKABLE bool | clear () |
Clear the LED strip. | |
Q_INVOKABLE bool | clear (int first, int last) |
Clear a range of LEDs. | |
Q_INVOKABLE bool | show () |
Write latest state to the LED strip. | |
Q_INVOKABLE void | save () |
Save current strip state for later restoration. | |
Q_INVOKABLE void | forgetSavedData () |
Forget saved strip data. | |
Q_INVOKABLE bool | canRestore () const |
Whether there is saved strip state that can be restored by calling restore(). | |
Q_INVOKABLE bool | restore (RestoreOptions options) |
Restore saved strip data if available. | |
void | classBegin () override |
Implements the QQmlParserStatus interface. | |
void | componentComplete () override |
Implements the QQmlParserStatus interface. | |
Properties | |
bool | enabled |
Toggle SPI-based communication with the LED strip. | |
QString | deviceName |
SPI device filename used to communicate with the LED strip. | |
int | frequency |
Clock frequency in Hz used for SPI communication with the LEDs. | |
bool | connected |
Whether there is an open SPI connection to the LED strip. | |
int | count |
Number of LEDs in the strip. | |
bool | gammaCorrection |
Toggle optional gamma correction using embedded LUT. | |
qreal | gamma |
Gamma correction value. | |
bool | hsvBrightness |
Toggle brightness based on color HSV value component. | |
bool | canRestore |
Whether there is saved strip state that can be restored by calling restore(). | |
Connects to and performs painting operations on a strip of SK9822/APA102 LEDs.
Handles communication with a strip of SK9822/APA102 LEDs using the Linux SPI API.
Features:
Implements QQmlParserStatus
for use from QML.
Used as parameters to restore to choose what saved strip state to restore.
Enumerator | |
---|---|
RestoreColor | Restore the color data from the saved strip state. |
RestoreBrightness | Restore the brightness data from the saved strip state. |
|
explicit |
Create a strip of default length.
Creates a strip with a default count of 1
.
parent | Parent object |
|
explicit |
|
override |
Cleanup on destruction.
Will gracefully end SPI-based communication.
int LedStrip::brightness | ( | int | index | ) | const |
Retrieves the brightness of a specific LED.
index | LED to operate on. |
0
and LED_MAX_BRIGHTNESS. int LedStrip::brightnessAverage | ( | int | first, |
int | last | ||
) | const |
Retrieves the average brightness of a range of LEDs.
first | First LED in the range. |
last | Last LED in the range. |
0
and LED_MAX_BRIGHTNESS. bool LedStrip::canRestore | ( | ) | const |
Whether there is saved strip state that can be restored by calling restore().
|
signal |
Whether there is saved strip data that can be restored has changed.
bool LedStrip::clear | ( | ) |
Clear the LED strip.
Sets color to black and brightness to 0
.
bool LedStrip::clear | ( | int | first, |
int | last | ||
) |
Clear a range of LEDs.
Sets color to black and brightness to 0
.
first | First LED in the range. |
last | Last LED in the range. |
QColor LedStrip::color | ( | int | index | ) | const |
Retrieves the color of a specific LED.
index | LED to operate on. |
QColor LedStrip::colorAverage | ( | int | first, |
int | last | ||
) | const |
Retrieves the average color of a range of LEDs.
first | First LED in the range. |
last | Last LED in the range. |
bool LedStrip::connected | ( | ) | const |
Whether there is an open SPI connection to the LED strip.
|
signal |
Whether there is an open SPI connection to the LED strip has changed.
int LedStrip::count | ( | ) | const |
The number of LEDs in the strip.
|
signal |
QString LedStrip::deviceName | ( | ) | const |
The SPI device filename used to communicate with the LED strip.
|
signal |
The SPI device filename used to communicate with the LED strip has changed.
bool LedStrip::enabled | ( | ) | const |
Whether SPI-based communication with the LED strip is enabled.
|
signal |
SPI-based communication with the LED strip has turned on or off.
bool LedStrip::fill | ( | int | first, |
int | last, | ||
const QColor & | color, | ||
int | brightness = LED_MAX_BRIGHTNESS |
||
) |
Change a range of LEDs.
first | First LED in the range. |
last | Last LED in the range. |
color | Color to set the LED range to. |
brightness | Brightness to set the LED to. Must be between 0 and LED_MAX_BRIGHTNESS. Defaults to LED_MAX_BRIGHTNESS. |
void LedStrip::forgetSavedData | ( | ) |
Forget saved strip data.
int LedStrip::frequency | ( | ) | const |
Clock frequency in Hz used for SPI communication with the LEDs.
|
signal |
The clock frequency in Hz used for SPI communication with the LEDs has changed.
qreal LedStrip::gamma | ( | ) | const |
The gamma correction value.
|
signal |
bool LedStrip::gammaCorrection | ( | ) | const |
Whether gamma correction is turned on.
Gamma correction is applied during show, just before the color data is written to the LED strip. Saved color data is not affected by this property.
If hsvBrightness is enabled, HSV-based brightness derivation is applied before gamma correction.
|
signal |
Whether gamma correction is turned on has changed.
bool LedStrip::hsvBrightness | ( | ) | const |
Whether brightness is based on color HSV value components.
The final brightness is calculated during show. Stored brightness data is not affected by this property.
If gammaCorrection is enabled, it is applied after brightness correction.
|
signal |
Whether brightness is based on color HSV value components has changed.
bool LedStrip::restore | ( | RestoreOptions | options | ) |
Restore saved strip data if available.
options | Choose the strip data to restore. Combination of RestoreOption flags. |
bool LedStrip::reverse | ( | ) |
Reverse the LED strip data.
void LedStrip::save | ( | ) |
Save current strip state for later restoration.
bool LedStrip::setBrightness | ( | int | first, |
int | last, | ||
int | brightness | ||
) |
Set the brightness of a range of LEDs.
first | First LED in the range. |
last | Last LED in the range. |
brightness | Brightness to set the LED to. Must be between 0 and LED_MAX_BRIGHTNESS. |
bool LedStrip::setBrightness | ( | int | index, |
int | brightness | ||
) |
Set the brightness of a specific LED.
index | LED to operate on. |
brightness | Brightness to set the LED to. Must be between 0 and LED_MAX_BRIGHTNESS. |
bool LedStrip::setColor | ( | int | first, |
int | last, | ||
const QColor & | color | ||
) |
Set the color of a range of LEDs.
first | First LED in the range. |
last | Last LED in the range. |
color | Color to set the LED range to. |
bool LedStrip::setColor | ( | int | index, |
const QColor & | color | ||
) |
Set the color of a specific LED.
index | LED to operate on. |
color | Color to set the LED to. |
void LedStrip::setCount | ( | int | leds | ) |
void LedStrip::setDeviceName | ( | const QString & | deviceName | ) |
Set the SPI device filename used to communicate with the LED strip.
deviceName | SPI device filename to use. |
void LedStrip::setEnabled | ( | bool | enabled | ) |
Turn SPI-based communication with the LED strip on or off.
enabled | SPI communication on or off. |
void LedStrip::setFrequency | ( | int | frequency | ) |
Set the clock frequency in Hz used for SPI communication with the LEDs.
frequency | SPI clock frequency in Hz. |
void LedStrip::setGamma | ( | qreal | gamma | ) |
Set the gamma correction value.
Will automatically call show when changed.
gamma | Gamma correction value. |
void LedStrip::setGammaCorrection | ( | bool | gammaCorrection | ) |
Turn gamma correction on or off.
Gamma correction is applied during show, just before the color data is written to the LED strip. Saved color data is not affected by this property.
Will automatically call show when toggled.
If hsvBrightness is enabled, HSV-based brightness derivation is applied before gamma correction.
gammaCorrection | Gamma correction on or off. |
void LedStrip::setHsvBrightness | ( | bool | hsvBrightness | ) |
Set whether brightness is based on color HSV value components.
When enabled, seperately set brightness is ignored. Instead, an LED's brightness between and
LED_MAX_BRIGHTNESS is set based on the HSV value component of its color.
The final brightness is calculated during show. Stored brightness data is not affected by this property.
Will automatically call show when toggled.
If gammaCorrection is enabled, it is applied after brightness correction.
hsvBrightness | HSV-based brightness on or off. |
bool LedStrip::setLed | ( | int | index, |
const QColor & | color, | ||
int | brightness | ||
) |
Changes a specific LED.
index | LED to operate on. |
color | Color to set the LED to. |
brightness | Brightness to set the LED to. Must be between 0 and LED_MAX_BRIGHTNESS. |
bool LedStrip::show | ( | ) |
Write latest state to the LED strip.
Updates the LED strip with new state after painting operations.
If gammaCorrection is true
, the color data will be gamma-corrected at this time before writing it to the strip.
|
read |
Whether there is saved strip state that can be restored by calling restore().
|
read |
Whether there is an open SPI connection to the LED strip.
Defaults to false
.
|
readwrite |
|
readwrite |
SPI device filename used to communicate with the LED strip.
Defaults to /dev/spidev0
.0.
|
readwrite |
Toggle SPI-based communication with the LED strip.
Defaults to false
.
|
readwrite |
Clock frequency in Hz used for SPI communication with the LEDs.
Defaults to 8000000
(8 Mhz).
|
readwrite |
|
readwrite |
Toggle optional gamma correction using embedded LUT.
Gamma correction is applied during show, just before the color data is written to the LED strip. Saved color data is not affected by this property.
Will automatically call show when toggled.
If hsvBrightness is enabled, HSV-based brightness derivation is applied before gamma correction.
Defaults to true
.
|
readwrite |
Toggle brightness based on color HSV value component.
When enabled, seperately set brightness is ignored. Instead, an LED's brightness between and
LED_MAX_BRIGHTNESS is set based on the HSV value component of its color.
The final brightness is calculated during show. Stored brightness data is not affected by this property.
Will automatically call show when toggled.
If gammaCorrection is enabled, it is applied after brightness correction.
Defaults to false
.