Announcement

Collapse
No announcement yet.

Need help displaying text from uSD card.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Need help displaying text from uSD card.

    Greetings Earthlings!

    My name is Steve, and I'm fresh meat here on the forum.
    A few weeks ago a uLCD-320-PMD2 sort of "fell into" my shopping cart while I was buying other parts...
    I've been recently playing with it and I've mostly of got the hang of controlling it and displaying images and text with a PIC16F727. (Using PICBASIC Pro) That much has worked out pretty well.

    Now I'm trying to get a grasp on 4DGL...

    I've got my uLCD-320 hooked up to a USB port with a genuine uUSB-MB5 converter. I've successfully loaded " uLCD-320-PMD2-4DGL-rev1_07.PmmC " into my device.
    I've got a 2GB uSD card that windoze formatted for FAT16 (not FAT32) and it's loaded with a couple dozen photos that were loaded with Graphics Composer. I've also loaded several short TEXT(.txt) files to the card, prepared with notepad and loaded from windows.

    I can mount the drive and I can view all the file names with file_Dir("*.*");

    I can successfully view a slide show of the photos on the card.

    What I'm having a devil of a time with is displaying the TEXT files from the card! I can call up a text file and "display" it, but it's total gibberish. It displays a long string that's full of ????? and random characters. File_Error(); returns a 0, so I assume it thinks it's found the file OK. The files are .txt files that have a short description that's maybe 20 to 70 characters long. Each text file was saved in notepad to the uSD card and I'd hoped to bring up and display one text file at a time under each photo. It seems like it sort of wants to work, but it just displays gibberish instead of my text file. I'm sure I've done something wrong or got the formatting screwy or something.


    Here's my first bit of 4DGL test code... most of it is swiped from one of the "sample" projects. I've added my own little bit to try and get the text on screen.
    This displays a few dozen photos, one at a time, and it's SUPPOSED to put a line of text from a file under each photo. This "test" only displays the same text file under all photos. Once I can get that much working then I can move on...

    If someone could look at this bit of code and gently point me in the right direction to get real text on to the display, I'd be ever so grateful.....

    Code:
    #platform "uLCD-320-PMD2"/*  Test File to pull up photos and text from a uSD card,display them as a slide show, with the text descriptionunder each photo.*/#inherit "4DGL_16bitColours.fnc"var p;                          // buffer pointervar j,n;var description;                 //text descriptionsfunc main()if(!file_Mount())print("Cannot mount uSD card");repeat foreverendifprint("uSD mounted\n");pause (2000);file_Dir("*.*");    // print directory to screenpause (2000);gfx_Cls();txt_Set(FONT_SIZE, FONT2);txt_Set(TEXT_OPACITY, OPAQUE);print("heap=", mem_Heap(), " bytes\n");         // show the heap sizeif (!file_Mount())print("File error ", file_Error());repeat foreverendifprint ("WAIT...building image list\n");j := file_LoadImageControl("PHOTOASST_.dat", "PHOTOASST_.gci", 1);  // build the image control, returning a pointer to the structure allocationif (j)print("image control=",[HEX] j,"\n");  // show the address of the image control allocationelseputstr("Failed to build image control....\n");repeat forever  // wait until hell freezes over if no listendifpause(2000);gfx_Cls();repeatn := 0;while(n < j[img] )img_SetPosition( j, n, 0, 30);  // set image locationimg_Show(j, n);n++;txt_MoveCursor(34, 1);description:= file_Open("204.TXT",'r');  //open the test text file.... please...print([STR] description);file_Close(description);pause(5000);gfx_Cls();pause(1000)wendforeverendfunc

    Thanks ever so much for any enlightenment you can provide ,

    steve


  • #2


    Just a quick guess, but I think file_Open() gives you handle to the file, not the content. You'll have to use file_read() for reading the strings from the file.

    Comment


    • #3


      THANK YOU rautenberg!
      Yes, of course I need to READ the file after I open it.
      I new it was something simple and obvious, but I just couldn't quite get there from here.
      You've saved my keyboard from being beaten to a pulp with my forehead. It works great now. THANKS!

      steve

      Comment

      Working...
      X