8#include "opsmiscsettings.h"
9#include "opsdslrsettings.h"
10#include <KConfigDialog>
12#include "cameraprocess.h"
13#include "camerastate.h"
14#include "capturedeviceadaptor.h"
15#include "captureadaptor.h"
16#include "refocusstate.h"
18#include "kstarsdata.h"
20#include "sequencejob.h"
21#include "placeholderpath.h"
22#include "ekos/manager.h"
23#include "ekos/auxiliary/darklibrary.h"
24#include "ekos/auxiliary/opticaltrainmanager.h"
25#include "ekos/auxiliary/profilesettings.h"
26#include "auxiliary/ksmessagebox.h"
28#include "scriptsmanager.h"
29#include "fitsviewer/fitsdata.h"
30#include "indi/driverinfo.h"
31#include "indi/indifilterwheel.h"
32#include "indi/indicamera.h"
33#include "indi/indirotator.h"
34#include "ekos/guide/guide.h"
35#include <basedevice.h>
37#include <ekos_capture_debug.h>
40#define MF_TIMER_TIMEOUT 90000
41#define MF_RA_DIFF_LIMIT 4
46#define KEY_FILTERS "filtersList"
47#define TAB_BUTTON_SIZE 20
57 qRegisterMetaType<CaptureState>(
"CaptureState");
58 qDBusRegisterMetaType<CaptureState>();
59 new CaptureAdaptor(
this);
61 m_moduleState.
reset(
new CaptureModuleState());
67 addButton->
setFixedSize(TAB_BUTTON_SIZE, TAB_BUTTON_SIZE);
68 addButton->
setToolTip(
i18n(
"<p>Add additional camera</p><p><b>WARNING</b>: This feature is experimental!</p>"));
71 cameraTabs->addTab(newTab,
"");
89 DarkLibrary::Instance()->setCaptureModule(
this);
92 connect(m_moduleState.
get(), &CaptureModuleState::dither,
this, &Capture::dither);
93 connect(m_moduleState.
get(), &CaptureModuleState::newLog,
this, &Capture::appendLogText);
105 m_OpsMiscSettings =
new OpsMiscSettings();
109 m_OpsDslrSettings =
new OpsDslrSettings();
110 page = dialog->
addPage(m_OpsDslrSettings,
i18n(
"DSLR"),
nullptr,
i18n(
"Capture DSLR"),
false);
118 newCamera.
reset(
new Camera(cameras().count(),
false,
nullptr));
121 const int tabIndex = cameraTabs->insertTab(std::max(0, cameraTabs->count() - 1), newCamera.
get(),
"new Camera");
122 cameraTabs->setCurrentIndex(tabIndex);
128 connect(newCamera.
get(), &Camera::newLog,
this, &Capture::appendLogText);
130 connect(newCamera.
get(), &Camera::sequenceChanged,
this, &Capture::sequenceChanged);
131 connect(newCamera.
get(), &Camera::newLocalPreview,
this, &Capture::newLocalPreview);
132 connect(newCamera.
get(), &Camera::dslrInfoRequested,
this, &Capture::dslrInfoRequested);
133 connect(newCamera.
get(), &Camera::trainChanged,
this, &Capture::trainChanged);
134 connect(newCamera.
get(), &Camera::settingsUpdated,
this, &Capture::settingsUpdated);
135 connect(newCamera.
get(), &Camera::filterManagerUpdated,
this, &Capture::filterManagerUpdated);
136 connect(newCamera.
get(), &Camera::newFilterStatus,
this, &Capture::newFilterStatus);
137 connect(newCamera.
get(), &Camera::ready,
this, &Capture::ready);
138 connect(newCamera.
get(), &Camera::newExposureProgress,
this, &Capture::newExposureProgress);
139 connect(newCamera.
get(), &Camera::captureComplete,
this, &Capture::captureComplete);
140 connect(newCamera.
get(), &Camera::captureStarting,
this, &Capture::captureStarting);
141 connect(newCamera.
get(), &Camera::captureAborted,
this, &Capture::captureAborted);
142 connect(newCamera.
get(), &Camera::checkFocus,
this, &Capture::checkFocus);
143 connect(newCamera.
get(), &Camera::newImage,
this, &Capture::newImage);
144 connect(newCamera.
get(), &Camera::runAutoFocus,
this, &Capture::runAutoFocus);
145 connect(newCamera.
get(), &Camera::resetFocusFrame,
this, &Capture::resetFocusFrame);
146 connect(newCamera.
get(), &Camera::abortFocus,
this, &Capture::abortFocus);
147 connect(newCamera.
get(), &Camera::adaptiveFocus,
this, &Capture::adaptiveFocus);
148 connect(newCamera.
get(), &Camera::meridianFlipStarted,
this, &Capture::meridianFlipStarted);
149 connect(newCamera.
get(), &Camera::captureTarget,
this, &Capture::captureTarget);
150 connect(newCamera.
get(), &Camera::guideAfterMeridianFlip,
this, &Capture::guideAfterMeridianFlip);
151 connect(newCamera.
get(), &Camera::newStatus,
this, &Capture::newStatus);
152 connect(newCamera.
get(), &Camera::suspendGuiding,
this, &Capture::suspendGuiding);
153 connect(newCamera.
get(), &Camera::resumeGuiding,
this, &Capture::resumeGuiding);
154 connect(newCamera.
get(), &Camera::resetNonGuidedDither,
this, &Capture::resetNonGuidedDither);
155 connect(newCamera.
get(), &Camera::driverTimedout,
this, &Capture::driverTimedout);
158 const QString train = tabIndex == 0 ?
"" : findUnusedOpticalTrain();
161 newCamera->opticalTrainCombo->setCurrentText(train);
163 moduleState()->addCamera(newCamera);
170const QString Capture::findUnusedOpticalTrain()
172 QList<QString> names = OpticalTrainManager::Instance()->getTrainNames();
173 foreach(
auto cam, cameras())
179 return names.
first();
186 if (tabID < cameraTabs->count() && tabID < cameras().count())
188 auto cam = moduleState()->mutableCameras()[tabID];
190 if (cam->activeCamera() !=
nullptr)
192 auto name = cam->activeCamera()->getDeviceName();
193 cameraTabs->setTabText(tabID, name);
197 cam->state()->getRefocusState()->setForceInSeqAF(moduleState()->forceInSeqAF(cam->opticalTrain()));
200 qCWarning(KSTARS_EKOS_CAPTURE) <<
"Unknown camera ID:" << tabID;
203 cameraTabs->setTabText(cameraTabs->currentIndex(),
"no camera");
209 return process()->setDome(device);
214 if (mainCamera()->m_standAlone)
216 if (name ==
"Mount" && mountInterface ==
nullptr)
218 qCDebug(KSTARS_EKOS_CAPTURE) <<
"Registering new Module (" << name <<
")";
219 mountInterface =
new QDBusInterface(
"org.kde.kstars",
"/KStars/Ekos/Mount",
226 if (mainCameraDevices()->getActiveCamera())
227 return mainCameraDevices()->getActiveCamera()->getDeviceName();
239 if (!mainCameraDevices()->getActiveCamera())
242 mainCameraState()->setSuspendGuidingOnDownload((mainCameraDevices()->getActiveCamera()->getChip(
243 ISD::CameraChip::GUIDE_CCD) == guideChip) ||
244 (guideChip->getCCD() == mainCameraDevices()->getActiveCamera() &&
245 mainCameraDevices()->getActiveCamera()->getDriverInfo()->getAuxInfo().value(
"mdpd",
false).toBool()));
251 for (
auto &cam : cameras())
252 if (trainname ==
"" || cam->opticalTrain() == trainname)
253 cam->setFocusStatus(newstate);
259 for (
auto &cam : cameras())
260 if (trainname ==
"" || cam->opticalTrain() == trainname)
261 cam->focusAdaptiveComplete(success);
266 if (mainCameraDevices()->filterWheel())
267 return mainCameraDevices()->filterWheel()->getDeviceName();
274 if (mainCameraDevices()->filterWheel())
276 mainCamera()->FilterPosCombo->setCurrentText(filter);
285 return mainCamera()->FilterPosCombo->currentText();
296 if (mainCamera()->opticalTrain() != train)
297 mainCamera()->selectOpticalTrain(train);
311 return cam->loadSequenceQueue(fileURL, targetName);
315void Capture::appendLogText(
const QString &text)
317 m_LogText.
insert(0,
i18nc(
"log entry; %1 is the date, %2 is the text",
"%1 %2",
318 KStarsData::Instance()->lt().toString(
"yyyy-MM-ddThh:mm:ss"), text));
320 qCInfo(KSTARS_EKOS_CAPTURE) << text;
325void Capture::clearLog()
333 Q_UNUSED(absTemperture);
335 for (
auto &cam : cameras())
336 if (trainname ==
"" || cam->opticalTrain() == trainname)
337 cam->state()->getRefocusState()->setFocusTemperatureDelta(focusTemperatureDelta);
343 moduleState()->setGuideDeviation(delta_ra, delta_dec);
350 mainCameraState()->setIgnoreJobProgress(
true);
363 qCWarning(KSTARS_EKOS_CAPTURE) <<
"Cannot set the captured frames map for train" << train;
368 cam->state()->setCapturedFramesCount(signature, count);
371void Capture::setAlignStatus(
AlignState newstate)
374 mainCameraState()->setAlignState(newstate);
377void Capture::setGuideStatus(GuideState newstate)
380 moduleState()->setGuideStatus(newstate);
385 if (mainCameraDevices()->getActiveCamera() ==
nullptr)
388 return mainCameraDevices()->getActiveCamera()->setStreamLimits(maxBufferSize, maxPreviewFPS);
402 qCWarning(KSTARS_EKOS_CAPTURE) <<
"Cannot start capturing for train" << train;
411 return cam->opticalTrain();
418 for (
auto cam : cameras())
425 qCWarning(KSTARS_EKOS_CAPTURE) <<
"Cannot abort capturing for train" << train;
438 if (i < cameras().count())
439 return moduleState()->mutableCameras()[i];
442 qCWarning(KSTARS_EKOS_CAPTURE) <<
"Unknown camera ID:" << i;
443 return moduleState()->mutableCameras()[0];
447void Ekos::Capture::closeCameraTab(
int tabIndex)
449 cameraTabs->removeTab(tabIndex);
450 moduleState()->removeCamera(tabIndex);
452 cameraTabs->setCurrentIndex(std::max(0, tabIndex - 1));
455void Capture::checkCloseCameraTab(
int tabIndex)
458 if (tabIndex == cameraTabs->count() - 1)
461 if (moduleState()->mutableCameras()[tabIndex]->state()->isBusy())
467 moduleState()->mutableCameras()[tabIndex]->abort();
468 closeCameraTab(tabIndex);
476 KSMessageBox::Instance()->warningContinueCancel(
i18n(
"Camera %1 is busy. Abort to close?",
477 moduleState()->mutableCameras()[tabIndex]->activeCamera()->getDeviceName()),
i18n(
"Stop capturing"), 30,
false,
482 closeCameraTab(tabIndex);
488 if (cameras().
size() > 0)
489 return moduleState()->cameras()[0];
493 cms.
reset(
new CaptureModuleState());
502 for (
auto &cam : cameras())
504 if (cam->opticalTrain() == train)
505 return cam->m_cameraId;
512 cam->selectOpticalTrain(train);
513 return cam->m_cameraId;
519void Capture::setMountStatus(ISD::Mount::Status newState)
523 case ISD::Mount::MOUNT_PARKING:
524 case ISD::Mount::MOUNT_SLEWING:
525 case ISD::Mount::MOUNT_MOVING:
526 mainCamera()->previewB->setEnabled(
false);
527 mainCamera()->liveVideoB->setEnabled(
false);
531 if (mainCameraState()->isBusy() ==
false)
532 mainCamera()->startB->setEnabled(
false);
536 if (mainCameraState()->isBusy() ==
false)
538 mainCamera()->previewB->setEnabled(
true);
539 if (mainCameraDevices()->getActiveCamera())
540 mainCamera()->liveVideoB->setEnabled(mainCameraDevices()->getActiveCamera()->hasVideoStream());
541 mainCamera()->startB->setEnabled(
true);
548void Capture::setAlignResults(
double solverPA,
double ra,
double de,
double pixscale)
553 if (mainCameraDevices()->rotator() && mainCamera()->m_RotatorControlPanel)
554 mainCamera()->m_RotatorControlPanel->refresh(solverPA);
559 mainCameraState()->setMeridianFlipState(newstate);
560 connect(mainCameraState()->getMeridianFlipState().
get(), &MeridianFlipState::newLog,
this, &Capture::appendLogText);
561 connect(mainCameraState()->getMeridianFlipState().
get(), &MeridianFlipState::newMountMFStatus, moduleState().
get(),
562 &CaptureModuleState::updateMFMountState);
568 for (
auto &cam : cameras())
569 if (cam->process()->hasCoolerControl())
570 result |= cam->process()->hasCoolerControl();
577 for (
auto &cam : cameras())
578 if (cam->process()->hasCoolerControl())
579 result &= cam->process()->setCoolerControl(enable);
586 process()->removeDevice(device);
589QString Capture::getTargetName()
592 return activeJob()->getCoreProperty(SequenceJob::SJ_TargetName).
toString();
600 for (
auto &cam : cameras())
601 if (trainname ==
"" || cam->opticalTrain() == trainname)
602 cam->state()->getRefocusState()->setFocusHFR(newHFR, inAutofocus);
608 for (
auto &cam : cameras())
609 if (trainname ==
"" || cam->opticalTrain() == trainname)
611 cam->state()->getRefocusState()->setForceInSeqAF(requested);
613 moduleState()->setForceInSeqAF(requested, trainname);
void setHFR(double newHFR, int position, bool inAutofocus, const QString &trainname)
setHFR Receive the measured HFR value of the latest frame
bool setVideoLimits(uint16_t maxBufferSize, uint16_t maxPreviewFPS)
setVideoLimits sets the buffer size and max preview fps for live preview
bool setDome(ISD::Dome *device)
setDome Set dome device
void updateCamera(int tabID, bool isValid)
Update the camera.
void inSequenceAFRequested(bool requested, const QString &trainname)
inSequenceAFRequested Focuser informs that the user wishes an AF run as soon as possible.
QSharedPointer< CameraProcess > process() const
process shortcut for the process engine
void setFocusStatus(FocusState newstate, const QString &trainname)
setFocusStatus Forward the new focus state to the capture module state machine
void setFocusTemperatureDelta(double focusTemperatureDelta, double absTemperature, const QString &trainname)
setFocusTemperatureDelta update the focuser's temperature delta
void setGuideDeviation(double delta_ra, double delta_dec)
setGuideDeviation Set the guiding deviation as measured by the guiding module.
void registerNewModule(const QString &name)
registerNewModule Register an Ekos module as it arrives via DBus and create the appropriate DBus inte...
void focusAdaptiveComplete(bool success, const QString &trainname)
focusAdaptiveComplete Forward the new focus state to the capture module state machine
int findCamera(QString train, bool addIfNecessary)
find the camera using the given train
void removeDevice(const QSharedPointer< ISD::GenericDevice > &device)
Generic method for removing any connected device.
CameraChip class controls a particular chip in camera.
Class handles control of INDI dome devices.
KPageWidgetItem * addPage(QWidget *page, const QString &itemName, const QString &pixmapName=QString(), const QString &header=QString(), bool manage=true)
void setIcon(const QIcon &icon)
Q_SCRIPTABLE bool hasCoolerControl()
DBUS interface function.
void prepareGUI()
prepareGUI Perform once only GUI prep processing
Q_SCRIPTABLE Q_NOREPLY void abort(QString train="")
DBUS interface function.
Q_SCRIPTABLE Q_NOREPLY void ignoreSequenceHistory()
DBUS interface function.
Q_SCRIPTABLE QString start(QString train="")
DBUS interface function.
Q_SCRIPTABLE bool loadSequenceQueue(const QString &fileURL, QString train="", bool isLead=true, QString targetName="")
DBUS interface function.
Q_SCRIPTABLE bool setCoolerControl(bool enable)
DBUS interface function.
Q_SCRIPTABLE bool setFilter(const QString &filter)
DBUS interface function.
Q_SCRIPTABLE Q_NOREPLY void setCapturedFramesMap(const QString &signature, int count, QString train="")
DBUS interface function.
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
Ekos is an advanced Astrophotography tool for Linux.
KIOCORE_EXPORT TransferJob * get(const QUrl &url, LoadType reload=NoReload, JobFlags flags=DefaultFlags)
bool connect(const QString &service, const QString &path, const QString &interface, const QString &name, QObject *receiver, const char *slot)
bool registerObject(const QString &path, QObject *object, RegisterOptions options)
QDBusConnection sessionBus()
QIcon fromTheme(const QString &name)
iterator insert(const_iterator before, parameter_type value)
bool isEmpty() const const
qsizetype removeAll(const AT &t)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
bool disconnect(const QMetaObject::Connection &connection)
QString toString() const const