/Misc Projects/PcMarlinInterface/SerialHelper.cpp |
---|
0,0 → 1,170 |
#include "SerialHelper.h" |
SerialHelper::SerialHelper(QObject *parent) : QObject(parent) |
{ |
connected = false; |
speeds << "9600" << "19200" << "38400" << "57600" << "115200" << "230400" << "250000"; |
dataBits << "8 Bits" << "7 Bits" << "6 Bits" << "5 Bits"; |
stopBits << "1 Bit" << "1.5 Bits" << "2 Bits"; |
parity << "None" << "Even" << "Odd" << "Space" << "Mark"; |
flowControl << "None" << "Hardware" << "Software"; |
} |
SerialHelper::~SerialHelper() |
{ |
serialPort->close(); |
delete serialPort; |
} |
void SerialHelper::Serial_QueryParameters() |
{ |
QList<QSerialPortInfo> portsList = QSerialPortInfo::availablePorts(); |
QStringList ports; |
for (int i = 0; i < portsList.size(); i++) { |
ports.append(portsList[i].portName()); |
} |
emit Serial_UpdateParameters(ports, speeds, dataBits, stopBits, parity, flowControl); |
} |
void SerialHelper::Serial_Connect(QString port, QString speed, QString dataBits, |
QString stopBits, QString parity, QString flowControl) |
{ |
if (!connected) { |
serialPort = new QSerialPort(); |
connect(serialPort, SIGNAL(readyRead()), this, SLOT(Serial_ProcessIncomingData())); |
connect(serialPort, SIGNAL(error(QSerialPort::SerialPortError)), this, SLOT(Serial_ProcessError(QSerialPort::SerialPortError))); |
serialPort->setPortName(port); |
if (serialPort->open(QIODevice::ReadWrite)) { |
connected = true; |
bool ok = false; |
int baud = speed.toInt(&ok); |
if (ok) serialPort->setBaudRate(baud); |
if (dataBits == "5 Bits") |
serialPort->setDataBits(QSerialPort::Data5); |
else if (dataBits == "6 Bits") |
serialPort->setDataBits(QSerialPort::Data6); |
else if (dataBits == "7 Bits") |
serialPort->setDataBits(QSerialPort::Data7); |
else |
serialPort->setDataBits(QSerialPort::Data8); |
if (stopBits == "1.5 Bits") |
serialPort->setStopBits(QSerialPort::OneAndHalfStop); |
else if (stopBits == "2 Bits") |
serialPort->setStopBits(QSerialPort::TwoStop); |
else |
serialPort->setStopBits(QSerialPort::OneStop); |
if (parity == "Even") |
serialPort->setParity(QSerialPort::EvenParity); |
else if (parity == "Odd") |
serialPort->setParity(QSerialPort::OddParity); |
else if (parity == "Space") |
serialPort->setParity(QSerialPort::SpaceParity); |
else if (parity == "Mark") |
serialPort->setParity(QSerialPort::MarkParity); |
else |
serialPort->setParity(QSerialPort::NoParity); |
if (flowControl == "Hardware") |
serialPort->setFlowControl(QSerialPort::HardwareControl); |
else if (flowControl == "Software") |
serialPort->setFlowControl(QSerialPort::SoftwareControl); |
else |
serialPort->setFlowControl(QSerialPort::NoFlowControl); |
// See http://umforum.ultimaker.com/index.php?/topic/5886-um2-controller-resetreboot-when-opening-usb-port-on-linux/ |
serialPort->setDataTerminalReady(1); |
if (ok) emit Serial_Connected(); |
else Serial_Disconnect(); |
} |
} |
} |
void SerialHelper::Serial_Disconnect() |
{ |
serialPort->disconnect(); |
serialPort->close(); |
delete serialPort; |
connected = false; |
emit Serial_Disconnected(); |
} |
void SerialHelper::Serial_TransmitString(QString string) |
{ |
serialPort->write(string.toStdString().c_str()); |
serialPort->write(SERIAL_NEWLINE_CHAR); |
} |
void SerialHelper::Serial_TransmitByteArray(QByteArray buffer) |
{ |
serialPort->write(buffer); |
} |
void SerialHelper::Serial_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]); |
} |
// 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) |
{ |
if (error == QSerialPort::NoError) return; |
switch(error) { |
case QSerialPort::DeviceNotFoundError: |
emit UpdateStatus("Serial Error: Nonexistant device"); |
return; |
case QSerialPort::PermissionError: |
emit UpdateStatus("Serial Error: Device already opened or lacking permission"); |
return; |
case QSerialPort::OpenError: |
emit UpdateStatus("Serial Error: Device already opened"); |
return; |
case QSerialPort::NotOpenError: |
emit UpdateStatus("Serial Error: Device not opened"); |
return; |
case QSerialPort::ParityError: |
emit UpdateStatus("Serial Error: Parity error detected"); |
break; |
case QSerialPort::FramingError: |
emit UpdateStatus("Serial Error: Framing error detected"); |
break; |
case QSerialPort::BreakConditionError: |
emit UpdateStatus("Serial Error: Break condition detected"); |
break; |
case QSerialPort::WriteError: |
emit UpdateStatus("Serial Error: Unable to write to device"); |
break; |
case QSerialPort::ReadError: |
emit UpdateStatus("Serial Error: Unable to read from device"); |
break; |
case QSerialPort::ResourceError: |
emit UpdateStatus("Serial Error: Device missing or disconnected"); |
break; |
case QSerialPort::UnsupportedOperationError: |
emit UpdateStatus("Serial Error: Operation not supported or prohibited"); |
break; |
case QSerialPort::TimeoutError: |
emit UpdateStatus("Serial Error: Timeout occurred"); |
break; |
case QSerialPort::UnknownError: |
emit UpdateStatus("Serial Error: Unknown error"); |
break; |
default: |
break; |
} |
serialPort->clearError(); |
Serial_Disconnect(); |
} |
/Misc Projects/PcMarlinInterface/SerialHelper.h |
---|
0,0 → 1,55 |
#ifndef SERIALHELPER_H |
#define SERIALHELPER_H |
#include "GlobalDefines.h" |
#include <QtSerialPort> |
#define SERIAL_NEWLINE_CHAR "\n" |
#define SERIAL_BUFFER_SIZE 32 |
class SerialHelper : public QObject |
{ |
Q_OBJECT |
public: |
SerialHelper(QObject *parent = 0); |
~SerialHelper(); |
bool connected; |
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(void); |
void Serial_TransmitString(QString string); |
void Serial_TransmitByteArray(QByteArray buffer); |
// Local processing of received data |
void Serial_ProcessIncomingData(void); |
void Serial_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 UpdateStatus(QString string); |
private: |
QSerialPort *serialPort; |
QStringList speeds; |
QStringList dataBits; |
QStringList stopBits; |
QStringList parity; |
QStringList flowControl; |
char bufferIn[SERIAL_BUFFER_SIZE]; |
int bufferInIndex; |
bool bufferInOverflow; |
QString currString; |
}; |
#endif // SERIALHELPER_H |
/Misc Projects/PcMarlinInterface/GlobalDefines.h |
---|
0,0 → 1,9 |
#ifndef GLOBALDEFINES |
#define GLOBALDEFINES |
#include <QtWidgets> |
#define STATUS_TIMEOUT_MS 3000 |
#endif // GLOBALDEFINES |
/Misc Projects/PcMarlinInterface/MacroController.cpp |
---|
0,0 → 1,401 |
#include "MacroController.h" |
MacroController::MacroController(QWidget *parent) : QWidget(parent) |
{ |
sigmapTransmit = new QSignalMapper(); |
sigmapKeybind = new QSignalMapper(); |
btnExport = new QPushButton("&Export"); |
btnImport = new QPushButton("&Import"); |
btnAddMacro = new QPushButton("&Add"); |
btnRemoveMacro = new QPushButton("&Remove"); |
btnClear = new QPushButton("&Clear"); |
currKeyBindInfo = QPair<QPushButton*,int>(NULL, 0); |
mainLayout = new QGridLayout(); |
macroCount = 0; |
connected = false; |
lastKnownFilePath = "."; |
ioLayout = new QHBoxLayout(); |
ioLayout->addWidget(btnAddMacro); |
ioLayout->addWidget(btnRemoveMacro); |
ioLayout->addWidget(btnClear); |
ioLayout->addWidget(btnExport); |
ioLayout->addWidget(btnImport); |
ioLayout->addStretch(); |
mainLayout->addLayout(ioLayout, 0, 0, 1, 2); |
for (int i = 0; i < MACRO_DEFAULT_COUNT; i++) { |
Macro_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))); |
// Register global event process for keyboard shortcut handling |
qApp->installEventFilter(this); |
} |
MacroController::~MacroController() |
{ |
} |
QSize MacroController::sizeHint() const |
{ |
return this->minimumSizeHint(); |
} |
void MacroController::Macro_EnableTransmit() |
{ |
connected = true; |
for (int i = 0; i < macroBtnSendList.size(); i++) { |
macroBtnSendList[i]->setEnabled(true); |
} |
} |
void MacroController::Macro_DisableTransmit() |
{ |
connected = false; |
for (int i = 0; i < macroBtnSendList.size(); i++) { |
macroBtnSendList[i]->setEnabled(false); |
} |
} |
void MacroController::Macro_InitTransmit(QWidget *t) |
{ |
if (connected) { |
QTextEdit *text = qobject_cast<QTextEdit*>(t); |
emit Macro_TransmitText(text->toPlainText()); |
} |
} |
void MacroController::Macro_KeybindPrompt(int id) |
{ |
QPushButton *btn = qobject_cast<QPushButton*>(sigmapKeybind->mapping(id)); |
// Check to make sure we arn't processing another key first |
if (currKeyBindInfo.first != NULL) { |
currKeyBindInfo.first->setText("Hotkey: None"); |
currKeyBindInfo.first->setDown(false); |
currKeyBindInfo.first->removeEventFilter(this); |
} |
// Mark and save button as waiting for key sequence |
btn->setDown(true); |
btn->setText("Waiting for Key.."); |
currKeyBindInfo = QPair<QPushButton*,int>(btn, id); |
// Remove current keybinding for this macro |
int index = registeredKeyMacroIDs.indexOf(id); |
if (index >= 0) { |
registeredKeySequences.removeAt(index); |
registeredKeyMacroIDs.removeAt(index); |
} |
// Inspect all following keyboard events |
btn->installEventFilter(this); |
} |
void MacroController::Macro_AddEntry() |
{ |
macroCount++; |
// Create new layout/widgets |
QLineEdit *lineEdit = new QLineEdit(QString("Macro %1").arg(macroCount)); |
lineEdit->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed); |
lineEdit->setMinimumWidth(100); |
lineEdit->setAlignment(Qt::AlignCenter); |
macroNameList.append(lineEdit); |
QTextEdit *textEdit = new QTextEdit(); |
textEdit->setMinimumHeight(50); |
textEdit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); |
textEdit->setWordWrapMode(QTextOption::NoWrap); |
textEdit->setFont(QFont("Consolas", 8)); |
textEdit->setAcceptRichText(false); |
textEdit->setTabChangesFocus(true); |
macroValueList.append(textEdit); |
QPushButton *keyButton = new QPushButton("Hotkey: None"); |
keyButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); |
macroBtnKeyList.append(keyButton); |
QPushButton *pushButton = new QPushButton("Send Macro"); |
pushButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); |
pushButton->setEnabled(connected); |
macroBtnSendList.append(pushButton); |
QVBoxLayout *tmpLayout = new QVBoxLayout(); |
tmpLayout->addWidget(lineEdit); |
tmpLayout->addWidget(keyButton); |
tmpLayout->addWidget(pushButton); |
// Add layout/widgets to main layout |
mainLayout->addLayout(tmpLayout, macroCount, 0); |
mainLayout->addWidget(textEdit, macroCount, 1); |
mainLayout->setColumnStretch(1, 1); |
// Associate KeyButton with its corresponding ID |
sigmapKeybind->setMapping(keyButton, macroCount-1); |
connect(keyButton, SIGNAL(clicked()), sigmapKeybind, SLOT(map())); |
// Associate PushButton with its corresponding TextEdit |
sigmapTransmit->setMapping(pushButton, textEdit); |
connect(pushButton, SIGNAL(clicked()), sigmapTransmit, SLOT(map())); |
QLayoutItem *item = mainLayout->itemAtPosition(1, 1); |
int height = item->widget()->height() + mainLayout->verticalSpacing(); |
QDockWidget *parent = qobject_cast<QDockWidget*>(this->parent()); |
if (parent->isFloating()) |
parent->resize(parent->width(), parent->height() + height); |
btnRemoveMacro->setEnabled(true); |
} |
void MacroController::Macro_RemoveEntry() |
{ |
// Remove and delete layout/widgets at last macro slot |
QLayoutItem *item = mainLayout->itemAtPosition(macroCount, 0); |
while(!item->isEmpty()) |
delete item->layout()->takeAt(0)->widget(); |
delete item; |
item = mainLayout->itemAtPosition(macroCount, 1); |
delete item->widget(); |
item = mainLayout->itemAtPosition(1, 1); |
int height = item->widget()->height() + mainLayout->verticalSpacing(); |
// Unmap and remove widgets from lists |
QPushButton *pushButton = macroBtnSendList.back(); |
sigmapTransmit->removeMappings(pushButton); |
QPushButton *keyButton = macroBtnKeyList.back(); |
sigmapKeybind->removeMappings(keyButton); |
macroNameList.pop_back(); |
macroValueList.pop_back(); |
macroBtnSendList.pop_back(); |
macroBtnKeyList.pop_back(); |
int index = registeredKeyMacroIDs.indexOf(macroCount-1); |
if (index >= 0) { |
registeredKeySequences.removeAt(index); |
registeredKeyMacroIDs.removeAt(index); |
} |
macroCount--; |
QDockWidget *parent = qobject_cast<QDockWidget*>(this->parent()); |
if (parent->isFloating()) |
parent->resize(parent->width(), parent->height() - height); |
if (macroCount == 1) |
btnRemoveMacro->setEnabled(false); |
} |
void MacroController::Macro_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"); |
} |
registeredKeyMacroIDs.clear(); |
registeredKeySequences.clear(); |
} |
void MacroController::Macro_WriteToFile() |
{ |
QString file = QFileDialog::getSaveFileName(this, "Settings XML File", lastKnownFilePath, "XML File (*.xml)"); |
QCoreApplication::processEvents(); // Wait for dialog to close |
if (file.size() == 0) return; |
// If file was selected, save directory for next time |
QFileInfo fileInfo = QFileInfo(file); |
lastKnownFilePath = fileInfo.absolutePath(); |
if (file.size() != 0) |
QFile::remove(file); |
QFile inputFile(file); |
if (!inputFile.open(QIODevice::ReadWrite | QIODevice::Text)) return; |
QXmlStreamWriter stream(&inputFile); |
stream.setAutoFormatting(true); |
stream.writeStartDocument(); |
stream.writeStartElement("Settings"); |
stream.writeStartElement("Macro"); |
for (int i = 0; i < macroCount; i++) { |
stream.writeStartElement("Macro_Entry"); |
stream.writeAttribute("Name", macroNameList[i]->text()); |
stream.writeTextElement("Value", macroValueList[i]->toPlainText()); |
int index = registeredKeyMacroIDs.indexOf(i); |
if (index >= 0) { |
stream.writeTextElement("Keybinding", registeredKeySequences[index].toString()); |
} else { |
stream.writeTextElement("Keybinding", ""); |
} |
stream.writeEndElement(); // Macro Entry |
} |
stream.writeEndElement(); // Macro |
stream.writeEndElement(); // Settings |
stream.writeEndDocument(); |
inputFile.close(); |
} |
void MacroController::Macro_ReadFromFile() |
{ |
int counter = 0; |
QString file = QFileDialog::getOpenFileName(this, "Settings XML File", lastKnownFilePath, "XML File (*.xml)"); |
QCoreApplication::processEvents(); // Wait for dialog to close |
if (file.size() == 0) return; |
Macro_Clear(); |
// If file was selected, save directory for next time |
QFileInfo fileInfo = QFileInfo(file); |
lastKnownFilePath = fileInfo.absolutePath(); |
QFile inputFile(file); |
if (!inputFile.open(QIODevice::ReadWrite | QIODevice::Text)) return; |
QXmlStreamReader stream(&inputFile); |
// Parse the XML file till we reach the end (or errors) |
while (!stream.atEnd() && !stream.hasError()) { |
QXmlStreamReader::TokenType token = stream.readNext(); |
// Ignore StartDocument |
if (token == QXmlStreamReader::StartDocument) continue; |
// Parse StartElements |
if (token == QXmlStreamReader::StartElement) { |
// Ignore elements <Settings> and <Macro> |
if (stream.name() == "Settings") continue; |
if (stream.name() == "Macro") continue; |
// Parse element <Macro_Entry> |
if (stream.name() == "Macro_Entry") { |
QString name, value, keybinding; |
// Read and save attribute value |
QXmlStreamAttributes attr = stream.attributes(); |
if (attr.hasAttribute("Name")) |
name = attr.value("Name").toString(); |
stream.readNext(); |
// Loop in this element to find all sub-elements |
while (!(stream.tokenType() == QXmlStreamReader::EndElement && stream.name() == "Macro_Entry")) { |
// Parse and save element value |
if (stream.tokenType() == QXmlStreamReader::StartElement) { |
if (stream.name() == "Value") { |
stream.readNext(); |
value = stream.text().toString(); |
} |
if (stream.name() == "Keybinding") { |
stream.readNext(); |
keybinding = stream.text().toString(); |
} |
} |
stream.readNext(); |
} |
// Write values to GUI |
if (counter == macroCount) |
Macro_AddEntry(); |
macroNameList[counter]->setText(name); |
macroValueList[counter]->setText(value); |
if (keybinding != "") { |
registeredKeySequences.append(QKeySequence(keybinding)); |
registeredKeyMacroIDs.append(counter); |
macroBtnKeyList[counter]->setText("Hotkey: " + keybinding); |
} |
counter++; |
} |
} |
} |
} |
bool MacroController::eventFilter(QObject *obj, QEvent *event) |
{ |
// Only process keyboard events |
if (event->type() == QEvent::KeyPress) { |
QKeyEvent *keyevent = static_cast<QKeyEvent*>(event); |
QKeySequence seq = keyevent->modifiers() + keyevent->key(); |
if ((keyevent->key() >= 0x21 && keyevent->key() <= 0x2F) || |
(keyevent->key() >= 0x3A && keyevent->key() <= 0x40) || |
(keyevent->key() >= 0x5E && keyevent->key() <= 0x7E) ) { |
seq = keyevent->key(); |
} |
if (connected) { |
// First check if key sequence matches any saved ones |
if (!registeredKeySequences.isEmpty()) { |
int index = registeredKeySequences.indexOf(seq); |
if (index >= 0) { |
Macro_InitTransmit(macroValueList[registeredKeyMacroIDs[index]]); |
return true; |
} |
} |
} |
// Then save key sequence if needed |
if (currKeyBindInfo.first != NULL) { |
// Ignore modifier keys and locks |
if (keyevent->key() == Qt::Key_Shift || keyevent->key() == Qt::Key_Control || |
keyevent->key() == Qt::Key_Meta || keyevent->key() == Qt::Key_Alt || |
keyevent->key() == Qt::Key_AltGr || keyevent->key() == Qt::Key_CapsLock || |
keyevent->key() == Qt::Key_NumLock || keyevent->key() == Qt::Key_ScrollLock) |
return true; |
// Reset on ESC key |
if (keyevent->key() == Qt::Key_Escape) { |
currKeyBindInfo.first->setText("Hotkey: None"); |
currKeyBindInfo.first->setDown(false); |
currKeyBindInfo.first->removeEventFilter(this); |
currKeyBindInfo = QPair<QPushButton*, int>(NULL, 0); |
return true; |
} |
// Otherwise save key sequence if it doesnt already exist |
if (!registeredKeySequences.contains(seq)) { |
registeredKeySequences.append(seq); |
registeredKeyMacroIDs.append(currKeyBindInfo.second); |
currKeyBindInfo.first->setText("Hotkey: " + seq.toString()); |
currKeyBindInfo.first->setDown(false); |
currKeyBindInfo.first->removeEventFilter(this); |
currKeyBindInfo = QPair<QPushButton*, int>(NULL, 0); |
return true; |
} |
} |
} |
return QWidget::eventFilter(obj, event); |
} |
/Misc Projects/PcMarlinInterface/MacroController.h |
---|
0,0 → 1,62 |
#ifndef MACROCONTROLLER |
#define MACROCONTROLLER |
#include "GlobalDefines.h" |
#define MACRO_DEFAULT_COUNT 4 |
class MacroController : public QWidget |
{ |
Q_OBJECT |
public: |
MacroController(QWidget *parent = 0); |
~MacroController(); |
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); |
signals: |
void Macro_TransmitText(QString string); |
protected: |
bool eventFilter(QObject *, QEvent *); |
private: |
int macroCount; |
bool connected; |
QString lastKnownFilePath; |
QPushButton *btnExport; |
QPushButton *btnImport; |
QPushButton *btnAddMacro; |
QPushButton *btnRemoveMacro; |
QPushButton *btnClear; |
QList<QLineEdit*> macroNameList; |
QList<QTextEdit*> macroValueList; |
QList<QPushButton*> macroBtnSendList; |
QList<QPushButton*> macroBtnKeyList; |
QList<QKeySequence> registeredKeySequences; |
QList<int> registeredKeyMacroIDs; |
QGridLayout *mainLayout; |
QHBoxLayout *ioLayout; |
QSignalMapper *sigmapTransmit; |
QSignalMapper *sigmapKeybind; |
QPair<QPushButton*,int> currKeyBindInfo; |
}; |
#endif // MACROCONTROLLER |
/Misc Projects/PcMarlinInterface/MainWindow.cpp |
---|
0,0 → 1,120 |
#include "MainWindow.h" |
MainWindow::MainWindow(QWidget *parent) : |
QMainWindow(parent) |
{ |
// Set central widget |
centralWidget = new QWidget(); |
setCentralWidget(centralWidget); |
// Serial data UI |
groupSerialData = new QGroupBox("Data"); |
textSerialData = new QTextEdit(); |
textSerialData->setCurrentFont(QFont("Consolas", 8)); |
textSerialData->append("Waiting for serial connection..."); |
textSerialData->setMinimumHeight(100); |
textSerialData->setReadOnly(true); |
textSerialTransmit = new QLineEdit(); |
textSerialTransmit->setFont(QFont("Consolas", 8)); |
btnSerialTransmit = new QPushButton("&Send"); |
btnSerialClear = new QPushButton("Clear"); |
QHBoxLayout *serialTransmitLayout = new QHBoxLayout(); |
serialTransmitLayout->addWidget(textSerialTransmit); |
serialTransmitLayout->addWidget(btnSerialTransmit); |
serialTransmitLayout->addWidget(btnSerialClear); |
QVBoxLayout *serialDataLayout = new QVBoxLayout(); |
serialDataLayout->addWidget(textSerialData); |
serialDataLayout->addLayout(serialTransmitLayout); |
groupSerialData->setLayout(serialDataLayout); |
// Macro controller |
groupMacro = new QGroupBox("Other"); |
btnMacro = new QPushButton("&Macros"); |
QHBoxLayout *macroLayout = new QHBoxLayout(); |
macroLayout->addWidget(btnMacro); |
groupMacro->setLayout(macroLayout); |
// Initialize serial controller |
serialController = new SerialController(); |
groupSerialInit = new QGroupBox("Serial Connection"); |
QGridLayout *serialInitLayout = new QGridLayout(); |
serialInitLayout->setContentsMargins(0, 0, 0, 0); |
serialInitLayout->addWidget(serialController); |
groupSerialInit->setLayout(serialInitLayout); |
connect(serialController, SIGNAL(UpdateStatus(QString)), this, SLOT(UpdateSerialStatus(QString))); |
// Initialize macro controller |
macroDockWidget = new QDockWidget("Macro Controller", this); |
macroController = new MacroController(macroDockWidget); |
macroDockWidget->setWidget(macroController); |
macroDockWidget->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); |
macroDockWidget->hide(); |
addDockWidget(Qt::RightDockWidgetArea, macroDockWidget); |
connect(macroController, SIGNAL(Macro_TransmitText(QString)), this, SLOT(Serial_PrepareTransmit(QString))); |
connect(serialController, SIGNAL(Serial_Connected()), macroController, SLOT(Macro_EnableTransmit())); |
connect(serialController, SIGNAL(Serial_Disconnected()), macroController, SLOT(Macro_DisableTransmit())); |
// Connect local widgets |
connect(btnSerialTransmit, SIGNAL(clicked()), this, SLOT(Serial_PrepareTransmit())); |
connect(textSerialTransmit, SIGNAL(returnPressed()), btnSerialTransmit, SIGNAL(clicked())); |
connect(btnSerialClear, SIGNAL(clicked()), this, SLOT(Serial_ClearBtn())); |
connect(btnMacro, SIGNAL(clicked()), macroDockWidget->toggleViewAction(), SLOT(trigger())); |
// Main layout |
QGridLayout *mainLayout = new QGridLayout(); |
mainLayout->addWidget(groupSerialInit, 0, 0, 1, 1, Qt::AlignLeft); |
mainLayout->addWidget(groupMacro, 0, 1, 1, 1, Qt::AlignLeft); |
mainLayout->addWidget(groupSerialData, 1, 0, 1, 2); |
mainLayout->setColumnStretch(0, 0); |
mainLayout->setColumnStretch(1, 1); |
centralWidget->setLayout(mainLayout); |
setWindowTitle("Marlin Controller"); |
setWindowIcon(QIcon(":/External/Resources/Icon_16.bmp")); |
statusSerial = new QLabel("Serial Status: Disconnected"); |
statusSerial->setMinimumWidth(300); |
statusBar()->addPermanentWidget(statusSerial); |
} |
MainWindow::~MainWindow() |
{ |
} |
void MainWindow::Serial_PrepareTransmit(QString string) |
{ |
if (string == "") { |
string = textSerialTransmit->text(); |
textSerialTransmit->setText(""); |
} |
emit Serial_TransmitString(string); |
textSerialData->setTextColor(Qt::darkBlue); |
QStringList cmds = string.split('\n'); |
for (int i = 0; i < cmds.size(); i++) { |
textSerialData->append("TX: " + cmds[i]); |
} |
} |
void MainWindow::Serial_ClearBtn() |
{ |
textSerialData->clear(); |
} |
void MainWindow::Serial_ReceivedString(QString string) |
{ |
textSerialData->setTextColor(Qt::darkRed); |
textSerialData->append("RX: " + string); |
} |
void MainWindow::UpdateStatus(QString string) |
{ |
statusBar()->showMessage(string, STATUS_TIMEOUT_MS); |
} |
void MainWindow::UpdateSerialStatus(QString string) |
{ |
statusSerial->setText(string); |
} |
/Misc Projects/PcMarlinInterface/MainWindow.h |
---|
0,0 → 1,55 |
#ifndef MAINWINDOW_H |
#define MAINWINDOW_H |
#include "GlobalDefines.h" |
#include "SerialController.h" |
#include "MacroController.h" |
class MainWindow : public QMainWindow |
{ |
Q_OBJECT |
public: |
explicit MainWindow(QWidget *parent = 0); |
~MainWindow(); |
public slots: |
void Serial_PrepareTransmit(QString string = ""); |
void Serial_ReceivedString(QString string); |
void Serial_ClearBtn(void); |
void UpdateStatus(QString string); |
void UpdateSerialStatus(QString string); |
signals: |
void Serial_TransmitString(QString string); |
protected: |
private: |
QWidget *centralWidget; |
// Serial controller + UI |
SerialController *serialController; |
QGroupBox *groupSerialInit; |
QPushButton *btnSerialConnect; |
// Serial data |
QGroupBox *groupSerialData; |
QTextEdit *textSerialData; |
QLineEdit *textSerialTransmit; |
QPushButton *btnSerialTransmit; |
QPushButton *btnSerialClear; |
// Macro controller + UI |
MacroController *macroController; |
QDockWidget *macroDockWidget; |
QGroupBox *groupMacro; |
QPushButton *btnMacro; |
QLabel *statusSerial; |
}; |
#endif // MAINWINDOW_H |
/Misc Projects/PcMarlinInterface/PcMarlinInterface.pro |
---|
0,0 → 1,29 |
#------------------------------------------------- |
# |
# Project created by QtCreator 2015-01-02T06:41:32 |
# |
#------------------------------------------------- |
QT += core gui serialport |
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets |
TARGET = PcMarlinInterface |
TEMPLATE = app |
SOURCES += main.cpp \ |
MainWindow.cpp \ |
SerialController.cpp \ |
MacroController.cpp \ |
SerialHelper.cpp |
HEADERS += GlobalDefines.h \ |
MainWindow.h \ |
SerialController.h \ |
MacroController.h \ |
SerialHelper.h |
RESOURCES += Resources.qrc |
RC_FILE = Icon.rc |
/Misc Projects/PcMarlinInterface/PcMarlinInterface.pro.user |
---|
0,0 → 1,257 |
<?xml version="1.0" encoding="UTF-8"?> |
<!DOCTYPE QtCreatorProject> |
<!-- Written by QtCreator 3.3.0, 2015-01-07T23:41:29. --> |
<qtcreator> |
<data> |
<variable>EnvironmentId</variable> |
<value type="QByteArray">{4c29e835-aad4-4677-99d7-2a63e01ab69b}</value> |
</data> |
<data> |
<variable>ProjectExplorer.Project.ActiveTarget</variable> |
<value type="int">0</value> |
</data> |
<data> |
<variable>ProjectExplorer.Project.EditorSettings</variable> |
<valuemap type="QVariantMap"> |
<value type="bool" key="EditorConfiguration.AutoIndent">true</value> |
<value type="bool" key="EditorConfiguration.AutoSpacesForTabs">false</value> |
<value type="bool" key="EditorConfiguration.CamelCaseNavigation">true</value> |
<valuemap type="QVariantMap" key="EditorConfiguration.CodeStyle.0"> |
<value type="QString" key="language">Cpp</value> |
<valuemap type="QVariantMap" key="value"> |
<value type="QByteArray" key="CurrentPreferences">CppGlobal</value> |
</valuemap> |
</valuemap> |
<valuemap type="QVariantMap" key="EditorConfiguration.CodeStyle.1"> |
<value type="QString" key="language">QmlJS</value> |
<valuemap type="QVariantMap" key="value"> |
<value type="QByteArray" key="CurrentPreferences">QmlJSGlobal</value> |
</valuemap> |
</valuemap> |
<value type="int" key="EditorConfiguration.CodeStyle.Count">2</value> |
<value type="QByteArray" key="EditorConfiguration.Codec">UTF-8</value> |
<value type="bool" key="EditorConfiguration.ConstrainTooltips">false</value> |
<value type="int" key="EditorConfiguration.IndentSize">4</value> |
<value type="bool" key="EditorConfiguration.KeyboardTooltips">false</value> |
<value type="int" key="EditorConfiguration.MarginColumn">80</value> |
<value type="bool" key="EditorConfiguration.MouseHiding">true</value> |
<value type="bool" key="EditorConfiguration.MouseNavigation">true</value> |
<value type="int" key="EditorConfiguration.PaddingMode">1</value> |
<value type="bool" key="EditorConfiguration.ScrollWheelZooming">true</value> |
<value type="bool" key="EditorConfiguration.ShowMargin">false</value> |
<value type="int" key="EditorConfiguration.SmartBackspaceBehavior">0</value> |
<value type="bool" key="EditorConfiguration.SpacesForTabs">true</value> |
<value type="int" key="EditorConfiguration.TabKeyBehavior">0</value> |
<value type="int" key="EditorConfiguration.TabSize">8</value> |
<value type="bool" key="EditorConfiguration.UseGlobal">true</value> |
<value type="int" key="EditorConfiguration.Utf8BomBehavior">1</value> |
<value type="bool" key="EditorConfiguration.addFinalNewLine">true</value> |
<value type="bool" key="EditorConfiguration.cleanIndentation">true</value> |
<value type="bool" key="EditorConfiguration.cleanWhitespace">true</value> |
<value type="bool" key="EditorConfiguration.inEntireDocument">false</value> |
</valuemap> |
</data> |
<data> |
<variable>ProjectExplorer.Project.PluginSettings</variable> |
<valuemap type="QVariantMap"/> |
</data> |
<data> |
<variable>ProjectExplorer.Project.Target.0</variable> |
<valuemap type="QVariantMap"> |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop Qt 5.4.0 MSVC2013 64bit</value> |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Desktop Qt 5.4.0 MSVC2013 64bit</value> |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">qt.54.win64_msvc2013_64_kit</value> |
<value type="int" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value> |
<value type="int" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value> |
<value type="int" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value> |
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0"> |
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">C:/Users/Kevin/Documents/Code/QT/PcMarlinInterface/build-PcMarlinInterface_Qt_5_4_0_MSVC2013_64bit</value> |
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0"> |
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0"> |
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value> |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">qmake</value> |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value> |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">QtProjectManager.QMakeBuildStep</value> |
<value type="bool" key="QtProjectManager.QMakeBuildStep.LinkQmlDebuggingLibrary">false</value> |
<value type="bool" key="QtProjectManager.QMakeBuildStep.LinkQmlDebuggingLibraryAuto">true</value> |
<value type="QString" key="QtProjectManager.QMakeBuildStep.QMakeArguments"></value> |
<value type="bool" key="QtProjectManager.QMakeBuildStep.QMakeForced">false</value> |
<value type="bool" key="QtProjectManager.QMakeBuildStep.UseQtQuickCompiler">false</value> |
</valuemap> |
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.1"> |
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value> |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Make</value> |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value> |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value> |
<valuelist type="QVariantList" key="Qt4ProjectManager.MakeStep.AutomaticallyAddedMakeArguments"/> |
<value type="bool" key="Qt4ProjectManager.MakeStep.Clean">false</value> |
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments"></value> |
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeCommand"></value> |
</valuemap> |
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">2</value> |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Build</value> |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value> |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value> |
</valuemap> |
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1"> |
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0"> |
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value> |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Make</value> |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value> |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value> |
<valuelist type="QVariantList" key="Qt4ProjectManager.MakeStep.AutomaticallyAddedMakeArguments"/> |
<value type="bool" key="Qt4ProjectManager.MakeStep.Clean">true</value> |
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments">clean</value> |
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeCommand"></value> |
</valuemap> |
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">1</value> |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Clean</value> |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value> |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value> |
</valuemap> |
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value> |
<value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value> |
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/> |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Debug</value> |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value> |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4BuildConfiguration</value> |
<value type="int" key="Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration">2</value> |
<value type="bool" key="Qt4ProjectManager.Qt4BuildConfiguration.UseShadowBuild">true</value> |
</valuemap> |
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.1"> |
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">C:/Users/Kevin/Documents/Code/QT/PcMarlinInterface/build-PcMarlinInterface_Qt_5_4_0_MSVC2013_64bit</value> |
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0"> |
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0"> |
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value> |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">qmake</value> |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value> |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">QtProjectManager.QMakeBuildStep</value> |
<value type="bool" key="QtProjectManager.QMakeBuildStep.LinkQmlDebuggingLibrary">false</value> |
<value type="bool" key="QtProjectManager.QMakeBuildStep.LinkQmlDebuggingLibraryAuto">true</value> |
<value type="QString" key="QtProjectManager.QMakeBuildStep.QMakeArguments"></value> |
<value type="bool" key="QtProjectManager.QMakeBuildStep.QMakeForced">false</value> |
<value type="bool" key="QtProjectManager.QMakeBuildStep.UseQtQuickCompiler">false</value> |
</valuemap> |
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.1"> |
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value> |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Make</value> |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value> |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value> |
<valuelist type="QVariantList" key="Qt4ProjectManager.MakeStep.AutomaticallyAddedMakeArguments"/> |
<value type="bool" key="Qt4ProjectManager.MakeStep.Clean">false</value> |
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments"></value> |
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeCommand"></value> |
</valuemap> |
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">2</value> |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Build</value> |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value> |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value> |
</valuemap> |
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1"> |
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0"> |
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value> |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Make</value> |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value> |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value> |
<valuelist type="QVariantList" key="Qt4ProjectManager.MakeStep.AutomaticallyAddedMakeArguments"/> |
<value type="bool" key="Qt4ProjectManager.MakeStep.Clean">true</value> |
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments">clean</value> |
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeCommand"></value> |
</valuemap> |
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">1</value> |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Clean</value> |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value> |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value> |
</valuemap> |
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value> |
<value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value> |
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/> |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Release</value> |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value> |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4BuildConfiguration</value> |
<value type="int" key="Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration">0</value> |
<value type="bool" key="Qt4ProjectManager.Qt4BuildConfiguration.UseShadowBuild">true</value> |
</valuemap> |
<value type="int" key="ProjectExplorer.Target.BuildConfigurationCount">2</value> |
<valuemap type="QVariantMap" key="ProjectExplorer.Target.DeployConfiguration.0"> |
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0"> |
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">0</value> |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Deploy</value> |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value> |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Deploy</value> |
</valuemap> |
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">1</value> |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Deploy locally</value> |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value> |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.DefaultDeployConfiguration</value> |
</valuemap> |
<value type="int" key="ProjectExplorer.Target.DeployConfigurationCount">1</value> |
<valuemap type="QVariantMap" key="ProjectExplorer.Target.PluginSettings"/> |
<valuemap type="QVariantMap" key="ProjectExplorer.Target.RunConfiguration.0"> |
<valuelist type="QVariantList" key="Analyzer.Valgrind.AddedSuppressionFiles"/> |
<value type="bool" key="Analyzer.Valgrind.Callgrind.CollectBusEvents">false</value> |
<value type="bool" key="Analyzer.Valgrind.Callgrind.CollectSystime">false</value> |
<value type="bool" key="Analyzer.Valgrind.Callgrind.EnableBranchSim">false</value> |
<value type="bool" key="Analyzer.Valgrind.Callgrind.EnableCacheSim">false</value> |
<value type="bool" key="Analyzer.Valgrind.Callgrind.EnableEventToolTips">true</value> |
<value type="double" key="Analyzer.Valgrind.Callgrind.MinimumCostRatio">0.01</value> |
<value type="double" key="Analyzer.Valgrind.Callgrind.VisualisationMinimumCostRatio">10</value> |
<value type="bool" key="Analyzer.Valgrind.FilterExternalIssues">true</value> |
<value type="int" key="Analyzer.Valgrind.LeakCheckOnFinish">1</value> |
<value type="int" key="Analyzer.Valgrind.NumCallers">25</value> |
<valuelist type="QVariantList" key="Analyzer.Valgrind.RemovedSuppressionFiles"/> |
<value type="int" key="Analyzer.Valgrind.SelfModifyingCodeDetection">1</value> |
<value type="bool" key="Analyzer.Valgrind.Settings.UseGlobalSettings">true</value> |
<value type="bool" key="Analyzer.Valgrind.ShowReachable">false</value> |
<value type="bool" key="Analyzer.Valgrind.TrackOrigins">true</value> |
<value type="QString" key="Analyzer.Valgrind.ValgrindExecutable">valgrind</value> |
<valuelist type="QVariantList" key="Analyzer.Valgrind.VisibleErrorKinds"> |
<value type="int">0</value> |
<value type="int">1</value> |
<value type="int">2</value> |
<value type="int">3</value> |
<value type="int">4</value> |
<value type="int">5</value> |
<value type="int">6</value> |
<value type="int">7</value> |
<value type="int">8</value> |
<value type="int">9</value> |
<value type="int">10</value> |
<value type="int">11</value> |
<value type="int">12</value> |
<value type="int">13</value> |
<value type="int">14</value> |
</valuelist> |
<value type="int" key="PE.EnvironmentAspect.Base">2</value> |
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/> |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">PcMarlinInterface</value> |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value> |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4RunConfiguration:C:/Users/Kevin/Documents/Code/QT/PcMarlinInterface/PcMarlinInterface.pro</value> |
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.CommandLineArguments"></value> |
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.ProFile">PcMarlinInterface.pro</value> |
<value type="bool" key="Qt4ProjectManager.Qt4RunConfiguration.UseDyldImageSuffix">false</value> |
<value type="bool" key="Qt4ProjectManager.Qt4RunConfiguration.UseTerminal">false</value> |
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.UserWorkingDirectory"></value> |
<value type="uint" key="RunConfiguration.QmlDebugServerPort">3768</value> |
<value type="bool" key="RunConfiguration.UseCppDebugger">false</value> |
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value> |
<value type="bool" key="RunConfiguration.UseMultiProcess">false</value> |
<value type="bool" key="RunConfiguration.UseQmlDebugger">false</value> |
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value> |
</valuemap> |
<value type="int" key="ProjectExplorer.Target.RunConfigurationCount">1</value> |
</valuemap> |
</data> |
<data> |
<variable>ProjectExplorer.Project.TargetCount</variable> |
<value type="int">1</value> |
</data> |
<data> |
<variable>ProjectExplorer.Project.Updater.FileVersion</variable> |
<value type="int">18</value> |
</data> |
<data> |
<variable>Version</variable> |
<value type="int">18</value> |
</data> |
</qtcreator> |
/Misc Projects/PcMarlinInterface/SerialController.cpp |
---|
0,0 → 1,227 |
#include "SerialController.h" |
SerialController::SerialController(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); |
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(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); |
setLayout(serialSettingsLayout); |
serialHelper = new SerialHelper(); |
serialThread = new QThread(); |
serialHelper->moveToThread(serialThread); |
connect(serialHelper, SIGNAL(UpdateStatus(QString)), this, SIGNAL(UpdateStatus(QString))); |
// Parameters |
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 |
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())); |
// Disconnect |
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())); |
// Transmit |
connect(this, SIGNAL(Serial_TransmitString(QString)), serialHelper, SLOT(Serial_TransmitString(QString))); |
connect(this, SIGNAL(Serial_TransmitByteArray(QByteArray)), serialHelper, SLOT(Serial_TransmitByteArray(QByteArray))); |
// Receive |
connect(serialHelper, SIGNAL(Serial_ReceivedByte(char)), this, SIGNAL(Serial_ReceivedByte(char))); |
// Threading |
connect(serialThread, SIGNAL(finished()), serialHelper, SLOT(deleteLater())); |
serialThread->start(); |
// Local GUI |
connect(btnSerialConnect, SIGNAL(clicked()), this, SLOT(Serial_ConnectToggleBtn())); |
connect(btnSerialRefresh, SIGNAL(clicked()), this, SIGNAL(Serial_QueryParameters())); |
emit Serial_QueryParameters(); |
Serial_LocalDisconnected(); |
} |
SerialController::~SerialController() |
{ |
serialThread->quit(); |
} |
void SerialController::Serial_UpdateParameters(QStringList ports, QStringList speeds, QStringList dataBits, |
QStringList stopBits, QStringList parity, QStringList flowControl) |
{ |
QString currPort = cboxSerialPort->currentText(); |
cboxSerialPort->clear(); |
cboxSerialPort->addItems(ports); |
if (currPort != "" && ports.contains(currPort)) |
cboxSerialPort->setCurrentText(currPort); |
QString currSpeed = cboxSerialSpeed->currentText(); |
cboxSerialSpeed->clear(); |
cboxSerialSpeed->addItems(speeds); |
if (currSpeed != "") cboxSerialSpeed->setCurrentText(currSpeed); |
int currData = cboxSerialDataBits->currentIndex(); |
cboxSerialDataBits->clear(); |
cboxSerialDataBits->addItems(dataBits); |
if (currData >= 0) cboxSerialDataBits->setCurrentIndex(currData); |
int currStop = cboxSerialStopBits->currentIndex(); |
cboxSerialStopBits->clear(); |
cboxSerialStopBits->addItems(stopBits); |
if (currStop >= 0) cboxSerialStopBits->setCurrentIndex(currStop); |
int currParity = cboxSerialParity->currentIndex(); |
cboxSerialParity->clear(); |
cboxSerialParity->addItems(parity); |
if (currParity >= 0) cboxSerialParity->setCurrentIndex(currParity); |
int currFlow = cboxSerialFlowControl->currentIndex(); |
cboxSerialFlowControl->clear(); |
cboxSerialFlowControl->addItems(flowControl); |
if (currFlow >= 0) cboxSerialFlowControl->setCurrentIndex(currFlow); |
} |
void SerialController::Serial_LocalConnected() |
{ |
btnSerialConnect->setText("&Disconnect"); |
// cboxSerialPort->setEnabled(false); |
// cboxSerialSpeed->setEnabled(false); |
// cboxSerialDataBits->setEnabled(false); |
// cboxSerialStopBits->setEnabled(false); |
// 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(); |
emit UpdateStatus("Serial: Connected"); |
} |
void SerialController::Serial_LocalDisconnected() |
{ |
btnSerialConnect->setText("&Connect"); |
// cboxSerialPort->setEnabled(true); |
// cboxSerialSpeed->setEnabled(true); |
// cboxSerialDataBits->setEnabled(true); |
// cboxSerialStopBits->setEnabled(true); |
// 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(); |
emit UpdateStatus("Serial: Disconnected"); |
} |
void SerialController::Serial_ConnectToggleBtn() |
{ |
if (serialHelper->connected) { |
emit Serial_Disconnect(); |
} else { |
if (cboxSerialPort->currentText() != "" && cboxSerialSpeed->currentText() != "") { |
emit Serial_Connect(cboxSerialPort->currentText(), cboxSerialSpeed->currentText(), cboxSerialDataBits->currentText(), |
cboxSerialStopBits->currentText(), cboxSerialParity->currentText(), cboxSerialFlowControl->currentText()); |
} |
} |
} |
//void SerialController::Serial_ProcessIncomingData() |
//{ |
// char tmpBuffer[SERIAL_BUFFER_SIZE]; |
// int len = serialPort->read(tmpBuffer, sizeof(tmpBuffer)); |
// while (len > 0) { |
// for (int i = 0; i < len; i++) { |
// // Save received data into local buffer |
// bufferIn[bufferInIndex] = tmpBuffer[i]; |
// // If newline char is received, end current string |
// if (tmpBuffer[i] == '\n') { |
// if (bufferInOverflow) |
// currString.append(QString::fromLocal8Bit(bufferIn, bufferInIndex)); |
// else |
// currString = QString::fromLocal8Bit(bufferIn, bufferInIndex); |
// bufferInOverflow = false; |
// bufferInIndex = 0; |
// emit Serial_ReceivedString(currString); |
// } else { |
// bufferInIndex++; |
// } |
// // If received string is larger than our serial buffer, append to previous data |
// if (bufferInIndex == SERIAL_BUFFER_SIZE-1) { |
// bufferIn[SERIAL_BUFFER_SIZE-1] = 0x0; |
// if (bufferInOverflow) |
// currString.append(QString::fromLocal8Bit(bufferIn, bufferInIndex)); |
// else |
// currString = QString::fromLocal8Bit(bufferIn, bufferInIndex); |
// bufferInOverflow = true; |
// bufferInIndex = 0; |
// } |
// } |
// // Check if there is more data to be read from the serial port |
// len = serialPort->read(tmpBuffer, sizeof(tmpBuffer)); |
// } |
//} |
/Misc Projects/PcMarlinInterface/SerialController.h |
---|
0,0 → 1,59 |
#ifndef SERIALCONTROLLER_H |
#define SERIALCONTROLLER_H |
#include "GlobalDefines.h" |
#include "SerialHelper.h" |
class SerialController : public QWidget |
{ |
Q_OBJECT |
public: |
SerialController(QWidget *parent = 0); |
~SerialController(); |
public slots: |
// Inbound from SerialHelper |
void Serial_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); |
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_TransmitString(QString string); |
void Serial_TransmitByteArray(QByteArray buffer); |
// Outbound to MainWindow |
void Serial_ReceivedByte(char byte); |
void Serial_Connected(void); |
void Serial_Disconnected(void); |
void UpdateStatus(QString string); |
private: |
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; |
}; |
#endif // SERIALCONTROLLER_H |
/Misc Projects/PcMarlinInterface/Resources/Icon.ico |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = application/octet-stream |
/Misc Projects/PcMarlinInterface/Resources/Icon.ico |
---|
Property changes: |
Added: svn:mime-type |
+application/octet-stream |
\ No newline at end of property |
/Misc Projects/PcMarlinInterface/Resources/Icon_16.bmp |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = application/octet-stream |
/Misc Projects/PcMarlinInterface/Resources/Icon_16.bmp |
---|
Property changes: |
Added: svn:mime-type |
+application/octet-stream |
\ No newline at end of property |
/Misc Projects/PcMarlinInterface/Resources/Icon_32.bmp |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = application/octet-stream |
/Misc Projects/PcMarlinInterface/Resources/Icon_32.bmp |
---|
Property changes: |
Added: svn:mime-type |
+application/octet-stream |
\ No newline at end of property |
/Misc Projects/PcMarlinInterface/Resources/Icon_64.bmp |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = application/octet-stream |
/Misc Projects/PcMarlinInterface/Resources/Icon_64.bmp |
---|
Property changes: |
Added: svn:mime-type |
+application/octet-stream |
\ No newline at end of property |
/Misc Projects/PcMarlinInterface/Icon.rc |
---|
0,0 → 1,0 |
IDI_ICON1 ICON DISCARDABLE "Resources\Icon.ico" |
/Misc Projects/PcMarlinInterface/Resources.qrc |
---|
0,0 → 1,7 |
<RCC> |
<qresource prefix="/External"> |
<file>Resources/Icon_16.bmp</file> |
<file>Resources/Icon_32.bmp</file> |
<file>Resources/Icon_64.bmp</file> |
</qresource> |
</RCC> |
/Misc Projects/PcMarlinInterface/main.cpp |
---|
0,0 → 1,11 |
#include "MainWindow.h" |
#include <QApplication> |
int main(int argc, char *argv[]) |
{ |
QApplication a(argc, argv); |
MainWindow w; |
w.show(); |
return a.exec(); |
} |