hyperion.ng
PriorityMuxer.h
1 #pragma once
2 
3 // STL includes
4 #include <vector>
5 #include <cstdint>
6 
7 // QT includes
8 #include <QMap>
9 #include <QObject>
10 #include <QMap>
11 #include <QVector>
12 
13 // Utils includes
14 #include <utils/ColorRgb.h>
15 #include <utils/Image.h>
16 #include <utils/Components.h>
17 
18 // global defines
19 #define SMOOTHING_MODE_DEFAULT 0
20 #define SMOOTHING_MODE_PAUSE 1
21 
22 class QTimer;
23 class Logger;
24 
30 class PriorityMuxer : public QObject
31 {
32  Q_OBJECT
33 public:
37  struct InputInfo
38  {
40  int priority;
42  int64_t timeoutTime_ms;
44  std::vector<ColorRgb> ledColors;
50  QString origin;
52  unsigned smooth_cfg;
54  QString owner;
55  };
56 
58  const static int LOWEST_PRIORITY;
59 
66  PriorityMuxer(int ledCount);
67 
72 
77  void setEnable(const bool& enable);
78 
84  bool setSourceAutoSelectEnabled(const bool& enabel, const bool& update = true);
85 
90  bool isSourceAutoSelectEnabled() const { return _sourceAutoSelectEnabled; };
91 
97  bool setPriority(const uint8_t priority);
98 
103  void updateLedColorsLength(const int& ledCount);
104 
110  int getCurrentPriority() const { return _currentPriority; }
111 
117  bool hasPriority(const int priority) const;
118 
124  QList<int> getPriorities() const;
125 
134  const InputInfo getInputInfo(const int priority) const;
135 
145  void registerInput(const int priority, const hyperion::Components& component, const QString& origin = "System", const QString& owner = "", unsigned smooth_cfg = SMOOTHING_MODE_DEFAULT);
146 
154  bool setInput(const int priority, const std::vector<ColorRgb>& ledColors, int64_t timeout_ms = -1);
155 
163  bool setInputImage(const int priority, const Image<ColorRgb>& image, int64_t timeout_ms = -1);
164 
170  bool setInputInactive(const quint8& priority);
171 
178  bool clearInput(const uint8_t priority);
179 
183  void clearAll(bool forceClearAll=false);
184 
185 signals:
189  void timeRunner();
190 
196  void priorityChanged(const quint8& priority, const bool& state);
197 
202  void visiblePriorityChanged(const quint8& priority);
203 
209  void activeStateChanged(const quint8& priority, const bool& state);
210 
215  void autoSelectChanged(const bool& state);
216 
221  void prioritiesChanged(void);
222 
226  void signalTimeTrigger();
227 
228 private slots:
232  void timeTrigger();
233 
238  void setCurrentTime(void);
239 
240 private:
242  Logger* _log;
243 
245  int _currentPriority;
246 
248  int _manualSelectedPriority;
249 
251  QMap<int, InputInfo> _activeInputs;
252 
254  InputInfo _lowestPriorityInfo;
255 
256  // Reflect the state of auto select
257  bool _sourceAutoSelectEnabled;
258 
259  // Timer to update Muxer times independent
260  QTimer* _updateTimer;
261 
262  QTimer* _timer;
263  QTimer* _blockTimer;
264 };
Definition: Logger.h:32
void clearAll(bool forceClearAll=false)
Clears all priority channels.
Definition: PriorityMuxer.cpp:258
void updateLedColorsLength(const int &ledCount)
Update all ledColos with min length of >= 1 to fit the new led length.
Definition: PriorityMuxer.cpp:99
void autoSelectChanged(const bool &state)
Emits whenever the auto selection state has been changed.
bool clearInput(const uint8_t priority)
Clears the specified priority channel and update _currentPriority on success.
Definition: PriorityMuxer.cpp:244
void setEnable(const bool &enable)
Start/Stop the PriorityMuxer update timer; On disabled no priority and timeout updates will be perfor...
Definition: PriorityMuxer.cpp:58
QString owner
specific owner description
Definition: PriorityMuxer.h:54
void timeRunner()
Signal which emits when a effect or color with timeout > -1 is running, once per second.
QList< int > getPriorities() const
Returns the number of active priorities.
Definition: PriorityMuxer.cpp:111
void registerInput(const int priority, const hyperion::Components &component, const QString &origin="System", const QString &owner="", unsigned smooth_cfg=SMOOTHING_MODE_DEFAULT)
Register a new input by priority, the priority is not active (timeout -100 isn&#39;t muxer recognized) un...
Definition: PriorityMuxer.cpp:136
static const int LOWEST_PRIORITY
The lowest possible priority, which is used when no priority channels are active. ...
Definition: PriorityMuxer.h:58
void priorityChanged(const quint8 &priority, const bool &state)
A priority has been added (registerInput()) or deleted, method clear or timeout clear.
The information structure for a single priority channel.
Definition: PriorityMuxer.h:37
int priority
The priority of this channel.
Definition: PriorityMuxer.h:40
void signalTimeTrigger()
internal used signal to resolve treading issues with timer
Image< ColorRgb > image
The raw Image (size should be preprocessed!)
Definition: PriorityMuxer.h:46
int64_t timeoutTime_ms
The absolute timeout of the channel.
Definition: PriorityMuxer.h:42
int getCurrentPriority() const
Returns the current priority.
Definition: PriorityMuxer.h:110
The PriorityMuxer handles the priority channels.
Definition: PriorityMuxer.h:30
unsigned smooth_cfg
id of smoothing config
Definition: PriorityMuxer.h:52
void activeStateChanged(const quint8 &priority, const bool &state)
Emits whenever a priority changes active state.
Components
Enumeration of components in Hyperion.
Definition: Components.h:10
void visiblePriorityChanged(const quint8 &priority)
Emits whenever the visible priority has changed.
bool setInput(const int priority, const std::vector< ColorRgb > &ledColors, int64_t timeout_ms=-1)
Update the current color of a priority (prev registered with registerInput())
Definition: PriorityMuxer.cpp:160
PriorityMuxer(int ledCount)
Constructs the PriorityMuxer for the given number of leds (used to switch to black when there are no ...
Definition: PriorityMuxer.cpp:17
bool setPriority(const uint8_t priority)
Overwrite current lowest piority with manual selection; On success disables aito selection.
Definition: PriorityMuxer.cpp:87
~PriorityMuxer()
Destructor.
Definition: PriorityMuxer.cpp:54
bool setInputImage(const int priority, const Image< ColorRgb > &image, int64_t timeout_ms=-1)
Update the current image of a priority (prev registered with registerInput())
Definition: PriorityMuxer.cpp:199
QString origin
Who set it.
Definition: PriorityMuxer.h:50
hyperion::Components componentId
The component.
Definition: PriorityMuxer.h:48
bool setSourceAutoSelectEnabled(const bool &enabel, const bool &update=true)
Enable or disable auto source selection.
Definition: PriorityMuxer.cpp:63
void prioritiesChanged(void)
Emits whenever something changes which influences the priorities listing Emits also in 1s interval wh...
std::vector< ColorRgb > ledColors
The colors for each led of the channel.
Definition: PriorityMuxer.h:44
bool hasPriority(const int priority) const
Returns the state (enabled/disabled) of a specific priority channel.
Definition: PriorityMuxer.cpp:116
const InputInfo getInputInfo(const int priority) const
Returns the information of a specified priority channel.
Definition: PriorityMuxer.cpp:121
bool setInputInactive(const quint8 &priority)
Set the given priority to inactive.
Definition: PriorityMuxer.cpp:238
bool isSourceAutoSelectEnabled() const
Get the state of source auto selection.
Definition: PriorityMuxer.h:90