Announcement

Collapse
No announcement yet.

Button coordinates in different flashbank

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

  • Button coordinates in different flashbank

    Hello,

    I am having some issues with code memory, so, I started moving some functions to flashbank 1 and then call them in the flashbank 0 through the "flash_Exec" command. With a bunch of functions moved it is working fine. But when I try to move the coordinates to flashbank 1, it is not working properly.

    My program uses button coordinates this way:

    (1) I define the buttons coordinates as 4-dim array at the beggining of my code (flashbank 0). Example:
    Code:
    var coord_Button_Cancel[] := [736, 240, 794, 288];
    (2) I call them in a function (catchTouchEvent) the following way:
    Code:
    if(touch_Get(TOUCH_STATUS) == TOUCH_PRESSED)
    if (touch_TestArea(coord_Button_Cancel))
    // (...)
    endif
    endif
    This was working fine for me until I needed to free up some code memory. As I have a lot of buttons (over 100 buttons, which means over 100 4-dim array assignments), the assignment stated in step (1) spends a lot of code memory. I was thinking of moving this assignment to flashbank 1, the following way:

    (a) I define a 100 dimension (for example) array called "coordinates" in flashbank 0
    Code:
    var coordinates[100];
    (b) In flashbank 0 program, I pass this array to flashbank 1 in a function called getCoordinates()
    Code:
    func getCoordinates()
    // Assign arguments for flashbank 1 arglist[1] := 15; // function id: 15 arglist[11] := coordinates; // there are other arguments that do not concern in this function // Execute function in flashbank 1 flash_Exec(1, arglist);
    endfunc
    In flashbank 1, the behavior is the following:

    Code:
    func getCoordinates(var coordinates) // in this function I assign every coordinates to every position of the buffer "coordinates"
    coordinates[0] := [736, 240, 794, 288]; //coordinates[1] := (...)
    endfunc
    Code:
    func main(var funcId, var ..., (...), var coordinates)
    switch (funcId)
    case 1:
    // ... break;
    // (...)
    case 15:
    getCoordinates(coordinates);
    break;
    endswitch
    endfunc
    I understand this should change the array "coordinates" and assign to every position the 4 coordinates I assign in flashbank 1. I am using other functions in flashbank 1 in a similar way and it is working. In other words, it should work the same way as steps (1) and (2).However, this is not working. With the (1) and (2) method, it works. With the (a) and (b) method, it does not.

    Is this possible to accomplish? Am I missing something? In case I haven't been clear enough, just let me know and I will explain it again. Is there an easier way to do this?

    Thank you in advance,

    Michael

  • #2
    Hi Michael,

    Is there any way you can reduce your code size and ram usage in the main as this is working. If you are already at the limit of RAM & flash memory, passing arrays to and from a flash function won't help.

    Would you like to send me your code to see if we can make some code changes to get some RAM & flash space back.

    Best regards

    Paul

    Comment


    • #3
      Hello pauleillo,

      My issue here is not RAM memory but is flash memory in the flashbank 0. I mean, I tried to move all the functions with "meat" to flashbank 1, but still having some issues with the code in flashbank 0. The main issue is that I cannot move functions that use the command "Img_Show", or similars (like load a user font), is this correct?

      By the way, looking a little bit more into it, I have realized that the problem seems to be the "array of arrays" that I try to modify in the flashbank 1.

      I mean,

      In flashbank 0, I define the array I want to modify in flashbank 1:

      Code:
      var coordinates[110];
      Note: This array is meant to save a 4-dimension array in every position (so, 110 arrays (4 dimension each one) that correspond to 110 buttons).

      Then I pass this array to the flashbank 1 (with the flash_Exec command).

      Now, in flashbank 1, I modify the "coordinates" array the following way:

      Code:
      func getCoordinates(var coordinates)
      coordinates[0] := [736, 240, 794, 288]; coordinates[1] := [274, 364, 404, 424]; coordinates[2] := [416, 364, 546, 424]; coordinates[3] := [639, 247, 791, 334]; // (...)
      endfunc
      Then, for instance, I print:

      Code:
      print(coordinates[0][1]);
      I expect here a 240, but get a 274.

      If I print:

      Code:
      print(coordinates[1][2]);
      I expect here a 364, but get a 639.

      This means the program understands "coordinates[0][1]" as "coordinates[1]" and only has one dimension.

      Same happens with "coordinates[1][2]" as "coordinates[3]". It is like "adding" the indices asked by me in one.

      So, I understand I am not defining properly this array. Is there any way to do it? Am I making it too complex? Is there an easier way? I have reviewed the programmers reference manual and did not get anything clear about it.

      Do you have any advice on how to solve it?

      According to the code, how do I send it in a private way? To make it private I mean.

      Thank you for your help,

      Michael

      Comment


      • #4
        Hello,

        I also tried to define the global array in flashbank 0:

        Code:
        var coordinates[110];
        And try to assign the coordinates in flashbank 1 the following way:

        Code:
        func getCoordinates(var coordinates)
        // Define coordinates arrays var coordinates0[] := [736, 240, 794, 288]; var coordinates1[] := [274, 364, 404, 424]; var coordinates2[] := [416, 364, 546, 424]; // (...) // Assign coordinates to buffer positions coordinates[0] := coordinates0; coordinates[1] := coordinates1; coordinates[2] := coordinates2; // (...)
        endfunc func main()
        getCoordinates(coordinates);
        endfunc
        It is not working though. I mean, the values I get later on, in flashbank 0, after executing the function in flashbank 1 are not the same. For example I get values over 7000, for instance, which I never assigned.

        Do you have any idea?

        Best regards,

        Michael

        Comment

        Working...
        X