Go Down

Topic: Nested switch...case (Read 2 times) previous topic - next topic

uberdum50

Just tried this. Again, to no avail...
Code: [Select]
   
case '4':
      if (menuActive == true) {
        menuActive = false;
        GLCD.ClearArea();
        GLCD.println("Master Configuration");
        GLCD.println("# To exit menu");
        GLCD.println("1. Device ID");
          switch (key) {
            case '1':
            //if(key == '1')
            GLCD.ClearArea();
            GLCD.println("Device ID menu");
            break;
      }
    break;


I tried disabling access to the menu system but that seems to lock me out entirely and if I remove the menuActive = false line I'm back to the problem of it turning the LED on again...  :S

uber

UKHeliBob

If I understand correctly you want a new switch...case after displaying a sub menu in your case '4'.  Is that right ?

If so then you will need to read the keyboard again in case '4' and assign the input to a different variable.  You currently have only one keypad.getKey in your code.
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

uberdum50

Just tried this now as you suggested:
Code: [Select]

    case '4':
      if(menuActive == true){
        GLCD.ClearArea();
        GLCD.println("Master Configuration");
        GLCD.println("# To exit menu");
        GLCD.println("1. Device ID");
        char key2 = keypad.getKey(); //Used for this sub menu only
          switch (key2) {
            case '1':
            GLCD.ClearArea();
            GLCD.println("Device ID menu");
            break;
      }


And it still toggles the LED, this is infuriating...

uber

PeterH

Is this menu supposed to be blocking (the code does not leave the switch case until the user has left the nested menu)?

In your original code it looks as if you were going to introduce a nested switch statement, but you omitted the switch statement itself - you only included the case statements. Hence it was considered as a (mangled) part of the outer switch, causing the error.

In a later copy of your code you added the switch statement but did not include the code to read the user input used to navigate within the menu or anything to cause the sketch to wait until that input arrived or cope if it did not arrive.
I only provide help via the forum - please do not contact me for private consultancy.

uberdum50

Yes, the menu system is supposed to be blocking as the actions are performed in the root menu itself. I am trying to get the user input to this one sub menu but it keeps triggering the second function (To turn on the LED) in the menu above the main configuration menu which isn't what I want and the only way I could see this possible is to put the menu in a routine and then call it and just pass it user input from the loop :/

uber

Go Up