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 dmStopBits: stopBits.currentIndex
|
||||||
property alias dmDataBits: dataBits.currentIndex
|
property alias dmDataBits: dataBits.currentIndex
|
||||||
property alias dmOpenMode: openMode.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 dmFlowControl: flowControl.currentIndex
|
||||||
property alias appLanguage: languageCombo.currentIndex
|
property alias appLanguage: languageCombo.currentIndex
|
||||||
property alias dmDisplayMode: displayMode.currentIndex
|
property alias dmDisplayMode: displayMode.currentIndex
|
||||||
@ -178,15 +180,24 @@ Control {
|
|||||||
//
|
//
|
||||||
Label {
|
Label {
|
||||||
text: qsTr("Baud Rate") + ":" + CppTranslator.dummy
|
text: qsTr("Baud Rate") + ":" + CppTranslator.dummy
|
||||||
|
|
||||||
|
enabled: !customBr.checked
|
||||||
|
opacity: enabled ? 1 : 0.5
|
||||||
|
Behavior on opacity {NumberAnimation{}}
|
||||||
|
|
||||||
} ComboBox {
|
} ComboBox {
|
||||||
id: baudRate
|
id: baudRate
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
model: CppSerialManager.baudRateList
|
model: CppSerialManager.baudRateList
|
||||||
currentIndex: CppSerialManager.baudRateIndex
|
currentIndex: CppSerialManager.baudRateIndex
|
||||||
onCurrentIndexChanged: {
|
onCurrentIndexChanged: {
|
||||||
if (CppSerialManager.baudRateIndex !== currentIndex)
|
if (CppSerialManager.baudRateIndex !== currentIndex && enabled)
|
||||||
CppSerialManager.baudRateIndex = currentIndex
|
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
|
// Spacer
|
||||||
//
|
//
|
||||||
|
@ -184,7 +184,7 @@ SerialManager::SerialManager()
|
|||||||
setDataBits(dataBitsList().indexOf("8"));
|
setDataBits(dataBitsList().indexOf("8"));
|
||||||
setStopBits(stopBitsList().indexOf("1"));
|
setStopBits(stopBitsList().indexOf("1"));
|
||||||
setParity(parityList().indexOf(tr("None")));
|
setParity(parityList().indexOf(tr("None")));
|
||||||
setBaudRate(baudRateList().indexOf("9600"));
|
setBaudRateIndex(baudRateList().indexOf("9600"));
|
||||||
setFlowControl(flowControlList().indexOf(tr("None")));
|
setFlowControl(flowControlList().indexOf(tr("None")));
|
||||||
disconnectDevice();
|
disconnectDevice();
|
||||||
|
|
||||||
@ -466,10 +466,14 @@ QStringList SerialManager::parityList() const
|
|||||||
QStringList SerialManager::baudRateList() const
|
QStringList SerialManager::baudRateList() const
|
||||||
{
|
{
|
||||||
QStringList list;
|
QStringList list;
|
||||||
auto stdBaudRates = QSerialPortInfo::standardBaudRates();
|
list.append("1200");
|
||||||
foreach (auto baud, stdBaudRates)
|
list.append("2400");
|
||||||
list.append(QString::number(baud));
|
list.append("4800");
|
||||||
|
list.append("9600");
|
||||||
|
list.append("19200");
|
||||||
|
list.append("38400");
|
||||||
|
list.append("57600");
|
||||||
|
list.append("115200");
|
||||||
return list;
|
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
|
* Closes the current serial port and tries to open & configure a new serial
|
||||||
* port connection with the device at the given @a port index.
|
* 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
|
* @note This function is meant to be used with a combobox in the
|
||||||
* QML interface
|
* QML interface
|
||||||
*/
|
*/
|
||||||
void SerialManager::setBaudRate(const quint8 baudRateIndex)
|
void SerialManager::setBaudRateIndex(const quint8 index)
|
||||||
{
|
{
|
||||||
// Argument verifications
|
if (index < baudRateList().count())
|
||||||
Q_ASSERT(baudRateIndex < baudRateList().count());
|
{
|
||||||
|
m_baudRateIndex = index;
|
||||||
|
setBaudRate(baudRateList().at(index).toInt());
|
||||||
|
emit baudRateIndexChanged();
|
||||||
|
}
|
||||||
|
|
||||||
// Update current index
|
else
|
||||||
m_baudRateIndex = baudRateIndex;
|
setBaudRateIndex(baudRateList().indexOf("9600"));
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -88,8 +88,8 @@ class SerialManager : public QObject
|
|||||||
NOTIFY displayModeChanged)
|
NOTIFY displayModeChanged)
|
||||||
Q_PROPERTY(quint8 baudRateIndex
|
Q_PROPERTY(quint8 baudRateIndex
|
||||||
READ baudRateIndex
|
READ baudRateIndex
|
||||||
WRITE setBaudRate
|
WRITE setBaudRateIndex
|
||||||
NOTIFY baudRateChanged)
|
NOTIFY baudRateIndexChanged)
|
||||||
Q_PROPERTY(quint8 dataBitsIndex
|
Q_PROPERTY(quint8 dataBitsIndex
|
||||||
READ dataBitsIndex
|
READ dataBitsIndex
|
||||||
WRITE setDataBits
|
WRITE setDataBits
|
||||||
@ -102,6 +102,10 @@ class SerialManager : public QObject
|
|||||||
READ flowControlIndex
|
READ flowControlIndex
|
||||||
WRITE setFlowControl
|
WRITE setFlowControl
|
||||||
NOTIFY flowControlChanged)
|
NOTIFY flowControlChanged)
|
||||||
|
Q_PROPERTY(qint32 baudRate
|
||||||
|
READ baudRate
|
||||||
|
WRITE setBaudRate
|
||||||
|
NOTIFY baudRateChanged)
|
||||||
Q_PROPERTY(QStringList portList
|
Q_PROPERTY(QStringList portList
|
||||||
READ portList
|
READ portList
|
||||||
NOTIFY availablePortsChanged)
|
NOTIFY availablePortsChanged)
|
||||||
@ -137,6 +141,7 @@ signals:
|
|||||||
void flowControlChanged();
|
void flowControlChanged();
|
||||||
void writeEnabledChanged();
|
void writeEnabledChanged();
|
||||||
void textDocumentChanged();
|
void textDocumentChanged();
|
||||||
|
void baudRateIndexChanged();
|
||||||
void maxBufferSizeChanged();
|
void maxBufferSizeChanged();
|
||||||
void startSequenceChanged();
|
void startSequenceChanged();
|
||||||
void receivedBytesChanged();
|
void receivedBytesChanged();
|
||||||
@ -192,11 +197,12 @@ public slots:
|
|||||||
void clearTempBuffer();
|
void clearTempBuffer();
|
||||||
void disconnectDevice();
|
void disconnectDevice();
|
||||||
void sendData(const QString &data);
|
void sendData(const QString &data);
|
||||||
|
void setBaudRate(const qint32 rate);
|
||||||
void setPort(const quint8 portIndex);
|
void setPort(const quint8 portIndex);
|
||||||
void setSendHexData(const bool &sendHex);
|
void setSendHexData(const bool &sendHex);
|
||||||
void setWriteEnabled(const bool enabled);
|
void setWriteEnabled(const bool enabled);
|
||||||
void setParity(const quint8 parityIndex);
|
void setParity(const quint8 parityIndex);
|
||||||
void setBaudRate(const quint8 baudRateIndex);
|
void setBaudRateIndex(const quint8 index);
|
||||||
void setDataBits(const quint8 dataBitsIndex);
|
void setDataBits(const quint8 dataBitsIndex);
|
||||||
void setStopBits(const quint8 stopBitsIndex);
|
void setStopBits(const quint8 stopBitsIndex);
|
||||||
void setDisplayMode(const quint8 displayMode);
|
void setDisplayMode(const quint8 displayMode);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user