Menu system broken
Dependencies: ANSITermMenuSystem
Fork of menuSystemMbed by
Revision 0:a5ece7312edc, committed 2013-02-28
- Comitter:
- mbedDevLondon
- Date:
- Thu Feb 28 00:38:31 2013 +0000
- Child:
- 1:a3b65af969d4
- Commit message:
- initial port to mbed
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ANSITerm.lib Thu Feb 28 00:38:31 2013 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/dansummers/code/ANSITerm/#a681bda60db7
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HANDLER_FilterPage.cpp Thu Feb 28 00:38:31 2013 +0000 @@ -0,0 +1,76 @@ +#include "mbed.h" + +#include "menuIDs.h" +#include "MainMenu.h" +#include "console.h" + +extern BusInOut switches; //(p21, p22, p23, p24) +extern MainMenu pageMenu[12]; + + +int FilterPageHandler() +{ + int userSelection = 0; + pageMenu[FILTER].printMenu(); + + unsigned char lastState = 0x0f; //0000 1111 + bool exitCurrentMenu = false; + + while ( exitCurrentMenu == false) + { + + unsigned char currentState = switches.read(); //reading a port add a AND MASK & 0b00000111 + wait_ms(10); + if( currentState == switches.read() && currentState != lastState) + { + lastState = currentState; + switch(currentState) + { + case 0x0e: + pageMenu[FILTER].erase(); + printXY(" ", 5, 10); //erases the ACTION prompt + userSelection = RECORDSET; + exitCurrentMenu = true; + break; + case 0x0d: + pageMenu[FILTER].highlightPrevItem(); + break; + case 0x0b: + pageMenu[FILTER].highlightNextItem(); + break; + case 0x07: + userSelection = pageMenu[FILTER].getHighlightedItem() ; + break; + }//eo select + + // is hte user selection an ACTION assigned to this page + if (userSelection != 0 && userSelection > FILTEROFFSET) //page selections are 0 through 12 + { + // place code here to handle actions processed directly from this page + switch(userSelection) + { + case FILTER1: + printXY("Filter 1 selected ", 5, 10); + //call function to perform task + break; + case FILTER2: + printXY("FIlter 2 selected ",5,10); + //call function to perform task + break; + case FILTER3: + printXY("Filter 3 selected ", 5, 10); + //call function to perform task + break; + case FILTERNONE: + printXY("No filter selected ",5,10); + //call function to perform task + break; + } + // eo place code here ...... + userSelection = 0; + } + wait_ms(200); + }//eo if kbhit + }//eo while + return userSelection; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HANDLER_HomePage.cpp Thu Feb 28 00:38:31 2013 +0000 @@ -0,0 +1,49 @@ +#include "mbed.h" + +#include "menuIDs.h" +#include "MainMenu.h" + + +extern BusInOut switches; //(p21, p22, p23, p24) +extern MainMenu pageMenu[12]; + +int homePageHandler() +{ + int userSelection = 0; + pageMenu[HOME].printMenu(); + + unsigned char lastState = 0x0f; //0000 1111 + bool exitCurrentMenu = false; + + while ( exitCurrentMenu == false) + { + + unsigned char currentState = switches.read(); //reading a port add a AND MASK & 0b00000111 + wait_ms(10); + if( currentState == switches.read() && currentState != lastState) + { + lastState = currentState; + switch(currentState) + { + case 0x0e: + pageMenu[HOME].erase(); + userSelection = HOME; + exitCurrentMenu = true; + break; + case 0x0d: + pageMenu[HOME].highlightPrevItem(); + break; + case 0x0b: + pageMenu[HOME].highlightNextItem(); + break; + case 0x07: + pageMenu[HOME].erase(); + userSelection = pageMenu[HOME].getHighlightedItem(); + exitCurrentMenu = true; + break; + }//eo select + wait_ms(200); + }//eo if switch press detected + }//eo while + return userSelection; +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HANDLER_InputPage.cpp Thu Feb 28 00:38:31 2013 +0000 @@ -0,0 +1,68 @@ +#include "mbed.h" + +#include "menuIDs.h" +#include "MainMenu.h" +#include "console.h" + +extern BusInOut switches; //(p21, p22, p23, p24) +extern MainMenu pageMenu[12]; + + +int InputPageHandler() +{ + int userSelection = 0; + pageMenu[INPUT].printMenu(); + + unsigned char lastState = 0x0f; //0000 1111 + bool exitCurrentMenu = false; + + while ( exitCurrentMenu == false) + { + + unsigned char currentState = switches.read(); //reading a port add a AND MASK & 0b00000111 + wait_ms(10); + if( currentState == switches.read() && currentState != lastState) + { + lastState = currentState; + switch(currentState) + { + case 0x0e: + pageMenu[INPUT].erase(); + printXY(" ", 5, 10); //erases the ACTION prompt + userSelection = RECORDSET; + exitCurrentMenu = true; + break; + case 0x0d: + pageMenu[INPUT].highlightPrevItem(); + break; + case 0x0b: + pageMenu[INPUT].highlightNextItem(); + break; + case 0x07: + userSelection = pageMenu[INPUT].getHighlightedItem() ; + break; + }//eo select + + // is the user selection an ACTION assigned to this page + if (userSelection != 0 && userSelection > INPUTOFFSET) //page selections are 0 through 12 + { + // place code here to handle actions processed directly from this page + switch(userSelection) + { + case INMIC: + printXY("Mic selected ", 5, 10); + //call function to perform task + break; + case INLINE: + printXY("Line selected ",5,10); + //call function to perform task + break; + } + // eo place code here ...... + userSelection = 0; + } + wait_ms(200); + }//eo if kbhit + }//eo while + return userSelection; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HANDLER_OutputPage.cpp Thu Feb 28 00:38:31 2013 +0000 @@ -0,0 +1,72 @@ +#include "mbed.h" + +#include "menuIDs.h" +#include "MainMenu.h" +#include "console.h" + +extern BusInOut switches; //(p21, p22, p23, p24) +extern MainMenu pageMenu[12]; + + +int OutputPageHandler() +{ + int userSelection = 0; + pageMenu[OUTPUT].printMenu(); + + unsigned char lastState = 0x0f; //0000 1111 + bool exitCurrentMenu = false; + + while ( exitCurrentMenu == false) + { + + unsigned char currentState = switches.read(); //reading a port add a AND MASK & 0b00000111 + wait_ms(10); + if( currentState == switches.read() && currentState != lastState) + { + lastState = currentState; + switch(currentState) + { + case 0x0e: + pageMenu[OUTPUT].erase(); + printXY(" ", 5, 10); + userSelection = RECORDSET; + exitCurrentMenu = true; + break; + case 0x0d: + pageMenu[OUTPUT].highlightPrevItem(); + break; + case 0x0b: + pageMenu[OUTPUT].highlightNextItem(); + break; + case 0x07: + userSelection = pageMenu[OUTPUT].getHighlightedItem() ; + break; + }//eo select + + + if (userSelection != 0 && userSelection != RECORDSET) + { + // place code here to handle actions processed directly from this page + switch(userSelection) + { + case LINE: + printXY("Line selected ", 5, 10); + //call function to perform task + break; + case HEADPHONES: + printXY("Headphones selected ",5,10); + //call function to perform task + break; + case SPEAKERS: + printXY("Speakers selected ", 5, 10); + //call function to perform task + break; + } + // eo place code here ...... + userSelection = 0; + } + wait_ms(200); + }//eo if kbhit + }//eo while + return userSelection; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HANDLER_RecordSettings.cpp Thu Feb 28 00:38:31 2013 +0000 @@ -0,0 +1,49 @@ +#include "mbed.h" + +#include "menuIDs.h" +#include "MainMenu.h" +#include "console.h" + +extern BusInOut switches; //(p21, p22, p23, p24) +extern MainMenu pageMenu[12]; + +int RecordSettingsHandler() +{ + int userSelection = 0; + pageMenu[RECORDSET].printMenu(); + + unsigned char lastState = 0x0f; //0000 1111 + bool exitCurrentMenu = false; + + while ( exitCurrentMenu == false) + { + + unsigned char currentState = switches.read(); //reading a port add a AND MASK & 0b00000111 + wait_ms(10); + if( currentState == switches.read() && currentState != lastState) + { + lastState = currentState; + switch(currentState) + { + case 0x0e: + pageMenu[RECORDSET].erase(); + userSelection = HOME; + exitCurrentMenu = true; + break; + case 0x0d: + pageMenu[RECORDSET].highlightPrevItem(); + break; + case 0x0b: + pageMenu[RECORDSET].highlightNextItem(); + break; + case 0x07: + pageMenu[RECORDSET].erase(); + userSelection = pageMenu[RECORDSET].getHighlightedItem() - RECSETOFFSET; + exitCurrentMenu = true; + break; + }//eo select + wait_ms(200); + }//eo if kbhit + }//eo while + return userSelection; +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/InitializeMenus.cpp Thu Feb 28 00:38:31 2013 +0000 @@ -0,0 +1,37 @@ + + +#include "menuIDs.h" +#include "MainMenu.h" + +extern MainMenu pageMenu[12]; + +void initializeMenuSystem() +{ + pageMenu[HOME].setMenuItem(0, RECORDSET, "Record Settings", 5, 2); + pageMenu[HOME].setMenuItem(1, PLAYBACK, "Playback", 5, 3); + pageMenu[HOME].setMenuItem(2, SCREENSET, "Screen Settings", 5, 4); + pageMenu[HOME].setMaxItems(3); + + pageMenu[RECORDSET].setMenuItem(0, RECSETOUT, "Output", 5, 2); + pageMenu[RECORDSET].setMenuItem(1, RECSETIN, "Input", 5, 3); + pageMenu[RECORDSET].setMenuItem(2, RECSETFILTERS, "Filters", 5, 4); + pageMenu[RECORDSET].setMenuItem(3, RECSETSAMPFRQ, "Sampling Freq", 5, 5); + pageMenu[RECORDSET].setMenuItem(4, RECSETAGC, "AGC", 5, 6); + pageMenu[RECORDSET].setMaxItems(5); + + pageMenu[OUTPUT].setMenuItem(0, LINE, "Line", 5, 2); + pageMenu[OUTPUT].setMenuItem(1, HEADPHONES, "Headphones", 5, 3); + pageMenu[OUTPUT].setMenuItem(2, SPEAKERS, "Speakers", 5, 4); + pageMenu[OUTPUT].setMaxItems(3); + + pageMenu[INPUT].setMenuItem(0, INMIC, "Mic", 5, 2); + pageMenu[INPUT].setMenuItem(1, INLINE, "Line", 5, 3); + pageMenu[INPUT].setMaxItems(2); + + pageMenu[FILTER].setMenuItem(0, FILTER1, "Low Pass", 5, 2); + pageMenu[FILTER].setMenuItem(1, FILTER2, "High Pass", 5, 3); + pageMenu[FILTER].setMenuItem(2, FILTER3, "Band Pass", 5, 4); + pageMenu[FILTER].setMenuItem(3, FILTERNONE, "None", 5, 5); + pageMenu[FILTER].setMaxItems(4); + +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MainMenu.cpp Thu Feb 28 00:38:31 2013 +0000 @@ -0,0 +1,70 @@ +// +// MainMenu.cpp +// menuSystem +// +// Created by BradDSmith on 2013-02-26. +// Copyright (c) 2013 BradDSmith. All rights reserved. +// + +#include "MainMenu.h" + +#include "console.h" + +MainMenu::MainMenu() +{ + highlightedItem = 0; + maxitems = MAXITEMS; +} + +void MainMenu::setMaxItems(int max) +{ + maxitems = max; +} + +void MainMenu::setMenuItem(int locID, int menuID, const char * menuText, int x, int y) +{ + if(locID <maxitems){ + menuItem[locID].initialize(menuID, (char *)menuText,x, y); + } +} + +void MainMenu::printMenu() +{ + for (int i = 0; i < maxitems; i++) { + menuItem[i].print(); + } + + menuItem[highlightedItem].highlight(); +} + +void MainMenu::highlightNextItem() +{ + menuItem[highlightedItem].removeHighLight(); + + highlightedItem++; + if(highlightedItem >= maxitems)highlightedItem = 0; + + menuItem[highlightedItem].highlight(); +} + +void MainMenu::highlightPrevItem() +{ + menuItem[highlightedItem].removeHighLight(); + + highlightedItem--; + if(highlightedItem < 0)highlightedItem = maxitems - 1 ; + + menuItem[highlightedItem].highlight(); +} + +int MainMenu::getHighlightedItem() +{ + return menuItem[highlightedItem].getMenuID(); +} + +void MainMenu::erase() +{ + for (int i = 0; i < maxitems; i++) { + menuItem[i].erase(); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MainMenu.h Thu Feb 28 00:38:31 2013 +0000 @@ -0,0 +1,31 @@ +// +// MainMenu.h +// menuSystem +// +// Created by BradDSmith on 2013-02-26. +// Copyright (c) 2013 BradDSmith. All rights reserved. +// + +#ifndef __menuSystem__MainMenu__ +#define __menuSystem__MainMenu__ + +#include "menuItem.h" + +class MainMenu { + static const int MAXITEMS = 5; + menuItem menuItem[MAXITEMS]; + int highlightedItem; + int maxitems; + +public: + MainMenu(); + void setMaxItems(int max); + void setMenuItem(int locID, int menuID,const char * menuText, int x, int y); + void highlightNextItem(); + void highlightPrevItem(); + void printMenu(); + int getHighlightedItem(); + void erase(); +}; + +#endif /* defined(__menuSystem__MainMenu__) */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/XYPoint.cpp Thu Feb 28 00:38:31 2013 +0000 @@ -0,0 +1,26 @@ +// +// XYPoint.cpp +// menuSystem +// +// Created by BradDSmith on 2013-02-26. +// Copyright (c) 2013 BradDSmith. All rights reserved. +// + +#include "XYPoint.h" + +XYPoint::XYPoint() +{ + X = 0; + Y = 0; +} + +XYPoint::XYPoint( int x, int y) +{ + X = x; + Y = y; + +} + + + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/XYPoint.h Thu Feb 28 00:38:31 2013 +0000 @@ -0,0 +1,24 @@ +// +// XYPoint.h +// menuSystem +// +// Created by BradDSmith on 2013-02-26. +// Copyright (c) 2013 BradDSmith. All rights reserved. +// + +#ifndef __menuSystem__XYPoint__ +#define __menuSystem__XYPoint__ + + +class XYPoint { +public: + int X; + int Y; + +public: + XYPoint( int x, int y); + XYPoint(); + +}; + +#endif /* defined(__menuSystem__XYPoint__) */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/console.cpp Thu Feb 28 00:38:31 2013 +0000 @@ -0,0 +1,101 @@ +// console.cpp +// + +#include "console.h" +#include "ANSITerm.h" + +using namespace std; + + +extern ANSITerm pc; + +// +// Clears the screen +// +void clrscr() +{ + pc.clear_screen(); +} + +// +// Moves the cursor to x, y in console window +// ie x=left\right y=top\bottom +// +void gotoxy(int x, int y) +{ + pc.set_cursor_position(x,y); +} + +void printXY( char * text, int x, int y) +{ + static bool runOnce = false; + if (runOnce == false){ + clrscr(); + runOnce = true; + } + + gotoxy( x, y); + pc.printf("%s", text); +} + +// +// Set text and background colors +// +void setrgb(int color) +{ + switch (color) + { + case 0: // White on Black + + break; + case 1: // Red on Black + + break; + case 2: // Green on Black + + break; + case 3: // Yellow on Black + + break; + case 4: // Blue on Black + + break; + case 5: // Magenta on Black + + break; + case 6: // Cyan on Black + + break; + case 7: // Black on Gray + + break; + case 8: // Black on White + + break; + case 9: // Red on White + + break; + case 10: // Green on White + + break; + case 11: // Yellow on White + + break; + case 12: // Blue on White + + break; + case 13: // Magenta on White + + break; + case 14: // Cyan on White + + break; + case 15: // White on White + + break; + default : // White on Black + + break; + } +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/console.h Thu Feb 28 00:38:31 2013 +0000 @@ -0,0 +1,17 @@ +// console.h +// +#ifndef CONSOLE_H +#define CONSOLE_H + +#include <iostream> +#include <iomanip> +#include <cmath> +#include <cstdlib> + + +void clrscr(); +void gotoxy(int, int); +void printXY( char * text, int x, int y); +void setrgb(int); + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/menuIDs.h Thu Feb 28 00:38:31 2013 +0000 @@ -0,0 +1,52 @@ +#ifndef __menuSystem__MenuIDs__ +#define __menuSystem__MenuIDs__ + +#define UNASSIGNED 99 + +//PAGE IDs +#define HOME 0 +#define RECORDSET 1 +#define OUTPUT 2 +#define INPUT 3 +#define FILTER 4 +#define SAMPRATE 5 +#define AGC 6 +#define PLAYBACK 7 +#define PLAY 8 +#define DELETESCR 9 +#define SCREENSET 10 +#define CONTRAST 11 + + +//RECORD SETTINGS MENU IDs +#define RECSETOFFSET 100 +#define RECSETOUT 102 +#define RECSETIN 103 +#define RECSETFILTERS 104 +#define RECSETSAMPFRQ 105 +#define RECSETAGC 106 + +//OUTPUT MENU IDs + +#define LINE 201 +#define HEADPHONES 202 +#define SPEAKERS 203 + + +//INPUT MENU IDs +#define INPUTOFFSET 300 +#define INMIC 301 +#define INLINE 302 + +//FILTER MENU IDs +#define FILTEROFFSET 400 +#define FILTER1 401 +#define FILTER2 402 +#define FILTER3 403 +#define FILTERNONE 404 + + + + + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/menuItem.cpp Thu Feb 28 00:38:31 2013 +0000 @@ -0,0 +1,64 @@ +// +// menuItem.cpp +// menuSystem +// +// Created by BradDSmith on 2013-02-26. +// Copyright (c) 2013 BradDSmith. All rights reserved. +// + +#include "menuItem.h" +#include "console.h" + +menuItem::menuItem():Text("EMPTY") +{ + + +} + +void menuItem::initialize( int ID, const char * text, int x, int y) +{ + menuID = ID; + setText( (char *) text); + setPosition(x,y); +} + +void menuItem::setText( char * menuText) +{ + Text.assign(menuText); +} + +void menuItem::setPosition(int x, int y) +{ + position.X = x; + position.Y = y; +} + +void menuItem::print() +{ + const char * msg = Text.c_str(); + printXY( (char *)msg, position.X, position.Y); + +} +void menuItem::erase() +{ + printXY (" ", position.X - 2, position.Y); +} + +void menuItem::highlight() +{ + printXY ("X", position.X - 2, position.Y); + gotoxy( position.X - 2, position.Y); +} + +void menuItem::removeHighLight() +{ + printXY (" ", position.X - 2, position.Y); + +} + +int menuItem::getMenuID() +{ + return menuID; +} + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/menuItem.h Thu Feb 28 00:38:31 2013 +0000 @@ -0,0 +1,36 @@ +// +// menuItem.h +// menuSystem +// +// Created by BradDSmith on 2013-02-26. +// Copyright (c) 2013 BradDSmith. All rights reserved. +// + +#ifndef __menuSystem__menuItem__ +#define __menuSystem__menuItem__ + +#include <string> + +using namespace std; + +#include "XYPoint.h" + +class menuItem { + int menuID; + XYPoint position; + string Text; + +public: + menuItem(); + void initialize( int ID, const char * text, int x, int y); + void setText( char *); + void setPosition(int x, int y); + void print(); + void highlight(); + void removeHighLight(); + int getMenuID(); + void erase(); +}; + + +#endif /* defined(__menuSystem__menuItem__) */