-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsmartpowermonitor.cpp
52 lines (47 loc) · 1.52 KB
/
smartpowermonitor.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include "smartpowermonitor.h"
#include <qhidmanager.h>
#include <cassert>
#include <QDebug>
SmartPowerMonitor::SmartPowerMonitor()
{}
QString SmartPowerMonitor::getName() {
return "Odroid";
}
void SmartPowerMonitor::monitor(quint32 interval_ms) {
connect(&tmr,SIGNAL(timeout()),this,SLOT(checkDevices()));
tmr.start(interval_ms);
}
void SmartPowerMonitor::checkDevices() {
QVector<QHIDInfo> devs = QHIDManager::get().enumerate(0x04d8,0x003f);
QList<OdroidSmartPowerSource*> toDelete = sources.toList();
//Delete obsoletes
for (QHIDInfo info : devs) {
bool newEntry = true;
for (OdroidSmartPowerSource* s : sources) {
if (s->path() == info.path) {
assert(toDelete.contains(s));
toDelete.removeAll(s);
assert(!toDelete.contains(s));
newEntry = false;
break;
}
}
if (newEntry) {
OdroidSmartPowerSource* sps = new OdroidSmartPowerSource(info.path.toStdString().c_str());
if (!sps->good()) continue;
sources.append(sps);
emit addSource(sources.last());
qDebug() << "Serial : " << info.serial_number;
qDebug() << "Manufacturer: " << info.manufacturer_string;
qDebug() << "Product : " << info.product_string;
qDebug() << "Other: : " << info.path << "\n";
}
}
for (int i = 0; i < sources.size(); i++) {
if (toDelete.contains(sources[i])) {
emit removeSource(sources.at(i));
delete sources.at(i);
sources.remove(i);
}
}
}