LCD implementation of our project.

Dependencies:   mbed mbed-rtos MLX90614

Committer:
ovidiup13
Date:
Fri Mar 20 23:22:41 2015 +0000
Revision:
0:1e597b0f8b3b
Child:
2:fcde41900fa5
initial menu mock-up st7565

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ovidiup13 0:1e597b0f8b3b 1
ovidiup13 0:1e597b0f8b3b 2 #ifndef _MENU_H_
ovidiup13 0:1e597b0f8b3b 3 #define _MENU_H_
ovidiup13 0:1e597b0f8b3b 4
ovidiup13 0:1e597b0f8b3b 5 #include<stdio.h>
ovidiup13 0:1e597b0f8b3b 6 #include <stdlib.h>
ovidiup13 0:1e597b0f8b3b 7 #include "st7565LCD.h"
ovidiup13 0:1e597b0f8b3b 8 #include "Item.h"
ovidiup13 0:1e597b0f8b3b 9
ovidiup13 0:1e597b0f8b3b 10 //define control keys
ovidiup13 0:1e597b0f8b3b 11 #define NL 121 //newline char
ovidiup13 0:1e597b0f8b3b 12 #define BS 8 //backspace
ovidiup13 0:1e597b0f8b3b 13 #define UP 119
ovidiup13 0:1e597b0f8b3b 14 #define DOWN 115
ovidiup13 0:1e597b0f8b3b 15
ovidiup13 0:1e597b0f8b3b 16 int const MAX_ITEMS = 16;
ovidiup13 0:1e597b0f8b3b 17 int const TITLE_LINE = 1;
ovidiup13 0:1e597b0f8b3b 18 int const FIRST_ITEM_LINE = 2;
ovidiup13 0:1e597b0f8b3b 19 int const LAST_ITEM_LINE = 7;
ovidiup13 0:1e597b0f8b3b 20
ovidiup13 0:1e597b0f8b3b 21 class Menu: public Item {
ovidiup13 0:1e597b0f8b3b 22 public:
ovidiup13 0:1e597b0f8b3b 23 //Menu will have a limited number of items
ovidiup13 0:1e597b0f8b3b 24 Item ** items;
ovidiup13 0:1e597b0f8b3b 25 int size;
ovidiup13 0:1e597b0f8b3b 26 bool isScreen;
ovidiup13 0:1e597b0f8b3b 27 //selected items variables
ovidiup13 0:1e597b0f8b3b 28 int selected, current_line;
ovidiup13 0:1e597b0f8b3b 29
ovidiup13 0:1e597b0f8b3b 30 //menu constructor
ovidiup13 0:1e597b0f8b3b 31 Menu(char * t, ST7565 *lcd, UI * ui){
ovidiup13 0:1e597b0f8b3b 32 title = t;
ovidiup13 0:1e597b0f8b3b 33 st7565 = lcd;
ovidiup13 0:1e597b0f8b3b 34 items = new Item*[MAX_ITEMS];
ovidiup13 0:1e597b0f8b3b 35 selected = 0;
ovidiup13 0:1e597b0f8b3b 36 size = 0;
ovidiup13 0:1e597b0f8b3b 37 current_line = FIRST_ITEM_LINE;
ovidiup13 0:1e597b0f8b3b 38 isScreen = false;
ovidiup13 0:1e597b0f8b3b 39 isSelectable = false;
ovidiup13 0:1e597b0f8b3b 40 this->ui = ui;
ovidiup13 0:1e597b0f8b3b 41 }
ovidiup13 0:1e597b0f8b3b 42
ovidiup13 0:1e597b0f8b3b 43 //menu item constructor - go to a screen
ovidiup13 0:1e597b0f8b3b 44 Menu(char * t, Item *screen, UI *ui){
ovidiup13 0:1e597b0f8b3b 45 title = t;
ovidiup13 0:1e597b0f8b3b 46 st7565 = NULL;
ovidiup13 0:1e597b0f8b3b 47 items = new Item*[1];
ovidiup13 0:1e597b0f8b3b 48 items[0] = screen;
ovidiup13 0:1e597b0f8b3b 49 selected = 0;
ovidiup13 0:1e597b0f8b3b 50 size = 1;
ovidiup13 0:1e597b0f8b3b 51 current_line = FIRST_ITEM_LINE;
ovidiup13 0:1e597b0f8b3b 52 isScreen = true;
ovidiup13 0:1e597b0f8b3b 53 isSelectable = true;
ovidiup13 0:1e597b0f8b3b 54 this->ui = ui;
ovidiup13 0:1e597b0f8b3b 55 }
ovidiup13 0:1e597b0f8b3b 56
ovidiup13 0:1e597b0f8b3b 57 //display the menu
ovidiup13 0:1e597b0f8b3b 58 virtual void display(void);
ovidiup13 0:1e597b0f8b3b 59
ovidiup13 0:1e597b0f8b3b 60 //update current selection
ovidiup13 0:1e597b0f8b3b 61 virtual void update(char c);
ovidiup13 0:1e597b0f8b3b 62
ovidiup13 0:1e597b0f8b3b 63 //get the title of the menu
ovidiup13 0:1e597b0f8b3b 64 virtual char * getTitle(void){
ovidiup13 0:1e597b0f8b3b 65 return title;
ovidiup13 0:1e597b0f8b3b 66 }
ovidiup13 0:1e597b0f8b3b 67
ovidiup13 0:1e597b0f8b3b 68 //set the title
ovidiup13 0:1e597b0f8b3b 69 void setTitle(char * t){
ovidiup13 0:1e597b0f8b3b 70 title = t;
ovidiup13 0:1e597b0f8b3b 71 }
ovidiup13 0:1e597b0f8b3b 72
ovidiup13 0:1e597b0f8b3b 73 //highlights the current selection
ovidiup13 0:1e597b0f8b3b 74 void addItem(Item * i);
ovidiup13 0:1e597b0f8b3b 75
ovidiup13 0:1e597b0f8b3b 76 private:
ovidiup13 0:1e597b0f8b3b 77 //display items on a new screen starting with a specific index
ovidiup13 0:1e597b0f8b3b 78 void display_items(int index);
ovidiup13 0:1e597b0f8b3b 79 //draw arrows on right side to indicate there are more items up or down
ovidiup13 0:1e597b0f8b3b 80 void draw_arrows(int line, char c);
ovidiup13 0:1e597b0f8b3b 81 //draw the circle indicating which item is selected
ovidiup13 0:1e597b0f8b3b 82 void draw_selected(void);
ovidiup13 0:1e597b0f8b3b 83 };
ovidiup13 0:1e597b0f8b3b 84
ovidiup13 0:1e597b0f8b3b 85 #endif
ovidiup13 0:1e597b0f8b3b 86