Subversion Repositories Code-Repo

Compare Revisions

Ignore whitespace Rev 361 → Rev 362

/Misc Projects/PcMarlinInterface/SerialIOWidget.h
File deleted
/Misc Projects/PcMarlinInterface/SerialIOWidget.cpp
File deleted
/Misc Projects/PcMarlinInterface/IOWidget.cpp
0,0 → 1,90
#include "IOWidget.h"
 
IOWidget::IOWidget(QWidget *parent) : QWidget(parent)
{
// Serial data UI
textData = new QTextEdit();
textData->setCurrentFont(QFont("Consolas", 8));
textData->append("Waiting for serial connection...");
textData->setMinimumSize(400, 100);
textData->setReadOnly(true);
textTransmit = new QLineEdit();
textTransmit->setEnabled(false);
textTransmit->setFont(QFont("Consolas", 8));
btnTransmit = new QPushButton("&Send");
btnTransmit->setEnabled(false);
btnClear = new QPushButton("Clear");
 
QHBoxLayout *transmitLayout = new QHBoxLayout();
transmitLayout->addWidget(textTransmit);
transmitLayout->addWidget(btnTransmit);
transmitLayout->addWidget(btnClear);
QVBoxLayout *dataLayout = new QVBoxLayout();
dataLayout->addWidget(textData);
dataLayout->addLayout(transmitLayout);
setLayout(dataLayout);
 
connect(btnTransmit, SIGNAL(clicked()), this, SLOT(PreprocessTransmit()));
connect(textTransmit, SIGNAL(returnPressed()), btnTransmit, SIGNAL(clicked()));
connect(btnClear, SIGNAL(clicked()), this, SLOT(ClearBtn()));
 
DisableTransmit();
lastTransmit = true;
}
 
IOWidget::~IOWidget()
{
 
}
 
void IOWidget::PreprocessTransmit(QByteArray data)
{
QString str;
if (data.isEmpty()) {
str = textTransmit->text();
textTransmit->setText("");
} else {
str = QString(data);
}
 
emit TransmitByteArray(str.toUtf8());
textData->setTextColor(Qt::darkBlue);
 
QStringList cmds = str.split('\n');
for (int i = 0; i < cmds.size(); i++) {
textData->append("TX: " + cmds[i]);
}
 
// Save a flag indicating last activity was a transmit
lastTransmit = true;
}
 
void IOWidget::ProcessReceivedByte(QByteArray data)
{
textData->setTextColor(Qt::darkRed);
data.replace("\n", "\nRX: ");
if (lastTransmit) {
textData->insertPlainText("\nRX: " + QString(data));
} else {
textData->insertPlainText(QString(data));
}
textData->moveCursor(QTextCursor::End);
lastTransmit = false;
}
 
void IOWidget::ClearBtn()
{
textData->clear();
}
 
void IOWidget::EnableTransmit()
{
textTransmit->setEnabled(true);
btnTransmit->setEnabled(true);
}
 
void IOWidget::DisableTransmit()
{
textTransmit->setEnabled(false);
btnTransmit->setEnabled(false);
}
/Misc Projects/PcMarlinInterface/IOWidget.h
0,0 → 1,32
#ifndef IOWIDGET_H
#define IOWIDGET_H
 
#include "GlobalDefines.h"
 
class IOWidget : public QWidget
{
Q_OBJECT
public:
IOWidget(QWidget *parent = 0);
~IOWidget();
 
public slots:
void PreprocessTransmit(QByteArray data = QByteArray());
void ProcessReceivedByte(QByteArray data);
void ClearBtn(void);
void EnableTransmit(void);
void DisableTransmit(void);
 
signals:
void TransmitByteArray(QByteArray data);
 
private:
QTextEdit *textData;
QLineEdit *textTransmit;
QPushButton *btnTransmit;
QPushButton *btnClear;
 
bool lastTransmit;
};
 
#endif // IOWIDGET_H
/Misc Projects/PcMarlinInterface/MacroWidget.cpp
14,7 → 14,7
 
mainLayout = new QGridLayout();
 
macroCount = 0;
count = 0;
connected = false;
lastKnownFilePath = ".";
 
28,18 → 28,18
mainLayout->addLayout(ioLayout, 0, 0, 1, 2);
 
for (int i = 0; i < MACRO_DEFAULT_COUNT; i++) {
Macro_AddEntry();
AddEntry();
}
 
setLayout(mainLayout);
 
connect(btnAddMacro, SIGNAL(clicked()), this, SLOT(Macro_AddEntry()));
connect(btnRemoveMacro, SIGNAL(clicked()), this, SLOT(Macro_RemoveEntry()));
connect(btnClear, SIGNAL(clicked()), this, SLOT(Macro_Clear()));
connect(btnExport, SIGNAL(clicked()), this, SLOT(Macro_WriteToFile()));
connect(btnImport, SIGNAL(clicked()), this, SLOT(Macro_ReadFromFile()));
connect(sigmapTransmit, SIGNAL(mapped(QWidget*)), this, SLOT(Macro_InitTransmit(QWidget*)));
connect(sigmapKeybind, SIGNAL(mapped(int)), this, SLOT(Macro_KeybindPrompt(int)));
connect(btnAddMacro, SIGNAL(clicked()), this, SLOT(AddEntry()));
connect(btnRemoveMacro, SIGNAL(clicked()), this, SLOT(RemoveEntry()));
connect(btnClear, SIGNAL(clicked()), this, SLOT(Clear()));
connect(btnExport, SIGNAL(clicked()), this, SLOT(WriteToFile()));
connect(btnImport, SIGNAL(clicked()), this, SLOT(ReadFromFile()));
connect(sigmapTransmit, SIGNAL(mapped(QWidget*)), this, SLOT(InitTransmit(QWidget*)));
connect(sigmapKeybind, SIGNAL(mapped(int)), this, SLOT(KeybindPrompt(int)));
 
// Register global event process for keyboard shortcut handling
qApp->installEventFilter(this);
55,31 → 55,31
return this->minimumSizeHint();
}
 
void MacroWidget::Macro_EnableTransmit()
void MacroWidget::EnableTransmit()
{
connected = true;
for (int i = 0; i < macroBtnSendList.size(); i++) {
macroBtnSendList[i]->setEnabled(true);
for (int i = 0; i < btnSendList.size(); i++) {
btnSendList[i]->setEnabled(true);
}
}
 
void MacroWidget::Macro_DisableTransmit()
void MacroWidget::DisableTransmit()
{
connected = false;
for (int i = 0; i < macroBtnSendList.size(); i++) {
macroBtnSendList[i]->setEnabled(false);
for (int i = 0; i < btnSendList.size(); i++) {
btnSendList[i]->setEnabled(false);
}
}
 
void MacroWidget::Macro_InitTransmit(QWidget *t)
void MacroWidget::InitTransmit(QWidget *t)
{
if (connected) {
QTextEdit *text = qobject_cast<QTextEdit*>(t);
emit Macro_TransmitText(text->toPlainText().toUtf8());
emit TransmitText(text->toPlainText().toUtf8());
}
}
 
void MacroWidget::Macro_KeybindPrompt(int id)
void MacroWidget::KeybindPrompt(int id)
{
QPushButton *btn = qobject_cast<QPushButton*>(sigmapKeybind->mapping(id));
 
106,16 → 106,16
btn->installEventFilter(this);
}
 
void MacroWidget::Macro_AddEntry()
void MacroWidget::AddEntry()
{
macroCount++;
count++;
 
// Create new layout/widgets
QLineEdit *lineEdit = new QLineEdit(QString("Macro %1").arg(macroCount));
QLineEdit *lineEdit = new QLineEdit(QString("Macro %1").arg(count));
lineEdit->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed);
lineEdit->setMinimumWidth(100);
lineEdit->setAlignment(Qt::AlignCenter);
macroNameList.append(lineEdit);
nameList.append(lineEdit);
 
QTextEdit *textEdit = new QTextEdit();
textEdit->setMinimumHeight(50);
124,16 → 124,16
textEdit->setFont(QFont("Consolas", 8));
textEdit->setAcceptRichText(false);
textEdit->setTabChangesFocus(true);
macroValueList.append(textEdit);
valueList.append(textEdit);
 
QPushButton *keyButton = new QPushButton("Hotkey: None");
keyButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
macroBtnKeyList.append(keyButton);
btnKeyList.append(keyButton);
 
QPushButton *pushButton = new QPushButton("Send Macro");
pushButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
pushButton->setEnabled(connected);
macroBtnSendList.append(pushButton);
btnSendList.append(pushButton);
 
QVBoxLayout *tmpLayout = new QVBoxLayout();
tmpLayout->addWidget(lineEdit);
141,12 → 141,12
tmpLayout->addWidget(pushButton);
 
// Add layout/widgets to main layout
mainLayout->addLayout(tmpLayout, macroCount, 0);
mainLayout->addWidget(textEdit, macroCount, 1);
mainLayout->addLayout(tmpLayout, count, 0);
mainLayout->addWidget(textEdit, count, 1);
mainLayout->setColumnStretch(1, 1);
 
// Associate KeyButton with its corresponding ID
sigmapKeybind->setMapping(keyButton, macroCount-1);
sigmapKeybind->setMapping(keyButton, count-1);
connect(keyButton, SIGNAL(clicked()), sigmapKeybind, SLOT(map()));
 
// Associate PushButton with its corresponding TextEdit
163,16 → 163,16
btnRemoveMacro->setEnabled(true);
}
 
void MacroWidget::Macro_RemoveEntry()
void MacroWidget::RemoveEntry()
{
 
// Remove and delete layout/widgets at last macro slot
QLayoutItem *item = mainLayout->itemAtPosition(macroCount, 0);
QLayoutItem *item = mainLayout->itemAtPosition(count, 0);
while(!item->isEmpty())
delete item->layout()->takeAt(0)->widget();
delete item;
 
item = mainLayout->itemAtPosition(macroCount, 1);
item = mainLayout->itemAtPosition(count, 1);
delete item->widget();
 
item = mainLayout->itemAtPosition(1, 1);
179,45 → 179,45
int height = item->widget()->height() + mainLayout->verticalSpacing();
 
// Unmap and remove widgets from lists
QPushButton *pushButton = macroBtnSendList.back();
QPushButton *pushButton = btnSendList.back();
sigmapTransmit->removeMappings(pushButton);
 
QPushButton *keyButton = macroBtnKeyList.back();
QPushButton *keyButton = btnKeyList.back();
sigmapKeybind->removeMappings(keyButton);
 
macroNameList.pop_back();
macroValueList.pop_back();
macroBtnSendList.pop_back();
macroBtnKeyList.pop_back();
nameList.pop_back();
valueList.pop_back();
btnSendList.pop_back();
btnKeyList.pop_back();
 
int index = registeredKeyMacroIDs.indexOf(macroCount-1);
int index = registeredKeyMacroIDs.indexOf(count-1);
if (index >= 0) {
registeredKeySequences.removeAt(index);
registeredKeyMacroIDs.removeAt(index);
}
 
macroCount--;
count--;
 
QDockWidget *parent = qobject_cast<QDockWidget*>(this->parent());
if (parent->isFloating())
parent->resize(parent->width(), parent->height() - height);
 
if (macroCount == 1)
if (count == 1)
btnRemoveMacro->setEnabled(false);
}
 
void MacroWidget::Macro_Clear()
void MacroWidget::Clear()
{
for (int i = 0; i < macroCount; i++) {
macroNameList[i]->setText(QString("Macro %1").arg(i+1));
macroValueList[i]->clear();
macroBtnKeyList[i]->setText("Hotkey: None");
for (int i = 0; i < count; i++) {
nameList[i]->setText(QString("Macro %1").arg(i+1));
valueList[i]->clear();
btnKeyList[i]->setText("Hotkey: None");
}
registeredKeyMacroIDs.clear();
registeredKeySequences.clear();
}
 
void MacroWidget::Macro_WriteToFile()
void MacroWidget::WriteToFile()
{
QString file = QFileDialog::getSaveFileName(this, "Settings XML File", lastKnownFilePath, "XML File (*.xml)");
QCoreApplication::processEvents(); // Wait for dialog to close
241,11 → 241,11
stream.writeStartElement("Settings");
stream.writeStartElement("Macro");
 
for (int i = 0; i < macroCount; i++) {
for (int i = 0; i < count; i++) {
stream.writeStartElement("Macro_Entry");
 
stream.writeAttribute("Name", macroNameList[i]->text());
stream.writeTextElement("Value", macroValueList[i]->toPlainText());
stream.writeAttribute("Name", nameList[i]->text());
stream.writeTextElement("Value", valueList[i]->toPlainText());
 
int index = registeredKeyMacroIDs.indexOf(i);
if (index >= 0) {
264,7 → 264,7
inputFile.close();
}
 
void MacroWidget::Macro_ReadFromFile()
void MacroWidget::ReadFromFile()
{
int counter = 0;
 
273,7 → 273,7
 
if (file.size() == 0) return;
 
Macro_Clear();
Clear();
 
// If file was selected, save directory for next time
QFileInfo fileInfo = QFileInfo(file);
327,15 → 327,15
}
 
// Write values to GUI
if (counter == macroCount)
Macro_AddEntry();
if (counter == count)
AddEntry();
 
macroNameList[counter]->setText(name);
macroValueList[counter]->setText(value);
nameList[counter]->setText(name);
valueList[counter]->setText(value);
if (keybinding != "") {
registeredKeySequences.append(QKeySequence(keybinding));
registeredKeyMacroIDs.append(counter);
macroBtnKeyList[counter]->setText("Hotkey: " + keybinding);
btnKeyList[counter]->setText("Hotkey: " + keybinding);
}
counter++;
}
360,7 → 360,7
if (!registeredKeySequences.isEmpty()) {
int index = registeredKeySequences.indexOf(seq);
if (index >= 0) {
Macro_InitTransmit(macroValueList[registeredKeyMacroIDs[index]]);
InitTransmit(valueList[registeredKeyMacroIDs[index]]);
return true;
}
}
/Misc Projects/PcMarlinInterface/MacroWidget.h
15,24 → 15,26
QSize sizeHint() const;
 
public slots:
void Macro_EnableTransmit(void);
void Macro_DisableTransmit(void);
void Macro_InitTransmit(QWidget* t);
void Macro_KeybindPrompt(int id);
void Macro_AddEntry(void);
void Macro_RemoveEntry(void);
void Macro_Clear(void);
void Macro_WriteToFile(void);
void Macro_ReadFromFile(void);
// *public* slots
void EnableTransmit(void);
void DisableTransmit(void);
// *private* slots
void InitTransmit(QWidget* t);
void KeybindPrompt(int id);
void AddEntry(void);
void RemoveEntry(void);
void Clear(void);
void WriteToFile(void);
void ReadFromFile(void);
 
signals:
void Macro_TransmitText(QByteArray data);
void TransmitText(QByteArray data);
 
protected:
bool eventFilter(QObject *, QEvent *);
 
private:
int macroCount;
int count;
bool connected;
QString lastKnownFilePath;
 
42,10 → 44,10
QPushButton *btnRemoveMacro;
QPushButton *btnClear;
 
QList<QLineEdit*> macroNameList;
QList<QTextEdit*> macroValueList;
QList<QPushButton*> macroBtnSendList;
QList<QPushButton*> macroBtnKeyList;
QList<QLineEdit*> nameList;
QList<QTextEdit*> valueList;
QList<QPushButton*> btnSendList;
QList<QPushButton*> btnKeyList;
 
QList<QKeySequence> registeredKeySequences;
QList<int> registeredKeyMacroIDs;
/Misc Projects/PcMarlinInterface/MainWindow.cpp
15,25 → 15,25
groupMacro->setLayout(macroLayout);
 
// Initialize serial widget
serialInitWidget = new SerialWidget();
serialWidget = new SerialWidget();
groupSerialInit = new QGroupBox("Serial Connection");
QGridLayout *serialInitLayout = new QGridLayout();
serialInitLayout->setContentsMargins(0, 0, 0, 0);
serialInitLayout->addWidget(serialInitWidget);
serialInitLayout->addWidget(serialWidget);
groupSerialInit->setLayout(serialInitLayout);
connect(serialInitWidget, SIGNAL(UpdateStatus(QString)), this, SLOT(UpdateSerialStatus(QString)));
connect(serialWidget, SIGNAL(UpdateStatus(QString)), this, SLOT(UpdateSerialStatus(QString)));
 
// Initialize data widget
serialIOWidget = new SerialIOWidget();
ioWidget = new IOWidget();
groupSerialData = new QGroupBox("Data");
QGridLayout *serialDataLayout = new QGridLayout();
serialDataLayout->setContentsMargins(0, 0, 0, 0);
serialDataLayout->addWidget(serialIOWidget);
serialDataLayout->addWidget(ioWidget);
groupSerialData->setLayout(serialDataLayout);
connect(serialInitWidget, SIGNAL(Serial_ReceivedByte(char)), serialIOWidget, SLOT(Serial_ReceivedByte(char)));
connect(serialInitWidget, SIGNAL(Serial_Connected()), serialIOWidget, SLOT(Serial_EnableTransmit()));
connect(serialInitWidget, SIGNAL(Serial_Disconnected()), serialIOWidget, SLOT(Serial_DisableTransmit()));
connect(serialIOWidget, SIGNAL(Serial_TransmitByteArray(QByteArray)), serialInitWidget, SIGNAL(Serial_TransmitByteArray(QByteArray)));
connect(serialWidget, SIGNAL(ReceivedByte(QByteArray)), ioWidget, SLOT(ProcessReceivedByte(QByteArray)));
connect(serialWidget, SIGNAL(Connected()), ioWidget, SLOT(EnableTransmit()));
connect(serialWidget, SIGNAL(Disconnected()), ioWidget, SLOT(DisableTransmit()));
connect(ioWidget, SIGNAL(TransmitByteArray(QByteArray)), serialWidget, SIGNAL(TransmitByteArray(QByteArray)));
 
// Initialize macro widget
macroDockWidget = new QDockWidget("Macro Controller", this);
42,9 → 42,9
macroDockWidget->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
macroDockWidget->hide();
addDockWidget(Qt::RightDockWidgetArea, macroDockWidget);
connect(macroWidget, SIGNAL(Macro_TransmitText(QByteArray)), serialIOWidget, SLOT(Serial_PrepareTransmit(QByteArray)));
connect(serialInitWidget, SIGNAL(Serial_Connected()), macroWidget, SLOT(Macro_EnableTransmit()));
connect(serialInitWidget, SIGNAL(Serial_Disconnected()), macroWidget, SLOT(Macro_DisableTransmit()));
connect(macroWidget, SIGNAL(TransmitText(QByteArray)), ioWidget, SLOT(PreprocessTransmit(QByteArray)));
connect(serialWidget, SIGNAL(Connected()), macroWidget, SLOT(EnableTransmit()));
connect(serialWidget, SIGNAL(Disconnected()), macroWidget, SLOT(DisableTransmit()));
 
// Connect local widgets
connect(btnMacro, SIGNAL(clicked()), macroDockWidget->toggleViewAction(), SLOT(trigger()));
/Misc Projects/PcMarlinInterface/MainWindow.h
4,7 → 4,7
#include "GlobalDefines.h"
#include "SerialWidget.h"
#include "MacroWidget.h"
#include "SerialIOWidget.h"
#include "IOWidget.h"
 
class MainWindow : public QMainWindow
{
26,12 → 26,12
QWidget *centralWidget;
 
// Serial controller + UI
SerialWidget *serialInitWidget;
SerialWidget *serialWidget;
QGroupBox *groupSerialInit;
QPushButton *btnSerialConnect;
 
// Serial data
SerialIOWidget *serialIOWidget;
IOWidget *ioWidget;
QGroupBox *groupSerialData;
 
// Macro controller + UI
/Misc Projects/PcMarlinInterface/PcMarlinInterface.pro
17,7 → 17,7
SerialHelper.cpp \
MacroWidget.cpp \
SerialWidget.cpp \
SerialIOWidget.cpp
IOWidget.cpp
 
HEADERS += GlobalDefines.h \
MainWindow.h \
24,7 → 24,7
SerialHelper.h \
MacroWidget.h \
SerialWidget.h \
SerialIOWidget.h
IOWidget.h
 
RESOURCES += Resources.qrc
 
/Misc Projects/PcMarlinInterface/PcMarlinInterface.pro.user
1,10 → 1,10
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 3.3.0, 2015-02-09T18:01:00. -->
<!-- Written by QtCreator 3.3.0, 2015-03-04T03:06:04. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
<value type="QByteArray">{22bd4f67-ea17-48ee-8299-171e5aa125c2}</value>
<value type="QByteArray">{4c29e835-aad4-4677-99d7-2a63e01ab69b}</value>
</data>
<data>
<variable>ProjectExplorer.Project.ActiveTarget</variable>
/Misc Projects/PcMarlinInterface/SerialHelper.cpp
16,7 → 16,7
delete serialPort;
}
 
void SerialHelper::Serial_QueryParameters()
void SerialHelper::QueryParameters()
{
QList<QSerialPortInfo> portsList = QSerialPortInfo::availablePorts();
QStringList ports;
23,17 → 23,17
for (int i = 0; i < portsList.size(); i++) {
ports.append(portsList[i].portName());
}
emit Serial_UpdateParameters(ports, speeds, dataBits, stopBits, parity, flowControl);
emit UpdateParameters(ports, speeds, dataBits, stopBits, parity, flowControl);
}
 
void SerialHelper::Serial_Connect(QString port, QString speed, QString dataBits,
void SerialHelper::Connect(QString port, QString speed, QString dataBits,
QString stopBits, QString parity, QString flowControl)
{
if (!connected) {
emit UpdateStatus("Connecting to " + port);
serialPort = new QSerialPort();
connect(serialPort, SIGNAL(readyRead()), this, SLOT(Serial_ProcessIncomingData()));
connect(serialPort, SIGNAL(error(QSerialPort::SerialPortError)), this, SLOT(Serial_ProcessError(QSerialPort::SerialPortError)));
connect(serialPort, SIGNAL(readyRead()), this, SLOT(ProcessIncomingData()));
connect(serialPort, SIGNAL(error(QSerialPort::SerialPortError)), this, SLOT(ProcessError(QSerialPort::SerialPortError)));
serialPort->setPortName(port);
if (serialPort->open(QIODevice::ReadWrite)) {
connected = true;
82,14 → 82,14
if (ok) {
QString status = "Connected (%1 @ %2 D: %3 S: %4 P: %5 FC: %6)";
emit UpdateStatus(status.arg(port).arg(speed).arg(dataBits).arg(stopBits).arg(parity).arg(flowControl));
emit Serial_Connected();
emit Connected();
} else
Serial_Disconnect();
Disconnect();
}
}
}
 
void SerialHelper::Serial_Disconnect(bool errored)
void SerialHelper::Disconnect(bool errored)
{
serialPort->disconnect();
serialPort->close();
97,34 → 97,33
connected = false;
if (!errored)
emit UpdateStatus("Disconnected");
emit Serial_Disconnected();
emit Disconnected();
}
 
void SerialHelper::Serial_TransmitString(QString string)
void SerialHelper::TransmitString(QString string)
{
serialPort->write(string.toStdString().c_str());
serialPort->write(SERIAL_NEWLINE_CHAR);
}
 
void SerialHelper::Serial_TransmitByteArray(QByteArray data)
void SerialHelper::TransmitByteArray(QByteArray data)
{
serialPort->write(data);
}
 
void SerialHelper::Serial_ProcessIncomingData()
void SerialHelper::ProcessIncomingData()
{
char tmpBuffer[SERIAL_BUFFER_SIZE];
int len = serialPort->read(tmpBuffer, sizeof(tmpBuffer));
while (len > 0) {
for (int i = 0; i < len; i++) {
emit Serial_ReceivedByte(tmpBuffer[i]);
}
QByteArray data(tmpBuffer, len);
emit ReceivedByte(data);
// Check if there is more data to be read from the serial port
len = serialPort->read(tmpBuffer, sizeof(tmpBuffer));
}
}
 
void SerialHelper::Serial_ProcessError(QSerialPort::SerialPortError error)
void SerialHelper::ProcessError(QSerialPort::SerialPortError error)
{
if (error == QSerialPort::NoError) return;
 
173,5 → 172,5
}
 
serialPort->clearError();
Serial_Disconnect(true);
Disconnect(true);
}
/Misc Projects/PcMarlinInterface/SerialHelper.h
18,24 → 18,24
 
public slots:
// Inbound from SerialController
void Serial_QueryParameters(void);
void Serial_Connect(QString port, QString speed, QString dataBits,
QString stopBits, QString parity, QString flowControl);
void Serial_Disconnect(bool errored = false);
void Serial_TransmitString(QString string);
void Serial_TransmitByteArray(QByteArray data);
void QueryParameters(void);
void Connect(QString port, QString speed, QString dataBits,
QString stopBits, QString parity, QString flowControl);
void Disconnect(bool errored = false);
void TransmitString(QString string);
void TransmitByteArray(QByteArray data);
 
// Local processing of received data
void Serial_ProcessIncomingData(void);
void Serial_ProcessError(QSerialPort::SerialPortError error);
void ProcessIncomingData(void);
void ProcessError(QSerialPort::SerialPortError error);
 
signals:
// Outbound to SerialController
void Serial_UpdateParameters(QStringList ports, QStringList speeds, QStringList dataBits,
QStringList stopBits, QStringList parity, QStringList flowControl);
void Serial_ReceivedByte(char byte);
void Serial_Connected(void);
void Serial_Disconnected(void);
void UpdateParameters(QStringList ports, QStringList speeds, QStringList dataBits,
QStringList stopBits, QStringList parity, QStringList flowControl);
void ReceivedByte(QByteArray);
void Connected(void);
void Disconnected(void);
void UpdateStatus(QString string);
 
private:
/Misc Projects/PcMarlinInterface/SerialWidget.cpp
3,43 → 3,43
SerialWidget::SerialWidget(QWidget *parent) : QWidget(parent)
{
// Serial connection UI
btnSerialConnect = new QPushButton("&Connect");
btnSerialRefresh = new QPushButton("&Refresh");
labelSerialPort = new QLabel("Serial Port:");
labelSerialSpeed = new QLabel("Baud Rate:");
labelSerialDataBits = new QLabel("Data:");
labelSerialStopBits = new QLabel("Stop:");
labelSerialParity = new QLabel("Parity Bit:");
labelSerialFlowControl = new QLabel("Flow Control:");
cboxSerialPort = new QComboBox();
cboxSerialPort->setMinimumWidth(80);
cboxSerialSpeed = new QComboBox();
cboxSerialSpeed->setEditable(true);
cboxSerialSpeed->setValidator(new QIntValidator(0, 100000000, this));
cboxSerialDataBits = new QComboBox();
cboxSerialDataBits->setMaximumWidth(60);
cboxSerialStopBits = new QComboBox();
cboxSerialStopBits->setMaximumWidth(60);
cboxSerialParity = new QComboBox();
cboxSerialFlowControl = new QComboBox();
cboxSerialFlowControl->setMinimumWidth(70);
btnConnect = new QPushButton("&Connect");
btnRefresh = new QPushButton("&Refresh");
labelPort = new QLabel("Serial Port:");
labelSpeed = new QLabel("Baud Rate:");
labelDataBits = new QLabel("Data:");
labelStopBits = new QLabel("Stop:");
labelParity = new QLabel("Parity Bit:");
labelFlowControl = new QLabel("Flow Control:");
cboxPort = new QComboBox();
cboxPort->setMinimumWidth(80);
cboxSpeed = new QComboBox();
cboxSpeed->setEditable(true);
cboxSpeed->setValidator(new QIntValidator(0, 100000000, this));
cboxDataBits = new QComboBox();
cboxDataBits->setMaximumWidth(60);
cboxStopBits = new QComboBox();
cboxStopBits->setMaximumWidth(60);
cboxParity = new QComboBox();
cboxFlowControl = new QComboBox();
cboxFlowControl->setMinimumWidth(70);
 
QGridLayout *serialSettingsLayout = new QGridLayout();
serialSettingsLayout->addWidget(btnSerialConnect, 0, 0);
serialSettingsLayout->addWidget(labelSerialPort, 0, 1);
serialSettingsLayout->addWidget(cboxSerialPort, 0, 2);
serialSettingsLayout->addWidget(labelSerialDataBits, 0, 3);
serialSettingsLayout->addWidget(cboxSerialDataBits, 0, 4);
serialSettingsLayout->addWidget(labelSerialParity, 0, 5);
serialSettingsLayout->addWidget(cboxSerialParity, 0, 6);
serialSettingsLayout->addWidget(btnConnect, 0, 0);
serialSettingsLayout->addWidget(labelPort, 0, 1);
serialSettingsLayout->addWidget(cboxPort, 0, 2);
serialSettingsLayout->addWidget(labelDataBits, 0, 3);
serialSettingsLayout->addWidget(cboxDataBits, 0, 4);
serialSettingsLayout->addWidget(labelParity, 0, 5);
serialSettingsLayout->addWidget(cboxParity, 0, 6);
 
serialSettingsLayout->addWidget(btnSerialRefresh, 1, 0);
serialSettingsLayout->addWidget(labelSerialSpeed, 1, 1);
serialSettingsLayout->addWidget(cboxSerialSpeed, 1, 2);
serialSettingsLayout->addWidget(labelSerialStopBits, 1, 3);
serialSettingsLayout->addWidget(cboxSerialStopBits, 1, 4);
serialSettingsLayout->addWidget(labelSerialFlowControl, 1, 5);
serialSettingsLayout->addWidget(cboxSerialFlowControl, 1, 6);
serialSettingsLayout->addWidget(btnRefresh, 1, 0);
serialSettingsLayout->addWidget(labelSpeed, 1, 1);
serialSettingsLayout->addWidget(cboxSpeed, 1, 2);
serialSettingsLayout->addWidget(labelStopBits, 1, 3);
serialSettingsLayout->addWidget(cboxStopBits, 1, 4);
serialSettingsLayout->addWidget(labelFlowControl, 1, 5);
serialSettingsLayout->addWidget(cboxFlowControl, 1, 6);
 
setLayout(serialSettingsLayout);
 
49,31 → 49,31
 
connect(serialHelper, SIGNAL(UpdateStatus(QString)), this, SIGNAL(UpdateStatus(QString)));
 
connect(this, SIGNAL(Serial_QueryParameters()), serialHelper, SLOT(Serial_QueryParameters()));
connect(serialHelper, SIGNAL(Serial_UpdateParameters(QStringList,QStringList,QStringList,QStringList,QStringList,QStringList)),
this, SLOT(Serial_UpdateParameters(QStringList,QStringList,QStringList,QStringList,QStringList,QStringList)));
connect(this, SIGNAL(QueryParameters()), serialHelper, SLOT(QueryParameters()));
connect(serialHelper, SIGNAL(UpdateParameters(QStringList,QStringList,QStringList,QStringList,QStringList,QStringList)),
this, SLOT(UpdateParameters(QStringList,QStringList,QStringList,QStringList,QStringList,QStringList)));
 
connect(this, SIGNAL(Serial_Connect(QString,QString,QString,QString,QString,QString)),
serialHelper, SLOT(Serial_Connect(QString,QString,QString,QString,QString,QString)));
connect(serialHelper, SIGNAL(Serial_Connected()), this, SIGNAL(Serial_Connected()));
connect(serialHelper, SIGNAL(Serial_Connected()), this, SLOT(Serial_LocalConnected()));
connect(this, SIGNAL(Connect(QString,QString,QString,QString,QString,QString)),
serialHelper, SLOT(Connect(QString,QString,QString,QString,QString,QString)));
connect(serialHelper, SIGNAL(Connected()), this, SIGNAL(Connected()));
connect(serialHelper, SIGNAL(Connected()), this, SLOT(LocalConnected()));
 
connect(this, SIGNAL(Serial_Disconnect()), serialHelper, SLOT(Serial_Disconnect()));
connect(serialHelper, SIGNAL(Serial_Disconnected()), this, SIGNAL(Serial_Disconnected()));
connect(serialHelper, SIGNAL(Serial_Disconnected()), this, SLOT(Serial_LocalDisconnected()));
connect(this, SIGNAL(Disconnect()), serialHelper, SLOT(Disconnect()));
connect(serialHelper, SIGNAL(Disconnected()), this, SIGNAL(Disconnected()));
connect(serialHelper, SIGNAL(Disconnected()), this, SLOT(LocalDisconnected()));
 
connect(this, SIGNAL(Serial_TransmitByteArray(QByteArray)), serialHelper, SLOT(Serial_TransmitByteArray(QByteArray)));
connect(this, SIGNAL(TransmitByteArray(QByteArray)), serialHelper, SLOT(TransmitByteArray(QByteArray)));
 
connect(serialHelper, SIGNAL(Serial_ReceivedByte(char)), this, SIGNAL(Serial_ReceivedByte(char)));
connect(serialHelper, SIGNAL(ReceivedByte(QByteArray)), this, SIGNAL(ReceivedByte(QByteArray)));
 
connect(serialThread, SIGNAL(finished()), serialHelper, SLOT(deleteLater()));
serialThread->start();
 
connect(btnSerialConnect, SIGNAL(clicked()), this, SLOT(Serial_ConnectToggleBtn()));
connect(btnSerialRefresh, SIGNAL(clicked()), this, SIGNAL(Serial_QueryParameters()));
connect(btnConnect, SIGNAL(clicked()), this, SLOT(ConnectToggleBtn()));
connect(btnRefresh, SIGNAL(clicked()), this, SIGNAL(QueryParameters()));
 
emit Serial_QueryParameters();
Serial_LocalDisconnected();
emit QueryParameters();
LocalDisconnected();
}
 
SerialWidget::~SerialWidget()
81,44 → 81,44
serialThread->quit();
}
 
void SerialWidget::Serial_UpdateParameters(QStringList ports, QStringList speeds, QStringList dataBits,
void SerialWidget::UpdateParameters(QStringList ports, QStringList speeds, QStringList dataBits,
QStringList stopBits, QStringList parity, QStringList flowControl)
{
QString currPort = cboxSerialPort->currentText();
cboxSerialPort->clear();
cboxSerialPort->addItems(ports);
QString currPort = cboxPort->currentText();
cboxPort->clear();
cboxPort->addItems(ports);
if (currPort != "" && ports.contains(currPort))
cboxSerialPort->setCurrentText(currPort);
cboxPort->setCurrentText(currPort);
 
QString currSpeed = cboxSerialSpeed->currentText();
cboxSerialSpeed->clear();
cboxSerialSpeed->addItems(speeds);
if (currSpeed != "") cboxSerialSpeed->setCurrentText(currSpeed);
QString currSpeed = cboxSpeed->currentText();
cboxSpeed->clear();
cboxSpeed->addItems(speeds);
if (currSpeed != "") cboxSpeed->setCurrentText(currSpeed);
 
int currData = cboxSerialDataBits->currentIndex();
cboxSerialDataBits->clear();
cboxSerialDataBits->addItems(dataBits);
if (currData >= 0) cboxSerialDataBits->setCurrentIndex(currData);
int currData = cboxDataBits->currentIndex();
cboxDataBits->clear();
cboxDataBits->addItems(dataBits);
if (currData >= 0) cboxDataBits->setCurrentIndex(currData);
 
int currStop = cboxSerialStopBits->currentIndex();
cboxSerialStopBits->clear();
cboxSerialStopBits->addItems(stopBits);
if (currStop >= 0) cboxSerialStopBits->setCurrentIndex(currStop);
int currStop = cboxStopBits->currentIndex();
cboxStopBits->clear();
cboxStopBits->addItems(stopBits);
if (currStop >= 0) cboxStopBits->setCurrentIndex(currStop);
 
int currParity = cboxSerialParity->currentIndex();
cboxSerialParity->clear();
cboxSerialParity->addItems(parity);
if (currParity >= 0) cboxSerialParity->setCurrentIndex(currParity);
int currParity = cboxParity->currentIndex();
cboxParity->clear();
cboxParity->addItems(parity);
if (currParity >= 0) cboxParity->setCurrentIndex(currParity);
 
int currFlow = cboxSerialFlowControl->currentIndex();
cboxSerialFlowControl->clear();
cboxSerialFlowControl->addItems(flowControl);
if (currFlow >= 0) cboxSerialFlowControl->setCurrentIndex(currFlow);
int currFlow = cboxFlowControl->currentIndex();
cboxFlowControl->clear();
cboxFlowControl->addItems(flowControl);
if (currFlow >= 0) cboxFlowControl->setCurrentIndex(currFlow);
}
 
void SerialWidget::Serial_LocalConnected()
void SerialWidget::LocalConnected()
{
btnSerialConnect->setText("&Disconnect");
btnConnect->setText("&Disconnect");
// cboxSerialPort->setEnabled(false);
// cboxSerialSpeed->setEnabled(false);
// cboxSerialDataBits->setEnabled(false);
126,24 → 126,24
// cboxSerialParity->setEnabled(false);
// cboxSerialFlowControl->setEnabled(false);
// btnSerialRefresh->setEnabled(false);
btnSerialRefresh->hide();
labelSerialPort->hide();
labelSerialSpeed->hide();
labelSerialDataBits->hide();
labelSerialStopBits->hide();
labelSerialParity->hide();
labelSerialFlowControl->hide();
cboxSerialPort->hide();
cboxSerialSpeed->hide();
cboxSerialDataBits->hide();
cboxSerialStopBits->hide();
cboxSerialParity->hide();
cboxSerialFlowControl->hide();
btnRefresh->hide();
labelPort->hide();
labelSpeed->hide();
labelDataBits->hide();
labelStopBits->hide();
labelParity->hide();
labelFlowControl->hide();
cboxPort->hide();
cboxSpeed->hide();
cboxDataBits->hide();
cboxStopBits->hide();
cboxParity->hide();
cboxFlowControl->hide();
}
 
void SerialWidget::Serial_LocalDisconnected()
void SerialWidget::LocalDisconnected()
{
btnSerialConnect->setText("&Connect");
btnConnect->setText("&Connect");
// cboxSerialPort->setEnabled(true);
// cboxSerialSpeed->setEnabled(true);
// cboxSerialDataBits->setEnabled(true);
151,29 → 151,29
// cboxSerialParity->setEnabled(true);
// cboxSerialFlowControl->setEnabled(true);
// btnSerialRefresh->setEnabled(true);
btnSerialRefresh->show();
labelSerialPort->show();
labelSerialSpeed->show();
labelSerialDataBits->show();
labelSerialStopBits->show();
labelSerialParity->show();
labelSerialFlowControl->show();
cboxSerialPort->show();
cboxSerialSpeed->show();
cboxSerialDataBits->show();
cboxSerialStopBits->show();
cboxSerialParity->show();
cboxSerialFlowControl->show();
btnRefresh->show();
labelPort->show();
labelSpeed->show();
labelDataBits->show();
labelStopBits->show();
labelParity->show();
labelFlowControl->show();
cboxPort->show();
cboxSpeed->show();
cboxDataBits->show();
cboxStopBits->show();
cboxParity->show();
cboxFlowControl->show();
}
 
void SerialWidget::Serial_ConnectToggleBtn()
void SerialWidget::ConnectToggleBtn()
{
if (serialHelper->connected) {
emit Serial_Disconnect();
emit Disconnect();
} else {
if (cboxSerialPort->currentText() != "" && cboxSerialSpeed->currentText() != "") {
emit Serial_Connect(cboxSerialPort->currentText(), cboxSerialSpeed->currentText(), cboxSerialDataBits->currentText(),
cboxSerialStopBits->currentText(), cboxSerialParity->currentText(), cboxSerialFlowControl->currentText());
if (cboxPort->currentText() != "" && cboxSpeed->currentText() != "") {
emit Connect(cboxPort->currentText(), cboxSpeed->currentText(), cboxDataBits->currentText(),
cboxStopBits->currentText(), cboxParity->currentText(), cboxFlowControl->currentText());
}
}
}
/Misc Projects/PcMarlinInterface/SerialWidget.h
13,26 → 13,26
 
public slots:
// Inbound from SerialHelper
void Serial_UpdateParameters(QStringList ports, QStringList speeds, QStringList dataBits,
QStringList stopBits, QStringList parity, QStringList flowControl);
void UpdateParameters(QStringList ports, QStringList speeds, QStringList dataBits,
QStringList stopBits, QStringList parity, QStringList flowControl);
 
// Local GUI processing
void Serial_ConnectToggleBtn(void);
void Serial_LocalConnected(void);
void Serial_LocalDisconnected(void);
void ConnectToggleBtn(void);
void LocalConnected(void);
void LocalDisconnected(void);
 
signals:
// Outbound to SerialHelper
void Serial_QueryParameters(void);
void Serial_Connect(QString port, QString speed, QString dataBits,
QString stopBits, QString parity, QString flowControl);
void Serial_Disconnect(void);
void Serial_TransmitByteArray(QByteArray data);
void QueryParameters(void);
void Connect(QString port, QString speed, QString dataBits,
QString stopBits, QString parity, QString flowControl);
void Disconnect(void);
void TransmitByteArray(QByteArray data);
 
// Outbound to MainWindow
void Serial_ReceivedByte(char byte);
void Serial_Connected(void);
void Serial_Disconnected(void);
void ReceivedByte(QByteArray data);
void Connected(void);
void Disconnected(void);
void UpdateStatus(QString string);
 
private:
39,20 → 39,20
SerialHelper *serialHelper;
QThread *serialThread;
 
QPushButton *btnSerialConnect;
QPushButton *btnSerialRefresh;
QLabel *labelSerialPort;
QLabel *labelSerialSpeed;
QLabel *labelSerialDataBits;
QLabel *labelSerialStopBits;
QLabel *labelSerialParity;
QLabel *labelSerialFlowControl;
QComboBox *cboxSerialPort;
QComboBox *cboxSerialSpeed;
QComboBox *cboxSerialDataBits;
QComboBox *cboxSerialStopBits;
QComboBox *cboxSerialParity;
QComboBox *cboxSerialFlowControl;
QPushButton *btnConnect;
QPushButton *btnRefresh;
QLabel *labelPort;
QLabel *labelSpeed;
QLabel *labelDataBits;
QLabel *labelStopBits;
QLabel *labelParity;
QLabel *labelFlowControl;
QComboBox *cboxPort;
QComboBox *cboxSpeed;
QComboBox *cboxDataBits;
QComboBox *cboxStopBits;
QComboBox *cboxParity;
QComboBox *cboxFlowControl;
};
 
#endif // SERIALWIDGET_H