Announcement

Collapse
No announcement yet.

Repaet - Forever, no loop

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

  • Repaet - Forever, no loop

    Hi,

    In the following code the button iWinbutton isnt working, only seen graphicaly, the state flag is stuck in ' 0 '. it looks like the Repeat/Forever loop isnt working.

    The first repeat is before "state := touch_Get(TOUCH_STATUS);" and the associate forever is at the end, before endfunc. so why it isnt looping?



    The code:

    "

    #platform "uLCD-43PT"

    #inherit "4DGL_16bitColours.fnc"

    #inherit "VisualConst.inc"

    #inherit "DiExMonitorConst.inc"

    #inherit "PrintDiskGoldelox.inc"

    #inherit "LedDigitsDisplayGoldelox.inc"

    var combuf[24]; // 24 vars = 48 bytes
    var combuffer[1]; // 24 vars = 48 bytes
    var page ;


    func main()
    var chr,char, e, e2, n, frame, state;
    var numx, dir, colr, redo, numt, Wbs1, i, x, y ;

    e := 0;
    e2 := 0;

    gfx_Set(SCREEN_MODE,LANDSCAPE) ;
    gfx_Set(CONTRAST,5) ;
    txt_Set(TEXT_OPACITY, OPAQUE);
    numx := 0 ;

    //com1_Reset();

    // Uncomment the following if uSD images used.
    // putstr("Mounting...\n");
    if (!(disk:=file_Mount()))
    while(!(disk :=file_Mount()))
    // putstr("Drive not mounted...");
    pause(200);
    gfx_Cls();
    pause(200);
    wend
    endif

    gfx_TransparentColour(0x0020);
    gfx_Transparency(ON);

    pin_Set(OUTPUT, AUDIO_ENABLE);
    pin_HI(AUDIO_ENABLE);

    hndl := file_LoadImageControl("DIEXMO~1.dat", "DIEXMO~1.gci", 1);

    // image1 1.0 generated 30/05/2014 11:38:29
    //img_Show(hndl,iimage1) ;
    // pause(5000);

    if(file_Exists("bl16k.wav"))
    snd_BufSize(3);
    snd_Volume(127);
    file_PlayWAV("bl16k.wav");
    while(snd_Playing());
    else
    putstr("bl16k.wav not found");
    endif

    if(file_Exists("intro1.wav"))
    snd_BufSize(3);
    snd_Volume(127);
    file_PlayWAV("intro1.wav");
    while(snd_Playing());
    else
    putstr("intro1.wav not found");
    endif
    */
    // gfx_Set(OUTLINE_COLOUR, DARKOLIVEGREEN); // set outline colour, gfx_Cls() will draw outline
    // gfx_Cls();


    // Image5 1.0 generated 26/08/2014 23:28:47
    //img_Show(hndl,iImage5) ;


    // Winbutton1 1.0 generated 26/08/2014 23:51:14
    img_ClearAttributes(hndl, iWinbutton1, I_TOUCH_DISABLE); // set to enable touch, only need to do this once
    img_Show(hndl, iWinbutton1); // show button, only do this once

    print("State 0"); // print initial state

    touch_Set(TOUCH_ENABLE); // enable touch detection

    // gfx_Cls();

    repeat

    state := touch_Get(TOUCH_STATUS); //get touch screen status
    n := img_Touched(hndl,iWinbutton1);

    //---------------------------------------------------------------------------
    if(state == TOUCH_PRESSED) //if there's a press
    if(n == iWinbutton1) //and if it's inside the button
    img_SetWord(hndl, iWinbutton1, IMAGE_INDEX, 1); //change state to state 1
    img_Show(hndl, iWinbutton1); //show button
    gfx_MoveTo(0,0); //move origin to point (0,0)
    print("State 1"); //print state
    endif
    endif
    //---------------------------------------------------------------------------

    //---------------------------------------------------------------------------
    if(state == TOUCH_RELEASED) //if there's a release
    if(n == iWinbutton1) //and if it's inside the button
    img_SetWord(hndl, iWinbutton1, IMAGE_INDEX,0); //change state to state 0
    img_Show(hndl, iWinbutton1); //show button
    gfx_MoveTo(0,0); //move origin to point (0,0)
    print("State 0"); //print state
    endif
    endif
    //---------------------------------------------------------------------------

    //---------------------------------------------------------------------------
    if(state == TOUCH_MOVING) //if there's movement

    if(n == iWinbutton1) //and if it's inside the button
    img_SetWord(hndl, iWinbutton1, IMAGE_INDEX, 1); //change state to state 1
    img_Show(hndl, iWinbutton1); //show button
    gfx_MoveTo(0,0); //move origin to point (0,0)
    print("State 1"); //print state

    else //if movement is outside the button
    img_SetWord(hndl, iWinbutton1, IMAGE_INDEX, 0); //change state to state 0
    img_Show(hndl, iWinbutton1); //show button
    gfx_MoveTo(0,0); //move origin to point (0,0)
    print("State 0"); //print state
    endif
    endif
    //----------------------------------------------------------------------------


    repeat

    // setbaud(BAUD_9600); // 9600 baud comms
    com_SetBaud(COM1,960);

    com1_Init(combuf, 48, 0); // set up a comms circular buffer, use the entire buffer, no sync character

    repeat

    sys_SetTimer(TIMER0, 2000); // set delay so we stay in next loop for 5 seconds

    // wait for a while gathering bytes
    // and continuously displaying the count
    // of characters in the buffer.
    //// repeat
    // Video1 1.0 generated 16/11/2013 18:32:51

    // txt_MoveCursor(2,1); // reset cursor to line 3, column 2
    // print("Buffered ", [DEC2Z] ( com_Count() )); // show count of chars in buffer


    until (! sys_GetTimer(TIMER0)); // loop until TIME_OUT register is 0

    /*
    if (com_Full())
    txt_MoveCursor(3,1); // reset cursor to line 5, column 2
    print("Buffer Full ", (++e) ); // print error count
    endif

    if (com_Error())
    txt_MoveCursor(4,1); // reset cursor to line 7, column 2
    print("Comms Error ", (++e2) ); // print error count
    endif
    */
    // now dump whatever we got to the terminal
    while ( (char := serin1()) >= 0)
    // txt_Set(TEXT_COLOUR, RED);
    gfx_MoveTo(0,0);
    // print("\n'",[CHR]char,"' is ");
    to(COM1); putch(char); // send buffered chars to com port
    //wend

    /*
    txt_Set(FONT_ID, 0);
    txt_MoveCursor(0,1); // reset cursor to line 1, column 2
    putstr("Serial Echo\n9600 baud");
    */

    switch

    case (char == 'A')

    // Image2 1.0 generated 22/08/2014 09:47:02
    img_Show(hndl,iImage2) ;

    // if(file_Exists("WF2.wav"))
    snd_BufSize(3);
    snd_Volume(127);
    file_PlayWAV("WF16k.wav");
    while(snd_Playing());
    // else
    // putstr("WF2.wav not found");
    //endif

    pause(7000);
    case (char == 'B')



    pause(7000);

    // Image3 1.0 generated 22/08/2014 09:47:16

    // putstr(" THREE");
    // com_Init(combuffer, 2, 0); // reset buffer

    case (char == 'C')

    // Image4 1.0 generated 22/08/2014 09:47:47
    img_Show(hndl,iImage4);
    // media_Imge(0, 3) ;// show image
    pause(1000);

    snd_BufSize(3);
    snd_Volume(127);
    file_PlayWAV("Bubble16k.wav"); //WF16k.wav");
    while(snd_Playing());

    case (char == 'D')

    for (frame := 0; frame <= 47; frame++)



    pause(1);
    next
    pause(7000);



    case (char == 'P')

    gfx_Cls() ;

    /*
    pause(3000);
    serout('A');//to(COM0); putch('5'); //
    pause(3000);

    case (char == '6')
    numx := 50 ;

    case (char == '7')
    numx := 100 ;
    */
    default:

    endswitch
    txt_MoveCursor(3,1);
    print("Buffered ", ( com1_Count() )); // show count of chars in buffer
    wend
    pause(1000);

    // Image4 1.0 generated 05/01/2014 15:03:59

    /*
    // Thermometer1 1.1 generated 16/11/2013 21:22:31
    media_SetAdd(iThermometer1H, iThermometer1L) ; // point to the Thermometer1 image
    media_VideoFrame(0, 0, numx) ; // where numx is 0 to 100 (for a displayed 50 to 150)
    if (numx == 0)
    dir := 1 ;
    else if (numx == 100)
    dir := -1 ;
    endif
    numx += dir ;
    pause(10) ;

    //putstr(" Idle");
    */
    until ( com1_Full() || com1_Error() ); // reset if error occurred


    forever

    endfunc
    "

    Thanks,
    Eyall

  • #2
    You code is a bit hard to follow, it also has an unmatched '*/'

    Why not use some print()s in your code to help you debug it?

    If you still can't figure it out use File, Zip project to create a zip file with everything in it that is needed for us to try and test it.
    Mark

    Comment


    • #3
      I have tried with printing but didnt success to understand the problem.

      I removed the */. the 'repeat' for the iWinbutton is wrong but i dont understand why. i marked it with // ************** //

      The code now is readable:

      "
      #platform "uLCD-43PT"

      #inherit "4DGL_16bitColours.fnc"

      #inherit "VisualConst.inc"

      #inherit "DiExMonitorConst.inc"

      #inherit "PrintDiskGoldelox.inc"

      #inherit "LedDigitsDisplayGoldelox.inc"

      var combuf[24]; // 24 vars = 48 bytes
      var combuffer[1]; // 24 vars = 48 bytes
      var page ;


      func main()
      var chr,char, e, e2, n, frame, state;
      var numx, dir, colr, redo, numt, Wbs1, i, x, y ;

      e := 0;
      e2 := 0;

      gfx_Set(SCREEN_MODE,LANDSCAPE) ;
      gfx_Set(CONTRAST,5) ;
      txt_Set(TEXT_OPACITY, OPAQUE);
      numx := 0 ;


      if (!(disk:=file_Mount()))
      while(!(disk :=file_Mount()))
      // putstr("Drive not mounted...");
      pause(200);
      gfx_Cls();
      pause(200);
      wend
      endif

      gfx_TransparentColour(0x0020);
      gfx_Transparency(ON);

      pin_Set(OUTPUT, AUDIO_ENABLE);
      pin_HI(AUDIO_ENABLE);

      hndl := file_LoadImageControl("DIEXMO~1.dat", "DIEXMO~1.gci", 1);


      if(file_Exists("bl16k.wav"))
      snd_BufSize(3);
      snd_Volume(127);
      file_PlayWAV("bl16k.wav");
      while(snd_Playing());
      else
      putstr("bl16k.wav not found");
      endif


      img_ClearAttributes(hndl, iWinbutton1, I_TOUCH_DISABLE); // set to enable touch, only need to do this once
      img_Show(hndl, iWinbutton1); // show button, only do this once

      print("State 0"); // print initial state

      touch_Set(TOUCH_ENABLE); // enable touch detection


      repeat

      // **************************************************************************************************** *********************** //
      repeat

      state := touch_Get(TOUCH_STATUS); //get touch screen status
      n := img_Touched(hndl,iWinbutton1);

      //---------------------------------------------------------------------------
      if(state == TOUCH_PRESSED) //if there's a press
      if(n == iWinbutton1) //and if it's inside the button
      img_SetWord(hndl, iWinbutton1, IMAGE_INDEX, 1); //change state to state 1
      img_Show(hndl, iWinbutton1); //show button
      gfx_MoveTo(0,0); //move origin to point (0,0)
      print("State 1"); //print state
      endif
      endif
      //---------------------------------------------------------------------------

      //---------------------------------------------------------------------------
      if(state == TOUCH_RELEASED) //if there's a release
      if(n == iWinbutton1) //and if it's inside the button
      img_SetWord(hndl, iWinbutton1, IMAGE_INDEX,0); //change state to state 0
      img_Show(hndl, iWinbutton1); //show button
      gfx_MoveTo(0,0); //move origin to point (0,0)
      print("State 0"); //print state
      endif
      endif
      //---------------------------------------------------------------------------

      //---------------------------------------------------------------------------
      if(state == TOUCH_MOVING) //if there's movement

      if(n == iWinbutton1) //and if it's inside the button
      img_SetWord(hndl, iWinbutton1, IMAGE_INDEX, 1); //change state to state 1
      img_Show(hndl, iWinbutton1); //show button
      gfx_MoveTo(0,0); //move origin to point (0,0)
      print("State 1"); //print state

      else //if movement is outside the button
      img_SetWord(hndl, iWinbutton1, IMAGE_INDEX, 0); //change state to state 0
      img_Show(hndl, iWinbutton1); //show button
      gfx_MoveTo(0,0); //move origin to point (0,0)
      print("State 0"); //print state
      endif
      endif
      //----------------------------------------------------------------------------


      com_SetBaud(COM1,960);

      com1_Init(combuf, 48, 0); // set up a comms circular buffer, use the entire buffer, no sync character

      repeat

      sys_SetTimer(TIMER0, 2000); // set delay so we stay in next loop for 5 seconds

      until (! sys_GetTimer(TIMER0)); // loop until TIME_OUT register is 0


      while ( (char := serin1()) >= 0)
      // txt_Set(TEXT_COLOUR, RED);
      gfx_MoveTo(0,0);
      // print("\n'",[CHR]char,"' is ");
      to(COM1); putch(char); // send buffered chars to com port
      //wend

      switch

      case (char == 'A')

      // Image2 1.0 generated 22/08/2014 09:47:02
      img_Show(hndl,iImage2) ;

      snd_BufSize(3);
      snd_Volume(127);
      file_PlayWAV("WF16k.wav");
      while(snd_Playing());


      pause(7000);
      case (char == 'B')

      pause(7000);

      case (char == 'C')


      img_Show(hndl,iImage4);

      pause(1000);

      snd_BufSize(3);
      snd_Volume(127);
      file_PlayWAV("Bubble16k.wav"); //WF16k.wav");
      while(snd_Playing());

      case (char == 'D')

      for (frame := 0; frame <= 47; frame++)


      pause(1);
      next
      pause(7000);

      case (char == 'P')

      gfx_Cls() ;


      default:

      endswitch
      txt_MoveCursor(3,1);
      print("Buffered ", ( com1_Count() )); // show count of chars in buffer
      wend
      pause(1000);


      until ( com1_Full() || com1_Error() ); // reset if error occurred


      forever

      endfunc
      "

      Thanks,
      Eyall

      Comment


      • #4
        You need to use File, Zip project to create a zip file with everything in it that is needed for us to try and test it.

        All you have supplied is the main source, there are quite a few other things required
        Mark

        Comment


        • #5
          Please see attached, i marked all the wav and video files and the problem still exist.
          Attached Files

          Comment


          • #6
            Please use File, Zip project in Workshop, it will collect all the files and the correct files.
            Mark

            Comment


            • #7
              I'm sorry it collect 44 MB , which is too big. i attahced the none media files.

              The code work as a standalone, no need for the media files, and stuck in the loop, you just need to build the project copy/paste and run it.
              Attached Files

              Comment


              • #8
                Unfortunately you still need the 3 videos and 5 images to be able to open the program in Workshop, so I had to spend time dummying them up. Of course I could have just deleted the objects, but that wasn't immediately obvious.

                If you want people to help you it's important that you make the smallest, simplest example of that demonstrates the problem you are having. Doing that will also make it obvious to you what the problem is 90% of the time

                Really, with such messy code, and no indentation it must be very hard to work out just what your code is doing.

                Once you indent it properly, it immediately becomes obvious that the touch code never gets a look in, the code is 'stuck' in the 'repeat until ( com1_Full() || com1_Error() );' 'loop'

                Another was of seeing that easily was to put a print(n) ; immediately after the img_Touched(), it only prints once

                Also, once you add touch, delays will impinge on the operation of the touch, so they need to go, but really in your current code they don't achieve much.

                Attached Files
                Mark

                Comment

                Working...
                X