Waterfal length may now be adjusted. Let's see what range of length

seems good and limit the control accordingly. Also there may be a memory
leak in the prepareWf() function where the colormap is created when the
image is resized.
merge-requests/5/head
Elliott Liggett 2021-05-30 23:26:36 -07:00
rodzic d601983beb
commit b5167a6a97
4 zmienionych plików z 142 dodań i 48 usunięć

Wyświetl plik

@ -171,7 +171,6 @@ void rigCommander::setup()
setCIVAddr(civAddr);
spectSeqMax = 0; // this is now set after rig ID determined
payloadSuffix = QByteArray("\xFD");
lookingForRig = false;

Wyświetl plik

@ -142,7 +142,7 @@ void wfmain::openRig()
}
// Start rigctld
if (prefs.enableRigCtlD) {
if (prefs.enableRigCtlD && rigCtl == Q_NULLPTR) {
rigCtl = new rigCtlD(this);
rigCtl->startServer(prefs.rigCtlPort);
@ -525,6 +525,7 @@ void wfmain::setupPlots()
{
// Line 290--
spectrumDrawLock = true;
plot = ui->plot; // rename it waterfall.
wf = ui->waterfall;
@ -563,7 +564,7 @@ void wfmain::setupPlots()
connect(wf, SIGNAL(mousePress(QMouseEvent*)), this, SLOT(handleWFClick(QMouseEvent*)));
connect(wf, SIGNAL(mouseWheel(QWheelEvent*)), this, SLOT(handleWFScroll(QWheelEvent*)));
connect(plot, SIGNAL(mouseWheel(QWheelEvent*)), this, SLOT(handlePlotScroll(QWheelEvent*)));
spectrumDrawLock = false;
}
void wfmain::setupMainUI()
@ -1136,7 +1137,7 @@ void wfmain::loadSettings()
}
ui->lanEnableBtn->setChecked(prefs.enableLAN);
ui->connectBtn->setEnabled(prefs.enableLAN);
ui->connectBtn->setEnabled(true);
prefs.enableRigCtlD = settings->value("EnableRigCtlD", defPrefs.enableRigCtlD).toBool();
prefs.rigCtlPort = settings->value("RigCtlPort", defPrefs.rigCtlPort).toInt();
@ -1422,35 +1423,66 @@ void wfmain::saveSettings()
settings->sync(); // Automatic, not needed (supposedly)
}
void wfmain::prepareWf()
{
prepareWf(160);
}
void wfmain::prepareWf(unsigned int wfLength)
{
// All this code gets moved in from the constructor of wfmain.
if(haveRigCaps)
{
// do things
spectWidth = rigCaps.spectLenMax; // was fixed at 475
wfLength = 160; // fixed for now, time-length of waterfall
// TODO: Lock the function that draws on the spectrum while we are updating.
spectrumDrawLock = true;
spectWidth = rigCaps.spectLenMax;
this->wfLength = wfLength; // fixed for now, time-length of waterfall
// Initialize before use!
QByteArray empty((int)spectWidth, '\x01');
spectrumPeaks = QByteArray( (int)spectWidth, '\x01' );
for(quint16 i=0; i<wfLength; i++)
if((unsigned int)wfimage.size() < wfLength)
{
wfimage.append(empty);
unsigned int i=0;
unsigned int oldSize = wfimage.size();
// Note: apparently .append() in this case does not add to the initial size.
// So if the initial size is 100 and you append 50 times,
// the end size is 50.
for(i=oldSize; i<(wfLength); i++)
{
wfimage.append(empty);
}
} else {
wfimage.remove(wfLength, wfimage.size()-wfLength);
}
wfimage.squeeze();
colorMap->clearData();
colorMap->data()->clear();
colorMap->data()->setValueRange(QCPRange(0, wfLength-1));
colorMap->data()->setKeyRange(QCPRange(0, spectWidth-1));
colorMap->setDataRange(QCPRange(0, rigCaps.spectAmpMax));
colorMap->setGradient(QCPColorGradient::gpJet); // TODO: Add preference
colorMapData = new QCPColorMapData(spectWidth, wfLength, QCPRange(0, spectWidth-1), QCPRange(0, wfLength-1));
if(colorMapData == Q_NULLPTR)
{
colorMapData = new QCPColorMapData(spectWidth, wfLength, QCPRange(0, spectWidth-1), QCPRange(0, wfLength-1));
} else {
//delete colorMapData; // TODO: Figure out why it crashes if we delete first.
colorMapData = new QCPColorMapData(spectWidth, wfLength, QCPRange(0, spectWidth-1), QCPRange(0, wfLength-1));
}
colorMap->setData(colorMapData);
spectRowCurrent = 0;
wf->yAxis->setRangeReversed(true);
wf->xAxis->setVisible(false);
rigName->setText(rigCaps.modelName);
spectrumDrawLock = false;
} else {
qInfo(logSystem()) << "Cannot prepare WF view without rigCaps. Waiting on this.";
return;
@ -2571,42 +2603,44 @@ void wfmain::receiveSpectrumData(QByteArray spectrum, double startFreq, double e
}
//ui->qcp->addGraph();
plot->graph(0)->setData(x,y);
if((freq.MHzDouble < endFreq) && (freq.MHzDouble > startFreq))
if(!spectrumDrawLock)
{
freqIndicatorLine->start->setCoords(freq.MHzDouble,0);
freqIndicatorLine->end->setCoords(freq.MHzDouble,160);
}
if(drawPeaks)
{
plot->graph(1)->setData(x,y2); // peaks
}
plot->yAxis->setRange(0, rigCaps.spectAmpMax+1);
plot->xAxis->setRange(startFreq, endFreq);
plot->replot();
if(specLen == spectWidth)
{
wfimage.prepend(spectrum);
if(wfimage.length() > wfLength)
//ui->qcp->addGraph();
plot->graph(0)->setData(x,y);
if((freq.MHzDouble < endFreq) && (freq.MHzDouble > startFreq))
{
wfimage.remove(wfLength);
freqIndicatorLine->start->setCoords(freq.MHzDouble,0);
freqIndicatorLine->end->setCoords(freq.MHzDouble,160);
}
// Waterfall:
for(int row = 0; row < wfLength; row++)
if(drawPeaks)
{
for(int col = 0; col < spectWidth; col++)
plot->graph(1)->setData(x,y2); // peaks
}
plot->yAxis->setRange(0, rigCaps.spectAmpMax+1);
plot->xAxis->setRange(startFreq, endFreq);
plot->replot();
if(specLen == spectWidth)
{
wfimage.prepend(spectrum);
if(wfimage.length() > wfLength)
{
colorMap->data()->setCell( col, row, wfimage.at(row).at(col));
wfimage.remove(wfLength);
}
}
wf->yAxis->setRange(0,wfLength - 1);
wf->xAxis->setRange(0, spectWidth-1);
wf->replot();
spectRowCurrent = (spectRowCurrent + 1) % wfLength;
// Waterfall:
for(int row = 0; row < wfLength; row++)
{
for(int col = 0; col < spectWidth; col++)
{
colorMap->data()->setCell( col, row, wfimage.at(row).at(col));
}
}
wf->yAxis->setRange(0,wfLength - 1);
wf->xAxis->setRange(0, spectWidth-1);
wf->replot();
}
}
}
@ -3552,7 +3586,7 @@ void wfmain::on_serialEnableBtn_clicked(bool checked)
prefs.enableLAN = !checked;
ui->serialDeviceListCombo->setEnabled(checked);
ui->connectBtn->setEnabled(!checked);
ui->connectBtn->setEnabled(true);
ui->ipAddressTxt->setEnabled(!checked);
ui->controlPortTxt->setEnabled(!checked);
ui->usernameTxt->setEnabled(!checked);
@ -3572,7 +3606,7 @@ void wfmain::on_serialEnableBtn_clicked(bool checked)
void wfmain::on_lanEnableBtn_clicked(bool checked)
{
prefs.enableLAN = checked;
ui->connectBtn->setEnabled(checked);
ui->connectBtn->setEnabled(true);
ui->ipAddressTxt->setEnabled(checked);
ui->controlPortTxt->setEnabled(checked);
ui->usernameTxt->setEnabled(checked);
@ -4447,10 +4481,15 @@ void wfmain::on_baudRateCombo_activated(int index)
(void)index;
}
void wfmain::on_wfLengthSlider_valueChanged(int value)
{
prepareWf(value);
}
// --- DEBUG FUNCTION ---
void wfmain::on_debugBtn_clicked()
{
qInfo(logSystem()) << "Debug button pressed.";
qInfo(logSystem()) << "getting mode.";
emit getRigID();
prepareWf(160);
}

Wyświetl plik

@ -45,7 +45,7 @@ public:
signals:
// Basic to rig:
void setCIVAddr(unsigned char);
void setCIVAddr(unsigned char newRigCIVAddr);
// Power
void sendPowerOn();
@ -446,6 +446,8 @@ private slots:
void on_baudRateCombo_activated(int);
void on_wfLengthSlider_valueChanged(int value);
private:
Ui::wfmain *ui;
void closeEvent(QCloseEvent *event);
@ -459,6 +461,7 @@ private:
void setAppTheme(bool isCustom);
void setPlotTheme(QCustomPlot *plot, bool isDark);
void prepareWf();
void prepareWf(unsigned int wfLength);
void getInitialRigState();
void setBandButtons();
void showButton(QPushButton *btn);
@ -543,8 +546,7 @@ private:
quint16 spectWidth;
quint16 wfLength;
quint16 spectRowCurrent;
bool spectrumDrawLock;
QByteArray spectrumPeaks;

Wyświetl plik

@ -18,7 +18,7 @@
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>3</number>
<number>0</number>
</property>
<widget class="QWidget" name="mainTab">
<attribute name="title">
@ -767,6 +767,60 @@
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_20">
<property name="rightMargin">
<number>0</number>
</property>
<item>
<widget class="QSlider" name="wfLengthSlider">
<property name="minimumSize">
<size>
<width>0</width>
<height>70</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>80</height>
</size>
</property>
<property name="toolTip">
<string>Waterfall Length</string>
</property>
<property name="accessibleName">
<string>Waterfall Length</string>
</property>
<property name="minimum">
<number>100</number>
</property>
<property name="maximum">
<number>1024</number>
</property>
<property name="value">
<number>160</number>
</property>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_35">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>15</height>
</size>
</property>
<property name="text">
<string>Len</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_16">
<property name="leftMargin">