Skip to content

ViSi-Genie: Arduino Form Navigation

Introduction

This codebase example presents a working application that illustrates the handling of REPORT_EVENT messages coming from the display module. The display module can send a REPORT_EVENT message to the host every time that the status of an object on it has changed. Input objects such as the winbutton, DIP switch, rocker switch, etc, can be configured to send a REPORT_EVENT message when they are touched. Even forms can be configured to send a REPORT_EVENT message when they are activated. This code example presents an application that demonstrates the above.

Note

REPORT_EVENT vs REPORT_OBJ
A REPORT_EVENT message is sent by the display module to the host as triggered primarily by touch detected on an object on the screen. A REPORT_EVENT message is not requested by the host.
A REPORT_OBJ, on the other hand, is a message sent by the display module to the host in response to a query. For instance, if the host specifically wants to know the index of the active form, it sends a READ_OBJ message to the display module.
The display module then sends a REPORT_EVENT message in response to the READ_OBJ message. The list below can be used to differentiate between REPORT_EVENT and REPORT_OBJ messages.

REPORT_EVENT REPORT_OBJ
"not polled" "polled"
"not queried" "queried"
"not requested" "requested"

The above explains the difference between this codebase example and ViSi-Genie Arduino Form Request. ViSi-Genie Arduino Form Request basically illustrates the handling and use of REPORT_OBJ messages while this codebase example deals with REPORT_EVENT messages.

This codebase example has two parts - the Workshop4 ViSi-Genie project and the Arduino sketch which are can be found on the Attachement below.

Prerequisites

This codebase example assumes the reader can program the 4D Systems display module using Workshop4 IDE ViSi-Genie environment. Beginners are advised to read the following aplication notes.

Instructions

Below were the steps involved in creating this code example:

  1. Compile the ViSi-Genie Magic project and upload the program to a uLCD-32PTU or any 4D Systems displays with PICASO, DIABLO-16, PIXXI-28 and PIXXI-44 graphics processors. Copy the supporting files to a uSD card mounted to the PC. Properly unmount the uSD card from the PC and mount it to the target display.

    Below are the main objects of the project.

    1. Form0 - configured to send a REPORT_EVENT message using the object inspector.

      1. 4Dbutton0 - configured to send a REPORT_EVENT message using the object inspector
      2. Dipswitch0 - configured to send a REPORT_EVENT message using the object inspector
      3. Leddigits0 - for displaying the counter value
      4. Winbutto - for navigating to Form1
    2. Form1 - configured to send a REPORT_EVENT message using the object inspector

      1. Leddigits1 - for displaying the counter value
      2. Rockerswitch0 - configured to send a REPORT_EVENT message using the object inspector
      3. Slider0 - configured to send a REPORT_EVENT message using the object inspector
      4. Winbutton1 - for navigating to Form2
    3. Form2 - configured to send a REPORT_EVENT message using the object inspector

      1. 4Dbutton1 - configured to send a REPORT_EVENT message using the object inspector
      2. 4Dbutton2 - configured to send a REPORT_EVENT message using the object inspector
      3. Leddigits2 - for displaying the counter value
      4. Winbutton2 - for navigating to Form0
  2. Compile and upload the attached sketch to an Arduino Uno. The sketch uses a software serial port for the display. See the program flow summary further below.

  3. Properly connect the Arduino Uno to the target display. See the application notes ViSi-Genie: Connecting a 4D Display to an Arduino for this.

  4. A screenshot image file of the expected serial terminal output below.

    expected-output

If without an Arduino host, you can still run this code example by performing step 1. Then use the GTX tool to monitor the messages coming from the display module.

Below is the logic used in writing the Arduino sketch for this code example.

Process:
Step 1. Wait for REPORT_EVENT messages from the display.
Step 2. Keep writing the value of the counter to the LED digits object of the current form.
Step 3. If a new form has been activated, change the index of the LED digits object to which the counter value is to be written.
Step 4. If an object has changed its status, print its index and status. Back to Step 1.

setup:

    curFormIx = prevFormIx = 0; // assume that the current form index is zero initially
    counter = 0;    // increments at each iteration of the 500-ms loop

main loop:

    [B]DoEvents():[/B] this executes myGenieMagicHandler(...){...} and other internal processes
        if a REPORT_EVENT message for activation of a form is received
            get the index of the form and assign to curFormIx
            if(prevFormIx != curFormIx)            // check if a new form has been activated so we don't have  
                print the current form index    // to print the same form index every time
                prevFormIx = curFormIx
        else if a REPORT_EVENT message for the change in status of a 4D button is received
            print 4D button index and status
        else if a REPORT_EVENT message for the change in status of a slider is received
            print slider index and status
        else if a REPORT_EVENT message for the change in status of a rocker switch is received
            print rocker switch index and status
        else if a REPORT_EVENT message for the change in status of a DIP switch is received
            print DIP switch index and status


    [B]500-ms loop:[/B] this is the conditional block "if (millis() >= waitPeriod){...}" inside the main loop
        if curFormIx == 0            
            write the value of the counter to Leddigits0 (which we know is on Form0)
        else if curFormIx == 1
            write the value of the counter to Leddigits1 (which we know is on Form1)            
        else if curFormIx == 2
            write the value of the counter to Leddigits2 (which we know is on Form2)        
        counter++

back to main loop

Attachment

Project Files