@@ -1450,6 +1450,8 @@ bool ToupBase::StartExposure(float duration)
14501450 m_CurrentTriggerMode = TRIGGER_SOFTWARE ;
14511451 }
14521452
1453+ m_ExposureTimer.start ();
1454+
14531455 timeval current_time, exposure_time;
14541456 exposure_time.tv_sec = uSecs / 1000000 ;
14551457 exposure_time.tv_usec = uSecs % 1000000 ;
@@ -1473,6 +1475,7 @@ bool ToupBase::AbortExposure()
14731475{
14741476 FP (Trigger (m_Handle, 0 ));
14751477 InExposure = false ;
1478+ m_ExposureTimer.invalidate ();
14761479 return true ;
14771480}
14781481
@@ -1571,44 +1574,13 @@ void ToupBase::TimerHit()
15711574 if (isConnected () == false )
15721575 return ;
15731576
1574- // Exposure timeout logic
15751577 if (InExposure)
15761578 {
1577- timeval curtime, diff;
1578- gettimeofday (&curtime, nullptr );
1579- timersub (&m_ExposureEnd, &curtime, &diff);
1580- double timeleft = diff.tv_sec + diff.tv_usec / 1e6 ;
1579+ double elapsed = m_ExposureTimer.elapsed () / 1000.0 ; // ms to seconds
1580+ double timeleft = m_ExposureRequest - elapsed;
15811581 if (timeleft < 0 )
15821582 timeleft = 0 ;
15831583 PrimaryCCD.setExposureLeft (timeleft);
1584-
1585- // Timeout check
1586- // Calculate allowed timeout using m_TimeoutFactorN
1587- double timeout_factor = m_TimeoutFactorN.value ;
1588- timeval allowed_end = m_ExposureEnd;
1589- if (timeout_factor > 1.0 )
1590- {
1591- // Add extra time to m_ExposureEnd
1592- double extra = (timeout_factor - 1.0 ) * m_ExposureRequest;
1593- long extra_sec = static_cast <long >(extra);
1594- long extra_usec = static_cast <long >((extra - extra_sec) * 1e6 );
1595- allowed_end.tv_sec += extra_sec;
1596- allowed_end.tv_usec += extra_usec;
1597- if (allowed_end.tv_usec >= 1000000 )
1598- {
1599- allowed_end.tv_sec += allowed_end.tv_usec / 1000000 ;
1600- allowed_end.tv_usec = allowed_end.tv_usec % 1000000 ;
1601- }
1602- }
1603-
1604- timeval now;
1605- gettimeofday (&now, nullptr );
1606- if (timercmp (&now, &allowed_end, >))
1607- {
1608- LOG_ERROR (" Exposure timed out waiting for image frame." );
1609- InExposure = false ;
1610- PrimaryCCD.setExposureFailed ();
1611- }
16121584 }
16131585
16141586 if (m_Instance->model ->flag & CP (FLAG_GETTEMPERATURE ))
@@ -1925,7 +1897,7 @@ void ToupBase::eventCallBack(unsigned event)
19251897 {
19261898 InExposure = false ;
19271899 PrimaryCCD.setExposureLeft (0 );
1928-
1900+ m_ExposureTimer. invalidate ();
19291901 XP (FrameInfoV2) info;
19301902 memset (&info, 0 , sizeof (XP (FrameInfoV2)));
19311903
0 commit comments