A first Try on Serial.

This commit is contained in:
Hiro Protagonist 2017-03-30 17:40:42 +13:00
parent 0a84d5bef1
commit 667f8dce71
7 changed files with 304 additions and 131 deletions

View file

@ -6,6 +6,7 @@
#-------------------------------------------------
QT += core gui
QT += serialport
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
@ -27,12 +28,14 @@ SOURCES += src/main.cpp\
src/mainwindow.cpp\
src/cameramanager.cpp\
src/recorder.cpp \
src/imagegrabber.cpp
src/imagegrabber.cpp \
src/serialcommunicator.cpp
HEADERS += src/mainwindow.h\
src/cameramanager.h\
src/recorder.h \
src/imagegrabber.h
src/imagegrabber.h \
src/serialcommunicator.h
FORMS += src/forms/mainwindow.ui

View file

@ -21,7 +21,7 @@
</property>
<widget class="QWidget" name="centralWidget">
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="0">
<item row="2" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
@ -37,74 +37,36 @@
</property>
</spacer>
</item>
<item row="0" column="1" rowspan="3">
<widget class="QLabel" name="preview_widget">
<property name="enabled">
<bool>false</bool>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Status</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QLabel" name="statusLabel">
<property name="text">
<string>Waiting.</string>
</property>
</widget>
</item>
<item>
<widget class="QWidget" name="recStats" native="true">
<layout class="QGridLayout" name="gridLayout_2">
<item row="1" column="1">
<widget class="QLCDNumber" name="timeCaptured"/>
</item>
<item row="1" column="0">
<widget class="QLCDNumber" name="framesCaptured"/>
</item>
<item row="0" column="0" alignment="Qt::AlignHCenter">
<widget class="QLabel" name="label_3">
<widget class="QGroupBox" name="groupBox_3">
<property name="title">
<string>Serial Control</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QPushButton" name="sRun">
<property name="text">
<string>Frames</string>
<string>Run</string>
</property>
</widget>
</item>
<item row="0" column="1" alignment="Qt::AlignHCenter">
<widget class="QLabel" name="label_4">
<item>
<widget class="QPushButton" name="sHalt">
<property name="text">
<string>Minutes</string>
<string>Halt</string>
</property>
</widget>
</item>
<item row="3" column="0" colspan="2" alignment="Qt::AlignHCenter">
<widget class="QLCDNumber" name="buffer"/>
</item>
<item row="2" column="0" colspan="2" alignment="Qt::AlignHCenter">
<widget class="QLabel" name="label_5">
<item>
<widget class="QPushButton" name="sFast">
<property name="text">
<string>Buffer</string>
<string>Fast</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
<item row="0" column="0">
<widget class="QGroupBox" name="groupBox">
<property name="sizePolicy">
@ -147,6 +109,20 @@
</item>
</layout>
</item>
<item>
<layout class="QFormLayout" name="formLayout_4">
<item row="0" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Serial Port:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="serialSelector"/>
</item>
</layout>
</item>
<item>
<widget class="QPushButton" name="camScanButton">
<property name="sizePolicy">
@ -270,6 +246,74 @@
</layout>
</widget>
</item>
<item row="3" column="0">
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Status</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QLabel" name="statusLabel">
<property name="text">
<string>Waiting.</string>
</property>
</widget>
</item>
<item>
<widget class="QWidget" name="recStats" native="true">
<layout class="QGridLayout" name="gridLayout_2">
<item row="1" column="1">
<widget class="QLCDNumber" name="timeCaptured"/>
</item>
<item row="1" column="0">
<widget class="QLCDNumber" name="framesCaptured"/>
</item>
<item row="0" column="0" alignment="Qt::AlignHCenter">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Frames</string>
</property>
</widget>
</item>
<item row="0" column="1" alignment="Qt::AlignHCenter">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Minutes</string>
</property>
</widget>
</item>
<item row="3" column="0" colspan="2" alignment="Qt::AlignHCenter">
<widget class="QLCDNumber" name="buffer"/>
</item>
<item row="2" column="0" colspan="2" alignment="Qt::AlignHCenter">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Buffer</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
<item row="0" column="2" rowspan="4">
<widget class="QLabel" name="preview_widget">
<property name="enabled">
<bool>false</bool>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</widget>
</widget>

View file

@ -19,7 +19,8 @@ MainWindow::MainWindow( QWidget * parent ) :
ui( new Ui::MainWindow ),
camMan( this ),
recorder( 0, 18, false ),
resize { false } {
resize { false },
comm( this ) {
ui->setupUi( this );
// Set Scene and Hide Preview Widget
@ -156,6 +157,13 @@ void MainWindow::updateCameraList( unsigned int num_cameras ) {
}
}
void MainWindow::fillSerialPorts() {
ui->serialSelector->clear();
for ( QSerialPortInfo &info : comm.getPorts() ) {
ui->cameraSelector->addItem( info.portName() );
}
}
void MainWindow::scanAndUpdateCameras() {
unsigned int num_cameras = camMan.numCameras();
updateCameraList( num_cameras );

View file

@ -7,6 +7,7 @@
#include "FlyCapture2.h"
#include "cameramanager.h"
#include "recorder.h"
#include "serialcommunicator.h"
namespace Ui {
class MainWindow;
@ -57,6 +58,8 @@ class MainWindow : public QMainWindow {
void setLcd();
SerialCommunicator comm;
private slots:
// Fills Camera Combobox with Cameras
void scanAndUpdateCameras();
@ -68,6 +71,8 @@ class MainWindow : public QMainWindow {
void startStopRecording();
void frameSaved( FlyCapture2::Image * image );
void fillSerialPorts();
signals:
void saveFrame( FlyCapture2::Image * image );
};

View file

@ -0,0 +1,28 @@
#include "serialcommunicator.h"
SerialCommunicator::SerialCommunicator( QObject * parent ) : QObject( parent ), port( this ) {}
const QList<QSerialPortInfo> &SerialCommunicator::getPorts() {
ports = QSerialPortInfo::availablePorts();
return ports;
}
bool SerialCommunicator::selectPort( QSerialPortInfo &info ) {
port.setPort( info );
bool open = port.isOpen();
if ( open ) {
emit connected();
}
return open;
}
// Overload just searches for the port.
bool SerialCommunicator::selectPort( QString &portName ) {
for ( QSerialPortInfo info : ports ) {
if ( info.portName() == portName ) {
return selectPort( info );
break;
}
}
}

32
src/serialcommunicator.h Normal file
View file

@ -0,0 +1,32 @@
#ifndef SERIALCOMMUNICATOR_H
#define SERIALCOMMUNICATOR_H
#include <QtSerialPort/QSerialPort>
#include <QtSerialPort/QSerialPortInfo>
#include <QList>
class SerialCommunicator : public QObject {
Q_OBJECT
public:
explicit SerialCommunicator( QObject * parent = 0 );
public:
const QList<QSerialPortInfo> &getPorts();
bool isConnected() const {
return port.isOpen();
}
public slots:
// returns False if the port is not open
bool selectPort( QSerialPortInfo &info );
bool selectPort( QString &portName );
signals:
void connected();
private:
QSerialPort port;
QList<QSerialPortInfo> ports;
};
#endif // SERIALCOMMUNICATOR_H

View file

@ -37,23 +37,19 @@ public:
QWidget *centralWidget;
QGridLayout *gridLayout;
QSpacerItem *verticalSpacer;
QLabel *preview_widget;
QGroupBox *groupBox_2;
QVBoxLayout *verticalLayout_2;
QLabel *statusLabel;
QWidget *recStats;
QGridLayout *gridLayout_2;
QLCDNumber *timeCaptured;
QLCDNumber *framesCaptured;
QLabel *label_3;
QLabel *label_4;
QLCDNumber *buffer;
QLabel *label_5;
QGroupBox *groupBox_3;
QVBoxLayout *verticalLayout_3;
QPushButton *sRun;
QPushButton *sHalt;
QPushButton *sFast;
QGroupBox *groupBox;
QVBoxLayout *verticalLayout;
QFormLayout *formLayout;
QComboBox *cameraSelector;
QLabel *label;
QFormLayout *formLayout_4;
QLabel *label_6;
QComboBox *serialSelector;
QPushButton *camScanButton;
QPushButton *directorySelector;
QGroupBox *recOptions;
@ -65,6 +61,18 @@ public:
QCheckBox *saveFrames;
QPushButton *startButton;
QPushButton *preview_button;
QGroupBox *groupBox_2;
QVBoxLayout *verticalLayout_2;
QLabel *statusLabel;
QWidget *recStats;
QGridLayout *gridLayout_2;
QLCDNumber *timeCaptured;
QLCDNumber *framesCaptured;
QLabel *label_3;
QLabel *label_4;
QLCDNumber *buffer;
QLabel *label_5;
QLabel *preview_widget;
void setupUi(QMainWindow *MainWindow)
{
@ -84,68 +92,31 @@ public:
gridLayout->setObjectName(QStringLiteral("gridLayout"));
verticalSpacer = new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::MinimumExpanding);
gridLayout->addItem(verticalSpacer, 1, 0, 1, 1);
gridLayout->addItem(verticalSpacer, 2, 0, 1, 1);
preview_widget = new QLabel(centralWidget);
preview_widget->setObjectName(QStringLiteral("preview_widget"));
preview_widget->setEnabled(false);
preview_widget->setFrameShape(QFrame::StyledPanel);
preview_widget->setFrameShadow(QFrame::Raised);
groupBox_3 = new QGroupBox(centralWidget);
groupBox_3->setObjectName(QStringLiteral("groupBox_3"));
verticalLayout_3 = new QVBoxLayout(groupBox_3);
verticalLayout_3->setSpacing(6);
verticalLayout_3->setContentsMargins(11, 11, 11, 11);
verticalLayout_3->setObjectName(QStringLiteral("verticalLayout_3"));
sRun = new QPushButton(groupBox_3);
sRun->setObjectName(QStringLiteral("sRun"));
gridLayout->addWidget(preview_widget, 0, 1, 3, 1);
verticalLayout_3->addWidget(sRun);
groupBox_2 = new QGroupBox(centralWidget);
groupBox_2->setObjectName(QStringLiteral("groupBox_2"));
verticalLayout_2 = new QVBoxLayout(groupBox_2);
verticalLayout_2->setSpacing(6);
verticalLayout_2->setContentsMargins(11, 11, 11, 11);
verticalLayout_2->setObjectName(QStringLiteral("verticalLayout_2"));
statusLabel = new QLabel(groupBox_2);
statusLabel->setObjectName(QStringLiteral("statusLabel"));
sHalt = new QPushButton(groupBox_3);
sHalt->setObjectName(QStringLiteral("sHalt"));
verticalLayout_2->addWidget(statusLabel);
verticalLayout_3->addWidget(sHalt);
recStats = new QWidget(groupBox_2);
recStats->setObjectName(QStringLiteral("recStats"));
gridLayout_2 = new QGridLayout(recStats);
gridLayout_2->setSpacing(6);
gridLayout_2->setContentsMargins(11, 11, 11, 11);
gridLayout_2->setObjectName(QStringLiteral("gridLayout_2"));
timeCaptured = new QLCDNumber(recStats);
timeCaptured->setObjectName(QStringLiteral("timeCaptured"));
sFast = new QPushButton(groupBox_3);
sFast->setObjectName(QStringLiteral("sFast"));
gridLayout_2->addWidget(timeCaptured, 1, 1, 1, 1);
framesCaptured = new QLCDNumber(recStats);
framesCaptured->setObjectName(QStringLiteral("framesCaptured"));
gridLayout_2->addWidget(framesCaptured, 1, 0, 1, 1);
label_3 = new QLabel(recStats);
label_3->setObjectName(QStringLiteral("label_3"));
gridLayout_2->addWidget(label_3, 0, 0, 1, 1, Qt::AlignHCenter);
label_4 = new QLabel(recStats);
label_4->setObjectName(QStringLiteral("label_4"));
gridLayout_2->addWidget(label_4, 0, 1, 1, 1, Qt::AlignHCenter);
buffer = new QLCDNumber(recStats);
buffer->setObjectName(QStringLiteral("buffer"));
gridLayout_2->addWidget(buffer, 3, 0, 1, 2, Qt::AlignHCenter);
label_5 = new QLabel(recStats);
label_5->setObjectName(QStringLiteral("label_5"));
gridLayout_2->addWidget(label_5, 2, 0, 1, 2, Qt::AlignHCenter);
verticalLayout_3->addWidget(sFast);
verticalLayout_2->addWidget(recStats);
gridLayout->addWidget(groupBox_2, 2, 0, 1, 1);
gridLayout->addWidget(groupBox_3, 1, 0, 1, 1);
groupBox = new QGroupBox(centralWidget);
groupBox->setObjectName(QStringLiteral("groupBox"));
@ -177,6 +148,22 @@ public:
verticalLayout->addLayout(formLayout);
formLayout_4 = new QFormLayout();
formLayout_4->setSpacing(6);
formLayout_4->setObjectName(QStringLiteral("formLayout_4"));
label_6 = new QLabel(groupBox);
label_6->setObjectName(QStringLiteral("label_6"));
formLayout_4->setWidget(0, QFormLayout::LabelRole, label_6);
serialSelector = new QComboBox(groupBox);
serialSelector->setObjectName(QStringLiteral("serialSelector"));
formLayout_4->setWidget(0, QFormLayout::FieldRole, serialSelector);
verticalLayout->addLayout(formLayout_4);
camScanButton = new QPushButton(groupBox);
camScanButton->setObjectName(QStringLiteral("camScanButton"));
QSizePolicy sizePolicy2(QSizePolicy::Minimum, QSizePolicy::Preferred);
@ -256,6 +243,67 @@ public:
gridLayout->addWidget(groupBox, 0, 0, 1, 1);
groupBox_2 = new QGroupBox(centralWidget);
groupBox_2->setObjectName(QStringLiteral("groupBox_2"));
verticalLayout_2 = new QVBoxLayout(groupBox_2);
verticalLayout_2->setSpacing(6);
verticalLayout_2->setContentsMargins(11, 11, 11, 11);
verticalLayout_2->setObjectName(QStringLiteral("verticalLayout_2"));
statusLabel = new QLabel(groupBox_2);
statusLabel->setObjectName(QStringLiteral("statusLabel"));
verticalLayout_2->addWidget(statusLabel);
recStats = new QWidget(groupBox_2);
recStats->setObjectName(QStringLiteral("recStats"));
gridLayout_2 = new QGridLayout(recStats);
gridLayout_2->setSpacing(6);
gridLayout_2->setContentsMargins(11, 11, 11, 11);
gridLayout_2->setObjectName(QStringLiteral("gridLayout_2"));
timeCaptured = new QLCDNumber(recStats);
timeCaptured->setObjectName(QStringLiteral("timeCaptured"));
gridLayout_2->addWidget(timeCaptured, 1, 1, 1, 1);
framesCaptured = new QLCDNumber(recStats);
framesCaptured->setObjectName(QStringLiteral("framesCaptured"));
gridLayout_2->addWidget(framesCaptured, 1, 0, 1, 1);
label_3 = new QLabel(recStats);
label_3->setObjectName(QStringLiteral("label_3"));
gridLayout_2->addWidget(label_3, 0, 0, 1, 1, Qt::AlignHCenter);
label_4 = new QLabel(recStats);
label_4->setObjectName(QStringLiteral("label_4"));
gridLayout_2->addWidget(label_4, 0, 1, 1, 1, Qt::AlignHCenter);
buffer = new QLCDNumber(recStats);
buffer->setObjectName(QStringLiteral("buffer"));
gridLayout_2->addWidget(buffer, 3, 0, 1, 2, Qt::AlignHCenter);
label_5 = new QLabel(recStats);
label_5->setObjectName(QStringLiteral("label_5"));
gridLayout_2->addWidget(label_5, 2, 0, 1, 2, Qt::AlignHCenter);
verticalLayout_2->addWidget(recStats);
gridLayout->addWidget(groupBox_2, 3, 0, 1, 1);
preview_widget = new QLabel(centralWidget);
preview_widget->setObjectName(QStringLiteral("preview_widget"));
preview_widget->setEnabled(false);
preview_widget->setFrameShape(QFrame::StyledPanel);
preview_widget->setFrameShadow(QFrame::Raised);
gridLayout->addWidget(preview_widget, 0, 2, 4, 1);
MainWindow->setCentralWidget(centralWidget);
retranslateUi(MainWindow);
@ -266,15 +314,14 @@ public:
void retranslateUi(QMainWindow *MainWindow)
{
MainWindow->setWindowTitle(QApplication::translate("MainWindow", "Taevitas", Q_NULLPTR));
preview_widget->setText(QString());
groupBox_2->setTitle(QApplication::translate("MainWindow", "Status", Q_NULLPTR));
statusLabel->setText(QApplication::translate("MainWindow", "Waiting.", Q_NULLPTR));
label_3->setText(QApplication::translate("MainWindow", "Frames", Q_NULLPTR));
label_4->setText(QApplication::translate("MainWindow", "Minutes", Q_NULLPTR));
label_5->setText(QApplication::translate("MainWindow", "Buffer", Q_NULLPTR));
groupBox_3->setTitle(QApplication::translate("MainWindow", "Serial Control", Q_NULLPTR));
sRun->setText(QApplication::translate("MainWindow", "Run", Q_NULLPTR));
sHalt->setText(QApplication::translate("MainWindow", "Halt", Q_NULLPTR));
sFast->setText(QApplication::translate("MainWindow", "Fast", Q_NULLPTR));
groupBox->setTitle(QApplication::translate("MainWindow", "Settings", Q_NULLPTR));
cameraSelector->setCurrentText(QString());
label->setText(QApplication::translate("MainWindow", "Camera:", Q_NULLPTR));
label_6->setText(QApplication::translate("MainWindow", "Serial Port:", Q_NULLPTR));
camScanButton->setText(QApplication::translate("MainWindow", "Rescan Cameras", Q_NULLPTR));
directorySelector->setText(QApplication::translate("MainWindow", "Working Directory", Q_NULLPTR));
recOptions->setTitle(QApplication::translate("MainWindow", "Recorder Settings", Q_NULLPTR));
@ -283,6 +330,12 @@ public:
saveFrames->setText(QApplication::translate("MainWindow", " Save Frames", Q_NULLPTR));
startButton->setText(QApplication::translate("MainWindow", "Start", Q_NULLPTR));
preview_button->setText(QApplication::translate("MainWindow", "Preview Camera", Q_NULLPTR));
groupBox_2->setTitle(QApplication::translate("MainWindow", "Status", Q_NULLPTR));
statusLabel->setText(QApplication::translate("MainWindow", "Waiting.", Q_NULLPTR));
label_3->setText(QApplication::translate("MainWindow", "Frames", Q_NULLPTR));
label_4->setText(QApplication::translate("MainWindow", "Minutes", Q_NULLPTR));
label_5->setText(QApplication::translate("MainWindow", "Buffer", Q_NULLPTR));
preview_widget->setText(QString());
} // retranslateUi
};