mirror of
https://github.com/caperren/school_archives.git
synced 2025-11-09 21:51:15 +00:00
Added old firmware and pcb design files
These are all design documents that I thought I had lost. It's may make me cringe, but it's still cool to use it to see how far I've come.
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
[.ShellClassInfo]
|
||||
IconResource=C:\Users\Corwin\AppData\Roaming\Insync\App\res\shared-folder-vista-7.ico,0
|
||||
@@ -0,0 +1,2 @@
|
||||
[.ShellClassInfo]
|
||||
IconResource=C:\Users\Corwin\AppData\Roaming\Insync\App\res\shared-folder-vista-7.ico,0
|
||||
@@ -0,0 +1,6 @@
|
||||
TEMPLATE = app
|
||||
DEPENDPATH += .
|
||||
CONFIG += console
|
||||
include(../../src/qextserialport.pri)
|
||||
SOURCES += main.cpp
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* @file main.cpp
|
||||
* @brief Main file.
|
||||
* @author Micha? Policht
|
||||
*/
|
||||
//! [0]
|
||||
#include "qextserialenumerator.h"
|
||||
//! [0]
|
||||
#include <QtCore/QList>
|
||||
#include <QtCore/QDebug>
|
||||
int main()
|
||||
{
|
||||
//! [1]
|
||||
QList<QextPortInfo> ports = QextSerialEnumerator::getPorts();
|
||||
//! [1]
|
||||
qDebug() << "List of ports:";
|
||||
//! [2]
|
||||
foreach (QextPortInfo info, ports) {
|
||||
qDebug() << "port name:" << info.portName;
|
||||
qDebug() << "friendly name:" << info.friendName;
|
||||
qDebug() << "physical name:" << info.physName;
|
||||
qDebug() << "enumerator name:" << info.enumName;
|
||||
qDebug() << "vendor ID:" << info.vendorID;
|
||||
qDebug() << "product ID:" << info.productID;
|
||||
|
||||
qDebug() << "===================================";
|
||||
}
|
||||
//! [2]
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
|
||||
#include "PortListener.h"
|
||||
#include <QtDebug>
|
||||
|
||||
PortListener::PortListener(const QString &portName)
|
||||
{
|
||||
qDebug() << "hi there";
|
||||
this->port = new QextSerialPort(portName, QextSerialPort::EventDriven);
|
||||
port->setBaudRate(BAUD9600);
|
||||
port->setFlowControl(FLOW_OFF);
|
||||
port->setParity(PAR_NONE);
|
||||
port->setDataBits(DATA_8);
|
||||
port->setStopBits(STOP_2);
|
||||
|
||||
if (port->open(QIODevice::ReadWrite) == true) {
|
||||
connect(port, SIGNAL(readyRead()), this, SLOT(onReadyRead()));
|
||||
connect(port, SIGNAL(dsrChanged(bool)), this, SLOT(onDsrChanged(bool)));
|
||||
if (!(port->lineStatus() & LS_DSR))
|
||||
qDebug() << "warning: device is not turned on";
|
||||
qDebug() << "listening for data on" << port->portName();
|
||||
}
|
||||
else {
|
||||
qDebug() << "device failed to open:" << port->errorString();
|
||||
}
|
||||
}
|
||||
|
||||
void PortListener::onReadyRead()
|
||||
{
|
||||
QByteArray bytes;
|
||||
int a = port->bytesAvailable();
|
||||
bytes.resize(a);
|
||||
port->read(bytes.data(), bytes.size());
|
||||
qDebug() << "bytes read:" << bytes.size();
|
||||
qDebug() << "bytes:" << bytes;
|
||||
}
|
||||
|
||||
void PortListener::onDsrChanged(bool status)
|
||||
{
|
||||
if (status)
|
||||
qDebug() << "device was turned on";
|
||||
else
|
||||
qDebug() << "device was turned off";
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
|
||||
|
||||
|
||||
#ifndef PORTLISTENER_H_
|
||||
#define PORTLISTENER_H_
|
||||
|
||||
#include <QObject>
|
||||
#include "qextserialport.h"
|
||||
|
||||
class PortListener : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
PortListener(const QString &portName);
|
||||
|
||||
private:
|
||||
QextSerialPort *port;
|
||||
|
||||
private slots:
|
||||
void onReadyRead();
|
||||
void onDsrChanged(bool status);
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif /*PORTLISTENER_H_*/
|
||||
@@ -0,0 +1,2 @@
|
||||
[.ShellClassInfo]
|
||||
IconResource=C:\Users\Corwin\AppData\Roaming\Insync\App\res\shared-folder-vista-7.ico,0
|
||||
@@ -0,0 +1,7 @@
|
||||
TEMPLATE = app
|
||||
DEPENDPATH += .
|
||||
CONFIG += console
|
||||
include(../../src/qextserialport.pri)
|
||||
|
||||
SOURCES += main.cpp PortListener.cpp
|
||||
HEADERS += PortListener.h
|
||||
@@ -0,0 +1,19 @@
|
||||
/**
|
||||
* @file main.cpp
|
||||
* @brief Main file.
|
||||
* @author Michal Policht
|
||||
*/
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include "PortListener.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QCoreApplication app(argc, argv);
|
||||
|
||||
QString portName = QLatin1String("COM1"); // update this to use your port of choice
|
||||
PortListener listener(portName); // signals get hooked up internally
|
||||
|
||||
// start the event loop and wait for signals
|
||||
return app.exec();
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
TEMPLATE = subdirs
|
||||
SUBDIRS = qespta enumerator \
|
||||
uartassistant
|
||||
win32:SUBDIRS += event
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
/**
|
||||
* @file MainWindow.cpp
|
||||
* @brief MainWindow Implementation.
|
||||
* @see MainWindow.h
|
||||
* @author Micha? Policht
|
||||
*/
|
||||
|
||||
|
||||
#include <QMessageBox>
|
||||
#include <QMenuBar>
|
||||
#include "MainWindow.h"
|
||||
#include "MessageWindow.h"
|
||||
#include "QespTest.h"
|
||||
|
||||
MainWindow::MainWindow()
|
||||
{
|
||||
//central widget
|
||||
QespTest *qespTest = new QespTest();
|
||||
setCentralWidget(qespTest);
|
||||
//bottom dock widget
|
||||
MessageWindow *msgWindow = new MessageWindow();
|
||||
addDockWidget(Qt::BottomDockWidgetArea, msgWindow);
|
||||
|
||||
createActions();
|
||||
createMenus();
|
||||
|
||||
setWindowTitle(tr("QextSerialPort Test Application"));
|
||||
}
|
||||
|
||||
void MainWindow::about()
|
||||
{
|
||||
QMessageBox::about(this, tr("About "),
|
||||
tr("<B>""</B><BR>"
|
||||
"author: Michal Policht<br>"
|
||||
"<a href='mailto:xpolik@users.sourceforge.net'>xpolik@users.sourceforge.net</a>"));
|
||||
}
|
||||
|
||||
void MainWindow::createActions()
|
||||
{
|
||||
//File actions
|
||||
exitAct = new QAction(tr("E&xit"), this);
|
||||
exitAct->setShortcut(tr("CTRL+D"));
|
||||
exitAct->setStatusTip(tr("Exit the application"));
|
||||
connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
|
||||
|
||||
//Help actions
|
||||
aboutAct = new QAction(tr("&About"), this);
|
||||
aboutAct->setShortcut(tr("CTRL+A"));
|
||||
aboutAct->setStatusTip(tr("About application"));
|
||||
connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
|
||||
}
|
||||
|
||||
void MainWindow::createMenus()
|
||||
{
|
||||
fileMenu = menuBar()->addMenu(tr("&File"));
|
||||
fileMenu->addAction(exitAct);
|
||||
|
||||
helpMenu = menuBar()->addMenu(tr("&Help"));
|
||||
helpMenu->addAction(aboutAct);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* @file MainWindow.h
|
||||
* @brief Application's Main Window.
|
||||
* @see MainWindow
|
||||
* @author Micha? Policht
|
||||
*/
|
||||
|
||||
#ifndef MAINWINDOW_H_
|
||||
#define MAINWINDOW_H_
|
||||
|
||||
#include <QMainWindow>
|
||||
|
||||
class QMenu;
|
||||
class QAction;
|
||||
|
||||
class MainWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
QMenu *fileMenu;
|
||||
QAction *exitAct;
|
||||
QMenu *helpMenu;
|
||||
QAction *aboutAct;
|
||||
|
||||
private:
|
||||
void createMenus();
|
||||
void createActions();
|
||||
|
||||
private slots:
|
||||
void about();
|
||||
|
||||
public:
|
||||
MainWindow();
|
||||
|
||||
};
|
||||
|
||||
#endif /*MAINWINDOW_H_*/
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
/**
|
||||
* @file MessageWindow.cpp
|
||||
* @brief MessageWindow Implementation.
|
||||
* @see MessageWindow.h
|
||||
* @author Micha? Policht
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "MessageWindow.h"
|
||||
#include <QMessageBox>
|
||||
#include <QCoreApplication>
|
||||
#include <QMutexLocker>
|
||||
|
||||
const char *MessageWindow::WINDOW_TITLE = "Message Window";
|
||||
MessageWindow *MessageWindow::MsgHandler = NULL;
|
||||
|
||||
MessageWindow::MessageWindow(QWidget *parent, Qt::WindowFlags flags)
|
||||
: QDockWidget(parent, flags),
|
||||
msgTextEdit(this)
|
||||
{
|
||||
setWindowTitle(tr(WINDOW_TITLE));
|
||||
msgTextEdit.setReadOnly(true);
|
||||
setWidget(&msgTextEdit);
|
||||
|
||||
MessageWindow::MsgHandler = this;
|
||||
}
|
||||
|
||||
//static
|
||||
QString MessageWindow::QtMsgToQString(QtMsgType type, const char *msg)
|
||||
{
|
||||
switch (type) {
|
||||
case QtDebugMsg:
|
||||
return QLatin1String("Debug: ")+QLatin1String(msg);
|
||||
case QtWarningMsg:
|
||||
return QLatin1String("Warning: ")+QLatin1String(msg);
|
||||
case QtCriticalMsg:
|
||||
return QLatin1String("Critical: ")+QLatin1String(msg);
|
||||
case QtFatalMsg:
|
||||
return QLatin1String("Fatal: ")+QLatin1String(msg);
|
||||
default:
|
||||
return QLatin1String("Unrecognized message type: ")+QLatin1String(msg);
|
||||
}
|
||||
}
|
||||
|
||||
//static
|
||||
void MessageWindow::AppendMsgWrapper(QtMsgType type, const char *msg)
|
||||
{
|
||||
static QMutex mutex;
|
||||
QMutexLocker locker(&mutex);
|
||||
|
||||
if (MessageWindow::MsgHandler != NULL)
|
||||
return MessageWindow::MsgHandler->postMsgEvent(type, msg);
|
||||
else
|
||||
fprintf(stderr, "%s", MessageWindow::QtMsgToQString(type, msg).toLatin1().data());
|
||||
}
|
||||
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
|
||||
void MessageWindow::AppendMsgWrapper(QtMsgType type, const QMessageLogContext & /*context*/, const QString &msg)
|
||||
{
|
||||
AppendMsgWrapper(type, msg.toLatin1().data());
|
||||
}
|
||||
#endif
|
||||
|
||||
void MessageWindow::customEvent(QEvent *event)
|
||||
{
|
||||
if (static_cast<MessageWindow::EventType>(event->type()) == MessageWindow::MessageEventType)
|
||||
msgTextEdit.append(dynamic_cast<MessageEvent *>(event)->msg);
|
||||
}
|
||||
|
||||
void MessageWindow::postMsgEvent(QtMsgType type, const char *msg)
|
||||
{
|
||||
QString qmsg = MessageWindow::QtMsgToQString(type, msg);
|
||||
switch (type) {
|
||||
case QtDebugMsg:
|
||||
break;
|
||||
case QtWarningMsg:
|
||||
qmsg.prepend(QLatin1String("<FONT color=\"#FF0000\">"));
|
||||
qmsg.append(QLatin1String("</FONT>"));
|
||||
break;
|
||||
case QtCriticalMsg:
|
||||
if (QMessageBox::critical(this, QLatin1String("Critical Error"), qmsg,
|
||||
QMessageBox::Ignore,
|
||||
QMessageBox::Abort,
|
||||
QMessageBox::NoButton) == QMessageBox::Abort)
|
||||
abort(); // core dump
|
||||
qmsg.prepend(QLatin1String("<B><FONT color=\"#FF0000\">"));
|
||||
qmsg.append(QLatin1String("</FONT></B>"));
|
||||
break;
|
||||
case QtFatalMsg:
|
||||
QMessageBox::critical(this, QLatin1String("Fatal Error"), qmsg, QMessageBox::Ok, QMessageBox::NoButton, QMessageBox::NoButton);
|
||||
abort(); // deliberately core dump
|
||||
}
|
||||
//it's impossible to change GUI directly from thread other than the main thread
|
||||
//so post message encapsulated by MessageEvent to the main thread's event queue
|
||||
QCoreApplication::postEvent(this, new MessageEvent(qmsg));
|
||||
}
|
||||
|
||||
MessageEvent::MessageEvent(QString &msg):
|
||||
QEvent(static_cast<QEvent::Type>(MessageWindow::MessageEventType))
|
||||
{
|
||||
this->msg = msg;
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
/**
|
||||
* @file MessageWindow.h
|
||||
* @brief Message Window.
|
||||
* @see MessageWindow
|
||||
* @author Micha? Policht
|
||||
*/
|
||||
|
||||
#ifndef MESSAGEWINDOW_H_
|
||||
#define MESSAGEWINDOW_H_
|
||||
|
||||
#include <QDockWidget>
|
||||
#include <QTextEdit>
|
||||
#include <QEvent>
|
||||
|
||||
/**
|
||||
* Message Window. Handling errors and other messages.
|
||||
*/
|
||||
class MessageWindow: public QDockWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
QTextEdit msgTextEdit; ///< Main widget.
|
||||
static MessageWindow *MsgHandler; ///< Set in constructor.
|
||||
static const char *WINDOW_TITLE; ///< Window title.
|
||||
|
||||
private:
|
||||
static QString QtMsgToQString(QtMsgType type, const char *msg);
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Handle custom events. MessageWindow hadles custom events listed in
|
||||
* EventType enum.
|
||||
*/
|
||||
virtual void customEvent(QEvent* event);
|
||||
|
||||
public:
|
||||
enum EventType {MessageEventType = QEvent::User}; ///< Custom event types.
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
* @param parent parent widget.
|
||||
* @param flags widget flags.
|
||||
*/
|
||||
MessageWindow(QWidget* parent = 0, Qt::WindowFlags flags = 0);
|
||||
|
||||
/**
|
||||
* Append message wrapper. Since ISO forbids casting member functions
|
||||
* to C functions, wrapper is needed to use this class as QtMsgHandler.
|
||||
* This method is thread-safe but not reentrant.
|
||||
* @param type message type.
|
||||
* @param msg message string.
|
||||
*/
|
||||
static void AppendMsgWrapper(QtMsgType type, const char *msg);
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
|
||||
static void AppendMsgWrapper(QtMsgType type, const QMessageLogContext &context, const QString &msg);
|
||||
#endif
|
||||
/**
|
||||
* Post message event to the main event loop. This function encapsulates
|
||||
* message into MessageEvent object and passes it to the main event loop.
|
||||
* @param type message type.
|
||||
* @param msg message string.
|
||||
*/
|
||||
void postMsgEvent(QtMsgType type, const char *msg);
|
||||
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Message Event. Custom event used by @ref MessageWindow to provide multi-threaded
|
||||
* access. Encapsulates message inside @a msg variable.
|
||||
*/
|
||||
class MessageEvent: public QEvent
|
||||
{
|
||||
public:
|
||||
QString msg; ///< Message string.
|
||||
|
||||
/**
|
||||
* Contructor.
|
||||
* @param msg message to post.
|
||||
*/
|
||||
MessageEvent(QString &msg);
|
||||
};
|
||||
|
||||
#endif /*MESSAGEWINDOW_H_*/
|
||||
@@ -0,0 +1,128 @@
|
||||
/* QespTest.cpp
|
||||
**************************************/
|
||||
#include "QespTest.h"
|
||||
#include "qextserialport.h"
|
||||
#include <QLayout>
|
||||
#include <QLineEdit>
|
||||
#include <QTextEdit>
|
||||
#include <QPushButton>
|
||||
#include <QSpinBox>
|
||||
|
||||
|
||||
QespTest::QespTest(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
|
||||
{
|
||||
//modify the port settings on your own
|
||||
#ifdef Q_OS_UNIX
|
||||
port = new QextSerialPort(QLatin1String("/dev/ttyS0"), QextSerialPort::Polling);
|
||||
#else
|
||||
port = new QextSerialPort(QLatin1String("COM1"), QextSerialPort::Polling);
|
||||
#endif /*Q_OS_UNIX*/
|
||||
port->setBaudRate(BAUD19200);
|
||||
port->setFlowControl(FLOW_OFF);
|
||||
port->setParity(PAR_NONE);
|
||||
port->setDataBits(DATA_8);
|
||||
port->setStopBits(STOP_2);
|
||||
//set timeouts to 500 ms
|
||||
port->setTimeout(500);
|
||||
|
||||
message = new QLineEdit(this);
|
||||
|
||||
// transmit receive
|
||||
QPushButton *transmitButton = new QPushButton(tr("Transmit"));
|
||||
connect(transmitButton, SIGNAL(clicked()), SLOT(transmitMsg()));
|
||||
QPushButton *receiveButton = new QPushButton(tr("Receive"));
|
||||
connect(receiveButton, SIGNAL(clicked()), SLOT(receiveMsg()));
|
||||
QHBoxLayout *trLayout = new QHBoxLayout;
|
||||
trLayout->addWidget(transmitButton);
|
||||
trLayout->addWidget(receiveButton);
|
||||
|
||||
//CR LF
|
||||
QPushButton *CRButton = new QPushButton(tr("CR"));
|
||||
connect(CRButton, SIGNAL(clicked()), SLOT(appendCR()));
|
||||
QPushButton *LFButton = new QPushButton(tr("LF"));
|
||||
connect(LFButton, SIGNAL(clicked()), SLOT(appendLF()));
|
||||
QHBoxLayout *crlfLayout = new QHBoxLayout;
|
||||
crlfLayout->addWidget(CRButton);
|
||||
crlfLayout->addWidget(LFButton);
|
||||
|
||||
//open close
|
||||
QPushButton *openButton = new QPushButton(tr("Open"));
|
||||
connect(openButton, SIGNAL(clicked()), SLOT(openPort()));
|
||||
QPushButton *closeButton = new QPushButton(tr("Close"));
|
||||
connect(closeButton, SIGNAL(clicked()), SLOT(closePort()));
|
||||
QHBoxLayout *ocLayout = new QHBoxLayout;
|
||||
ocLayout->addWidget(openButton);
|
||||
ocLayout->addWidget(closeButton);
|
||||
|
||||
received_msg = new QTextEdit();
|
||||
|
||||
QVBoxLayout *myVBox = new QVBoxLayout;
|
||||
myVBox->addWidget(message);
|
||||
myVBox->addLayout(crlfLayout);
|
||||
myVBox->addLayout(trLayout);
|
||||
myVBox->addLayout(ocLayout);
|
||||
myVBox->addWidget(received_msg);
|
||||
setLayout(myVBox);
|
||||
|
||||
qDebug("isOpen : %d", port->isOpen());
|
||||
}
|
||||
|
||||
QespTest::~QespTest()
|
||||
{
|
||||
delete port;
|
||||
port = NULL;
|
||||
}
|
||||
|
||||
void QespTest::transmitMsg()
|
||||
{
|
||||
int i = port->write(message->text().toLatin1());
|
||||
qDebug("trasmitted : %d", i);
|
||||
}
|
||||
|
||||
void QespTest::receiveMsg()
|
||||
{
|
||||
char buff[1024];
|
||||
int numBytes;
|
||||
|
||||
numBytes = port->bytesAvailable();
|
||||
if(numBytes > 1024)
|
||||
numBytes = 1024;
|
||||
|
||||
int i = port->read(buff, numBytes);
|
||||
if (i != -1)
|
||||
buff[i] = '\0';
|
||||
else
|
||||
buff[0] = '\0';
|
||||
QString msg = QLatin1String(buff);
|
||||
|
||||
received_msg->append(msg);
|
||||
received_msg->ensureCursorVisible();
|
||||
qDebug("bytes available: %d", numBytes);
|
||||
qDebug("received: %d", i);
|
||||
}
|
||||
|
||||
|
||||
void QespTest::appendCR()
|
||||
{
|
||||
message->insert(QLatin1String("\x0D"));
|
||||
}
|
||||
|
||||
void QespTest::appendLF()
|
||||
{
|
||||
message->insert(QLatin1String("\x0A"));
|
||||
}
|
||||
|
||||
void QespTest::closePort()
|
||||
{
|
||||
port->close();
|
||||
qDebug("is open: %d", port->isOpen());
|
||||
}
|
||||
|
||||
void QespTest::openPort()
|
||||
{
|
||||
port->open(QIODevice::ReadWrite | QIODevice::Unbuffered);
|
||||
qDebug("is open: %d", port->isOpen());
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
/* qesptest.h
|
||||
**************************************/
|
||||
#ifndef _QESPTEST_H_
|
||||
#define _QESPTEST_H_
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
class QLineEdit;
|
||||
class QTextEdit;
|
||||
class QextSerialPort;
|
||||
class QSpinBox;
|
||||
|
||||
class QespTest : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
QespTest(QWidget *parent=0);
|
||||
|
||||
virtual ~QespTest();
|
||||
|
||||
private:
|
||||
QLineEdit *message;
|
||||
QSpinBox *delaySpinBox;
|
||||
QTextEdit *received_msg;
|
||||
QextSerialPort *port;
|
||||
|
||||
private slots:
|
||||
void transmitMsg();
|
||||
void receiveMsg();
|
||||
void appendCR();
|
||||
void appendLF();
|
||||
void closePort();
|
||||
void openPort();
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,4 @@
|
||||
This is simple application using QextSerialPort library.
|
||||
|
||||
Port settings are in QespTest constructor (QespTest.cpp)
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
[.ShellClassInfo]
|
||||
IconResource=C:\Users\Corwin\AppData\Roaming\Insync\App\res\shared-folder-vista-7.ico,0
|
||||
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* @file main.cpp
|
||||
* @brief Main file.
|
||||
* @author Micha? Policht
|
||||
*/
|
||||
|
||||
#include <QApplication>
|
||||
#include "MainWindow.h"
|
||||
#include "MessageWindow.h"
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication app(argc, argv);
|
||||
//! [0]
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
|
||||
//redirect debug messages to the MessageWindow dialog
|
||||
qInstallMsgHandler(MessageWindow::AppendMsgWrapper);
|
||||
#else
|
||||
qInstallMessageHandler(MessageWindow::AppendMsgWrapper);
|
||||
#endif
|
||||
//! [0]
|
||||
|
||||
MainWindow mainWindow;
|
||||
mainWindow.show();
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
TEMPLATE = app
|
||||
DEPENDPATH += .
|
||||
QT += core gui
|
||||
contains(QT_VERSION, ^5\\..*\\..*): QT += widgets
|
||||
HEADERS += MainWindow.h \
|
||||
MessageWindow.h \
|
||||
QespTest.h
|
||||
|
||||
SOURCES += main.cpp \
|
||||
MainWindow.cpp \
|
||||
MessageWindow.cpp \
|
||||
QespTest.cpp
|
||||
|
||||
include(../../src/qextserialport.pri)
|
||||
@@ -0,0 +1,2 @@
|
||||
[.ShellClassInfo]
|
||||
IconResource=C:\Users\Corwin\AppData\Roaming\Insync\App\res\shared-folder-vista-7.ico,0
|
||||
@@ -0,0 +1,179 @@
|
||||
#include "qextserialport.h"
|
||||
#include "qextserialenumerator.h"
|
||||
#include "dialog.h"
|
||||
#include "ui_dialog.h"
|
||||
#include <QtCore>
|
||||
|
||||
Dialog::Dialog(QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::Dialog)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
//! [0]
|
||||
foreach (QextPortInfo info, QextSerialEnumerator::getPorts())
|
||||
ui->portBox->addItem(info.portName);
|
||||
//make sure user can input their own port name!
|
||||
ui->portBox->setEditable(true);
|
||||
|
||||
ui->baudRateBox->addItem("1200", BAUD1200);
|
||||
ui->baudRateBox->addItem("2400", BAUD2400);
|
||||
ui->baudRateBox->addItem("4800", BAUD4800);
|
||||
ui->baudRateBox->addItem("9600", BAUD9600);
|
||||
ui->baudRateBox->addItem("19200", BAUD19200);
|
||||
ui->baudRateBox->setCurrentIndex(3);
|
||||
|
||||
ui->parityBox->addItem("NONE", PAR_NONE);
|
||||
ui->parityBox->addItem("ODD", PAR_ODD);
|
||||
ui->parityBox->addItem("EVEN", PAR_EVEN);
|
||||
|
||||
ui->dataBitsBox->addItem("5", DATA_5);
|
||||
ui->dataBitsBox->addItem("6", DATA_6);
|
||||
ui->dataBitsBox->addItem("7", DATA_7);
|
||||
ui->dataBitsBox->addItem("8", DATA_8);
|
||||
ui->dataBitsBox->setCurrentIndex(3);
|
||||
|
||||
ui->stopBitsBox->addItem("1", STOP_1);
|
||||
ui->stopBitsBox->addItem("2", STOP_2);
|
||||
|
||||
ui->queryModeBox->addItem("Polling", QextSerialPort::Polling);
|
||||
ui->queryModeBox->addItem("EventDriven", QextSerialPort::EventDriven);
|
||||
//! [0]
|
||||
|
||||
ui->led->turnOff();
|
||||
|
||||
timer = new QTimer(this);
|
||||
timer->setInterval(40);
|
||||
//! [1]
|
||||
PortSettings settings = {BAUD9600, DATA_8, PAR_NONE, STOP_1, FLOW_OFF, 10};
|
||||
port = new QextSerialPort(ui->portBox->currentText(), settings, QextSerialPort::Polling);
|
||||
//! [1]
|
||||
|
||||
enumerator = new QextSerialEnumerator(this);
|
||||
enumerator->setUpNotifications();
|
||||
|
||||
connect(ui->baudRateBox, SIGNAL(currentIndexChanged(int)), SLOT(onBaudRateChanged(int)));
|
||||
connect(ui->parityBox, SIGNAL(currentIndexChanged(int)), SLOT(onParityChanged(int)));
|
||||
connect(ui->dataBitsBox, SIGNAL(currentIndexChanged(int)), SLOT(onDataBitsChanged(int)));
|
||||
connect(ui->stopBitsBox, SIGNAL(currentIndexChanged(int)), SLOT(onStopBitsChanged(int)));
|
||||
connect(ui->queryModeBox, SIGNAL(currentIndexChanged(int)), SLOT(onQueryModeChanged(int)));
|
||||
connect(ui->timeoutBox, SIGNAL(valueChanged(int)), SLOT(onTimeoutChanged(int)));
|
||||
connect(ui->portBox, SIGNAL(editTextChanged(QString)), SLOT(onPortNameChanged(QString)));
|
||||
connect(ui->openCloseButton, SIGNAL(clicked()), SLOT(onOpenCloseButtonClicked()));
|
||||
connect(ui->sendButton, SIGNAL(clicked()), SLOT(onSendButtonClicked()));
|
||||
connect(timer, SIGNAL(timeout()), SLOT(onReadyRead()));
|
||||
connect(port, SIGNAL(readyRead()), SLOT(onReadyRead()));
|
||||
|
||||
connect(enumerator, SIGNAL(deviceDiscovered(QextPortInfo)), SLOT(onPortAddedOrRemoved()));
|
||||
connect(enumerator, SIGNAL(deviceRemoved(QextPortInfo)), SLOT(onPortAddedOrRemoved()));
|
||||
|
||||
setWindowTitle(tr("QextSerialPort Demo"));
|
||||
}
|
||||
|
||||
Dialog::~Dialog()
|
||||
{
|
||||
delete ui;
|
||||
delete port;
|
||||
}
|
||||
|
||||
void Dialog::changeEvent(QEvent *e)
|
||||
{
|
||||
QDialog::changeEvent(e);
|
||||
switch (e->type()) {
|
||||
case QEvent::LanguageChange:
|
||||
ui->retranslateUi(this);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Dialog::onPortNameChanged(const QString & /*name*/)
|
||||
{
|
||||
if (port->isOpen()) {
|
||||
port->close();
|
||||
ui->led->turnOff();
|
||||
}
|
||||
}
|
||||
//! [2]
|
||||
void Dialog::onBaudRateChanged(int idx)
|
||||
{
|
||||
port->setBaudRate((BaudRateType)ui->baudRateBox->itemData(idx).toInt());
|
||||
}
|
||||
|
||||
void Dialog::onParityChanged(int idx)
|
||||
{
|
||||
port->setParity((ParityType)ui->parityBox->itemData(idx).toInt());
|
||||
}
|
||||
|
||||
void Dialog::onDataBitsChanged(int idx)
|
||||
{
|
||||
port->setDataBits((DataBitsType)ui->dataBitsBox->itemData(idx).toInt());
|
||||
}
|
||||
|
||||
void Dialog::onStopBitsChanged(int idx)
|
||||
{
|
||||
port->setStopBits((StopBitsType)ui->stopBitsBox->itemData(idx).toInt());
|
||||
}
|
||||
|
||||
void Dialog::onQueryModeChanged(int idx)
|
||||
{
|
||||
port->setQueryMode((QextSerialPort::QueryMode)ui->queryModeBox->itemData(idx).toInt());
|
||||
}
|
||||
|
||||
void Dialog::onTimeoutChanged(int val)
|
||||
{
|
||||
port->setTimeout(val);
|
||||
}
|
||||
//! [2]
|
||||
//! [3]
|
||||
void Dialog::onOpenCloseButtonClicked()
|
||||
{
|
||||
if (!port->isOpen()) {
|
||||
port->setPortName(ui->portBox->currentText());
|
||||
port->open(QIODevice::ReadWrite);
|
||||
}
|
||||
else {
|
||||
port->close();
|
||||
}
|
||||
|
||||
//If using polling mode, we need a QTimer
|
||||
if (port->isOpen() && port->queryMode() == QextSerialPort::Polling)
|
||||
timer->start();
|
||||
else
|
||||
timer->stop();
|
||||
|
||||
//update led's status
|
||||
ui->led->turnOn(port->isOpen());
|
||||
}
|
||||
//! [3]
|
||||
//! [4]
|
||||
void Dialog::onSendButtonClicked()
|
||||
{
|
||||
if (port->isOpen() && !ui->sendEdit->toPlainText().isEmpty())
|
||||
port->write(ui->sendEdit->toPlainText().toLatin1());
|
||||
}
|
||||
|
||||
void Dialog::onReadyRead()
|
||||
{
|
||||
if (port->bytesAvailable()) {
|
||||
ui->recvEdit->moveCursor(QTextCursor::End);
|
||||
ui->recvEdit->insertPlainText(QString::fromLatin1(port->readAll()));
|
||||
}
|
||||
}
|
||||
|
||||
void Dialog::onPortAddedOrRemoved()
|
||||
{
|
||||
QString current = ui->portBox->currentText();
|
||||
|
||||
ui->portBox->blockSignals(true);
|
||||
ui->portBox->clear();
|
||||
foreach (QextPortInfo info, QextSerialEnumerator::getPorts())
|
||||
ui->portBox->addItem(info.portName);
|
||||
|
||||
ui->portBox->setCurrentIndex(ui->portBox->findText(current));
|
||||
|
||||
ui->portBox->blockSignals(false);
|
||||
}
|
||||
|
||||
//! [4]
|
||||
@@ -0,0 +1,45 @@
|
||||
#ifndef DIALOG_H
|
||||
#define DIALOG_H
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
namespace Ui {
|
||||
class Dialog;
|
||||
}
|
||||
class QTimer;
|
||||
class QextSerialPort;
|
||||
class QextSerialEnumerator;
|
||||
|
||||
class Dialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit Dialog(QWidget *parent = 0);
|
||||
~Dialog();
|
||||
|
||||
protected:
|
||||
void changeEvent(QEvent *e);
|
||||
|
||||
private Q_SLOTS:
|
||||
void onPortNameChanged(const QString &name);
|
||||
void onBaudRateChanged(int idx);
|
||||
void onParityChanged(int idx);
|
||||
void onDataBitsChanged(int idx);
|
||||
void onStopBitsChanged(int idx);
|
||||
void onQueryModeChanged(int idx);
|
||||
void onTimeoutChanged(int val);
|
||||
void onOpenCloseButtonClicked();
|
||||
void onSendButtonClicked();
|
||||
void onReadyRead();
|
||||
|
||||
void onPortAddedOrRemoved();
|
||||
|
||||
private:
|
||||
Ui::Dialog *ui;
|
||||
QTimer *timer;
|
||||
QextSerialPort *port;
|
||||
QextSerialEnumerator *enumerator;
|
||||
};
|
||||
|
||||
#endif // DIALOG_H
|
||||
@@ -0,0 +1,191 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>Dialog</class>
|
||||
<widget class="QDialog" name="Dialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>604</width>
|
||||
<height>485</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Dialog</string>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout" stretch="3,1">
|
||||
<item>
|
||||
<widget class="QPlainTextEdit" name="recvEdit">
|
||||
<property name="maximumBlockCount">
|
||||
<number>800</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPlainTextEdit" name="sendEdit"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Port:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QComboBox" name="portBox"/>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>BaudRate:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QComboBox" name="baudRateBox"/>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>DataBits:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QComboBox" name="dataBitsBox"/>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>Parity:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QComboBox" name="parityBox"/>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="text">
|
||||
<string>StopBits:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<widget class="QComboBox" name="stopBitsBox"/>
|
||||
</item>
|
||||
<item row="6" column="0">
|
||||
<widget class="QLabel" name="label_6">
|
||||
<property name="text">
|
||||
<string>QueryMode:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="1">
|
||||
<widget class="QComboBox" name="queryModeBox"/>
|
||||
</item>
|
||||
<item row="5" column="0">
|
||||
<widget class="QLabel" name="label_7">
|
||||
<property name="text">
|
||||
<string>Timeout:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="1">
|
||||
<widget class="QSpinBox" name="timeoutBox">
|
||||
<property name="suffix">
|
||||
<string> ms</string>
|
||||
</property>
|
||||
<property name="minimum">
|
||||
<number>-1</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>10000</number>
|
||||
</property>
|
||||
<property name="singleStep">
|
||||
<number>10</number>
|
||||
</property>
|
||||
<property name="value">
|
||||
<number>10</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="HLed" name="led" native="true">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>25</width>
|
||||
<height>25</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="openCloseButton">
|
||||
<property name="text">
|
||||
<string>Open/Close</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="sendButton">
|
||||
<property name="text">
|
||||
<string>Send</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>HLed</class>
|
||||
<extends>QWidget</extends>
|
||||
<header>hled.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
@@ -0,0 +1,133 @@
|
||||
#include <QtGui>
|
||||
#include "hled.h"
|
||||
|
||||
struct HLed::Private
|
||||
{
|
||||
public:
|
||||
Private()
|
||||
: darkerFactor(300), color(Qt::green), isOn(true)
|
||||
{ }
|
||||
|
||||
int darkerFactor;
|
||||
QColor color;
|
||||
bool isOn;
|
||||
};
|
||||
|
||||
HLed::HLed(QWidget *parent)
|
||||
:QWidget(parent), m_d(new Private)
|
||||
{
|
||||
}
|
||||
|
||||
HLed::~HLed()
|
||||
{
|
||||
delete m_d;
|
||||
}
|
||||
|
||||
QColor HLed::color() const
|
||||
{
|
||||
return m_d->color;
|
||||
}
|
||||
|
||||
void HLed::setColor(const QColor &color)
|
||||
{
|
||||
if (m_d->color == color)
|
||||
return;
|
||||
update();
|
||||
}
|
||||
|
||||
QSize HLed::sizeHint() const
|
||||
{
|
||||
return QSize(20, 20);
|
||||
}
|
||||
|
||||
QSize HLed::minimumSizeHint() const
|
||||
{
|
||||
return QSize(16, 16);
|
||||
}
|
||||
|
||||
void HLed::toggle()
|
||||
{
|
||||
m_d->isOn = !m_d->isOn;
|
||||
update();
|
||||
}
|
||||
|
||||
void HLed::turnOn(bool on)
|
||||
{
|
||||
m_d->isOn = on;
|
||||
update();
|
||||
}
|
||||
|
||||
void HLed::turnOff(bool off)
|
||||
{
|
||||
turnOn(!off);
|
||||
}
|
||||
|
||||
void HLed::paintEvent(QPaintEvent * /*event*/)
|
||||
{
|
||||
int width = ledWidth();
|
||||
|
||||
QPainter painter(this);
|
||||
painter.setRenderHint(QPainter::Antialiasing);
|
||||
|
||||
QColor color = m_d->isOn ? m_d->color
|
||||
: m_d->color.darker(m_d->darkerFactor);
|
||||
|
||||
QBrush brush;
|
||||
brush.setStyle(Qt::SolidPattern);
|
||||
brush.setColor(color);
|
||||
painter.setBrush(brush);
|
||||
// draw plain
|
||||
painter.drawEllipse(1, 1, width-1, width-1);
|
||||
|
||||
QPen pen;
|
||||
pen.setWidth(2);
|
||||
|
||||
int pos = width / 5 + 1;
|
||||
int lightWidth = width * 2 / 3;
|
||||
int lightQuote = 130 * 2 / (lightWidth ? lightWidth : 1) + 100;
|
||||
|
||||
// draw bright spot
|
||||
while (lightWidth) {
|
||||
color = color.lighter(lightQuote);
|
||||
pen.setColor(color);
|
||||
painter.setPen(pen);
|
||||
painter.drawEllipse(pos, pos, lightWidth, lightWidth);
|
||||
lightWidth--;
|
||||
|
||||
if (!lightWidth)
|
||||
break;
|
||||
|
||||
painter.drawEllipse(pos, pos, lightWidth, lightWidth);
|
||||
lightWidth--;
|
||||
|
||||
if (!lightWidth)
|
||||
break;
|
||||
|
||||
painter.drawEllipse(pos, pos, lightWidth, lightWidth);
|
||||
pos++;
|
||||
lightWidth--;
|
||||
}
|
||||
|
||||
//draw border
|
||||
painter.setBrush(Qt::NoBrush);
|
||||
|
||||
int angle = -720;
|
||||
color = palette().color(QPalette::Light);
|
||||
|
||||
for (int arc=120; arc<2880; arc+=240) {
|
||||
pen.setColor(color);
|
||||
painter.setPen(pen);
|
||||
int w = width - pen.width()/2;
|
||||
painter.drawArc(pen.width()/2, pen.width()/2, w, w, angle+arc, 240);
|
||||
painter.drawArc(pen.width()/2, pen.width()/2, w, w, angle-arc, 240);
|
||||
color = color.darker(110);
|
||||
}
|
||||
}
|
||||
|
||||
int HLed::ledWidth() const
|
||||
{
|
||||
int width = qMin(this->width(), this->height());
|
||||
width -= 2;
|
||||
return width > 0 ? width : 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
#ifndef HLED_H
|
||||
#define HLED_H
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
class QColor;
|
||||
|
||||
class HLed : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
HLed(QWidget *parent = 0);
|
||||
~HLed();
|
||||
|
||||
QColor color() const;
|
||||
QSize sizeHint() const;
|
||||
QSize minimumSizeHint() const;
|
||||
|
||||
public slots:
|
||||
void setColor(const QColor &color);
|
||||
void toggle();
|
||||
void turnOn(bool on=true);
|
||||
void turnOff(bool off=true);
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *);
|
||||
int ledWidth() const;
|
||||
|
||||
private:
|
||||
struct Private;
|
||||
Private * const m_d;
|
||||
};
|
||||
|
||||
#endif // HLED_H
|
||||
@@ -0,0 +1,11 @@
|
||||
#include <QApplication>
|
||||
#include "dialog.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication a(argc, argv);
|
||||
Dialog w;
|
||||
w.show();
|
||||
|
||||
return a.exec();
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
#-------------------------------------------------
|
||||
#
|
||||
# Project created by QtCreator 2011-11-06T21:37:41
|
||||
#
|
||||
#-------------------------------------------------
|
||||
|
||||
QT += core gui
|
||||
contains(QT_VERSION, ^5\\..*\\..*): QT += widgets
|
||||
|
||||
TARGET = uartassistant
|
||||
TEMPLATE = app
|
||||
|
||||
include(../../src/qextserialport.pri)
|
||||
|
||||
SOURCES += main.cpp\
|
||||
dialog.cpp\
|
||||
hled.cpp
|
||||
|
||||
HEADERS += dialog.h \
|
||||
hled.h
|
||||
|
||||
FORMS += dialog.ui
|
||||
Reference in New Issue
Block a user