Subversion Repositories Code-Repo

Rev

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

Rev 349 Rev 351
Line 5... Line 5...
5
{
5
{
6
    // Set central widget
6
    // Set central widget
7
    centralWidget = new QWidget();
7
    centralWidget = new QWidget();
8
    setCentralWidget(centralWidget);
8
    setCentralWidget(centralWidget);
9
 
9
 
10
    // Serial connection UI
-
 
11
    groupSerialInit = new QGroupBox("Initialization");
-
 
12
    btnSerialConnect = new QPushButton("&Connect");
-
 
13
    btnSerialRefresh = new QPushButton("&Refresh");
-
 
14
    labelSerialPort = new QLabel("Serial Port:");
-
 
15
    labelSerialSpeed = new QLabel("Baud Rate:");
-
 
16
    labelSerialDataBits = new QLabel("Data:");
-
 
17
    labelSerialStopBits = new QLabel("Stop:");
-
 
18
    labelSerialParity = new QLabel("Parity Bit:");
-
 
19
    labelSerialFlowControl = new QLabel("Flow Control:");
-
 
20
    cboxSerialPort = new QComboBox();
-
 
21
    cboxSerialPort->setMinimumWidth(80);
-
 
22
    cboxSerialSpeed = new QComboBox();
-
 
23
    cboxSerialSpeed->setEditable(true);
-
 
24
    cboxSerialSpeed->setValidator(new QIntValidator(0, 100000000, this));
-
 
25
    cboxSerialDataBits = new QComboBox();
-
 
26
    cboxSerialDataBits->setMaximumWidth(60);
-
 
27
    cboxSerialStopBits = new QComboBox();
-
 
28
    cboxSerialStopBits->setMaximumWidth(60);
-
 
29
    cboxSerialParity = new QComboBox();
-
 
30
    cboxSerialFlowControl = new QComboBox();
-
 
31
    cboxSerialFlowControl->setMinimumWidth(70);
-
 
32
 
-
 
33
    QGridLayout *serialSettingsLayout = new QGridLayout();
-
 
34
    serialSettingsLayout->addWidget(btnSerialConnect, 0, 0);
-
 
35
    serialSettingsLayout->addWidget(labelSerialPort, 0, 1);
-
 
36
    serialSettingsLayout->addWidget(cboxSerialPort, 0, 2);
-
 
37
    serialSettingsLayout->addWidget(labelSerialDataBits, 0, 3);
-
 
38
    serialSettingsLayout->addWidget(cboxSerialDataBits, 0, 4);
-
 
39
    serialSettingsLayout->addWidget(labelSerialParity, 0, 5);
-
 
40
    serialSettingsLayout->addWidget(cboxSerialParity, 0, 6);
-
 
41
 
-
 
42
    serialSettingsLayout->addWidget(btnSerialRefresh, 1, 0);
-
 
43
    serialSettingsLayout->addWidget(labelSerialSpeed, 1, 1);
-
 
44
    serialSettingsLayout->addWidget(cboxSerialSpeed, 1, 2);
-
 
45
    serialSettingsLayout->addWidget(labelSerialStopBits, 1, 3);
-
 
46
    serialSettingsLayout->addWidget(cboxSerialStopBits, 1, 4);
-
 
47
    serialSettingsLayout->addWidget(labelSerialFlowControl, 1, 5);
-
 
48
    serialSettingsLayout->addWidget(cboxSerialFlowControl, 1, 6);
-
 
49
 
-
 
50
    groupSerialInit->setLayout(serialSettingsLayout);
-
 
51
    groupSerialInit->setFixedSize(groupSerialInit->sizeHint());
-
 
52
 
-
 
53
    // Serial data UI
10
    // Serial data UI
54
    groupSerialData = new QGroupBox("Data");
11
    groupSerialData = new QGroupBox("Data");
55
    textSerialData = new QTextEdit();
12
    textSerialData = new QTextEdit();
56
    textSerialData->setCurrentFont(QFont("Consolas", 8));
13
    textSerialData->setCurrentFont(QFont("Consolas", 8));
57
    textSerialData->append("Waiting for serial connection...");
14
    textSerialData->append("Waiting for serial connection...");
Line 69... Line 26...
69
    QVBoxLayout *serialDataLayout = new QVBoxLayout();
26
    QVBoxLayout *serialDataLayout = new QVBoxLayout();
70
    serialDataLayout->addWidget(textSerialData);
27
    serialDataLayout->addWidget(textSerialData);
71
    serialDataLayout->addLayout(serialTransmitLayout);
28
    serialDataLayout->addLayout(serialTransmitLayout);
72
    groupSerialData->setLayout(serialDataLayout);
29
    groupSerialData->setLayout(serialDataLayout);
73
 
30
 
74
 
-
 
75
    // Macro controller
31
    // Macro controller
76
    groupMacro = new QGroupBox("Other");
32
    groupMacro = new QGroupBox("Other");
77
    btnMacro = new QPushButton("&Macros");
33
    btnMacro = new QPushButton("&Macros");
78
    QHBoxLayout *macroLayout = new QHBoxLayout();
34
    QHBoxLayout *macroLayout = new QHBoxLayout();
79
    macroLayout->addWidget(btnMacro);
35
    macroLayout->addWidget(btnMacro);
80
    groupMacro->setLayout(macroLayout);
36
    groupMacro->setLayout(macroLayout);
81
//    groupMacro->setFixedSize(groupMacro->sizeHint());
-
 
82
 
-
 
83
 
-
 
84
    // Main layout
-
 
85
    QGridLayout *mainLayout = new QGridLayout();
-
 
86
    mainLayout->addWidget(groupSerialInit, 0, 0, 1, 1, Qt::AlignLeft);
-
 
87
    mainLayout->addWidget(groupMacro, 0, 1, 1, 1, Qt::AlignLeft);
-
 
88
    mainLayout->addWidget(groupSerialData, 1, 0, 1, 2);
-
 
89
    mainLayout->setColumnStretch(0, 0);
-
 
90
    mainLayout->setColumnStretch(1, 1);
-
 
91
    centralWidget->setLayout(mainLayout);
-
 
92
 
37
 
93
    // Initialize thread for connection to serial port
38
    // Initialize serial controller
94
    serialThread = new QThread();
-
 
95
    serialController = new SerialController();
39
    serialController = new SerialController();
96
    serialController->moveToThread(serialThread);
40
    groupSerialInit = new QGroupBox("Serial Connection");
97
    connect(this, SIGNAL(Serial_QueryParameters()), serialController, SLOT(Serial_QueryParameters()));
-
 
98
    connect(this, SIGNAL(Serial_Connect(QString,QString,QString,QString,QString,QString)),
41
    QGridLayout *serialInitLayout = new QGridLayout();
99
            serialController, SLOT(Serial_Connect(QString,QString,QString,QString,QString,QString)));
42
    serialInitLayout->setContentsMargins(0, 0, 0, 0);
100
    connect(this, SIGNAL(Serial_Disconnect()), serialController, SLOT(Serial_Disconnect()));
43
    serialInitLayout->addWidget(serialController);
101
    connect(this, SIGNAL(Serial_TransmitString(QString)), serialController, SLOT(Serial_TransmitString(QString)));
-
 
102
    connect(serialController, SIGNAL(Serial_UpdateParameters(QStringList,QStringList,QStringList,QStringList,QStringList,QStringList)),
-
 
103
            this, SLOT(Serial_UpdateParameters(QStringList,QStringList,QStringList,QStringList,QStringList,QStringList)));
-
 
104
    connect(serialController, SIGNAL(Serial_ReceivedString(QString)), this, SLOT(Serial_ReceivedString(QString)));
-
 
105
    connect(serialController, SIGNAL(Serial_Connected()), this, SLOT(Serial_Connected()));
44
    groupSerialInit->setLayout(serialInitLayout);
106
    connect(serialController, SIGNAL(Serial_Disconnected()), this, SLOT(Serial_Disconnected()));
45
    connect(serialController, SIGNAL(UpdateStatus(QString)), this, SLOT(UpdateSerialStatus(QString)));
107
    connect(serialThread, SIGNAL(finished()), serialController, SLOT(deleteLater()));
-
 
108
    serialThread->start();
-
 
109
 
46
 
110
    // Initialize macro widget
47
    // Initialize macro controller
111
    macroDockWidget = new QDockWidget("Macro Controller", this);
48
    macroDockWidget = new QDockWidget("Macro Controller", this);
112
    macroController = new MacroController(macroDockWidget);
49
    macroController = new MacroController(macroDockWidget);
113
    macroDockWidget->setWidget(macroController);
50
    macroDockWidget->setWidget(macroController);
114
    macroDockWidget->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
51
    macroDockWidget->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
115
    macroDockWidget->hide();
52
    macroDockWidget->hide();
Line 117... Line 54...
117
    connect(macroController, SIGNAL(Macro_TransmitText(QString)), this, SLOT(Serial_PrepareTransmit(QString)));
54
    connect(macroController, SIGNAL(Macro_TransmitText(QString)), this, SLOT(Serial_PrepareTransmit(QString)));
118
    connect(serialController, SIGNAL(Serial_Connected()), macroController, SLOT(Macro_EnableTransmit()));
55
    connect(serialController, SIGNAL(Serial_Connected()), macroController, SLOT(Macro_EnableTransmit()));
119
    connect(serialController, SIGNAL(Serial_Disconnected()), macroController, SLOT(Macro_DisableTransmit()));
56
    connect(serialController, SIGNAL(Serial_Disconnected()), macroController, SLOT(Macro_DisableTransmit()));
120
 
57
 
121
    // Connect local widgets
58
    // Connect local widgets
122
    connect(btnSerialConnect, SIGNAL(clicked()), this, SLOT(Serial_ConnectToggleBtn()));
-
 
123
    connect(btnSerialRefresh, SIGNAL(clicked()), this, SIGNAL(Serial_QueryParameters()));
-
 
124
    connect(btnSerialTransmit, SIGNAL(clicked()), this, SLOT(Serial_PrepareTransmit()));
59
    connect(btnSerialTransmit, SIGNAL(clicked()), this, SLOT(Serial_PrepareTransmit()));
125
    connect(textSerialTransmit, SIGNAL(returnPressed()), btnSerialTransmit, SIGNAL(clicked()));
60
    connect(textSerialTransmit, SIGNAL(returnPressed()), btnSerialTransmit, SIGNAL(clicked()));
126
    connect(btnSerialClear, SIGNAL(clicked()), this, SLOT(Serial_ClearBtn()));
61
    connect(btnSerialClear, SIGNAL(clicked()), this, SLOT(Serial_ClearBtn()));
127
    connect(btnMacro, SIGNAL(clicked()), macroDockWidget->toggleViewAction(), SLOT(trigger()));
62
    connect(btnMacro, SIGNAL(clicked()), macroDockWidget->toggleViewAction(), SLOT(trigger()));
128
 
63
 
-
 
64
    // Main layout
-
 
65
    QGridLayout *mainLayout = new QGridLayout();
-
 
66
    mainLayout->addWidget(groupSerialInit, 0, 0, 1, 1, Qt::AlignLeft);
-
 
67
    mainLayout->addWidget(groupMacro, 0, 1, 1, 1, Qt::AlignLeft);
-
 
68
    mainLayout->addWidget(groupSerialData, 1, 0, 1, 2);
129
    emit Serial_QueryParameters();
69
    mainLayout->setColumnStretch(0, 0);
130
    Serial_Disconnected();
70
    mainLayout->setColumnStretch(1, 1);
-
 
71
    centralWidget->setLayout(mainLayout);
131
 
72
 
132
    setWindowTitle("Marlin Controller");
73
    setWindowTitle("Marlin Controller");
133
    setWindowIcon(QIcon(":/External/Resources/Icon_16.bmp"));
74
    setWindowIcon(QIcon(":/External/Resources/Icon_16.bmp"));
-
 
75
 
-
 
76
    statusSerial = new QLabel("Serial Status: Disconnected");
-
 
77
    statusSerial->setMinimumWidth(300);
-
 
78
    statusBar()->addPermanentWidget(statusSerial);
134
}
79
}
135
 
80
 
136
MainWindow::~MainWindow()
81
MainWindow::~MainWindow()
137
{
82
{
138
    serialThread->quit();
-
 
139
}
-
 
140
 
83
 
141
void MainWindow::Serial_ConnectToggleBtn()
-
 
142
{
-
 
143
    if (serialController->connected) {
-
 
144
        emit Serial_Disconnect();
-
 
145
    } else {
-
 
146
        if (cboxSerialPort->currentText() != "" && cboxSerialSpeed->currentText() != "") {
-
 
147
            emit Serial_Connect(cboxSerialPort->currentText(), cboxSerialSpeed->currentText(), cboxSerialDataBits->currentText(),
-
 
148
                                cboxSerialStopBits->currentText(), cboxSerialParity->currentText(), cboxSerialFlowControl->currentText());
-
 
149
        }
-
 
150
    }
-
 
151
}
84
}
152
 
85
 
153
void MainWindow::Serial_PrepareTransmit(QString string)
86
void MainWindow::Serial_PrepareTransmit(QString string)
154
{
87
{
155
    if (string == "") {
88
    if (string == "") {
Line 168... Line 101...
168
void MainWindow::Serial_ClearBtn()
101
void MainWindow::Serial_ClearBtn()
169
{
102
{
170
    textSerialData->clear();
103
    textSerialData->clear();
171
}
104
}
172
 
105
 
173
void MainWindow::Serial_UpdateParameters(QStringList ports, QStringList speeds, QStringList dataBits,
-
 
174
                                     QStringList stopBits, QStringList parity, QStringList flowControl)
-
 
175
{
-
 
176
    QString currPort = cboxSerialPort->currentText();
-
 
177
    cboxSerialPort->clear();
-
 
178
    cboxSerialPort->addItems(ports);
-
 
179
    if (currPort != "" && ports.contains(currPort))
-
 
180
        cboxSerialPort->setCurrentText(currPort);
-
 
181
 
-
 
182
    QString currSpeed = cboxSerialSpeed->currentText();
-
 
183
    cboxSerialSpeed->clear();
-
 
184
    cboxSerialSpeed->addItems(speeds);
-
 
185
    if (currSpeed != "") cboxSerialSpeed->setCurrentText(currSpeed);
-
 
186
 
-
 
187
    int currData = cboxSerialDataBits->currentIndex();
-
 
188
    cboxSerialDataBits->clear();
-
 
189
    cboxSerialDataBits->addItems(dataBits);
-
 
190
    if (currData >= 0) cboxSerialDataBits->setCurrentIndex(currData);
-
 
191
 
-
 
192
    int currStop = cboxSerialStopBits->currentIndex();
-
 
193
    cboxSerialStopBits->clear();
-
 
194
    cboxSerialStopBits->addItems(stopBits);
-
 
195
    if (currStop >= 0) cboxSerialStopBits->setCurrentIndex(currStop);
-
 
196
 
-
 
197
    int currParity = cboxSerialParity->currentIndex();
-
 
198
    cboxSerialParity->clear();
-
 
199
    cboxSerialParity->addItems(parity);
-
 
200
    if (currParity >= 0) cboxSerialParity->setCurrentIndex(currParity);
-
 
201
 
-
 
202
    int currFlow = cboxSerialFlowControl->currentIndex();
-
 
203
    cboxSerialFlowControl->clear();
-
 
204
    cboxSerialFlowControl->addItems(flowControl);
-
 
205
    if (currFlow >= 0) cboxSerialFlowControl->setCurrentIndex(currFlow);
-
 
206
}
-
 
207
 
-
 
208
void MainWindow::Serial_ReceivedString(QString string)
106
void MainWindow::Serial_ReceivedString(QString string)
209
{
107
{
210
    textSerialData->setTextColor(Qt::darkRed);
108
    textSerialData->setTextColor(Qt::darkRed);
211
    textSerialData->append("RX:  " + string);
109
    textSerialData->append("RX:  " + string);
212
}
110
}
213
 
111
 
214
void MainWindow::Serial_Connected()
112
void MainWindow::UpdateStatus(QString string)
-
 
113
{
-
 
114
    statusBar()->showMessage(string, STATUS_TIMEOUT_MS);
-
 
115
}
-
 
116
 
-
 
117
void MainWindow::UpdateSerialStatus(QString string)
215
{
118
{
216
    btnSerialConnect->setText("&Disconnect");
-
 
217
    cboxSerialPort->setEnabled(false);
-
 
218
    cboxSerialSpeed->setEnabled(false);
-
 
219
    cboxSerialDataBits->setEnabled(false);
-
 
220
    cboxSerialStopBits->setEnabled(false);
-
 
221
    cboxSerialParity->setEnabled(false);
-
 
222
    cboxSerialFlowControl->setEnabled(false);
-
 
223
    btnSerialRefresh->setEnabled(false);
-
 
224
    textSerialTransmit->setEnabled(true);
-
 
225
    btnSerialTransmit->setEnabled(true);
-
 
226
}
-
 
227
 
-
 
228
void MainWindow::Serial_Disconnected()
-
 
229
{
-
 
230
    btnSerialConnect->setText("&Connect");
119
    statusSerial->setText(string);
231
    cboxSerialPort->setEnabled(true);
-
 
232
    cboxSerialSpeed->setEnabled(true);
-
 
233
    cboxSerialDataBits->setEnabled(true);
-
 
234
    cboxSerialStopBits->setEnabled(true);
-
 
235
    cboxSerialParity->setEnabled(true);
-
 
236
    cboxSerialFlowControl->setEnabled(true);
-
 
237
    btnSerialRefresh->setEnabled(true);
-
 
238
    textSerialTransmit->setEnabled(false);
-
 
239
    btnSerialTransmit->setEnabled(false);
-
 
240
}
120
}