CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

MENU

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
ad



Joined: 24 Mar 2015
Posts: 14

View user's profile Send private message

MENU
PostPosted: Wed Jul 15, 2015 3:10 am     Reply with quote

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: 291

View user's profile Send private message Visit poster's website

PostPosted: Sat Jul 18, 2015 9:33 am     Reply with quote

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
         }
    }
}
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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