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:
		@@ -295,9 +295,24 @@
 | 
				
			|||||||
			"vscan" : { "minimum" : 0, "maximum" : 10 }
 | 
								"vscan" : { "minimum" : 0, "maximum" : 10 }
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	],
 | 
						],
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"xbmcVideoChecker" : {
 | 
						"xbmcVideoChecker" : {
 | 
				
			||||||
		"enable" : true,
 | 
							"enable" : true,
 | 
				
			||||||
		"xbmcAddress" : "127.0.0.1",
 | 
							"xbmcAddress" : "127.0.0.1",
 | 
				
			||||||
		"xbmcTcpPort" : 9090
 | 
							"xbmcTcpPort" : 9090
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"bootsequence" :
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							"type"        : "rainbow",
 | 
				
			||||||
 | 
							"duration_ms" : 3000
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"framegrabber" :
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							"width"        : 64,
 | 
				
			||||||
 | 
							"height"       : 64,
 | 
				
			||||||
 | 
							"frequency_Hz" : 10
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										24
									
								
								include/bootsequence/BootSequence.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								include/bootsequence/BootSequence.h
									
									
									
									
									
										Normal file
									
								
							@@ -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;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
							
								
								
									
										29
									
								
								include/bootsequence/BootSequenceFactory.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								include/bootsequence/BootSequenceFactory.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,29 @@
 | 
				
			|||||||
 | 
					#pragma once
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Jsoncpp includes
 | 
				
			||||||
 | 
					#include <json/json.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Bootsequence includes
 | 
				
			||||||
 | 
					#include <bootsequence/BootSequence.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Hyperion includes
 | 
				
			||||||
 | 
					#include <hyperion/Hyperion.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					///
 | 
				
			||||||
 | 
					/// 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);
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
@@ -1,32 +0,0 @@
 | 
				
			|||||||
 | 
					 | 
				
			||||||
#pragma once
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// QT includes
 | 
					 | 
				
			||||||
#include <QTimer>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// Hyperion includes
 | 
					 | 
				
			||||||
#include <hyperion/Hyperion.h>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
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<RgbColor> _ledColors;
 | 
					 | 
				
			||||||
	int _iterationCounter;
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
							
								
								
									
										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
 | 
					# Group the headers that go through the MOC compiler
 | 
				
			||||||
SET(BootsequenceQT_HEADERS
 | 
					SET(BootsequenceQT_HEADERS
 | 
				
			||||||
		${CURRENT_HEADER_DIR}/RainbowBootSequence.h
 | 
							${CURRENT_SOURCE_DIR}/RainbowBootSequence.h
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
SET(BootsequenceHEADERS
 | 
					SET(BootsequenceHEADERS
 | 
				
			||||||
 | 
							${CURRENT_HEADER_DIR}/BootSequence.h
 | 
				
			||||||
 | 
							${CURRENT_HEADER_DIR}/BootSequenceFactory.h
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
SET(BootsequenceSOURCES
 | 
					SET(BootsequenceSOURCES
 | 
				
			||||||
 | 
							${CURRENT_SOURCE_DIR}/BootSequenceFactory.cpp
 | 
				
			||||||
		${CURRENT_SOURCE_DIR}/RainbowBootSequence.cpp
 | 
							${CURRENT_SOURCE_DIR}/RainbowBootSequence.cpp
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,9 +1,11 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					// Utils includes
 | 
				
			||||||
#include <utils/HsvTransform.h>
 | 
					#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(),
 | 
						_timer(),
 | 
				
			||||||
	_hyperion(hyperion),
 | 
						_hyperion(hyperion),
 | 
				
			||||||
	_priority(0),
 | 
						_priority(0),
 | 
				
			||||||
@@ -16,9 +18,7 @@ RainbowBootSequence::RainbowBootSequence(Hyperion * hyperion) :
 | 
				
			|||||||
		HsvTransform::hsv2rgb(iLed*360/_hyperion->getLedCount(), 255, 255, color.red, color.green, color.blue);
 | 
							HsvTransform::hsv2rgb(iLed*360/_hyperion->getLedCount(), 255, 255, color.red, color.green, color.blue);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	unsigned sequenceLength_ms = 3000;
 | 
						_timer.setInterval(duration_ms/_hyperion->getLedCount());
 | 
				
			||||||
 | 
					 | 
				
			||||||
	_timer.setInterval(sequenceLength_ms/_hyperion->getLedCount());
 | 
					 | 
				
			||||||
	_timer.setSingleShot(false);
 | 
						_timer.setSingleShot(false);
 | 
				
			||||||
	QObject::connect(&_timer, SIGNAL(timeout()), this, SLOT(update()));
 | 
						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;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -11,7 +11,9 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// Hyperion includes
 | 
					// Hyperion includes
 | 
				
			||||||
#include <hyperion/Hyperion.h>
 | 
					#include <hyperion/Hyperion.h>
 | 
				
			||||||
#include <bootsequence/RainbowBootSequence.h>
 | 
					
 | 
				
			||||||
 | 
					// Bootsequence includes
 | 
				
			||||||
 | 
					#include <bootsequence/BootSequenceFactory.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Dispmanx grabber includes
 | 
					// Dispmanx grabber includes
 | 
				
			||||||
#include <dispmanx-grabber/DispmanxWrapper.h>
 | 
					#include <dispmanx-grabber/DispmanxWrapper.h>
 | 
				
			||||||
@@ -74,8 +76,8 @@ int main(int argc, char** argv)
 | 
				
			|||||||
	Hyperion hyperion(config);
 | 
						Hyperion hyperion(config);
 | 
				
			||||||
	std::cout << "Hyperion created and initialised" << std::endl;
 | 
						std::cout << "Hyperion created and initialised" << std::endl;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	RainbowBootSequence bootSequence(&hyperion);
 | 
						BootSequence * bootSequence = BootSequenceFactory::createBootSequence(&hyperion, config["bootsequence"]);
 | 
				
			||||||
	bootSequence.start();
 | 
						bootSequence->start();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	const Json::Value & videoCheckerConfig = config["xbmcVideoChecker"];
 | 
						const Json::Value & videoCheckerConfig = config["xbmcVideoChecker"];
 | 
				
			||||||
	XBMCVideoChecker xbmcVideoChecker(videoCheckerConfig["xbmcAddress"].asString(), videoCheckerConfig["xbmcTcpPort"].asUInt(), 1000, &hyperion, 999);
 | 
						XBMCVideoChecker xbmcVideoChecker(videoCheckerConfig["xbmcAddress"].asString(), videoCheckerConfig["xbmcTcpPort"].asUInt(), 1000, &hyperion, 999);
 | 
				
			||||||
@@ -85,7 +87,13 @@ int main(int argc, char** argv)
 | 
				
			|||||||
		std::cout << "XBMC video checker created and started" << std::endl;
 | 
							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();
 | 
						dispmanx.start();
 | 
				
			||||||
	std::cout << "Frame grabber created and started" << std::endl;
 | 
						std::cout << "Frame grabber created and started" << std::endl;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -94,10 +102,14 @@ int main(int argc, char** argv)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	// run the application
 | 
						// run the application
 | 
				
			||||||
	int rc = app.exec();
 | 
						int rc = app.exec();
 | 
				
			||||||
 | 
					 | 
				
			||||||
	std::cout << "Application closed" << std::endl;
 | 
						std::cout << "Application closed" << std::endl;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Stop the frame grabber
 | 
						// Stop the frame grabber
 | 
				
			||||||
	dispmanx.stop();
 | 
						dispmanx.stop();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Delete the boot sequence
 | 
				
			||||||
 | 
						delete bootSequence;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Clear all colors (switchting off all leds)
 | 
						// Clear all colors (switchting off all leds)
 | 
				
			||||||
	hyperion.clearall();
 | 
						hyperion.clearall();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user