From 8b80bf11d9aa46ff16116b0c1d7b8160455807de Mon Sep 17 00:00:00 2001 From: Jan Grewe Date: Mon, 16 Mar 2020 11:26:50 +0100 Subject: [PATCH] more messaging for user, reduce writer waiting time --- grabber.cpp | 1 - pylonrecorder.cpp | 46 +++++++++++++++++++++++++++++++++++++++++----- pylonrecorder.h | 8 ++++---- writer.cpp | 4 +--- 4 files changed, 46 insertions(+), 13 deletions(-) diff --git a/grabber.cpp b/grabber.cpp index 4c00e02..4c70d09 100644 --- a/grabber.cpp +++ b/grabber.cpp @@ -18,6 +18,5 @@ void Grabber::run() { count += 1; } cam->StopGrabbing(); - std::cerr << "terminated: " << count << std::endl; } } diff --git a/pylonrecorder.cpp b/pylonrecorder.cpp index 940544f..827bec3 100644 --- a/pylonrecorder.cpp +++ b/pylonrecorder.cpp @@ -54,6 +54,8 @@ PylonRecorder::PylonRecorder(QWidget *parent) connect(frameTimer, &QTimer::timeout, this, &PylonRecorder::displaySingleFrame); preassureTimer = new QTimer(this); connect(preassureTimer, &QTimer::timeout, this, &PylonRecorder::displayBufferPreassure); + labelTimer = new QTimer(this); + connect(labelTimer, &QTimer::timeout, this, &PylonRecorder::displayActivity); preassureBar = new QProgressBar(this); preassureBar->setRange(0, 100); @@ -68,10 +70,23 @@ PylonRecorder::PylonRecorder(QWidget *parent) loadBar->setRange(0, 1000); QLabel *loadLabel = new QLabel("Load:", this); + writingLabel = new QLabel("writing"); + //writingLabel->setStyleSheet("QLabel { color : gray; }"); + writingLabel->setEnabled(false); + grabbingLabel = new QLabel("grabbing"); + //grabbingLabel->setStyleSheet("QLabel { color : gray; }"); + grabbingLabel->setEnabled(false); + labelSwitch = false; + cameraConnectedLabel = new QLabel("disconnected"); + + statusBar()->addWidget(new QLabel("Camera:")); + statusBar()->addWidget(cameraConnectedLabel); statusBar()->addWidget(preassureLabel); statusBar()->addWidget(preassureBar); statusBar()->addWidget(loadLabel); statusBar()->addWidget(loadBar); + statusBar()->addWidget(grabbingLabel); + statusBar()->addWidget(writingLabel); resize(QGuiApplication::primaryScreen()->availableSize() * 3 / 5); } @@ -384,7 +399,11 @@ void PylonRecorder::adjustScrollBar(QScrollBar *scrollBar, double factor) { void PylonRecorder::connectCamera() { std::string message; - pylon->openCamera(message); + bool success = pylon->openCamera(message); + if (success) { + cameraConnectedLabel->setText("connected"); + cameraConnectedLabel->setStyleSheet("QLabel { color : green; }"); + } statusBar()->showMessage(QString::fromStdString(message)); updateActions(); } @@ -392,6 +411,8 @@ void PylonRecorder::connectCamera() { void PylonRecorder::disconnectCamera() { pylon->closeCamera(); statusBar()->showMessage(tr("Camera closed!")); + cameraConnectedLabel->setText("disconnected"); + cameraConnectedLabel->setStyleSheet("QLabel { color : black; }"); updateActions(); } @@ -410,29 +431,44 @@ void PylonRecorder::startRecording() { grabber->start(); writer->start(); grabbing = true; + writing = true; + stopRequest = false; preassureTimer->start(50); frameTimer->start(50); + labelTimer->start(333); updateActions(); } void PylonRecorder::stopRecording() { - frameTimer->stop(); - grabber->requestStop(); - writer->requestStop(); + if (!stopRequest) { + frameTimer->stop(); + grabber->requestStop(); + writer->requestStop(); + grabbing = false; + stopRequest = true; + } } void PylonRecorder::writerDone() { preassureTimer->stop(); preassureBar->reset(); loadBar->reset(); + labelTimer->stop(); + writingLabel->setEnabled(false); + grabbingLabel->setEnabled(false); grabber->wait(10000); writer->wait(10000); - grabbing = false; + writing = false; updateActions(); } +void PylonRecorder::displayActivity() { + grabbingLabel->setEnabled(labelSwitch && grabbing); + writingLabel->setEnabled(labelSwitch && writing); + labelSwitch = !labelSwitch; +} void PylonRecorder::displaySingleFrame() { MyImage img; bool valid = buffer->readLast(img); diff --git a/pylonrecorder.h b/pylonrecorder.h index 2a821e8..8479990 100644 --- a/pylonrecorder.h +++ b/pylonrecorder.h @@ -56,6 +56,7 @@ private slots: void quitApplication(); void displaySingleFrame(); void displayBufferPreassure(); + void displayActivity(); void writerDone(); private: @@ -71,9 +72,8 @@ private: void adjustScrollBar(QScrollBar *scrollBar, double factor); QImage image; - QTimer *frameTimer; - QTimer *preassureTimer; - QLabel *imageLabel; + QTimer *frameTimer, *preassureTimer, *labelTimer; + QLabel *imageLabel, *writingLabel, *grabbingLabel, *cameraConnectedLabel; QProgressBar *preassureBar; QProgressBar *loadBar; QScrollArea *scrollArea; @@ -82,7 +82,7 @@ private: ImageBuffer *buffer; Grabber *grabber; Writer *writer; - bool grabbing; + bool grabbing, stopRequest, writing, labelSwitch; QPalette progressPalette; #if defined(QT_PRINTSUPPORT_LIB) && QT_CONFIG(printer) diff --git a/writer.cpp b/writer.cpp index 2c23712..87d09f1 100644 --- a/writer.cpp +++ b/writer.cpp @@ -28,14 +28,12 @@ void Writer::run() { } } } else { - while (buffer->bufferLoad() < 5 && !stop_request) { + while (buffer->bufferLoad() < 1 && !stop_request) { msleep(10); - std::cerr << "waiting.." << buffer->bufferLoad() << std::endl; } } } videoWriter.Close(); - std::cerr << "writer terminated: " << count << std::endl; } else { std::cerr << "Got no video specifications, not writing!" << std::endl; }