Announcement

Collapse
No announcement yet.

uVGA 640x480 Page Flipping, Timer Issue, and Rectangle Bug

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

  • uVGA 640x480 Page Flipping, Timer Issue, and Rectangle Bug

    I am using the most recent uVGA firmware (version 26). I am using Workshop 3.1.014. I have a few issues with my simple program and I would like to resolve them before adding more functionality. The hardware is currently at school in our research lab, so I won't be able to test any suggestions until next semester starts in January. I have worked around these issues for now and have the project running very rudimentary, but I would like to understand what I'm doing incorrectly- be it a silly mistake, incorrect context, etc. I have listed the issues in order of importance, so if we could deal with them in this order that would be thoroughly helpful. Thanks for taking your time to assist.

    1) Page flipping doesn't appear to work in my code for 640x480 on the uVGA. I realize that there isn't enough memory for 2 full pages from other posts. So I have assumed that it will over-lap display memory. My code draws in the center of the screen, so I should avoid any artifacts connected with the memory overlap. When sent a ":I3" command on COM0, my code draws the first rectangle and displays it properly, but I don't get anything on the second page- it's completely blank. Am I calling something incorrectly or is page flipping not possible and non-functional in this resolution? I couldn't find any example code that specifically dealt with the proper way to do page flipping (unless I missed it in the sample code, the forums, and the online code examples...which is entirely possible).

    2) I have the page flipping being done by on a timer routine while I check for other serial image change requests on COM0. What is the proper method to stop a timer routine? My program does not appear to stop the timer function correctly by it's behavior. It clears the screen when a new command image is received, the requested image briefly shows, and then it disappears like the timer is still trying to change the screen still.

    3) It appears that if there are math functions in the first two arguments of the rectangle command- the command doesn't draw anything. Math functions work in the circle command, but not in the rectangle. Even adding spaces between the math functions didn't make it work. However, I worked around this issue with some more constants (which is how I have my full code in the larger snippet at the end). The original snippet that wasn't working was similar to the following:

    var x1 250
    var y1 170
    var size 140
    var radius 50
    var corr1 80
    var corr2 10

    func main()

    gfx_Cls();
    gfx_Rectangle(x1+(corr1/2),y1+(corr1/2),x1+size-(corr1*4),y1+size-(corr1*4),RED);
    gfx_CircleFilled(x1+(size/2),y1+(size/2),radius-(corr2*frame),BLUE);

    endfunc

    -----------------------------
    The full code for issues #1 and #2 follows:

    #platform "uVGA-II_GFX2"
    #inherit "4DGL_16bitColours.fnc"

    #MODE RUNFLASH // execute the as top level prog, leaving memory available for overlays etc

    #constant AUDIO_ENABLED // comment out for no audio
    #STACK 800 // make sure stack is big enough for main prog and called functions/programs

    //global variables
    var D; // disk
    var *hFile; // handle for image control
    var combuf[2]; //com0 buffer
    var frame := 0; // start with frame 0
    var stopflag :=0; // flag to stop animation
    var animationrunning :=0; //flag to tell if animation is running

    #constant size 140
    #constant size2 size/2
    #constant x1 250
    #constant y1 170
    #constant x2 x1+size
    #constant y2 y1+size

    #constant corrr 40

    #constant x3 x1+(corrr/2)
    #constant y3 y1+(corrr/2)
    #constant x4 x2+size-(corrr*4)
    #constant y4 y2+size-(corrr*4)

    #constant radius 50
    #constant corrc 10
    #constant radius2 radius-corrc

    #constant updatespeed 80
    //#constant updatespeed 6000

    // TIMER2 event
    func animation()

    if (frame == 0)
    gfx_Set(DISPLAY_PAGE, 0);
    //gfx_Set(READ_PAGE, 0);
    //gfx_Set(WRITE_PAGE, 0);

    frame := 1;
    else
    gfx_Set(DISPLAY_PAGE, 0);
    //gfx_Set(READ_PAGE, 1);
    //gfx_Set(WRITE_PAGE, 1);

    frame := 0;
    endif

    if (stopflag == 0)
    //start timer again to retrigger next subroutine call
    sys_SetTimer(TIMER2,updatespeed); // reset the event timer
    else
    //clear flag and don't set next timer call
    stopflag :=0;

    gfx_Set(DISPLAY_PAGE, 0);
    gfx_Set(READ_PAGE, 0);
    gfx_Set(WRITE_PAGE, 0);

    endif

    endfunc

    func main()
    var private i := 0;

    var n,ch; //local variables
    var bufptr;

    bufptr := str_Ptr(combuf);

    // Clear screen and set landscape mode
    gfx_Set(SCREEN_RES, 1); //0 for 320x240, 1 for 640x480, 2 for 800x480
    gfx_ScreenMode(LANDSCAPE); // rotate to landscape mode
    gfx_Cls();

    //print("heap now=",mem_Heap()," bytes\n"); // show the heap sizeafter image control load
    //gfx_MoveTo(0, 0);

    txt_Set(FONT_SIZE, FONT1);
    putstr("Mounting SD Card...");
    pause(500);
    if (!(D:=file_Mount()))
    while(!(D:=file_Mount()))
    putstr("SD Card Not Present- Insert Card.");
    pause(1000);
    gfx_Cls();
    wend
    endif
    putstr("SD Card Mounted.\n");
    pause(1000);

    gfx_Cls(); //Clear away boot text

    //Initialize both COM ports to 9600 baud
    com_SetBaud(COM0, 960);
    com_SetBaud(COM1, 960);

    //Load image files & build table
    hFile := file_LoadImageControl("3D.dat", "3D.gci",0);

    com_Reset();
    com_Init(combuf, 2, ':' ); // set up a comms buffer, requires ':' lead in character

    repeat
    //---
    if (com_Sync() && com_Full()) // if we have a sync byte of ":" and the buffer is full, then we may have received a valid change image command from uLCD
    switch
    case(str_Match(&bufptr, "I0"))
    //get rid of animation if running
    if (animationrunning == 1)
    stopflag :=1;

    //Trigger event early to stop it!
    sys_SetTimer(TIMER2,1);

    endif

    //display image 0 (red cube) from SD card file
    img_SetPosition(hFile, 0, 0, 0);
    img_Show(hFile,0);
    img_Enable(hFile, 0);

    //Reset COM0 and restart buffer
    com_Reset();
    com_Init(combuf, 2, ':' );
    bufptr := str_Ptr(combuf);
    break;
    case(str_Match(&bufptr, "I1"))
    //get rid of animation if running
    if (animationrunning == 1)
    stopflag :=1;

    //Trigger event early to stop it!
    sys_SetTimer(TIMER2,1);

    endif

    //display image 1 (red cube with blue cylinder) from SD card file
    img_SetPosition(hFile, 1, 0, 0);
    img_Show(hFile,1);
    img_Enable(hFile, 1);

    //Reset COM0 and restart buffer
    com_Reset();
    com_Init(combuf, 2, ':' );
    bufptr := str_Ptr(combuf);
    break;
    case(str_Match(&bufptr, "I2"))
    //get rid of animation if running
    if (animationrunning == 1)
    stopflag :=1;

    //Trigger event early to stop it!
    sys_SetTimer(TIMER2,1);

    endif

    //display image 2 (red cube with black hole) from SD card file
    img_SetPosition(hFile, 2, 0, 0);
    img_Show(hFile,2);
    img_Enable(hFile, 2);

    //Reset COM0 and restart buffer
    com_Reset();
    com_Init(combuf, 2, ':' );
    bufptr := str_Ptr(combuf);
    break;
    case(str_Match(&bufptr, "I3"))
    //keep track- animation is running will need to be stopped
    animationrunning :=1;

    //Reset COM0 and restart buffer
    com_Reset();
    com_Init(combuf, 2, ':' );
    bufptr := str_Ptr(combuf);

    //Clear screen
    gfx_Cls();

    //display requested animation

    //draw page 0
    //gfx_Set(DISPLAY_PAGE, 0);
    gfx_Set(READ_PAGE, 0);
    gfx_Set(WRITE_PAGE, 0);

    gfx_Cls();
    gfx_Rectangle(x1,y1,x2,y2,RED);
    gfx_CircleFilled(x1+size2,y1+size2,radius,BLUE);

    //draw page 1
    //gfx_Set(DISPLAY_PAGE, 1);
    gfx_Set(READ_PAGE, 0);
    gfx_Set(WRITE_PAGE, 0);

    //gfx_Cls();
    gfx_Rectangle(x3,y3,x4,y4,GREEN);
    gfx_CircleFilled(x1 + size2,y1 + size2,radius2,RED);

    //Set-up timer event
    sys_SetTimerEvent(TIMER2,animation);

    //Trigger event
    sys_SetTimer(TIMER2,1);

    break;
    default:
    // received garbage or non-recognized command- reset buffer & try again

    //Reset COM0 and restart buffer
    com_Reset();
    com_Init(combuf, 2, ':' );
    bufptr := str_Ptr(combuf);
    endswitch
    endif

    //---



    forever

    //Disable File
    img_Disable(hFile, 0);
    gfx_Cls();

    //Unmount SD Card
    file_Unmount();


    endfunc


    Elario
Working...
X