1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-12-25 20:22:10 -05:00
sdrangel/plugins/channelrx/demodlora/lorademodgui.cpp

192 lines
5.0 KiB
C++
Raw Normal View History

#include <device/devicesourceapi.h>
#include "device/deviceuiset.h"
#include <dsp/downchannelizer.h>
2015-01-10 19:12:58 -05:00
#include <QDockWidget>
#include <QMainWindow>
2015-01-10 19:12:58 -05:00
#include "ui_lorademodgui.h"
#include "dsp/spectrumvis.h"
#include "gui/glspectrum.h"
#include "plugin/pluginapi.h"
#include "util/simpleserializer.h"
2015-08-17 02:29:34 -04:00
#include "dsp/dspengine.h"
2017-10-07 18:28:42 -04:00
#include "lorademod.h"
#include "lorademodgui.h"
2015-01-10 19:12:58 -05:00
LoRaDemodGUI* LoRaDemodGUI::create(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, BasebandSampleSink *rxChannel)
2015-01-10 19:12:58 -05:00
{
LoRaDemodGUI* gui = new LoRaDemodGUI(pluginAPI, deviceUISet, rxChannel);
2015-01-10 19:12:58 -05:00
return gui;
}
void LoRaDemodGUI::destroy()
{
delete this;
}
void LoRaDemodGUI::setName(const QString& name)
{
setObjectName(name);
}
QString LoRaDemodGUI::getName() const
{
return objectName();
}
qint64 LoRaDemodGUI::getCenterFrequency() const {
return m_channelMarker.getCenterFrequency();
}
void LoRaDemodGUI::setCenterFrequency(qint64 centerFrequency)
{
m_channelMarker.setCenterFrequency(centerFrequency);
applySettings();
}
2015-01-10 19:12:58 -05:00
void LoRaDemodGUI::resetToDefaults()
{
2017-10-07 18:28:42 -04:00
m_settings.resetToDefaults();
displaySettings();
applySettings(true);
2015-01-10 19:12:58 -05:00
}
QByteArray LoRaDemodGUI::serialize() const
{
2017-10-07 18:28:42 -04:00
return m_settings.serialize();
2015-01-10 19:12:58 -05:00
}
bool LoRaDemodGUI::deserialize(const QByteArray& data)
{
2017-10-07 18:28:42 -04:00
if(m_settings.deserialize(data)) {
displaySettings();
applySettings(true);
return true;
} else {
resetToDefaults();
return false;
}
2015-01-10 19:12:58 -05:00
}
2017-05-25 14:13:34 -04:00
bool LoRaDemodGUI::handleMessage(const Message& message __attribute__((unused)))
2015-01-10 19:12:58 -05:00
{
return false;
}
void LoRaDemodGUI::viewChanged()
{
applySettings();
}
void LoRaDemodGUI::on_BW_valueChanged(int value)
{
2017-10-07 18:28:42 -04:00
if (value < 0) {
m_settings.m_bandwidthIndex = 0;
} else if (value < LoRaDemodSettings::nb_bandwidths) {
m_settings.m_bandwidthIndex = value;
} else {
m_settings.m_bandwidthIndex = LoRaDemodSettings::nb_bandwidths - 1;
}
int thisBW = LoRaDemodSettings::bandwidths[value];
2015-01-12 09:25:16 -05:00
ui->BWText->setText(QString("%1 Hz").arg(thisBW));
m_channelMarker.setBandwidth(thisBW);
2017-10-07 18:28:42 -04:00
2015-01-10 19:12:58 -05:00
applySettings();
}
2017-05-25 14:13:34 -04:00
void LoRaDemodGUI::on_Spread_valueChanged(int value __attribute__((unused)))
2015-01-12 09:25:16 -05:00
{
}
2017-05-25 14:13:34 -04:00
void LoRaDemodGUI::onWidgetRolled(QWidget* widget __attribute__((unused)), bool rollDown __attribute__((unused)))
2015-01-10 19:12:58 -05:00
{
}
LoRaDemodGUI::LoRaDemodGUI(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, BasebandSampleSink *rxChannel, QWidget* parent) :
2015-01-10 19:12:58 -05:00
RollupWidget(parent),
ui(new Ui::LoRaDemodGUI),
m_pluginAPI(pluginAPI),
m_deviceUISet(deviceUISet),
m_channelMarker(this),
m_doApplySettings(true)
2015-01-10 19:12:58 -05:00
{
ui->setupUi(this);
setAttribute(Qt::WA_DeleteOnClose, true);
connect(this, SIGNAL(widgetRolled(QWidget*,bool)), this, SLOT(onWidgetRolled(QWidget*,bool)));
m_spectrumVis = new SpectrumVis(SDR_RX_SCALEF, ui->glSpectrum);
m_LoRaDemod = (LoRaDemod*) rxChannel; //new LoRaDemod(m_deviceUISet->m_deviceSourceAPI);
2017-10-07 19:42:18 -04:00
m_LoRaDemod->setSpectrumSink(m_spectrumVis);
2015-01-10 19:12:58 -05:00
2015-01-12 09:25:16 -05:00
ui->glSpectrum->setCenterFrequency(16000);
ui->glSpectrum->setSampleRate(32000);
2015-01-10 19:12:58 -05:00
ui->glSpectrum->setDisplayWaterfall(true);
ui->glSpectrum->setDisplayMaxHold(true);
m_channelMarker.setMovable(false);
m_channelMarker.setVisible(true);
connect(&m_channelMarker, SIGNAL(changedByCursor()), this, SLOT(viewChanged()));
m_deviceUISet->registerRxChannelInstance(LoRaDemod::m_channelIdURI, this);
m_deviceUISet->addChannelMarker(&m_channelMarker);
m_deviceUISet->addRollupWidget(this);
2015-01-10 19:12:58 -05:00
2017-10-07 19:42:18 -04:00
ui->spectrumGUI->setBuddies(m_spectrumVis->getInputMessageQueue(), m_spectrumVis, ui->glSpectrum);
2015-01-10 19:12:58 -05:00
2017-10-07 19:42:18 -04:00
m_settings.setChannelMarker(&m_channelMarker);
m_settings.setSpectrumGUI(ui->spectrumGUI);
displaySettings();
applySettings(true);
2015-01-10 19:12:58 -05:00
}
LoRaDemodGUI::~LoRaDemodGUI()
{
m_deviceUISet->removeRxChannelInstance(this);
delete m_LoRaDemod; // TODO: check this: when the GUI closes it has to delete the demodulator
2015-01-10 19:12:58 -05:00
delete m_spectrumVis;
delete ui;
}
void LoRaDemodGUI::blockApplySettings(bool block)
{
m_doApplySettings = !block;
}
2017-10-07 18:28:42 -04:00
void LoRaDemodGUI::applySettings(bool force)
2015-01-10 19:12:58 -05:00
{
if (m_doApplySettings)
{
2017-10-07 19:42:18 -04:00
setTitleColor(m_channelMarker.getColor());
2015-08-17 02:29:34 -04:00
2017-10-07 19:42:18 -04:00
LoRaDemod::MsgConfigureChannelizer* channelConfigMsg = LoRaDemod::MsgConfigureChannelizer::create(
LoRaDemodSettings::bandwidths[m_settings.m_bandwidthIndex],
m_channelMarker.getCenterFrequency());
m_LoRaDemod->getInputMessageQueue()->push(channelConfigMsg);
LoRaDemod::MsgConfigureLoRaDemod* message = LoRaDemod::MsgConfigureLoRaDemod::create( m_settings, force);
m_LoRaDemod->getInputMessageQueue()->push(message);
}
2015-01-10 19:12:58 -05:00
}
2017-10-07 18:28:42 -04:00
void LoRaDemodGUI::displaySettings()
{
int thisBW = LoRaDemodSettings::bandwidths[m_settings.m_bandwidthIndex];
2017-10-07 19:42:18 -04:00
m_channelMarker.blockSignals(true);
m_channelMarker.setBandwidth(thisBW);
m_channelMarker.setCenterFrequency(0);
m_channelMarker.setColor(m_settings.m_rgbColor);
setTitleColor(m_settings.m_rgbColor);
m_channelMarker.blockSignals(false);
2017-10-11 19:21:30 -04:00
blockApplySettings(true);
ui->BWText->setText(QString("%1 Hz").arg(thisBW));
ui->BW->setValue(m_settings.m_bandwidthIndex);
blockApplySettings(false);
2017-10-07 18:28:42 -04:00
}