
BTS SNEC Menus
Revision 6:a31127c43225, committed 2021-10-18
- Comitter:
- rtk
- Date:
- Mon Oct 18 10:24:59 2021 +0000
- Parent:
- 5:d879f538c159
- Commit message:
- TP SNEC
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Sun Oct 10 14:26:20 2021 +0000 +++ b/main.cpp Mon Oct 18 10:24:59 2021 +0000 @@ -1,93 +1,116 @@ #include "mbed.h" #include "C12832.h" - - - DigitalIn up(A2); DigitalIn down(A3); DigitalIn left(A4); DigitalIn right(A5); DigitalIn center(D4); C12832 lcd(D11, D13, D12, D7, D10); -enum {MATIN,MIDI,SOIR, PETIT, DEJ,DINER} etat = MATIN; +enum {MATIN,MIDI,SOIR, PETIT, DEJ,DINER} menuPrincipal = MATIN; int menu_precedent = MIDI; -char message_precedent[]=" "; +char message_precedent[]="unMessageAuHasard"; + +void AttendreRelachementBoutons() +{ + if (up) while (up) wait(0.01); + else if (down) while (down) wait(0.01); + else if (left) while (left) wait(0.01); + else if (right) while (right) wait(0.01); + else if (center) while (center) wait(0.01); +} + +void AttendreNouvelAppuiCenter() +{ + AttendreRelachementBoutons(); + while (!center) wait(0.01); +} + +void Afficher_Message(char *Message)// Pour ne pas avoir de scintillement +{ + if (strcmp(message_precedent,Message) ==0) return; + strcpy(message_precedent,Message); + lcd.cls(); + lcd.locate(0,8); + lcd.printf(Message); + AttendreRelachementBoutons(); +} + void Afficher_Menu(int Menu) { - if (menu_precedent == Menu) return; - menu_precedent = Menu; - lcd.cls(); - lcd.locate(0,8); - //wait(0.050); switch(Menu) { case MATIN : - lcd.printf("Matin"); + Afficher_Message("Matin"); break; case MIDI : - lcd.printf("Midi"); + Afficher_Message("Midi"); break; case SOIR : - lcd.printf("Soir"); + Afficher_Message("Soir"); break; case PETIT : - lcd.printf("Petit dejeuner"); + Afficher_Message("Petit dejeuner"); break; case DEJ : - lcd.printf("Dejeuner"); + Afficher_Message("Dejeuner"); break; case DINER : - lcd.printf("Diner"); + Afficher_Message("Diner"); break; } } -void Afficher_Message(char *Message) +void Menu_Matin(int SousMenu) { - if (strcmp(message_precedent,Message) ==0) return; - lcd.cls(); - lcd.locate(0,8); - lcd.printf(Message); - -} - -void Menu_Matin(int etat) -{ + //main bool Sortir = false; // On sort du sous-menu while (!Sortir) { - Afficher_Menu(etat); - switch (etat) { + //while + Afficher_Menu(SousMenu); + + switch (SousMenu) { + //switch case PETIT : // évèments if (left) { - etat = MATIN; + menuPrincipal = MATIN; Sortir=true; } - if (right) etat=DEJ; - if (center)Afficher_Message("Ok"); + if (right) SousMenu=DEJ; + if (center) { + Afficher_Message("Ok"); + AttendreNouvelAppuiCenter(); + } break; case DEJ : // évèments + if (left) SousMenu=PETIT; break; case DINER : + break; - } - wait(0.125); + }//switch + - } -} + }//while +}//main + + + + int main() { while (1) { - Afficher_Menu(etat); - switch (etat) { + Afficher_Menu(menuPrincipal); + switch (menuPrincipal) { case MATIN : // évèments - if (down) etat = MIDI; + if (down) menuPrincipal = MIDI; if (right) Menu_Matin(PETIT); break; case MIDI : + if (up) menuPrincipal = MATIN; break; case SOIR : break;