2018-03-12 00:07:51 -04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Copyright (C) 2018 F4EXB //
|
|
|
|
// written by Edouard Griffiths //
|
|
|
|
// //
|
|
|
|
// This program is free software; you can redistribute it and/or modify //
|
|
|
|
// it under the terms of the GNU General Public License as published by //
|
|
|
|
// the Free Software Foundation as version 3 of the License, or //
|
2019-04-11 08:43:33 -04:00
|
|
|
// (at your option) any later version. //
|
2018-03-12 00:07:51 -04:00
|
|
|
// //
|
|
|
|
// This program is distributed in the hope that it will be useful, //
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
|
|
|
// GNU General Public License V3 for more details. //
|
|
|
|
// //
|
|
|
|
// You should have received a copy of the GNU General Public License //
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2018-11-12 12:36:27 -05:00
|
|
|
#include <chrono>
|
|
|
|
#include <thread>
|
|
|
|
|
2018-03-12 00:07:51 -04:00
|
|
|
#include "scopevisxy.h"
|
2022-02-12 18:57:33 -05:00
|
|
|
#include "util/message.h"
|
2018-03-12 00:07:51 -04:00
|
|
|
#include "gui/tvscreen.h"
|
|
|
|
|
|
|
|
ScopeVisXY::ScopeVisXY(TVScreen *tvScreen) :
|
|
|
|
m_tvScreen(tvScreen),
|
|
|
|
m_scale(1.0),
|
|
|
|
m_cols(0),
|
|
|
|
m_rows(0),
|
|
|
|
m_pixelsPerFrame(480),
|
|
|
|
m_pixelCount(0),
|
2018-03-12 20:39:43 -04:00
|
|
|
m_alphaTrace(128),
|
|
|
|
m_alphaReset(128),
|
2018-03-12 00:07:51 -04:00
|
|
|
m_plotRGB(qRgb(0, 255, 0)),
|
|
|
|
m_gridRGB(qRgb(255, 255 ,255))
|
|
|
|
{
|
|
|
|
setObjectName("ScopeVisXY");
|
2018-03-12 20:39:43 -04:00
|
|
|
setPixelsPerFrame(m_pixelsPerFrame);
|
|
|
|
m_tvScreen->setAlphaBlend(true);
|
2018-03-12 00:07:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
ScopeVisXY::~ScopeVisXY()
|
2018-03-12 20:39:43 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScopeVisXY::setPixelsPerFrame(int pixelsPerFrame)
|
|
|
|
{
|
|
|
|
m_pixelsPerFrame = pixelsPerFrame;
|
|
|
|
m_pixelCount = 0;
|
|
|
|
m_tvScreen->setAlphaReset();
|
|
|
|
}
|
2018-03-12 00:07:51 -04:00
|
|
|
|
2018-11-12 12:36:27 -05:00
|
|
|
void ScopeVisXY::feed(const SampleVector::const_iterator& cbegin, const SampleVector::const_iterator& end, bool positiveOnly)
|
2018-03-12 00:07:51 -04:00
|
|
|
{
|
2018-11-12 12:36:27 -05:00
|
|
|
(void) positiveOnly;
|
2018-03-12 00:07:51 -04:00
|
|
|
SampleVector::const_iterator begin(cbegin);
|
|
|
|
|
|
|
|
while (begin < end)
|
|
|
|
{
|
|
|
|
float x = m_scale * (begin->m_real/SDR_RX_SCALEF);
|
|
|
|
float y = m_scale * (begin->m_imag/SDR_RX_SCALEF);
|
|
|
|
|
|
|
|
int row = m_rows * ((1.0 - y) / 2.0);
|
|
|
|
int col = m_cols * ((1.0 + x) / 2.0);
|
|
|
|
|
|
|
|
row = row < 0 ? 0 : row >= m_rows ? m_rows-1 : row;
|
|
|
|
col = col < 0 ? 0 : col >= m_cols ? m_cols-1 : col;
|
|
|
|
|
|
|
|
m_tvScreen->selectRow(row);
|
2018-03-12 20:39:43 -04:00
|
|
|
m_tvScreen->setDataColor(col, qRed(m_plotRGB), qGreen(m_plotRGB), qBlue(m_plotRGB), m_alphaTrace);
|
|
|
|
|
|
|
|
++begin;
|
2018-03-12 00:07:51 -04:00
|
|
|
m_pixelCount++;
|
|
|
|
|
|
|
|
if (m_pixelCount == m_pixelsPerFrame)
|
|
|
|
{
|
2018-03-14 19:16:50 -04:00
|
|
|
int rows, cols;
|
|
|
|
m_tvScreen->getSize(rows, cols);
|
|
|
|
|
|
|
|
if ((rows != m_rows) || (cols != m_cols))
|
|
|
|
{
|
|
|
|
calculateGraticule(rows, cols);
|
|
|
|
m_rows = rows;
|
|
|
|
m_cols = cols;
|
|
|
|
}
|
|
|
|
|
2018-03-12 00:07:51 -04:00
|
|
|
m_tvScreen->renderImage(0);
|
2018-03-23 04:24:18 -04:00
|
|
|
m_tvScreen->update();
|
2018-11-12 12:36:27 -05:00
|
|
|
std::this_thread::sleep_for(std::chrono::microseconds(5000));
|
2018-03-12 20:39:43 -04:00
|
|
|
m_tvScreen->resetImage(m_alphaReset);
|
2018-04-01 18:58:46 -04:00
|
|
|
drawGraticule();
|
2018-03-12 00:07:51 -04:00
|
|
|
m_pixelCount = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScopeVisXY::start()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScopeVisXY::stop()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-02-12 18:57:33 -05:00
|
|
|
void ScopeVisXY::handleInputMessages()
|
|
|
|
{
|
|
|
|
Message* message;
|
|
|
|
|
|
|
|
while ((message = m_inputMessageQueue.pop()) != 0)
|
|
|
|
{
|
|
|
|
if (handleMessage(*message)) {
|
|
|
|
delete message;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-12 12:36:27 -05:00
|
|
|
bool ScopeVisXY::handleMessage(const Message& message)
|
2018-03-12 00:07:51 -04:00
|
|
|
{
|
2018-11-12 12:36:27 -05:00
|
|
|
(void) message;
|
2018-03-12 00:07:51 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScopeVisXY::addGraticulePoint(const std::complex<float>& z) {
|
|
|
|
m_graticule.push_back(z);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScopeVisXY::clearGraticule() {
|
|
|
|
m_graticule.clear();
|
|
|
|
}
|
|
|
|
|
2018-03-14 19:16:50 -04:00
|
|
|
void ScopeVisXY::calculateGraticule(int rows, int cols)
|
2018-03-12 00:07:51 -04:00
|
|
|
{
|
2018-03-14 19:16:50 -04:00
|
|
|
m_graticuleRows.clear();
|
|
|
|
m_graticuleCols.clear();
|
2018-03-12 00:07:51 -04:00
|
|
|
|
2018-03-14 19:16:50 -04:00
|
|
|
std::vector<std::complex<float> >::const_iterator grIt = m_graticule.begin();
|
|
|
|
|
|
|
|
for (; grIt != m_graticule.end(); ++grIt)
|
|
|
|
{
|
|
|
|
int y = rows * ((1.0 - grIt->imag()) / 2.0);
|
|
|
|
int x = cols * ((1.0 + grIt->real()) / 2.0);
|
2018-03-12 00:07:51 -04:00
|
|
|
|
|
|
|
for (int d = -4; d <= 4; ++d)
|
|
|
|
{
|
2018-03-14 19:16:50 -04:00
|
|
|
m_graticuleRows.push_back(y+d);
|
|
|
|
m_graticuleCols.push_back(x);
|
|
|
|
m_graticuleRows.push_back(y);
|
|
|
|
m_graticuleCols.push_back(x+d);
|
2018-03-12 00:07:51 -04:00
|
|
|
}
|
2018-03-14 19:16:50 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScopeVisXY::drawGraticule()
|
|
|
|
{
|
|
|
|
std::vector<int>::const_iterator rowIt = m_graticuleRows.begin();
|
|
|
|
std::vector<int>::const_iterator colIt = m_graticuleCols.begin();
|
|
|
|
|
|
|
|
for(; (rowIt != m_graticuleRows.end()) && (colIt != m_graticuleCols.end()); ++rowIt, ++colIt)
|
|
|
|
{
|
|
|
|
m_tvScreen->selectRow(*rowIt);
|
|
|
|
m_tvScreen->setDataColor(*colIt, qRed(m_gridRGB), qGreen(m_gridRGB), qBlue(m_gridRGB));
|
|
|
|
}
|
2018-03-12 00:07:51 -04:00
|
|
|
}
|
|
|
|
|