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
Diff: testconsole.cpp
- Revision:
- 0:907d2d5e77f7
- Child:
- 1:c6deb449c132
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/testconsole.cpp Fri May 01 03:56:34 2015 +0000
@@ -0,0 +1,84 @@
+#include "testconsole.h"
+
+TestConsole::TestConsole(const char * Name_p):
+ Name(Name_p),
+ num_pages(0),
+ current_page(0)
+{
+
+ term.printf("TestConsole::TestConsole('%')\n",Name);
+ page_change(current_page);
+ page[current_page].display();
+ }
+
+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){
+
+
+ for(int index=0; index < page[current_page].num_menuitems; index++){
+ if('x' == cmd) {
+ page_change(previous_page);
+ return 0;
+ }
+
+ 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;
+ }