diff --git a/Modules/include/PeriodicTrigger.h b/Modules/include/PeriodicTrigger.h index 631c3faca62584f0fb8493d53117bbffb4e98de1..809d04a6a5555d72f14a9634da78fd2b735d83e8 100644 --- a/Modules/include/PeriodicTrigger.h +++ b/Modules/include/PeriodicTrigger.h @@ -16,26 +16,33 @@ namespace ChimeraTK { /** Constructor. In addition to the usual arguments of an ApplicationModule, the default timeout value is specified. * This value is used as a timeout if the timeout value is set to 0. The timeout value is in milliseconds. */ PeriodicTrigger(EntityOwner *owner, const std::string &name, const std::string &description, - const uint32_t defaultTimeout=1000, bool eliminateHierarchy=false, const std::unordered_set<std::string> &tags={}) + const uint32_t defaultPeriod=1000, bool eliminateHierarchy=false, const std::unordered_set<std::string> &tags={}) : ApplicationModule(owner, name, description, eliminateHierarchy, tags), - defaultTimeout_(defaultTimeout) + defaultPeriod_(defaultPeriod) {} - ScalarPollInput<uint32_t> timeout{this, "timeout", "ms", "Timeout in milliseconds. The trigger is sent once per the specified duration."}; + ScalarPollInput<uint32_t> period{this, "period", "ms", "period in milliseconds. The trigger is sent once per the specified duration."}; ScalarOutput<uint64_t> tick{this, "tick", "", "Timer tick. Counts the trigger number starting from 0."}; + void sendTrigger() { + ++tick; + tick.write(); + } + void mainLoop() { + if (Application::getInstance().isTestableModeEnabled()) { + return; + } tick = 0; - std::chrono::time_point<std::chrono::steady_clock> t = std::chrono::steady_clock::now(); while(true) { - timeout.read(); - if(timeout == 0){ + period.read(); + if(period == 0){ // set receiving end of timeout. Will only be overwritten if there is new data. - timeout = defaultTimeout_; + period = defaultPeriod_; } - t += std::chrono::milliseconds(static_cast<uint32_t>(timeout)); + t += std::chrono::milliseconds(static_cast<uint32_t>(period)); boost::this_thread::interruption_point(); std::this_thread::sleep_until(t); @@ -46,7 +53,7 @@ namespace ChimeraTK { private: - uint32_t defaultTimeout_; + uint32_t defaultPeriod_; }; } diff --git a/include/Application.h b/include/Application.h index a46b256da1801ca59153dc4cc678b490b98e1467..27ee68fc6e5c2001f2cdd3c1256d3d7ce52c0922 100644 --- a/include/Application.h +++ b/include/Application.h @@ -91,6 +91,12 @@ namespace ChimeraTK { testableModeLock("enableTestableMode"); } + /** + * Returns true if application is in testable mode else returns + * false. + **/ + bool isTestableModeEnabled() { return testableMode; } + /** Resume the application until all application threads are stuck in a blocking read operation. Works only when * the testable mode was enabled. */ void stepApplication();