Subversion Repositories Code-Repo

Rev

Rev 364 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 364 Rev 372
Line 3... Line 3...
3
IOWidget::IOWidget(QWidget *parent) : QWidget(parent)
3
IOWidget::IOWidget(QWidget *parent) : QWidget(parent)
4
{
4
{
5
    // Serial data UI
5
    // Serial data UI
6
    textData = new QTextEdit();
6
    textData = new QTextEdit();
7
    textData->setCurrentFont(QFont("Consolas", 8));
7
    textData->setCurrentFont(QFont("Consolas", 8));
8
    textData->append("Waiting for serial connection...");
8
    textData->append("Waiting for serial connection... ");
9
    textData->setMinimumSize(400, 100);
9
    textData->setMinimumSize(400, 100);
10
    textData->setReadOnly(true);
10
    textData->setReadOnly(true);
11
    textTransmit = new QLineEdit();
11
    textTransmit = new QLineEdit();
12
    textTransmit->setEnabled(false);
12
    textTransmit->setEnabled(false);
13
    textTransmit->setFont(QFont("Consolas", 8));
13
    textTransmit->setFont(QFont("Consolas", 8));
Line 26... Line 26...
26
 
26
 
27
    connect(btnTransmit, SIGNAL(clicked()), this, SLOT(PreprocessTransmit()));
27
    connect(btnTransmit, SIGNAL(clicked()), this, SLOT(PreprocessTransmit()));
28
    connect(textTransmit, SIGNAL(returnPressed()), btnTransmit, SIGNAL(clicked()));
28
    connect(textTransmit, SIGNAL(returnPressed()), btnTransmit, SIGNAL(clicked()));
29
    connect(btnClear, SIGNAL(clicked()), this, SLOT(ClearBtn()));
29
    connect(btnClear, SIGNAL(clicked()), this, SLOT(ClearBtn()));
30
 
30
 
31
    EnableTransmit(false);
31
//    EnableTransmit(false);
-
 
32
    textTransmit->setEnabled(false);
-
 
33
    btnTransmit->setEnabled(false);
32
    lastTransmit = true;
34
    lastTransmit = true;
33
}
35
}
34
 
36
 
35
IOWidget::~IOWidget()
37
IOWidget::~IOWidget()
36
{
38
{
Line 45... Line 47...
45
        textTransmit->setText("");
47
        textTransmit->setText("");
46
    } else {
48
    } else {
47
        str = QString(data);
49
        str = QString(data);
48
    }
50
    }
49
 
51
 
50
    emit TransmitByteArray(str.toUtf8());
52
    QTime curTime = QTime::currentTime();
51
    textData->setTextColor(Qt::darkBlue);
-
 
52
 
-
 
53
    QStringList cmds = str.split('\n');
53
    QStringList cmds = str.split('\n', QString::SkipEmptyParts);
54
    for (int i = 0; i < cmds.size(); i++) {
54
    for (int i = 0; i < cmds.size(); i++) {
-
 
55
        emit TransmitByteArray((cmds[i] + '\n').toUtf8());
55
        textData->append("TX:  " + cmds[i]);
56
        textData->setTextColor(Qt::darkBlue);
-
 
57
        textData->append(curTime.toString("[HH:mm:ss:zzz]: ") + cmds[i]);
56
    }
58
    }
-
 
59
    textData->moveCursor(QTextCursor::End);
-
 
60
    textData->ensureCursorVisible();
57
 
61
 
58
    // Save a flag indicating last activity was a transmit
62
    // Save a flag indicating last activity was a transmit
59
    lastTransmit = true;
63
    lastTransmit = true;
60
}
64
}
61
 
65
 
62
void IOWidget::ProcessReceivedByte(QByteArray data)
66
void IOWidget::ProcessReceivedByte(QByteArray data)
63
{
67
{
64
    textData->setTextColor(Qt::darkRed);
68
    textData->setTextColor(Qt::darkRed);
-
 
69
    QTime curTime = QTime::currentTime();
-
 
70
    QString timeString = "\n" + curTime.toString("[HH:mm:ss:zzz]: ");
-
 
71
    if (data.endsWith('\n')) data.remove(data.size()-1, 1);
65
    data.replace("\n", "\nRX:  ");
72
    data.replace('\n', timeString);
66
    if (lastTransmit) {
73
    if (lastTransmit) {
67
        textData->insertPlainText("\nRX:  " + QString(data));
74
        textData->insertPlainText(timeString + QString(data));
68
    } else {
75
    } else {
69
        textData->insertPlainText(QString(data));
76
        textData->insertPlainText(QString(data));
70
    }
77
    }
71
    textData->moveCursor(QTextCursor::End);
78
    textData->moveCursor(QTextCursor::End);
-
 
79
    textData->ensureCursorVisible();
72
    lastTransmit = false;
80
    lastTransmit = false;
73
}
81
}
74
 
82
 
75
void IOWidget::ClearBtn()
83
void IOWidget::ClearBtn()
76
{
84
{
77
    textData->clear();
85
    textData->clear();
78
}
86
}
79
 
87
 
80
void IOWidget::EnableTransmit(bool enable)
88
void IOWidget::EnableTransmit(bool enable)
81
{
89
{
-
 
90
    textData->setTextColor(Qt::black);
82
    if (enable) {
91
    if (enable) {
83
        textTransmit->setEnabled(true);
92
        textTransmit->setEnabled(true);
84
        btnTransmit->setEnabled(true);
93
        btnTransmit->setEnabled(true);
-
 
94
        textData->insertPlainText("connected!");
85
    } else {
95
    } else {
86
        textTransmit->setEnabled(false);
96
        textTransmit->setEnabled(false);
87
        btnTransmit->setEnabled(false);
97
        btnTransmit->setEnabled(false);
-
 
98
        textData->append("Serial disconnected.");
-
 
99
        textData->append("Waiting for serial connection... ");
88
    }
100
    }
-
 
101
    textData->moveCursor(QTextCursor::End);
-
 
102
    textData->ensureCursorVisible();
89
}
103
}