Exercise-008:Implementation part 4
In this article, now let’s generate some code. In the source(../src), it has got a couple of files like ClockAlarm_SM.cpp, ClockAlarm_SM.h, alarm.cpp, alarm.h, button.cpp, button.h. (Figure 1)
First of all, ClockAlarm_SM.cpp. So, this is just like the previous code. We are going to modify this. And this implements the state machine of the ClockAlarm active object and its associated ClockAlarm_SM.h file.
In the ClockAlarm_SM.h file, I added a few more signals; SET_SIG, OK_SIG, and ABRT_SIG were over there. I just added ALARM_SIG, and another one I added ALARM_CHECK_SIG. Please note this change.
After that, alarm.cpp. So this is a source file for implementing the component alarm and its associated state machine. And its associated header file alarm.h, which is now empty. We will fill that in later.
And Button.cpp or I would rather call this as button_SM.cpp. This implements the state machine of the button active object and its associated header file Button_SM.h.
In the ClockAlarm_SM.h file, you also see one more enum definition here for setting. There are three options, NO_SETTING, CLOCK_SETTING, ALARM_SETTING.
Now, let’s go to alarm.cpp. First, let’s modify this file.
This is a .cpp file. Just include these header files, like ‘Arduino.h’, ‘qpn.h’, its associated header file, and the ‘ClockAlarm_SM.h.’ Because of this alarm class containers header file.
After that, generate the code. Here, let’s use the code generation directive $define and drag and drop this Alarm: QHsm. And also, you should define the ctor. (Figure 6)
Let’s go to the alarm.h and here you have to declare. Declare this alarm class and also declare the ctor, as shown in Figure 7.
Now, let’s go to the button_SM.cpp, and here also include all the header files that you included in the alarm.cpp. You don’t need #include “alarm.h”. Remove that. You may need this “button_SM.h.”
Here, define button class and also define the button_ctor, as shown in Figure 8.
And go to button_SM.h, declare button class and declare Button_ctor, as shown in Figure 9.
Now, let’s generate the code. There are a couple of issues. Let’s see what that is.
Error is saying something is broken. In the ClockAlarm_SM.cpp file, the package name is not HSMs. Now the package name has changed. It must be AOs. Let’s replace that. Save it. (as shown in Figure 11)
Go to ClockAlarm_SM.h, and here the package name is AOs. (Figure 12)
Let’s generate. Now, it is fine, with 0 errors.
And we also have this global free attribute: AO_ClockAlarm:QActive *const and AO_Button:QActive *const. For that also, you have to generate the code.
That’s why, in the ClockAlarm_SM.cpp, I have this code, as shown in Figure 13. I have defined that here in the .cpp $define${AOs::AO_ClockAlarm}.
Same thing you have to do in button_SM.cpp.
In the button_SM.cpp, define that pointer variable, that is AO_Button:QActive *const.
And it should be shared with other files. That’s why we have to declare that in the button_SM.h file.
We will do that in the button_SM.h file. $declare${AOs::AO_Button} shown in Figure 15.
Let’s go to the IDE, and our project is 008ClockAlarm_AO. In the source, as you can see here, we got a couple of files here, as shown in Figure 16.
We should also update the library path. Go to 007ClockAlarm, go to the platformio.ini, copy the library path code. And go to your current project 008ClockAlarm_AO, go to platform.ini and paste that code, as shown in Figure 17.
Also, go to your old project, and you need these files lcd.cpp, lcd.h. Copy both files, go to your current project, and goto source and paste it here. You can see the lcd. cpp and lcd.h file shown in Figure 16.
FastBit Embedded Brain Academy Courses
Click here: https://fastbitlab.com/course1