![](/media/cache/profiles/2012_sf_avc_095.jpg.50x50_q85.jpg)
Code for autonomous rover for Sparkfun AVC. DataBus won 3rd in 2012 and the same code was used on Troubled Child, a 1986 Jeep Grand Wagoneer to win 1st in 2014.
Dependencies: mbed Watchdog SDFileSystem DigoleSerialDisp
Diff: UI/Menu/Menu.cpp
- Revision:
- 0:a6a169de725f
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/UI/Menu/Menu.cpp Mon May 27 13:26:03 2013 +0000 @@ -0,0 +1,62 @@ +#include "mbed.h" +#include "Menu.h" +#include <string.h> + +Menu::Menu(): + _item(0), _itemCount(0) +{ +} + +void Menu::add(char *name, FunctionPtr f) +{ + if (_itemCount < _ITEM_MAX) { + _exec[_itemCount] = f; + strncpy(_name[_itemCount], name, NAMESIZ-1); + _itemCount++; + } + + return; +} + +void Menu::next() +{ + _item++; + if (_item >= _itemCount) _item = 0; + + return; +} + +void Menu::prev() +{ + if (_item == 0) _item = _itemCount; + _item--; + + return; +} + +void Menu::select() +{ + (_exec[_item])(); +} + +char *Menu::getItemName(int i) +{ + return _name[i]; +} + + +char *Menu::getItemName() +{ + return _name[_item]; +} + +void Menu::printAll() +{ + fprintf(stdout, "Menus:\n"); + for (int i=0; i < _itemCount; i++) { + fprintf(stdout, "%s\n", _name[i]); + } + fprintf(stdout, "\n"); + + return; +} \ No newline at end of file