From 08506451c616551dec9939b478a86cd3899f1cd1 Mon Sep 17 00:00:00 2001 From: AverageGuy Date: Fri, 5 Jul 2024 12:42:33 -0400 Subject: [PATCH] Adding template file. It compiles and correctly runs one example file. Theexample file is full of extraneous code and needs to be cleaned up. --- TaskSched.tpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 TaskSched.tpp diff --git a/TaskSched.tpp b/TaskSched.tpp new file mode 100644 index 0000000..3012dc7 --- /dev/null +++ b/TaskSched.tpp @@ -0,0 +1,29 @@ +#ifndef TASKSCHED_TPP +#define TASKSCHED_TPP + +template +void Task::initializeTask(T interval, bool enabled, int iterations, const char* name, bool runImmediately) { + if constexpr (std::is_floating_point::value) { + mInterval = static_cast(interval * 1000.0 + 0.5); // Convert seconds to milliseconds and round + } else { + mInterval = static_cast(interval); // Already in milliseconds + } + mEnabled = enabled; + mIterations = iterations; + mName = name; + mRunImmediately = runImmediately; + mOrig.mEnabled=enabled; + mOrig.mInterval=mInterval; + mOrig.mIterations=iterations; + mOrig.mRunImmediately=runImmediately; + mLastStartTime=millis(); + + // ... other initializations ... + + #ifdef DEBUG + Serial.print("Interval set to: "); + Serial.print(mInterval); + Serial.println(" ms"); + #endif +} +#endif // TASKSCHED_TPP