mirror of
https://github.com/Serial-Studio/Serial-Studio.git
synced 2025-01-31 17:42:55 +08:00
Implement enhancement on issue #12
This commit is contained in:
parent
97f4fb6cdf
commit
6b5cef43d4
@ -51,7 +51,9 @@ Control {
|
||||
property alias dmStopBits: stopBits.currentIndex
|
||||
property alias dmDataBits: dataBits.currentIndex
|
||||
property alias dmOpenMode: openMode.currentIndex
|
||||
property alias dmBaudRateIndex: baudRate.currentIndex
|
||||
property alias dmBaudIndex: baudRate.currentIndex
|
||||
property alias dmCustomBrEnabled: customBr.checked
|
||||
property alias dmCustomBaudRate: customBaudRateValue.value
|
||||
property alias dmFlowControl: flowControl.currentIndex
|
||||
property alias appLanguage: languageCombo.currentIndex
|
||||
property alias dmDisplayMode: displayMode.currentIndex
|
||||
@ -178,15 +180,24 @@ Control {
|
||||
//
|
||||
Label {
|
||||
text: qsTr("Baud Rate") + ":" + CppTranslator.dummy
|
||||
|
||||
enabled: !customBr.checked
|
||||
opacity: enabled ? 1 : 0.5
|
||||
Behavior on opacity {NumberAnimation{}}
|
||||
|
||||
} ComboBox {
|
||||
id: baudRate
|
||||
Layout.fillWidth: true
|
||||
model: CppSerialManager.baudRateList
|
||||
currentIndex: CppSerialManager.baudRateIndex
|
||||
onCurrentIndexChanged: {
|
||||
if (CppSerialManager.baudRateIndex !== currentIndex)
|
||||
if (CppSerialManager.baudRateIndex !== currentIndex && enabled)
|
||||
CppSerialManager.baudRateIndex = currentIndex
|
||||
}
|
||||
|
||||
enabled: !customBr.checked
|
||||
opacity: enabled ? 1 : 0.5
|
||||
Behavior on opacity {NumberAnimation{}}
|
||||
}
|
||||
|
||||
//
|
||||
@ -222,6 +233,32 @@ Control {
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Custom baud rate
|
||||
//
|
||||
CheckBox {
|
||||
id: customBr
|
||||
Layout.leftMargin: -app.spacing
|
||||
text: qsTr("Custom baud rate") + CppTranslator.dummy
|
||||
} SpinBox {
|
||||
id: customBaudRateValue
|
||||
|
||||
from: 1
|
||||
stepSize: 1
|
||||
to: 10000000
|
||||
value: 9600
|
||||
editable: true
|
||||
Layout.fillWidth: true
|
||||
enabled: customBr.checked
|
||||
opacity: enabled ? 1 : 0.5
|
||||
Behavior on opacity {NumberAnimation{}}
|
||||
|
||||
onValueChanged: {
|
||||
if (enabled)
|
||||
CppSerialManager.setBaudRate(value)
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Spacer
|
||||
//
|
||||
|
@ -184,7 +184,7 @@ SerialManager::SerialManager()
|
||||
setDataBits(dataBitsList().indexOf("8"));
|
||||
setStopBits(stopBitsList().indexOf("1"));
|
||||
setParity(parityList().indexOf(tr("None")));
|
||||
setBaudRate(baudRateList().indexOf("9600"));
|
||||
setBaudRateIndex(baudRateList().indexOf("9600"));
|
||||
setFlowControl(flowControlList().indexOf(tr("None")));
|
||||
disconnectDevice();
|
||||
|
||||
@ -466,10 +466,14 @@ QStringList SerialManager::parityList() const
|
||||
QStringList SerialManager::baudRateList() const
|
||||
{
|
||||
QStringList list;
|
||||
auto stdBaudRates = QSerialPortInfo::standardBaudRates();
|
||||
foreach (auto baud, stdBaudRates)
|
||||
list.append(QString::number(baud));
|
||||
|
||||
list.append("1200");
|
||||
list.append("2400");
|
||||
list.append("4800");
|
||||
list.append("9600");
|
||||
list.append("19200");
|
||||
list.append("38400");
|
||||
list.append("57600");
|
||||
list.append("115200");
|
||||
return list;
|
||||
}
|
||||
|
||||
@ -664,6 +668,28 @@ void SerialManager::sendData(const QString &data)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the baud @a rate of the serial port
|
||||
*/
|
||||
void SerialManager::setBaudRate(const qint32 rate)
|
||||
{
|
||||
// Asserts
|
||||
Q_ASSERT(rate > 10);
|
||||
|
||||
// Update baud rate
|
||||
m_baudRate = rate;
|
||||
|
||||
// Update serial port config
|
||||
if (port())
|
||||
port()->setBaudRate(baudRate());
|
||||
|
||||
// Update user interface
|
||||
emit baudRateChanged();
|
||||
|
||||
// Log information
|
||||
LOG_INFO() << "Baud rate set to" << rate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the current serial port and tries to open & configure a new serial
|
||||
* port connection with the device at the given @a port index.
|
||||
@ -820,24 +846,17 @@ void SerialManager::setParity(const quint8 parityIndex)
|
||||
* @note This function is meant to be used with a combobox in the
|
||||
* QML interface
|
||||
*/
|
||||
void SerialManager::setBaudRate(const quint8 baudRateIndex)
|
||||
void SerialManager::setBaudRateIndex(const quint8 index)
|
||||
{
|
||||
// Argument verifications
|
||||
Q_ASSERT(baudRateIndex < baudRateList().count());
|
||||
if (index < baudRateList().count())
|
||||
{
|
||||
m_baudRateIndex = index;
|
||||
setBaudRate(baudRateList().at(index).toInt());
|
||||
emit baudRateIndexChanged();
|
||||
}
|
||||
|
||||
// Update current index
|
||||
m_baudRateIndex = baudRateIndex;
|
||||
m_baudRate = QSerialPortInfo::standardBaudRates().at(baudRateIndex);
|
||||
|
||||
// Update serial port config
|
||||
if (port())
|
||||
port()->setBaudRate(baudRate());
|
||||
|
||||
// Update user interface
|
||||
emit baudRateChanged();
|
||||
|
||||
// Log changes
|
||||
LOG_INFO() << "Baud rate set to" << baudRate();
|
||||
else
|
||||
setBaudRateIndex(baudRateList().indexOf("9600"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -88,8 +88,8 @@ class SerialManager : public QObject
|
||||
NOTIFY displayModeChanged)
|
||||
Q_PROPERTY(quint8 baudRateIndex
|
||||
READ baudRateIndex
|
||||
WRITE setBaudRate
|
||||
NOTIFY baudRateChanged)
|
||||
WRITE setBaudRateIndex
|
||||
NOTIFY baudRateIndexChanged)
|
||||
Q_PROPERTY(quint8 dataBitsIndex
|
||||
READ dataBitsIndex
|
||||
WRITE setDataBits
|
||||
@ -102,6 +102,10 @@ class SerialManager : public QObject
|
||||
READ flowControlIndex
|
||||
WRITE setFlowControl
|
||||
NOTIFY flowControlChanged)
|
||||
Q_PROPERTY(qint32 baudRate
|
||||
READ baudRate
|
||||
WRITE setBaudRate
|
||||
NOTIFY baudRateChanged)
|
||||
Q_PROPERTY(QStringList portList
|
||||
READ portList
|
||||
NOTIFY availablePortsChanged)
|
||||
@ -137,6 +141,7 @@ signals:
|
||||
void flowControlChanged();
|
||||
void writeEnabledChanged();
|
||||
void textDocumentChanged();
|
||||
void baudRateIndexChanged();
|
||||
void maxBufferSizeChanged();
|
||||
void startSequenceChanged();
|
||||
void receivedBytesChanged();
|
||||
@ -192,11 +197,12 @@ public slots:
|
||||
void clearTempBuffer();
|
||||
void disconnectDevice();
|
||||
void sendData(const QString &data);
|
||||
void setBaudRate(const qint32 rate);
|
||||
void setPort(const quint8 portIndex);
|
||||
void setSendHexData(const bool &sendHex);
|
||||
void setWriteEnabled(const bool enabled);
|
||||
void setParity(const quint8 parityIndex);
|
||||
void setBaudRate(const quint8 baudRateIndex);
|
||||
void setBaudRateIndex(const quint8 index);
|
||||
void setDataBits(const quint8 dataBitsIndex);
|
||||
void setStopBits(const quint8 stopBitsIndex);
|
||||
void setDisplayMode(const quint8 displayMode);
|
||||
|
Loading…
x
Reference in New Issue
Block a user