dRonin  adbada4
dRonin GCS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
usbmonitor.h
Go to the documentation of this file.
1 
16 /*
17  * This program is free software; you can redistribute it and/or modify
18  * it under the terms of the GNU General Public License as published by
19  * the Free Software Foundation; either version 3 of the License, or
20  * (at your option) any later version.
21  *
22  * This program is distributed in the hope that it will be useful, but
23  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
24  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
25  * for more details.
26  *
27  * You should have received a copy of the GNU General Public License along
28  * with this program; if not, see <http://www.gnu.org/licenses/>
29  *
30  * Additional note on redistribution: The copyright and license notices above
31  * must be maintained in each individual source file that is a derivative work
32  * of this source file; otherwise redistribution is prohibited.
33  */
34 
35 #ifndef USBMONITOR_H
36 #define USBMONITOR_H
37 
38 #include "rawhid_global.h"
39 
40 #include <QTimer>
41 
43 {
44  QString serialNumber; // As a string as it can be anything, really...
45  QString manufacturer;
46  QString product;
47 
48  QString path;
49 
50  int vendorID;
51  int productID;
52  int bcdDevice;
53 
54  unsigned char getRunState() { return bcdDevice & 0x00ff; }
55 
56  bool operator==(USBPortInfo const &port)
57  {
58  if (port.vendorID != vendorID)
59  return false;
60 
61  if (port.productID != productID)
62  return false;
63 
64  if (port.bcdDevice != bcdDevice)
65  return false;
66 
67  if (port.serialNumber != serialNumber) {
68  if ((serialNumber != "") && (port.serialNumber != "")) {
69  return false;
70  }
71  }
72 
73  /* Don't compare manufacturer or product strings for identification */
74 
75  return true; // We ran the gauntlet and came out OK.
76  }
77 };
78 
80 
85 class RAWHID_EXPORT USBMonitor : public QObject
86 {
87  Q_OBJECT
88 
89 public:
90  enum RunState {
91  Bootloader = 0x01,
92  Running = 0x02,
93  Upgrader = 0x03,
94  };
95 
96  static USBMonitor *instance();
97 
98  USBMonitor(QObject *parent = nullptr);
99  ~USBMonitor();
100  QList<USBPortInfo> availableDevices();
101  QList<USBPortInfo> availableDevices(int vid, int pid, int boardModel, int runState);
102 signals:
110  void deviceDiscovered(const USBPortInfo &info);
118  void deviceRemoved(const USBPortInfo &info);
119 
120 private slots:
121  void periodic();
122 
123 private:
125  QList<USBPortInfo> knowndevices;
126 
127  Q_DISABLE_COPY(USBMonitor)
128  static USBMonitor *m_instance;
129 
130  QTimer periodicTimer;
131 
132  struct hid_device_info *prevDevList;
133 
134  bool enumerating;
135 };
136 #endif // USBMONITOR_H
Q_DECLARE_METATYPE(USBPortInfo)
int productID
Product ID.
Definition: usbmonitor.h:51
QString manufacturer
Definition: usbmonitor.h:45
int bcdDevice
Definition: usbmonitor.h:52
QString serialNumber
Definition: usbmonitor.h:44
QString product
Definition: usbmonitor.h:46
unsigned char getRunState()
Definition: usbmonitor.h:54
QString path
Opaque OS-specific path.
Definition: usbmonitor.h:48
bool operator==(USBPortInfo const &port)
Definition: usbmonitor.h:56
int vendorID
Vendor ID.
Definition: usbmonitor.h:50