From cadf835d958050be5f7b58074c0e9f5f27cb065d Mon Sep 17 00:00:00 2001 From: Phil Taylor Date: Mon, 27 Mar 2023 12:38:01 +0100 Subject: [PATCH] Receive current knob values from rig --- usbcontroller.cpp | 39 ++++++++++++++++++++++--------- usbcontroller.h | 4 ++++ wfmain.cpp | 58 ++++++++++++++++++++++++++--------------------- wfmain.h | 5 ++-- wfmain.ui | 21 ++++++----------- wfviewtypes.h | 2 +- 6 files changed, 75 insertions(+), 54 deletions(-) diff --git a/usbcontroller.cpp b/usbcontroller.cpp index 58f7223..4db9e76 100644 --- a/usbcontroller.cpp +++ b/usbcontroller.cpp @@ -1418,17 +1418,17 @@ void usbController::loadCommands() commands.append(COMMAND(num++, "Split On", commandButton, cmdNone, 0x01)); commands.append(COMMAND(num++, "Split Off", commandButton, cmdNone, 0x0)); commands.append(COMMAND(num++, "Swap VFO", commandButton, cmdVFOSwap, 0x0)); - commands.append(COMMAND(num++, "AF Gain", commandKnob, cmdSetAfGain, 0xff)); - commands.append(COMMAND(num++, "RF Gain", commandKnob, cmdSetRxRfGain, 0xff)); - commands.append(COMMAND(num++, "TX Power", commandKnob, cmdSetTxPower, 0xff)); - commands.append(COMMAND(num++, "Mic Gain", commandKnob, cmdSetMicGain, 0xff)); - commands.append(COMMAND(num++, "Mod Level", commandKnob, cmdSetModLevel, 0xff)); - commands.append(COMMAND(num++, "Squelch", commandKnob, cmdSetSql, 0xff)); - commands.append(COMMAND(num++, "IF Shift", commandKnob, cmdSetIFShift, 0xff)); - commands.append(COMMAND(num++, "In PBT", commandKnob, cmdSetTPBFInner, 0xff)); - commands.append(COMMAND(num++, "Out PBT", commandKnob, cmdSetTPBFOuter, 0xff)); - commands.append(COMMAND(num++, "CW Pitch", commandKnob, cmdSetCwPitch, 0xff)); - commands.append(COMMAND(num++, "CW Speed", commandKnob, cmdSetKeySpeed, 0xff)); + commands.append(COMMAND(num++, "AF Gain", commandKnob, cmdSetAfGain, cmdGetAfGain, 0xff)); + commands.append(COMMAND(num++, "RF Gain", commandKnob, cmdSetRxRfGain, cmdGetRxGain, 0xff)); + commands.append(COMMAND(num++, "TX Power", commandKnob, cmdSetTxPower, cmdGetTxPower, 0xff)); + commands.append(COMMAND(num++, "Mic Gain", commandKnob, cmdSetMicGain, cmdGetMicGain, 0xff)); + commands.append(COMMAND(num++, "Mod Level", commandKnob, cmdSetModLevel, cmdNone, 0xff)); + commands.append(COMMAND(num++, "Squelch", commandKnob, cmdSetSql, cmdGetSql, 0xff)); + commands.append(COMMAND(num++, "IF Shift", commandKnob, cmdSetIFShift, cmdGetIFShift, 0xff)); + commands.append(COMMAND(num++, "In PBT", commandKnob, cmdSetTPBFInner, cmdGetTPBFInner, 0xff)); + commands.append(COMMAND(num++, "Out PBT", commandKnob, cmdSetTPBFOuter, cmdGetTPBFOuter, 0xff)); + commands.append(COMMAND(num++, "CW Pitch", commandKnob, cmdSetCwPitch, cmdGetCwPitch, 0xff)); + commands.append(COMMAND(num++, "CW Speed", commandKnob, cmdSetKeySpeed, cmdGetKeySpeed, 0xff)); commands.append(COMMAND(num++, "Waterfall", commandButton, cmdLCDWaterfall, 0x0)); commands.append(COMMAND(num++, "Spectrum", commandButton, cmdLCDSpectrum, 0x0)); commands.append(COMMAND(num++, "Page Down", commandButton, cmdPageDown, 0x0)); @@ -1563,5 +1563,22 @@ void usbController::buttonState(QString name, double val) /* End of Gamepad functions*/ +void usbController::receiveLevel(cmds cmd, unsigned char level) +{ + // Update knob if relevant, step through all devices + QMutexLocker locker(mutex); + + for (auto dev = usbDevices.begin(); dev != usbDevices.end(); dev++) + { + auto kb = std::find_if(knobList->begin(), knobList->end(), [dev, cmd](const KNOB& k) + { return (k.command && k.path == dev->path && k.page == dev->currentPage && k.command->getCommand == cmd);}); + if (kb != knobList->end() && kb->num < dev->knobValues.size()) { + qInfo(logUsbControl()) << "Received value:" << level << "for knob" << kb->num; + // Set both current and previous knobvalue to the received value + dev->knobValues[kb->num] = level; + dev->knobPrevious[kb->num] = level; + } + } +} #endif diff --git a/usbcontroller.h b/usbcontroller.h index e9a41fd..148a89d 100644 --- a/usbcontroller.h +++ b/usbcontroller.h @@ -123,6 +123,8 @@ struct COMMAND { COMMAND() {} COMMAND(int index, QString text, usbCommandType cmdType, int command, unsigned char suffix) : index(index), text(text), cmdType(cmdType), command(command), suffix(suffix) {} + COMMAND(int index, QString text, usbCommandType cmdType, int command, int getCommand, unsigned char suffix) : + index(index), text(text), cmdType(cmdType), command(command), getCommand(getCommand), suffix(suffix) {} COMMAND(int index, QString text, usbCommandType cmdType, int command, availableBands band) : index(index), text(text), cmdType(cmdType), command(command), band(band) {} COMMAND(int index, QString text, usbCommandType cmdType, int command, mode_kind mode) : @@ -132,6 +134,7 @@ struct COMMAND { QString text; usbCommandType cmdType = commandButton; int command=0; + int getCommand=0; unsigned char suffix=0x0; int value=0; availableBands band=bandGen; @@ -222,6 +225,7 @@ public slots: void runTimer(); void ledControl(bool on, unsigned char num); void receivePTTStatus(bool on); + void receiveLevel(cmds cmd, unsigned char level); void programPages(USBDEVICE* dev, int pages); void programDisable(USBDEVICE* dev, bool disabled); diff --git a/wfmain.cpp b/wfmain.cpp index c4f7737..36fc16c 100644 --- a/wfmain.cpp +++ b/wfmain.cpp @@ -174,8 +174,7 @@ wfmain::wfmain(const QString settingsFile, const QString logFile, bool debugMode #if !defined(USB_CONTROLLER) ui->enableUsbChk->setVisible(false); ui->usbControllerBtn->setVisible(false); - ui->usbButtonsResetBtn->setVisible(false); - ui->usbCommandsResetBtn->setVisible(false); + ui->usbControllersResetBtn->setVisible(false); ui->usbResetLbl->setVisible(false); #endif @@ -1694,6 +1693,7 @@ void wfmain::setupUsbControllerDevice() connect(shut, SIGNAL(programPages(USBDEVICE*, int)), usbControllerDev, SLOT(programPages(USBDEVICE*, int))); connect(shut, SIGNAL(programDisable(USBDEVICE*, bool)), usbControllerDev, SLOT(programDisable(USBDEVICE*, bool))); connect(this, SIGNAL(setPTT(bool)), usbControllerDev, SLOT(receivePTTStatus(bool))); + connect(this, SIGNAL(sendLevel(cmds, unsigned char)), usbControllerDev, SLOT(receiveLevel(cmds, unsigned char))); connect(this, SIGNAL(initUsbController(QMutex*,usbMap*,QVector