|
|
View previous topic :: View next topic |
Author |
Message |
ad
Joined: 24 Mar 2015 Posts: 14
|
MENU |
Posted: Wed Jul 15, 2015 3:10 am |
|
|
I'm doing a menu with submenu inside. The function is performed as follows:
First, you have the option 1. MENU or 2.ENVIAR DATA.
If you press 1, you have the option to select 4 variables, if you press one of the four variables, you find two options, 1. GET DATA, # . BACK.
Code: |
while(TRUE){ //Bucle infinito siempre consulta el teclado
k=kbd_getc();
if (k!=0 & j!=k){ //Comprueba que la tecla presionada no sea la misma que se presiono la ultima vez
switch(Nivelmenu){
case 0:
switch (k){ //Menu principal
case '1':
Mostrar_menu_de_variables();
Nivelmenu=1;
break;
case '2':
EnviarDatos();
break;
default:
break;
}
break;
case 1: //Menu de variables, se muestran todas las variables para que se seleccione una
switch (k){
case '1':
Mostrar_menu_var();
variable=1;
Nivelmenu=2;
break;
case '2':
Mostrar_menu_var();
variable=2;
Nivelmenu=2;
break;
case '3':
Mostrar_menu_var();
variable=3;
Nivelmenu=2;
break;
case '4':
Mostrar_menu_var();
variable=4;
Nivelmenu=2;
break;
default:
break;
}
break;
case 2: // Menu de cada variable, todas tienen 2 opciones, obtener datos y salir al menu anterior
switch (k){
case '1':
Obtenerdatos (variable); //Segun la variable escogida
Nivelmenu=1; //Vuelve al menu de seleccionar las variables
Mostrar_menu_de_variables(); //Muestra menu variables
break;
case '#': //Se muestra el menu anterior y se vuelve a los botones del anterior tmb
Mostrar_menu_de_variables(); //Muestra menu variables
Nivelmenu=1; //Vuelve al menu de seleccionar las variables
break;
default:
break;
}
break;
default: // Caso unico que por algun problema se llegue este punto, poniendo a 0 y el nivel y mostrando el menu inicial
Mostrar_menu_inicial();
Nivelmenu=0;
break;
}
}
j=k; //Para que no entre de nuevo si se mantiene presionado la tecla
}
}
|
It leaves me right up here, as you can see in the code.
But what I want is that when the data showing the LCD, me an option to stop viewing data appears, EXIT option. |
|
|
guy
Joined: 21 Oct 2005 Posts: 297
|
|
Posted: Sat Jul 18, 2015 9:33 am |
|
|
Hi! My favorite way of doing menus is to have a separate piece of code that handles each menu and submenus. This is instead of having one loop and inside it determine which menu/submenu we are in. There are pros and cons.
So my implementation would be
Code: | while(1) {
show main menu
wait for key
if(key==1) {
key=0; // clear last keypress
while(key!=ESCAPE) {
show submenu, wait for key, handle submenu
}
}
if(key==2) {
key=0; // clear last keypress
while(key!=ESCAPE) {
show submenu, wait for key, handle submenu
}
}
} |
|
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|