Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of Menu by
Navigator.cpp
00001 #include "Navigator.h" 00002 00003 Navigator::Navigator(Menu *root, TextLCD *lcd) : 00004 root(root), activeMenu(root), _lcd(lcd) { 00005 cursorPos = 0; 00006 printMenu(); 00007 } 00008 00009 void Navigator::printMenu() { 00010 _lcd->cls(); 00011 _lcd->printf("%s\n", activeMenu->menuID); 00012 _lcd->printf(">%s\n", activeMenu->selections[cursorPos].selText); 00013 } 00014 00015 void Navigator::actionNone() { 00016 if (_lastAction != none) { 00017 00018 } 00019 _lastAction = none; 00020 } 00021 00022 void Navigator::actionUp() { 00023 if (_lastAction != up) { 00024 if (cursorPos > 0) { 00025 cursorPos--; 00026 printMenu(); 00027 } 00028 } 00029 _lastAction = up; 00030 } 00031 00032 void Navigator::actionDown() { 00033 if (_lastAction != down) { 00034 if (cursorPos < (activeMenu->selections.size() - 1)) { 00035 cursorPos++; 00036 printMenu(); 00037 } 00038 } 00039 _lastAction = down; 00040 } 00041 00042 void Navigator::actionBack() { 00043 if (_lastAction != back) { 00044 if (activeMenu->parent != NULL) { 00045 activeMenu = activeMenu->parent; 00046 cursorPos = 0; 00047 printMenu(); 00048 } 00049 } 00050 _lastAction = back; 00051 } 00052 00053 void Navigator::actionEnter() { 00054 if (_lastAction != enter) { 00055 if (activeMenu->selections[cursorPos].fun != NULL) { 00056 activeMenu->selections[cursorPos].fun->call(); 00057 printMenu(); 00058 } 00059 if (activeMenu->selections[cursorPos].childMenu != NULL) { 00060 activeMenu = activeMenu->selections[cursorPos].childMenu; 00061 cursorPos = 0; 00062 printMenu(); 00063 } 00064 } 00065 _lastAction = enter; 00066 } 00067 00068 void Navigator::actionHome() { 00069 if (_lastAction != home) { 00070 activeMenu = root; 00071 cursorPos = 0; 00072 printMenu(); 00073 } 00074 _lastAction = home; 00075 }
Generated on Sat Jul 23 2022 03:26:07 by
1.7.2
