ckb-next  v0.2.8 at branch master
ckb-next driver for corsair devices
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
kbmanager.h
Go to the documentation of this file.
1 #ifndef KBMANAGER_H
2 #define KBMANAGER_H
3 
4 #include <QObject>
5 #include <QTimer>
6 #include <cmath>
7 #include <QSet>
8 #include "kb.h"
9 
10 // Class for managing keyboard devices. Handles scanning devices from the daemon and creating/destroying Kb objects for each device.
11 
12 #define DAEMON_UNAVAILABLE_STR "<unavailable>"
13 
14 class KbManager : public QObject
15 {
16  Q_OBJECT
17 public:
18  // Call at startup
19  static void init(QString guiVersion);
20  // Call at shutdown
21  static void stop();
22  // Singleton instance. Signals are emitted from here. Created when init() is called.
23  static inline KbManager* kbManager() { return _kbManager; }
24 
25  // ckb version info
26  static inline QString ckbGuiVersion() { return _guiVersion; }
27  static inline QString ckbDaemonVersion(){ return _daemonVersion; }
28  // String (e.g. "alpha-v0.0.1" or "0.0.1") -> float. Daemon version returns INFINITY if not connected.
29  static float parseVersionString(QString version);
30  static inline float ckbGuiVersionF() { return parseVersionString(_guiVersion); }
32 
33  // List of all connected devices
34  static const QSet<Kb*> devices() { return _kbManager ? _kbManager->_devices : QSet<Kb*>(); }
35 
36  // Event timer for the driver. Created during init(). Starts ticking when fps() is called.
37  // Use this for animations or other events which need to run at a high frame rate.
38  static inline QTimer* eventTimer() { return _kbManager ? _kbManager->_eventTimer : 0; }
39  // Sets the frame rate for the event timer
40  static void fps(int framerate);
41 
42  // Timer for scanning the driver/device list. May also be useful for periodic GUI events. Created during init(), always runs at 10FPS.
43  static inline QTimer* scanTimer() { return _kbManager ? _kbManager->_scanTimer : 0; }
44 
45 signals:
46  // A new device was connected.
47  void kbConnected(Kb* device);
48  // A device was disconnected. The Kb object will be deleted afterward.
49  void kbDisconnected(Kb* device);
50 
51  // The daemon version info was updated (or the daemon was started/stopped)
52  void versionUpdated();
53 
54 private slots:
55  void scanKeyboards();
56 
57 private:
59  static QString _guiVersion, _daemonVersion;
60 
61  explicit KbManager(QObject* parent = 0);
62 
63  QSet<Kb*> _devices;
65 };
66 
67 #endif // KBMANAGER_H
static KbManager * kbManager()
Definition: kbmanager.h:23
static void stop()
Definition: kbmanager.cpp:19
static QString ckbGuiVersion()
Definition: kbmanager.h:26
static QTimer * eventTimer()
Definition: kbmanager.h:38
static QString _daemonVersion
Definition: kbmanager.h:59
static float parseVersionString(QString version)
Definition: kbmanager.cpp:48
static const QSet< Kb * > devices()
Definition: kbmanager.h:34
void versionUpdated()
static QTimer * scanTimer()
Definition: kbmanager.h:43
static float ckbDaemonVersionF()
Definition: kbmanager.h:31
QTimer * _eventTimer
Definition: kbmanager.h:64
QTimer * _scanTimer
Definition: kbmanager.h:64
void kbDisconnected(Kb *device)
static float ckbGuiVersionF()
Definition: kbmanager.h:30
QSet< Kb * > _devices
Definition: kbmanager.h:63
void kbConnected(Kb *device)
Definition: kb.h:11
static void init(QString guiVersion)
Definition: kbmanager.cpp:12
#define DAEMON_UNAVAILABLE_STR
Definition: kbmanager.h:12
KbManager(QObject *parent=0)
Definition: kbmanager.cpp:26
static QString ckbDaemonVersion()
Definition: kbmanager.h:27
void scanKeyboards()
Definition: kbmanager.cpp:62
static QString _guiVersion
Definition: kbmanager.h:59
static KbManager * _kbManager
Definition: kbmanager.h:58
static void fps(int framerate)
Definition: kbmanager.cpp:38