Exercise-003 Implementing TIME_SET state
In this article, let’s process all the events for TIME_SET state.
The application is in TIME_SET state, and the Increment time event is received. Increment time means you have to increment the time—the c_time variable.
Now the increment time should happen inside the TIME_SET state (Figure 1).
This is a state which takes care of setting the time. That’s why it cannot transition; it should take care inside of it.
Hence, increment time and decrement time will be Internal Transition for this state. It cannot ask someone else to do increment time or decrement time. It’s the TIME_SET state’s responsibility.
Select TIME_SET state and go to Internal; the trigger is INC_TIME. Action is the same as previous. And there is one more action: mobj->c_time+=60; it should show the incremented time on the display.
So, disp_time (mobj->c_time). Whenever increment time is received, it just does + to c_time and then displays the modified time. That’s it.
Let’s process the decrement time. The decrement time is also an Internal Transition. Let me add one more Internal Transition DEC_TIME.
Action is: You have to do ‘-’ here. mobj->c_time-=60; you modified the time, so display the time, mobj->c_time. That’s it, as you can see in Figure 2.
Guard is mobj->c_time >=60.The current time should be greater than or at least = 60. That’s a Guard. This is a Boolean expression; a Boolean expression will be FALSE if c_time is less than 60.
Please note that you can only increment or decrement the minutes, not the seconds, using increment time and decrement time. So, this has no effects on the seconds.
The next event is ABORT.
When there is an ABORT event, it just comes back to the IDLE state. I mean, no guard, no action, nothing, just ABRT.
When the ABORT event is received, it comes to the IDLE state, but the TIME_SET state has displayed something. That needs to be cleared. That’s why you can give one Exit action.
Exit action is a disp_clr(). And when it comes to the IDLE mode, it sets everything to 0, and displays 0 and sends the message “Set time.”
The next event is START_PAUSE.
Now you have done the time settings, so now the user presses the START/PAUSE button, so the COUNTDOWN has to be started. And that happens in the COUNTDOWN state. That’s why now there will be one transition from TIME_SET state to the COUNTDOWN state (Figure 4). The trigger is START_PAUSE.
Guard is mobj->c_time>=60, the COUNTDOWN cannot begin if minutes is 0.That’s why a Guard would be mobj->c_time should be greater than or = 60. That’s a Guard for this transition to happen. If this condition is not TRUE, then this transition cannot happen. That’s our START_PAUSE event.
The next event is the TIME_TICK event.
When the application is in TIME_SET state, it doesn’t process the TIME_TICK event. I mean, there is no action that is synchronous with the time. Because TIME_SET nearly does modification to the time variable as per the ‘+’ or ‘–’ button pressed by the user. It has no time-based action defined. That’s why let’s ignore that event in this state.
FastBit Embedded Brain Academy Courses
Click here: https://fastbitlab.com/course1