Robert Tomczak
/
TP3_2021-Menu
BTS SNEC Menus
main.cpp@5:d879f538c159, 2021-10-10 (annotated)
- Committer:
- rtk
- Date:
- Sun Oct 10 14:26:20 2021 +0000
- Revision:
- 5:d879f538c159
- Parent:
- 4:dd6d3b44dcb9
- Child:
- 6:a31127c43225
BTS 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" |
chris | 0:0325ecbd1916 | 3 | |
chris | 0:0325ecbd1916 | 4 | |
chris | 0:0325ecbd1916 | 5 | |
rtk | 5:d879f538c159 | 6 | DigitalIn up(A2); |
rtk | 5:d879f538c159 | 7 | DigitalIn down(A3); |
rtk | 5:d879f538c159 | 8 | DigitalIn left(A4); |
rtk | 5:d879f538c159 | 9 | DigitalIn right(A5); |
rtk | 5:d879f538c159 | 10 | DigitalIn center(D4); |
rtk | 5:d879f538c159 | 11 | C12832 lcd(D11, D13, D12, D7, D10); |
rtk | 5:d879f538c159 | 12 | enum {MATIN,MIDI,SOIR, PETIT, DEJ,DINER} etat = MATIN; |
chris | 0:0325ecbd1916 | 13 | |
rtk | 5:d879f538c159 | 14 | int menu_precedent = MIDI; |
rtk | 5:d879f538c159 | 15 | char message_precedent[]=" "; |
rtk | 5:d879f538c159 | 16 | void Afficher_Menu(int Menu) |
rtk | 5:d879f538c159 | 17 | { |
rtk | 5:d879f538c159 | 18 | if (menu_precedent == Menu) return; |
rtk | 5:d879f538c159 | 19 | menu_precedent = Menu; |
rtk | 5:d879f538c159 | 20 | lcd.cls(); |
rtk | 5:d879f538c159 | 21 | lcd.locate(0,8); |
rtk | 5:d879f538c159 | 22 | //wait(0.050); |
rtk | 5:d879f538c159 | 23 | switch(Menu) { |
rtk | 5:d879f538c159 | 24 | case MATIN : |
rtk | 5:d879f538c159 | 25 | lcd.printf("Matin"); |
rtk | 5:d879f538c159 | 26 | break; |
rtk | 5:d879f538c159 | 27 | case MIDI : |
rtk | 5:d879f538c159 | 28 | lcd.printf("Midi"); |
rtk | 5:d879f538c159 | 29 | break; |
rtk | 5:d879f538c159 | 30 | case SOIR : |
rtk | 5:d879f538c159 | 31 | lcd.printf("Soir"); |
rtk | 5:d879f538c159 | 32 | break; |
rtk | 5:d879f538c159 | 33 | case PETIT : |
rtk | 5:d879f538c159 | 34 | lcd.printf("Petit dejeuner"); |
rtk | 5:d879f538c159 | 35 | break; |
rtk | 5:d879f538c159 | 36 | case DEJ : |
rtk | 5:d879f538c159 | 37 | lcd.printf("Dejeuner"); |
rtk | 5:d879f538c159 | 38 | break; |
rtk | 5:d879f538c159 | 39 | case DINER : |
rtk | 5:d879f538c159 | 40 | lcd.printf("Diner"); |
rtk | 5:d879f538c159 | 41 | break; |
chris | 2:507020c78d79 | 42 | } |
chris | 0:0325ecbd1916 | 43 | } |
chris | 0:0325ecbd1916 | 44 | |
rtk | 5:d879f538c159 | 45 | void Afficher_Message(char *Message) |
rtk | 5:d879f538c159 | 46 | { |
rtk | 5:d879f538c159 | 47 | if (strcmp(message_precedent,Message) ==0) return; |
rtk | 5:d879f538c159 | 48 | lcd.cls(); |
rtk | 5:d879f538c159 | 49 | lcd.locate(0,8); |
rtk | 5:d879f538c159 | 50 | lcd.printf(Message); |
chris | 0:0325ecbd1916 | 51 | |
rtk | 5:d879f538c159 | 52 | } |
rtk | 5:d879f538c159 | 53 | |
rtk | 5:d879f538c159 | 54 | void Menu_Matin(int etat) |
rtk | 5:d879f538c159 | 55 | { |
rtk | 5:d879f538c159 | 56 | bool Sortir = false; // On sort du sous-menu |
rtk | 5:d879f538c159 | 57 | while (!Sortir) { |
rtk | 5:d879f538c159 | 58 | Afficher_Menu(etat); |
rtk | 5:d879f538c159 | 59 | switch (etat) { |
rtk | 5:d879f538c159 | 60 | case PETIT : |
rtk | 5:d879f538c159 | 61 | // évèments |
rtk | 5:d879f538c159 | 62 | if (left) { |
rtk | 5:d879f538c159 | 63 | etat = MATIN; |
rtk | 5:d879f538c159 | 64 | Sortir=true; |
rtk | 5:d879f538c159 | 65 | } |
rtk | 5:d879f538c159 | 66 | if (right) etat=DEJ; |
rtk | 5:d879f538c159 | 67 | if (center)Afficher_Message("Ok"); |
rtk | 5:d879f538c159 | 68 | break; |
rtk | 5:d879f538c159 | 69 | case DEJ : |
rtk | 5:d879f538c159 | 70 | // évèments |
rtk | 5:d879f538c159 | 71 | break; |
rtk | 5:d879f538c159 | 72 | case DINER : |
rtk | 5:d879f538c159 | 73 | |
rtk | 5:d879f538c159 | 74 | } |
rtk | 5:d879f538c159 | 75 | wait(0.125); |
rtk | 5:d879f538c159 | 76 | |
rtk | 5:d879f538c159 | 77 | } |
rtk | 5:d879f538c159 | 78 | } |
rtk | 5:d879f538c159 | 79 | |
rtk | 5:d879f538c159 | 80 | int main() |
rtk | 5:d879f538c159 | 81 | { |
rtk | 5:d879f538c159 | 82 | while (1) { |
rtk | 5:d879f538c159 | 83 | Afficher_Menu(etat); |
rtk | 5:d879f538c159 | 84 | switch (etat) { |
rtk | 5:d879f538c159 | 85 | case MATIN : |
rtk | 5:d879f538c159 | 86 | // évèments |
rtk | 5:d879f538c159 | 87 | if (down) etat = MIDI; |
rtk | 5:d879f538c159 | 88 | if (right) Menu_Matin(PETIT); |
rtk | 5:d879f538c159 | 89 | break; |
rtk | 5:d879f538c159 | 90 | case MIDI : |
rtk | 5:d879f538c159 | 91 | break; |
rtk | 5:d879f538c159 | 92 | case SOIR : |
rtk | 5:d879f538c159 | 93 | break; |
rtk | 5:d879f538c159 | 94 | } |
rtk | 5:d879f538c159 | 95 | |
rtk | 5:d879f538c159 | 96 | |
rtk | 5:d879f538c159 | 97 | } |
rtk | 5:d879f538c159 | 98 | |
rtk | 5:d879f538c159 | 99 | } |