Merged in f5soh/librepilot/update_credits (pull request #529)
[librepilot.git] / ground / gcs / src / plugins / ophid / inc / ophid.h
blob6f29227d875d88be5671de48379837b95c22ae21
1 /**
2 ******************************************************************************
4 * @file ophid.h
5 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2013.
6 * @addtogroup GCSPlugins GCS Plugins
7 * @{
8 * @addtogroup opHIDPlugin Raw HID Plugin
9 * @{
10 * @brief Impliments a HID USB connection to the flight hardware as a QIODevice
11 *****************************************************************************/
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 * for more details.
23 * You should have received a copy of the GNU General Public License along
24 * with this program; if not, write to the Free Software Foundation, Inc.,
25 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #ifndef OPHID_H
29 #define OPHID_H
31 #include "ophid_global.h"
33 #include <QThread>
34 #include <QIODevice>
35 #include <QMutex>
36 #include <QByteArray>
37 #include "ophid_hidapi.h"
38 #include "ophid_usbmon.h"
40 class RawHIDReadThread;
41 class RawHIDWriteThread;
43 /**
44 * The actual IO device that will be used to communicate
45 * with the board.
47 class OPHID_EXPORT RawHID : public QIODevice {
48 Q_OBJECT
50 friend class RawHIDReadThread;
51 friend class RawHIDWriteThread;
53 public:
54 RawHID();
55 RawHID(const QString &deviceName);
56 virtual ~RawHID();
58 virtual bool open(OpenMode mode);
59 virtual void close();
60 virtual bool isSequential() const;
62 signals:
63 void closed();
65 public slots:
66 void onDeviceUnplugged(int num);
68 protected:
69 virtual qint64 readData(char *data, qint64 maxSize);
70 virtual qint64 writeData(const char *data, qint64 maxSize);
71 virtual qint64 bytesAvailable() const;
72 virtual qint64 bytesToWrite() const;
74 // Callback from the read thread to open the device
75 bool openDevice();
77 // Callback from teh read thread to close the device
78 bool closeDevice();
80 QString serialNumber;
82 int m_deviceNo;
83 opHID_hidapi dev;
84 bool device_open;
86 RawHIDReadThread *m_readThread;
87 RawHIDWriteThread *m_writeThread;
89 QMutex *m_mutex;
90 QMutex *m_startedMutex;
93 #endif // OPHID_H