Added 'rainbow' boot sequence

Moved color transform to utils lib
This commit is contained in:
T. van der Zwan
2013-08-23 16:24:10 +00:00
parent 6ee94409dc
commit 3d02fecc7a
20 changed files with 218 additions and 78 deletions

View 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})

View 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;
}
}