Step 8: Review the Application Code
Application File: app.h
Open the app.h file and review the code. This file is generated by the MPLAB® Harmony Configurator (MHC) when you click the "Generate Code" button. It enumerates the application states and creates a structure to hold application data.
- The application states corresponding to the state machine are enumerated as shown in the following image. These states are explained in the next section.
Application Data Structure
- The global application data structure is defined as shown in this graphic:
Descriptions of important application data structure members:
- state: Holds the application's current state.
- slidePauseTime: Keeps track of the pause interval time between the slides.
- dirHandle: Holds SYS_FS File handle for directory.
- dirstat: Holds SYS_FS status for dir read.
- fileHandle: Holds SYS_FS File handle for current image file.
- fileStatus: Holds SYS_FS File status for current image file.
- fileSize: Keeps track of the file size.
- imageResourceHeader: Holds the Resource Header for the slide image (specifies if the resource is image, font, or binary). It also holds type and ID information for the resource.
- rootNode: Holds the root node of the media (SD card) volume.
- fileNameTable: Holds a table which has the file names for the volume.
- fileName: Holds the name of the current file.
- totalFiles: Holds the total number of files in the volume.
- imageIndex: Tracks the current image to show.
- imageReadyToDraw: Tracks if the image is ready to be rendered on the screen.
- animationStopRequested: Tracks if the user initiated a slide exit.
- sysTmrHandle: Tracks the delay between slides while the application is in the Slideshow mode.
- metaDataEnable: Tracks if the metadata of the image is to be displayed.
- doubleBufferingEnable: Tracks whether to enable double buffering for the the Slideshow.
- currentTouchBehavior: Track whether the current touch event is PRESS, MOVE, STILLPRESS, RELEASE, or INVALID.
- mostRecentTouchX: Holds most recent valid touch position x-coordinate.
- mostRecentTouchY: Holds most recent valid touch position y-coordinate.
- imageFrameCount: Tracks the number of frames in an animated GIF image.
- secondString: Displays the value of pause interval time on the screen.
Application File: app.c
Open the app.c file and review the code. This file is generated by MHC when you click the "Generate Code" button.
- Allows the application to initialize various tasks and application related data.
- Implements the application state machine. It is called periodically from the SYS_Tasks function. These states are described in the following section.
The Application initialization happens in this state.
In this state, an event handler (APP_SYSFS_EventHandler) is registered with the FileSystem.
This event handler is invoked if there is a Mount or Unmount of the SD card media.
State when the media is unmounted. The application remains in this state until a SYS_FS mount event occurs.
State where the application waits for the TCP/IP stack to be initialized.
State where the application checks for network changes and displays the new value on the console. In this state a user LED is toggled, serving as a heartbeat for the TCP/IP activity.
State when the media is mounted. The application retrieves the mounted drive for image files.
The state when the next image's header data is scanned to determine the image format type and set it to the SlideScreen screen.
The state handles the wait time between slides.
The state the application is in while in main menu, settings and the feature lists screens. The application also checks for network changes.