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:
2016-05-12 20:04:43 -07:00
parent a4df0d921d
commit b300c76103
1047 changed files with 379298 additions and 0 deletions

View File

@@ -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);
}

View File

@@ -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_*/

View File

@@ -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;
}

View File

@@ -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_*/

View File

@@ -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());
}

View File

@@ -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

View File

@@ -0,0 +1,4 @@
This is simple application using QextSerialPort library.
Port settings are in QespTest constructor (QespTest.cpp)

View File

@@ -0,0 +1,2 @@
[.ShellClassInfo]
IconResource=C:\Users\Corwin\AppData\Roaming\Insync\App\res\shared-folder-vista-7.ico,0

View File

@@ -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();
}

View File

@@ -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)