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 Class Reference

#include <src/ckb/kbmanager.h>

+ Inheritance diagram for KbManager:
+ Collaboration diagram for KbManager:

Signals

void kbConnected (Kb *device)
 
void kbDisconnected (Kb *device)
 
void versionUpdated ()
 

Static Public Member Functions

static void init (QString guiVersion)
 
static void stop ()
 
static KbManagerkbManager ()
 
static QString ckbGuiVersion ()
 
static QString ckbDaemonVersion ()
 
static float parseVersionString (QString version)
 
static float ckbGuiVersionF ()
 
static float ckbDaemonVersionF ()
 
static const QSet< Kb * > devices ()
 
static QTimer * eventTimer ()
 
static void fps (int framerate)
 
static QTimer * scanTimer ()
 

Private Slots

void scanKeyboards ()
 

Private Member Functions

 KbManager (QObject *parent=0)
 

Private Attributes

QSet< Kb * > _devices
 
QTimer * _eventTimer
 
QTimer * _scanTimer
 

Static Private Attributes

static KbManager_kbManager = 0
 
static QString _guiVersion
 
static QString _daemonVersion = "<unavailable>"
 

Detailed Description

Definition at line 14 of file kbmanager.h.

Constructor & Destructor Documentation

KbManager::KbManager ( QObject parent = 0)
explicitprivate

Definition at line 26 of file kbmanager.cpp.

References _eventTimer, _scanTimer, and scanKeyboards().

Referenced by init().

26  : QObject(parent){
27  // Set up the timers
28  _eventTimer = new QTimer(this);
29  _eventTimer->setTimerType(Qt::PreciseTimer);
30  _scanTimer = new QTimer(this);
31  _scanTimer->start(1000);
32  connect(_scanTimer, SIGNAL(timeout()), this, SLOT(scanKeyboards()));
33 
34  // Scan for keyboards immediately so they show up as soon as the GUI appears.
35  QTimer::singleShot(0,this,SLOT(scanKeyboards()));
36 }
QTimer * _eventTimer
Definition: kbmanager.h:64
QTimer * _scanTimer
Definition: kbmanager.h:64
void scanKeyboards()
Definition: kbmanager.cpp:62

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Function Documentation

static QString KbManager::ckbDaemonVersion ( )
inlinestatic

Definition at line 27 of file kbmanager.h.

References _daemonVersion.

Referenced by MainWindow::updateVersion().

27 { return _daemonVersion; }
static QString _daemonVersion
Definition: kbmanager.h:59

+ Here is the caller graph for this function:

static float KbManager::ckbDaemonVersionF ( )
inlinestatic

Definition at line 31 of file kbmanager.h.

References _daemonVersion, DAEMON_UNAVAILABLE_STR, and parseVersionString().

Referenced by KbFirmware::_latestForBoard(), and MainWindow::updateVersion().

static QString _daemonVersion
Definition: kbmanager.h:59
static float parseVersionString(QString version)
Definition: kbmanager.cpp:48
#define DAEMON_UNAVAILABLE_STR
Definition: kbmanager.h:12

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static QString KbManager::ckbGuiVersion ( )
inlinestatic

Definition at line 26 of file kbmanager.h.

References _guiVersion.

26 { return _guiVersion; }
static QString _guiVersion
Definition: kbmanager.h:59
static float KbManager::ckbGuiVersionF ( )
inlinestatic

Definition at line 30 of file kbmanager.h.

References _guiVersion, and parseVersionString().

Referenced by KbFirmware::_latestForBoard(), and MainWindow::updateVersion().

static float parseVersionString(QString version)
Definition: kbmanager.cpp:48
static QString _guiVersion
Definition: kbmanager.h:59

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static const QSet<Kb*> KbManager::devices ( )
inlinestatic

Definition at line 34 of file kbmanager.h.

References _devices, and _kbManager.

34 { return _kbManager ? _kbManager->_devices : QSet<Kb*>(); }
QSet< Kb * > _devices
Definition: kbmanager.h:63
static KbManager * _kbManager
Definition: kbmanager.h:58
static QTimer* KbManager::eventTimer ( )
inlinestatic

Definition at line 38 of file kbmanager.h.

References _eventTimer, and _kbManager.

Referenced by fps().

38 { return _kbManager ? _kbManager->_eventTimer : 0; }
QTimer * _eventTimer
Definition: kbmanager.h:64
static KbManager * _kbManager
Definition: kbmanager.h:58

+ Here is the caller graph for this function:

void KbManager::fps ( int  framerate)
static

Definition at line 38 of file kbmanager.cpp.

References eventTimer().

Referenced by Kb::frameRate().

38  {
39  QTimer* timer = eventTimer();
40  if(!timer)
41  return;
42  if(timer->isActive())
43  timer->setInterval(1000 / framerate);
44  else
45  timer->start(1000 / framerate);
46 }
static QTimer * eventTimer()
Definition: kbmanager.h:38

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void KbManager::init ( QString  guiVersion)
static

Definition at line 12 of file kbmanager.cpp.

References _guiVersion, _kbManager, and KbManager().

Referenced by MainWindow::MainWindow().

12  {
13  _guiVersion = guiVersion;
14  if(_kbManager)
15  return;
16  _kbManager = new KbManager();
17 }
KbManager(QObject *parent=0)
Definition: kbmanager.cpp:26
static QString _guiVersion
Definition: kbmanager.h:59
static KbManager * _kbManager
Definition: kbmanager.h:58

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void KbManager::kbConnected ( Kb device)
signal

Definition at line 174 of file moc_kbmanager.cpp.

Referenced by scanKeyboards().

175 {
176  void *_a[] = { Q_NULLPTR, const_cast<void*>(reinterpret_cast<const void*>(&_t1)) };
177  QMetaObject::activate(this, &staticMetaObject, 0, _a);
178 }

+ Here is the caller graph for this function:

void KbManager::kbDisconnected ( Kb device)
signal

Definition at line 181 of file moc_kbmanager.cpp.

Referenced by scanKeyboards().

182 {
183  void *_a[] = { Q_NULLPTR, const_cast<void*>(reinterpret_cast<const void*>(&_t1)) };
184  QMetaObject::activate(this, &staticMetaObject, 1, _a);
185 }

+ Here is the caller graph for this function:

static KbManager* KbManager::kbManager ( )
inlinestatic

Definition at line 23 of file kbmanager.h.

References _kbManager.

Referenced by MainWindow::MainWindow().

23 { return _kbManager; }
static KbManager * _kbManager
Definition: kbmanager.h:58

+ Here is the caller graph for this function:

float KbManager::parseVersionString ( QString  version)
static

Definition at line 48 of file kbmanager.cpp.

Referenced by ckbDaemonVersionF(), ckbGuiVersionF(), and KbFirmware::processDownload().

48  {
49  // Remove extraneous info (anything after a +, anything non-numeric)
50  QStringList dots = version.replace(QRegExp("\\+.+"), "").replace(QRegExp("[^\\d\\.]"), "").split(".");
51  float base = 1.f;
52  float res = 0.f;
53  // A number like "1.2.3" will result in 1.0203
54  // NB: will fail if a point version goes over 99 or if using more than two dots. floats can only reliably encode 7 decimal digits.
55  foreach(const QString& dot, dots){
56  res += dot.toFloat() * base;
57  base /= 100.f;
58  }
59  return res;
60 }

+ Here is the caller graph for this function:

void KbManager::scanKeyboards ( )
privateslot

Definition at line 62 of file kbmanager.cpp.

References _daemonVersion, _devices, _eventTimer, _scanTimer, DAEMON_UNAVAILABLE_STR, devpath, Kb::isOpen(), kbConnected(), kbDisconnected(), Kb::load(), Kb::matches(), Kb::save(), and versionUpdated().

Referenced by KbManager().

62  {
63  QString rootdev = devpath.arg(0);
64  QFile connected(rootdev + "/connected");
65  if(!connected.open(QIODevice::ReadOnly)){
66  // No root controller - remove all keyboards
67  foreach(Kb* kb, _devices){
68  emit kbDisconnected(kb);
69  kb->save();
70  delete kb;
71  }
72  _devices.clear();
75  emit versionUpdated();
76  }
77  return;
78  }
79  // Check daemon version
80  QFile version(rootdev + "/version");
81  QString vString;
82  if(version.open(QIODevice::ReadOnly)){
83  vString = QString::fromUtf8(version.readLine()).trimmed();
84  version.close();
85  } else
86  vString = DAEMON_UNAVAILABLE_STR;
87  if(_daemonVersion != vString){
88  _daemonVersion = vString;
89  emit versionUpdated();
90  }
91 
92  // Scan connected devices
93  QList<QStringList> lines;
94  while(1){
95  QString line = connected.readLine().trimmed();
96  if(line.isEmpty())
97  break;
98  QStringList components = line.split(" ");
99  if(components.length() < 2) // "<path> <serial> <name>" (we're only interested in the first two)
100  continue;
101  lines.append(components);
102  }
103  connected.close();
104 
105  // Remove any active devices not in the list
106  QMutableSetIterator<Kb*> i(_devices);
107  while(i.hasNext()){
108  Kb* kb = i.next();
109  bool matched = false;
110  foreach(const QStringList& line, lines){
111  if(kb->matches(line[0], line[1])){
112  matched = true;
113  break;
114  }
115  }
116  if(matched)
117  continue;
118  // Device not found, remove
119  i.remove();
120  emit kbDisconnected(kb);
121  kb->save();
122  delete kb;
123  }
124 
125  // Add any new devices found in the list
126  foreach(const QStringList& line, lines){
127  bool matched = false;
128  foreach(Kb* kb, _devices){
129  if(kb->matches(line[0], line[1])){
130  matched = true;
131  break;
132  }
133  }
134  if(matched)
135  continue;
136  // Device not found, create new
137  Kb* kb = new Kb(this, line[0]);
138  if(!kb->isOpen()){
139  delete kb;
140  continue;
141  }
142  _devices.insert(kb);
143  // Load preferences and send signal
144  emit kbConnected(kb);
145  kb->load();
146  connect(_eventTimer, SIGNAL(timeout()), kb, SLOT(frameUpdate()));
147  connect(_scanTimer, SIGNAL(timeout()), kb, SLOT(autoSave()));
148  }
149 }
bool matches(const QString &path, const QString &serial)
Definition: kb.h:157
void load()
Definition: kb.cpp:241
static QString _daemonVersion
Definition: kbmanager.h:59
void versionUpdated()
QTimer * _eventTimer
Definition: kbmanager.h:64
QString devpath
Definition: kbmanager.cpp:4
QTimer * _scanTimer
Definition: kbmanager.h:64
void kbDisconnected(Kb *device)
QSet< Kb * > _devices
Definition: kbmanager.h:63
void kbConnected(Kb *device)
Definition: kb.h:11
#define DAEMON_UNAVAILABLE_STR
Definition: kbmanager.h:12
bool isOpen() const
Definition: kb.h:147
void save()
Definition: kb.cpp:273

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static QTimer* KbManager::scanTimer ( )
inlinestatic

Definition at line 43 of file kbmanager.h.

References _kbManager, and _scanTimer.

Referenced by MainWindow::MainWindow().

43 { return _kbManager ? _kbManager->_scanTimer : 0; }
QTimer * _scanTimer
Definition: kbmanager.h:64
static KbManager * _kbManager
Definition: kbmanager.h:58

+ Here is the caller graph for this function:

void KbManager::stop ( )
static

Definition at line 19 of file kbmanager.cpp.

References _kbManager.

Referenced by MainWindow::cleanup().

19  {
20  if(!_kbManager)
21  return;
22  delete _kbManager;
23  _kbManager = 0;
24 }
static KbManager * _kbManager
Definition: kbmanager.h:58

+ Here is the caller graph for this function:

void KbManager::versionUpdated ( )
signal

Definition at line 188 of file moc_kbmanager.cpp.

Referenced by scanKeyboards().

189 {
190  QMetaObject::activate(this, &staticMetaObject, 2, Q_NULLPTR);
191 }

+ Here is the caller graph for this function:

Field Documentation

QString KbManager::_daemonVersion = "<unavailable>"
staticprivate

Definition at line 59 of file kbmanager.h.

Referenced by ckbDaemonVersion(), ckbDaemonVersionF(), and scanKeyboards().

QSet<Kb*> KbManager::_devices
private

Definition at line 63 of file kbmanager.h.

Referenced by devices(), and scanKeyboards().

QTimer* KbManager::_eventTimer
private

Definition at line 64 of file kbmanager.h.

Referenced by eventTimer(), KbManager(), and scanKeyboards().

QString KbManager::_guiVersion
staticprivate

Definition at line 59 of file kbmanager.h.

Referenced by ckbGuiVersion(), ckbGuiVersionF(), and init().

KbManager * KbManager::_kbManager = 0
staticprivate

Definition at line 58 of file kbmanager.h.

Referenced by devices(), eventTimer(), init(), kbManager(), scanTimer(), and stop().

QTimer * KbManager::_scanTimer
private

Definition at line 64 of file kbmanager.h.

Referenced by KbManager(), scanKeyboards(), and scanTimer().


The documentation for this class was generated from the following files: