mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
Added 'rainbow' boot sequence
Moved color transform to utils lib
This commit is contained in:
29
libsrc/bootsequence/CMakeLists.txt
Normal file
29
libsrc/bootsequence/CMakeLists.txt
Normal file
@@ -0,0 +1,29 @@
|
||||
|
||||
# Define the current source locations
|
||||
SET(CURRENT_HEADER_DIR ${CMAKE_SOURCE_DIR}/include/bootsequence)
|
||||
SET(CURRENT_SOURCE_DIR ${CMAKE_SOURCE_DIR}/libsrc/bootsequence)
|
||||
|
||||
# Group the headers that go through the MOC compiler
|
||||
SET(BootsequenceQT_HEADERS
|
||||
${CURRENT_HEADER_DIR}/RainbowBootSequence.h
|
||||
)
|
||||
|
||||
SET(BootsequenceHEADERS
|
||||
)
|
||||
|
||||
SET(BootsequenceSOURCES
|
||||
${CURRENT_SOURCE_DIR}/RainbowBootSequence.cpp
|
||||
)
|
||||
|
||||
QT4_WRAP_CPP(BootsequenceHEADERS_MOC ${BootsequenceQT_HEADERS})
|
||||
|
||||
add_library(bootsequence
|
||||
${BootsequenceHEADERS}
|
||||
${BootsequenceQT_HEADERS}
|
||||
${BootsequenceHEADERS_MOC}
|
||||
${BootsequenceSOURCES}
|
||||
)
|
||||
|
||||
target_link_libraries(bootsequence
|
||||
hyperion
|
||||
${QT_LIBRARIES})
|
54
libsrc/bootsequence/RainbowBootSequence.cpp
Normal file
54
libsrc/bootsequence/RainbowBootSequence.cpp
Normal file
@@ -0,0 +1,54 @@
|
||||
|
||||
#include <utils/HsvTransform.h>
|
||||
|
||||
#include <bootsequence/RainbowBootSequence.h>
|
||||
|
||||
RainbowBootSequence::RainbowBootSequence(Hyperion * hyperion) :
|
||||
_timer(),
|
||||
_hyperion(hyperion),
|
||||
_priority(0),
|
||||
_ledColors(hyperion->getLedCount()),
|
||||
_iterationCounter(hyperion->getLedCount())
|
||||
{
|
||||
for (unsigned iLed=0; iLed<_hyperion->getLedCount(); ++iLed)
|
||||
{
|
||||
RgbColor& color = _ledColors[iLed];
|
||||
HsvTransform::hsv2rgb(iLed*360/_hyperion->getLedCount(), 255, 255, color.red, color.green, color.blue);
|
||||
}
|
||||
|
||||
unsigned sequenceLength_ms = 3000;
|
||||
|
||||
_timer.setInterval(sequenceLength_ms/_hyperion->getLedCount());
|
||||
_timer.setSingleShot(false);
|
||||
QObject::connect(&_timer, SIGNAL(timeout()), this, SLOT(update()));
|
||||
}
|
||||
|
||||
void RainbowBootSequence::start()
|
||||
{
|
||||
_timer.start();
|
||||
}
|
||||
|
||||
void RainbowBootSequence::update()
|
||||
{
|
||||
if (_iterationCounter == 0)
|
||||
{
|
||||
_timer.stop();
|
||||
_hyperion->clear(_priority);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Rotate the colors left
|
||||
const RgbColor headColor = _ledColors.front();
|
||||
for (unsigned i=1; i<_ledColors.size(); ++i)
|
||||
{
|
||||
_ledColors[i-1] = _ledColors[i];
|
||||
}
|
||||
_ledColors.back() = headColor;
|
||||
|
||||
// Write the colors to hyperion
|
||||
_hyperion->setColors(_priority, _ledColors, -1);
|
||||
|
||||
// Decrease the loop count
|
||||
--_iterationCounter;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user