dRonin  adbada4
dRonin GCS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
usbsignalfilter.cpp
Go to the documentation of this file.
1 
13 /*
14  * This program is free software; you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation; either version 3 of the License, or
17  * (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful, but
20  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  * for more details.
23  *
24  * You should have received a copy of the GNU General Public License along
25  * with this program; if not, see <http://www.gnu.org/licenses/>
26  *
27  * Additional note on redistribution: The copyright and license notices above
28  * must be maintained in each individual source file that is a derivative work
29  * of this source file; otherwise redistribution is prohibited.
30  */
31 
32 #include "usbsignalfilter.h"
33 #include <QDebug>
34 
35 //#define USB_FILTER_DEBUG
36 #ifdef USB_FILTER_DEBUG
37 #define USB_FILTER_QXTLOG_DEBUG(...) qDebug() << __VA_ARGS__
38 #else // USB_FILTER_DEBUG
39 #define USB_FILTER_QXTLOG_DEBUG(...)
40 #endif // USB_FILTER_DEBUG
41 
42 bool USBSignalFilter::portMatches(USBPortInfo port)
43 {
44  if ((m_vid.contains(port.vendorID) || m_vid.isEmpty())
45  && (port.productID == m_pid || m_pid == -1)
46  && ((port.bcdDevice >> 8) == m_boardModel || m_boardModel == -1)
47  && (port.getRunState() == m_runState || m_runState == -1)) {
48  return true;
49  }
50 
51  return false;
52 }
53 
54 void USBSignalFilter::m_deviceDiscovered(USBPortInfo port)
55 {
56  if (portMatches(port)) {
57  USB_FILTER_QXTLOG_DEBUG("USBSignalFilter emit device discovered");
58  emit deviceDiscovered();
59  }
60 }
61 
62 void USBSignalFilter::m_deviceRemoved(USBPortInfo port)
63 {
64  if (portMatches(port)) {
65  USB_FILTER_QXTLOG_DEBUG("USBSignalFilter emit device removed");
66  emit deviceRemoved();
67  }
68 }
69 
70 USBSignalFilter::USBSignalFilter(int vid, int pid, int boardModel, int runState)
71  : m_pid(pid)
72  , m_boardModel(boardModel)
73  , m_runState(runState)
74 {
75  if (vid != -1)
76  m_vid.append(vid);
77 
79  &USBSignalFilter::m_deviceDiscovered, Qt::QueuedConnection);
81  &USBSignalFilter::m_deviceRemoved, Qt::QueuedConnection);
82 }
83 
84 USBSignalFilter::USBSignalFilter(QList<int> vid, int pid, int boardModel, int runState)
85  : m_vid(vid)
86  , m_pid(pid)
87  , m_boardModel(boardModel)
88  , m_runState(runState)
89 {
91  &USBSignalFilter::m_deviceDiscovered, Qt::QueuedConnection);
93  &USBSignalFilter::m_deviceRemoved, Qt::QueuedConnection);
94 }
int productID
Product ID.
Definition: usbmonitor.h:51
int bcdDevice
Definition: usbmonitor.h:52
void deviceDiscovered(const USBPortInfo &info)
void deviceRemoved()
static USBMonitor * instance()
Definition: usbmonitor.cpp:176
void deviceRemoved(const USBPortInfo &info)
USBSignalFilter(int vid, int pid, int boardModel, int runState)
void deviceDiscovered()
unsigned char getRunState()
Definition: usbmonitor.h:54
int vendorID
Vendor ID.
Definition: usbmonitor.h:50