ViSi-Genie Magic: Arduino File Size Request
Introduction
This codebase 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:
This codebase example has two parts - the ViSi-Genie Magic project and the Arduino sketch. The ViSi-Genie Magic project "FileAccess" is found in Workshop4 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.
Note
Worskhop 4 PRO is needed for this codebase example.
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.
- ViSi-Genie: Getting Started with PICASO Displays
- ViSi-Genie: Getting Started with DIABLO-16 Displays
- ViSi-Genie: Getting Started with PIXXI Displays
- ViSi-Genie: Connecting a 4D Display to an Arduino
Instructions
Below were the steps involved in creating this code example:
-
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.
Note
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.
-
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.
-
Properly connect the Arduino Uno to the target dispplay. See the application notes ViSi-Genie: Connecting a 4D Display to an Arduino for this.
-
A screenshot image file of the expected serial terminal output is shown below.
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
- 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.
- This process will run once only at the start.
setup:
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:
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