hyperion.ng/libsrc/bootsequence/KittBootSequence.cpp
T. van der Zwan a567f0feeb Added abstract boot sequence to handle events and iteration count.
Implemented KnightRider bootsequence (KittBootSequence).
2013-09-09 15:24:36 +00:00

68 lines
1.2 KiB
C++

// Hyperion includes
#include <hyperion/ImageProcessorFactory.h>
// Local-Bootsequence includes
#include "KittBootSequence.h"
KittBootSequence::KittBootSequence(Hyperion * hyperion, const unsigned duration_ms) :
AbstractBootSequence(hyperion, 100, duration_ms/100),
_processor(ImageProcessorFactory::getInstance().newImageProcessor()),
_image(9, 1),
_ledColors(hyperion->getLedCount(), RgbColor::BLACK),
_forwardMove(false),
_currentLight(0)
{
// empty
}
KittBootSequence::~KittBootSequence()
{
delete _processor;
}
const std::vector<RgbColor>& KittBootSequence::nextColors()
{
// Switch the previous light 'off'
_image(_currentLight, 0) = RgbColor::BLACK;
// Move the current to the next light
moveNextLight();
// Switch the current light 'on'
_image(_currentLight, 0) = RgbColor::RED;
// Translate the 'image' to led colors
_processor->process(_image, _ledColors);
// Return the colors
return _ledColors;
}
void KittBootSequence::moveNextLight()
{
// Increase/Decrease the current light
if (_forwardMove)
{
++_currentLight;
if (_currentLight == _image.width())
{
_forwardMove = false;
--_currentLight;
}
}
else
{
if (_currentLight == 0)
{
_forwardMove = true;
}
else
{
--_currentLight;
}
}
}