wfview/usbcontroller.h

117 wiersze
2.5 KiB
C
Czysty Zwykły widok Historia

2022-04-22 10:11:21 +00:00
#ifndef usbController_H
#define usbController_H
#include <iostream>
#include <QThread>
#include <QCoreApplication>
#include <QTimer>
#include <QDateTime>
#include <QRect>
#include <QGraphicsTextItem>
#include <QColor>
2022-04-25 16:40:41 +00:00
#include <QVector>
2022-04-22 10:11:21 +00:00
#ifndef Q_OS_WIN
#include "hidapi/hidapi.h"
#else
#include "hidapi.h"
#endif
#ifndef Q_OS_WIN
//Headers needed for sleeping.
#include <unistd.h>
#endif
// Include these so we have the various enums
#include "rigidentities.h"
using namespace std;
#define HIDDATALENGTH 64
#define MAX_STR 255
struct COMMAND {
2022-04-26 07:41:58 +00:00
COMMAND() {}
2022-04-25 16:40:41 +00:00
2022-05-17 07:53:24 +00:00
COMMAND(int index, QString text, int command, char suffix) :
2022-04-25 16:40:41 +00:00
index(index), text(text), command(command), suffix(suffix), bandswitch(false){}
2022-05-17 07:53:24 +00:00
COMMAND(int index, QString text, int command, bandType band) :
2022-04-25 16:40:41 +00:00
index(index), text(text), command(command),band(band), bandswitch(true) {}
2022-04-22 10:11:21 +00:00
int index;
2022-04-26 07:41:58 +00:00
QString text;
2022-05-17 07:53:24 +00:00
int command;
unsigned char suffix;
2022-04-22 10:11:21 +00:00
bandType band;
2022-04-26 07:41:58 +00:00
bool bandswitch;
2022-04-22 10:11:21 +00:00
};
struct BUTTON {
2022-04-26 07:41:58 +00:00
BUTTON() {}
BUTTON(char num, QRect pos, const QColor textColour) :
num(num), pos(pos), textColour(textColour) {}
2022-04-22 10:11:21 +00:00
quint8 num;
QRect pos;
2022-04-26 07:41:58 +00:00
const QColor textColour;
2022-04-22 10:11:21 +00:00
int onEvent = 0;
int offEvent = 0;
2022-04-27 11:56:54 +00:00
const COMMAND* onCommand=Q_NULLPTR;
const COMMAND* offCommand=Q_NULLPTR;
2022-04-25 16:40:41 +00:00
QGraphicsTextItem* onText;
QGraphicsTextItem* offText;
2022-04-22 10:11:21 +00:00
};
class usbController : public QObject
{
Q_OBJECT
public:
usbController();
~usbController();
int hidApiWrite(unsigned char* data, unsigned char length);
public slots:
void init();
void run();
void runTimer();
void ledControl(bool on, unsigned char num);
2022-09-18 16:42:41 +00:00
void receiveCommands(QVector<COMMAND>*);
2022-04-22 10:11:21 +00:00
signals:
void jogPlus();
void jogMinus();
void sendJog(int counter);
void doShuttle(bool plus, quint8 level);
void setBand(int band);
2022-04-27 11:56:54 +00:00
void button(const COMMAND* cmd);
2022-04-25 16:40:41 +00:00
void newDevice(unsigned char devType, QVector<BUTTON>* but,QVector<COMMAND>* cmd);
2022-05-17 07:53:24 +00:00
2022-04-22 10:11:21 +00:00
private:
hid_device* handle;
enum { NONE, shuttleXpress, shuttlePro2, RC28 }usbDevice;
bool isOpen=false;
unsigned int buttons=0;
unsigned char jogpos=0;
unsigned char shutpos=0;
unsigned char shutMult = 0;
int jogCounter = 0;
2022-04-22 10:11:21 +00:00
QTime lastusbController = QTime::currentTime();
QByteArray lastData="";
unsigned char lastDialPos=0;
QVector<BUTTON> buttonList;
2022-09-18 16:42:41 +00:00
QVector<COMMAND>* commands = Q_NULLPTR;
2022-04-27 11:56:54 +00:00
QString product="";
QString manufacturer="";
QString serial="<none>";
2022-04-22 10:11:21 +00:00
protected:
};
#endif