From 4e1518fa4944002c6463dfcc4fe23bafae9a5a0d Mon Sep 17 00:00:00 2001 From: "Mark A. Tsuchida" Date: Sun, 23 Oct 2022 13:32:16 -0500 Subject: [PATCH] Require explicit construction of MMTime Forbid implicit conversion from double (so that, for example, arithmetic and comparison operators won't treat double as microseconds but instead require an explicit MMTime object). This is safer because there is a lower risk of getting the units wrong. While this change requires device code to be updated, it does not affect the binary interface and therefore does not require the device interface version to be incremented. Changes to device adapters all belong to these categories: - Comparison of an MMTime with a number -> replace number with MMTime using appropriate unit (`1000.0 * x` -> `MM::MMTime::fromMs(x)`). - In a subset of the previous case, remove a redundant if statement and return a bool directly. - Replace assignment of 0 with assignment of MM::MMTime{}. - Replace `return 0` with `return {}` in functions returning MMTime. - Subtraction of a number from MMTime -> replace with MMTime using appropriate unit (fromSeconds()) All of the above changes preserve behavior exactly. But a few obvious bugs were fixed: - K8601/K8601.cpp:539 Fix `1000.0 < GetDelayMs()` which should have been `1000.0 * GetDelayMs()`; use `MM::MMTime::fromMs(GetDelayMs())`. Compare K8055 and others that use the same pattern. - Yokogawa/CSUX.cpp:330 Comment said '33 msec' but use of raw number meant it was interpreted as 33 us. Fixed to use 33 ms as this was almost certainly what was intended. The following looks like a potential bug, but I'm leaving the behavior unchanged in the absence of a means to test: - PeCon2000/PeCon2000.cpp:378 Comparison with `double delta` interprets `delta` as microseconds, but usage of `is_older_than` under variable name `is_older_than_a_minute` suggests `delta` (= 60.0) was meant to be in seconds. I cannot tell if the behavior is correct or the name, so I'm opting to preserve current behavior. --- DeviceAdapters/ASIFW1000/ASIFW1000.cpp | 5 +--- DeviceAdapters/AmScope/SequenceThread.cpp | 4 +-- DeviceAdapters/AndorSDK3/AndorSDK3.cpp | 2 +- DeviceAdapters/Arduino/Arduino.cpp | 5 +--- .../Arduino32bitBoards/Arduino32bitBoards.cpp | 5 +--- .../ArduinoNeoPixelShutter.cpp | 5 +--- DeviceAdapters/CSUW1/CSUW1.cpp | 10 ++----- DeviceAdapters/Conix/Conix.cpp | 6 +--- DeviceAdapters/DemoCamera/DemoCamera.cpp | 4 +-- DeviceAdapters/IDS_uEye/IDS_uEye.cpp | 4 +-- DeviceAdapters/K8055/K8055.cpp | 6 +--- DeviceAdapters/K8061/K8061.cpp | 6 +--- DeviceAdapters/LeicaDMR/LeicaDMR.cpp | 20 +++++-------- DeviceAdapters/LeicaDMR/LeicaDMRHub.cpp | 3 +- DeviceAdapters/LeicaDMSTC/LeicaDMSTC.cpp | 2 +- DeviceAdapters/Ludl/Ludl.cpp | 2 +- .../MatrixVision/mvIMPACT_Acquire_Device.cpp | 4 +-- .../Mightex_C_Cam/Mightex_USBCamera.cpp | 4 +-- DeviceAdapters/Neos/Neos.cpp | 6 +--- DeviceAdapters/NikonTE2000/TEHub.cpp | 3 +- DeviceAdapters/Okolab/OkolabDevice.cpp | 4 +-- .../OpenCVgrabber/OpenCVgrabber.cpp | 4 +-- .../OxxiusCombiner/Oxxius_combiner.cpp | 6 ++-- DeviceAdapters/PeCon2000/PeCon2000.cpp | 2 +- DeviceAdapters/RaptorEPIX/RaptorEPIX.cpp | 4 +-- DeviceAdapters/SpectralLMM5/SpectralLMM5.cpp | 4 +-- DeviceAdapters/Spinnaker/SpinnakerCamera.cpp | 4 +-- DeviceAdapters/SutterLambda/SutterLambda.cpp | 29 ++++++++++++++----- DeviceAdapters/SutterLambda2/WheelBase.h | 2 +- DeviceAdapters/TUCam/MMTUCam.cpp | 4 +-- .../ThorlabsUSBCamera/ThorlabsUSBCamera.cpp | 4 +-- .../TwainCamera/CameraSequenceThread.h | 4 +-- .../UniversalMMHubSerial/ummhSerial.cpp | 4 +-- DeviceAdapters/UniversalMMHubUsb/ummhUsb.cpp | 8 ++--- DeviceAdapters/VariLC/VariLC.cpp | 4 +-- DeviceAdapters/VarispecLCTF/VarispecLCTF.cpp | 2 +- DeviceAdapters/Ximea/XIMEACamera.cpp | 4 +-- DeviceAdapters/Yokogawa/CSU22.cpp | 6 +--- DeviceAdapters/Yokogawa/CSUX.cpp | 10 ++----- DeviceAdapters/ZeissAxioZoom/ZeissAxioZoom.h | 4 +-- DeviceAdapters/ZeissCAN29/ZeissCAN29.h | 4 +-- MMDevice/DeviceBase.h | 4 +-- MMDevice/MMDevice.h | 4 +-- 43 files changed, 100 insertions(+), 131 deletions(-) diff --git a/DeviceAdapters/ASIFW1000/ASIFW1000.cpp b/DeviceAdapters/ASIFW1000/ASIFW1000.cpp index 931a0b339..a946a8bc6 100644 --- a/DeviceAdapters/ASIFW1000/ASIFW1000.cpp +++ b/DeviceAdapters/ASIFW1000/ASIFW1000.cpp @@ -1001,10 +1001,7 @@ bool Shutter::Busy() { //TODO: using the SQ command and shutters with sensors, we can check wether the shutter is open or closed. This need checking for sensors on initialization, and will also need caching of the last requested position MM::MMTime interval = GetCurrentMMTime() - changedTime_; - if (interval < (1000.0 * GetDelayMs() )) - return true; - else - return false; + return interval < MM::MMTime::fromMs(GetDelayMs()); } int Shutter::Shutdown() diff --git a/DeviceAdapters/AmScope/SequenceThread.cpp b/DeviceAdapters/AmScope/SequenceThread.cpp index b95602d4f..1cd1c6f3f 100644 --- a/DeviceAdapters/AmScope/SequenceThread.cpp +++ b/DeviceAdapters/AmScope/SequenceThread.cpp @@ -55,9 +55,9 @@ void SequenceThread::Start(long numImages, double intervalMs) stop_ = false; suspend_=false; activate(); - actualDuration_ = 0; + actualDuration_ = MM::MMTime{}; startTime_= camera_->GetCurrentMMTime(); - lastFrameTime_ = 0; + lastFrameTime_ = MM::MMTime{}; } bool SequenceThread::IsStopped(){ diff --git a/DeviceAdapters/AndorSDK3/AndorSDK3.cpp b/DeviceAdapters/AndorSDK3/AndorSDK3.cpp index 7d388bdb7..2454d1ef4 100644 --- a/DeviceAdapters/AndorSDK3/AndorSDK3.cpp +++ b/DeviceAdapters/AndorSDK3/AndorSDK3.cpp @@ -1845,7 +1845,7 @@ void MySequenceThread::Start(long numImages, double intervalMs) stop_ = false; suspend_ = false; activate(); - actualDuration_ = 0; + actualDuration_ = MM::MMTime{}; startTime_ = camera_->GetCurrentMMTime(); } diff --git a/DeviceAdapters/Arduino/Arduino.cpp b/DeviceAdapters/Arduino/Arduino.cpp index ad07a9a4b..71fc4c419 100644 --- a/DeviceAdapters/Arduino/Arduino.cpp +++ b/DeviceAdapters/Arduino/Arduino.cpp @@ -1247,10 +1247,7 @@ bool CArduinoShutter::Busy() { MM::MMTime interval = GetCurrentMMTime() - changedTime_; - if (interval < (1000.0 * GetDelayMs() )) - return true; - else - return false; + return interval < MM::MMTime::fromMs(GetDelayMs()); } int CArduinoShutter::Initialize() diff --git a/DeviceAdapters/Arduino32bitBoards/Arduino32bitBoards.cpp b/DeviceAdapters/Arduino32bitBoards/Arduino32bitBoards.cpp index 8bc4748e5..5e59da4ee 100644 --- a/DeviceAdapters/Arduino32bitBoards/Arduino32bitBoards.cpp +++ b/DeviceAdapters/Arduino32bitBoards/Arduino32bitBoards.cpp @@ -1335,10 +1335,7 @@ bool CArduino32Shutter::Busy() { MM::MMTime interval = GetCurrentMMTime() - changedTime_; - if (interval < (1000.0 * GetDelayMs() )) - return true; - else - return false; + return interval < MM::MMTime::fromMs(GetDelayMs()); } int CArduino32Shutter::Initialize() diff --git a/DeviceAdapters/CNCMicroscope/ArduinoNeoPixelShutter/ArduinoNeoPixelShutter.cpp b/DeviceAdapters/CNCMicroscope/ArduinoNeoPixelShutter/ArduinoNeoPixelShutter.cpp index 57b045ae5..d880e6d99 100644 --- a/DeviceAdapters/CNCMicroscope/ArduinoNeoPixelShutter/ArduinoNeoPixelShutter.cpp +++ b/DeviceAdapters/CNCMicroscope/ArduinoNeoPixelShutter/ArduinoNeoPixelShutter.cpp @@ -332,10 +332,7 @@ bool CArduinoNeoPixelShutter::Busy() { MM::MMTime interval = GetCurrentMMTime() - changedTime_; - if (interval < (1000.0 * GetDelayMs() )) - return true; - else - return false; + return interval < MM::MMTime::fromMs(GetDelayMs()); } int CArduinoNeoPixelShutter::Initialize() diff --git a/DeviceAdapters/CSUW1/CSUW1.cpp b/DeviceAdapters/CSUW1/CSUW1.cpp index f4783d196..653e4540f 100644 --- a/DeviceAdapters/CSUW1/CSUW1.cpp +++ b/DeviceAdapters/CSUW1/CSUW1.cpp @@ -617,10 +617,7 @@ int Shutter::Initialize() bool Shutter::Busy() { MM::MMTime interval = GetCurrentMMTime() - changedTime_; - if (interval < (1000.0 * GetDelayMs() )) - return true; - - return false; + return interval < MM::MMTime::fromMs(GetDelayMs()); } int Shutter::Shutdown() @@ -1471,10 +1468,7 @@ int NIRShutter::Initialize() bool NIRShutter::Busy() { MM::MMTime interval = GetCurrentMMTime() - changedTime_; - if (interval < (1000.0 * GetDelayMs() )) - return true; - - return false; + return interval < MM::MMTime::fromMs(GetDelayMs()); } int NIRShutter::Shutdown() diff --git a/DeviceAdapters/Conix/Conix.cpp b/DeviceAdapters/Conix/Conix.cpp index 57a9a1477..f95896825 100644 --- a/DeviceAdapters/Conix/Conix.cpp +++ b/DeviceAdapters/Conix/Conix.cpp @@ -417,11 +417,7 @@ int HexaFluor::Shutdown() bool HexaFluor::Busy() { MM::MMTime interval = GetCurrentMMTime() - changedTime_; - - if (interval < (1000.0 * GetDelayMs()) ) - return true; - - return false; + return interval < MM::MMTime::fromMs(GetDelayMs()); } diff --git a/DeviceAdapters/DemoCamera/DemoCamera.cpp b/DeviceAdapters/DemoCamera/DemoCamera.cpp index f10423ba5..fc30ef702 100644 --- a/DeviceAdapters/DemoCamera/DemoCamera.cpp +++ b/DeviceAdapters/DemoCamera/DemoCamera.cpp @@ -1219,9 +1219,9 @@ void MySequenceThread::Start(long numImages, double intervalMs) stop_ = false; suspend_=false; activate(); - actualDuration_ = 0; + actualDuration_ = MM::MMTime{}; startTime_= camera_->GetCurrentMMTime(); - lastFrameTime_ = 0; + lastFrameTime_ = MM::MMTime{}; } bool MySequenceThread::IsStopped(){ diff --git a/DeviceAdapters/IDS_uEye/IDS_uEye.cpp b/DeviceAdapters/IDS_uEye/IDS_uEye.cpp index 569b26262..deac65f2f 100644 --- a/DeviceAdapters/IDS_uEye/IDS_uEye.cpp +++ b/DeviceAdapters/IDS_uEye/IDS_uEye.cpp @@ -1445,9 +1445,9 @@ void MySequenceThread::Start(long numImages, double intervalMs) stop_ = false; suspend_=false; activate(); - actualDuration_ = 0; + actualDuration_ = MM::MMTime{}; startTime_= camera_->GetCurrentMMTime(); - lastFrameTime_ = 0; + lastFrameTime_ = MM::MMTime{}; } bool MySequenceThread::IsStopped(){ diff --git a/DeviceAdapters/K8055/K8055.cpp b/DeviceAdapters/K8055/K8055.cpp index b1577d6c8..5d9b3406a 100644 --- a/DeviceAdapters/K8055/K8055.cpp +++ b/DeviceAdapters/K8055/K8055.cpp @@ -506,11 +506,7 @@ void CK8055Shutter::GetName(char* name) const bool CK8055Shutter::Busy() { MM::MMTime interval = GetCurrentMMTime() - changedTime_; - - if (interval < (1000.0 * GetDelayMs() )) - return true; - else - return false; + return interval < MM::MMTime::fromMs(GetDelayMs()); } int CK8055Shutter::Initialize() diff --git a/DeviceAdapters/K8061/K8061.cpp b/DeviceAdapters/K8061/K8061.cpp index 0489c59bb..d4a648af3 100644 --- a/DeviceAdapters/K8061/K8061.cpp +++ b/DeviceAdapters/K8061/K8061.cpp @@ -536,11 +536,7 @@ void CK8061Shutter::GetName(char* name) const bool CK8061Shutter::Busy() { MM::MMTime interval = GetCurrentMMTime() - changedTime_; - - if (interval < (1000.0 < GetDelayMs() )) - return true; - else - return false; + return interval < MM::MMTime::fromMs(GetDelayMs()); } int CK8061Shutter::Initialize() diff --git a/DeviceAdapters/LeicaDMR/LeicaDMR.cpp b/DeviceAdapters/LeicaDMR/LeicaDMR.cpp index 51046c5be..19c50f46f 100644 --- a/DeviceAdapters/LeicaDMR/LeicaDMR.cpp +++ b/DeviceAdapters/LeicaDMR/LeicaDMR.cpp @@ -453,8 +453,8 @@ int Lamp::Initialize() return ret; // Set timer for the Busy signal, or we'll get a time-out the first time we check the state of the shutter, for good measure, go back 5s into the past - changedTime_ = GetCurrentMMTime() - 5000000; - + changedTime_ = GetCurrentMMTime() - MM::MMTime::fromSeconds(5); + // Check current intensity of lamp ret = g_hub.GetLampIntensity(*this, *GetCoreCallback(), intensity_); if (DEVICE_OK != ret) @@ -497,10 +497,7 @@ int Lamp::Initialize() bool Lamp::Busy() { MM::MMTime interval = GetCurrentMMTime() - changedTime_; - if (interval < (1000.0 * GetDelayMs() )) - return true; - - return false; + return interval < MM::MMTime::fromMs(GetDelayMs()); } int Lamp::Shutdown() @@ -654,8 +651,8 @@ int RLShutter::Initialize() return ret; // Set timer for the Busy signal, or we'll get a time-out the first time we check the state of the shutter, for good measure, go back 5s into the past - changedTime_ = GetCurrentMMTime() - 5000000; - + changedTime_ = GetCurrentMMTime() - MM::MMTime::fromSeconds(5); + // State CPropertyAction* pAct = new CPropertyAction (this, &RLShutter::OnState); ret = CreateProperty(MM::g_Keyword_State, "0", MM::Integer, false, pAct); @@ -681,8 +678,7 @@ bool RLShutter::Busy() // TODO: determine whether we need to use delay /* MM::MMTime interval = GetCurrentMMTime() - changedTime_; - if (interval < (1000.0 * GetDelayMs() )) - return true; + return interval < MM::MMTime::fromMs(GetDelayMs()); */ return false; } @@ -801,8 +797,8 @@ int ZStage::Initialize() return ret; // Set timer for the Busy signal, or we'll get a time-out the first time we check the state of the shutter, for good measure, go back 5s into the past - changedTime_ = GetCurrentMMTime() - 5000000; - + changedTime_ = GetCurrentMMTime() - MM::MMTime::fromSeconds(5); + // Position // There are two reference frames. An absolute reference frame (implemeted here) // and a relative reference frame, implemented with a upper and lower lower limit diff --git a/DeviceAdapters/LeicaDMR/LeicaDMRHub.cpp b/DeviceAdapters/LeicaDMR/LeicaDMRHub.cpp index e12624507..996f90a1d 100644 --- a/DeviceAdapters/LeicaDMR/LeicaDMRHub.cpp +++ b/DeviceAdapters/LeicaDMR/LeicaDMRHub.cpp @@ -168,7 +168,8 @@ int LeicaDMRHub::GetRLModulePosition(MM::Device& device, MM::Core& core, int& po pos = 0; MM::MMTime start = core.GetCurrentMMTime(); int ret; - while (pos == 0 && (core.GetCurrentMMTime() - start < 500000) ) { + while (pos == 0 && + (core.GetCurrentMMTime() - start < MM::MMTime::fromMs(500))) { ret = GetCommand(device, core, rLFA_, 10, pos); if (ret != DEVICE_OK) return ret; diff --git a/DeviceAdapters/LeicaDMSTC/LeicaDMSTC.cpp b/DeviceAdapters/LeicaDMSTC/LeicaDMSTC.cpp index 645d04454..14b02356b 100644 --- a/DeviceAdapters/LeicaDMSTC/LeicaDMSTC.cpp +++ b/DeviceAdapters/LeicaDMSTC/LeicaDMSTC.cpp @@ -303,7 +303,7 @@ int XYStage::Initialize() // Do not implement a position property as it can lead to trouble! // Set timer for the Busy signal, or we'll get a time-out the first time we check the state of the shutter, for good measure, go back 5s into the past - changedTime_ = GetCurrentMMTime() - 5000000; + changedTime_ = GetCurrentMMTime() - MM::MMTime::fromSeconds(5); initialized_ = true; diff --git a/DeviceAdapters/Ludl/Ludl.cpp b/DeviceAdapters/Ludl/Ludl.cpp index 42ea6dd00..c93b3fd4b 100644 --- a/DeviceAdapters/Ludl/Ludl.cpp +++ b/DeviceAdapters/Ludl/Ludl.cpp @@ -1405,7 +1405,7 @@ bool Shutter::Busy() { // First check delay, then query controller MM::MMTime interval = GetCurrentMMTime() - changedTime_; - if (interval < (1000.0 * GetDelayMs())) + if (interval < MM::MMTime::fromMs(GetDelayMs())) return true; clearPort(*this, *GetCoreCallback(), GetPort().c_str()); diff --git a/DeviceAdapters/MatrixVision/mvIMPACT_Acquire_Device.cpp b/DeviceAdapters/MatrixVision/mvIMPACT_Acquire_Device.cpp index bb2b36617..b8c3d7aae 100644 --- a/DeviceAdapters/MatrixVision/mvIMPACT_Acquire_Device.cpp +++ b/DeviceAdapters/MatrixVision/mvIMPACT_Acquire_Device.cpp @@ -1214,9 +1214,9 @@ void MySequenceThread::Start( long numImages, double intervalMs ) stop_ = false; suspend_ = false; activate(); - actualDuration_ = 0; + actualDuration_ = MM::MMTime{}; startTime_ = pmvIMPACT_Acquire_Device_->GetCurrentMMTime(); - lastFrameTime_ = 0; + lastFrameTime_ = MM::MMTime{}; } //----------------------------------------------------------------------------- diff --git a/DeviceAdapters/Mightex_C_Cam/Mightex_USBCamera.cpp b/DeviceAdapters/Mightex_C_Cam/Mightex_USBCamera.cpp index 5307d8ea5..b70c41be7 100755 --- a/DeviceAdapters/Mightex_C_Cam/Mightex_USBCamera.cpp +++ b/DeviceAdapters/Mightex_C_Cam/Mightex_USBCamera.cpp @@ -1668,9 +1668,9 @@ void MySequenceThread::Start(long numImages, double intervalMs) stop_ = false; suspend_=false; activate(); - actualDuration_ = 0; + actualDuration_ = MM::MMTime{}; startTime_= camera_->GetCurrentMMTime(); - lastFrameTime_ = 0; + lastFrameTime_ = MM::MMTime{}; } bool MySequenceThread::IsStopped(){ diff --git a/DeviceAdapters/Neos/Neos.cpp b/DeviceAdapters/Neos/Neos.cpp index 151eae01c..2992376f7 100644 --- a/DeviceAdapters/Neos/Neos.cpp +++ b/DeviceAdapters/Neos/Neos.cpp @@ -150,11 +150,7 @@ int Neos::Shutdown() bool Neos::Busy() { MM::MMTime interval = GetCurrentMMTime() - changedTime_; - - if (interval < (1000.0 * GetDelayMs())) - return true; - - return false; + return interval < MM::MMTime::fromMs(GetDelayMs()); } diff --git a/DeviceAdapters/NikonTE2000/TEHub.cpp b/DeviceAdapters/NikonTE2000/TEHub.cpp index 3c980f8dc..598ebb3e4 100644 --- a/DeviceAdapters/NikonTE2000/TEHub.cpp +++ b/DeviceAdapters/NikonTE2000/TEHub.cpp @@ -896,7 +896,8 @@ int TEHub::ExecuteCommand(MM::Device& device, MM::Core& core, const char* type, else { CDeviceUtils::SleepMs(delayMs); - if ( (core.GetCurrentMMTime() - startTime) > (maxTimeMs*1000.0) ) + if ((core.GetCurrentMMTime() - startTime) > + MM::MMTime::fromMs(maxTimeMs)) done = true; } } diff --git a/DeviceAdapters/Okolab/OkolabDevice.cpp b/DeviceAdapters/Okolab/OkolabDevice.cpp index 1f11d1d66..7f63c0c65 100644 --- a/DeviceAdapters/Okolab/OkolabDevice.cpp +++ b/DeviceAdapters/Okolab/OkolabDevice.cpp @@ -1016,9 +1016,9 @@ void OkolabThread::Start(double intervalMs) _stop = false; _suspend = false; activate(); - _actualDuration = 0; + _actualDuration = MM::MMTime{}; _startTime = _device->GetCurrentMMTime(); - _lastFrameTime = 0; + _lastFrameTime = MM::MMTime{}; Sleep(THREAD_SLEEP_MS); } diff --git a/DeviceAdapters/OpenCVgrabber/OpenCVgrabber.cpp b/DeviceAdapters/OpenCVgrabber/OpenCVgrabber.cpp index 0d6810763..6ce9d0c3a 100644 --- a/DeviceAdapters/OpenCVgrabber/OpenCVgrabber.cpp +++ b/DeviceAdapters/OpenCVgrabber/OpenCVgrabber.cpp @@ -920,9 +920,9 @@ void MySequenceThread::Start(long numImages, double intervalMs) stop_ = false; suspend_=false; activate(); - actualDuration_ = 0; + actualDuration_ = MM::MMTime{}; startTime_= camera_->GetCurrentMMTime(); - lastFrameTime_ = 0; + lastFrameTime_ = MM::MMTime{}; } bool MySequenceThread::IsStopped(){ diff --git a/DeviceAdapters/OxxiusCombiner/Oxxius_combiner.cpp b/DeviceAdapters/OxxiusCombiner/Oxxius_combiner.cpp index 275bfc564..49e042ddd 100644 --- a/DeviceAdapters/OxxiusCombiner/Oxxius_combiner.cpp +++ b/DeviceAdapters/OxxiusCombiner/Oxxius_combiner.cpp @@ -565,9 +565,11 @@ int OxxiusCombinerHub::QueryCommand(MM::Device* device, MM::Core* core, const un while (!done) { counter++; ret = core->GetSerialAnswer(device, port_.c_str(), RCV_BUF_LENGTH, rcvBuf_, "\r\n"); - if ( (ret == DEVICE_OK) || ( (core->GetCurrentMMTime() - startTime) > (maxTimeMs*1000.0) ) ) + if ((ret == DEVICE_OK) || + ((core->GetCurrentMMTime() - startTime) > + MM::MMTime::fromMs(maxTimeMs))) { done = true; - else { + } else { CDeviceUtils::SleepMs(delayMs); delayMs *= 2; } diff --git a/DeviceAdapters/PeCon2000/PeCon2000.cpp b/DeviceAdapters/PeCon2000/PeCon2000.cpp index 32486a482..771b77e23 100644 --- a/DeviceAdapters/PeCon2000/PeCon2000.cpp +++ b/DeviceAdapters/PeCon2000/PeCon2000.cpp @@ -375,7 +375,7 @@ struct is_older_than { inline is_older_than(MM::MMTime now, double delta) : now(now), delta(delta) {}; inline bool operator()(const MM::MMTime& then) { - return (now - then) > delta; + return (now - then) > MM::MMTime(delta); } }; diff --git a/DeviceAdapters/RaptorEPIX/RaptorEPIX.cpp b/DeviceAdapters/RaptorEPIX/RaptorEPIX.cpp index 96384b858..b239c1dc7 100644 --- a/DeviceAdapters/RaptorEPIX/RaptorEPIX.cpp +++ b/DeviceAdapters/RaptorEPIX/RaptorEPIX.cpp @@ -6098,9 +6098,9 @@ void MySequenceThread::Start(long numImages, double intervalMs) stop_ = false; suspend_=false; activate(); - actualDuration_ = 0; + actualDuration_ = MM::MMTime{}; startTime_= camera_->GetCurrentMMTime(); - lastFrameTime_ = 0; + lastFrameTime_ = MM::MMTime{}; } bool MySequenceThread::IsStopped(){ diff --git a/DeviceAdapters/SpectralLMM5/SpectralLMM5.cpp b/DeviceAdapters/SpectralLMM5/SpectralLMM5.cpp index 590c5a107..44f1a7f8d 100644 --- a/DeviceAdapters/SpectralLMM5/SpectralLMM5.cpp +++ b/DeviceAdapters/SpectralLMM5/SpectralLMM5.cpp @@ -568,9 +568,7 @@ void LMM5Shutter::GetName(char* pszName) const bool LMM5Shutter::Busy() { MM::MMTime interval = GetCurrentMMTime() - changedTime_; - if (interval < (1000.0 * GetDelayMs() )) - return true; - return false; + return interval < MM::MMTime::fromMs(GetDelayMs()); } int LMM5Shutter::SetOpen(bool open) diff --git a/DeviceAdapters/Spinnaker/SpinnakerCamera.cpp b/DeviceAdapters/Spinnaker/SpinnakerCamera.cpp index 8f473cb6c..e2e2aeb88 100644 --- a/DeviceAdapters/Spinnaker/SpinnakerCamera.cpp +++ b/DeviceAdapters/Spinnaker/SpinnakerCamera.cpp @@ -1717,9 +1717,9 @@ void SpinnakerAcquisitionThread::Start(long numImages, double intervalMs) m_stop = false; m_suspend = false; activate(); - m_actualDuration = 0; + m_actualDuration = MM::MMTime{}; m_startTime = m_spkrCam->GetCurrentMMTime(); - m_lastFrameTime = 0; + m_lastFrameTime = MM::MMTime{}; m_spkrCam->allocateImageBuffer(m_spkrCam->GetImageBufferSize(), m_spkrCam->m_cam->PixelFormat.GetValue()); if (numImages == -1) diff --git a/DeviceAdapters/SutterLambda/SutterLambda.cpp b/DeviceAdapters/SutterLambda/SutterLambda.cpp index 4e7fb54f9..10d642495 100644 --- a/DeviceAdapters/SutterLambda/SutterLambda.cpp +++ b/DeviceAdapters/SutterLambda/SutterLambda.cpp @@ -212,7 +212,9 @@ int SutterUtils::GoOnLine(MM::Device& device, MM::Core& core, if (answer == 238) responseReceived = true; } - while( !responseReceived && (core.GetCurrentMMTime() - startTime) < (answerTimeoutMs * 1000.0) ); + while (!responseReceived && + (core.GetCurrentMMTime() - startTime) < + MM::MMTime::fromMs(answerTimeoutMs)); if (!responseReceived) return ERR_NO_ANSWER; @@ -294,7 +296,9 @@ int SutterUtils::GetStatus(MM::Device& device, MM::Core& core, responseReceived = true; CDeviceUtils::SleepMs(2); } - while( !responseReceived && (core.GetCurrentMMTime() - startTime) < (answerTimeoutMs * 1000.0) ); + while (!responseReceived && + (core.GetCurrentMMTime() - startTime) < + MM::MMTime::fromMs(answerTimeoutMs)); if (!responseReceived) return ERR_NO_ANSWER; @@ -313,7 +317,10 @@ int SutterUtils::GetStatus(MM::Device& device, MM::Core& core, } CDeviceUtils::SleepMs(2); } - while( !responseReceived && (core.GetCurrentMMTime() - startTime) < (answerTimeoutMs * 1000.0) && j < 22); + while (!responseReceived && + (core.GetCurrentMMTime() - startTime) < + MM::MMTime::fromMs(answerTimeoutMs) && + j < 22); if (!responseReceived) return ERR_NO_ANSWER; @@ -1498,7 +1505,9 @@ bool ShutterOnTenDashTwo::SetShutterPosition(bool state) LogMessage("busy entering SetShutterPosition",true); MM::MMTime startTime = GetCurrentMMTime(); - while (::g_Busy[port_] && (GetCurrentMMTime() - startTime) < (g_busyTimeoutMs * 1000.0) ) + while (::g_Busy[port_] && + (GetCurrentMMTime() - startTime) < + MM::MMTime::fromMs(g_busyTimeoutMs)) { CDeviceUtils::SleepMs(10); } @@ -2090,7 +2099,9 @@ bool ShutterOn721::SetLEDState(long led, bool state) LogMessage("busy entering SetShutterPosition",true); MM::MMTime startTime = GetCurrentMMTime(); - while (::g_Busy[port_] && (GetCurrentMMTime() - startTime) < (g_busyTimeoutMs * 1000.0) ) + while (::g_Busy[port_] && + (GetCurrentMMTime() - startTime) < + MM::MMTime::fromMs(g_busyTimeoutMs)) { CDeviceUtils::SleepMs(10); } @@ -2199,7 +2210,9 @@ bool ShutterOn721::GetLEDStates(int *state) LogMessage("busy entering SetShutterPosition",true); MM::MMTime startTime = GetCurrentMMTime(); - while (::g_Busy[port_] && (GetCurrentMMTime() - startTime) < (g_busyTimeoutMs * 1000.0) ) + while (::g_Busy[port_] && + (GetCurrentMMTime() - startTime) < + MM::MMTime::fromMs(g_busyTimeoutMs)) { CDeviceUtils::SleepMs(10); } @@ -2320,7 +2333,9 @@ bool ShutterOn721::SetLEDPower(long led, long power) LogMessage("busy entering SetLEDPower",true); MM::MMTime startTime = GetCurrentMMTime(); - while (::g_Busy[port_] && (GetCurrentMMTime() - startTime) < (g_busyTimeoutMs * 1000.0) ) + while (::g_Busy[port_] && + (GetCurrentMMTime() - startTime) < + MM::MMTime::fromMs(g_busyTimeoutMs)) { CDeviceUtils::SleepMs(10); } diff --git a/DeviceAdapters/SutterLambda2/WheelBase.h b/DeviceAdapters/SutterLambda2/WheelBase.h index e511edd91..6abd9cd14 100644 --- a/DeviceAdapters/SutterLambda2/WheelBase.h +++ b/DeviceAdapters/SutterLambda2/WheelBase.h @@ -362,7 +362,7 @@ int WheelBase::OnDelay(MM::PropertyBase* pProp, MM::ActionType eAct) double delay; pProp->Get(delay); this->SetDelayMs(delay); - delay_ = delay * 1000; + delay_ = MM::MMTime::fromMs(delay); } return DEVICE_OK; } diff --git a/DeviceAdapters/TUCam/MMTUCam.cpp b/DeviceAdapters/TUCam/MMTUCam.cpp index b54ca7cd1..7d73b1d06 100755 --- a/DeviceAdapters/TUCam/MMTUCam.cpp +++ b/DeviceAdapters/TUCam/MMTUCam.cpp @@ -2619,9 +2619,9 @@ void CTUCamThread::Start(long numImages, double intervalMs) stop_ = false; suspend_=false; activate(); - actualDuration_ = 0; + actualDuration_ = MM::MMTime{}; startTime_= camera_->GetCurrentMMTime(); - lastFrameTime_ = 0; + lastFrameTime_ = MM::MMTime{}; } bool CTUCamThread::IsStopped() diff --git a/DeviceAdapters/ThorlabsUSBCamera/ThorlabsUSBCamera.cpp b/DeviceAdapters/ThorlabsUSBCamera/ThorlabsUSBCamera.cpp index ad5616dfe..cbce849bb 100644 --- a/DeviceAdapters/ThorlabsUSBCamera/ThorlabsUSBCamera.cpp +++ b/DeviceAdapters/ThorlabsUSBCamera/ThorlabsUSBCamera.cpp @@ -730,9 +730,9 @@ void MySequenceThread::Start(long numImages, double intervalMs) stop_ = false; suspend_=false; activate(); - actualDuration_ = 0; + actualDuration_ = MM::MMTime{}; startTime_= camera_->GetCurrentMMTime(); - lastFrameTime_ = 0; + lastFrameTime_ = MM::MMTime{}; } bool MySequenceThread::IsStopped(){ diff --git a/DeviceAdapters/TwainCamera/CameraSequenceThread.h b/DeviceAdapters/TwainCamera/CameraSequenceThread.h index f1f9d34b4..39eca7df4 100644 --- a/DeviceAdapters/TwainCamera/CameraSequenceThread.h +++ b/DeviceAdapters/TwainCamera/CameraSequenceThread.h @@ -32,9 +32,9 @@ class CameraSequenceThread : public MMDeviceThreadBase stop_ = false; suspend_=false; activate(); - actualDuration_ = 0; + actualDuration_ = MM::MMTime{}; startTime_= camera_->GetCurrentMMTime(); - lastFrameTime_ = 0; + lastFrameTime_ = MM::MMTime{}; } bool IsStopped(){ MMThreadGuard(this->stopLock_); diff --git a/DeviceAdapters/UniversalMMHubSerial/ummhSerial.cpp b/DeviceAdapters/UniversalMMHubSerial/ummhSerial.cpp index 1774c7d1e..c1ef20c59 100644 --- a/DeviceAdapters/UniversalMMHubSerial/ummhSerial.cpp +++ b/DeviceAdapters/UniversalMMHubSerial/ummhSerial.cpp @@ -313,7 +313,7 @@ MM::MMTime UniHub::GetTimeout(string devicename) { UmmhGeneric* p = static_cast(pDevice); return p->GetTimeout(); } - return 0; + return {}; } void UniHub::SetTimeout(string devicename, MM::MMTime val) { @@ -360,7 +360,7 @@ MM::MMTime UniHub::GetLastCommandTime(string devicename) { UmmhGeneric* p = static_cast(pDevice); return p->GetLastCommandTime(); } - return 0; + return {}; } void UniHub::SetLastCommandTime(string devicename, MM::MMTime val) { diff --git a/DeviceAdapters/UniversalMMHubUsb/ummhUsb.cpp b/DeviceAdapters/UniversalMMHubUsb/ummhUsb.cpp index 337b4a572..0fafe962a 100644 --- a/DeviceAdapters/UniversalMMHubUsb/ummhUsb.cpp +++ b/DeviceAdapters/UniversalMMHubUsb/ummhUsb.cpp @@ -445,7 +445,7 @@ MM::MMTime UniHub::GetTimeout(string devicename) { UmmhCamera* p = static_cast(pDevice); return p->GetTimeout(); } - return 0; + return {}; } void UniHub::SetTimeout(string devicename, MM::MMTime val) { @@ -500,7 +500,7 @@ MM::MMTime UniHub::GetLastCommandTime(string devicename) { UmmhCamera* p = static_cast(pDevice); return p->GetLastCommandTime(); } - return 0; + return {}; } void UniHub::SetLastCommandTime(string devicename, MM::MMTime val) { @@ -3879,9 +3879,9 @@ void MySequenceThread::Start(long numImages, double intervalMs) stop_ = false; suspend_=false; activate(); - actualDuration_ = 0; + actualDuration_ = MM::MMTime{}; startTime_= camera_->GetCurrentMMTime(); - lastFrameTime_ = 0; + lastFrameTime_ = MM::MMTime{}; } bool MySequenceThread::IsStopped(){ diff --git a/DeviceAdapters/VariLC/VariLC.cpp b/DeviceAdapters/VariLC/VariLC.cpp index ec01df71f..168515c4d 100644 --- a/DeviceAdapters/VariLC/VariLC.cpp +++ b/DeviceAdapters/VariLC/VariLC.cpp @@ -662,7 +662,7 @@ int VariLC::OnGetFromVariLC(MM::PropertyBase* pProp, MM::ActionType eAct) if (initializedDelay_) { SetDelayMs(delayT); } - delay = delayT*1000; + delay = MM::MMTime::fromMs(delayT); } return DEVICE_OK; } @@ -724,4 +724,4 @@ int VariLC::sendCmd(std::string cmd) { return 99; } return DEVICE_OK; -} \ No newline at end of file +} diff --git a/DeviceAdapters/VarispecLCTF/VarispecLCTF.cpp b/DeviceAdapters/VarispecLCTF/VarispecLCTF.cpp index 571a6ce5d..8dbc1c01f 100644 --- a/DeviceAdapters/VarispecLCTF/VarispecLCTF.cpp +++ b/DeviceAdapters/VarispecLCTF/VarispecLCTF.cpp @@ -499,7 +499,7 @@ int VarispecLCTF::OnDelay(MM::PropertyBase* pProp, MM::ActionType eAct) if (initializedDelay_) { SetDelayMs(delayT); } - delay_ = delayT * 1000; + delay_ = MM::MMTime::fromMs(delayT); } return DEVICE_OK; } diff --git a/DeviceAdapters/Ximea/XIMEACamera.cpp b/DeviceAdapters/Ximea/XIMEACamera.cpp index f2e6bcf5b..82c39e4cb 100644 --- a/DeviceAdapters/Ximea/XIMEACamera.cpp +++ b/DeviceAdapters/Ximea/XIMEACamera.cpp @@ -1680,9 +1680,9 @@ void XiSequenceThread::Start(long numImages, double intervalMs) stop_ = false; suspend_ = false; activate(); - actualDuration_ = 0; + actualDuration_ = MM::MMTime{}; startTime_ = camera_->GetCurrentMMTime(); - lastFrameTime_ = 0; + lastFrameTime_ = MM::MMTime{}; } //*********************************************************************** diff --git a/DeviceAdapters/Yokogawa/CSU22.cpp b/DeviceAdapters/Yokogawa/CSU22.cpp index 222530a55..0ea842749 100644 --- a/DeviceAdapters/Yokogawa/CSU22.cpp +++ b/DeviceAdapters/Yokogawa/CSU22.cpp @@ -429,11 +429,7 @@ int FilterSet::Initialize() bool FilterSet::Busy() { MM::MMTime interval = GetCurrentMMTime() - changedTime_; - - if (interval < (1000.0 * GetDelayMs() )) - return true; - - return false; + return interval < MM::MMTime::fromMs(GetDelayMs()); } int FilterSet::Shutdown() diff --git a/DeviceAdapters/Yokogawa/CSUX.cpp b/DeviceAdapters/Yokogawa/CSUX.cpp index ed191a750..6795fcc17 100644 --- a/DeviceAdapters/Yokogawa/CSUX.cpp +++ b/DeviceAdapters/Yokogawa/CSUX.cpp @@ -327,10 +327,7 @@ bool FilterWheel::Busy() // TODO: figure out how speed commadn affects Busy MM::MMTime now = GetCurrentMMTime(); // each position moved takes 33 msec - if ((now - lastMoveTime_) < (posMoved_ * 33)) - return true; - - return false; + return (now - lastMoveTime_) < MM::MMTime::fromMs(posMoved_ * 33); } int FilterWheel::Shutdown() @@ -605,10 +602,7 @@ int Shutter::Initialize() bool Shutter::Busy() { MM::MMTime interval = GetCurrentMMTime() - changedTime_; - if (interval < (1000.0 * GetDelayMs() )) - return true; - - return false; + return interval < MM::MMTime::fromMs(GetDelayMs()); } int Shutter::Shutdown() diff --git a/DeviceAdapters/ZeissAxioZoom/ZeissAxioZoom.h b/DeviceAdapters/ZeissAxioZoom/ZeissAxioZoom.h index 6cab59a90..1385657b3 100644 --- a/DeviceAdapters/ZeissAxioZoom/ZeissAxioZoom.h +++ b/DeviceAdapters/ZeissAxioZoom/ZeissAxioZoom.h @@ -157,8 +157,8 @@ class ZeissMonitoringThread; */ struct ZeissDeviceInfo { ZeissDeviceInfo(){ - lastUpdateTime = 0; - lastRequestTime = 0; + lastUpdateTime = MM::MMTime{}; + lastRequestTime = MM::MMTime{}; currentPos = 0; targetPos = 0; maxPos = 0; diff --git a/DeviceAdapters/ZeissCAN29/ZeissCAN29.h b/DeviceAdapters/ZeissCAN29/ZeissCAN29.h index 6e36c3908..2e9d328a4 100644 --- a/DeviceAdapters/ZeissCAN29/ZeissCAN29.h +++ b/DeviceAdapters/ZeissCAN29/ZeissCAN29.h @@ -131,8 +131,8 @@ class ZeissMonitoringThread; */ struct ZeissDeviceInfo { ZeissDeviceInfo(){ - lastUpdateTime = 0; - lastRequestTime = 0; + lastUpdateTime = MM::MMTime{}; + lastRequestTime = MM::MMTime{}; currentPos = 0; targetPos = 0; maxPos = 0; diff --git a/MMDevice/DeviceBase.h b/MMDevice/DeviceBase.h index ab92448ba..520728798 100644 --- a/MMDevice/DeviceBase.h +++ b/MMDevice/DeviceBase.h @@ -1638,9 +1638,9 @@ class CCameraBase : public CDeviceBase stop_ = false; suspend_=false; activate(); - actualDuration_ = 0; + actualDuration_ = MM::MMTime{}; startTime_= camera_->GetCurrentMMTime(); - lastFrameTime_ = 0; + lastFrameTime_ = MM::MMTime{}; } bool IsStopped(){ MMThreadGuard g(this->stopLock_); diff --git a/MMDevice/MMDevice.h b/MMDevice/MMDevice.h index 466e6fa52..6a17735bd 100644 --- a/MMDevice/MMDevice.h +++ b/MMDevice/MMDevice.h @@ -103,13 +103,13 @@ namespace MM { MMTime() : sec_(0), uSec_(0) {} - MMTime(double uSecTotal) + explicit MMTime(double uSecTotal) { sec_ = (long) (uSecTotal / 1.0e6); uSec_ = (long) (uSecTotal - sec_ * 1.0e6); } - MMTime(long sec, long uSec) : sec_(sec), uSec_(uSec) + explicit MMTime(long sec, long uSec) : sec_(sec), uSec_(uSec) { Normalize(); }