Announcement

Collapse
No announcement yet.

4D-CD-00013 Genie - Form Navigation - Arduino

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 4D-CD-00013 Genie - Form Navigation - Arduino

    This code 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 code example and Genie - Form Request - Arduino. Genie - Form Request - Arduino basically illustrates the handling and use of REPORT_OBJ messages while this code example deals with REPORT_EVENT messages.

    This code example has two parts - the ViSi-Genie project and the Arduino sketch. The ViSi-Genie project is found in the attached folder "Genie Project". The sketch is found in the attached folder "Arduino Sketch".

    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. 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 uLCD-32PTU. Below are the main objects of the project.

    Form0 - configured to send a REPORT_EVENT message using the object inspector
    4Dbutton0 - configured to send a REPORT_EVENT message using the object inspector
    Dipswitch0 - configured to send a REPORT_EVENT message using the object inspector
    Leddigits0 - for displaying the counter value
    Winbutton0 - for navigating to Form1

    Form1 - configured to send a REPORT_EVENT message using the object inspector
    Leddigits1 - for displaying the counter value
    Rockerswitch0 - configured to send a REPORT_EVENT message using the object inspector
    Slider0 - configured to send a REPORT_EVENT message using the object inspector
    Winbutton1 - for navigating to Form2

    Form2 - configured to send a REPORT_EVENT message using the object inspector
    4Dbutton1 - configured to send a REPORT_EVENT message using the object inspector
    4Dbutton2 - configured to send a REPORT_EVENT message using the object inspector
    Leddigits2 - for displaying the counter value
    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 uLCD-32PTU. See the application notes for this.

    4. A screenshot image file of the expected serial terminal output is inside the attached folder "images".
    expectedOutput.png


    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:
    Code:
        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:
    Code:
        DoEvents(): 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
            
            
        500-ms loop: 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
    Attached Files
    Doff

  • #2
    Screenshot images of the expected serial terminal output (Arduino IDE) and the forms of the ViSi-Genie project:

    Click image for larger version

Name:	expectedOutput.png
Views:	112
Size:	31.7 KB
ID:	44231

    Click image for larger version

Name:	Form0.png
Views:	95
Size:	6.8 KB
ID:	44228

    Click image for larger version

Name:	Form1.png
Views:	97
Size:	5.7 KB
ID:	44229

    Click image for larger version

Name:	Form2.png
Views:	99
Size:	9.7 KB
ID:	44230
    Doff

    Comment

    Working...
    X