Announcement

Collapse
No announcement yet.

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

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

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

    This code example presents a working application for demonstrating how to perform a file append operation. To understand this code example more quickly, please see first the code example:

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

    This code example has two parts - the ViSi-Genie Magic project and the Arduino sketch. The attached ViSi-Genie Magic project is a modified version of the example project "FileAccess" 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 attached 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: The difference between the attached ViSi-Genie Magic project and the FileAccess example in Workshop 4 Pro is the inclusion of delays into the Magic Object code of the latter. Please see the image files "GenieMagicObjectCodeInsertedDelay_1.png" and "GenieMagicObjectCodeInsertedDelay_2.png" inside the attached folder "images". Users are free to customise further the code for MagicObject0 to suit their application.

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

    Note 1.C: The file "data.log" 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. Screenshot image files of the expected serial terminal output are inside the attached folder "images".
    expectedOutputSteps1and2.png
    expectedOutputStep3.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. Do a file read and print the data.
    Step 2. Do a file append.
    Step 3. Do a second file read and print the data (to prove that step 2 was successful).

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

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

  • #2
    Screenshot images of the expected serial terminal output:

    Click image for larger version

Name:	expectedOutputSteps1and2.png
Views:	52
Size:	56.5 KB
ID:	44224

    Click image for larger version

Name:	expectedOutputStep3.png
Views:	52
Size:	55.4 KB
ID:	44226



    Attached Files
    Doff

    Comment

    Working...
    X