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.
Dependencies: Terminal
testconsole.cpp
- Committer:
- iillyyaa
- Date:
- 2015-05-01
- Revision:
- 3:f308cd7a34ed
- Parent:
- 2:399e080c4909
- Child:
- 6:e992366d0684
File content as of revision 3:f308cd7a34ed:
#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;
}
Page* active_page = &page[current_page];
for(int index=0; index < active_page->num_menuitems; index++) {
MenuItem *item = &active_page->item[index];
if(active_page->command_letter[index] != cmd) continue;
if(item->type == menu) {
// for menuitems that goto other menus, just change the page
page_change(item->target_page);
} else if(item->action) {
// otherwise call the callaback
item->action->doAction();
}
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;
}