Team Alpha / Mbed 2 deprecated UserIntefaceLCD

Dependencies:   mbed mbed-rtos MLX90614

Committer:
ovidiup13
Date:
Sat Apr 04 18:24:21 2015 +0000
Revision:
2:fcde41900fa5
Parent:
0:1e597b0f8b3b
Child:
3:688b62ff6474
Cleaned up interface, added buttons.

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