Announcement

Collapse
No announcement yet.

4D-CD-00012 ViSi-Genie Magic Arduino File Size Request

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

  • 4D-CD-00012 ViSi-Genie Magic Arduino File Size Request

    This code example presents a working application that demonstrates how to perform a file size request operation. To understand this code example more quickly, please read the code examples:

    4D-CD-00009 Genie Magic - How to Read a File - Arduino
    4D-CD-00011 Genie Magic - How to Append to a File - Arduino

    This code example has two parts - the ViSi-Genie Magic project and the Arduino sketch. The ViSi-Genie Magic project "FileAccess" is found in Workshop 4 Pro (go to File -> Samples -> ViSi Genie Magic(Picaso/Diablo). FileAccess contains a working example of a Magic Object that handles and responds to file access instructions from a host. The Magic Object example can be edited and customised by users.

    The ViSi-Genie-Arduino library, on the other hand, has been updated to include a function for sending messages to a Magic Object. The library also has a function for responding to messages from a Magic Object.

    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.

    Note 1.A: Workshop 4 Pro is needed for this code example.

    Note 1.B: The file "data.log" also needs to be copied to the uSD card of the display module. This filename is hard coded in the attached sketch. Open the attached folder "uSD card file" and copy the content to the uSD card.

    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 send and receive messages to and from the display module.

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

    Process:
    Step 1. Send the first file size request command and print the size.
    Step 2. Do a file append.
    Step 3. Send the second file size request command and print the size (the file size should now be larger since bytes were appended to the file).

    Note 1: The first command sent to the display is a file size request command, and it is assumed that the first file size reply received is a reply to the first command sent.
    Note 2: This process will run once only at the start.

    setup:
    Code:
        firstSizeDoneFlag = false; //if this flag is set, print a success message for the first file size request in the 50-ms loop
        appendDoneFlag = false; //if this flag is set, print success message for file append in the 50-ms loop
        secondSizeDoneFlag = false; //if this flag is set, print a success message for the second file size request in the 50-ms loop
        processDoneFlag = false; //flag to indicate if the process is ended
    
        send the first file size request command
    main loop:
    Code:
        DoEvents(): this executes myGenieMagicHandler(...){...} and other internal processes
            if reply to first file size request command is received && processDoneFlag == false
                firstSizeDoneFlag = true
            else if reply to file append command is received && processDoneFlag == false
                appendDoneFlag = true
            else if reply to second file size request command is received && processDoneFlag == false
                secondSizeDoneFlag = true
            
            
        50-ms loop: this is the conditional block "if (millis() > lastRun){...}" inside the main loop
            if firstSizeDoneFlag == true
                print success message for first file size request
                send file append command
                firstSizeDoneFlag = false (to make this case run once only)
                
            else if appendDoneFlag == true
                print success message for file append
                send second file size request command    
                appendDoneFlag = false (to make this case run once only)
                
            else if secondSizeDoneFlag == true
                print success message for second file size request
                print "process ended"
                secondSizeDoneFlag = false (to make this case run once only)
                processDoneFlag = true (to make the whole process run once only)
    
    back to main loop
    Screenshot image of the expected serial terminal output:

    Click image for larger version

Name:	image_613.png
Views:	31
Size:	50.6 KB
ID:	44214
    Doff
Working...
X