Hello, welcome back.
And this lesson, we go in to see how to work with the gatekeeper task, I'm going to create a new project
by making a copy of the last one over here.
I'll copy and paste it over here.
I'll call this gatekeeper.
Like this.
OK.
So it's cop in.
OK, so I'm going to open our gate keeper to ask.
This is minimized.
Here we are, gatekeeper over here, source and may not see over here, so we go in to achieve what
we've been achieving with our semaphores.
But this time without semaphores, we're going to use our gatekeeper and the gatekeeper is going to
be the task which is keeping the gate for our serial port.
Our Ewart's is going to be handled by just one task.
So both our analog sensor task and our digital sensor task, if they have something to print, they
have to give it to the gatekeeper task to print it for them.
That is what we going to do over here.
So over here, we don't require semaphores or delete our semaphore handle here and then.
So currently, I've just deleted our SEMAFO, Honda or Semaphore crates of deleted as well.
OK.
So what do we have we have two tasks, we have our Botin Reid task and we have a white button, Reid
and Senator Reid, and we know Button Reid is our digital button and then sensor is, of course, our
ADC.
What I'm going to do next is I'm going to clean this bit here where we were taken and given to SEMAFO.
I'm going to clean it in both of these task functions.
Such that's what we have left in our digital sense or task is just read the digital sense or storage
in a variable, and then we toss one here and what we have in our analog senso with the analog sense
or storage in a variable.
And we have to delay one here.
So we're going to create a third task known as the gatekeeper task.
And this would have the same it would have the same amount of rum, the same success story as the other
tasks.
We're going to give this a priority of zero.
The others have a priority of one.
So our gatekeeper essentially has the lowest priority here.
No problem with this.
Right.
So now the question is, how are we going to get information from our tasks to the gatekeeper?
What are we going to do is employ a Q We're going to use a Q So if if a task has something to print,
it would put it into.
Q You can think of.
You can think of being in an office with a number of computers and having a central computer that is
connected to the printer such that if you want something to print, you send it to the central computer
in the central computer keywords for you.
In the printer, and then you print one after the other based on which arrived first.
OK, so we have three tasks.
Yeah, our bottom reader task.
Sensory task.
Our gatekeeper task.
OK, next, we going to define the handle for a Q.
Of course, we said we're going to use a cue, so I'll come up here and have this Q&A Hondo here, experiencer
cue.
OK, so since we have the handle for the cue, we have to create the cue, then we're going to see the
cue.
Should have a maximum capacity of two elements.
So we see X execute great size of end.
This is going to be the data type.
And we want to study Hunda here, OK, once that is done, we said the name of our.
Our gatekeeper task is task, we can call it a little task for now, right?
You can call it zero printer task if you want, or LCD task.
I'm just calling the LCD task here, OK?
So that's the name we give the task function.
We know this already.
So I'm going to create an LCD task function down here.
We have our first task function is the second one for the second task, the third one over here like
this.
We're going to have our infinite loop here.
OK, so over here, in a digital sense or task, whenever it's reached the sense data we wanted to send
DICENZO who wanted to send the button data to our queue.
So what we want to do is see X, Q send it back because we want to add this to the Q.
Excuse and to back and what we want to send is the button states, so what we read here, we send in
it to the cute, OK, and we want to do the same for our.
Analog Senseor.
So the analog sensor volume that we store in this variable, we want to send that to the queue over
here like this.
OK, so then our queue has our sense of values.
Now, what we want to do is go to our gatekeeper task over here and tell the gatekeeper task to wait.
We're going to create a variable for the gatekeeper task to store what it received or of this variable
into variable here called value to print.
So the gatekeeper task is going to wait.
We're going to see Portsmouth's delay over here.
We're going to pass this over here.
So we're going to wait.
For data to become available, maximum delay, OK, so when the data is received from this key is going
to be stored in this variable here and we can print the content of this variable without of.
So you simply say printf here, and if we want to make it more complex, of course we can identify whether
this is coming from the from the digital sense or the analog sense or using the the one of our Q examples
where we had a structure, we would send in a structure to the Q and one of the structure members told
us the the identification of the data, whether it was humidity data or pressure sense or data, we
can use that method here to identify what arrives here.
But this is simplified.
We simply say new value.
OK, let's build it and see what we've got.
Now click over here to build.
OK, we've not placed the prototype of this.
Tosk function at a topia, so I'll place that over here.
We're looking good.
Click over here to build.
It's built successfully.
OK, I'm going to right click over here and also run us a STEM 32 double click on Gatekeeper.
And I'll say, OK, over here.
OK.
Says.
Download verified successfully.
So I'm going to open this and I can see we have new value.
OK, but that is rather strange.
We simply have in our.
Sense of value only, we're not receiving anything we have in just our digital sense of value.
I'm pressing the button.
That is why he's changing.
We're not receiving the atkeson.
So let's see where we could have gone wrong.
We have this here.
This is it's.
We are in this.
And it looks so to cue.
AK.
OK, we could solve this by making it more stable, we can just increase v task delay here from one
to ten and then ten, OK?
So click over here to build.
It's built successfully, I'll click here to run.
It's running, says the sea, as you can see now, we have our unlock value.
And then or pushbutton, when I push, you can see it's change.
OK, so this all the wrist, this all the wrist with regards to the gatekeeper to ask any questions,
leave them in the questions and answers area and I'll see you later.
Have a nice day.