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 }
 | 
			
		||||
		}
 | 
			
		||||
	],
 | 
			
		||||
 | 
			
		||||
	"xbmcVideoChecker" : {
 | 
			
		||||
		"enable" : true,
 | 
			
		||||
		"xbmcAddress" : "127.0.0.1",
 | 
			
		||||
		"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
 | 
			
		||||
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;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
@@ -11,7 +11,9 @@
 | 
			
		||||
 | 
			
		||||
// Hyperion includes
 | 
			
		||||
#include <hyperion/Hyperion.h>
 | 
			
		||||
#include <bootsequence/RainbowBootSequence.h>
 | 
			
		||||
 | 
			
		||||
// Bootsequence includes
 | 
			
		||||
#include <bootsequence/BootSequenceFactory.h>
 | 
			
		||||
 | 
			
		||||
// Dispmanx grabber includes
 | 
			
		||||
#include <dispmanx-grabber/DispmanxWrapper.h>
 | 
			
		||||
@@ -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();
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user