Hello, welcome back.
And this lesson, we're going to see how to work with software timers when you use in these cases are
apps.
I've created a copy of our last project over here.
I've given it a name all this time.
The last project was always delay, so I just make it.
I just made a copy of Not Changed Anything.
So we're simply going to open the main road see file here.
And this is as we left it.
We have four tasks with different priorities.
That was the last thing we did.
OK, so we're going to create software timers just like we saw when we were using the native free Arktos
APIs.
At time, I can either be a one a one short timer or aperiodic or to reload.
A timer is the same over here.
And just like we saw there as well, time is half callback functions and the callback function is the
function that gets executed when a timeout occurs.
Let's go to our documentation to find the function for the timer we can scroll here and look for.
Taimur.
Over here, there is time management.
I'm going to click here.
It's not open and OK, so we have this.
See?
Let's look at the timer again, so there is timer management.
I'm going to click to dropdown and then dysfunction or waste time a new.
Let's see.
So this is the function, the first argument, a pointer to the time, a callback function, the next
argument here is the type of time we want, whether we want a callback function or whether we want to
one short function over here, one should function.
Whether we want to one short timer, sorry about that over here, once your timer is known as always
timer was or whether we want an auto reload periodic timer.
And this is not known as always time periodic.
And then the third argument is argument we can pass to the timer callback function, just like we have
the ability to pass argument to our task functions.
We can pass arguments to over time a callback function as well.
And of course, a timer like a task also requires the.
Time attributes.
Just like the attributes we assign to it our task and we pass the attribute structure as argument,
we are required to pass the same thing with a timer if we want to provide any further configuration
through the attribute.
But in this example, we're simply going to pass.
Now, over here says we can pass.
No.
OK.
Let's see, yeah.
I wonder why it's sehnalová over here, it says Waititi, our time attributes now default values.
OK, so the attribute is supposed to allow us to have a configuration.
In a way, we go to pass this last argument.
We're going to create over time a callback function plays its prototype here.
We're going to decide whether we want to one short time or periodic time.
And we're going to pass now here.
We have no arguments and we're going to pass.
Not here.
We have no further attributes.
OK.
So this is how could as we left it, we're going to study the ideas of our time into their own variables.
We're going to have to time this.
So over here, just like we had.
Thread ID, we have time, I know, one full time or one and one for a time or two, so we have time,
I wanted to add.
OK, so we're going to create the timer.
And when we create the time at the time, it's going to return the ad and the ad is going to be stored
in the 80 variables we've declared up there.
So I'll come over here.
We call the time accretes and we're going to give this time is a callback function to name time one
callback.
And this is a one shot timer.
We have no arguments.
We have no further attributes to add.
OK, and we're going to create the second one.
We simply say timer to ID, we're going to create a callback called timer to callback this one.
We want it to be periodic.
We have no further argument, no further attributes to add here.
So once we've created a timer, we go.
Once we create a timer, we have to start the timer and to start the timer.
If you check our documentation, there is a function known as always timer start.
This function takes to document the idea of the timer you want to start and then the period of the timer.
So rather than start the timer in the main function, I'm going to start a timer and one of our tasks
I'll see.
Maybe the blue task is going to start.
Our time is where it's blue.
OK, so when Blue starts over here, we're going to call our timer starts and we're going to give our
time one a period of five thousand and timer to a period of 1000 like this.
OK, so we know what time or one.
Who is time one?
Time one is our one short time, our time to choose our periodic time.
So this time outs would occur periodically after every thousand ticks.
OK, so once this is done, we go to implement the time a callback function.
And what we can do also is create profiles for our time, just like we have our task profiler.
We can create global variables for our time as well.
So I'm going to create over here we have profiler's for our task functions.
I'm going to have profiler for time one another one for Tamati, OK?
And the timer callback function is simply going to do what our task functions do over here.
We're not implementing any complicated algorithm.
You can add your own algorithm over here for me to show you how it works, I simply increment the profiler.
OK, so we simply going to we set a callback function for the time that one is going to be timer one
underscore callback and a wonderful time or two will be timer to underscore a callback.
So we simply put a callback function here year.
And also I should mention time a callback functions are different from our tasks.
They have to run to completion.
There's no well, one loop here.
So we run and then we end, whereas our tasks have one loops.
OK, so don't make the mistake of putting a one loop here, OK?
So once this is done, we've got to put the the prototype of the callback functions at the top of the
code or copy this and.
Would drop it over here and up west, semicolon here and then this fourth time or two where semicolon
here.
So let's build and see what we have.
I'll click over here to build.
To building.
Spewed successfully.
I'm going to right click over here.
And I'll say debug us estimate 30 to.
And select forty one over here.
And I say, OK, over here.
It's open in.
Switch.
And I'm going to add our time, our profilers, I'm going to delete this resume monitor, we don't need
it over here.
Remove this and I'm going to come over here at time of one profiler.
And to profile.
And then click here to run.
As you can see, that period up in time to.
OK, no time or one time I want you to waste your time, so it's OK after time to reach five and two
is to run in time.
No one wants to run again because it's a one short timer.
So it's as simple as that.
We know the theory behind this.
We've seen how to do this using the native free ARTUS APIs.
Now this is how to do it.
Using the sensors are to us too.
So that's all there is.
And I'll see you in the next lesson.
Have a nice day.