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

213 lines
5.5 KiB
C++
Raw Normal View History

#include <device/devicesourceapi.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"
#include "gui/basicchannelsettingswidget.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
const QString LoRaDemodGUI::m_channelID = "de.maintech.sdrangelove.channel.lora";
LoRaDemodGUI* LoRaDemodGUI::create(PluginAPI* pluginAPI, DeviceSourceAPI *deviceAPI)
2015-01-10 19:12:58 -05:00
{
LoRaDemodGUI* gui = new LoRaDemodGUI(pluginAPI, deviceAPI);
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
{
/*
if((widget == ui->spectrumContainer) && (m_LoRaDemod != NULL))
m_LoRaDemod->setSpectrum(m_threadedSampleSink->getMessageQueue(), rollDown);
*/
}
void LoRaDemodGUI::onMenuDoubleClicked()
{
if(!m_basicSettingsShown) {
m_basicSettingsShown = true;
BasicChannelSettingsWidget* bcsw = new BasicChannelSettingsWidget(&m_channelMarker, this);
2015-01-10 19:12:58 -05:00
bcsw->show();
}
}
LoRaDemodGUI::LoRaDemodGUI(PluginAPI* pluginAPI, DeviceSourceAPI *deviceAPI, QWidget* parent) :
2015-01-10 19:12:58 -05:00
RollupWidget(parent),
ui(new Ui::LoRaDemodGUI),
m_pluginAPI(pluginAPI),
m_deviceAPI(deviceAPI),
m_channelMarker(this),
m_basicSettingsShown(false),
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)));
connect(this, SIGNAL(menuDoubleClickEvent()), this, SLOT(onMenuDoubleClicked()));
m_spectrumVis = new SpectrumVis(ui->glSpectrum);
2017-10-07 19:42:18 -04:00
m_LoRaDemod = new LoRaDemod(m_deviceAPI);
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);
2017-10-07 19:42:18 -04:00
// setTitleColor(Qt::magenta);
//
// m_channelMarker.setColor(Qt::magenta);
// m_channelMarker.setBandwidth(LoRaDemodSettings::bandwidths[0]);
// m_channelMarker.setCenterFrequency(0);
m_channelMarker.setVisible(true);
connect(&m_channelMarker, SIGNAL(changed()), this, SLOT(viewChanged()));
m_deviceAPI->registerChannelInstance(m_channelID, this);
m_deviceAPI->addChannelMarker(&m_channelMarker);
m_deviceAPI->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_deviceAPI->removeChannelInstance(this);
2015-01-10 19:12:58 -05:00
delete m_LoRaDemod;
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
}