Announcement

Collapse
No announcement yet.

Global variable not updating?

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

  • Global variable not updating?

    I have declared phone_num[17] after the #inherit lines as so:

    var phone_num[17];

    I am using this array to store the individual digits of a phone number entered by the user, displaying them on a set of LED digits (both done via the screen of a uLCD 32PT)

    Entry and display of numbers works fine - Digits go into the elements of the array, and the 15th element stores the number of digits entered.

    The only thing I can't do... is clear the array (sort-of). Or, it seems, change the value in phone_num[16].

    Here's a breakdown of what's happening:
    -Enter first set of numbers into array (eg, 12345)
    -Store number of digits to display (5)
    -Numbers display correctly (right-justified)
    -Clear array
    -Enter second set of numbers (eg 123)
    -Store number of digits to display(3)
    -Number displayed is 12123 - the numbers have overwritten correctly, but neither the digit count nor the old numbers have been cleared.

    I've run a basic test on this - set phone_num to be filled with 1s on initialisation, then entering no digits. This functions correctly - the digit count is set to zero and no 1s are displayed. Essentially, first time round works great but nothing after that.

    The only way I've found of clearing the array is to take the exact same clearing code I am using prior to number entry, and put it right before the display code. The display shows all zeroes. Put the code in the previous function, or the one that calls that function, or AFTER the numbers are displayed (ie, before it goes into the next cycle) and I get the same issue.

    I honestly have no idea why this is happening, and would be grateful for any advice. I can attach the entire program if necessary, but it's nearly 600 lines and most of it isn't related.

    The clearing code is as follows:

    for(x := 0; x < 17; x++)
    phone_num[x] := 0;
    next

    And the display code is:

    var digit[15] := [iCall_Dig15,iCall_Dig14,iCall_Dig13,iCall_Dig12,iCall_Dig11,iCall_Dig10,iCall_Dig9,iCall_Dig8,iCall_ Dig7,iCall_Dig6,iCall_Dig5,iCall_Dig4,iCall_Dig3,iCall_Dig2,iCall_Dig1];
    var left[15] := [260,244,228,212,196,180,164,148,132,116,100,84,68,52,36];
    var x;
    var y;

    y := phone_num[16];
    phone_num[16]--;

    for(x := 0; x

  • #2


    Um, I'm finding it a bit hard to follow, but isn't the code doing exactly what you are telling it to do?

    Eg

    Display 5 numbers 12345

    Display shows "12345"

    Display 3 numbers "98"

    Display shows "98345"

    The last 3 digits remain from before, where are you blanking them?
    Mark

    Comment


    • #3


      I posted excerpts from the code as the numerical entry and display spans multiple functions. The blanking code is in my first post. The three major functions (called in the order shown) are:

      func phone_select()

      var x;
      var secure;
      var index;
      var flag := 0;

      repeat //Keeps screen in 'call mode' unless otherwise directed
      if(touch_Get(0) == 1) //Checks for touch and which button
      index := img_Touched(hndl,ALL);
      untouch(); //Waits until button is released
      pause(200);

      switch (index)
      case iPhone_Bk: //Goes back to main screen
      main_init();
      return;
      case iDial_Btn: //Goes to touchscreen dialling screen
      dial_init();
      secure := dial_press();
      if(secure != 'X') //Goes to calling screen if valid call value returned
      call_init(secure);
      call_ctrl();
      endif
      phone_init(); //Reshows phone options screen if back button was pressed
      break;
      case iPhonebk_Btn: //Goes to phonebook
      break;
      case iSpeed_Btn: //Goes to speed-dial/redial
      break;
      endswitch
      endif
      forever
      endfunc

      /*Detects a press on the numerical keypad*/
      func dial_press()

      var counter := 0;
      var index;
      var x;

      //Why does this not clear phone_num so far as call screen is concerned, when it works on call screen?
      for(x := 0; x < 17; x++)
      phone_num[x] := 0;
      next

      /*
      Checks for press on the keypad and determines which key has been pressed.
      Each key places the appropriate number in the current location in the 'phone num' array,
      then increments array element by 1.
      The backspace button moves back one position in the array,
      and also clears the displayed numbers to remove the deleted value.
      The max no. of digits is 15; the 16th element records the number of digits entered.
      */

      repeat
      if(touch_Get(0) == 1)
      index := img_Touched(hndl,ALL);
      untouch();
      if(counter < 15) //Keypad response if 0) counter--;
      clearnum();
      break;
      case iCallSec_Btn:
      phone_num[16] := counter;
      return 1;
      break;
      case iCallClr_Btn:
      phone_num[16] := counter;
      return 0;
      break;
      case iDial_Bk:
      return 'X';
      default:
      break;
      endswitch
      num_enter(counter);
      else //Keypad response if 15 numbers entered
      switch (index)
      case iKey_BkSpce:
      clearnum();
      counter--;
      break;
      case iCallSec_Btn:
      phone_num[16] := counter;
      return 1;
      break;
      case iCallClr_Btn:
      phone_num[16] := counter;
      return 0;
      break;
      case iDial_Bk:
      return 'X';
      endswitch
      endif
      endif
      forever
      return 1;
      endfunc

      /*Controls for call-in-progress*/
      func call_ctrl()

      var digit[15] := [iCall_Dig15,iCall_Dig14,iCall_Dig13,iCall_Dig12,iCall_Dig11,iCall_Dig10,iCall_Dig9,iCall_Dig8,iCall_ Dig7,iCall_Dig6,iCall_Dig5,iCall_Dig4,iCall_Dig3,iCall_Dig2,iCall_Dig1];
      var left[15] := [260,244,228,212,196,180,164,148,132,116,100,84,68,52,36];
      var x;
      var y;

      y := phone_num[16];
      phone_num[16]--;

      for(x := 0; x

      Comment


      • #4


        UPDATE: Did some more checks, and it's nothing to do with the variables - the data's being entered and retrieved just fine. Leaving the above post in just for the code.

        The real issue seems to be with the LED digits. If they have been showing a value previously, they default back to that value on re-displaying (ie, switch to another form and switch back). I'd forgotten that I needed to clear digit+1!

        A couple of related questions, however:

        - How do I view compiler notices?
        - Can custom digits contain more than 9 positions? (ie blank, # and + in addition to the 9 digits)
        - Is there a way of removing an object (eg text) from the screen without affecting the other objects?

        Comment


        • #5


          Since you are using ViSi you have control over how form changes happen.

          So you have it fixed?

          - How do I view compiler notices?
          Set Options, Compiler, Reporting level to All

          - Can custom digits contain more than 9 positions? (ie blank, # and + in addition to the 9 digits)
          You mean 10? No sorry that can't be changed. What you can do is produce a GIF with all the characters and digits you want and then select them individually. Have a look at the code for LedDigitsDisplay, most of what that does is what you will need, you just need to add to it.

          - Is there a way of removing an object (eg text) from the screen without affecting the other objects?
          Either draw a filled rectangle of the background color over it, or draw the background image clipped to the space were the text is.
          Mark

          Comment

          Working...
          X