LCD implementation of our project.

Dependencies:   mbed mbed-rtos MLX90614

Files at this revision

API Documentation at this revision

Comitter:
ovidiup13
Date:
Sun Apr 26 16:29:53 2015 +0000
Parent:
2:fcde41900fa5
Child:
4:024e6a9c2ebf
Commit message:
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

Changed in this revision

Compass.cpp Show annotated file Show diff for this revision Revisions of this file
Compass.h Show annotated file Show diff for this revision Revisions of this file
Header.h Show annotated file Show diff for this revision Revisions of this file
Item.h Show annotated file Show diff for this revision Revisions of this file
LevelMeter.cpp Show annotated file Show diff for this revision Revisions of this file
LevelMeter.h Show annotated file Show diff for this revision Revisions of this file
Measure.cpp Show annotated file Show diff for this revision Revisions of this file
Measure.h Show annotated file Show diff for this revision Revisions of this file
Menu.cpp Show annotated file Show diff for this revision Revisions of this file
Menu.h Show annotated file Show diff for this revision Revisions of this file
Screen.h Show diff for this revision Revisions of this file
Settings.h Show annotated file Show diff for this revision Revisions of this file
UserInterface.cpp Show annotated file Show diff for this revision Revisions of this file
UserInterface.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Compass.cpp	Sun Apr 26 16:29:53 2015 +0000
@@ -0,0 +1,74 @@
+#include "Compass.h"
+
+void Compass::display(void){
+    //create a new thread to get and update compass - do later
+    draw_compass(0);
+}
+
+void Compass::update(char c){
+    //kill thread and go back
+    if(c == 'y')
+        this->setSelectedScreen(back);
+}
+
+//get direction
+char * get_direction(double degrees){
+    if(degrees >= 330 || degrees < 30)
+        return "East";
+    else if(degrees >= 30 && degrees <= 60)
+        return "North-East";
+    else if(degrees >= 60 && degrees < 120)
+        return "North";
+    else if(degrees >= 120 && degrees < 150)
+        return "North-West";
+    else if(degrees >= 150 && degrees < 210)
+        return "West";
+    else if(degrees >= 210 && degrees < 240)
+        return "South-West";
+    else if(degrees >= 240 && degrees < 300)
+        return "South";
+    else
+        return "South-East";
+}
+
+//function that draws the compass on the screen
+void Compass::draw_compass(double degrees){
+    //variables
+    int x_temp, y_temp;
+    double rad = degrees * M_PI / 180;
+    
+    //calculate coordinates to point
+    x_temp = X_CENTER + (int) (POINTER_LENGTH * cos(rad));
+    y_temp = Y_CENTER + (int) (POINTER_LENGTH * (-sin(rad)));
+    
+    //draw the main circle and small one
+    st7565->drawcircle(X_CENTER, Y_CENTER, RADIUS, 20);
+    st7565->drawcircle(X_CENTER, Y_CENTER, 2, 20);
+    
+    //draw the lines
+    st7565->drawline(X_CENTER, Y_CENTER, x_temp, y_temp, 20); //draw line from center to coordinates
+    st7565->drawline(X_CENTER, Y_CENTER - RADIUS, X_CENTER, Y_CENTER - 15, 20); //north line
+    st7565->drawline(X_CENTER, Y_CENTER + RADIUS, X_CENTER, Y_CENTER + 15, 20); //south line
+    st7565->drawline(X_CENTER + RADIUS, Y_CENTER, X_CENTER + 15, Y_CENTER, 20); //east line
+    st7565->drawline(X_CENTER - RADIUS, Y_CENTER, X_CENTER - 15, Y_CENTER, 20); //west line
+    
+    //draw the initials
+    st7565->drawstring(X_CENTER - 2, 1, "N");
+    st7565->drawstring(X_CENTER - 2, 7, "S");
+    st7565->drawstring(X_CENTER + 21, 4, "E");
+    st7565->drawstring(X_CENTER - 25, 4, "W");
+    
+    //display pointing direction
+    st7565->drawstring(0, 2, "Pointing:");
+    char * pointer = get_direction(degrees);
+    st7565->drawstring(0, 4, pointer);
+    
+    //display degrees and radians in bottom left corner
+    char s_deg[10], s_rad[10];
+    sprintf(s_deg, "DEG:%g", degrees);
+    sprintf(s_rad, "RAD:%.2g", rad);
+    st7565->drawstring(1, 6, s_deg);
+    st7565->drawstring(1, 7, s_rad);
+    
+    st7565->display();
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Compass.h	Sun Apr 26 16:29:53 2015 +0000
@@ -0,0 +1,33 @@
+#ifndef _COMPASS_H
+#define _COMPASS_H
+
+#include "Item.h"
+#include<stdio.h>
+#define _USE_MATH_DEFINES
+#include <math.h>
+#define M_PI 3.14159265358979323846  /* pi */
+
+//define center coordinates
+#define X_CENTER 95
+#define Y_CENTER 35
+#define POINTER_LENGTH 10
+#define RADIUS 19
+
+class Compass: public Item {
+    public:
+    
+    //inherited functions
+        Compass(ST7565 * lcd, Item * back){
+            this->title = " Compass";
+            this->st7565= lcd;
+            this->back = back;
+        }
+        
+        virtual void display(void);
+        virtual void update(char c);
+        
+        void draw_compass(double degrees);
+        void update_compass(void);
+};
+
+#endif
\ No newline at end of file
--- a/Header.h	Sat Apr 04 18:24:21 2015 +0000
+++ b/Header.h	Sun Apr 26 16:29:53 2015 +0000
@@ -1,7 +1,7 @@
 #ifndef _HEADER_H_
 #define _HEADER_H_
 
-#include<stdio.h>
+#include <stdio.h>
 #include <stdlib.h>
 #include "st7565LCD.h"
 
--- a/Item.h	Sat Apr 04 18:24:21 2015 +0000
+++ b/Item.h	Sun Apr 26 16:29:53 2015 +0000
@@ -2,20 +2,16 @@
 #define _ITEM_H
 
 #include "st7565LCD.h"
-#include "UserInterface.h"
-
 #define LEFT_MARGIN 5
 #define DEFAULT_COLOR 20
 
-class UI;
-
 class Item {
     public:
         //name
         char * title;
         ST7565 * st7565;
-        UI * ui;
         bool isSelectable;
+        Item *selectedScreen, *back;
         
         //declare pure virtual functions
         virtual void display(void) = 0;
@@ -26,18 +22,13 @@
             return title;
         }
         
-        /*
-        //constructors
-        Item(char *title, ST7565 * lcd, UI * ui){
-            this->title = title;
-            this->st7565 = lcd;
+        Item * getSelectedScreen(){
+            return selectedScreen;
         }
-        Item(void){
-            title = NULL;
-            st7565 = NULL;
-            ui = NULL;
+        
+        void setSelectedScreen(Item *s){
+            selectedScreen = s;
         }
-        */
 };
 
 #endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LevelMeter.cpp	Sun Apr 26 16:29:53 2015 +0000
@@ -0,0 +1,25 @@
+#include "LevelMeter.h"
+
+void LevelMeter::display(void){
+    draw_circles(0,0);
+}
+
+void LevelMeter::update(char c){
+    if(c == 'y')
+        this->setSelectedScreen(back);
+}
+
+void LevelMeter::draw_circles(double rX, double rY){
+    
+    int X1 = 95, Y1 = 35, X2 = 30, Y2 = 35; //need to calculate these
+    
+    //draw the circles
+    st7565->fillcircle(X1, Y1, RADIUS_lvl, 20);
+    st7565->drawcircle(X2, Y2, RADIUS_lvl, 1);
+    
+    //draw cross
+    st7565->drawline(X0 - 2, Y0, X0 + 2, Y0, 20);
+    st7565->drawline(X0, Y0 - 2, X0, Y0 + 2, 20);
+    
+    st7565->display();
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LevelMeter.h	Sun Apr 26 16:29:53 2015 +0000
@@ -0,0 +1,26 @@
+#include "Item.h"
+
+//define coordinates
+#define X0 63 //center
+#define Y0 35 //center
+#define POINTER_LENGTH 10
+#define RADIUS_lvl 10
+
+class LevelMeter: public Item {
+    public:
+        //constructors
+        LevelMeter(ST7565 *lcd, Item * back){
+            this->st7565 = lcd;
+            this->title = " Level meter";
+            this->back = back;
+        }
+        
+        //inherited functions
+        virtual void display(void);
+        virtual void update(char c);
+        
+        private:
+            void draw_circles(double rX, double rY);
+            void update_degrees(double degrees);
+        
+};
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Measure.cpp	Sun Apr 26 16:29:53 2015 +0000
@@ -0,0 +1,63 @@
+#include "Measure.h"
+
+void Measure::display(void){
+    this->display_items();
+}
+
+void Measure::update(char c){
+    //select down
+    if(c == 's'){
+        if(selected == 2) return; //do nothing
+        printf("measure - going down");
+        selected = 2;
+        current_line = 7;
+    }
+    //select up
+    else if(c == 'w'){
+        if(selected == 1) return; //do nothing
+        selected = 1;
+        current_line = 6;
+    }
+    //go to next screen
+    else if(c == 'y'){
+        if(selected == 1)
+            this->setSelectedScreen(next);
+        else if(selected == 2)
+            this->setSelectedScreen(back);
+        else
+            return;
+    }
+    //display items
+    display_items();
+}
+
+void Measure::display_description(char * r){
+    st7565->drawstring(0, 2, description); //description
+    //result
+    if(hasResult)
+        st7565->drawstring(30, 5, r);
+}
+
+void Measure::display_items(void){
+    //clear screen
+    st7565->clear();
+    
+    //display result if it is a result screen
+    float r = 5;
+    char result[15];
+    if(hasResult){
+        //calculate result
+        sprintf(result, "%.2f Meters", r);
+    }
+    
+    //display description
+    display_description(result);
+    
+    //draw items
+    st7565->drawstring(LEFT_MARGIN * 2, SELECTION_LINE, nextName);
+    st7565->drawstring(LEFT_MARGIN * 2, SELECTION_LINE + 1, backName);
+    
+    //set first as selected
+    st7565->drawcircle(2, (current_line * 8) + 3, 2, 20);
+    st7565->display();
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Measure.h	Sun Apr 26 16:29:53 2015 +0000
@@ -0,0 +1,52 @@
+#include "Item.h"
+
+#define SELECTION_LINE 6
+
+class Measure: public Item {
+    public:
+        //menu items - only 2 -> start and back
+        Item **items[2];
+        Item *next; //screen to go next
+        bool hasResult;
+        
+        //constructors
+        Measure(char * title, ST7565 *lcd, Item *back){
+            this->title = title;
+            this->st7565 = lcd;
+            this->back = back;
+            backName = " Back";
+            hasResult = false;
+            selected = 1;
+            current_line = 6;
+        };
+        
+        Measure();
+        
+        //inherited functions
+        virtual void display();
+        virtual void update(char c);
+        
+        //set next screen
+        void setNext(char * t, Item *item){
+            this->nextName = t;
+            this->next = item;
+        }
+        
+        //set description of screen
+        void setDescription(char * description){
+            this->description = description;
+        }
+        
+        //function to set screen as result screen
+        void setResult(bool r){
+            hasResult = r;
+        }
+        
+        private:
+            int selected, current_line;
+            char * description, *nextName, *backName;
+            void display_description(char *r);
+            void set_selected(int s);
+            void display_result(double result);
+            void display_items(void);
+};
\ No newline at end of file
--- a/Menu.cpp	Sat Apr 04 18:24:21 2015 +0000
+++ b/Menu.cpp	Sun Apr 26 16:29:53 2015 +0000
@@ -1,16 +1,7 @@
 #include "Menu.h"
 
 void Menu::display(void){
-    ui->setCurrent(this);
-    ui->setHeaderTitle(this->title);
-    //if it is a menu item, go to referenced screen
-    if(isScreen){
-        items[0]->display();
-        return;
-    }
-    //otherwise it's a menu, display items
-    current_line = FIRST_ITEM_LINE; //set first item on screen as selected
-    selected = 0;
+    //display items
     display_items(0); //display items starting from index 0
 }
 
@@ -51,22 +42,19 @@
             selected--;
             //display items from the next selected item
             current_line = LAST_ITEM_LINE; //current selected line will be top of screen
-            printf("got up, selected is: %d; current line is: %d\n", selected, current_line);
         }
         //it is not first on the screen
         else{
             current_line--;
             selected--;
-            printf("selected is: %d; current line is: %d\n", selected, current_line);
         }
         st7565->clear();
         display_items(selected/ITEMS_PER_SCREEN * ITEMS_PER_SCREEN);
         return;
     }
     else if(c == NL && items[selected]->isSelectable){
-        //switch to other screen
-        ui->setCurrent(items[selected]);
-        ui->display();
+        //set selected screen so that UI knows which screen we selected to display
+        this->setSelectedScreen(items[selected]);
     }
 }
 
--- a/Menu.h	Sat Apr 04 18:24:21 2015 +0000
+++ b/Menu.h	Sun Apr 26 16:29:53 2015 +0000
@@ -1,4 +1,3 @@
-
 #ifndef _MENU_H_
 #define _MENU_H_
 
@@ -21,28 +20,23 @@
 
 class Menu: public Item {
     public:
-        //Menu will have a limited number of items
         Item ** items;
-        int size;
+        int size, selected, current_line;
         bool isScreen;
-        //selected items variables
-        int selected, current_line;
         
         //menu constructor
-        Menu(char * t, ST7565 *lcd, UI * ui){
+        Menu(char * t, ST7565 *lcd){
             title = t;
             st7565 = lcd;
             items = new Item*[MAX_ITEMS];
-            selected = 0;
-            size = 0;
+            selected = size = 0;
             current_line = FIRST_ITEM_LINE;
             isScreen = false;
             isSelectable = false;
-            this->ui = ui;
         }
         
         //menu item constructor - go to a screen
-        Menu(char * t, Item *screen, UI *ui){
+        Menu(char * t, Item *screen){
             title = t;
             st7565 = NULL;
             items = new Item*[1];
@@ -52,7 +46,6 @@
             current_line = FIRST_ITEM_LINE;
             isScreen = true;
             isSelectable = true;
-            this->ui = ui;
         }
         
         //display the menu
--- a/Screen.h	Sat Apr 04 18:24:21 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,18 +0,0 @@
-#ifndef _SCREEN_H
-#define _SCREEN_H
-
-#include "Item.h"
-
-class Screen: public Item {
-    
-    public:
-        Item *back, *start;
-        char * description;
-        
-        //inherited functions
-        virtual void display(void);
-        virtual void update(char *c);
-        
-};
-
-#endif
\ No newline at end of file
--- a/UserInterface.cpp	Sat Apr 04 18:24:21 2015 +0000
+++ b/UserInterface.cpp	Sun Apr 26 16:29:53 2015 +0000
@@ -33,6 +33,7 @@
     st7565->display();
     wait(2.0);
     
+    header->setTitle(current->getTitle());
     display();
 }
 
@@ -44,6 +45,10 @@
 
 void UI::update(char c){
     current->update(c);
-    //display header after update
-    header->display();
+    //set header after update
+    if(c == 'y'){
+        current = current->getSelectedScreen();
+        header->setTitle(current->getTitle());
+    }
+    this->display();
 }
\ No newline at end of file
--- a/UserInterface.h	Sat Apr 04 18:24:21 2015 +0000
+++ b/UserInterface.h	Sun Apr 26 16:29:53 2015 +0000
@@ -1,14 +1,20 @@
 #ifndef _UI_H_
 #define _UI_H_
 
+//include files
+#include "st7565LCD.h"
+#include "Header.h"
+#include "Item.h"
+#include "Menu.h"
+#include "Compass.h"
+#include "LevelMeter.h"
+#include "Measure.h"
+
+//include libs
 #include <string.h>
 #include <assert.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include "st7565LCD.h"
-#include "Header.h"
-#include "Item.h"
-#include "Menu.h"
 
 //define brightness and contrast
 #define _DEFAULT_BRIGHTNESS 25
--- a/main.cpp	Sat Apr 04 18:24:21 2015 +0000
+++ b/main.cpp	Sun Apr 26 16:29:53 2015 +0000
@@ -21,44 +21,63 @@
     UI * ui = new UI(&st7565);
     
     //create main menu
-    Menu * main_menu = new Menu(" Main Menu", &st7565, ui);
+    Menu * main_menu = new Menu(" Main Menu", &st7565);
+    
+    //create distance screens
+    Measure *distance = new Measure(" Distance", &st7565, main_menu);
+    distance->setDescription("Select Start from the menu below to start laser.");
+    Measure *distance2 = new Measure(" Distance", &st7565, distance);
+    distance2->setDescription("Press select button to fix target.");
+    Measure *distance3 = new Measure(" Distance", &st7565, main_menu);
+    distance3->setDescription("Distance to target is:");
+    distance3->setResult(true);
+    
+    distance->setNext(" Start", distance2);
+    distance2->setNext(" Select", distance3);
+    distance3->setNext(" Start again", distance);
+    main_menu->addItem(distance);
     
-    //create distance screen
-    Menu *distance = new Menu(" Distance", &st7565, ui);
-    distance->addItem(new Menu(" Back", main_menu, ui));
+    //create point-to-point screens
+    Measure *p2p = new Measure(" Point-to-Point", &st7565, main_menu);
+    p2p->setDescription("Select Start from the menu to start laser for #1 target.");
+    Measure *p2p2 = new Measure(" Point-to-Point", &st7565, p2p);
+    p2p2->setDescription("Press select button to fix target #1.");
+    Measure *p2p3 = new Measure(" Point-to-Point", &st7565, p2p2);
+    p2p3->setDescription("Press select button to fix target #2.");
+    Measure *p2p4 = new Measure(" Point-to-Point", &st7565, p2p3);
+    p2p4->setDescription("Distance between targets is:");
+    p2p4->setResult(true); //result screen
     
-    //create point-to-point screen
-    Menu *p2p = new Menu(" Point2Point", &st7565, ui);
-    p2p->addItem(new Menu(" Back", main_menu, ui));
+    p2p->setNext(" Start", p2p2);
+    p2p2->setNext(" Select", p2p3);
+    p2p3->setNext(" Select", p2p4);
+    p2p4->setNext(" Start again", p2p);
+    main_menu->addItem(p2p);
     
     //create level meter screen
-    Menu *lvlm = new Menu(" Level meter", &st7565, ui);
-    lvlm->addItem(new Menu(" Back", main_menu, ui));
+    LevelMeter *lvl = new LevelMeter(&st7565, main_menu);
+    main_menu->addItem(lvl);
     
     //create compass screen
-    Menu *compass = new Menu(" Compass", &st7565, ui);
-    compass->addItem(new Menu(" Back", main_menu, ui));
+    Compass *compass = new Compass(&st7565, main_menu);
+    main_menu->addItem(compass);
     
-    //create thermometer screen
-    Menu *thermo = new Menu(" Thermometer", &st7565, ui);
-    thermo->addItem(new Menu(" Back", main_menu, ui));
+    //create thermo screen
+    Measure *thermo = new Measure(" Thermometer", &st7565, main_menu);
+    thermo->setDescription("Press Start from the menu to start laser.");
+    Measure *thermo2 = new Measure(" Thermometer", &st7565, thermo);
+    thermo2->setDescription("Press select button to fix target.");
+    Measure *thermo3 = new Measure(" Thermometer", &st7565, main_menu);
+    thermo3->setDescription("Target temperature is:");
+    thermo3->setResult(true);
+    
+    thermo->setNext(" Start", thermo2);
+    thermo2->setNext(" Start", thermo3);
+    thermo3->setNext(" Start", thermo);
+    main_menu->addItem(thermo);
     
     //create settings menu
-    Menu *settings = new Menu(" Settings", &st7565, ui);
-    Menu *m_settings = new Menu(" Distance", &st7565, ui);
-    settings->addItem(m_settings);
-    Menu *s_settings = new Menu(" Screen Colour", &st7565, ui);
-    settings->addItem(s_settings);
-    Menu *b_settings = new Menu(" Brightness", &st7565, ui);
-    settings->addItem(b_settings);
-    settings->addItem(new Menu(" Back", main_menu, ui));
-    
-    //add menus to main menu
-    main_menu->addItem(distance);
-    main_menu->addItem(p2p);
-    main_menu->addItem(lvlm);
-    main_menu->addItem(compass);
-    main_menu->addItem(thermo);
+    Menu *settings = new Menu(" Settings", &st7565);
     main_menu->addItem(settings);
     
     //create header object
@@ -66,10 +85,7 @@
     
     //set header and current menu
     ui->setCurrent(main_menu);
-    header->setTitle(main_menu->getTitle());
     ui->setHeader(header);
-    
-    //initialize the display
     ui->init();
     
     while(1) {