Shop OBEX P1 Docs P2 Docs Learn Events
Simple Menu system on Prop — Parallax Forums

Simple Menu system on Prop

eagletalontimeagletalontim Posts: 1,399
edited 2012-12-01 22:34 in Propeller 1
I am looking for a basic menu system that I can use to display on my 2 x 16 display. I used to work with the SX but now I am switching over to the Prop and am not sure how to have "Preset menu items" that I can call for and display on the screen. On the SX, there was the DATA function which allowed each character to be "looked up" and then displayed on the screen. Is there something similar to this or easier to work with instead of writing each line like this :
  lcd.init(24, 9600, 2)
  lcd.displayOn
  lcd.backLight(TRUE)
  waitcnt(2_000_000 + cnt)
  lcd.gotoxy(0,0)
  [B]lcd.str(string("Testing String.. "))[/B]


Old SX Code....
showmenu:
  temp1 = __PARAM1
  temp1 = temp1 - 1
  temp4 = temp1
  IF temp1 > 14 THEN
    temp1 = temp1 - 15
    temp3 = 1
  ELSE
    temp3 = 0
  ENDIF
  temp1 = temp1 * 17
  FOR idx = 0 TO 15
    IF temp3 = 0 THEN
      READ Menu1 + temp1, temp2
    ELSE
      READ Menu2 + temp1, temp2
    ENDIF
    INC temp1
    PUT line1(idx), temp2
  NEXT
  IF temp4 = 0 THEN
    PUT line2, "Running...      "
  ELSE
    PUT line2, "Setting :       "
  ENDIF
  UPDATE_L1
  UPDATE_L2
  RETURN

Menu1:                  ' Tags end here
  DATA "Sample menu 1 : ", 0
  DATA " ......... etc...       ", 0

Menu2:
  DATA "Continuing on..... ", 0
  DATA "........and on........", 0

Comments

  • eagletalontimeagletalontim Posts: 1,399
    edited 2012-12-01 17:16
    I think I figured out a way to do it with using something like this :
    LONG Menu[100]
    
    Menu[0] := "First menu item    "
    Menu[1] := "Second menu item"
    
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2012-12-01 17:32
    You can't really create an array of strings like that. Think about defining the strings as DATa, and reference the starting addresses of the strings.


    PUB menu
    lcd.str(@lcdstring0)
    ' etc...
    '
    DAT
    lcdstring0 byte "first menu item",0 ' <-- note null terminated
    lcdstring1 byte "second menu item",0
    ' etc
  • JonnyMacJonnyMac Posts: 9,193
    edited 2012-12-01 18:22
    The paradox is that the easier you menu is to use, the harder it can be to code. Last year I did two menu-based projects with multi-line menus. The key is understanding navigation through the menus and making it consistent. I have been using four arrows, and enter key, and an escape key since my days at Toro. In fact, I wrote an object that gives me four-bit LCD control plus adds two lines for the Enter and Escape buttons (the arrow buttons use the LCD buss pins). My systems work like subroutine calls: when you go to a menu item you call a handler that deals with the keys and will go back to the caller on Enter or Escape. Again, getting the architecture laid out and understood really needs to happen first, otherwise you can spend a lot of frustrating time writing code (ask me how I know).
  • eagletalontimeagletalontim Posts: 1,399
    edited 2012-12-01 19:16
    With the current menu system, I am just using a standard 2x16 display and displaying the Menu Item on the first line. The second line will have "Value : " and the value of that specific menu item which is stored in the EEPROM. To access the menu, a user will have 3 buttons. One is the Menu button, the other 2 are up and down buttons. Holding the menu button for 2 seconds will activate the menu. Pressing the menu button quickly will store that value for the menu item, then move to the next menu item in a continual loop. To exit the menu, a user can hold the Menu button again for say 3 seconds and it will save the value in the current view, then exit back to the main screen which will then continue normal operations. Trying to keep buttons / circuitry to a minimum at the moment to save space and drilling time on each box.
  • JonnyMacJonnyMac Posts: 9,193
    edited 2012-12-01 22:34
    I'm not a big fan of the timed button approach, but it's your project. The key is keeping an index as to which menu level you've selected so you can display the appropriate text and associated value(s). For ease of coding you may want to create methods called show_menu_nn where nn is the menu number. Each of these methods would clear the display, display the appropriate values, then return to the main loop. When you have an "enter" command you can call a similar method called edit_menu_nn which will handle any editing chores for the menu level. It's a bit verbose, but an easy-to-deplay solution.
Sign In or Register to comment.