Photo capture and PHD dither support
This commit is contained in:
@@ -0,0 +1,142 @@
|
||||
#include "photocapture.h"
|
||||
#include <QHBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QFileDialog>
|
||||
#include <QStandardPaths>
|
||||
#include <QDateTime>
|
||||
#include <QDebug>
|
||||
#include <QTimer>
|
||||
#include <QHostAddress>
|
||||
|
||||
PhotoCapture::PhotoCapture(QWidget *parent) : QWidget(parent)
|
||||
{
|
||||
QHBoxLayout *layout = new QHBoxLayout(this);
|
||||
setLayout(layout);
|
||||
|
||||
layout->addWidget(new QLabel(tr("Exposure time"), this));
|
||||
_exposureTime = new QSpinBox(this);
|
||||
_exposureTime->setValue(60);
|
||||
_exposureTime->setSingleStep(60);
|
||||
_exposureTime->setRange(0, 3600);
|
||||
_exposureTime->setSuffix("s");
|
||||
layout->addWidget(_exposureTime);
|
||||
|
||||
layout->addWidget(new QLabel(tr("Count"), this));
|
||||
_numberOfExposures = new QSpinBox(this);
|
||||
_numberOfExposures->setValue(1);
|
||||
layout->addWidget(_numberOfExposures);
|
||||
|
||||
layout->addWidget(new QLabel(tr("Dither frequency"), this));
|
||||
_ditherFreq = new QSpinBox(this);
|
||||
_ditherFreq->setValue(1);
|
||||
_ditherFreq->setRange(0, 10);
|
||||
layout->addWidget(_ditherFreq);
|
||||
|
||||
_startCapture = new QPushButton(tr("Start capture"), this);
|
||||
connect(_startCapture, SIGNAL(clicked()), this, SLOT(startCaputre()));
|
||||
layout->addWidget(_startCapture);
|
||||
|
||||
QPushButton *selectDirButton = new QPushButton(tr("Select output"), this);
|
||||
layout->addWidget(selectDirButton);
|
||||
connect(selectDirButton, SIGNAL(clicked()), this, SLOT(selectDir()));
|
||||
|
||||
_process = new QProcess(this);
|
||||
_process->setProgram("gphoto2");
|
||||
connect(_process, SIGNAL(finished(int)), this, SLOT(processFinished(int)));
|
||||
connect(_process, SIGNAL(readyReadStandardOutput()), this, SLOT(readStdout()));
|
||||
connect(_process, SIGNAL(readyReadStandardError()), this, SLOT(readStderr()));
|
||||
|
||||
QStringList paths = QStandardPaths::standardLocations(QStandardPaths::PicturesLocation);
|
||||
if(paths.size())
|
||||
_outputDir.setPath(paths.first()+"/astro");
|
||||
|
||||
_timer = new QTimer(this);
|
||||
_timer->setInterval(1000);
|
||||
_timer->setSingleShot(true);
|
||||
connect(_timer, SIGNAL(timeout()), this, SLOT(startCaputre()));
|
||||
|
||||
_phd = new PHD(this);
|
||||
_phd->connectTo(QHostAddress("127.0.0.1"));
|
||||
connect(_phd, SIGNAL(settled()), this, SLOT(startCaputre()));
|
||||
|
||||
_photoCount = 0;
|
||||
}
|
||||
|
||||
PhotoCapture::~PhotoCapture()
|
||||
{
|
||||
if(_process->state()==QProcess::Running)
|
||||
{
|
||||
_process->terminate();
|
||||
_process->waitForFinished(5000);
|
||||
}
|
||||
}
|
||||
|
||||
void PhotoCapture::startCaputre()
|
||||
{
|
||||
if(_process->state()==QProcess::Running)
|
||||
{
|
||||
_process->terminate();
|
||||
_process->waitForFinished(10000);
|
||||
_startCapture->setText(tr("Start capture"));
|
||||
_numberOfExposures->setValue(0);
|
||||
_photoCount = 0;
|
||||
}
|
||||
else if(_numberOfExposures->value()>0)
|
||||
{
|
||||
_photoCount++;
|
||||
_startCapture->setText(tr("Stop capture"));
|
||||
QString file = "capt"+QDateTime::currentDateTime().toString(Qt::ISODate)+".cr2";
|
||||
QString path = _outputDir.absoluteFilePath(file);
|
||||
|
||||
QStringList args = {"--force-overwrite", "--set-config", "eosremoterelease=5",
|
||||
QString("--wait-event=%1s").arg(_exposureTime->value()),
|
||||
"--set-config", "eosremoterelease=9",
|
||||
"--wait-event-and-download=3s",
|
||||
QString("--filename=%1").arg(path)};
|
||||
_process->setArguments(args);
|
||||
_process->start();
|
||||
}
|
||||
else
|
||||
{
|
||||
_photoCount = 0;
|
||||
_startCapture->setText(tr("Start capture"));
|
||||
}
|
||||
}
|
||||
|
||||
void PhotoCapture::processFinished(int exit)
|
||||
{
|
||||
if(exit==0)
|
||||
{
|
||||
_numberOfExposures->setValue(_numberOfExposures->value()-1);
|
||||
if(_ditherFreq->value() == _photoCount)
|
||||
{
|
||||
_photoCount = 0;
|
||||
_phd->dither(4, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
_timer->start();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << "gphoto failed" << exit;
|
||||
_startCapture->setText(tr("Start capture"));
|
||||
}
|
||||
}
|
||||
|
||||
void PhotoCapture::selectDir()
|
||||
{
|
||||
QString path = QFileDialog::getExistingDirectory(this, tr("Output directory"), _outputDir.absolutePath());
|
||||
_outputDir.setPath(path);
|
||||
}
|
||||
|
||||
void PhotoCapture::readStdout()
|
||||
{
|
||||
//qDebug() << _process->readAllStandardOutput();
|
||||
}
|
||||
|
||||
void PhotoCapture::readStderr()
|
||||
{
|
||||
//qDebug() << _process->readAllStandardError();
|
||||
}
|
||||
Reference in New Issue
Block a user