From af9f247903209174caf593451dfe93b99e0f5369 Mon Sep 17 00:00:00 2001 From: lm Date: Wed, 26 Jan 2011 10:08:28 +0100 Subject: [PATCH] Fixed line end handling in communication console, allowed to use enter for sending --- qgroundcontrol.pri | 3 ++ src/comm/SerialLink.cc | 16 +++---- src/ui/DebugConsole.cc | 96 ++++++++++++++++++++++++++++++++++++------ src/ui/DebugConsole.h | 8 ++++ 4 files changed, 102 insertions(+), 21 deletions(-) diff --git a/qgroundcontrol.pri b/qgroundcontrol.pri index f846c60db..2657c46cd 100644 --- a/qgroundcontrol.pri +++ b/qgroundcontrol.pri @@ -38,6 +38,9 @@ release { QMAKE_POST_LINK += echo "Copying files" +# Turn off serial port warnings +DEFINES += _TTY_NOWARN_ + #QMAKE_POST_LINK += && cp -rf $$BASEDIR/models $$TARGETDIR/debug/. #QMAKE_POST_LINK += && cp -rf $$BASEDIR/models $$TARGETDIR/release/. diff --git a/src/comm/SerialLink.cc b/src/comm/SerialLink.cc index 80600efa6..0420dbaae 100644 --- a/src/comm/SerialLink.cc +++ b/src/comm/SerialLink.cc @@ -179,18 +179,18 @@ void SerialLink::writeBytes(const char* data, qint64 size) if (b > 0) { - qDebug() << "Serial link " << this->getName() << "transmitted" << b << "bytes:"; +// qDebug() << "Serial link " << this->getName() << "transmitted" << b << "bytes:"; // Increase write counter bitsSentTotal += size * 8; - int i; - for (i=0; ispecialComboBox, SIGNAL(highlighted(QString)), this, SLOT(specialSymbolSelected(QString))); // Set add button invisible if auto add checkbox is checked connect(m_ui->specialCheckBox, SIGNAL(clicked(bool)), m_ui->addSymbolButton, SLOT(setHidden(bool))); + // Allow to send via return + connect(m_ui->sendText, SIGNAL(returnPressed()), this, SLOT(sendBytes())); hold(false); @@ -205,7 +207,8 @@ void DebugConsole::setAutoHold(bool hold) void DebugConsole::receiveTextMessage(int id, int component, int severity, QString text) { Q_UNUSED(severity); - m_ui->receiveText->appendHtml(QString("(MAV%2:%3) %4").arg(UASManager::instance()->getUASForId(id)->getColor().name(), QString::number(id), QString::number(component), text)); + m_ui->receiveText->appendHtml(QString("(MAV%2:%3) %4\n").arg(UASManager::instance()->getUASForId(id)->getColor().name(), QString::number(id), QString::number(component), text)); + //m_ui->receiveText->appendPlainText(""); } void DebugConsole::updateTrafficMeasurements() @@ -293,14 +296,13 @@ void DebugConsole::receiveBytes(LinkInterface* link, QByteArray bytes) { switch (byte) { - // Catch line feed -// case (unsigned char)'\n': -// m_ui->receiveText->appendPlainText(str); -// str = ""; -// break; - // Catch carriage return and line feed - case (unsigned char)0xD: - case (unsigned char)0xA: + // Accept line feed and tab + case (unsigned char)'\n': + case (unsigned char)'\t': + str.append(byte); + break; + // Catch and ignore carriage return + case (unsigned char)'\r': // Ignore break; default: @@ -330,8 +332,14 @@ void DebugConsole::receiveBytes(LinkInterface* link, QByteArray bytes) } } - if (lineBuffer.length() > 0) m_ui->receiveText->appendPlainText(lineBuffer); - lineBuffer.clear(); + if (lineBuffer.length() > 0) + { + m_ui->receiveText->insertPlainText(lineBuffer); + // Ensure text area scrolls correctly + m_ui->receiveText->ensureCursorVisible(); + lineBuffer.clear(); + } + } else if (link == currLink && holdOn) @@ -595,6 +603,7 @@ void DebugConsole::hexModeEnabled(bool mode) m_ui->receiveText->clear(); m_ui->sendText->clear(); m_ui->sentText->clear(); + commandHistory.clear(); } /** @@ -640,12 +649,12 @@ void DebugConsole::setConnectionState(bool connected) if(connected) { m_ui->connectButton->setText(tr("Disconn.")); - m_ui->receiveText->appendHtml(QString("%2").arg(QGC::colorGreen.name(), tr("Link %1 is connected.").arg(currLink->getName()))); + m_ui->receiveText->appendHtml(QString("%2\n").arg(QGC::colorGreen.name(), tr("Link %1 is connected.").arg(currLink->getName()))); } else { m_ui->connectButton->setText(tr("Connect")); - m_ui->receiveText->appendHtml(QString("%2").arg(QGC::colorYellow.name(), tr("Link %1 is unconnected.").arg(currLink->getName()))); + m_ui->receiveText->appendHtml(QString("%2\n").arg(QGC::colorYellow.name(), tr("Link %1 is unconnected.").arg(currLink->getName()))); } } @@ -665,6 +674,67 @@ void DebugConsole::handleConnectButton() } } +void DebugConsole::keyPressEvent(QKeyEvent * event) +{ + if (event->key() == Qt::Key_Up) + { + qDebug() << "UP KEY PRESSED"; + cycleCommandHistory(true); + } + else if (event->key() == Qt::Key_Down) + { + qDebug() << "DOWN KEY PRESSED"; + cycleCommandHistory(false); + } + else if (event->key() == Qt::Key_Enter) + { + this->sendBytes(); + } + else + { + QWidget::keyPressEvent(event); + } +} + +void DebugConsole::cycleCommandHistory(bool up) +{ + // Store current command if we're not in history yet + if (commandIndex == commandHistory.length()) + { + currCommand = m_ui->sendText->text(); + } + + if (up) + { + // UP + commandIndex--; + if (commandIndex >= 0) + { + m_ui->sendText->setText(commandHistory.at(commandIndex)); + } + + // If the index + } + else + { + // DOWN + commandIndex++; + if (commandIndex < commandHistory.length()) + { + m_ui->sendText->setText(commandHistory.at(commandIndex)); + } + // If the index is at history length, load the last current command + + } + + // If we are too far down or too far up, wrap around to current command + if (commandIndex < 0 || commandIndex > commandHistory.length()) + { + commandIndex = commandHistory.length(); + m_ui->sendText->setText(currCommand); + } +} + void DebugConsole::changeEvent(QEvent *e) { QWidget::changeEvent(e); diff --git a/src/ui/DebugConsole.h b/src/ui/DebugConsole.h index cfc4ad91e..dc6ef02b9 100644 --- a/src/ui/DebugConsole.h +++ b/src/ui/DebugConsole.h @@ -36,6 +36,7 @@ This file is part of the QGROUNDCONTROL project #include #include #include +#include #include "LinkInterface.h" @@ -102,8 +103,15 @@ protected: QByteArray symbolNameToBytes(const QString& symbol); /** @brief Convert a symbol byte to the name */ QString bytesToSymbolNames(const QByteArray& b); + /** @brief Handle keypress events */ + void keyPressEvent(QKeyEvent * event); + /** @brief Cycle through the command history */ + void cycleCommandHistory(bool up); QList links; + QStringList commandHistory; + QString currCommand; + int commandIndex; LinkInterface* currLink; bool holdOn; ///< Hold current view, ignore new data -- 2.22.0