Commit af9f2479 authored by lm's avatar lm

Fixed line end handling in communication console, allowed to use enter for sending

parent 04ecfa68
......@@ -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/.
......
......@@ -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; i<size; i++)
{
unsigned char v =data[i];
qDebug("%02x ", v);
}
qDebug("\n");
// int i;
// for (i=0; i<size; i++)
// {
// unsigned char v =data[i];
// qDebug("%02x ", v);
// }
// qDebug("\n");
}
else
{
......
......@@ -115,6 +115,8 @@ DebugConsole::DebugConsole(QWidget *parent) :
connect(m_ui->specialComboBox, 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("<font color=\"%1\">(MAV%2:%3) %4</font>").arg(UASManager::instance()->getUASForId(id)->getColor().name(), QString::number(id), QString::number(component), text));
m_ui->receiveText->appendHtml(QString("<font color=\"%1\">(MAV%2:%3) %4</font>\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("<font color=\"%1\">%2</font>").arg(QGC::colorGreen.name(), tr("Link %1 is connected.").arg(currLink->getName())));
m_ui->receiveText->appendHtml(QString("<font color=\"%1\">%2</font>\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("<font color=\"%1\">%2</font>").arg(QGC::colorYellow.name(), tr("Link %1 is unconnected.").arg(currLink->getName())));
m_ui->receiveText->appendHtml(QString("<font color=\"%1\">%2</font>\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);
......
......@@ -36,6 +36,7 @@ This file is part of the QGROUNDCONTROL project
#include <QList>
#include <QByteArray>
#include <QTimer>
#include <QKeyEvent>
#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<LinkInterface*> links;
QStringList commandHistory;
QString currCommand;
int commandIndex;
LinkInterface* currLink;
bool holdOn; ///< Hold current view, ignore new data
......
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