Skip to content
Snippets Groups Projects
Commit 8f5311e1 authored by am0ebe's avatar am0ebe
Browse files

[not tested] progressbar for recordings: add functions to iprinter to print...

[not tested] progressbar for recordings: add functions to iprinter to print progressbar, get width from console and calc chars, get times and format mm:ss.
parent 2a59fe82
No related branches found
No related tags found
No related merge requests found
......@@ -256,6 +256,16 @@ void Cam::showRecordingStats()
}
void Cam::showRecordingProgress()
{
if( _state != recording )
return; // error("cant show progress, when cam is " + stateToString(_state));
//TODO test
//fps?
progressBar(_timer);
}
void Cam::printFeatures( QString feature)
{
printFeatures(QStringList(feature));
......
......@@ -61,6 +61,7 @@ public:
QString printCamInfo();
void showRecordingStats();
void showRecordingProgress();
void printFeatures(QStringList);
void printFeatures(QString);
......
......@@ -10,7 +10,7 @@
#include <QTimer>
#include <iostream>
#include <math.h>
#include <cmath>
using utils::DELIM;
......
#include "iprinter.h"
#include <QDebug>
#include <QTimer>
#ifdef CONSOLE
#include "cmd/console.h"
#include <cstdlib>
#endif
IPrinter::IPrinter(QObject *parent) : QObject(parent)
{
#ifdef CONSOLE //defined in .pro
......@@ -22,6 +28,36 @@ IPrinter::~IPrinter()
{
}
bool IPrinter::f(const VmbErrorType& ret, const QString& msg)
{
// vimba function wrapper to test return type and potentially emit error message or successmsg
// returns true on error
// qDebug() << __LINE__ << "-" << __PRETTY_FUNCTION__ << " ret:" << ret << " msg:" << msg;
if ( VmbErrorSuccess == ret )
{
if (! msg.isEmpty())
emit info(msg);
return false;
}
else
{
if (! msg.isEmpty())
emit info("Fail! " + msg);
emit error(ret);
return true;
}
}
void IPrinter::g(const VmbErrorType& ret, const QString& msg)
{
//vimba function wrapper - throws exception on error - to declutter error handling code
if( f(ret,msg) )
throw std::runtime_error("Error: " + msg.toStdString());
}
void IPrinter::print(const QStringList& name)
{
emit info(name);
......@@ -70,31 +106,47 @@ void IPrinter::print(const char* name, const QString& val)
emit info(QString::fromLocal8Bit(name) + ": " + val);
}
bool IPrinter::f(const VmbErrorType& ret, const QString& msg)
void IPrinter::progressBar(QTimer* timer)
{
// vimba function wrapper to test return type and potentially emit error message or successmsg
// returns true on error
// qDebug() << __LINE__ << "-" << __PRETTY_FUNCTION__ << " ret:" << ret << " msg:" << msg;
int total_ms = timer->interval();
int remaining_ms = timer->remainingTime();
auto elapsed_ms = total_ms - remaining_ms;
int progressInPercent = (double) elapsed_ms / total_ms;
//print in minutes and secs
print(QString::number(progressInPercent) + "% | " + formatTime(elapsed_ms) + " < " + formatTime(remaining_ms));
progressBar(progressInPercent);
}
if ( VmbErrorSuccess == ret )
{
if (! msg.isEmpty())
emit info(msg);
void IPrinter::progressBar(int percentage)
{
return false;
int cols = 42;
if (const char* env_p = std::getenv("COLUMNS"))
{
cols = atoi(env_p);
}
else
qDebug() << "#col: " << cols;
// print without appending newline
QDebug deb = qDebug();
deb << "[";
int pos_progress = cols*(percentage/100.0);
for(int pos=1; pos<cols-1; pos++)
{
if (! msg.isEmpty())
emit info("Fail! " + msg);
emit error(ret);
return true;
if( pos < pos_progress )
deb << "=";
else
deb << " ";
}
deb << "]";
}
void IPrinter::g(const VmbErrorType& ret, const QString& msg)
QString IPrinter::formatTime(const int& milliseconds)
{
//vimba function wrapper - throws exception on error - to declutter error handling code
if( f(ret,msg) )
throw std::runtime_error("Error: " + msg.toStdString());
int seconds = milliseconds / 1000;
int minutes = seconds / 60;
seconds %= 60;
return QString::asprintf("%02d:%02d", minutes, seconds);
}
......@@ -6,6 +6,8 @@
#include <QString>
#include <QStringList>
class QTimer;
// common functionality "interface" for printing, error handling and connecting messages to CMD
class IPrinter : public QObject
{
......@@ -35,4 +37,13 @@ public:
void print(const char*);
void print(const char*, const VmbInt64_t&);
void print(const char*, const QString&);
void progressBar(QTimer*);
private:
void progressBar(int);
QString formatTime(const int&);
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment