Simple LCD Menu Main Page: Unterschied zwischen den Versionen

Aus ProjectWiki
Wechseln zu:Navigation, Suche
Zeile 58: Zeile 58:
  
 
== Interface description ==
 
== Interface description ==
 +
<pre>Const Menu_default_entry</pre>
 +
ID of the default entry
 +
 +
 +
<pre>Const Menu_value_string_width</pre>
 +
size for strings used to display
 +
 +
 +
<pre>Macro Menu_init</pre>
 +
loads the menu data
 +
 +
 
<pre>Declare Sub Menu()</pre>
 
<pre>Declare Sub Menu()</pre>
 +
Main function, called in Main Loop
 +
 +
 
<pre>Declare Sub Menu_forward()</pre>
 
<pre>Declare Sub Menu_forward()</pre>
 +
Goes one step forward in the menu or while in edit mode, bit values are set to true, numerical values are increased by the step size and for strings, the following character in the table will be selected.
 +
 +
 
<pre>Declare Sub Menu_backward()</pre>
 
<pre>Declare Sub Menu_backward()</pre>
 +
Goes one step backward in the menu or while in edit mode, bit values are set to false, numerical values are decreased by the step size and for strings, the preceeding character in the table will be selected.
 +
 +
 
<pre>Declare Function Menu_enter() As Byte</pre>
 
<pre>Declare Function Menu_enter() As Byte</pre>
 +
Shows the menu if inactive, follows a link, enters/exits the edit mode, adds a character in string edit mode or selects a function
 +
 +
 
<pre>Declare Sub Menu_show(byval Entry_id As Byte)</pre>
 
<pre>Declare Sub Menu_show(byval Entry_id As Byte)</pre>
<pre>Declare Sub Menu_hide()</pre>
+
Displays the menu with the provided entry id, if 0, the default entry is selected
<pre>Macro Menu_init</pre>
 
<pre>Const Menu_default_entry</pre>
 
<pre>Const Menu_value_string_width</pre>
 
  
  
== Sample ==
+
<pre>Declare Sub Menu_hide()</pre>
 
+
hides the menu
 +
== Small Sample ==
 
=== Menu structure overview ===
 
=== Menu structure overview ===
  

Version vom 3. Juli 2011, 02:21 Uhr

Overview

This is a menu system for standard alphanumerical LC-displays.

To navigate through the menu, only 3 buttons are needed: Forward, Backward and Menu/Enter (or a rotary encoder with push button).

You can make multiple nested sub-menus, hidden menus (not supported by the designer yet), function calls and display or edit different value types (Bit, Byte, Word, Integer, Single, String).

The menu structure and associated data is stored in arrays at runtime, the structure is made by connecting the right entries together (with their array indexes).

Numerical values are displayed both as value and as a bargraph showing the current position in the specified range.

Bit values can be set to On/Off (or another custom text), numerical values will be increased/decreased by the specified step size and string values can be edited using a custom set of characters (and two special characters for backspace/enter). Read-Only values just show the content of a variable.

To save program space, just the pieces of code you use are compiled. You get the smallest size if you just use Links and Function Calls, it will increase if you use values (read-only, editable or both) and for each data type used.


How to use it

Setup

Include the menu structure created with the designer and the menu functions:

Macro Menu_include_data
   $include "inc\menu_data.bas"
End Macro
$include "inc\menu.bas"

Dimension used Variables

Between the function include and the initialisation you have to dimension the variables used to display or edit in the menu:

Dim Test_bit As Byte
Dim Test_byte As Byte
Dim Test_word As Word
Dim Test_integer As Integer
Dim Test_dword As Dword
Dim Test_long As Long
Dim Test_single As Single
Dim Test_double As Double
Dim Test_string As String * Menu_value_string_width

Bit data types have to be defined as a byte. Note that a constant was created containing the maximum string size.

Initialisation

Menu_init

Main Loop

Do
   If Switch_minus = 1 Then Menu_backward()            ' back button pressed
   If Switch_plus = 1 Then Menu_forward()              ' forward button pressed
   If Switch_enter = 1 Then                            ' enter button pressed
      Select Case Menu_enter()
      Case Menu_exit:                                  ' Exit entry selected
         ...
      Case 2-255:                                      ' Function call
         ...
      End Select
   End If
   Menu                                                ' Main function
   ...
Loop


Interface description

Const Menu_default_entry

ID of the default entry


Const Menu_value_string_width

size for strings used to display


Macro Menu_init

loads the menu data


Declare Sub Menu()

Main function, called in Main Loop


Declare Sub Menu_forward()

Goes one step forward in the menu or while in edit mode, bit values are set to true, numerical values are increased by the step size and for strings, the following character in the table will be selected.


Declare Sub Menu_backward()

Goes one step backward in the menu or while in edit mode, bit values are set to false, numerical values are decreased by the step size and for strings, the preceeding character in the table will be selected.


Declare Function Menu_enter() As Byte

Shows the menu if inactive, follows a link, enters/exits the edit mode, adds a character in string edit mode or selects a function


Declare Sub Menu_show(byval Entry_id As Byte)

Displays the menu with the provided entry id, if 0, the default entry is selected


Declare Sub Menu_hide()

hides the menu

Small Sample

Menu structure overview

Menu data include file

Main file

Download