Library which creates a serial test console, it supports pages and menu items. The items are added and the pages are added as necessary when the user sets it up. This is a great too for creating an easy to maintain menu system, whether for a test sytem, or anything else.
Dependencies: Terminal
testconsole.cpp
- Committer:
- glansberry
- Date:
- 2015-05-01
- Revision:
- 2:399e080c4909
- Parent:
- 1:c6deb449c132
- Child:
- 3:f308cd7a34ed
File content as of revision 2:399e080c4909:
#include "testconsole.h" TestConsole::TestConsole(const char * Name_p): Name(Name_p), num_pages(0), current_page(0) { // term.printf("TestConsole::TestConsole('%')\n",Name); term.HideCursor(); page_change(current_page); } Page& TestConsole::add_page(Page const &page_p){ term.printf("TestConsole::add_page\n"); if(num_pages < MAX_PAGES) { page[num_pages] = page_p; page[num_pages].page_num = num_pages; //let the page know what number it is to help with lookups if(num_pages == 0) { //if this is the first page, set it active page[num_pages].set_active(); } term.printf("Added page '%s'\n", page[num_pages].Name); return page[num_pages++]; } term.printf("Failed to add page'%s'\n", page_p.Name); return page[MAX_PAGES-1]; //return 0 if no error } int TestConsole::page_change(int new_page){ previous_page = current_page; //save a copy of the page so we can go back current_page = new_page; page[current_page].display(); page[current_page].ack_active(); return current_page; } //here, using knowledge of the page, we process commands int TestConsole::process_cmd(char cmd){ if('x' == cmd) { page_change(previous_page); return 0; } for(int index=0; index < page[current_page].num_menuitems; index++){ if(page[current_page].command_letter[index] == cmd) { //for menuitems that goto other menus, just change the page if(page[current_page].item[index].type == menu) { page_change(page[current_page].item[index].target_page); return 0; } //otherwise call the callaback page[current_page].item[index].callback(true); return 0; } } return 1; } int TestConsole::tick(void){ if (term.readable()){ //if there is a character if(process_cmd(term.getc())){ term.locate(TERM_LOC_FEEDBACK); term.printf("invalid command"); } } //go through the list of pages, and see if any want to become active for(int index=0; index < page[current_page].num_menuitems; index++){ if(page[index].check_active()) page_change(index); } page[current_page].update(); return 0; }