kopia lustrzana https://gitlab.com/eliggett/wfview
Add storing button config
rodzic
c87dc5ef73
commit
e6506cd55f
|
@ -35,7 +35,7 @@ void shuttleSetup::mousePressed(QPoint p)
|
|||
bool found = false;
|
||||
for (BUTTON& b : *buttons)
|
||||
{
|
||||
if (b.pos.contains(p))
|
||||
if (b.dev == currentDevice && b.pos.contains(p))
|
||||
{
|
||||
found = true;
|
||||
currentButton = &b;
|
||||
|
@ -144,16 +144,18 @@ void shuttleSetup::newDevice(unsigned char devType, QVector<BUTTON>* but, QVecto
|
|||
// Set button text
|
||||
for (BUTTON& b : *buttons)
|
||||
{
|
||||
b.onCommand = &commands->at(0);
|
||||
b.onText = new QGraphicsTextItem(b.onCommand->text);
|
||||
b.onText->setDefaultTextColor(b.textColour);
|
||||
scene->addItem(b.onText);
|
||||
b.onText->setPos(b.pos.x(), b.pos.y());
|
||||
if (b.dev == currentDevice) {
|
||||
//b.onCommand = &commands->at(0);
|
||||
b.onText = new QGraphicsTextItem(b.onCommand->text);
|
||||
b.onText->setDefaultTextColor(b.textColour);
|
||||
scene->addItem(b.onText);
|
||||
b.onText->setPos(b.pos.x(), b.pos.y());
|
||||
|
||||
b.offCommand = &commands->at(0);
|
||||
b.offText = new QGraphicsTextItem(b.offCommand->text);
|
||||
b.offText->setDefaultTextColor(b.textColour);
|
||||
scene->addItem(b.offText);
|
||||
b.offText->setPos(b.pos.x(), b.pos.y()+10);
|
||||
//b.offCommand = &commands->at(0);
|
||||
b.offText = new QGraphicsTextItem(b.offCommand->text);
|
||||
b.offText->setDefaultTextColor(b.textColour);
|
||||
scene->addItem(b.offText);
|
||||
b.offText->setPos(b.pos.x(), b.pos.y() + 10);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,7 +43,8 @@ public slots:
|
|||
void offEventIndexChanged(int index);
|
||||
|
||||
private:
|
||||
enum { NONE, shuttleXpress, shuttlePro2, RC28 }usbDevice;
|
||||
enum { NONE=0, shuttleXpress, shuttlePro2, RC28 } usbDevice;
|
||||
|
||||
Ui::shuttleSetup* ui;
|
||||
QGraphicsScene* scene;
|
||||
QGraphicsTextItem* textItem;
|
||||
|
|
|
@ -14,13 +14,6 @@ usbController::~usbController()
|
|||
qInfo(logUsbControl) << "Ending usbController()";
|
||||
hid_close(handle);
|
||||
hid_exit();
|
||||
for (BUTTON& b : buttonList)
|
||||
{
|
||||
if (b.onText)
|
||||
delete b.onText;
|
||||
if (b.offText)
|
||||
delete b.offText;
|
||||
}
|
||||
}
|
||||
|
||||
void usbController::init()
|
||||
|
@ -33,6 +26,12 @@ void usbController::receiveCommands(QVector<COMMAND>* cmds)
|
|||
commands = cmds;
|
||||
}
|
||||
|
||||
void usbController::receiveButtons(QVector<BUTTON>* buts)
|
||||
{
|
||||
qDebug(logUsbControl()) << "Receiving buttons";
|
||||
buttonList = buts;
|
||||
}
|
||||
|
||||
int usbController::hidApiWrite(unsigned char* data, unsigned char length)
|
||||
{
|
||||
Q_UNUSED(data);
|
||||
|
@ -85,33 +84,10 @@ void usbController::run()
|
|||
}
|
||||
else {
|
||||
usbDevice = shuttlePro2;
|
||||
buttonList.clear();
|
||||
buttonList.append(BUTTON(0, QRect(60, 66, 40, 30), Qt::red));
|
||||
buttonList.append(BUTTON(1, QRect(114, 50, 40, 30), Qt::red));
|
||||
buttonList.append(BUTTON(2, QRect(169, 47, 40, 30), Qt::red));
|
||||
buttonList.append(BUTTON(3, QRect(225, 59, 40, 30), Qt::red));
|
||||
buttonList.append(BUTTON(4, QRect(41, 132, 40, 30), Qt::red));
|
||||
buttonList.append(BUTTON(5, QRect(91, 105, 40, 30), Qt::red));
|
||||
buttonList.append(BUTTON(6, QRect(144, 93, 40, 30), Qt::red));
|
||||
buttonList.append(BUTTON(7, QRect(204, 99, 40, 30), Qt::red));
|
||||
buttonList.append(BUTTON(8, QRect(253, 124, 40, 30), Qt::red));
|
||||
buttonList.append(BUTTON(9, QRect(50, 270, 70, 55), Qt::red));
|
||||
buttonList.append(BUTTON(10, QRect(210, 270, 70, 55), Qt::red));
|
||||
buttonList.append(BUTTON(11, QRect(50, 335, 70, 55), Qt::red));
|
||||
buttonList.append(BUTTON(12, QRect(210, 335, 70, 55), Qt::red));
|
||||
buttonList.append(BUTTON(13, QRect(30, 195, 25, 80), Qt::red));
|
||||
buttonList.append(BUTTON(14, QRect(280, 195, 25, 80), Qt::red));
|
||||
|
||||
}
|
||||
}
|
||||
else {
|
||||
usbDevice = shuttleXpress;
|
||||
buttonList.append(BUTTON(0, QRect(60, 66, 40, 30), Qt::red));
|
||||
buttonList.append(BUTTON(1, QRect(114, 50, 40, 30), Qt::red));
|
||||
buttonList.append(BUTTON(2, QRect(169, 47, 40, 30), Qt::red));
|
||||
buttonList.append(BUTTON(3, QRect(225, 59, 40, 30), Qt::red));
|
||||
buttonList.append(BUTTON(4, QRect(41, 132, 40, 30), Qt::red));
|
||||
|
||||
}
|
||||
|
||||
if (handle)
|
||||
|
@ -141,7 +117,7 @@ void usbController::run()
|
|||
|
||||
qInfo(logUsbControl()) << QString("Found Device: %0 from %1 S/N %2").arg(this->product).arg(this->manufacturer).arg(this->serial);
|
||||
hid_set_nonblocking(handle, 1);
|
||||
emit newDevice(usbDevice, &buttonList, commands); // Let the UI know we have a new controller
|
||||
emit newDevice(usbDevice, buttonList, commands); // Let the UI know we have a new controller
|
||||
QTimer::singleShot(0, this, SLOT(runTimer()));
|
||||
}
|
||||
}
|
||||
|
@ -155,7 +131,7 @@ void usbController::runTimer()
|
|||
if (res < 0)
|
||||
{
|
||||
qInfo(logUsbControl()) << "USB Device disconnected" << this->product;
|
||||
emit newDevice(0,&buttonList,commands);
|
||||
emit newDevice(0,buttonList,commands);
|
||||
this->product = "";
|
||||
this->manufacturer = "";
|
||||
this->serial = "<none>";
|
||||
|
@ -207,23 +183,26 @@ void usbController::runTimer()
|
|||
*/
|
||||
if (buttons != tempButtons)
|
||||
{
|
||||
//qDebug(logUsbControl()) << "BUTTON: " << qSetFieldWidth(16) << bin << tempButtons;
|
||||
|
||||
|
||||
|
||||
// Step through all buttons and emit ones that have been pressed.
|
||||
for (unsigned char i = 0; i < 16; i++)
|
||||
{
|
||||
if ((tempButtons >> i & 1) && !(buttons >> i & 1))
|
||||
{
|
||||
if (i < buttonList.size() && buttonList[i].onCommand != Q_NULLPTR && buttonList[i].onCommand->index > 0) {
|
||||
qDebug() << "On Button event:" << buttonList[i].onCommand->text;
|
||||
emit button(buttonList[i].onCommand);
|
||||
}
|
||||
}
|
||||
else if ((buttons >> i & 1) && !(tempButtons >> i & 1))
|
||||
{
|
||||
if (i < buttonList.size() && buttonList[i].offCommand != Q_NULLPTR && buttonList[i].offCommand->index > 0) {
|
||||
qDebug() << "Off Button event:" << buttonList[i].offCommand->text;
|
||||
emit button(buttonList[i].offCommand);
|
||||
|
||||
for (BUTTON* but = buttonList->begin(); but != buttonList->end(); but++) {
|
||||
if (but->dev == usbDevice && but->num == i) {
|
||||
|
||||
if ((tempButtons >> i & 1) && !(buttons >> i & 1) && but->onCommand->index > 0)
|
||||
{
|
||||
qDebug() << "On Button event:" << but->onCommand->text;
|
||||
emit button(but->onCommand);
|
||||
}
|
||||
else if ((buttons >> i & 1) && !(tempButtons >> i & 1) && but->offCommand->index > 0)
|
||||
{
|
||||
qDebug() << "Off Button event:" << but->offCommand->text;
|
||||
emit button(but->offCommand);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -52,18 +52,20 @@ struct COMMAND {
|
|||
struct BUTTON {
|
||||
BUTTON() {}
|
||||
|
||||
BUTTON(char num, QRect pos, const QColor textColour) :
|
||||
num(num), pos(pos), textColour(textColour) {}
|
||||
BUTTON(quint8 dev, int num, QRect pos, const QColor textColour) :
|
||||
dev(dev), num(num), pos(pos), textColour(textColour) {}
|
||||
|
||||
quint8 num;
|
||||
quint8 dev;
|
||||
int num;
|
||||
QRect pos;
|
||||
const QColor textColour;
|
||||
QColor textColour;
|
||||
int onEvent = 0;
|
||||
int offEvent = 0;
|
||||
const COMMAND* onCommand=Q_NULLPTR;
|
||||
const COMMAND* offCommand=Q_NULLPTR;
|
||||
QGraphicsTextItem* onText;
|
||||
QGraphicsTextItem* offText;
|
||||
|
||||
};
|
||||
|
||||
class usbController : public QObject
|
||||
|
@ -81,6 +83,7 @@ public slots:
|
|||
void runTimer();
|
||||
void ledControl(bool on, unsigned char num);
|
||||
void receiveCommands(QVector<COMMAND>*);
|
||||
void receiveButtons(QVector<BUTTON>*);
|
||||
|
||||
signals:
|
||||
void jogPlus();
|
||||
|
@ -103,7 +106,7 @@ private:
|
|||
QTime lastusbController = QTime::currentTime();
|
||||
QByteArray lastData="";
|
||||
unsigned char lastDialPos=0;
|
||||
QVector<BUTTON> buttonList;
|
||||
QVector<BUTTON>* buttonList;
|
||||
QVector<COMMAND>* commands = Q_NULLPTR;
|
||||
QString product="";
|
||||
QString manufacturer="";
|
||||
|
|
130
wfmain.cpp
130
wfmain.cpp
|
@ -121,6 +121,7 @@ wfmain::wfmain(const QString serialPortCL, const QString hostCL, const QString s
|
|||
// Setup USB Controller
|
||||
setupUsbControllerDevice();
|
||||
emit sendUsbControllerCommands(&usbCommands);
|
||||
emit sendUsbControllerButtons(&usbButtons);
|
||||
|
||||
connect(ui->txPowerSlider, &QSlider::sliderMoved,
|
||||
[&](int value) {
|
||||
|
@ -1383,8 +1384,8 @@ void wfmain::setupUsbControllerDevice()
|
|||
connect(shut, SIGNAL(setButtonCommand(QString, BUTTON*)), this, SLOT(getButtonCommand(QString, BUTTON*)));
|
||||
usbControllerThread->start(QThread::LowestPriority);
|
||||
|
||||
connect(this, SIGNAL(sendUsbControllerCommands(QVector<COMMAND>*)), usbControllerDev, SLOT(receiveCommands(QVector<COMMAND>*))); emit sendUsbControllerCommands(&usbCommands);
|
||||
|
||||
connect(this, SIGNAL(sendUsbControllerCommands(QVector<COMMAND>*)), usbControllerDev, SLOT(receiveCommands(QVector<COMMAND>*)));
|
||||
connect(this, SIGNAL(sendUsbControllerButtons(QVector<BUTTON>*)), usbControllerDev, SLOT(receiveButtons(QVector<BUTTON>*)));
|
||||
|
||||
}
|
||||
|
||||
|
@ -1549,17 +1550,17 @@ void wfmain::loadSettings()
|
|||
int numPresetsInFile = settings->beginReadArray("ColorPreset");
|
||||
// We will use the number of presets that the working copy of wfview
|
||||
// supports, as we must never exceed the available number.
|
||||
if(numPresetsInFile > 0)
|
||||
if (numPresetsInFile > 0)
|
||||
{
|
||||
colorPrefsType *p;
|
||||
colorPrefsType* p;
|
||||
QString tempName;
|
||||
for(int pn=0; pn < numColorPresetsTotal; pn++)
|
||||
for (int pn = 0; pn < numColorPresetsTotal; pn++)
|
||||
{
|
||||
settings->setArrayIndex(pn);
|
||||
p = &(colorPreset[pn]);
|
||||
p->presetNum = settings->value("presetNum", p->presetNum).toInt();
|
||||
tempName = settings->value("presetName", *p->presetName).toString();
|
||||
if((!tempName.isEmpty()) && tempName.length() < 11)
|
||||
if ((!tempName.isEmpty()) && tempName.length() < 11)
|
||||
{
|
||||
p->presetName->clear();
|
||||
p->presetName->append(tempName);
|
||||
|
@ -1904,10 +1905,11 @@ void wfmain::loadSettings()
|
|||
|
||||
/* Load USB buttons*/
|
||||
settings->beginGroup("USB");
|
||||
size=settings->beginReadArray("Buttons");
|
||||
if (size == 0) {
|
||||
int numCommands = settings->beginReadArray("Commands");
|
||||
if (numCommands == 0) {
|
||||
settings->endArray();
|
||||
// We have no buttons so create defaults
|
||||
usbCommands.clear();
|
||||
usbCommands.append(COMMAND(0, "None", cmdNone, 0x0));
|
||||
usbCommands.append(COMMAND(1, "PTT On", cmdSetPTT, 0x1));
|
||||
usbCommands.append(COMMAND(2, "PTT Off", cmdSetPTT, 0x0));
|
||||
|
@ -1943,8 +1945,83 @@ void wfmain::loadSettings()
|
|||
usbCommands.append(COMMAND(31, "630m", cmdGetBandStackReg, band630m));
|
||||
usbCommands.append(COMMAND(32, "2200m", cmdGetBandStackReg, band2200m));
|
||||
usbCommands.append(COMMAND(33, "GEN", cmdGetBandStackReg, bandGen));
|
||||
|
||||
}
|
||||
else {
|
||||
for (int nc = 0; nc < numCommands; nc++)
|
||||
{
|
||||
settings->setArrayIndex(nc);
|
||||
COMMAND comm;
|
||||
comm.index = settings->value("Num", 0).toInt();
|
||||
comm.text = settings->value("Text", "").toString();
|
||||
comm.command = settings->value("Command", 0).toInt();
|
||||
comm.band = (bandType)settings->value("Band", 0).toInt();
|
||||
usbCommands.append(comm);
|
||||
}
|
||||
settings->endArray();
|
||||
}
|
||||
|
||||
int numButtons = settings->beginReadArray("Buttons");
|
||||
if (numButtons == 0) {
|
||||
settings->endArray();
|
||||
// We have no buttons so create defaults
|
||||
usbButtons.clear();
|
||||
|
||||
// ShuttleXpress
|
||||
usbButtons.append(BUTTON(1, 0, QRect(60, 66, 40, 30), Qt::red));
|
||||
usbButtons.append(BUTTON(1, 1, QRect(114, 50, 40, 30), Qt::red));
|
||||
usbButtons.append(BUTTON(1, 2, QRect(169, 47, 40, 30), Qt::red));
|
||||
usbButtons.append(BUTTON(1, 3, QRect(225, 59, 40, 30), Qt::red));
|
||||
usbButtons.append(BUTTON(1, 4, QRect(41, 132, 40, 30), Qt::red));
|
||||
|
||||
// ShuttlePro2
|
||||
usbButtons.append(BUTTON(2, 0, QRect(60, 66, 40, 30), Qt::red));
|
||||
usbButtons.append(BUTTON(2, 1, QRect(114, 50, 40, 30), Qt::red));
|
||||
usbButtons.append(BUTTON(2, 2, QRect(169, 47, 40, 30), Qt::red));
|
||||
usbButtons.append(BUTTON(2, 3, QRect(225, 59, 40, 30), Qt::red));
|
||||
usbButtons.append(BUTTON(2, 4, QRect(41, 132, 40, 30), Qt::red));
|
||||
usbButtons.append(BUTTON(2, 5, QRect(91, 105, 40, 30), Qt::red));
|
||||
usbButtons.append(BUTTON(2, 6, QRect(144, 93, 40, 30), Qt::red));
|
||||
usbButtons.append(BUTTON(2, 7, QRect(204, 99, 40, 30), Qt::red));
|
||||
usbButtons.append(BUTTON(2, 8, QRect(253, 124, 40, 30), Qt::red));
|
||||
usbButtons.append(BUTTON(2, 9, QRect(50, 270, 70, 55), Qt::red));
|
||||
usbButtons.append(BUTTON(2, 10, QRect(210, 270, 70, 55), Qt::red));
|
||||
usbButtons.append(BUTTON(2, 11, QRect(50, 335, 70, 55), Qt::red));
|
||||
usbButtons.append(BUTTON(2, 12, QRect(210, 335, 70, 55), Qt::red));
|
||||
usbButtons.append(BUTTON(2, 13, QRect(30, 195, 25, 80), Qt::red));
|
||||
usbButtons.append(BUTTON(2, 14, QRect(280, 195, 25, 80), Qt::red));
|
||||
}
|
||||
else {
|
||||
usbButtons.clear();
|
||||
for (int nb = 0; nb < numButtons; nb++)
|
||||
{
|
||||
settings->setArrayIndex(nb);
|
||||
BUTTON butt;
|
||||
butt.dev = settings->value("Dev", 0).toInt();
|
||||
butt.num = settings->value("Num", 0).toInt();
|
||||
butt.pos = QRect(settings->value("Left", 0).toInt(),
|
||||
settings->value("Top", 0).toInt(),
|
||||
settings->value("Width", 0).toInt(),
|
||||
settings->value("Height", 0).toInt());
|
||||
butt.textColour = QColor((settings->value("Colour", "Green").toString()));
|
||||
|
||||
int on = settings->value("OnCommand", 0).toInt();
|
||||
int off = settings->value("OffCommand", 0).toInt();
|
||||
if (on < usbCommands.size())
|
||||
butt.onCommand = &usbCommands.at(on);
|
||||
else
|
||||
butt.onCommand = &usbCommands.at(0);
|
||||
|
||||
if (off < usbCommands.size())
|
||||
butt.offCommand = &usbCommands.at(off);
|
||||
else
|
||||
butt.offCommand = &usbCommands.at(0);
|
||||
|
||||
usbButtons.append(butt);
|
||||
|
||||
}
|
||||
settings->endArray();
|
||||
}
|
||||
|
||||
|
||||
settings->endGroup();
|
||||
|
||||
|
@ -2284,25 +2361,30 @@ void wfmain::saveSettings()
|
|||
settings->endGroup();
|
||||
|
||||
settings->beginGroup("USB");
|
||||
settings->beginGroup(usbDeviceName);
|
||||
settings->beginWriteArray("Buttons");
|
||||
|
||||
QHashIterator<quint8, BUTTON*> i(usbButtons);
|
||||
int count = 0;
|
||||
while (i.hasNext()) {
|
||||
i.next();
|
||||
settings->setArrayIndex(count++);
|
||||
settings->setValue("Number", i.value()->num);
|
||||
settings->setValue("OnCommand", i.value()->onCommand->text);
|
||||
settings->setValue("OffCommand", i.value()->offCommand->text);
|
||||
// Store USB Controller
|
||||
|
||||
|
||||
settings->beginWriteArray("Buttons");
|
||||
for (int nb = 0; nb < usbButtons.count(); nb++)
|
||||
{
|
||||
settings->setArrayIndex(nb);
|
||||
settings->setValue("Dev", usbButtons[nb].dev);
|
||||
settings->setValue("Num", usbButtons[nb].num);
|
||||
settings->setValue("Left", usbButtons[nb].pos.left());
|
||||
settings->setValue("Top", usbButtons[nb].pos.top());
|
||||
settings->setValue("Width", usbButtons[nb].pos.width());
|
||||
settings->setValue("Height", usbButtons[nb].pos.height());
|
||||
settings->setValue("Colour", usbButtons[nb].textColour.name());
|
||||
if (usbButtons[nb].onCommand != Q_NULLPTR)
|
||||
settings->setValue("OnCommand", usbButtons[nb].onCommand->index);
|
||||
if (usbButtons[nb].offCommand != Q_NULLPTR)
|
||||
settings->setValue("OffCommand", usbButtons[nb].offCommand->index);
|
||||
}
|
||||
|
||||
settings->endArray();
|
||||
|
||||
settings->endGroup();
|
||||
settings->endGroup();
|
||||
|
||||
|
||||
|
||||
settings->sync(); // Automatic, not needed (supposedly)
|
||||
}
|
||||
|
@ -7341,10 +7423,10 @@ void wfmain::getButtonCommand(QString device, BUTTON* but)
|
|||
// New or unknown device?
|
||||
usbDeviceName = device;
|
||||
qDebug(logUsbControl()) << "New controller:" << device;
|
||||
usbButtons.clear();
|
||||
//usbButtons.clear();
|
||||
}
|
||||
qDebug(logUsbControl()) << "Adding" << "Commands for" << device << "button" << but->num << "onCommand" << but->onCommand->text << "offCommand" << but->offCommand->text;
|
||||
usbButtons.insert(but->num, but);
|
||||
//usbButtons.insert(but->num, but);
|
||||
}
|
||||
|
||||
void wfmain::updateUsbButtons()
|
||||
|
|
4
wfmain.h
4
wfmain.h
|
@ -195,6 +195,7 @@ signals:
|
|||
void stateUpdated();
|
||||
void shuttleLed(bool, unsigned char);
|
||||
void sendUsbControllerCommands(QVector<COMMAND>* cmds);
|
||||
void sendUsbControllerButtons(QVector<BUTTON>* buts);
|
||||
|
||||
private slots:
|
||||
void updateSizes(int tabIndex);
|
||||
|
@ -1056,10 +1057,9 @@ private:
|
|||
usbController *usbControllerDev = Q_NULLPTR;
|
||||
QThread *usbControllerThread = Q_NULLPTR;
|
||||
|
||||
QHash<quint8, BUTTON*> usbButtons;
|
||||
QString usbDeviceName;
|
||||
QVector<COMMAND> usbCommands;
|
||||
|
||||
QVector<BUTTON> usbButtons;
|
||||
|
||||
};
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue