hyperion.ng
LedDevice.h
1 #pragma once
2 
3 #include <QObject>
4 #include <QString>
5 #include <QJsonObject>
6 #include <QJsonArray>
7 #include <QJsonDocument>
8 
9 // STL incldues
10 #include <vector>
11 #include <map>
12 #include <algorithm>
13 
14 #include <QTimer>
15 
16 // Utility includes
17 #include <utils/ColorRgb.h>
18 #include <utils/ColorRgbw.h>
19 #include <utils/RgbToRgbw.h>
20 #include <utils/Logger.h>
21 #include <functional>
22 #include <utils/Components.h>
23 
24 class LedDevice;
25 
26 typedef LedDevice* ( *LedDeviceCreateFuncType ) ( const QJsonObject& );
27 typedef std::map<QString,LedDeviceCreateFuncType> LedDeviceRegistry;
28 
32 class LedDevice : public QObject
33 {
34  Q_OBJECT
35 
36 public:
37  LedDevice(const QJsonObject& config = QJsonObject(), QObject* parent = nullptr);
38  virtual ~LedDevice();
39 
41  virtual int switchOff();
42 
44  virtual int switchOn();
45 
46  virtual int setLedValues(const std::vector<ColorRgb>& ledValues);
47 
52  const QString & getColorOrder() { return _colorOrder; };
53 
54  void setActiveDevice(QString dev);
55  const QString & getActiveDevice() { return _activeDevice; };
56  void setLedCount(int ledCount);
57  int getLedCount() { return _ledCount; }
58 
59  void setEnable(bool enable);
60  bool enabled() { return _enabled; };
61  int getLatchTime() { return _latchTime_ms; };
62 
63  inline bool componentState() { return enabled(); };
64 
65 public slots:
69  virtual void start() { _deviceReady = open(); };
70 
78  virtual int write(const std::vector<ColorRgb>& ledValues) = 0;
79 
80 signals:
85  void enableStateChanged(bool newState);
86 
93  void visiblePriorityChanged(const quint8 &priority);
94 
95 protected:
96  virtual bool init(const QJsonObject &deviceConfig);
97 
103  virtual int open();
104 
105  // Helper to pipe device config from constructor to start()
106  QJsonObject _devConfig;
107 
110 
112  std::vector<uint8_t> _ledBuffer;
113 
114  bool _deviceReady;
115 
116  QString _activeDevice;
117 
118  int _ledCount;
119  int _ledRGBCount;
120  int _ledRGBWCount;
121 
125  unsigned int _refresh_timer_interval;
126  qint64 _last_write_time;
127  unsigned int _latchTime_ms;
128 protected slots:
130  int rewriteLeds();
131 
132 private:
133  std::vector<ColorRgb> _ledValues;
134  bool _componentRegistered;
135  bool _enabled;
136  QString _colorOrder;
137 };
Definition: Logger.h:32
Interface (pure virtual base class) for LedDevices.
Definition: LedDevice.h:32
virtual int write(const std::vector< ColorRgb > &ledValues)=0
Writes the RGB-Color values to the leds.
QTimer _refresh_timer
Timer object which makes sure that led data is written at a minimum rate e.g.
Definition: LedDevice.h:124
const QString & getColorOrder()
Get color order of device.
Definition: LedDevice.h:52
std::vector< uint8_t > _ledBuffer
The buffer containing the packed RGB values.
Definition: LedDevice.h:112
virtual void start()
Is called on thread start, all construction tasks and init should run here.
Definition: LedDevice.h:69
Logger * _log
The common Logger instance for all LedDevices.
Definition: LedDevice.h:109
virtual int open()
Opens and configures the output device.
Definition: LedDevice.cpp:39
virtual int switchOn()
Switch the leds on (led hardware enable), used if reinitialization is required for the device impleme...
Definition: LedDevice.cpp:108
void enableStateChanged(bool newState)
Emits whenever the led device switches between on/off.
int rewriteLeds()
Write the last data to the leds again.
Definition: LedDevice.cpp:120
virtual int switchOff()
Switch the leds off (led hardware disable)
Definition: LedDevice.cpp:103
void visiblePriorityChanged(const quint8 &priority)
PIPER signal for Priority Muxer -> LedDevice.