Backup/restore legacy waveform when enabling/disabling txUart

This commit is contained in:
mmehari 2024-03-26 06:34:19 +01:00
parent abd97d4b27
commit 752b488caf
3 changed files with 37 additions and 3 deletions

View File

@ -10,6 +10,7 @@ ChannelData const& SingleChannelController::getData() const {
void SingleChannelController::waveformName(QString newName)
{
qDebug() << "newName = " << newName;
m_data.waveform = newName;
newName.append(".tlw");
int length;
@ -139,12 +140,22 @@ void SingleChannelController::txuartUpdate(int baudRate, std::vector<uint8_t> sa
m_data.samples.resize(length);
m_data.samples = samples;
m_data.freq = baudRate/length;
m_data.divisibility = 1;
m_data.repeat_forever = false;
notifyUpdate(this);
}
void SingleChannelController::backup_waveform()
{
m_data.freq2 = m_data.freq;
}
void SingleChannelController::restore_waveform()
{
m_data.freq = m_data.freq2;
waveformName(m_data.waveform);
}
DualChannelController::DualChannelController(QWidget *parent) : QLabel(parent)
{
@ -208,6 +219,16 @@ void DualChannelController::txuartUpdate(ChannelID channelID, int baudRate, std:
getChannelController(channelID)->txuartUpdate(baudRate, samples);
}
void DualChannelController::backup_waveform(ChannelID channelID)
{
getChannelController(channelID)->backup_waveform();
}
void DualChannelController::restore_waveform(ChannelID channelID)
{
getChannelController(channelID)->restore_waveform();
}
void DualChannelController::waveformName_CH1(QString newName)
{

View File

@ -24,9 +24,10 @@ enum class ChannelID
struct ChannelData
{
std::vector<uint8_t> samples;
QString waveform;
bool repeat_forever;
int divisibility;
double freq = 1000.0;
double freq = 1000.0, freq2 = 1000.0;
double amplitude = 0.0;
double offset = 0.0;
};
@ -49,6 +50,8 @@ public slots:
void amplitudeUpdate(double newAmplitude);
void offsetUpdate(double newOffset);
void txuartUpdate(int baudRate, std::vector<uint8_t> samples);
void backup_waveform();
void restore_waveform();
private:
ChannelData m_data;
@ -63,6 +66,8 @@ public:
public:
SingleChannelController* getChannelController(ChannelID channelID);
void txuartUpdate(ChannelID channelID, int baudRate, std::vector<uint8_t> samples);
void backup_waveform(ChannelID channelID);
void restore_waveform(ChannelID channelID);
signals:
void functionGenToUpdate(ChannelID channel, SingleChannelController* fGenControl);

View File

@ -2639,8 +2639,12 @@ void MainWindow::on_serialEncodingCheck_CH1_toggled(bool checked)
std::vector<uint8_t> data;
// If uart encoding is enabled
using functionGen::ChannelID;
if(checked)
{
// Backup waveform on CH1
ui->controller_fg->backup_waveform(ChannelID::CH1);
// Enable uart decoding
ui->serialDecodingCheck_CH1->setChecked(true);
@ -2653,9 +2657,13 @@ void MainWindow::on_serialEncodingCheck_CH1_toggled(bool checked)
data = uartEncode("\r\n", parity_CH1);
// Transmit txuart data
using functionGen::ChannelID;
ui->controller_fg->txuartUpdate(ChannelID::CH1, baudRate_CH1, data);
}
else
{
// Restore waveform on CH1
ui->controller_fg->restore_waveform(ChannelID::CH1);
}
}
void MainWindow::on_txuart_textChanged()