-
-
Notifications
You must be signed in to change notification settings - Fork 34
Task Time
The time values used throughout this library are an abstract. They should not be considered a usable time period directly and should be converted to and from the task time.
The resolution of the task interval is based on millis()
or micros()
. The default is millis()
. To allow the code to easily switch, callers should use the macros to wrap constants.
uint32_t taskTime = MsToTaskTime(400); // 400 ms
uint32_t timeMilliseconds = TaskTimeToMs(taskTime);
uint32_t timeMicroseconds = TaskTimeToUs(taskTime);
taskTime = UsToTaskTime(400000) // 4000000us, 400ms also
This is important for passing in time interval when the task is created, and when handling the deltaTime
parameter in the Update method.
FunctionTask taskTurnLedOn(OnUpdateTaskLedOn, MsToTaskTime(400)); 400ms
void OnUpdateTaskLedOn(uint32_t deltaTime)
{
uint32_t deltaTimeMs = TaskTimeToMs(deltaTime);
}
If you call millis()
or micros()
, you will get the time as it is right at the time of the call. If you want relative time from update to update, you can get this from the TaskManager. This value will change only on the update interval, and should only be used within an update call.
uint32_t updateTaskTime = taskManager.CurrentTaskTime();
WARNING: Advanced feature
To switch the library to use a higher resolution interval (microseconds), you need to edit the Task.h file in the library/Task/Src folder and uncomment the following line.
//#define TASK_MICRO_RESOLUTION
If you have used the macros mentioned above, your project should compile and run, but now at a higher resolution.
By doing this, the longest time a task interval can be is just over 70 minutes.
TaskTime values will now be microseconds, but the time interval may still be larger than a single microsecond, as some Arduinos will only return values that incremented by 2, 4, or even 8.