diff --git a/config/hyperion.config.json b/config/hyperion.config.json index 6085537d..a1215e5f 100644 --- a/config/hyperion.config.json +++ b/config/hyperion.config.json @@ -2,302 +2,317 @@ // Generation script: ./WriteConfig { - "device" : - { - "name" : "MyPi", - "type" : "ws2801", - "output" : "/dev/spidev0.0", - "interval" : 20000, - "rate" : 48000 - }, - "color" : - { - "hsv" : { - "saturationGain" : 1.0, - "valueGain" : 1.0 - }, - "red" : - { - "threshold" : 0.0, - "gamma" : 1.0, - "blacklevel" : 0.0, - "whitelevel" : 1.0 - }, - "green" : - { - "threshold" : 0.0, - "gamma" : 1.0, - "blacklevel" : 0.0, - "whitelevel" : 1.0 - }, - "blue" : - { - "threshold" : 0.0, - "gamma" : 1.0, - "blacklevel" : 0.0, - "whitelevel" : 1.0 - } - }, - "leds" : - [ - { - "index" : 0, - "hscan" : { "minimum" : 47.0588, "maximum" : 52.9412 }, - "vscan" : { "minimum" : 0, "maximum" : 10 } - }, - { - "index" : 1, - "hscan" : { "minimum" : 41.1765, "maximum" : 47.0588 }, - "vscan" : { "minimum" : 0, "maximum" : 10 } - }, - { - "index" : 2, - "hscan" : { "minimum" : 35.2941, "maximum" : 41.1765 }, - "vscan" : { "minimum" : 0, "maximum" : 10 } - }, - { - "index" : 3, - "hscan" : { "minimum" : 29.4118, "maximum" : 35.2941 }, - "vscan" : { "minimum" : 0, "maximum" : 10 } - }, - { - "index" : 4, - "hscan" : { "minimum" : 23.5294, "maximum" : 29.4118 }, - "vscan" : { "minimum" : 0, "maximum" : 10 } - }, - { - "index" : 5, - "hscan" : { "minimum" : 17.6471, "maximum" : 23.5294 }, - "vscan" : { "minimum" : 0, "maximum" : 10 } - }, - { - "index" : 6, - "hscan" : { "minimum" : 11.7647, "maximum" : 17.6471 }, - "vscan" : { "minimum" : 0, "maximum" : 10 } - }, - { - "index" : 7, - "hscan" : { "minimum" : 5.88235, "maximum" : 11.7647 }, - "vscan" : { "minimum" : 0, "maximum" : 10 } - }, - // TOP-LEFT Corner - { - "index" : 8, - "hscan" : { "minimum" : 0, "maximum" : 5.88235 }, - "vscan" : { "minimum" : 0, "maximum" : 10 } - }, - { - "index" : 9, - "hscan" : { "minimum" : 0, "maximum" : 10 }, - "vscan" : { "minimum" : 10, "maximum" : 20 } - }, - { - "index" : 10, - "hscan" : { "minimum" : 0, "maximum" : 10 }, - "vscan" : { "minimum" : 20, "maximum" : 30 } - }, - { - "index" : 11, - "hscan" : { "minimum" : 0, "maximum" : 10 }, - "vscan" : { "minimum" : 30, "maximum" : 40 } - }, - { - "index" : 12, - "hscan" : { "minimum" : 0, "maximum" : 10 }, - "vscan" : { "minimum" : 40, "maximum" : 50 } - }, - { - "index" : 13, - "hscan" : { "minimum" : 0, "maximum" : 10 }, - "vscan" : { "minimum" : 50, "maximum" : 60 } - }, - { - "index" : 14, - "hscan" : { "minimum" : 0, "maximum" : 10 }, - "vscan" : { "minimum" : 60, "maximum" : 70 } - }, - { - "index" : 15, - "hscan" : { "minimum" : 0, "maximum" : 10 }, - "vscan" : { "minimum" : 70, "maximum" : 80 } - }, - { - "index" : 16, - "hscan" : { "minimum" : 0, "maximum" : 10 }, - "vscan" : { "minimum" : 80, "maximum" : 90 } - }, - // BOTTOM-LEFT Corner - { - "index" : 17, - "hscan" : { "minimum" : 0, "maximum" : 5.88235 }, - "vscan" : { "minimum" : 90, "maximum" : 100 } - }, - { - "index" : 18, - "hscan" : { "minimum" : 5.88235, "maximum" : 11.7647 }, - "vscan" : { "minimum" : 90, "maximum" : 100 } - }, - { - "index" : 19, - "hscan" : { "minimum" : 11.7647, "maximum" : 17.6471 }, - "vscan" : { "minimum" : 90, "maximum" : 100 } - }, - { - "index" : 20, - "hscan" : { "minimum" : 17.6471, "maximum" : 23.5294 }, - "vscan" : { "minimum" : 90, "maximum" : 100 } - }, - { - "index" : 21, - "hscan" : { "minimum" : 23.5294, "maximum" : 29.4118 }, - "vscan" : { "minimum" : 90, "maximum" : 100 } - }, - { - "index" : 22, - "hscan" : { "minimum" : 29.4118, "maximum" : 35.2941 }, - "vscan" : { "minimum" : 90, "maximum" : 100 } - }, - { - "index" : 23, - "hscan" : { "minimum" : 35.2941, "maximum" : 41.1765 }, - "vscan" : { "minimum" : 90, "maximum" : 100 } - }, - { - "index" : 24, - "hscan" : { "minimum" : 41.1765, "maximum" : 47.0588 }, - "vscan" : { "minimum" : 90, "maximum" : 100 } - }, - { - "index" : 25, - "hscan" : { "minimum" : 47.0588, "maximum" : 52.9412 }, - "vscan" : { "minimum" : 90, "maximum" : 100 } - }, - { - "index" : 26, - "hscan" : { "minimum" : 52.9412, "maximum" : 58.8235 }, - "vscan" : { "minimum" : 90, "maximum" : 100 } - }, - { - "index" : 27, - "hscan" : { "minimum" : 58.8235, "maximum" : 64.7059 }, - "vscan" : { "minimum" : 90, "maximum" : 100 } - }, - { - "index" : 28, - "hscan" : { "minimum" : 64.7059, "maximum" : 70.5882 }, - "vscan" : { "minimum" : 90, "maximum" : 100 } - }, - { - "index" : 29, - "hscan" : { "minimum" : 70.5882, "maximum" : 76.4706 }, - "vscan" : { "minimum" : 90, "maximum" : 100 } - }, - { - "index" : 30, - "hscan" : { "minimum" : 76.4706, "maximum" : 82.3529 }, - "vscan" : { "minimum" : 90, "maximum" : 100 } - }, - { - "index" : 31, - "hscan" : { "minimum" : 82.3529, "maximum" : 88.2353 }, - "vscan" : { "minimum" : 90, "maximum" : 100 } - }, - { - "index" : 32, - "hscan" : { "minimum" : 88.2353, "maximum" : 94.1176 }, - "vscan" : { "minimum" : 90, "maximum" : 100 } - }, - // BOTTOM-RIGHT Corner - { - "index" : 33, - "hscan" : { "minimum" : 94.1176, "maximum" : 100 }, - "vscan" : { "minimum" : 90, "maximum" : 100 } - }, - { - "index" : 34, - "hscan" : { "minimum" : 90, "maximum" : 100 }, - "vscan" : { "minimum" : 80, "maximum" : 90 } - }, - { - "index" : 35, - "hscan" : { "minimum" : 90, "maximum" : 100 }, - "vscan" : { "minimum" : 70, "maximum" : 80 } - }, - { - "index" : 36, - "hscan" : { "minimum" : 90, "maximum" : 100 }, - "vscan" : { "minimum" : 60, "maximum" : 70 } - }, - { - "index" : 37, - "hscan" : { "minimum" : 90, "maximum" : 100 }, - "vscan" : { "minimum" : 50, "maximum" : 60 } - }, - { - "index" : 38, - "hscan" : { "minimum" : 90, "maximum" : 100 }, - "vscan" : { "minimum" : 40, "maximum" : 50 } - }, - { - "index" : 39, - "hscan" : { "minimum" : 90, "maximum" : 100 }, - "vscan" : { "minimum" : 30, "maximum" : 40 } - }, - { - "index" : 40, - "hscan" : { "minimum" : 90, "maximum" : 100 }, - "vscan" : { "minimum" : 20, "maximum" : 30 } - }, - { - "index" : 41, - "hscan" : { "minimum" : 90, "maximum" : 100 }, - "vscan" : { "minimum" : 10, "maximum" : 20 } - }, - // TOP-RIGHT Corner - { - "index" : 42, - "hscan" : { "minimum" : 94.1176, "maximum" : 100 }, - "vscan" : { "minimum" : 0, "maximum" : 10 } - }, - { - "index" : 43, - "hscan" : { "minimum" : 88.2353, "maximum" : 94.1176 }, - "vscan" : { "minimum" : 0, "maximum" : 10 } - }, - { - "index" : 44, - "hscan" : { "minimum" : 82.3529, "maximum" : 88.2353 }, - "vscan" : { "minimum" : 0, "maximum" : 10 } - }, - { - "index" : 45, - "hscan" : { "minimum" : 76.4706, "maximum" : 82.3529 }, - "vscan" : { "minimum" : 0, "maximum" : 10 } - }, - { - "index" : 46, - "hscan" : { "minimum" : 70.5882, "maximum" : 76.4706 }, - "vscan" : { "minimum" : 0, "maximum" : 10 } - }, - { - "index" : 47, - "hscan" : { "minimum" : 64.7059, "maximum" : 70.5882 }, - "vscan" : { "minimum" : 0, "maximum" : 10 } - }, - { - "index" : 48, - "hscan" : { "minimum" : 58.8235, "maximum" : 64.7059 }, - "vscan" : { "minimum" : 0, "maximum" : 10 } - }, - { - "index" : 49, - "hscan" : { "minimum" : 52.9412, "maximum" : 58.8235 }, - "vscan" : { "minimum" : 0, "maximum" : 10 } - } - ], - "xbmcVideoChecker" : { - "enable" : true, - "xbmcAddress" : "127.0.0.1", - "xbmcTcpPort" : 9090 - } + "device" : + { + "name" : "MyPi", + "type" : "ws2801", + "output" : "/dev/spidev0.0", + "interval" : 20000, + "rate" : 48000 + }, + "color" : + { + "hsv" : { + "saturationGain" : 1.0, + "valueGain" : 1.0 + }, + "red" : + { + "threshold" : 0.0, + "gamma" : 1.0, + "blacklevel" : 0.0, + "whitelevel" : 1.0 + }, + "green" : + { + "threshold" : 0.0, + "gamma" : 1.0, + "blacklevel" : 0.0, + "whitelevel" : 1.0 + }, + "blue" : + { + "threshold" : 0.0, + "gamma" : 1.0, + "blacklevel" : 0.0, + "whitelevel" : 1.0 + } + }, + "leds" : + [ + { + "index" : 0, + "hscan" : { "minimum" : 47.0588, "maximum" : 52.9412 }, + "vscan" : { "minimum" : 0, "maximum" : 10 } + }, + { + "index" : 1, + "hscan" : { "minimum" : 41.1765, "maximum" : 47.0588 }, + "vscan" : { "minimum" : 0, "maximum" : 10 } + }, + { + "index" : 2, + "hscan" : { "minimum" : 35.2941, "maximum" : 41.1765 }, + "vscan" : { "minimum" : 0, "maximum" : 10 } + }, + { + "index" : 3, + "hscan" : { "minimum" : 29.4118, "maximum" : 35.2941 }, + "vscan" : { "minimum" : 0, "maximum" : 10 } + }, + { + "index" : 4, + "hscan" : { "minimum" : 23.5294, "maximum" : 29.4118 }, + "vscan" : { "minimum" : 0, "maximum" : 10 } + }, + { + "index" : 5, + "hscan" : { "minimum" : 17.6471, "maximum" : 23.5294 }, + "vscan" : { "minimum" : 0, "maximum" : 10 } + }, + { + "index" : 6, + "hscan" : { "minimum" : 11.7647, "maximum" : 17.6471 }, + "vscan" : { "minimum" : 0, "maximum" : 10 } + }, + { + "index" : 7, + "hscan" : { "minimum" : 5.88235, "maximum" : 11.7647 }, + "vscan" : { "minimum" : 0, "maximum" : 10 } + }, + // TOP-LEFT Corner + { + "index" : 8, + "hscan" : { "minimum" : 0, "maximum" : 5.88235 }, + "vscan" : { "minimum" : 0, "maximum" : 10 } + }, + { + "index" : 9, + "hscan" : { "minimum" : 0, "maximum" : 10 }, + "vscan" : { "minimum" : 10, "maximum" : 20 } + }, + { + "index" : 10, + "hscan" : { "minimum" : 0, "maximum" : 10 }, + "vscan" : { "minimum" : 20, "maximum" : 30 } + }, + { + "index" : 11, + "hscan" : { "minimum" : 0, "maximum" : 10 }, + "vscan" : { "minimum" : 30, "maximum" : 40 } + }, + { + "index" : 12, + "hscan" : { "minimum" : 0, "maximum" : 10 }, + "vscan" : { "minimum" : 40, "maximum" : 50 } + }, + { + "index" : 13, + "hscan" : { "minimum" : 0, "maximum" : 10 }, + "vscan" : { "minimum" : 50, "maximum" : 60 } + }, + { + "index" : 14, + "hscan" : { "minimum" : 0, "maximum" : 10 }, + "vscan" : { "minimum" : 60, "maximum" : 70 } + }, + { + "index" : 15, + "hscan" : { "minimum" : 0, "maximum" : 10 }, + "vscan" : { "minimum" : 70, "maximum" : 80 } + }, + { + "index" : 16, + "hscan" : { "minimum" : 0, "maximum" : 10 }, + "vscan" : { "minimum" : 80, "maximum" : 90 } + }, + // BOTTOM-LEFT Corner + { + "index" : 17, + "hscan" : { "minimum" : 0, "maximum" : 5.88235 }, + "vscan" : { "minimum" : 90, "maximum" : 100 } + }, + { + "index" : 18, + "hscan" : { "minimum" : 5.88235, "maximum" : 11.7647 }, + "vscan" : { "minimum" : 90, "maximum" : 100 } + }, + { + "index" : 19, + "hscan" : { "minimum" : 11.7647, "maximum" : 17.6471 }, + "vscan" : { "minimum" : 90, "maximum" : 100 } + }, + { + "index" : 20, + "hscan" : { "minimum" : 17.6471, "maximum" : 23.5294 }, + "vscan" : { "minimum" : 90, "maximum" : 100 } + }, + { + "index" : 21, + "hscan" : { "minimum" : 23.5294, "maximum" : 29.4118 }, + "vscan" : { "minimum" : 90, "maximum" : 100 } + }, + { + "index" : 22, + "hscan" : { "minimum" : 29.4118, "maximum" : 35.2941 }, + "vscan" : { "minimum" : 90, "maximum" : 100 } + }, + { + "index" : 23, + "hscan" : { "minimum" : 35.2941, "maximum" : 41.1765 }, + "vscan" : { "minimum" : 90, "maximum" : 100 } + }, + { + "index" : 24, + "hscan" : { "minimum" : 41.1765, "maximum" : 47.0588 }, + "vscan" : { "minimum" : 90, "maximum" : 100 } + }, + { + "index" : 25, + "hscan" : { "minimum" : 47.0588, "maximum" : 52.9412 }, + "vscan" : { "minimum" : 90, "maximum" : 100 } + }, + { + "index" : 26, + "hscan" : { "minimum" : 52.9412, "maximum" : 58.8235 }, + "vscan" : { "minimum" : 90, "maximum" : 100 } + }, + { + "index" : 27, + "hscan" : { "minimum" : 58.8235, "maximum" : 64.7059 }, + "vscan" : { "minimum" : 90, "maximum" : 100 } + }, + { + "index" : 28, + "hscan" : { "minimum" : 64.7059, "maximum" : 70.5882 }, + "vscan" : { "minimum" : 90, "maximum" : 100 } + }, + { + "index" : 29, + "hscan" : { "minimum" : 70.5882, "maximum" : 76.4706 }, + "vscan" : { "minimum" : 90, "maximum" : 100 } + }, + { + "index" : 30, + "hscan" : { "minimum" : 76.4706, "maximum" : 82.3529 }, + "vscan" : { "minimum" : 90, "maximum" : 100 } + }, + { + "index" : 31, + "hscan" : { "minimum" : 82.3529, "maximum" : 88.2353 }, + "vscan" : { "minimum" : 90, "maximum" : 100 } + }, + { + "index" : 32, + "hscan" : { "minimum" : 88.2353, "maximum" : 94.1176 }, + "vscan" : { "minimum" : 90, "maximum" : 100 } + }, + // BOTTOM-RIGHT Corner + { + "index" : 33, + "hscan" : { "minimum" : 94.1176, "maximum" : 100 }, + "vscan" : { "minimum" : 90, "maximum" : 100 } + }, + { + "index" : 34, + "hscan" : { "minimum" : 90, "maximum" : 100 }, + "vscan" : { "minimum" : 80, "maximum" : 90 } + }, + { + "index" : 35, + "hscan" : { "minimum" : 90, "maximum" : 100 }, + "vscan" : { "minimum" : 70, "maximum" : 80 } + }, + { + "index" : 36, + "hscan" : { "minimum" : 90, "maximum" : 100 }, + "vscan" : { "minimum" : 60, "maximum" : 70 } + }, + { + "index" : 37, + "hscan" : { "minimum" : 90, "maximum" : 100 }, + "vscan" : { "minimum" : 50, "maximum" : 60 } + }, + { + "index" : 38, + "hscan" : { "minimum" : 90, "maximum" : 100 }, + "vscan" : { "minimum" : 40, "maximum" : 50 } + }, + { + "index" : 39, + "hscan" : { "minimum" : 90, "maximum" : 100 }, + "vscan" : { "minimum" : 30, "maximum" : 40 } + }, + { + "index" : 40, + "hscan" : { "minimum" : 90, "maximum" : 100 }, + "vscan" : { "minimum" : 20, "maximum" : 30 } + }, + { + "index" : 41, + "hscan" : { "minimum" : 90, "maximum" : 100 }, + "vscan" : { "minimum" : 10, "maximum" : 20 } + }, + // TOP-RIGHT Corner + { + "index" : 42, + "hscan" : { "minimum" : 94.1176, "maximum" : 100 }, + "vscan" : { "minimum" : 0, "maximum" : 10 } + }, + { + "index" : 43, + "hscan" : { "minimum" : 88.2353, "maximum" : 94.1176 }, + "vscan" : { "minimum" : 0, "maximum" : 10 } + }, + { + "index" : 44, + "hscan" : { "minimum" : 82.3529, "maximum" : 88.2353 }, + "vscan" : { "minimum" : 0, "maximum" : 10 } + }, + { + "index" : 45, + "hscan" : { "minimum" : 76.4706, "maximum" : 82.3529 }, + "vscan" : { "minimum" : 0, "maximum" : 10 } + }, + { + "index" : 46, + "hscan" : { "minimum" : 70.5882, "maximum" : 76.4706 }, + "vscan" : { "minimum" : 0, "maximum" : 10 } + }, + { + "index" : 47, + "hscan" : { "minimum" : 64.7059, "maximum" : 70.5882 }, + "vscan" : { "minimum" : 0, "maximum" : 10 } + }, + { + "index" : 48, + "hscan" : { "minimum" : 58.8235, "maximum" : 64.7059 }, + "vscan" : { "minimum" : 0, "maximum" : 10 } + }, + { + "index" : 49, + "hscan" : { "minimum" : 52.9412, "maximum" : 58.8235 }, + "vscan" : { "minimum" : 0, "maximum" : 10 } + } + ], + + "xbmcVideoChecker" : { + "enable" : true, + "xbmcAddress" : "127.0.0.1", + "xbmcTcpPort" : 9090 + }, + + "bootsequence" : + { + "type" : "rainbow", + "duration_ms" : 3000 + }, + + "framegrabber" : + { + "width" : 64, + "height" : 64, + "frequency_Hz" : 10 + } + } diff --git a/include/bootsequence/BootSequence.h b/include/bootsequence/BootSequence.h new file mode 100644 index 00000000..17606d30 --- /dev/null +++ b/include/bootsequence/BootSequence.h @@ -0,0 +1,24 @@ +#pragma once + +/// +/// Pure virtual base class (or interface) for boot sequences. A BootSequence is started after the +/// Hyperion deamon is started to demonstrate the proper functioninf of the attached leds (and lets +/// face it because it is cool) +/// +class BootSequence +{ +public: + + /// + /// Empty virtual destructor for abstract base class + /// + virtual ~BootSequence() + { + // empty + } + + /// + /// Starts the boot sequence writing one or more colors to the attached leds + /// + virtual void start() = 0; +}; diff --git a/include/bootsequence/BootSequenceFactory.h b/include/bootsequence/BootSequenceFactory.h new file mode 100644 index 00000000..f6ba7d67 --- /dev/null +++ b/include/bootsequence/BootSequenceFactory.h @@ -0,0 +1,29 @@ +#pragma once + +// Jsoncpp includes +#include + +// Bootsequence includes +#include + +// Hyperion includes +#include + +/// +/// Factory for settings based construction of a boot-sequence +/// +class BootSequenceFactory +{ +public: + + /// + /// Creates a BootSequence using the given configuration (and Hyperion connection). Ownship of + /// the returned instance is transferred + /// + /// @param[in] hyperion The Hyperion controlling the leds + /// @param[in] jsonConfig The boot-sequence configuration + /// + /// @return The bootsequence (ownership is transferred to the caller + /// + static BootSequence * createBootSequence(Hyperion * hyperion, const Json::Value & jsonConfig); +}; diff --git a/include/bootsequence/RainbowBootSequence.h b/include/bootsequence/RainbowBootSequence.h deleted file mode 100644 index edf6cefc..00000000 --- a/include/bootsequence/RainbowBootSequence.h +++ /dev/null @@ -1,32 +0,0 @@ - -#pragma once - -// QT includes -#include - -// Hyperion includes -#include - -class RainbowBootSequence : public QObject -{ -Q_OBJECT - -public: - RainbowBootSequence(Hyperion * hyperion); - - void start(); - -private slots: - void update(); - -private: - QTimer _timer; - - Hyperion * _hyperion; - - int _priority; - - std::vector _ledColors; - int _iterationCounter; -}; - diff --git a/libsrc/bootsequence/BootSequenceFactory.cpp b/libsrc/bootsequence/BootSequenceFactory.cpp new file mode 100644 index 00000000..d8e02b0a --- /dev/null +++ b/libsrc/bootsequence/BootSequenceFactory.cpp @@ -0,0 +1,34 @@ + +// Bootsequence includes +#include + +// 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; +} + + diff --git a/libsrc/bootsequence/CMakeLists.txt b/libsrc/bootsequence/CMakeLists.txt index ee95f83b..28bfdfb3 100644 --- a/libsrc/bootsequence/CMakeLists.txt +++ b/libsrc/bootsequence/CMakeLists.txt @@ -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 ) diff --git a/libsrc/bootsequence/RainbowBootSequence.cpp b/libsrc/bootsequence/RainbowBootSequence.cpp index 1e6d8b99..b60364ed 100644 --- a/libsrc/bootsequence/RainbowBootSequence.cpp +++ b/libsrc/bootsequence/RainbowBootSequence.cpp @@ -1,9 +1,11 @@ +// Utils includes #include -#include +// 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())); } diff --git a/libsrc/bootsequence/RainbowBootSequence.h b/libsrc/bootsequence/RainbowBootSequence.h new file mode 100644 index 00000000..a6b38ca1 --- /dev/null +++ b/libsrc/bootsequence/RainbowBootSequence.h @@ -0,0 +1,57 @@ + +#pragma once + +// QT includes +#include + +// Bootsequence include +#include + +// Hyperion includes +#include + +/// +/// 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 _ledColors; + /// The counter of the number of iterations left + int _iterationCounter; +}; + diff --git a/src/hyperiond/hyperiond.cpp b/src/hyperiond/hyperiond.cpp index 3270240c..0f216db5 100644 --- a/src/hyperiond/hyperiond.cpp +++ b/src/hyperiond/hyperiond.cpp @@ -11,7 +11,9 @@ // Hyperion includes #include -#include + +// Bootsequence includes +#include // Dispmanx grabber includes #include @@ -74,8 +76,11 @@ int main(int argc, char** argv) Hyperion hyperion(config); std::cout << "Hyperion created and initialised" << std::endl; - RainbowBootSequence bootSequence(&hyperion); - bootSequence.start(); + BootSequence * bootSequence = BootSequenceFactory::createBootSequence(&hyperion, config["bootsequence"]); + if (bootSequence) + { + bootSequence->start(); + } const Json::Value & videoCheckerConfig = config["xbmcVideoChecker"]; XBMCVideoChecker xbmcVideoChecker(videoCheckerConfig["xbmcAddress"].asString(), videoCheckerConfig["xbmcTcpPort"].asUInt(), 1000, &hyperion, 999); @@ -85,7 +90,13 @@ int main(int argc, char** argv) std::cout << "XBMC video checker created and started" << std::endl; } - DispmanxWrapper dispmanx(64, 64, 10, &hyperion); + // Construct and start the frame-grabber + const Json::Value & frameGrabberConfig = config["framegrabber"]; + DispmanxWrapper dispmanx( + frameGrabberConfig["width"].asUInt(), + frameGrabberConfig["height"].asUInt(), + frameGrabberConfig["frequency_Hz"].asUInt(), + &hyperion); dispmanx.start(); std::cout << "Frame grabber created and started" << std::endl; @@ -94,10 +105,14 @@ int main(int argc, char** argv) // run the application int rc = app.exec(); - std::cout << "Application closed" << std::endl; + // Stop the frame grabber dispmanx.stop(); + + // Delete the boot sequence + delete bootSequence; + // Clear all colors (switchting off all leds) hyperion.clearall();