Robert Tomczak
/
TP3_2021-Menu
BTS SNEC Menus
main.cpp@6:a31127c43225, 2021-10-18 (annotated)
- Committer:
- rtk
- Date:
- Mon Oct 18 10:24:59 2021 +0000
- Revision:
- 6:a31127c43225
- Parent:
- 5:d879f538c159
TP SNEC
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
chris | 0:0325ecbd1916 | 1 | #include "mbed.h" |
rtk | 4:dd6d3b44dcb9 | 2 | #include "C12832.h" |
rtk | 5:d879f538c159 | 3 | DigitalIn up(A2); |
rtk | 5:d879f538c159 | 4 | DigitalIn down(A3); |
rtk | 5:d879f538c159 | 5 | DigitalIn left(A4); |
rtk | 5:d879f538c159 | 6 | DigitalIn right(A5); |
rtk | 5:d879f538c159 | 7 | DigitalIn center(D4); |
rtk | 5:d879f538c159 | 8 | C12832 lcd(D11, D13, D12, D7, D10); |
rtk | 6:a31127c43225 | 9 | enum {MATIN,MIDI,SOIR, PETIT, DEJ,DINER} menuPrincipal = MATIN; |
chris | 0:0325ecbd1916 | 10 | |
rtk | 5:d879f538c159 | 11 | int menu_precedent = MIDI; |
rtk | 6:a31127c43225 | 12 | char message_precedent[]="unMessageAuHasard"; |
rtk | 6:a31127c43225 | 13 | |
rtk | 6:a31127c43225 | 14 | void AttendreRelachementBoutons() |
rtk | 6:a31127c43225 | 15 | { |
rtk | 6:a31127c43225 | 16 | if (up) while (up) wait(0.01); |
rtk | 6:a31127c43225 | 17 | else if (down) while (down) wait(0.01); |
rtk | 6:a31127c43225 | 18 | else if (left) while (left) wait(0.01); |
rtk | 6:a31127c43225 | 19 | else if (right) while (right) wait(0.01); |
rtk | 6:a31127c43225 | 20 | else if (center) while (center) wait(0.01); |
rtk | 6:a31127c43225 | 21 | } |
rtk | 6:a31127c43225 | 22 | |
rtk | 6:a31127c43225 | 23 | void AttendreNouvelAppuiCenter() |
rtk | 6:a31127c43225 | 24 | { |
rtk | 6:a31127c43225 | 25 | AttendreRelachementBoutons(); |
rtk | 6:a31127c43225 | 26 | while (!center) wait(0.01); |
rtk | 6:a31127c43225 | 27 | } |
rtk | 6:a31127c43225 | 28 | |
rtk | 6:a31127c43225 | 29 | void Afficher_Message(char *Message)// Pour ne pas avoir de scintillement |
rtk | 6:a31127c43225 | 30 | { |
rtk | 6:a31127c43225 | 31 | if (strcmp(message_precedent,Message) ==0) return; |
rtk | 6:a31127c43225 | 32 | strcpy(message_precedent,Message); |
rtk | 6:a31127c43225 | 33 | lcd.cls(); |
rtk | 6:a31127c43225 | 34 | lcd.locate(0,8); |
rtk | 6:a31127c43225 | 35 | lcd.printf(Message); |
rtk | 6:a31127c43225 | 36 | AttendreRelachementBoutons(); |
rtk | 6:a31127c43225 | 37 | } |
rtk | 6:a31127c43225 | 38 | |
rtk | 5:d879f538c159 | 39 | void Afficher_Menu(int Menu) |
rtk | 5:d879f538c159 | 40 | { |
rtk | 5:d879f538c159 | 41 | switch(Menu) { |
rtk | 5:d879f538c159 | 42 | case MATIN : |
rtk | 6:a31127c43225 | 43 | Afficher_Message("Matin"); |
rtk | 5:d879f538c159 | 44 | break; |
rtk | 5:d879f538c159 | 45 | case MIDI : |
rtk | 6:a31127c43225 | 46 | Afficher_Message("Midi"); |
rtk | 5:d879f538c159 | 47 | break; |
rtk | 5:d879f538c159 | 48 | case SOIR : |
rtk | 6:a31127c43225 | 49 | Afficher_Message("Soir"); |
rtk | 5:d879f538c159 | 50 | break; |
rtk | 5:d879f538c159 | 51 | case PETIT : |
rtk | 6:a31127c43225 | 52 | Afficher_Message("Petit dejeuner"); |
rtk | 5:d879f538c159 | 53 | break; |
rtk | 5:d879f538c159 | 54 | case DEJ : |
rtk | 6:a31127c43225 | 55 | Afficher_Message("Dejeuner"); |
rtk | 5:d879f538c159 | 56 | break; |
rtk | 5:d879f538c159 | 57 | case DINER : |
rtk | 6:a31127c43225 | 58 | Afficher_Message("Diner"); |
rtk | 5:d879f538c159 | 59 | break; |
chris | 2:507020c78d79 | 60 | } |
chris | 0:0325ecbd1916 | 61 | } |
chris | 0:0325ecbd1916 | 62 | |
rtk | 6:a31127c43225 | 63 | void Menu_Matin(int SousMenu) |
rtk | 5:d879f538c159 | 64 | { |
rtk | 6:a31127c43225 | 65 | //main |
rtk | 5:d879f538c159 | 66 | bool Sortir = false; // On sort du sous-menu |
rtk | 5:d879f538c159 | 67 | while (!Sortir) { |
rtk | 6:a31127c43225 | 68 | //while |
rtk | 6:a31127c43225 | 69 | Afficher_Menu(SousMenu); |
rtk | 6:a31127c43225 | 70 | |
rtk | 6:a31127c43225 | 71 | switch (SousMenu) { |
rtk | 6:a31127c43225 | 72 | //switch |
rtk | 5:d879f538c159 | 73 | case PETIT : |
rtk | 5:d879f538c159 | 74 | // évèments |
rtk | 5:d879f538c159 | 75 | if (left) { |
rtk | 6:a31127c43225 | 76 | menuPrincipal = MATIN; |
rtk | 5:d879f538c159 | 77 | Sortir=true; |
rtk | 5:d879f538c159 | 78 | } |
rtk | 6:a31127c43225 | 79 | if (right) SousMenu=DEJ; |
rtk | 6:a31127c43225 | 80 | if (center) { |
rtk | 6:a31127c43225 | 81 | Afficher_Message("Ok"); |
rtk | 6:a31127c43225 | 82 | AttendreNouvelAppuiCenter(); |
rtk | 6:a31127c43225 | 83 | } |
rtk | 5:d879f538c159 | 84 | break; |
rtk | 5:d879f538c159 | 85 | case DEJ : |
rtk | 5:d879f538c159 | 86 | // évèments |
rtk | 6:a31127c43225 | 87 | if (left) SousMenu=PETIT; |
rtk | 5:d879f538c159 | 88 | break; |
rtk | 5:d879f538c159 | 89 | case DINER : |
rtk | 6:a31127c43225 | 90 | break; |
rtk | 5:d879f538c159 | 91 | |
rtk | 6:a31127c43225 | 92 | }//switch |
rtk | 6:a31127c43225 | 93 | |
rtk | 5:d879f538c159 | 94 | |
rtk | 6:a31127c43225 | 95 | }//while |
rtk | 6:a31127c43225 | 96 | }//main |
rtk | 6:a31127c43225 | 97 | |
rtk | 6:a31127c43225 | 98 | |
rtk | 6:a31127c43225 | 99 | |
rtk | 6:a31127c43225 | 100 | |
rtk | 5:d879f538c159 | 101 | |
rtk | 5:d879f538c159 | 102 | int main() |
rtk | 5:d879f538c159 | 103 | { |
rtk | 5:d879f538c159 | 104 | while (1) { |
rtk | 6:a31127c43225 | 105 | Afficher_Menu(menuPrincipal); |
rtk | 6:a31127c43225 | 106 | switch (menuPrincipal) { |
rtk | 5:d879f538c159 | 107 | case MATIN : |
rtk | 5:d879f538c159 | 108 | // évèments |
rtk | 6:a31127c43225 | 109 | if (down) menuPrincipal = MIDI; |
rtk | 5:d879f538c159 | 110 | if (right) Menu_Matin(PETIT); |
rtk | 5:d879f538c159 | 111 | break; |
rtk | 5:d879f538c159 | 112 | case MIDI : |
rtk | 6:a31127c43225 | 113 | if (up) menuPrincipal = MATIN; |
rtk | 5:d879f538c159 | 114 | break; |
rtk | 5:d879f538c159 | 115 | case SOIR : |
rtk | 5:d879f538c159 | 116 | break; |
rtk | 5:d879f538c159 | 117 | } |
rtk | 5:d879f538c159 | 118 | |
rtk | 5:d879f538c159 | 119 | |
rtk | 5:d879f538c159 | 120 | } |
rtk | 5:d879f538c159 | 121 | |
rtk | 5:d879f538c159 | 122 | } |