diff --git a/usbcontroller.cpp b/usbcontroller.cpp index 9091ee2b..59126483 100644 --- a/usbcontroller.cpp +++ b/usbcontroller.cpp @@ -363,6 +363,8 @@ void usbController::run() dev.knobSend.append(0); } + dev.knobPrevious.append(dev.knobValues); + // Find our defaults/knobs/buttons for this controller: // First see if we have any stored and add them to the list if not. @@ -764,7 +766,8 @@ void usbController::runTimer() for (unsigned char i = 0; i < dev.knobValues.size(); i++) { for (KNOB* kb = knobList->begin(); kb != knobList->end(); kb++) { if (kb != knobList->end() && kb->command && kb->devicePath == dev.path && kb->num == i && dev.knobValues[i]) { - COMMAND cmd(*kb->command); + // sendCommand mustn't be deleted so we ensure it stays in-scope by declaring it private. + sendCommand = *kb->command; if (kb->num >0) { if (dev.knobSend[i] + (dev.knobValues[i] * 10) <= 0) { @@ -777,14 +780,23 @@ void usbController::runTimer() else { dev.knobSend[i] = dev.knobSend[i] + (dev.knobValues[i] * 10); } - cmd.suffix = dev.knobSend[i]; + sendCommand.suffix = dev.knobSend[i]; } else { - cmd.value = dev.knobValues[i]/dev.sensitivity; + int tempVal = dev.knobValues[i] * dev.sensitivity; + tempVal = qMin(qMax(tempVal,0),255); + sendCommand.suffix = quint8(tempVal); + dev.knobValues[i]=tempVal/dev.sensitivity; // This ensures that dial can't go outside 0-255 } - qInfo(logUsbControl()) << "Sending Knob:" << kb->num << "Command:" << cmd.command << " Value:" << cmd.suffix << "Raw value:" << dev.knobValues[i]; - emit button(&cmd); - dev.knobValues[i] = 0; + if (dev.knobValues[i] != dev.knobPrevious[i]) { + emit button(&sendCommand); + } + + if (sendCommand.command == cmdSetFreq) { + dev.knobValues[i] = 0; + } else { + dev.knobPrevious[i]=dev.knobValues[i]; + } } } } diff --git a/usbcontroller.h b/usbcontroller.h index 1e30be9f..63f4c718 100644 --- a/usbcontroller.h +++ b/usbcontroller.h @@ -78,6 +78,7 @@ struct USBDEVICE { quint32 buttons = 0; quint32 knobs = 0; QList knobValues; + QList knobPrevious; QList knobSend; QTime lastusbController = QTime::currentTime(); QByteArray lastData = QByteArray(8,0x0); @@ -218,6 +219,7 @@ private: QColor currentColour; QMutex* mutex=Q_NULLPTR; + COMMAND sendCommand; unsigned short knownUsbDevices[6][5] = { {shuttleXpress,0x0b33,0x0020,0x0000,0x0000}, diff --git a/wfmain.cpp b/wfmain.cpp index 33c29ad3..3116d4ff 100644 --- a/wfmain.cpp +++ b/wfmain.cpp @@ -1860,7 +1860,6 @@ void wfmain::buttonControl(const COMMAND* cmd) } default: issueCmdUniquePriority((cmds)cmd->command, cmd->suffix); - qInfo(logUsbControl()) << "Command fell through command:" << cmd->command << "suffix" << cmd->suffix; break; } }