1
00:00:00,870 --> 00:00:01,970
Hello, welcome back.

2
00:00:01,980 --> 00:00:09,240
And this lesson, we're going to see how to work with software timers when you use in these cases are

3
00:00:09,570 --> 00:00:10,320
apps.

4
00:00:10,740 --> 00:00:13,430
I've created a copy of our last project over here.

5
00:00:13,800 --> 00:00:15,480
I've given it a name all this time.

6
00:00:15,690 --> 00:00:19,120
The last project was always delay, so I just make it.

7
00:00:19,170 --> 00:00:21,510
I just made a copy of Not Changed Anything.

8
00:00:21,960 --> 00:00:24,930
So we're simply going to open the main road see file here.

9
00:00:25,530 --> 00:00:27,000
And this is as we left it.

10
00:00:27,000 --> 00:00:30,390
We have four tasks with different priorities.

11
00:00:30,960 --> 00:00:32,130
That was the last thing we did.

12
00:00:32,490 --> 00:00:40,920
OK, so we're going to create software timers just like we saw when we were using the native free Arktos

13
00:00:40,920 --> 00:00:41,610
APIs.

14
00:00:41,940 --> 00:00:47,690
At time, I can either be a one a one short timer or aperiodic or to reload.

15
00:00:47,700 --> 00:00:49,620
A timer is the same over here.

16
00:00:50,070 --> 00:00:56,250
And just like we saw there as well, time is half callback functions and the callback function is the

17
00:00:56,250 --> 00:00:59,370
function that gets executed when a timeout occurs.

18
00:01:00,760 --> 00:01:07,480
Let's go to our documentation to find the function for the timer we can scroll here and look for.

19
00:01:08,860 --> 00:01:09,460
Taimur.

20
00:01:10,400 --> 00:01:12,450
Over here, there is time management.

21
00:01:12,470 --> 00:01:13,420
I'm going to click here.

22
00:01:18,570 --> 00:01:20,790
It's not open and OK, so we have this.

23
00:01:23,990 --> 00:01:24,300
See?

24
00:01:29,300 --> 00:01:33,470
Let's look at the timer again, so there is timer management.

25
00:01:33,590 --> 00:01:38,720
I'm going to click to dropdown and then dysfunction or waste time a new.

26
00:01:39,720 --> 00:01:40,310
Let's see.

27
00:01:41,270 --> 00:01:47,540
So this is the function, the first argument, a pointer to the time, a callback function, the next

28
00:01:47,540 --> 00:01:54,020
argument here is the type of time we want, whether we want a callback function or whether we want to

29
00:01:54,530 --> 00:01:57,410
one short function over here, one should function.

30
00:01:58,970 --> 00:02:03,590
Whether we want to one short timer, sorry about that over here, once your timer is known as always

31
00:02:03,590 --> 00:02:07,340
timer was or whether we want an auto reload periodic timer.

32
00:02:07,820 --> 00:02:10,460
And this is not known as always time periodic.

33
00:02:11,210 --> 00:02:18,710
And then the third argument is argument we can pass to the timer callback function, just like we have

34
00:02:18,710 --> 00:02:23,230
the ability to pass argument to our task functions.

35
00:02:23,240 --> 00:02:27,010
We can pass arguments to over time a callback function as well.

36
00:02:27,320 --> 00:02:30,980
And of course, a timer like a task also requires the.

37
00:02:32,540 --> 00:02:33,560
Time attributes.

38
00:02:35,180 --> 00:02:40,940
Just like the attributes we assign to it our task and we pass the attribute structure as argument,

39
00:02:41,420 --> 00:02:47,780
we are required to pass the same thing with a timer if we want to provide any further configuration

40
00:02:47,780 --> 00:02:49,170
through the attribute.

41
00:02:49,690 --> 00:02:51,890
But in this example, we're simply going to pass.

42
00:02:51,890 --> 00:02:54,620
Now, over here says we can pass.

43
00:02:54,620 --> 00:02:54,920
No.

44
00:02:55,750 --> 00:02:56,310
OK.

45
00:03:00,800 --> 00:03:02,060
Let's see, yeah.

46
00:03:03,480 --> 00:03:11,010
I wonder why it's sehnalová over here, it says Waititi, our time attributes now default values.

47
00:03:11,670 --> 00:03:16,770
OK, so the attribute is supposed to allow us to have a configuration.

48
00:03:17,430 --> 00:03:20,760
In a way, we go to pass this last argument.

49
00:03:20,790 --> 00:03:26,190
We're going to create over time a callback function plays its prototype here.

50
00:03:26,190 --> 00:03:29,820
We're going to decide whether we want to one short time or periodic time.

51
00:03:30,000 --> 00:03:31,470
And we're going to pass now here.

52
00:03:31,480 --> 00:03:33,660
We have no arguments and we're going to pass.

53
00:03:33,660 --> 00:03:34,070
Not here.

54
00:03:34,080 --> 00:03:35,700
We have no further attributes.

55
00:03:36,340 --> 00:03:36,870
OK.

56
00:03:37,760 --> 00:03:47,910
So this is how could as we left it, we're going to study the ideas of our time into their own variables.

57
00:03:47,930 --> 00:03:49,130
We're going to have to time this.

58
00:03:50,030 --> 00:03:52,160
So over here, just like we had.

59
00:03:53,100 --> 00:03:58,980
Thread ID, we have time, I know, one full time or one and one for a time or two, so we have time,

60
00:03:58,980 --> 00:04:00,530
I wanted to add.

61
00:04:01,200 --> 00:04:04,620
OK, so we're going to create the timer.

62
00:04:04,620 --> 00:04:09,750
And when we create the time at the time, it's going to return the ad and the ad is going to be stored

63
00:04:09,750 --> 00:04:12,260
in the 80 variables we've declared up there.

64
00:04:13,020 --> 00:04:14,340
So I'll come over here.

65
00:04:15,180 --> 00:04:20,820
We call the time accretes and we're going to give this time is a callback function to name time one

66
00:04:20,820 --> 00:04:21,390
callback.

67
00:04:21,750 --> 00:04:23,630
And this is a one shot timer.

68
00:04:24,030 --> 00:04:25,290
We have no arguments.

69
00:04:25,290 --> 00:04:27,360
We have no further attributes to add.

70
00:04:28,090 --> 00:04:31,200
OK, and we're going to create the second one.

71
00:04:32,130 --> 00:04:39,210
We simply say timer to ID, we're going to create a callback called timer to callback this one.

72
00:04:39,210 --> 00:04:40,380
We want it to be periodic.

73
00:04:40,380 --> 00:04:44,580
We have no further argument, no further attributes to add here.

74
00:04:46,270 --> 00:04:50,080
So once we've created a timer, we go.

75
00:04:52,020 --> 00:04:57,120
Once we create a timer, we have to start the timer and to start the timer.

76
00:04:57,150 --> 00:05:01,680
If you check our documentation, there is a function known as always timer start.

77
00:05:02,040 --> 00:05:08,370
This function takes to document the idea of the timer you want to start and then the period of the timer.

78
00:05:08,880 --> 00:05:15,210
So rather than start the timer in the main function, I'm going to start a timer and one of our tasks

79
00:05:16,050 --> 00:05:16,860
I'll see.

80
00:05:16,860 --> 00:05:19,410
Maybe the blue task is going to start.

81
00:05:19,410 --> 00:05:21,420
Our time is where it's blue.

82
00:05:22,590 --> 00:05:28,980
OK, so when Blue starts over here, we're going to call our timer starts and we're going to give our

83
00:05:28,980 --> 00:05:38,010
time one a period of five thousand and timer to a period of 1000 like this.

84
00:05:38,530 --> 00:05:41,310
OK, so we know what time or one.

85
00:05:41,310 --> 00:05:42,270
Who is time one?

86
00:05:43,190 --> 00:05:47,790
Time one is our one short time, our time to choose our periodic time.

87
00:05:48,410 --> 00:05:54,500
So this time outs would occur periodically after every thousand ticks.

88
00:05:55,280 --> 00:06:01,250
OK, so once this is done, we go to implement the time a callback function.

89
00:06:02,240 --> 00:06:08,670
And what we can do also is create profiles for our time, just like we have our task profiler.

90
00:06:09,290 --> 00:06:12,150
We can create global variables for our time as well.

91
00:06:12,650 --> 00:06:18,350
So I'm going to create over here we have profiler's for our task functions.

92
00:06:18,820 --> 00:06:24,370
I'm going to have profiler for time one another one for Tamati, OK?

93
00:06:24,380 --> 00:06:31,870
And the timer callback function is simply going to do what our task functions do over here.

94
00:06:31,880 --> 00:06:34,340
We're not implementing any complicated algorithm.

95
00:06:34,340 --> 00:06:40,700
You can add your own algorithm over here for me to show you how it works, I simply increment the profiler.

96
00:06:41,750 --> 00:06:47,330
OK, so we simply going to we set a callback function for the time that one is going to be timer one

97
00:06:47,330 --> 00:06:51,830
underscore callback and a wonderful time or two will be timer to underscore a callback.

98
00:06:52,280 --> 00:06:54,860
So we simply put a callback function here year.

99
00:06:56,150 --> 00:07:00,680
And also I should mention time a callback functions are different from our tasks.

100
00:07:01,400 --> 00:07:03,020
They have to run to completion.

101
00:07:03,440 --> 00:07:04,970
There's no well, one loop here.

102
00:07:06,960 --> 00:07:11,280
So we run and then we end, whereas our tasks have one loops.

103
00:07:11,880 --> 00:07:17,590
OK, so don't make the mistake of putting a one loop here, OK?

104
00:07:17,610 --> 00:07:22,740
So once this is done, we've got to put the the prototype of the callback functions at the top of the

105
00:07:22,740 --> 00:07:25,290
code or copy this and.

106
00:07:26,430 --> 00:07:34,650
Would drop it over here and up west, semicolon here and then this fourth time or two where semicolon

107
00:07:34,650 --> 00:07:34,950
here.

108
00:07:35,910 --> 00:07:37,470
So let's build and see what we have.

109
00:07:38,690 --> 00:07:40,070
I'll click over here to build.

110
00:07:47,300 --> 00:07:47,940
To building.

111
00:07:49,000 --> 00:07:50,140
Spewed successfully.

112
00:07:52,260 --> 00:07:54,570
I'm going to right click over here.

113
00:07:55,440 --> 00:07:58,260
And I'll say debug us estimate 30 to.

114
00:07:59,380 --> 00:08:01,810
And select forty one over here.

115
00:08:03,780 --> 00:08:05,520
And I say, OK, over here.

116
00:08:08,360 --> 00:08:09,260
It's open in.

117
00:08:13,060 --> 00:08:13,750
Switch.

118
00:08:17,330 --> 00:08:24,380
And I'm going to add our time, our profilers, I'm going to delete this resume monitor, we don't need

119
00:08:24,380 --> 00:08:25,250
it over here.

120
00:08:26,350 --> 00:08:31,300
Remove this and I'm going to come over here at time of one profiler.

121
00:08:33,910 --> 00:08:35,800
And to profile.

122
00:08:39,450 --> 00:08:40,830
And then click here to run.

123
00:08:42,270 --> 00:08:44,280
As you can see, that period up in time to.

124
00:08:46,130 --> 00:08:54,200
OK, no time or one time I want you to waste your time, so it's OK after time to reach five and two

125
00:08:54,200 --> 00:08:55,560
is to run in time.

126
00:08:55,560 --> 00:08:58,340
No one wants to run again because it's a one short timer.

127
00:08:58,730 --> 00:09:00,310
So it's as simple as that.

128
00:09:00,470 --> 00:09:02,110
We know the theory behind this.

129
00:09:02,480 --> 00:09:06,610
We've seen how to do this using the native free ARTUS APIs.

130
00:09:06,650 --> 00:09:08,030
Now this is how to do it.

131
00:09:08,030 --> 00:09:11,240
Using the sensors are to us too.

132
00:09:12,110 --> 00:09:13,160
So that's all there is.

133
00:09:13,160 --> 00:09:14,570
And I'll see you in the next lesson.

134
00:09:14,570 --> 00:09:15,350
Have a nice day.
