Ensemble Graphics Toolkit: Timers

Introduction

In this training, you will learn how to construct a Periodic and One-Shot Timer. As a bonus, you will also learn how to display the CPU usage on the WVGA Display.

Steps:


Prerequisites

You have prepared the Host PC with all the development software tools and Ensemble Graphics Toolkit source code as explained in:

You have installed and prepared the Eclipse IDE for C/C++ Developers as explained in:


Create a New Source File

In this section you will be creating a new timer.cpp source file that you will build in this and later training, demonstrating the following:

In this training, you will use EgtProject and its settings you entered in the Ensemble Graphics Toolkit -- First Application using Eclipse IDE training.

1

Start the Eclipse IDE.

Eclipse will ask you to select a directory for your workspace. Accept the default directory and click on the Launch button.

eclipse_ide_launcher.png

Eclipse will launch the previous workspace you configured.

eclipse_previous_workspace.png

2

You will be adding a new source file with the name: timer.cpp. If you have a *.cpp source file from a previous Ensemble Graphics Toolkit training, perform the following steps:

a

Right-click in the *.cpp window and select Resource Configurations > Exclude from Build…

The Exclude from build window will open:

eclipse_exclude_from_build.png

b

Select Debug and Release and click on the OK button.

The selected *.cpp will be excluded from the build.

3

Right-click on EgtProject and select Clean Project.

4

Right-click on EgtProject and select New > Source File.

The New Source File window will open:

timer_new_source_file.png

5

Enter timer.cpp into the Source file: text box. Click on the Finish button.

A new source file tab timers.cpp is created within the EgtProject.

6

Enter the following source code to the timers.cpp window pane:

7

Save your program by selecting File > Save. You may also save by pressing CTRL + S.

You have completed adding a new source file to EgtProject.


Periodic Timer

In this section, you will modify and build the timer.cpp source code that you entered in the previous section to construct a Periodic Timer and display the CPU usage.
.

1

Modify the timer.cpp source code by adding the following lines of code as shown :

2

Save your program by selecting File > Save. You may also save by pressing CTRL + S.

3

To build the project, hover over EgtProject, right-click and select Build Project from the menu. Or you can click on the Build icon.

The Console window (bottom pane) will display the build progress.

4

To set run properties, hover over EgtProject, right-click and select Run As > Run Configurations… from the menu.

5

In the left-hand pane, select EgtProject Debug (under C/C++ Remote Application).

timer_debug_configuration.png

6

In the Run Configurations window, enter the following in the Remote Absolute File Path for C/C++ Application: text box:

/root/timer

You may see the previous program /root/???? here. Replace it with /root/timer.

This is the location the timer.cpp executable will be loaded and run on the target.

7

Click on the Apply button.

8

Click on the Run button.

9

Observe the WVGA Display on the target:

The timer.cpp executable is running remotely on the target.

Observe the Press Me button in the center of the WVGA Display and observe the status “periodic timer fire!” every three seconds on the Console.

Also, observe the CPU usage in the bottom left corner of the WVGA Display.

periodic timer fired!
periodic timer fired!
periodic timer fired!

timers_1.png

PeriodicTimer class

From ~/egt/docs/html/annotated.html, click on the PeriodicTimer class. All the functions, attributes, and constructors associated with the class are documented here.

The PeriodicTimer will keep firing at the duration interval until it is stopped by calling cancel().

On_timeout

This function allows you to add a handler callback function to be called when the timer times out. This function may be called any number of times to add handlers.

CPUMonitorUsage

From ~/egt/docs/html/annotated.html, click on the CPUMonitorUsage class. All the functions, attributes, and constructors associated with the Dialog class are documented here.

This class allows user to monitor the CPU usage of the system.

10

To stop the program, press the Stop button (upper left hand, just below the menu bar).

Before you start another session, be sure to stop the current session.


One-Shot Timer

In this section, you will modify and build the timer.cpp source code to construct a One-Shot Timer that will fire after three seconds.
.

1

Modify the timer.cpp source code by adding the following lines of code as shown :

2

Save your program by selecting File > Save. You may also save by pressing CTRL + S.

3

To build the project, hover over EgtProject, right-click and select Build Project from the menu, or you can click on the Build icon.

The Console window (bottom pane) will display the build progress.

4

Click on the Run button.

5

Observe the WVGA Display on the target:

The timer.cpp executable is running remotely on the target.

Observe the target Console for the status “One shot timer fired” after a period of three seconds.

# /root/timer; exit

One shot timer fired

Timer class

From ~/egt/docs/html/annotated.html, click on the Timer class. All the functions, attributes, and constructors associated with the class are documented here.

The Basic One-shot timer will fire once after the specified duration.

On_timeout

This function allows you to add a handler callback function to be called when the timer times out. This function may be called any number of times to add handlers.

6

To stop the program, press the Stop button (upper left hand, just below the menu bar).

Before you start another session, be sure to stop the current session.


Summary

In this training, you learned how to construct a Periodic and One-Shot Timer. As a bonus, you also learned how to display the CPU usage on the WVGA Display.


What’s Next?

There’s plenty more to learn. Here are some additional Ensemble Graphics Toolkit training resources to help you gain more knowledge and skills:

© 2022 Microchip Technology, Inc.
Notice: ARM and Cortex are the registered trademarks of ARM Limited in the EU and other countries.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.