From 65b45389682f97cae9072c273bf457578cc17a3f Mon Sep 17 00:00:00 2001 From: Phil Taylor Date: Thu, 19 Aug 2021 10:21:09 +0100 Subject: [PATCH] Use hidapi statically and set lowest priority for thread --- shuttle.cpp | 45 ++++++++++++----------- shuttle.h | 20 +++-------- wfmain.cpp | 30 +++++++++++++--- wfmain.h | 3 +- wfview.pro | 2 +- wfview.vcxproj | 81 ++++++++++++++++++++++++++++++++++-------- wfview.vcxproj.filters | 38 +++++++++++++++++--- 7 files changed, 157 insertions(+), 62 deletions(-) diff --git a/shuttle.cpp b/shuttle.cpp index 786de23..b7079c6 100644 --- a/shuttle.cpp +++ b/shuttle.cpp @@ -1,3 +1,4 @@ +#pragma comment (lib, "Setupapi.lib") #include "shuttle.h" #include @@ -141,17 +142,14 @@ void shuttle::runTimer() { qDebug() << "BUTTON: " << qSetFieldWidth(16) << bin << tempButtons; - // Step size down - if ((tempButtons >> 5 & 1) && !(buttons >> 5 & 1)) - emit button5(true); - // PTT on and off - if ((tempButtons >> 6 & 1) && !(buttons >> 6 & 1)) - emit button6(true); - else if ((buttons >> 6 & 1) && !(tempButtons >> 6 & 1)) - emit button6(false); - // Step size up - if ((tempButtons >> 7 & 1) && !(buttons >> 7 & 1)) - emit button7(true); + // 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)) + emit button(true,i); + else if ((buttons >> i & 1) && !(tempButtons >> i & 1)) + emit button(false,i); + } } buttons = tempButtons; @@ -176,21 +174,26 @@ void shuttle::runTimer() } + } - - if (shutpos > 0 && shutpos < 8) + if (lastShuttle.msecsTo(QTime::currentTime()) >= 1000) { - shutMult = shutpos; - emit doShuttle(true,shutMult); - qDebug() << "SHUTTLE PLUS" << shutMult; + if (shutpos > 0 && shutpos < 8) + { + shutMult = shutpos; + emit doShuttle(true, shutMult); + qInfo() << "SHUTTLE PLUS" << shutMult; + } + else if (shutpos <= 0xff && shutpos >= 0xf0) { + shutMult = abs(shutpos - 0xff) + 1; + emit doShuttle(false, shutMult); + qInfo() << "SHUTTLE MINUS" << shutMult; + } + lastShuttle = QTime::currentTime(); } - else if (shutpos <= 0xff && shutpos >= 0xf0) { - shutMult = abs(shutpos - 0xff)+1; - emit doShuttle(false,shutMult); - qDebug() << "SHUTTLE MINUS" << shutMult; - } + // Run every 25ms QTimer::singleShot(25, this, SLOT(runTimer())); diff --git a/shuttle.h b/shuttle.h index 2e24688..04300a4 100644 --- a/shuttle.h +++ b/shuttle.h @@ -5,6 +5,7 @@ #include #include #include +#include #ifndef Q_OS_WIN #include "hidapi/hidapi.h" @@ -43,22 +44,7 @@ signals: void doShuttle(bool plus, quint8 level); - void button0(bool); - void button1(bool); - void button2(bool); - void button3(bool); - void button4(bool); - void button5(bool); - void button6(bool); - void button7(bool); - void button8(bool); - void button9(bool); - void button10(bool); - void button11(bool); - void button12(bool); - void button13(bool); - void button14(bool); - void button15(bool); + void button(bool,unsigned char num); private: hid_device* handle; @@ -68,6 +54,8 @@ private: unsigned char shutpos=0; unsigned char shutMult = 0; enum { NONE, shuttleXpress, shuttlePro2, RC28 }usbDevice; + QTime lastShuttle = QTime::currentTime(); + protected: }; diff --git a/wfmain.cpp b/wfmain.cpp index 6981862..8a466b1 100644 --- a/wfmain.cpp +++ b/wfmain.cpp @@ -1228,15 +1228,14 @@ void wfmain::setupShuttleDevice() { shuttleDev = new shuttle(); shuttleThread = new QThread(this); + shuttleThread->setPriority(QThread::LowestPriority); shuttleDev->moveToThread(shuttleThread); connect(shuttleThread, SIGNAL(started()), shuttleDev, SLOT(run())); connect(shuttleThread, SIGNAL(finished()), shuttleDev, SLOT(deleteLater())); connect(shuttleDev, SIGNAL(jogPlus()), this, SLOT(shortcutStepPlus())); connect(shuttleDev, SIGNAL(jogMinus()), this, SLOT(shortcutStepMinus())); - connect(shuttleDev, SIGNAL(doShuttle(bool,quint8)), this, SLOT(doShuttle(bool,quint8))); - connect(shuttleDev, SIGNAL(button5(bool)), this, SLOT(stepDown())); - connect(shuttleDev, SIGNAL(button6(bool)), this, SLOT(pttToggle(bool))); - connect(shuttleDev, SIGNAL(button7(bool)), this, SLOT(stepUp())); + connect(shuttleDev, SIGNAL(doShuttle(bool, unsigned char)), this, SLOT(doShuttle(bool, unsigned char))); + connect(shuttleDev, SIGNAL(button(bool, unsigned char)), this, SLOT(buttonControl(bool, unsigned char))); shuttleThread->start(); } @@ -1258,7 +1257,7 @@ void wfmain::pttToggle(bool status) issueDelayedCommand(cmdGetPTT); } -void wfmain::doShuttle(bool up, quint8 level) +void wfmain::doShuttle(bool up, unsigned char level) { if (level == 1 && up) shortcutShiftPlus(); @@ -1278,6 +1277,27 @@ void wfmain::doShuttle(bool up, quint8 level) shortcutControlMinus(); } +void wfmain::buttonControl(bool on, unsigned char button) +{ + //qInfo() << "buttonControl()" << on << button; + switch (button) + { + case(5): + if(on) + stepDown(); + break; + case(6): + pttToggle(on); + break; + case(7): + if (on) + stepUp(); + break; + default: + qInfo() << "Unknown button pressed:" << button; + } +} + void wfmain::stepUp() { if (ui->tuningStepCombo->currentIndex() < ui->tuningStepCombo->count() - 1) diff --git a/wfmain.h b/wfmain.h index 27d12a8..8c4d69a 100644 --- a/wfmain.h +++ b/wfmain.h @@ -198,7 +198,7 @@ private slots: void handlePttLimit(); // hit at 3 min transmit length - void doShuttle(bool up, quint8 level); + void doShuttle(bool up, unsigned char level); void receiveCommReady(); void receiveFreq(freqt); @@ -263,6 +263,7 @@ private slots: void setRadioTimeDateSend(); + void buttonControl(bool on, unsigned char button); // void on_getFreqBtn_clicked(); diff --git a/wfview.pro b/wfview.pro index c953ea5..08753d8 100644 --- a/wfview.pro +++ b/wfview.pro @@ -115,8 +115,8 @@ CONFIG(debug, release|debug) { linux:LIBS += -L./ -l$$QCPLIB -lhidapi-libusb -lopus macx:LIBS += -framework CoreAudio -framework CoreFoundation -lhidapi -lpthread -lopus -win32:LIBS += -L../hidapi/windows/release -lhidapi win32:INCLUDEPATH += ../hidapi/hidapi +win32:SOURCES += ../hidapi/windows/hid.c #win32:SOURCES += rtaudio/RTAudio.cpp #win32:HEADERS += rtaudio/RTAUdio.h diff --git a/wfview.vcxproj b/wfview.vcxproj index 409634c..bfdd557 100644 --- a/wfview.vcxproj +++ b/wfview.vcxproj @@ -48,7 +48,7 @@ - .;..\hidapi\hidapi;..\qcustomplot;opus-tools\src;rtaudio;release;/include;%(AdditionalIncludeDirectories) + .;..\hidapi\hidapi;..\qcustomplot;..\opus\include;resampler;release;/include;%(AdditionalIncludeDirectories) -Zc:rvalueCast -Zc:inline -Zc:strictStrings -Zc:throwingNew -Zc:referenceBinding -Zc:__cplusplus -w34100 -w34189 -w44996 -w44456 -w44457 -w44458 %(AdditionalOptions) release\ false @@ -57,7 +57,7 @@ Sync release\ MaxSpeed - _WINDOWS;UNICODE;_UNICODE;WIN32;_ENABLE_EXTENDED_ALIGNED_STORAGE;QT_DEPRECATED_WARNINGS;QCUSTOMPLOT_COMPILE_LIBRARY;OUTSIDE_SPEEX;RANDOM_PREFIX=wf;__WINDOWS_WASAPI__;GITSHORT="28ba131";HOST="wfview.org";UNAME="build";QT_NO_DEBUG;NDEBUG;%(PreprocessorDefinitions) + _WINDOWS;UNICODE;_UNICODE;WIN32;_ENABLE_EXTENDED_ALIGNED_STORAGE;QT_DEPRECATED_WARNINGS;QCUSTOMPLOT_COMPILE_LIBRARY;USE_SSE;OUTSIDE_SPEEX;RANDOM_PREFIX=wf;PREFIX="/usr/local";__WINDOWS_WASAPI__;GITSHORT="87dc468";HOST="wfview.org";UNAME="build";NDEBUG;QT_NO_DEBUG;%(PreprocessorDefinitions) false MultiThreadedDLL @@ -66,13 +66,14 @@ Level3 true - ..\hidapi\windows\release\hidapi.lib;shell32.lib;%(AdditionalDependencies) - ..\hidapi\windows\release;C:\opensslx86\lib;C:\Utils\my_sql\mysql-5.6.11-win32\lib;C:\Utils\postgresqlx86\pgsql\lib;%(AdditionalLibraryDirectories) + ..\opus\win32\VS2015\Win32\Release\opus.lib;shell32.lib;%(AdditionalDependencies) + ..\opus\win32\VS2015\Win32\Release;C:\opensslx86\lib;C:\Utils\my_sql\mysql-5.7.25-win32\lib;C:\Utils\postgresqlx86\pgsql\lib;%(AdditionalLibraryDirectories) "/MANIFESTDEPENDENCY:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' publicKeyToken='6595b64144ccf1df' language='*' processorArchitecture='*'" %(AdditionalOptions) true false true false + true $(OutDir)\wfview.exe true Windows @@ -84,12 +85,12 @@ 0 - _WINDOWS;UNICODE;_UNICODE;WIN32;_ENABLE_EXTENDED_ALIGNED_STORAGE;QT_DEPRECATED_WARNINGS;QCUSTOMPLOT_COMPILE_LIBRARY;OUTSIDE_SPEEX;RANDOM_PREFIX=wf;__WINDOWS_WASAPI__;GITSHORT=\"28ba131\";HOST=\"wfview.org\";UNAME=\"build\";QT_NO_DEBUG;QT_MULTIMEDIA_LIB;QT_PRINTSUPPORT_LIB;QT_WIDGETS_LIB;QT_GUI_LIB;QT_SERIALPORT_LIB;QT_NETWORK_LIB;QT_CORE_LIB;%(PreprocessorDefinitions) + _WINDOWS;UNICODE;_UNICODE;WIN32;_ENABLE_EXTENDED_ALIGNED_STORAGE;QT_DEPRECATED_WARNINGS;QCUSTOMPLOT_COMPILE_LIBRARY;USE_SSE;OUTSIDE_SPEEX;RANDOM_PREFIX=wf;PREFIX=\"/usr/local\";__WINDOWS_WASAPI__;GITSHORT=\"87dc468\";HOST=\"wfview.org\";UNAME=\"build\";NDEBUG;QT_NO_DEBUG;QT_MULTIMEDIA_LIB;QT_PRINTSUPPORT_LIB;QT_WIDGETS_LIB;QT_GUI_LIB;QT_SERIALPORT_LIB;QT_NETWORK_LIB;QT_CORE_LIB;%(PreprocessorDefinitions) msvc./$(Configuration)/moc_predefs.hMoc'ing %(Identity)...output$(Configuration)moc_%(Filename).cppdefaultRcc'ing %(Identity)...$(Configuration)qrc_%(Filename).cppUic'ing %(Identity)...$(ProjectDir)ui_%(Filename).h - .;..\hidapi\hidapi;..\qcustomplot;opus-tools\src;rtaudio;debug;/include;%(AdditionalIncludeDirectories) + .;..\hidapi\hidapi;..\qcustomplot;..\opus\include;resampler;debug;/include;%(AdditionalIncludeDirectories) -Zc:rvalueCast -Zc:inline -Zc:strictStrings -Zc:throwingNew -Zc:referenceBinding -Zc:__cplusplus -w34100 -w34189 -w44996 -w44456 -w44457 -w44458 %(AdditionalOptions) debug\ false @@ -98,7 +99,7 @@ Sync debug\ Disabled - _WINDOWS;UNICODE;_UNICODE;WIN32;_ENABLE_EXTENDED_ALIGNED_STORAGE;QT_DEPRECATED_WARNINGS;QCUSTOMPLOT_COMPILE_LIBRARY;OUTSIDE_SPEEX;RANDOM_PREFIX=wf;__WINDOWS_WASAPI__;GITSHORT="28ba131";HOST="wfview.org";UNAME="build";%(PreprocessorDefinitions) + _WINDOWS;UNICODE;_UNICODE;WIN32;_ENABLE_EXTENDED_ALIGNED_STORAGE;QT_DEPRECATED_WARNINGS;QCUSTOMPLOT_COMPILE_LIBRARY;USE_SSE;OUTSIDE_SPEEX;RANDOM_PREFIX=wf;PREFIX="/usr/local";__WINDOWS_WASAPI__;GITSHORT="87dc468";HOST="wfview.org";UNAME="build";%(PreprocessorDefinitions) false MultiThreadedDebugDLL true @@ -106,8 +107,8 @@ Level3 true - ..\hidapi\windows\release\hidapi.lib;shell32.lib;%(AdditionalDependencies) - ..\hidapi\windows\release;C:\opensslx86\lib;C:\Utils\my_sql\mysql-5.6.11-win32\lib;C:\Utils\postgresqlx86\pgsql\lib;%(AdditionalLibraryDirectories) + ..\opus\win32\VS2015\Win32\Debug\opus.lib;shell32.lib;%(AdditionalDependencies) + ..\opus\win32\VS2015\Win32\Debug;C:\opensslx86\lib;C:\Utils\my_sql\mysql-5.7.25-win32\lib;C:\Utils\postgresqlx86\pgsql\lib;%(AdditionalLibraryDirectories) "/MANIFESTDEPENDENCY:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' publicKeyToken='6595b64144ccf1df' language='*' processorArchitecture='*'" %(AdditionalOptions) true true @@ -123,14 +124,16 @@ 0 - _WINDOWS;UNICODE;_UNICODE;WIN32;_ENABLE_EXTENDED_ALIGNED_STORAGE;QT_DEPRECATED_WARNINGS;QCUSTOMPLOT_COMPILE_LIBRARY;OUTSIDE_SPEEX;RANDOM_PREFIX=wf;__WINDOWS_WASAPI__;GITSHORT=\"28ba131\";HOST=\"wfview.org\";UNAME=\"build\";QT_MULTIMEDIA_LIB;QT_PRINTSUPPORT_LIB;QT_WIDGETS_LIB;QT_GUI_LIB;QT_SERIALPORT_LIB;QT_NETWORK_LIB;QT_CORE_LIB;_DEBUG;%(PreprocessorDefinitions) + _WINDOWS;UNICODE;_UNICODE;WIN32;_ENABLE_EXTENDED_ALIGNED_STORAGE;QT_DEPRECATED_WARNINGS;QCUSTOMPLOT_COMPILE_LIBRARY;USE_SSE;OUTSIDE_SPEEX;RANDOM_PREFIX=wf;PREFIX=\"/usr/local\";__WINDOWS_WASAPI__;GITSHORT=\"87dc468\";HOST=\"wfview.org\";UNAME=\"build\";QT_MULTIMEDIA_LIB;QT_PRINTSUPPORT_LIB;QT_WIDGETS_LIB;QT_GUI_LIB;QT_SERIALPORT_LIB;QT_NETWORK_LIB;QT_CORE_LIB;_DEBUG;%(PreprocessorDefinitions) msvc./$(Configuration)/moc_predefs.hMoc'ing %(Identity)...output$(Configuration)moc_%(Filename).cppdefaultRcc'ing %(Identity)...$(Configuration)qrc_%(Filename).cppUic'ing %(Identity)...$(ProjectDir)ui_%(Filename).h + + @@ -138,20 +141,31 @@ - + + - + + + + + + + + + + + @@ -162,6 +176,7 @@ + @@ -236,7 +251,7 @@ - + @@ -279,7 +294,17 @@ - + + + + + + + + + + + @@ -331,6 +356,8 @@ + + Document true @@ -375,6 +402,10 @@ + + + + @@ -382,6 +413,17 @@ + + + + + + + + + + + @@ -414,6 +456,17 @@ + + + + + + + + + + + diff --git a/wfview.vcxproj.filters b/wfview.vcxproj.filters index fe3ebcb..445e538 100644 --- a/wfview.vcxproj.filters +++ b/wfview.vcxproj.filters @@ -57,6 +57,9 @@ + + Source Files + Source Files @@ -69,6 +72,9 @@ Source Files + + Source Files + Source Files @@ -90,7 +96,7 @@ Source Files - + Source Files @@ -111,6 +117,9 @@ Source Files + + Source Files + Source Files @@ -125,12 +134,18 @@ - + + Header Files + + Header Files Header Files + + Header Files + Header Files @@ -164,7 +179,7 @@ Header Files - + Header Files @@ -185,9 +200,12 @@ Header Files - + Header Files + + Header Files + Header Files @@ -213,6 +231,8 @@ + + Generated Files @@ -247,6 +267,10 @@ + + + + @@ -254,6 +278,9 @@ + + Form Files + Form Files @@ -263,6 +290,9 @@ Form Files + + Form Files + Form Files