7#include "sequencejobstate.h"
10#include "kstarsdata.h"
12#include "ekos/auxiliary/rotatorutils.h"
18 m_CameraState = sharedState;
21void SequenceJobState::setFrameType(CCDFrameType frameType)
24 m_frameType = frameType;
26 m_PreparationState = PREP_NONE;
29void SequenceJobState::initPreparation(
bool isPreview)
32 m_isPreview = isPreview;
33 wpScopeStatus = WP_NONE;
36void SequenceJobState::prepareLightFrameCapture(
bool enforceCCDTemp,
bool isPreview)
39 if (m_status == JOB_BUSY && enforceCCDTemp == m_enforceTemperature)
43 initPreparation(isPreview);
49 emit setCCDBatchMode(!isPreview);
52 prepareTemperatureCheck(enforceCCDTemp);
55 prepareRotatorCheck();
60 m_PreparationState = PREP_BUSY;
62 checkAllActionsReady();
65void SequenceJobState::prepareFlatFrameCapture(
bool enforceCCDTemp,
bool isPreview)
68 if (m_status == JOB_BUSY && enforceCCDTemp == m_enforceTemperature)
72 initPreparation(isPreview);
78 emit setCCDBatchMode(!isPreview);
81 prepareTemperatureCheck(enforceCCDTemp);
84 m_PreparationState = PREP_BUSY;
86 checkAllActionsReady();
89void SequenceJobState::prepareDarkFrameCapture(
bool enforceCCDTemp,
bool isPreview)
92 if (m_status == JOB_BUSY && enforceCCDTemp == m_enforceTemperature)
96 initPreparation(isPreview);
102 emit setCCDBatchMode(!isPreview);
105 prepareTemperatureCheck(enforceCCDTemp);
108 m_PreparationState = PREP_BUSY;
110 checkAllActionsReady();
113void SequenceJobState::prepareBiasFrameCapture(
bool enforceCCDTemp,
bool isPreview)
115 prepareDarkFrameCapture(enforceCCDTemp, isPreview);
118bool SequenceJobState::initCapture(CCDFrameType frameType,
bool isPreview,
bool isAutofocusReady, FITSMode mode)
120 m_PreparationState = PREP_INIT_CAPTURE;
121 autoFocusReady = isAutofocusReady;
125 prepareTargetFilter(frameType, isPreview);
126 checkAllActionsReady();
128 return areActionsReady();
131bool SequenceJobState::areActionsReady()
133 for (
bool &ready : prepareActions.values())
142void SequenceJobState::checkAllActionsReady()
144 switch (m_PreparationState)
151 if (areActionsReady())
154 if (checkLightFrameScopeCoverOpen() != IPS_OK)
157 m_PreparationState = PREP_COMPLETED;
158 emit prepareComplete();
162 if (!areActionsReady())
166 if (checkFlatsCoverReady() != IPS_OK)
173 if (checkFlatSyncFocus() != IPS_OK)
177 if (m_PreparationState == PREP_BUSY)
179 m_PreparationState = PREP_COMPLETED;
180 emit prepareComplete();
186 if (!areActionsReady())
190 if (checkDarksCoverReady() != IPS_OK)
194 if (m_PreparationState == PREP_BUSY)
196 m_PreparationState = PREP_COMPLETED;
197 emit prepareComplete();
202 emit prepareComplete();
208 case PREP_INIT_CAPTURE:
209 if (areActionsReady())
212 m_PreparationState = PREP_NONE;
213 emit initCaptureComplete(m_fitsMode);
224void SequenceJobState::setAllActionsReady()
234 for (CameraState::PrepareActions action :
236 CameraState::ACTION_FILTER, CameraState::ACTION_ROTATOR, CameraState::ACTION_TEMPERATURE
238 setInitialized(action,
false);
241void SequenceJobState::prepareTargetFilter(CCDFrameType frameType,
bool isPreview)
243 if (targetFilterID != INVALID_VALUE)
245 if (isInitialized(CameraState::ACTION_FILTER) ==
false)
247 prepareActions[CameraState::ACTION_FILTER] =
false;
250 if (isPreview || frameType != FRAME_LIGHT || autoFocusReady ==
false)
251 m_filterPolicy =
static_cast<FilterManager::FilterPolicy
>(m_filterPolicy & ~FilterManager::AUTOFOCUS_POLICY);
253 emit readFilterPosition();
255 else if (targetFilterID != m_CameraState->currentFilterID)
258 prepareActions[CameraState::ACTION_FILTER] =
false;
261 m_filterPolicy = FilterManager::ALL_POLICIES;
264 if (isPreview || frameType != FRAME_LIGHT || autoFocusReady ==
false)
265 m_filterPolicy =
static_cast<FilterManager::FilterPolicy
>(m_filterPolicy & ~FilterManager::AUTOFOCUS_POLICY);
267 emit changeFilterPosition(targetFilterID, m_filterPolicy);
273void SequenceJobState::prepareTemperatureCheck(
bool enforceCCDTemp)
276 m_enforceTemperature = enforceCCDTemp;
278 if (m_enforceTemperature)
280 prepareActions[CameraState::ACTION_TEMPERATURE] =
false;
281 if (isInitialized(CameraState::ACTION_TEMPERATURE))
285 ignoreNextValue[CameraState::ACTION_TEMPERATURE] =
true;
287 emit setCCDTemperature(targetTemperature);
297void SequenceJobState::prepareRotatorCheck()
299 if (targetPositionAngle > Ekos::INVALID_VALUE)
301 if (isInitialized(CameraState::ACTION_ROTATOR))
303 prepareActions[CameraState::ACTION_ROTATOR] =
false;
304 double rawAngle = RotatorUtils::Instance()->calcRotatorAngle(targetPositionAngle);
306 emit setRotatorAngle(rawAngle);
314IPState SequenceJobState::checkCalibrationPreActionsReady()
316 IPState result = IPS_OK;
318 if (m_CalibrationPreAction & ACTION_WALL)
319 result = checkWallPositionReady(FRAME_FLAT);
321 if (result != IPS_OK)
324 if (m_CalibrationPreAction & ACTION_PARK_MOUNT)
325 result = checkPreMountParkReady();
327 if (result != IPS_OK)
330 if (m_CalibrationPreAction & ACTION_PARK_DOME)
331 result = checkPreDomeParkReady();
336IPState SequenceJobState::checkFlatsCoverReady()
338 auto result = checkCalibrationPreActionsReady();
339 if (result == IPS_OK)
341 if (m_CameraState->hasDustCap && m_CameraState->hasLightBox)
342 return checkDustCapReady(FRAME_FLAT);
344 else if (m_CalibrationPreAction & ACTION_WALL)
349 if (m_CameraState->hasLightBox)
350 return checkDustCapReady(FRAME_FLAT);
352 return checkManualCoverReady(
true);
359IPState SequenceJobState::checkDarksCoverReady()
361 IPState result = checkCalibrationPreActionsReady();;
363 if (result == IPS_OK)
366 result = checkHasShutter();
367 if (result != IPS_OK)
370 if (m_CameraState->hasDustCap)
371 return checkDustCapReady(FRAME_DARK);
373 else if (m_CalibrationPreAction & ACTION_WALL)
376 return checkManualCoverReady(
false);
381IPState SequenceJobState::checkManualCoverReady(
bool lightSourceRequired)
384 if (lightSourceRequired && m_CameraState->m_ManualCoverState != CameraState::MANUAL_COVER_CLOSED_LIGHT)
386 if (coverQueryState == CAL_CHECK_CONFIRMATION)
390 emit askManualScopeCover(
i18n(
"Cover the telescope with an evenly illuminated light source."),
391 i18n(
"Flat Frame"),
true);
392 coverQueryState = CAL_CHECK_CONFIRMATION;
396 else if (!lightSourceRequired && m_CameraState->m_ManualCoverState != CameraState::MANUAL_COVER_CLOSED_DARK &&
397 m_CameraState->shutterStatus == CameraState::SHUTTER_NO)
399 if (coverQueryState == CAL_CHECK_CONFIRMATION)
402 emit askManualScopeCover(
i18n(
"Cover the telescope in order to take a dark exposure."),
403 i18n(
"Dark Exposure"),
false);
405 coverQueryState = CAL_CHECK_CONFIRMATION;
412IPState SequenceJobState::checkDustCapReady(CCDFrameType frameType)
415 if (m_CameraState->getLightBoxLightState() == CameraState::CAP_LIGHT_BUSY ||
416 m_CameraState->getDustCapState() == CameraState::CAP_PARKING ||
417 m_CameraState->getDustCapState() == CameraState::CAP_UNPARKING)
420 if (m_CameraState->getDustCapState() == CameraState::CAP_ERROR)
423 auto captureLights = (frameType == FRAME_LIGHT);
426 CameraState::CapState targetCapState = captureLights ? CameraState::CAP_IDLE : CameraState::CAP_PARKED;
428 if (m_CameraState->hasDustCap && m_CameraState->getDustCapState() != targetCapState)
430 m_CameraState->setDustCapState(captureLights ? CameraState::CAP_UNPARKING : CameraState::CAP_PARKING);
431 emit parkDustCap(!captureLights);
432 emit newLog(captureLights ?
i18n(
"Unparking dust cap...") :
i18n(
"Parking dust cap..."));
436 auto captureFlats = (frameType == FRAME_FLAT);
437 CameraState::LightState targetLightBoxStatus = captureFlats ? CameraState::CAP_LIGHT_ON :
438 CameraState::CAP_LIGHT_OFF;
440 if (m_CameraState->hasLightBox && m_CameraState->getLightBoxLightState() != targetLightBoxStatus)
442 m_CameraState->setLightBoxLightState(CameraState::CAP_LIGHT_BUSY);
443 emit setLightBoxLight(captureFlats);
444 emit newLog(captureFlats ?
i18n(
"Turn light box light on...") :
i18n(
"Turn light box light off..."));
452IPState SequenceJobState::checkWallPositionReady(CCDFrameType frametype)
454 if (m_CameraState->hasTelescope)
456 if (wpScopeStatus < WP_SLEWING)
459 KStarsData::Instance()->
geo()->lat());
460 wpScopeStatus = WP_SLEWING;
461 emit slewTelescope(wallCoord);
462 emit newLog(
i18n(
"Mount slewing to wall position (az =%1 alt =%2)",
467 else if (wpScopeStatus == WP_SLEWING || wpScopeStatus == WP_TRACKING_BUSY)
470 else if (wpScopeStatus == WP_SLEW_COMPLETED)
472 wpScopeStatus = WP_TRACKING_BUSY;
473 emit setScopeTracking(
false);
474 emit newLog(
i18n(
"Slew to wall position complete, stop tracking."));
477 else if (wpScopeStatus == WP_TRACKING_OFF)
478 emit newLog(
i18n(
"Slew to wall position complete, tracking stopped."));
481 bool captureFlats = (frametype == FRAME_FLAT);
482 CameraState::LightState targetLightState = (captureFlats ? CameraState::CAP_LIGHT_ON :
483 CameraState::CAP_LIGHT_OFF);
485 if (m_CameraState->hasLightBox ==
true)
487 if (m_CameraState->getLightBoxLightState() != targetLightState)
489 m_CameraState->setLightBoxLightState(CameraState::CAP_LIGHT_BUSY);
490 emit setLightBoxLight(captureFlats);
491 emit newLog(captureFlats ?
i18n(
"Turn light box light on...") :
i18n(
"Turn light box light off..."));
500IPState SequenceJobState::checkPreMountParkReady()
502 if (m_CameraState->hasTelescope)
504 switch (m_CameraState->getScopeParkState())
506 case ISD::PARK_PARKED:
508 case ISD::PARK_ERROR:
509 emit newLog(
i18n(
"Parking mount failed, aborting..."));
512 case ISD::PARK_PARKING:
514 case ISD::PARK_UNPARKED:
515 case ISD::PARK_UNPARKING:
517 emit setScopeParked(
true);
518 emit newLog(
i18n(
"Parking mount prior to calibration frames capture..."));
520 case ISD::PARK_UNKNOWN:
522 emit readCurrentMountParkState();
531IPState SequenceJobState::checkPreDomeParkReady()
533 if (m_CameraState->hasDome)
535 if (m_CameraState->getDomeState() == ISD::Dome::DOME_ERROR)
537 emit newLog(
i18n(
"Parking dome failed, aborting..."));
541 else if (m_CameraState->getDomeState() == ISD::Dome::DOME_PARKING)
543 else if (m_CameraState->getDomeState() != ISD::Dome::DOME_PARKED)
545 m_CameraState->setDomeState(ISD::Dome::DOME_PARKING);
546 emit setDomeParked(
true);
547 emit newLog(
i18n(
"Parking dome prior to calibration frames capture..."));
555IPState SequenceJobState::checkFlatSyncFocus()
558 if (flatSyncStatus == FS_BUSY)
563 emit flatSyncFocus(targetFilterID);
568 if (m_frameType == FRAME_FLAT && Options::flatSyncFocus() && flatSyncStatus != FS_COMPLETED)
570 flatSyncStatus = FS_BUSY;
571 emit flatSyncFocus(targetFilterID);
578IPState SequenceJobState::checkHasShutter()
580 if (m_CameraState->shutterStatus == CameraState::SHUTTER_BUSY)
582 if (m_CameraState->shutterStatus != CameraState::SHUTTER_UNKNOWN)
585 m_CameraState->shutterStatus = CameraState::SHUTTER_BUSY;
586 emit queryHasShutter();
590IPState SequenceJobState::checkLightFrameScopeCoverOpen()
593 if (m_CameraState->hasLightBox && m_CameraState->getLightBoxLightState() != CameraState::CAP_LIGHT_OFF)
595 if (m_CameraState->getLightBoxLightState() != CameraState::CAP_LIGHT_BUSY)
597 m_CameraState->setLightBoxLightState(CameraState::CAP_LIGHT_BUSY);
598 emit setLightBoxLight(
false);
599 emit newLog(
i18n(
"Turn light box light off..."));
605 if (m_CameraState->hasDustCap)
607 if (m_CameraState->getDustCapState() != CameraState::CAP_IDLE)
609 if (m_CameraState->getDustCapState() != CameraState::CAP_UNPARKING)
611 m_CameraState->setDustCapState(CameraState::CAP_UNPARKING);
612 emit parkDustCap(
false);
613 emit newLog(
i18n(
"Unparking dust cap..."));
623 if (m_CameraState->m_ManualCoverState != CameraState::MANAUL_COVER_OPEN)
628 if (coverQueryState == CAL_CHECK_CONFIRMATION)
631 emit askManualScopeOpen(m_CameraState->m_ManualCoverState == CameraState::MANUAL_COVER_CLOSED_LIGHT);
640bool SequenceJobState::isInitialized(CameraState::PrepareActions action)
642 return m_CameraState.
data()->isInitialized[action];
645void SequenceJobState::setInitialized(CameraState::PrepareActions action,
bool init)
647 m_CameraState.
data()->isInitialized[action] =
init;
650void SequenceJobState::setCurrentFilterID(
int value)
652 m_CameraState->currentFilterID = value;
653 if (isInitialized(CameraState::ACTION_FILTER) ==
false && value != targetFilterID)
657 prepareActions[CameraState::ACTION_FILTER] =
false;
659 emit changeFilterPosition(targetFilterID, m_filterPolicy);
662 setInitialized(CameraState::ACTION_FILTER,
true);
664 if (value == targetFilterID)
665 prepareActions[CameraState::ACTION_FILTER] =
true;
667 checkAllActionsReady();
670void SequenceJobState::setCurrentCCDTemperature(
double currentTemperature)
673 if (ignoreNextValue[CameraState::ACTION_TEMPERATURE])
675 ignoreNextValue[CameraState::ACTION_TEMPERATURE] =
false;
679 if (isInitialized(CameraState::ACTION_TEMPERATURE))
681 if (m_enforceTemperature ==
false
682 || fabs(targetTemperature - currentTemperature) <= Options::maxTemperatureDiff())
683 prepareActions[CameraState::ACTION_TEMPERATURE] =
true;
685 checkAllActionsReady();
689 setInitialized(CameraState::ACTION_TEMPERATURE,
true);
690 if (m_enforceTemperature ==
false
691 || fabs(targetTemperature - currentTemperature) <= Options::maxTemperatureDiff())
693 prepareActions[CameraState::ACTION_TEMPERATURE] =
true;
694 checkAllActionsReady();
698 prepareTemperatureCheck(m_enforceTemperature);
703void SequenceJobState::setCurrentRotatorPositionAngle(
double rotatorAngle, IPState state)
705 double currentPositionAngle = RotatorUtils::Instance()->calcCameraAngle(rotatorAngle,
false);
707 if (isInitialized(CameraState::ACTION_ROTATOR))
711 if (fabs(currentPositionAngle - targetPositionAngle) * 60 <= Options::astrometryRotatorThreshold()
712 && state != IPS_BUSY)
713 prepareActions[CameraState::ACTION_ROTATOR] =
true;
715 checkAllActionsReady();
719 setInitialized(CameraState::ACTION_ROTATOR,
true);
720 if (fabs(currentPositionAngle - targetPositionAngle) * 60 <= Options::astrometryRotatorThreshold()
721 && state != IPS_BUSY)
723 prepareActions[CameraState::ACTION_ROTATOR] =
true;
724 checkAllActionsReady();
728 prepareRotatorCheck();
733void SequenceJobState::setFocusStatus(FocusState state)
739 if (prepareActions[CameraState::ACTION_AUTOFOCUS] ==
false)
741 prepareActions[CameraState::ACTION_AUTOFOCUS] =
true;
742 checkAllActionsReady();
748 emit prepareComplete(
false);
756void SequenceJobState::updateManualScopeCover(
bool closed,
bool success,
bool light)
762 m_CameraState->m_ManualCoverState = light ? CameraState::MANUAL_COVER_CLOSED_LIGHT :
763 CameraState::MANUAL_COVER_CLOSED_DARK;
765 m_CameraState->m_ManualCoverState = CameraState::MANAUL_COVER_OPEN;
766 coverQueryState = CAL_CHECK_TASK;
768 checkAllActionsReady();
773 m_CameraState->shutterStatus = CameraState::SHUTTER_UNKNOWN;
774 coverQueryState = CAL_CHECK_TASK;
780void SequenceJobState::lightBoxLight(
bool on)
782 m_CameraState->setLightBoxLightState(on ? CameraState::CAP_LIGHT_ON : CameraState::CAP_LIGHT_OFF);
783 emit newLog(
i18n(on ?
"Light box on." :
"Light box off."));
785 checkAllActionsReady();
788void SequenceJobState::dustCapStateChanged(ISD::DustCap::Status status)
792 case ISD::DustCap::CAP_ERROR:
801 checkAllActionsReady();
804void SequenceJobState::scopeStatusChanged(ISD::Mount::Status status)
809 case ISD::Mount::MOUNT_TRACKING:
810 if (wpScopeStatus == WP_SLEWING)
811 wpScopeStatus = WP_SLEW_COMPLETED;
813 case ISD::Mount::MOUNT_IDLE:
814 if (wpScopeStatus == WP_SLEWING || wpScopeStatus == WP_TRACKING_BUSY)
815 wpScopeStatus = WP_TRACKING_OFF;
817 case ISD::Mount::MOUNT_PARKING:
819 m_CameraState->setScopeParkState(ISD::PARK_PARKING);
826 checkAllActionsReady();
829void SequenceJobState::scopeParkStatusChanged(ISD::ParkStatus)
832 checkAllActionsReady();
835void SequenceJobState::domeStatusChanged(ISD::Dome::Status)
838 checkAllActionsReady();
841void SequenceJobState::flatSyncFocusChanged(
bool completed)
843 flatSyncStatus = (completed ? FS_COMPLETED : FS_BUSY);
845 checkAllActionsReady();
848void SequenceJobState::hasShutter(
bool present)
851 m_CameraState->shutterStatus = CameraState::SHUTTER_YES;
853 m_CameraState->shutterStatus = CameraState::SHUTTER_NO;
856 checkAllActionsReady();
859SequenceJobState::PreparationState SequenceJobState::getPreparationState()
const
861 return m_PreparationState;
864void SequenceJobState::setFilterStatus(FilterState filterState)
868 case FILTER_AUTOFOCUS:
870 prepareActions[CameraState::ACTION_AUTOFOCUS] =
false;
void HorizontalToEquatorial(const dms *LST, const dms *lat)
Determine the (RA, Dec) coordinates of the SkyPoint from its (Altitude, Azimuth) coordinates,...
const QString toDMSString(const bool forceSign=false, const bool machineReadable=false, const bool highPrecision=false) const
QString i18n(const char *text, const TYPE &arg...)
Ekos is an advanced Astrophotography tool for Linux.
@ CAPTURE_SETTING_ROTATOR
@ CAPTURE_CHANGING_FILTER
@ CAPTURE_SETTING_TEMPERATURE
void init(KXmlGuiWindow *window, KGameDifficulty *difficulty=nullptr)
GeoCoordinates geo(const QVariant &location)