mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
Added factory to boot-sequence
Added json-config for boot-sequence.
This commit is contained in:
34
libsrc/bootsequence/BootSequenceFactory.cpp
Normal file
34
libsrc/bootsequence/BootSequenceFactory.cpp
Normal file
@@ -0,0 +1,34 @@
|
||||
|
||||
// Bootsequence includes
|
||||
#include <bootsequence/BootSequenceFactory.h>
|
||||
|
||||
// Local Bootsequence includes
|
||||
#include "RainbowBootSequence.h"
|
||||
|
||||
BootSequence * BootSequenceFactory::createBootSequence(Hyperion * hyperion, const Json::Value & jsonConfig)
|
||||
{
|
||||
const std::string type = jsonConfig["type"].asString();
|
||||
|
||||
if (type == "none")
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
else if (type == "rainbow")
|
||||
{
|
||||
const unsigned duration_ms = jsonConfig["duration_ms"].asUInt();
|
||||
return new RainbowBootSequence(hyperion, duration_ms);
|
||||
}
|
||||
else if (type == "knightrider")
|
||||
{
|
||||
std::cout << "KNIGHT RIDER NOT IMPLEMENTED YET" << std::endl;
|
||||
return nullptr;
|
||||
// const unsigned duration_ms = jsonConfig["duration_ms"].asUint();
|
||||
// const std::string colorStr = jsonConfig["color"].asString();
|
||||
// return new KnightRiderSequence(hyperion, duration_ms);
|
||||
}
|
||||
|
||||
std::cerr << "Unknown boot-sequence selected; boot-sequence disabled." << std::endl;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@@ -5,13 +5,16 @@ 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
|
||||
${CURRENT_SOURCE_DIR}/RainbowBootSequence.h
|
||||
)
|
||||
|
||||
SET(BootsequenceHEADERS
|
||||
${CURRENT_HEADER_DIR}/BootSequence.h
|
||||
${CURRENT_HEADER_DIR}/BootSequenceFactory.h
|
||||
)
|
||||
|
||||
SET(BootsequenceSOURCES
|
||||
${CURRENT_SOURCE_DIR}/BootSequenceFactory.cpp
|
||||
${CURRENT_SOURCE_DIR}/RainbowBootSequence.cpp
|
||||
)
|
||||
|
||||
|
@@ -1,9 +1,11 @@
|
||||
|
||||
// Utils includes
|
||||
#include <utils/HsvTransform.h>
|
||||
|
||||
#include <bootsequence/RainbowBootSequence.h>
|
||||
// Local-Bootsequence include
|
||||
#include "RainbowBootSequence.h"
|
||||
|
||||
RainbowBootSequence::RainbowBootSequence(Hyperion * hyperion) :
|
||||
RainbowBootSequence::RainbowBootSequence(Hyperion * hyperion, const unsigned duration_ms) :
|
||||
_timer(),
|
||||
_hyperion(hyperion),
|
||||
_priority(0),
|
||||
@@ -16,9 +18,7 @@ RainbowBootSequence::RainbowBootSequence(Hyperion * hyperion) :
|
||||
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.setInterval(duration_ms/_hyperion->getLedCount());
|
||||
_timer.setSingleShot(false);
|
||||
QObject::connect(&_timer, SIGNAL(timeout()), this, SLOT(update()));
|
||||
}
|
||||
|
57
libsrc/bootsequence/RainbowBootSequence.h
Normal file
57
libsrc/bootsequence/RainbowBootSequence.h
Normal file
@@ -0,0 +1,57 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
// QT includes
|
||||
#include <QTimer>
|
||||
|
||||
// Bootsequence include
|
||||
#include <bootsequence/BootSequence.h>
|
||||
|
||||
// Hyperion includes
|
||||
#include <hyperion/Hyperion.h>
|
||||
|
||||
///
|
||||
/// The RainborBootSequence shows a 'rainbow' (all lights have a different color). The rainbow is
|
||||
/// rotated over each led during the length of the sequence.
|
||||
///
|
||||
class RainbowBootSequence : public QObject, public BootSequence
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
///
|
||||
/// Constructs the rainbow boot-sequence. Hyperion is used for writing the led colors. The given
|
||||
/// duration is the length of the sequence.
|
||||
///
|
||||
/// @param[in] hyperion The Hyperion instance
|
||||
/// @param[in] duration_ms The length of the sequence [ms]
|
||||
///
|
||||
RainbowBootSequence(Hyperion * hyperion, const unsigned duration_ms);
|
||||
|
||||
///
|
||||
/// Starts the boot-sequence
|
||||
///
|
||||
virtual void start();
|
||||
|
||||
private slots:
|
||||
///
|
||||
/// Moves the rainbow one led further
|
||||
///
|
||||
void update();
|
||||
|
||||
private:
|
||||
/// The timer used to generate an 'update' signal every interval
|
||||
QTimer _timer;
|
||||
|
||||
/// The Hyperion instance
|
||||
Hyperion * _hyperion;
|
||||
|
||||
/// The priority of the boot sequence
|
||||
int _priority;
|
||||
|
||||
/// The current color of the boot sequence (the rainbow)
|
||||
std::vector<RgbColor> _ledColors;
|
||||
/// The counter of the number of iterations left
|
||||
int _iterationCounter;
|
||||
};
|
||||
|
Reference in New Issue
Block a user