2013-08-13 11:10:45 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
// STL includes
|
|
|
|
#include <vector>
|
|
|
|
#include <map>
|
|
|
|
#include <cstdint>
|
|
|
|
#include <limits>
|
|
|
|
|
|
|
|
// QT includes
|
|
|
|
#include <QMap>
|
|
|
|
|
|
|
|
// Utils includes
|
|
|
|
#include <utils/RgbColor.h>
|
|
|
|
|
|
|
|
// Hyperion includes
|
|
|
|
#include <hyperion/LedDevice.h>
|
|
|
|
|
2013-09-06 21:26:58 +02:00
|
|
|
///
|
|
|
|
/// The PriorityMuxer handles the priority channels. Led values input is written to the priority map
|
|
|
|
/// and the muxer keeps track of all active priorities. The current priority can be queried and per
|
|
|
|
/// priority the led colors.
|
|
|
|
///
|
2013-08-13 11:10:45 +02:00
|
|
|
class PriorityMuxer
|
|
|
|
{
|
|
|
|
public:
|
2013-09-06 21:26:58 +02:00
|
|
|
///
|
|
|
|
/// The information structure for a single priority channel
|
|
|
|
///
|
2013-08-13 11:10:45 +02:00
|
|
|
struct InputInfo
|
|
|
|
{
|
2013-09-06 21:26:58 +02:00
|
|
|
/// The priority of this channel
|
2013-08-13 11:10:45 +02:00
|
|
|
int priority;
|
|
|
|
|
2013-09-06 21:26:58 +02:00
|
|
|
/// The absolute timeout of the channel
|
2013-08-13 11:10:45 +02:00
|
|
|
int64_t timeoutTime_ms;
|
2013-09-06 21:26:58 +02:00
|
|
|
/// The colors for each led of the channel
|
2013-08-13 11:10:45 +02:00
|
|
|
std::vector<RgbColor> ledColors;
|
|
|
|
};
|
|
|
|
|
2013-09-06 21:26:58 +02:00
|
|
|
///
|
|
|
|
/// Constructs the PriorityMuxer for the given number of leds (used to switch to black when
|
|
|
|
/// there are no priority channels
|
|
|
|
///
|
|
|
|
/// @param ledCount The number of leds
|
|
|
|
///
|
2013-08-18 13:33:56 +02:00
|
|
|
PriorityMuxer(int ledCount);
|
2013-08-13 11:10:45 +02:00
|
|
|
|
2013-09-06 21:26:58 +02:00
|
|
|
///
|
|
|
|
/// Destructor
|
|
|
|
///
|
2013-08-13 11:10:45 +02:00
|
|
|
~PriorityMuxer();
|
|
|
|
|
2013-09-06 21:26:58 +02:00
|
|
|
///
|
|
|
|
/// Returns the current priority
|
|
|
|
///
|
|
|
|
/// @return The current priority
|
|
|
|
///
|
2013-08-13 11:10:45 +02:00
|
|
|
int getCurrentPriority() const;
|
|
|
|
|
2013-09-06 21:26:58 +02:00
|
|
|
///
|
|
|
|
/// Returns the state (enabled/disabled) of a specific priority channel
|
|
|
|
/// @param priority The priority channel
|
|
|
|
/// @return True if the priority channel exists else false
|
|
|
|
///
|
2013-08-13 11:10:45 +02:00
|
|
|
bool hasPriority(const int priority) const;
|
|
|
|
|
2013-09-06 21:26:58 +02:00
|
|
|
///
|
|
|
|
/// Returns the number of active priorities
|
|
|
|
///
|
|
|
|
/// @return The list with active priorities
|
|
|
|
///
|
2013-08-13 11:10:45 +02:00
|
|
|
QList<int> getPriorities() const;
|
|
|
|
|
2013-09-06 21:26:58 +02:00
|
|
|
///
|
|
|
|
/// Returns the information of a specified priority channel
|
|
|
|
///
|
|
|
|
/// @param priority The priority channel
|
|
|
|
///
|
|
|
|
/// @return The information for the specified priority channel
|
|
|
|
///
|
|
|
|
/// @throws std::runtime_error if the priority channel does not exist
|
|
|
|
///
|
2013-08-13 11:10:45 +02:00
|
|
|
const InputInfo& getInputInfo(const int priority) const;
|
|
|
|
|
2013-09-06 21:26:58 +02:00
|
|
|
///
|
|
|
|
/// Sets/Updates the data for a priority channel
|
|
|
|
///
|
|
|
|
/// @param[in] priority The priority of the channel
|
|
|
|
/// @param[in] ledColors The led colors of the priority channel
|
|
|
|
/// @param[in] timeoutTime_ms The absolute timeout time of the channel
|
|
|
|
///
|
2013-08-13 11:10:45 +02:00
|
|
|
void setInput(const int priority, const std::vector<RgbColor>& ledColors, const int64_t timeoutTime_ms=-1);
|
|
|
|
|
2013-09-06 21:26:58 +02:00
|
|
|
///
|
|
|
|
/// Clears the specified priority channel
|
|
|
|
///
|
|
|
|
/// @param[in] priority The priority of the channel to clear
|
|
|
|
///
|
2013-08-13 11:10:45 +02:00
|
|
|
void clearInput(const int priority);
|
|
|
|
|
2013-09-06 21:26:58 +02:00
|
|
|
///
|
|
|
|
/// Clears all priority channels
|
|
|
|
///
|
2013-08-13 11:10:45 +02:00
|
|
|
void clearAll();
|
|
|
|
|
2013-09-06 21:26:58 +02:00
|
|
|
///
|
|
|
|
/// Updates the current time. Channels with a configured time out will be checked and cleared if
|
|
|
|
/// required.
|
|
|
|
///
|
|
|
|
/// @param[in] now The current time
|
|
|
|
///
|
2013-08-13 11:10:45 +02:00
|
|
|
void setCurrentTime(const int64_t& now);
|
|
|
|
|
|
|
|
private:
|
2013-09-06 21:26:58 +02:00
|
|
|
/// The current priority (lowest value in _activeInputs)
|
2013-08-18 13:33:56 +02:00
|
|
|
int _currentPriority;
|
2013-08-13 11:10:45 +02:00
|
|
|
|
2013-09-06 21:26:58 +02:00
|
|
|
/// The mapping from priority channel to led-information
|
2013-08-18 13:33:56 +02:00
|
|
|
QMap<int, InputInfo> _activeInputs;
|
2013-08-13 11:10:45 +02:00
|
|
|
|
2013-09-06 21:26:58 +02:00
|
|
|
/// The information of the lowest priority channel
|
2013-08-18 13:33:56 +02:00
|
|
|
InputInfo _lowestPriorityInfo;
|
|
|
|
|
2013-09-06 21:26:58 +02:00
|
|
|
/// The lowest possible priority, which is used when no priority channels are active
|
2013-08-18 13:33:56 +02:00
|
|
|
const static int LOWEST_PRIORITY = std::numeric_limits<int>::max();
|
2013-08-13 11:10:45 +02:00
|
|
|
};
|