Commit e388f8be authored by Susurrus's avatar Susurrus

Merge pull request #1213 from mavlink/comm_fix

Fix setting the baud rate.
parents d6c39c38 5730af5c
......@@ -770,17 +770,8 @@ bool SerialLink::setBaudRateType(int rateIndex)
return result;
}
bool SerialLink::setBaudRateString(const QString& rate)
{
bool ok;
int intrate = rate.toInt(&ok);
if (!ok) return false;
return setBaudRate(intrate);
}
bool SerialLink::setBaudRate(int rate)
{
bool accepted = false;
if (rate != m_baud) {
m_baud = rate;
......@@ -839,37 +830,6 @@ bool SerialLink::setParityType(int parity)
return accepted;
}
bool SerialLink::setDataBits(int dataBits)
{
qDebug("SET DATA BITS");
bool accepted = false;
if (dataBits != m_dataBits) {
m_dataBits = static_cast<QSerialPort::DataBits>(dataBits);
accepted = true;
if (m_port && !m_is_cdc)
accepted = m_port->setDataBits(static_cast<QSerialPort::DataBits>(dataBits));
emit updateLink(this);
}
return accepted;
}
bool SerialLink::setStopBits(int stopBits)
{
// Note 3 is OneAndAHalf stopbits.
bool accepted = false;
if (stopBits != m_stopBits) {
m_stopBits = static_cast<QSerialPort::StopBits>(stopBits);
accepted = true;
if (m_port && !m_is_cdc)
accepted = m_port->setStopBits(static_cast<QSerialPort::StopBits>(stopBits));
emit updateLink(this);
}
return accepted;
}
bool SerialLink::setDataBitsType(int dataBits)
{
......
......@@ -123,11 +123,6 @@ signals: //[TODO] Refactor to Linkinterface
public slots:
bool setPortName(QString portName);
bool setBaudRate(int rate);
bool setDataBits(int dataBits);
bool setStopBits(int stopBits);
// Set string rate
bool setBaudRateString(const QString& rate);
// Set ENUM values
bool setBaudRateType(int rateIndex);
......
......@@ -29,13 +29,14 @@ This file is part of the QGROUNDCONTROL project
*/
#include <QDebug>
#include <SerialConfigurationWindow.h>
#include <SerialLinkInterface.h>
#include <QDir>
#include <QSettings>
#include <QFileInfoList>
#include "SerialConfigurationWindow.h"
#include "SerialLinkInterface.h"
#include "SerialLink.h"
SerialConfigurationWindow::SerialConfigurationWindow(LinkInterface* link, QWidget *parent, Qt::WindowFlags flags) : QWidget(parent, flags),
userConfigured(false)
{
......@@ -125,13 +126,13 @@ SerialConfigurationWindow::SerialConfigurationWindow(LinkInterface* link, QWidge
// Connect the individual user interface inputs
connect(ui.portName, SIGNAL(editTextChanged(QString)), this, SLOT(setPortName(QString)));
connect(ui.portName, SIGNAL(currentIndexChanged(QString)), this, SLOT(setPortName(QString)));
connect(ui.baudRate, SIGNAL(activated(QString)), this->link, SLOT(setBaudRateString(QString)));
connect(ui.baudRate, static_cast<void (QComboBox::*)(const QString&)>(&QComboBox::activated), this, &SerialConfigurationWindow::setBaudRate);
connect(ui.flowControlCheckBox, SIGNAL(toggled(bool)), this, SLOT(enableFlowControl(bool)));
connect(ui.parNone, SIGNAL(toggled(bool)), this, SLOT(setParityNone(bool)));
connect(ui.parOdd, SIGNAL(toggled(bool)), this, SLOT(setParityOdd(bool)));
connect(ui.parEven, SIGNAL(toggled(bool)), this, SLOT(setParityEven(bool)));
connect(ui.dataBitsSpinBox, SIGNAL(valueChanged(int)), this->link, SLOT(setDataBits(int)));
connect(ui.stopBitsSpinBox, SIGNAL(valueChanged(int)), this->link, SLOT(setStopBits(int)));
connect(ui.dataBitsSpinBox, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, &SerialConfigurationWindow::setDataBits);
connect(ui.stopBitsSpinBox, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, &SerialConfigurationWindow::setStopBits);
connect(ui.advCheckBox, SIGNAL(clicked(bool)), ui.advGroupBox, SLOT(setVisible(bool)));
ui.advCheckBox->setCheckable(true);
ui.advCheckBox->setChecked(false);
......@@ -284,6 +285,28 @@ void SerialConfigurationWindow::setPortName(QString port)
userConfigured = true;
}
void SerialConfigurationWindow::setBaudRate(QString rate)
{
bool ok;
int intrate = rate.toInt(&ok);
if (ok) {
link->setBaudRate(intrate);
}
userConfigured = true;
}
void SerialConfigurationWindow::setDataBits(int dataBits)
{
link->setDataBitsType(static_cast<QSerialPort::DataBits>(dataBits));
userConfigured = true;
}
void SerialConfigurationWindow::setStopBits(int stopBits)
{
link->setStopBitsType(static_cast<QSerialPort::DataBits>(stopBits));
userConfigured = true;
}
void SerialConfigurationWindow::setLinkName(QString name)
{
Q_UNUSED(name);
......
......@@ -59,6 +59,10 @@ public slots:
void setParityOdd(bool accept);
void setParityEven(bool accept);
void setPortName(QString port);
void setBaudRate(QString rate);
void setDataBits(int dataBits);
void setStopBits(int stopBits);
void setLinkName(QString name);
/**
* @brief setupPortList Populates the dropdown with the list of available serial ports.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment