Web Photo Frame Tutorial: Step 8

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.

Application States

  • 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_states.png

Application Data Structure

  • The global application data structure is defined as shown in this graphic:
application_datastructure.png

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 directory 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 Slideshow.
  • currentTouchBehavior: Tracks 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.

APP_Initialize

  • Allows the application to initialize various tasks and application-related data.

APP_Tasks

  • Implements the application state machine. It is called periodically from the SYS_Tasks function. These states are described in the following section.

1

APP_STATE_INIT:

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.

2

APP_STATE_MEDIA_UNMOUNTED:

State when the media is unmounted. The application remains in this state until a SYS_FS mount event occurs.

3

APP_TCPIP_WAIT_INIT:

State where the application waits for the TCP/IP Stack to be initialized.

4

APP_TCPIP_TRANSACT:

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.

5

APP_STATE_MEDIA_MOUNTED:

State when the media is mounted. The application retrieves the mounted drive for image files.

6

APP_STATE_DRAW_NEXT_SLIDE:

State when the next image's header data is scanned to determine the image format type and set it to the SlideScreen screen.

7

APP_STATE_WAIT_BETWEEN_SLIDE:

The state handles the wait time between slides.

8

APP_STATE_IDLE:

The state the application is in while in main menu, settings, and the feature lists screens. The application also checks for network changes.



Next Step >

© 2020 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.