Hyelicht 2.0
Controller application for the Hyelicht shelf. Paint on the shelf with colors, turn on the fireplace mode, and more.
Loading...
Searching...
No Matches
Public Types | Signals | Public Member Functions | Properties | List of all members
LedStrip Class Reference

Connects to and performs painting operations on a strip of SK9822/APA102 LEDs. More...

#include <ledstrip.h>

Inheritance diagram for LedStrip:
Inheritance graph
[legend]
Collaboration diagram for LedStrip:
Collaboration graph
[legend]

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().
 

Detailed Description

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.

See also
QQmlParserStatus

Member Enumeration Documentation

◆ RestoreOption

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.

Constructor & Destructor Documentation

◆ LedStrip() [1/2]

LedStrip::LedStrip ( QObject *  parent = nullptr)
explicit

Create a strip of default length.

Creates a strip with a default count of 1.

Parameters
parentParent object

◆ LedStrip() [2/2]

LedStrip::LedStrip ( int  count,
QObject *  parent = nullptr 
)
explicit

Create a strip of specific length.

Parameters
countInitializes the count property. count is the number of LEDs in the strip.
parentParent object

◆ ~LedStrip()

LedStrip::~LedStrip ( )
override

Cleanup on destruction.

Will gracefully end SPI-based communication.

Member Function Documentation

◆ brightness()

int LedStrip::brightness ( int  index) const

Retrieves the brightness of a specific LED.

Parameters
indexLED to operate on.
Returns
Brightness of the LED. Will be between 0 and LED_MAX_BRIGHTNESS.

◆ brightnessAverage()

int LedStrip::brightnessAverage ( int  first,
int  last 
) const

Retrieves the average brightness of a range of LEDs.

Parameters
firstFirst LED in the range.
lastLast LED in the range.
Returns
Average brightness of the LED range. Will be between 0 and LED_MAX_BRIGHTNESS.

◆ canRestore()

bool LedStrip::canRestore ( ) const

Whether there is saved strip state that can be restored by calling restore().

Returns
Saved strip data available.
See also
save
forgetSavedData
canRestoreChanged
restore

◆ canRestoreChanged

void LedStrip::canRestoreChanged ( )
signal

Whether there is saved strip data that can be restored has changed.

See also
canRestore
save
forgetSavedData
restore

◆ clear() [1/2]

bool LedStrip::clear ( )

Clear the LED strip.

Sets color to black and brightness to 0.

Returns
Success.

◆ clear() [2/2]

bool LedStrip::clear ( int  first,
int  last 
)

Clear a range of LEDs.

Sets color to black and brightness to 0.

Parameters
firstFirst LED in the range.
lastLast LED in the range.
Returns
Success.

◆ color()

QColor LedStrip::color ( int  index) const

Retrieves the color of a specific LED.

Parameters
indexLED to operate on.
Returns
Color of the LED.

◆ colorAverage()

QColor LedStrip::colorAverage ( int  first,
int  last 
) const

Retrieves the average color of a range of LEDs.

Parameters
firstFirst LED in the range.
lastLast LED in the range.
Returns
Average color of the LED range.

◆ connected()

bool LedStrip::connected ( ) const

Whether there is an open SPI connection to the LED strip.

Returns
SPI connection established or not.
See also
connectedChanged
enabled
setEnabled
enabledChanged

◆ connectedChanged

void LedStrip::connectedChanged ( )
signal

Whether there is an open SPI connection to the LED strip has changed.

See also
connected
enabled
setEnabled
enabledChanged

◆ count()

int LedStrip::count ( ) const

The number of LEDs in the strip.

Returns
Number of LEDs.
See also
count (property)
setCount
countChanged

◆ countChanged

void LedStrip::countChanged ( ) const
signal

The number of LEDs in the strip has changed.

See also
count
setCount

◆ deviceName()

QString LedStrip::deviceName ( ) const

The SPI device filename used to communicate with the LED strip.

Returns
SPI device filename in use.
See also
deviceName (property)
setDeviceName
deviceNameChanged
frequency

◆ deviceNameChanged

void LedStrip::deviceNameChanged ( )
signal

The SPI device filename used to communicate with the LED strip has changed.

See also
deviceName
setDeviceName

◆ enabled()

bool LedStrip::enabled ( ) const

Whether SPI-based communication with the LED strip is enabled.

Returns
SPI communication on or off.
See also
enabled (property)
setEnabled
enabledChanged

◆ enabledChanged

void LedStrip::enabledChanged ( ) const
signal

SPI-based communication with the LED strip has turned on or off.

See also
enabled
setEnabled

◆ fill()

bool LedStrip::fill ( int  first,
int  last,
const QColor &  color,
int  brightness = LED_MAX_BRIGHTNESS 
)

Change a range of LEDs.

Parameters
firstFirst LED in the range.
lastLast LED in the range.
colorColor to set the LED range to.
brightnessBrightness to set the LED to. Must be between 0 and LED_MAX_BRIGHTNESS. Defaults to LED_MAX_BRIGHTNESS.
Returns
Success.

◆ forgetSavedData()

void LedStrip::forgetSavedData ( )

Forget saved strip data.

See also
save
canRestore
canRestoreChanged
restore

◆ frequency()

int LedStrip::frequency ( ) const

Clock frequency in Hz used for SPI communication with the LEDs.

Returns
SPI clock frequency in Hz.
See also
frequency (property)
setFrequency
frequencyChanged
deviceName

◆ frequencyChanged

void LedStrip::frequencyChanged ( ) const
signal

The clock frequency in Hz used for SPI communication with the LEDs has changed.

See also
frequency
setFrequency

◆ gamma()

qreal LedStrip::gamma ( ) const

The gamma correction value.

Returns
Gamma correction value.
See also
gamma (property)
setGamma
gammaChanged
gammaCorrection

◆ gammaChanged

void LedStrip::gammaChanged ( )
signal

The gamma correction value has changed.

See also
gamma
setGamma

◆ gammaCorrection()

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.

Returns
Gamma correction is turned on or off.
See also
gammaCorrection (property)
setGammaCorrection
gammaCorrectionChanged
gamma
hsvBrightness

◆ gammaCorrectionChanged

void LedStrip::gammaCorrectionChanged ( )
signal

Whether gamma correction is turned on has changed.

See also
gammaCorrection
setGammaCorrection

◆ hsvBrightness()

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.

Returns
HSV-based brightness on or off.
See also
hsvBrightness (property)
setHsvBrightness
hsvBrightnessChanged
gammaCorrection

◆ hsvBrightnessChanged

void LedStrip::hsvBrightnessChanged ( )
signal

Whether brightness is based on color HSV value components has changed.

See also
hsvBrightness
setHsvBrightness

◆ restore()

bool LedStrip::restore ( RestoreOptions  options)

Restore saved strip data if available.

Parameters
optionsChoose the strip data to restore. Combination of RestoreOption flags.
Returns
Success
See also
RestoreOption
save
forgetSavedData
canRestore
canRestoreChanged

◆ reverse()

bool LedStrip::reverse ( )

Reverse the LED strip data.

Returns
Success.

◆ save()

void LedStrip::save ( )

Save current strip state for later restoration.

See also
forgetSavedData
canRestore
canRestoreChanged
restore

◆ setBrightness() [1/2]

bool LedStrip::setBrightness ( int  first,
int  last,
int  brightness 
)

Set the brightness of a range of LEDs.

Parameters
firstFirst LED in the range.
lastLast LED in the range.
brightnessBrightness to set the LED to. Must be between 0 and LED_MAX_BRIGHTNESS.
Returns
Success.

◆ setBrightness() [2/2]

bool LedStrip::setBrightness ( int  index,
int  brightness 
)

Set the brightness of a specific LED.

Parameters
indexLED to operate on.
brightnessBrightness to set the LED to. Must be between 0 and LED_MAX_BRIGHTNESS.
Returns
Success.

◆ setColor() [1/2]

bool LedStrip::setColor ( int  first,
int  last,
const QColor &  color 
)

Set the color of a range of LEDs.

Parameters
firstFirst LED in the range.
lastLast LED in the range.
colorColor to set the LED range to.
Returns
Success.

◆ setColor() [2/2]

bool LedStrip::setColor ( int  index,
const QColor &  color 
)

Set the color of a specific LED.

Parameters
indexLED to operate on.
colorColor to set the LED to.
Returns
Success.

◆ setCount()

void LedStrip::setCount ( int  leds)

Set the number of LEDs in the strip.

Parameters
ledsNumber of LEDs.
See also
count
countChanged

◆ setDeviceName()

void LedStrip::setDeviceName ( const QString &  deviceName)

Set the SPI device filename used to communicate with the LED strip.

Parameters
deviceNameSPI device filename to use.
See also
deviceName
deviceNameChanged
frequency

◆ setEnabled()

void LedStrip::setEnabled ( bool  enabled)

Turn SPI-based communication with the LED strip on or off.

Parameters
enabledSPI communication on or off.
See also
enabled
enabledChanged

◆ setFrequency()

void LedStrip::setFrequency ( int  frequency)

Set the clock frequency in Hz used for SPI communication with the LEDs.

Parameters
frequencySPI clock frequency in Hz.
See also
frequency
frequencyChanged
deviceName

◆ setGamma()

void LedStrip::setGamma ( qreal  gamma)

Set the gamma correction value.

Will automatically call show when changed.

Parameters
gammaGamma correction value.
See also
gamma
gammaChanged
gammaCorrection

◆ setGammaCorrection()

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.

Parameters
gammaCorrectionGamma correction on or off.
See also
gammaCorrection
gammaCorrectionChanged
gamma
hsvBrightness

◆ setHsvBrightness()

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.

Parameters
hsvBrightnessHSV-based brightness on or off.
See also
hsvBrightness
hsvBrightnessChanged
gammaCorrection

◆ setLed()

bool LedStrip::setLed ( int  index,
const QColor &  color,
int  brightness 
)

Changes a specific LED.

Parameters
indexLED to operate on.
colorColor to set the LED to.
brightnessBrightness to set the LED to. Must be between 0 and LED_MAX_BRIGHTNESS.
Returns
Success.

◆ show()

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.

Returns
Success.
See also
gammaCorrection

Property Documentation

◆ canRestore

bool LedStrip::canRestore
read

Whether there is saved strip state that can be restored by calling restore().

See also
canRestoreChanged
save
forgetSavedData
restore

◆ connected

bool LedStrip::connected
read

Whether there is an open SPI connection to the LED strip.

Defaults to false.

See also
connectedChanged
enabled

◆ count

int LedStrip::count
readwrite

Number of LEDs in the strip.

Defaults to 1.

See also
setCount
countChanged

◆ deviceName

QString LedStrip::deviceName
readwrite

SPI device filename used to communicate with the LED strip.

Defaults to /dev/spidev0.0.

See also
setDeviceName
deviceNameChanged
frequency

◆ enabled

bool LedStrip::enabled
readwrite

Toggle SPI-based communication with the LED strip.

Defaults to false.

See also
setEnabled
enabledChanged
deviceName
frequency
connected

◆ frequency

int LedStrip::frequency
readwrite

Clock frequency in Hz used for SPI communication with the LEDs.

Defaults to 8000000 (8 Mhz).

See also
setFrequency
frequencyChanged
deviceName

◆ gamma

qreal LedStrip::gamma
readwrite

Gamma correction value.

Will automatically call show when changed.

Defaults to 2.6.

See also
setGammaCorrection
gammaCorrectionChanged
gamma

◆ gammaCorrection

bool LedStrip::gammaCorrection
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.

See also
setGammaCorrection
gammaCorrectionChanged
gamma
hsvBrightness

◆ hsvBrightness

bool LedStrip::hsvBrightness
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.

See also
setHsvBrightness
hsvBrightnessChanged
gammaCorrection

The documentation for this class was generated from the following files: