Hello, welcome back.
And this lesson, we go in to see how to work with software timers, I'm going to make a copy of the
Gatekeeper Task Project and paste it over here.
And I'll call this working with software time as.
They copy over here.
Then expand this and then call.
Then I'll look at it, I may not see fall over here.
OK, so we're going to create two new tasks.
So I'm going to clean all the artists related code from the project.
OK, I've cleaned all the tasks we created, deletes the task functions as well.
Of deleted them.
And.
Delete them from here as well.
So we just have our project.
Well, no more projects before we use time as we need to include time as to our projects.
So I'll go to our Simms's always thought each fall by right clicking an open declaration.
And over here I'm going to include time in storage so I can simply copy one of these and paste over
here and change this word.
To Taimur.
Well, time is plural, it is required click here to be able to see how we are looking.
OK, we're looking good, and then I'll come back here to our main function, so I'm going to declare
the time up period.
We're going to experiment with both the periodic timer and the one short timer.
OK, I'll delete this.
Excuse Hondo here.
We don't need this, so we're going to have to puritz.
OK.
So we define in this we're going to see the one short time period should be four thousand.
Milliseconds.
I cuts this by mistake, sorry about that.
So.
The Winshaw time either period should be four thousand milliseconds because we are doing PDM, Static's
and then our periodic timer issued whuppin every 500 Ms.
OK, so that's the period to now.
What we're going to do is we going to create a handle for our timer or our time is because we have two
of them.
We're going to have a handle for the want one short time as well as our periodic auto reload timer.
And also we're going to create a variable to hold our time as that is whether the timer is started or
not.
We can start our variable in the base type, so we see a base type over here X time or one started,
X time or two started OK.
Once that is done, we're going to create over time to create over time.
We use the X time to create function.
The first argument of this function is a string just to let us know the name of this timer.
The second argument is the the period.
And the third argument is whether we want to said this as a one shot timer or not.
And then the last after that, there's an argument.
Where we can place a variable to start a timer timer ID, and then after that, the argument is.
The callback function for the timer, so I'll come over here, we first got our first argument as the
time we call in this one one shot.
The second argument is the time up period.
So the period before it is defined at the top, we gave it this value, but it wasn't your time.
OK, so the next argument after this is the is whether we want this time to be a one short timer or
an auto reload timer because we want this to be one shot, we're going to pass false over here.
The next argument is the time of ID.
We're not using time ID.
So I'm going to pause.
You hear the last argument is the callback function for the time.
I just like our tasks of task functions.
Our time is of callback functions.
We're going to create a callback function called Pravy one short time, a callback.
So I'm just put in the name here, OK?
And of course, this time I will return to handle which we are storing in our X time X one short time
handle.
So I'm going to copy this.
And then we create the auto reload version.
So over here, we said this is going to be our auto reload or periodic timer, I'll call this auto reload
and then the period for our auto reload we defined up here.
So I copy this period and this time it's asking whether we want to want to make it one shot we want.
So to phrase this properly, this parameter asks whether you want it to be auto reload or not.
So over here, when we said force, we said we don't want auto reload.
And since the all the other option is one shot, if you said to force, you are going to have a one
shot timer.
So over here we want auto reload.
So we're going to set it to true this parameter.
OK, and then after that, we have this argument, which is for the time, a Honda, and then we have
this disco back where we have to put a TAMAKO box over here, we're going to use a kolba called PSV.
Pravy, we can give it a name, auto reload time I Kobuk Pravy.
Auto reload time, I call back like this.
OK, so.
Once we are done, we've created our time is now we have to start our time is.
So to start the timer, we simply use the the time I start to function to do the.
My computer does.
I pressed a single key and then it's duplicated over 50 times.
It could be that my computer is getting slow because I've turned off the fun so that it doesn't disturb
the video, because when you're recording for long and your computer phone is on, you hear the the
sound of the fun.
OK, so the task function.
All the the callback function for our time, as this one is called.
So what we want to do is get the current time and print.
We can get the time using the get count.
So I'm going to create a local variable here called X Time Now.
And then I'm going to get it current time and store it in this variable, so to get a time, we simply
see.
Get take count.
So I obtain that and storage in this very well, and once we've done that, then we can go ahead to
print this using our print.
OK, so remember, Tamako back functions are different from our task functions.
There shouldn't be an infinite loop here.
We don't have it.
If it's not, we don't have is not an optional thing.
We we must make sure we don't put a while.
One loop here.
This is a callback function is supposed to run to completion his thoughts and then it completes.
There's no one here, OK.
So this is the.
The Kobuk for our.
One short timer, so a similar one for our auto reload timer is simply going to print the time just
like we've done above.
So we have P RV or to reload the time I call back, it gets the.
Take account and then print it like this.
OK, so once I've done this, I'm going to expose the prototypes.
I'll copy this.
I'll bring this to the top over here.
And then I'll come down to get the auto reload.
I'll this.
And then put this over here.
OK, let's see what we have.
Click over here to build.
We have two errors, what does A, C, P, R, v?
Auto reload.
OK, there's an anomaly here, I forgot the word or the letter T over here, so I'll click here to build.
It's built in.
OK, Canaro.
And, um.
We can right click over here.
And run us estimate that it's you select this twenty three.
And then I'll say, OK.
OK.
It's still working, so standard verified.
OK, let's go to real time to see what we have.
Here we are.
I'm going to clear this up, I'm going to open our port again.
Real time, it's not responding.
OK, I'm going to close this in open again.
Here we are.
So like this in port, so I tell poetry to hear.
And then this is how port.
OK, still not responded.
OK, now let's see where we could have an anomaly, we came over here, we created two times.
And they've got a callback function as we started our scheduler, we didn't forget that.
Did we start a time is the next time I start?
We started both time as.
Let's inspect our code, so we came over here, we created our timer, we stored the handle, the Winshaw
timer here and over here, we created the auto reload.
OK, but we stored the auto reload and one short handle.
OK, this may be creating an error.
So our our program is probably crushing around here.
Um, so of course we have to change this because we made a copy of this one.
We or I thought to change this the handle.
So the auto reload will be stored in the auto reload handle over here.
OK, let's run and see if this is what was causing us the issue.
Click over here to build its Beurden.
And it's done building, I'll click here to run.
If I hear.
And hoping to see.
Eau Claire rootin.
Waiting for the power connection.
OK, there we go.
Oh, we can see our timer running.
OK, I'm going to post this right, we see that one short time, OK, and once that's.
This time period, four thousand times, but we see that every 500 times auto reload time.
Executed callback such that we have six thousand five hundred seven thousand seven thousand five hundred
eight thousand, so it's working as expected, because this this is the period we defined that the author
reload timer is 500 times every 500 M is issued execute its callback function, whereas we want the
Winshaw time to execute.
This was issued execute four thousand milliseconds after we started and that's what occurred over here.
OK, so this order is with regards to our time is I'll see in the next lesson of a nice day.