Announcement

Collapse
No announcement yet.

Parents, kids and grandfathers....

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

  • Parents, kids and grandfathers....

    Hello team 4D,

    For once more I need your help. Up until now I had a let's say bootloader written to the flash, who was calling my main program using file_Run. The reason for that was so that if I need to change the program later on I wont have to run to the factories across the globe with a programming cable, just copy paste the files to the sd card. That was working like a charm up until the point when memory started to become an issue (or the lack of it). The only solution in my mind is to break down my program in to smaller ones that I will be calling from a main one, do what they are supposed to do and then unload from the memory. I have read the examples r_runprogram and r_insane (I will need to pass variables from the main to the "child" and when the child is done it will return something back to the main) and tried to use it. But... it's not working. LCD restarts, the variables are not passed and all sorts of problems. The examples are talking about writing the program R_runprogram to the flash and then it will be calling the kids. But like I mentioned earlier my main program is not actually the main program. It's actually a child as well. The "bootloader" is the real main. Is it worth it to post my code here or it simply cannot be done? Only a main program can call other child programs? I really hope I am making sense.

    Thanks,

    Dimitris

  • #2
    You can cascade as many sub programs as you like, provided you have memory.

    Ensure that you have the parms set up correctly, i.e. parms are an array with element 0 being the count of parms following.

    If you are still having issues make yourself a small example and post it here.
    Mark

    Comment


    • #3
      Hello Mark and thanks for the reply. You should have heard the sound the head slap did when I read
      parms are an array with element 0 being the count of parms following
      . Anyway we are on to something now since I am able to pass a number to form2, form2 changes that number and returns it to form1. I am able to display that new number but then Black screen. I know it has to do with the goto redo: I am not sure what I am supposed to "redo" since simply redrawing form1 doesn't do the trick. I have tried moving redo: at various points but the result is either a black screen or the restart of the screen. Another question that I have is how do I pass more than 1 variables.
      Ok I guess
      params[0]:=2;
      params[1]:=244;
      params[2]:=550;

      but what am I supposed to expect at form2 and ofc how can I return those 2 variables back and use them on form1.
      Here is what I am trying to do:

      BootLoader:
      Code:
      #platform "uLCD-32PTU"
      
      #inherit "4DGL_16bitColours.fnc"
      #MODE RUNFLASH
      #STACK 1000
      func main()
      
          gfx_ScreenMode(LANDSCAPE) ; // change manually if orientation change
      
          print("Rational Labelling. BootLoader v1.4") ;      // replace with your code
          pause(1000);
          gfx_Cls();
      
          putstr("Mounting...\n");
          if (!(file_Mount()))
              while(!(file_Mount()))
                  putstr("Drive not mounted...");
                  pause(500);
                  gfx_Cls();
                  pause(500);
              wend
          endif
          if (!(file_Exists("form1.4XE")))
              while(!(file_Exists("form1.4XE")))
                  putstr("form1.4XE does not exist...");
                  pause(500);
                  gfx_Cls();
                  pause(500);
              wend
          endif
          file_Run("form1.4XE", 0);
      
      endfunc
      form1
      Code:
      #platform "uLCD-32PTU"
      #inherit "4DGL_16bitColours.fnc"
      #inherit "VisualConst.inc"
      #inherit "form1Const.inc"
      #inherit "stringFuncs.inc"
      #inherit "serialFuncs.inc"
      #inherit "timerFuncs.inc"
      
      #STACK 300
      
      var arialBold80,dynamicDate1[5], dynamicDate2[5],trace[5],dynamicDateTemp1[5], dynamicDateTemp2[5],prevErrorValue;
      var printerOnError :=0;
      var degrees,x,y,posit,state,n,buttonValue1, buttonValue2,buttonValue3,knobValue, printValue;
      degrees := 0;
      var com1buf[200];
      var raspiTimeOut := 10000;
      var allowSerial := 1;
      var char;
      var activeForm:=1;
      var triggerSelectValue :=1;
      var openPackDetectorValue :=1;
      var trackBarBufferCommand[10];
      var motorPauseMask;
      var screenTimeout :=60000;
      var returned :=0;
      var notDate:=1;
      #CONST
          LCDW 320
          LCDH 240
          Version "Version 3.0.0.3.1\0"
      #END
      
      
      func main()
      redo:
      var params[8];
      params[0] := 1;
      params[1] := 244;
      var returnedValue;
      
          gfx_Set(SCREEN_MODE,LANDSCAPE) ;
          gfx_Cls();
          txt_Set(FONT_ID, FONT2);
          txt_Set(TEXT_WIDTH, 1);
          txt_Set(TEXT_HEIGHT, 1);
          print (mem_Heap(), " bytes free" );
          pause(1000);
          putstr("Mounting...\n");
          if (!(file_Mount()))
              while(!(file_Mount()))
                  putstr("Drive not mounted...");
                  pause(500);
                  gfx_Cls();
                  pause(500);
              wend
          endif
      
          hndl := file_LoadImageControl("form1.dat", "form1.gci", 1);
          arialBold80 := file_LoadImageControl("form1.da1", "form1.gc1", 1);
          gfx_Cls();
          snd_Volume(0);
          setbaud(BAUD_115200);
          com_Init(com1buf, 100, 0 );
          touch_Set(TOUCH_ENABLE);                            // enable the touch screen
          buttonValue1 := 0;
          buttonValue2 := 0;
          sys_SetTimerEvent(TIMER1,timer1Func);
          sys_SetTimerEvent(TIMER2,timer2Func);
          sys_SetTimerEvent(TIMER3,timer3Func);
          sys_SetTimerEvent(TIMER4,timer4Func);
          sys_SetTimerEvent(TIMER5,timer5Func);
          sys_SetTimerEvent(TIMER6,timer6Func);
          sys_SetTimerEvent(TIMER7,timer7Func);
          sys_SetTimerEvent(TIMER0,timer0Func);
          //sys_SetTimer(TIMER7,raspiTimeOut);
      
      
              var p;
              p := str_Ptr(tempBuff) ;
      
              drawMainForm();
      
              repeat
              /*
                  char := serin();
                  if (allowSerial == 1)
                      if (char > 3)
                          str_PutByte(p, char);                                      // put in string
                          p++ ;                                                   // reposition pointer
                      endif
                      if (char == 3)                                              // if end of transmission
                          str_PutByte(p, 0);                                      // terminate string
                          p := str_Ptr(tempBuff) ;                                   // point back to start
                          handleSerialCommand(tempBuff);
                          sys_SetTimer(TIMER4,50);
                      endif
      
                  endif
                */
                  state := touch_Get(TOUCH_STATUS);               // get touchscreen status
                  if (state != 0)
                      screenSaverStop :=1;
                      n := img_Touched(hndl,-1) ;
                      x := touch_Get(TOUCH_GETX);
                      y := touch_Get(TOUCH_GETY);
                      if(state == TOUCH_RELEASED)                      // if there's a release
                          if (printerOnError != 1)
                          /*
                              if (x>= 50 && y >= 60 && y <= 115)
                                  drawChangeDateForm("BEST BEFORE", dynamicDate1,5);
                                  //pause(2000);
                                  //drawMainForm();
                                  notDate:=0;
                              endif
                              if (x>= 50 && y >= 130 && y <= 190)
                                  drawChangeDateForm("DISPLAY UNTIL", dynamicDate2,6);
                                  //pause(2000);
                                  //drawMainForm();
                                  notDate:=0;
                              endif */
                              if (notDate)
                                  returnedValue:=file_Run("form2.4FN", params);
                                  gfx_Cls();
                                  txt_Set(FONT_ID, FONT2);
                                  txt_Set(TEXT_WIDTH, 1);
                                  txt_Set(TEXT_HEIGHT, 1);
                                  print (mem_Heap(), " bytes free" );
                                  txt_MoveCursor(1,1);
                                  print (" Returned: ",[DEC5]returnedValue);
                                  pause(1000);
                                  drawMainForm();
                              endif
      
                          endif //if (activeForm==1 )
                      endif //end touchReleased
                  endif
              forever
          return 1;
      endfunc
      
      
      
      
      func drawIntro()
      lcdString(1,2, 1, 1, WHITE,2,Version,"     ",1);
      var frame:=0;
          for (frame:=0; frame<148; frame++)
              img_SetWord(hndl, iVideo1, IMAGE_INDEX, frame) ; // where frame is 0 to 148
              img_Show(hndl,iVideo1) ;
              frame++;// FrameSkipping
              frame++;// FrameSkipping
          next
      
          return 1;
      
      endfunc
      
      func drawMainForm()
          gfx_Cls();
          disTouch();
          gfx_RectangleFilled(50, 70, 310, 130, BLACK);
          gfx_RectangleFilled(50, 140, 310, 200, BLACK);
          date1(" BEST","BEFORE",dynamicDate1);
          date2("DISPLAY"," UNTIL",dynamicDate2);
          //date3("Retraceability",trace);
          drawHeadStatusButton(motorPauseMask);
          to(COM0); print("CDF0");serout(10);
          //sys_SetTimer(TIMER7,raspiTimeOut);
          emptyBuffer(str_Ptr(errorLine1), 40);
          if((intRLVmask&4)>0)
              to(errorLine1);putstr("                         \0");
          else
              to(errorLine1);putstr("No TCP with OP13!!!\0");
          endif
          //if (screenSaverStop !=1)
          drawErrorFrame(printerOnError);
          screenSaverStop :=0;
          to(COM0); print("REFRESH");serout(10);
          screenTimeout :=60000;
          sys_SetTimer(TIMER6,30000); //Enable Screen saver
          sys_SetTimer(TIMER3,0);
      
          return 1;
      endfunc
      
      
      
      func disTouch()
          sys_SetTimer(TIMER4,10);
           sys_SetTimer(TIMER6,0);
          var itemEnum;
          itemEnum := 1;
          repeat
              if (!img_SetAttributes(hndl, itemEnum, I_TOUCH_DISABLE)) break;
              itemEnum := itemEnum + 1;
          forever
      
          return 1;
      endfunc
      
      
      func drawErrorFrame(var value)
      
       // Userbutton3 1.0 generated 29/04/2016 15:03:52
          img_SetAttributes(hndl, iUserbutton3, I_TOUCH_DISABLE);
          //sys_SetTimer(TIMER0,0);
          if (value ==1)
              img_ClearAttributes(hndl, iUserbutton3, I_TOUCH_DISABLE); // set to enable touch, only need to do this once
              //sys_SetTimer(TIMER0,1000);
              img_SetWord(hndl, iUserbutton3, IMAGE_INDEX, value); // where state is 0 for up and 1 for down, or 2 total states
              gfx_Set(TRANSPARENCY, ON);
              gfx_Set(TRANSPARENT_COLOUR, BLACK);
              img_Show(hndl,iUserbutton3) ;
              gfx_Set(TRANSPARENCY, OFF);
              prevErrorValue := printerOnError;
      
          endif
          if (prevErrorValue != printerOnError)
               prevErrorValue := printerOnError;
               gfx_Cls();
               drawMainForm();
          endif
      
          return 1;
      
      endfunc
      
      func drawHeadStatusButton(var value)
          img_SetWord(hndl, iheadStatusButton, IMAGE_INDEX, value); // where state is 0 for up and 1 for down, or 8 total states
          img_Show(hndl,iheadStatusButton) ;
          return 1;
      endfunc
      
      func handleTouch()
      
      
      
      
      return 1;
      endfunc
      form2
      Code:
      #platform "uLCD-32PTU"
      #inherit "4DGL_16bitColours.fnc"
      #inherit "VisualConst.inc"
      #inherit "form2Const.inc"
      
      func main(var myParams)
          if (!(file_Mount()))
              while(!(file_Mount()))
                  putstr("Drive not mounted...");
                  pause(200);
                  gfx_Cls();
                  pause(200);
              wend
          endif
          hndl := file_LoadImageControl("form2.dat", "form2.gci", 1);
          gfx_Set(SCREEN_MODE,LANDSCAPE) ;
          gfx_Cls();
          txt_Set(FONT_ID, FONT2);
          txt_Set(TEXT_WIDTH, 1);
          txt_Set(TEXT_HEIGHT, 1);
          img_ClearAttributes(hndl, iWinbutton1, I_TOUCH_DISABLE); // set to enable touch, only need to do this once
          img_SetWord(hndl, iWinbutton1, IMAGE_INDEX, 1); // where state is 0 for up and 1 for down
          img_Show(hndl,iWinbutton1) ;
          gfx_MoveTo(100,150);
          print (" Receieved: ",[DEC5]myParams);
          pause(2000);
          myParams := 255;
          return myParams;
      
      endfunc
      For once more thanks for all the help

      Comment


      • #4
        So, as you probably know, return can only return a single value, and passed parms do not get altered.

        To be able to alter, or return more than one value you need to pass an address of the variable, or the address of an array, something like this.

        Code:
            var parms[2] ;
            var results[2] ;
            parms[0] := 1 ;
            parms[2] := results ; // will put address of results into parms[2]
        Then your called main becomes
        Code:
        func main(var *parms)
            print(parms[0], " ", parms[1]) ; // will print results[0] and results[1], maybe parms should be called results here to make it 'obvious')
            parms[0] := 12345 ; // set results[0]
            parms[1] := 0xfedb ; // rests results[1]
        Mark

        Comment


        • #5
          Mark to the rescue.
          Thanks a lot. It really makes sense now.
          Any memory allocations in the main FLASH program are released, however, the stack and
          globals are maintained.
          So yes I should have seen that, I don't actually need to return something just play with the global variables.

          ... However I still have problems with the lcd restarting . I am certain that it has to do with the calling of functions. I did put some debug messages in my program and I see that the program hangs at different places based on where the functions are. If they are all in form1 then it crashes the moment I return from form2. If all the functions are in a fnc file that I inherit then it crashes after the "putstr("Mounting...\n");". If I have some!!!! of the functions in the fnc file then it crashes a bit further down......
          This combined with this:
          30th June 2012, 03:31 AM

          Alright, I must be blind... turns out I was hooking a function in my called program to a timer then shooting it off AFTER I was back to my calling program. Apparently the system has problems calling functions that don't exist anymore Should be smooth sailing now.
          makes me think that func is not the way but gosub and gotos... am I thinking correct?

          I attached my files if you want to have a look. The bootloader is the same as the one I quoted 2 posts up. Again I can't thank you enough for all the help.
          Attached Files

          Comment


          • #6
            Funcs are the way to go, but if you set up a timer func or the like you need to 'turn it off' before you return from the 'function/program' it is in or else 'anything can happen'.

            Could you be setting a font to a program or uSD font and then returning from the function that set the font? You need to reset the font before returning as well.
            Mark

            Comment


            • #7
              Heh I am actually doing both. When you say reset the font you mean?
              arialBold80 := file_LoadImageControl("form1.da1", "form1.gc1", 1);

              Comment


              • #8
                Well, obviously you have
                Code:
                txt_FontID(arialBold80) ;
                Somewhere, so you need to
                Code:
                txt_FontID(FONT3) ;
                to reset it to an internal font before that imagecontrol becomes invalid (eg returning from the function that has the variable arialBold80 in it)
                You should also mem_Free the the variable to recover the storage used in the handle.
                Have you been using mem_Heap() to check up on memory?
                Mark

                Comment


                • #9
                  Ok now I am completely stuck. Instead of getting it better it's getting worst.
                  Here are my stripped down programs...
                  bootLoader written in FLASH
                  Code:
                  #platform "uLCD-32PTU"
                  
                  #inherit "4DGL_16bitColours.fnc"
                  #MODE RUNFLASH
                  #STACK 1000
                  func main()
                                                                 
                      gfx_ScreenMode(LANDSCAPE) ; // change manually if orientation change
                  
                      print("Rational Labelling. BootLoader v1.4") ;      // replace with your code
                      pause(1000);
                      gfx_Cls();
                  
                      putstr("Mounting...\n");
                      if (!(file_Mount()))
                          while(!(file_Mount()))
                              putstr("Drive not mounted...");
                              pause(500);
                              gfx_Cls();
                              pause(500);
                          wend
                      endif
                      if (!(file_Exists("form1.4XE")))
                          while(!(file_Exists("form1.4XE")))
                              putstr("form1.4XE does not exist...");
                              pause(500);
                              gfx_Cls();
                              pause(500);
                          wend
                      endif
                      file_Run("form1.4XE", 0);
                  
                  endfunc
                  form1
                  Code:
                  #platform "uLCD-32PTU"
                  #inherit "4DGL_16bitColours.fnc"
                  #inherit "VisualConst.inc"
                  #inherit "form1Const.inc"
                  
                  #STACK 600
                  
                  var params[2];
                  var results[2];
                  
                  func main()
                  params[0] := 1;
                  params[1] := results;
                  results[0]:=300;
                  results[1]:=400;
                  redo:
                      gfx_Set(SCREEN_MODE,LANDSCAPE) ;
                      gfx_Cls();
                      //debug("1");
                      pause(1000);
                      if (!(file_Mount()))
                          while(!(file_Mount()))
                              gfx_Cls();
                              putstr("Drive not mounted...");
                              pause(500);
                          wend
                      endif
                      //debug("2");
                      hndl := file_LoadImageControl("form1.dat", "form1.gci", 1);
                      touch_Set(TOUCH_ENABLE);
                      var state,n,x,y,returnedValue;
                      //debug("3");
                      print ("Just before the repeat");
                      pause(300);
                      gfx_Cls();
                          repeat
                              state := touch_Get(TOUCH_STATUS);               // get touchscreen status
                              if (state != 0)
                                  n := img_Touched(hndl,-1) ;
                                  x := touch_Get(TOUCH_GETX);
                                  y := touch_Get(TOUCH_GETY);
                                  if(state == TOUCH_RELEASED)                      // if there's a release
                                              print ("about to call form2");
                                              pause(300);
                                              returnedValue:=file_Run("form2.4FN", params);
                                              gfx_Cls();
                                              txt_Set(FONT_ID, FONT2);
                                              txt_Set(TEXT_WIDTH, 1);
                                              txt_Set(TEXT_HEIGHT, 1);
                                              print (mem_Heap(), " bytes free" );
                                              txt_MoveCursor(1,1);
                                              print (" Returned: ",[DEC5]results[0],"  ",[DEC5]results[1]);
                                              pause(1000);
                                              goto redo;
                  
                                  endif
                              endif
                  
                          forever
                      return 1;
                  endfunc
                  and form2
                  Code:
                  #platform "uLCD-32PTU"
                  #inherit "4DGL_16bitColours.fnc"
                  #inherit "VisualConst.inc"
                  #inherit "form2Const.inc"
                  
                  func main(var *myParams)
                      gfx_Set(SCREEN_MODE,LANDSCAPE) ;
                      gfx_Cls();
                      txt_Set(FONT_ID, FONT2);
                      txt_Set(TEXT_WIDTH, 1);
                      txt_Set(TEXT_HEIGHT, 1);
                  
                      if (!(file_Mount()))
                          while(!(file_Mount()))
                              putstr("Drive not mounted...");
                              pause(200);
                              gfx_Cls();
                              pause(200);
                          wend
                      endif
                      hndl := file_LoadImageControl("form2.dat", "form2.gci", 1);
                      img_ClearAttributes(hndl, iWinbutton1, I_TOUCH_DISABLE); // set to enable touch, only need to do this once
                      img_SetWord(hndl, iWinbutton1, IMAGE_INDEX, 1); // where state is 0 for up and 1 for down
                      img_Show(hndl,iWinbutton1) ;
                      gfx_MoveTo(100,150);
                      print (" Receieved: ",[DEC5]myParams[0],"  ",[DEC5]myParams[1]);
                      pause(2000);
                      myParams[0] := 255;
                      myParams[1] := 455;
                      //mem_Free(hndl2);
                      return 1;
                  
                  endfunc
                  crashes right after print ("about to call form2");
                  PLEH!!!!

                  Comment


                  • #10
                    When you use file_Run() "Any memory allocations in the main FLASH program are released".

                    Think about it, what is "Form1"?

                    It's a memory allocation made by the bootloader, so Form1 will be freed as part of trying to load and run Form2. In this case the filename passed to file_Run() vanishes part way through the execution of the statement, this results in the "Error 10" ("Could not load function file from disk") because a valid filename doesn't exist

                    You need to use file_Exec() in everything other than the 'top level' programs
                    Mark

                    Comment


                    • #11
                      Thank you Mark.... again...

                      yes ofc mem_Exec does the trick. The small issue that I am having now is loosing memory every time I return from form2. Originally I was loosing about 1kb. mem_Free(hndl) and I am now loosing 362 bytes on every return. Adding "code" to form2 (debug messages and press any key to continue) raises that number. So it has to be relevant to the calling of form2 and the size of it. How can I discard that? Is there a way to discard that? (heh need some more coffee I guess, and btw is there any way to discard that?)

                      Comment


                      • #12
                        You should be able to get it all back. Are you sure you are mem_Free()ing all allocations and image controls and file_Closing all files? What about a file_Unmount() (if you did a mount in that routine)?
                        Mark

                        Comment


                        • #13
                          Thanks a lot Mark. mem_Free the handls on both files and file_Unmount() on form1 does the trick. Ofcourse I will need to re-mount the fat16 system again after the unmount.Bellow are the 3 files with debug "press anykey" and available memory messages for anyone else who might have problems with calling files from other files. Bootloader is written on flash, form1 and form2 are copied to the sd card.

                          BootLoader
                          Code:
                          #platform "uLCD-32PTU"
                          
                          #inherit "4DGL_16bitColours.fnc"
                          #MODE RUNFLASH
                          #STACK 1000
                          func main()
                          
                              gfx_ScreenMode(LANDSCAPE) ; // change manually if orientation change
                          
                              print("Rational Labelling. BootLoader v1.4") ;      // replace with your code
                              pause(1000);
                              gfx_Cls();
                          
                              putstr("Mounting...\n");
                              if (!(file_Mount()))
                                  while(!(file_Mount()))
                                      putstr("Drive not mounted...");
                                      pause(500);
                                      gfx_Cls();
                                      pause(500);
                                  wend
                              endif
                              if (!(file_Exists("form1.4XE")))
                                  while(!(file_Exists("form1.4XE")))
                                      putstr("form1.4XE does not exist...");
                                      pause(500);
                                      gfx_Cls();
                                      pause(500);
                                  wend
                              endif
                              file_Run("form1.4XE", 0);
                          
                          endfunc
                          form1
                          Code:
                          #platform "uLCD-32PTU"
                          #inherit "4DGL_16bitColours.fnc"
                          #inherit "VisualConst.inc"
                          #inherit "form1Const.inc"
                          
                          #STACK 600
                          
                          var params[2];
                          var results[2];
                          
                          func main()
                          params[0] := 1;
                          params[1] := results;
                          results[0]:=300;
                          results[1]:=400;
                              gfx_Set(SCREEN_MODE,LANDSCAPE) ;
                              gfx_Cls();
                              //debug("1");
                              pause(1000);
                              redo:
                              if (!(file_Mount()))
                                  while(!(file_Mount()))
                                      gfx_Cls();
                                      putstr("Drive not mounted...");
                                      pause(500);
                                  wend
                              endif
                              //debug("2");
                              hndl := file_LoadImageControl("form1.dat", "form1.gci", 1);
                              touch_Set(TOUCH_ENABLE);
                              var state,n,x,y,returnedValue;
                              //debug("3");
                          
                              gfx_Cls();
                              print ("Just before the repeat");
                              pause(300);
                              gfx_Cls();
                                  repeat
                                      state := touch_Get(TOUCH_STATUS);               // get touchscreen status
                                      if (state != 0)
                                          n := img_Touched(hndl,-1) ;
                                          x := touch_Get(TOUCH_GETX);
                                          y := touch_Get(TOUCH_GETY);
                                          if(state == TOUCH_RELEASED)                      // if there's a release
                                                      gfx_Cls();
                                                      print ("about to call form2 ",mem_Heap(), " bytes free");
                                                      while (touch_Get(TOUCH_STATUS) != TOUCH_RELEASED);
                                                      returnedValue:=file_Exec("form2.4FN", params);
                                                      gfx_Cls();
                                                      txt_Set(FONT_ID, FONT2);
                                                      txt_Set(TEXT_WIDTH, 1);
                                                      txt_Set(TEXT_HEIGHT, 1);
                                                      print (mem_Heap(), " bytes free" );
                                                      txt_MoveCursor(1,1);
                                                      print (" Returned: ",[DEC5]results[0],"  ",[DEC5]results[1]);
                                                      while (touch_Get(TOUCH_STATUS) != TOUCH_RELEASED);
                                                      mem_Free(hndl);
                                                      file_Unmount();
                                                      goto redo;
                          
                                          endif
                                      endif
                          
                                  forever
                              return 1;
                          endfunc
                          form2
                          Code:
                          #platform "uLCD-32PTU"
                          #inherit "4DGL_16bitColours.fnc"
                          #inherit "VisualConst.inc"
                          #inherit "form2Const.inc"
                          
                          func main(var *myParams)
                              gfx_Set(SCREEN_MODE,LANDSCAPE) ;
                              touch_Set(TOUCH_ENABLE);
                              gfx_Cls();
                              txt_Set(FONT_ID, FONT2);
                              txt_Set(TEXT_WIDTH, 1);
                              txt_Set(TEXT_HEIGHT, 1);
                              print ("Inside form 2 ",mem_Heap(), " bytes free");
                              while (touch_Get(TOUCH_STATUS) != TOUCH_RELEASED);
                              if (!(file_Mount()))
                                  while(!(file_Mount()))
                                      putstr("Drive not mounted...");
                                      pause(200);
                                      gfx_Cls();
                                      pause(200);
                                  wend
                              endif
                              hndl := file_LoadImageControl("form2.dat", "form2.gci", 1);
                              gfx_Cls();
                              print ("after hndl := ",mem_Heap(), " bytes free");
                              while (touch_Get(TOUCH_STATUS) != TOUCH_RELEASED);
                              img_ClearAttributes(hndl, iWinbutton1, I_TOUCH_DISABLE); // set to enable touch, only need to do this once
                              img_SetWord(hndl, iWinbutton1, IMAGE_INDEX, 1); // where state is 0 for up and 1 for down
                              img_Show(hndl,iWinbutton1) ;
                              txt_MoveCursor(11,1);
                              print (" Receieved: ",[DEC5]myParams[0],"  ",[DEC5]myParams[1]);
                              while (touch_Get(TOUCH_STATUS) != TOUCH_RELEASED);
                              myParams[0] := 255;
                              myParams[1] := 455;
                              mem_Free(hndl);
                              gfx_Cls();
                              print ("after mem_Free and bofore return ",mem_Heap(), " bytes free");
                              while (touch_Get(TOUCH_STATUS) != TOUCH_RELEASED);
                              return 1;
                          
                          endfunc

                          Comment

                          Working...
                          X