Skip to content

Commit

Permalink
Backup/restore legacy waveform when enabling/disabling txUart
Browse files Browse the repository at this point in the history
  • Loading branch information
mmehari committed Mar 26, 2024
1 parent abd97d4 commit 752b488
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
23 changes: 22 additions & 1 deletion Desktop_Interface/functiongencontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down
7 changes: 6 additions & 1 deletion Desktop_Interface/functiongencontrol.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand All @@ -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;
Expand All @@ -63,6 +66,8 @@ class DualChannelController : public QLabel
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);
Expand Down
10 changes: 9 additions & 1 deletion Desktop_Interface/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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()
Expand Down

0 comments on commit 752b488

Please sign in to comment.