diff --git a/audioconverter.h b/audioconverter.h index b3a1492..b0eb1ad 100644 --- a/audioconverter.h +++ b/audioconverter.h @@ -17,7 +17,7 @@ #include #endif -enum audioType {qtAudio,portAudio,rtAudio}; +#include "wfviewtypes.h" #include "resampler/speex_resampler.h" diff --git a/prefs.h b/prefs.h new file mode 100644 index 0000000..96f13e2 --- /dev/null +++ b/prefs.h @@ -0,0 +1,52 @@ +#ifndef PREFS_H +#define PREFS_H + +#include + +#include "wfviewtypes.h" + +struct preferences { + QString version; + bool useFullScreen; + bool useSystemTheme; + bool drawPeaks; + underlay_t underlayMode = underlayNone; + int underlayBufferSize = 64; + bool wfAntiAlias; + bool wfInterpolate; + QString stylesheetPath; + unsigned char radioCIVAddr; + bool CIVisRadioModel; + bool forceRTSasPTT; + QString serialPortRadio; + quint32 serialPortBaud; + int polling_ms; + bool enablePTT; + bool niceTS; + bool enableLAN; + bool enableRigCtlD; + quint16 rigCtlPort; + int currentColorPresetNumber = 0; + QString virtualSerialPort; + unsigned char localAFgain; + unsigned int wflength; + int wftheme; + int plotFloor; + int plotCeiling; + bool confirmExit; + bool confirmPowerOff; + meterKind meter2Type; + quint16 tcpPort; + quint8 waterfallFormat; + audioType audioSystem; + bool clusterUdpEnable; + bool clusterTcpEnable; + int clusterUdpPort; + QString clusterTcpServerName; + QString clusterTcpUserName; + QString clusterTcpPassword; + int clusterTimeout; + bool clickDragTuningEnable; +}; + +#endif // PREFS_H diff --git a/rigcommander.h b/rigcommander.h index cbd475d..9f49832 100644 --- a/rigcommander.h +++ b/rigcommander.h @@ -5,7 +5,7 @@ #include #include - +#include "wfviewtypes.h" #include "commhandler.h" #include "pttyhandler.h" #include "udphandler.h" @@ -23,48 +23,6 @@ // note: using a define because switch case doesn't even work with const unsigned char. Surprised me. #define compCivAddr 0xE1 -enum meterKind { - meterNone=0, - meterS, - meterCenter, - meterSWR, - meterPower, - meterALC, - meterComp, - meterVoltage, - meterCurrent, - meterRxdB, - meterTxMod, - meterRxAudio, - meterAudio, - meterLatency -}; - -enum spectrumMode { - spectModeCenter=0x00, - spectModeFixed=0x01, - spectModeScrollC=0x02, - spectModeScrollF=0x03, - spectModeUnknown=0xff -}; - -struct freqt { - quint64 Hz; - double MHzDouble; -}; - -struct datekind { - uint16_t year; - unsigned char month; - unsigned char day; -}; - -struct timekind { - unsigned char hours; - unsigned char minutes; - bool isMinus; -}; - class rigCommander : public QObject { Q_OBJECT diff --git a/wfmain.cpp b/wfmain.cpp index b6656bb..f79cd4b 100644 --- a/wfmain.cpp +++ b/wfmain.cpp @@ -1422,6 +1422,7 @@ void wfmain::setDefPrefs() defPrefs.forceRTSasPTT = false; defPrefs.serialPortRadio = QString("auto"); defPrefs.serialPortBaud = 115200; + defPrefs.polling_ms = 0; // 0 = Automatic defPrefs.enablePTT = false; defPrefs.niceTS = true; defPrefs.enableRigCtlD = false; @@ -1570,6 +1571,27 @@ void wfmain::loadSettings() serverConfig.baudRate = prefs.serialPortBaud; } + prefs.polling_ms = settings->value("polling_ms", defPrefs.polling_ms).toInt(); + if(prefs.polling_ms == 0) + { + // Automatic + ui->pollingButtonGroup->blockSignals(true); + ui->autoPollBtn->setChecked(true); + ui->manualPollBtn->setChecked(false); + ui->pollingButtonGroup->blockSignals(false); + ui->pollTimeMsSpin->setEnabled(false); + } else { + // Manual + ui->pollingButtonGroup->blockSignals(true); + ui->autoPollBtn->setChecked(false); + ui->manualPollBtn->setChecked(true); + ui->pollingButtonGroup->blockSignals(false); + ui->pollTimeMsSpin->blockSignals(true); + ui->pollTimeMsSpin->setValue(prefs.polling_ms); + ui->pollTimeMsSpin->blockSignals(false); + ui->pollTimeMsSpin->setEnabled(true); + } + prefs.virtualSerialPort = settings->value("VirtualSerialPort", defPrefs.virtualSerialPort).toString(); int vspIndex = ui->vspCombo->findText(prefs.virtualSerialPort); if (vspIndex != -1) { @@ -2100,6 +2122,10 @@ void wfmain::saveSettings() qInfo(logSystem()) << "Saving settings to " << settings->fileName(); // Basic things to load: + settings->beginGroup("Program"); + settings->setValue("version", QString(WFVIEW_VERSION)); + settings->endGroup(); + // UI: (full screen, dark theme, draw peaks, colors, etc) settings->beginGroup("Interface"); settings->setValue("UseFullScreen", prefs.useFullScreen); @@ -2129,6 +2155,7 @@ void wfmain::saveSettings() settings->setValue("RigCIVuInt", prefs.radioCIVAddr); settings->setValue("CIVisRadioModel", prefs.CIVisRadioModel); settings->setValue("ForceRTSasPTT", prefs.forceRTSasPTT); + settings->setValue("polling_ms", prefs.polling_ms); // 0 = automatic settings->setValue("SerialPortRadio", prefs.serialPortRadio); settings->setValue("SerialPortBaud", prefs.serialPortBaud); settings->setValue("VirtualSerialPort", prefs.virtualSerialPort); @@ -3711,7 +3738,12 @@ void wfmain::receiveRigID(rigCapabilities rigCaps) issueDelayedCommand(cmdGetFreq); issueDelayedCommand(cmdGetMode); // recalculate command timing now that we know the rig better: - calculateTimingParameters(); + if(prefs.polling_ms != 0) + { + changePollTiming(prefs.polling_ms, true); + } else { + calculateTimingParameters(); + } initPeriodicCommands(); // Set the second meter here as I suspect we need to be connected for it to work? @@ -5883,6 +5915,10 @@ void wfmain::calculateTimingParameters() qInfo(logSystem()) << "Delay command interval timing: " << delayedCommand->interval() << "ms"; + ui->pollTimeMsSpin->blockSignals(true); + ui->pollTimeMsSpin->setValue(delayedCommand->interval()); + ui->pollTimeMsSpin->blockSignals(false); + // Normal: delayedCmdIntervalLAN_ms = delayedCommand->interval(); delayedCmdIntervalSerial_ms = delayedCommand->interval(); @@ -6164,20 +6200,6 @@ void wfmain::on_wfLengthSlider_valueChanged(int value) prepareWf(value); } -void wfmain::on_pollingBtn_clicked() -{ - bool ok; - int timing = 0; - timing = QInputDialog::getInt(this, "wfview Radio Polling Setup", "Poll Timing Interval (ms)", delayedCommand->interval(), 1, 200, 1, &ok ); - - if(ok && timing) - { - delayedCommand->setInterval( timing ); - qInfo(logSystem()) << "User changed radio polling interval to " << timing << "ms."; - showStatusBarText("User changed radio polling interval to " + QString("%1").arg(timing) + "ms."); - } -} - void wfmain::on_wfAntiAliasChk_clicked(bool checked) { colorMap->setAntialiased(checked); @@ -7840,3 +7862,46 @@ void wfmain::on_clickDragTuningEnableChk_clicked(bool checked) } + +void wfmain::on_autoPollBtn_clicked(bool checked) +{ + ui->pollTimeMsSpin->setEnabled(!checked); + if(checked) + { + prefs.polling_ms = 0; + qInfo(logSystem()) << "User set radio polling interval to automatic."; + calculateTimingParameters(); + } +} + +void wfmain::on_manualPollBtn_clicked(bool checked) +{ + ui->pollTimeMsSpin->setEnabled(checked); + if(checked) + { + prefs.polling_ms = ui->pollTimeMsSpin->value(); + changePollTiming(prefs.polling_ms); + } +} + +void wfmain::on_pollTimeMsSpin_valueChanged(int timing_ms) +{ + if(ui->manualPollBtn->isChecked()) + { + changePollTiming(timing_ms); + } +} + +void wfmain::changePollTiming(int timing_ms, bool setUI) +{ + delayedCommand->setInterval(timing_ms); + qInfo(logSystem()) << "User changed radio polling interval to " << timing_ms << "ms."; + showStatusBarText("User changed radio polling interval to " + QString("%1").arg(timing_ms) + "ms."); + prefs.polling_ms = timing_ms; + if(setUI) + { + ui->pollTimeMsSpin->blockSignals(true); + ui->pollTimeMsSpin->setValue(timing_ms); + ui->pollTimeMsSpin->blockSignals(false); + } +} diff --git a/wfmain.h b/wfmain.h index 0c37db8..7f318b2 100644 --- a/wfmain.h +++ b/wfmain.h @@ -20,6 +20,8 @@ #include #include "logcategories.h" +#include "wfviewtypes.h" +#include "prefs.h" #include "commhandler.h" #include "rigcommander.h" #include "rigstate.h" @@ -511,8 +513,6 @@ private slots: void on_wfLengthSlider_valueChanged(int value); - void on_pollingBtn_clicked(); - void on_wfAntiAliasChk_clicked(bool checked); void on_wfInterpolateChk_clicked(bool checked); @@ -684,6 +684,12 @@ private slots: void receiveClusterOutput(QString text); void receiveSpots(QList spots); + void on_autoPollBtn_clicked(bool checked); + + void on_manualPollBtn_clicked(bool checked); + + void on_pollTimeMsSpin_valueChanged(int arg1); + private: Ui::wfmain *ui; void closeEvent(QCloseEvent *event); @@ -801,9 +807,6 @@ private: quint16 wfLength; bool spectrumDrawLock; - enum underlay_t { underlayNone, underlayPeakHold, underlayPeakBuffer, underlayAverageBuffer }; - - QByteArray spectrumPeaks; QVector spectrumPlasmaLine; QVector spectrumPlasma; @@ -904,49 +907,7 @@ private: colorPrefsType colorPreset[numColorPresetsTotal]; - struct preferences { - bool useFullScreen; - bool useSystemTheme; - bool drawPeaks; - underlay_t underlayMode = underlayNone; - int underlayBufferSize = 64; - bool wfAntiAlias; - bool wfInterpolate; - QString stylesheetPath; - unsigned char radioCIVAddr; - bool CIVisRadioModel; - bool forceRTSasPTT; - QString serialPortRadio; - quint32 serialPortBaud; - bool enablePTT; - bool niceTS; - bool enableLAN; - bool enableRigCtlD; - quint16 rigCtlPort; - int currentColorPresetNumber = 0; - QString virtualSerialPort; - unsigned char localAFgain; - unsigned int wflength; - int wftheme; - int plotFloor; - int plotCeiling; - bool confirmExit; - bool confirmPowerOff; - meterKind meter2Type; - quint16 tcpPort; - quint8 waterfallFormat; - audioType audioSystem; - bool clusterUdpEnable; - bool clusterTcpEnable; - int clusterUdpPort; - QString clusterTcpServerName; - QString clusterTcpUserName; - QString clusterTcpPassword; - int clusterTimeout; - bool clusterSkimmerSpotsEnable; - bool clickDragTuningEnable; - } prefs; - + preferences prefs; preferences defPrefs; udpPreferences udpPrefs; udpPreferences udpDefPrefs; @@ -1016,6 +977,7 @@ private: void insertSlowPeriodicCommand(cmds cmd, unsigned char priority); void calculateTimingParameters(); + void changePollTiming(int timing_ms, bool setUI=false); void changeMode(mode_kind mode); void changeMode(mode_kind mode, bool dataOn); diff --git a/wfmain.ui b/wfmain.ui index 08414bc..65972b3 100644 --- a/wfmain.ui +++ b/wfmain.ui @@ -6,7 +6,7 @@ 0 0 - 1023 + 1082 660 @@ -3147,18 +3147,51 @@ - + - Set up radio polling. The radio's meter is polled every-other interval. - - - Polling - - - + wfview will automatically calculate command polling. Recommended. - Polling + AutoPolling + + + true + + + pollingButtonGroup + + + + + + + Manual (user-defined) command polling + + + Manual Polling Inteval: + + + pollingButtonGroup + + + + + + + Sets the polling interval, in ms. Automatic polling is recommended. Serial port and USB port radios should not poll quicker than about 75ms. + + + 1 + + + 250 + + + + + + + ms @@ -3350,8 +3383,8 @@ 0 0 - 801 - 311 + 858 + 287 @@ -5295,7 +5328,7 @@ 0 0 - 1023 + 1082 21 @@ -5323,7 +5356,8 @@ - + + diff --git a/wfview.pro b/wfview.pro index 290e517..a7c39aa 100644 --- a/wfview.pro +++ b/wfview.pro @@ -185,6 +185,7 @@ HEADERS += wfmain.h \ colorprefs.h \ commhandler.h \ loggingwindow.h \ + prefs.h \ rigcommander.h \ freqmemory.h \ rigidentities.h \ @@ -218,7 +219,8 @@ HEADERS += wfmain.h \ tcpserver.h \ cluster.h \ database.h \ - aboutbox.h + aboutbox.h \ + wfviewtypes.h FORMS += wfmain.ui \ diff --git a/wfviewtypes.h b/wfviewtypes.h new file mode 100644 index 0000000..46876b8 --- /dev/null +++ b/wfviewtypes.h @@ -0,0 +1,51 @@ +#ifndef WFVIEWTYPES_H +#define WFVIEWTYPES_H + +enum underlay_t { underlayNone, underlayPeakHold, underlayPeakBuffer, underlayAverageBuffer }; + +enum meterKind { + meterNone=0, + meterS, + meterCenter, + meterSWR, + meterPower, + meterALC, + meterComp, + meterVoltage, + meterCurrent, + meterRxdB, + meterTxMod, + meterRxAudio, + meterAudio, + meterLatency +}; + +enum spectrumMode { + spectModeCenter=0x00, + spectModeFixed=0x01, + spectModeScrollC=0x02, + spectModeScrollF=0x03, + spectModeUnknown=0xff +}; + +struct freqt { + quint64 Hz; + double MHzDouble; +}; + +struct datekind { + uint16_t year; + unsigned char month; + unsigned char day; +}; + +struct timekind { + unsigned char hours; + unsigned char minutes; + bool isMinus; +}; + +enum audioType {qtAudio,portAudio,rtAudio}; + + +#endif // WFVIEWTYPES_H