Team Alpha / Mbed 2 deprecated UserIntefaceLCD

Dependencies:   mbed mbed-rtos MLX90614

Committer:
ovidiup13
Date:
Sun Apr 26 16:29:53 2015 +0000
Revision:
3:688b62ff6474
Parent:
2:fcde41900fa5
Child:
4:024e6a9c2ebf
added screens for interacting with other components. i.e. distance, thermo, gyro, compass, etc. Need to complete settings screen and create threads for interacting with other code

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ovidiup13 0:1e597b0f8b3b 1 #include "Menu.h"
ovidiup13 0:1e597b0f8b3b 2
ovidiup13 0:1e597b0f8b3b 3 void Menu::display(void){
ovidiup13 3:688b62ff6474 4 //display items
ovidiup13 0:1e597b0f8b3b 5 display_items(0); //display items starting from index 0
ovidiup13 0:1e597b0f8b3b 6 }
ovidiup13 0:1e597b0f8b3b 7
ovidiup13 0:1e597b0f8b3b 8 void Menu::update(char c){
ovidiup13 0:1e597b0f8b3b 9 //case down
ovidiup13 0:1e597b0f8b3b 10 if(c == DOWN){
ovidiup13 0:1e597b0f8b3b 11 //if last item already selected, do nothing
ovidiup13 0:1e597b0f8b3b 12 if(selected + 1 == size)
ovidiup13 0:1e597b0f8b3b 13 return; //do nothing
ovidiup13 0:1e597b0f8b3b 14
ovidiup13 0:1e597b0f8b3b 15 //if we are at the bottom of the screen
ovidiup13 0:1e597b0f8b3b 16 if(current_line % LAST_ITEM_LINE == 0){
ovidiup13 0:1e597b0f8b3b 17 // more items left => clear screen and add items
ovidiup13 0:1e597b0f8b3b 18 selected++;
ovidiup13 0:1e597b0f8b3b 19 //display items from the next selected item
ovidiup13 0:1e597b0f8b3b 20 current_line = FIRST_ITEM_LINE; //current selected line will be top of screen
ovidiup13 0:1e597b0f8b3b 21 printf("got down, selected is: %d; current line is: %d\n", selected, current_line);
ovidiup13 0:1e597b0f8b3b 22 }
ovidiup13 0:1e597b0f8b3b 23 //it is not last on the screen
ovidiup13 0:1e597b0f8b3b 24 else{
ovidiup13 0:1e597b0f8b3b 25 //clear the screen
ovidiup13 0:1e597b0f8b3b 26 current_line++;
ovidiup13 0:1e597b0f8b3b 27 selected++;
ovidiup13 0:1e597b0f8b3b 28 printf("selected is: %d; current line is: %d\n", selected, current_line);
ovidiup13 0:1e597b0f8b3b 29 }
ovidiup13 0:1e597b0f8b3b 30 st7565->clear();
ovidiup13 2:fcde41900fa5 31 display_items(selected/ITEMS_PER_SCREEN * ITEMS_PER_SCREEN);
ovidiup13 0:1e597b0f8b3b 32 return;
ovidiup13 0:1e597b0f8b3b 33 }
ovidiup13 0:1e597b0f8b3b 34 //case up
ovidiup13 0:1e597b0f8b3b 35 else if(c == UP){
ovidiup13 0:1e597b0f8b3b 36 //we are at top of items
ovidiup13 0:1e597b0f8b3b 37 if(selected == 0)
ovidiup13 0:1e597b0f8b3b 38 return; //do nothing
ovidiup13 0:1e597b0f8b3b 39
ovidiup13 0:1e597b0f8b3b 40 //if we are at the top of the screen => there are more items to show
ovidiup13 0:1e597b0f8b3b 41 if(current_line == FIRST_ITEM_LINE){
ovidiup13 0:1e597b0f8b3b 42 selected--;
ovidiup13 0:1e597b0f8b3b 43 //display items from the next selected item
ovidiup13 0:1e597b0f8b3b 44 current_line = LAST_ITEM_LINE; //current selected line will be top of screen
ovidiup13 0:1e597b0f8b3b 45 }
ovidiup13 0:1e597b0f8b3b 46 //it is not first on the screen
ovidiup13 0:1e597b0f8b3b 47 else{
ovidiup13 0:1e597b0f8b3b 48 current_line--;
ovidiup13 0:1e597b0f8b3b 49 selected--;
ovidiup13 0:1e597b0f8b3b 50 }
ovidiup13 0:1e597b0f8b3b 51 st7565->clear();
ovidiup13 2:fcde41900fa5 52 display_items(selected/ITEMS_PER_SCREEN * ITEMS_PER_SCREEN);
ovidiup13 0:1e597b0f8b3b 53 return;
ovidiup13 0:1e597b0f8b3b 54 }
ovidiup13 0:1e597b0f8b3b 55 else if(c == NL && items[selected]->isSelectable){
ovidiup13 3:688b62ff6474 56 //set selected screen so that UI knows which screen we selected to display
ovidiup13 3:688b62ff6474 57 this->setSelectedScreen(items[selected]);
ovidiup13 0:1e597b0f8b3b 58 }
ovidiup13 0:1e597b0f8b3b 59 }
ovidiup13 0:1e597b0f8b3b 60
ovidiup13 0:1e597b0f8b3b 61 void Menu::addItem(Item * i){
ovidiup13 0:1e597b0f8b3b 62 //if there are many items, ignore
ovidiup13 0:1e597b0f8b3b 63 if(size == MAX_ITEMS)
ovidiup13 0:1e597b0f8b3b 64 return;
ovidiup13 0:1e597b0f8b3b 65 //add pointer to item
ovidiup13 0:1e597b0f8b3b 66 items[size] = i;
ovidiup13 0:1e597b0f8b3b 67 size++;
ovidiup13 0:1e597b0f8b3b 68 isSelectable = true;
ovidiup13 0:1e597b0f8b3b 69 }
ovidiup13 0:1e597b0f8b3b 70
ovidiup13 0:1e597b0f8b3b 71 /*
ovidiup13 0:1e597b0f8b3b 72 Function that displays items on a new screen starting from an index.
ovidiup13 0:1e597b0f8b3b 73 */
ovidiup13 0:1e597b0f8b3b 74 void Menu::display_items(int index){
ovidiup13 0:1e597b0f8b3b 75 //draw title of menu
ovidiup13 0:1e597b0f8b3b 76 //display 1 or more items on the screen
ovidiup13 0:1e597b0f8b3b 77 int i = FIRST_ITEM_LINE, j;
ovidiup13 0:1e597b0f8b3b 78 //draw the first items
ovidiup13 0:1e597b0f8b3b 79 for(j = index; j < size && i <= LAST_ITEM_LINE; j++)
ovidiup13 2:fcde41900fa5 80 st7565->drawstring(LEFT_MARGIN * 2, i++, items[j]->getTitle());
ovidiup13 0:1e597b0f8b3b 81
ovidiup13 0:1e597b0f8b3b 82 //up arrow
ovidiup13 0:1e597b0f8b3b 83 if(index != 0){
ovidiup13 0:1e597b0f8b3b 84 st7565->drawline(119, 15, 125, 15,DEFAULT_COLOR);
ovidiup13 0:1e597b0f8b3b 85 st7565->drawline(119, 15, 122, 12,DEFAULT_COLOR);
ovidiup13 0:1e597b0f8b3b 86 st7565->drawline(125, 15, 122, 12,DEFAULT_COLOR);
ovidiup13 0:1e597b0f8b3b 87 }
ovidiup13 0:1e597b0f8b3b 88 //down arrow
ovidiup13 0:1e597b0f8b3b 89 if(j < size){
ovidiup13 0:1e597b0f8b3b 90 st7565->drawline(119, 60, 125, 60,DEFAULT_COLOR);
ovidiup13 0:1e597b0f8b3b 91 st7565->drawline(119, 60, 122, 63,DEFAULT_COLOR);
ovidiup13 0:1e597b0f8b3b 92 st7565->drawline(125, 60, 122, 63,DEFAULT_COLOR);
ovidiup13 0:1e597b0f8b3b 93 }
ovidiup13 0:1e597b0f8b3b 94 //set selected as first
ovidiup13 2:fcde41900fa5 95 st7565->drawcircle(2, (current_line * 8) + 3, 2, 20);
ovidiup13 0:1e597b0f8b3b 96 st7565->display();
ovidiup13 0:1e597b0f8b3b 97 }