LCD implementation of our project.

Dependencies:   mbed mbed-rtos MLX90614

Committer:
ovidiup13
Date:
Sun Apr 26 16:29:53 2015 +0000
Revision:
3:688b62ff6474
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 3:688b62ff6474 1 #include "Compass.h"
ovidiup13 3:688b62ff6474 2
ovidiup13 3:688b62ff6474 3 void Compass::display(void){
ovidiup13 3:688b62ff6474 4 //create a new thread to get and update compass - do later
ovidiup13 3:688b62ff6474 5 draw_compass(0);
ovidiup13 3:688b62ff6474 6 }
ovidiup13 3:688b62ff6474 7
ovidiup13 3:688b62ff6474 8 void Compass::update(char c){
ovidiup13 3:688b62ff6474 9 //kill thread and go back
ovidiup13 3:688b62ff6474 10 if(c == 'y')
ovidiup13 3:688b62ff6474 11 this->setSelectedScreen(back);
ovidiup13 3:688b62ff6474 12 }
ovidiup13 3:688b62ff6474 13
ovidiup13 3:688b62ff6474 14 //get direction
ovidiup13 3:688b62ff6474 15 char * get_direction(double degrees){
ovidiup13 3:688b62ff6474 16 if(degrees >= 330 || degrees < 30)
ovidiup13 3:688b62ff6474 17 return "East";
ovidiup13 3:688b62ff6474 18 else if(degrees >= 30 && degrees <= 60)
ovidiup13 3:688b62ff6474 19 return "North-East";
ovidiup13 3:688b62ff6474 20 else if(degrees >= 60 && degrees < 120)
ovidiup13 3:688b62ff6474 21 return "North";
ovidiup13 3:688b62ff6474 22 else if(degrees >= 120 && degrees < 150)
ovidiup13 3:688b62ff6474 23 return "North-West";
ovidiup13 3:688b62ff6474 24 else if(degrees >= 150 && degrees < 210)
ovidiup13 3:688b62ff6474 25 return "West";
ovidiup13 3:688b62ff6474 26 else if(degrees >= 210 && degrees < 240)
ovidiup13 3:688b62ff6474 27 return "South-West";
ovidiup13 3:688b62ff6474 28 else if(degrees >= 240 && degrees < 300)
ovidiup13 3:688b62ff6474 29 return "South";
ovidiup13 3:688b62ff6474 30 else
ovidiup13 3:688b62ff6474 31 return "South-East";
ovidiup13 3:688b62ff6474 32 }
ovidiup13 3:688b62ff6474 33
ovidiup13 3:688b62ff6474 34 //function that draws the compass on the screen
ovidiup13 3:688b62ff6474 35 void Compass::draw_compass(double degrees){
ovidiup13 3:688b62ff6474 36 //variables
ovidiup13 3:688b62ff6474 37 int x_temp, y_temp;
ovidiup13 3:688b62ff6474 38 double rad = degrees * M_PI / 180;
ovidiup13 3:688b62ff6474 39
ovidiup13 3:688b62ff6474 40 //calculate coordinates to point
ovidiup13 3:688b62ff6474 41 x_temp = X_CENTER + (int) (POINTER_LENGTH * cos(rad));
ovidiup13 3:688b62ff6474 42 y_temp = Y_CENTER + (int) (POINTER_LENGTH * (-sin(rad)));
ovidiup13 3:688b62ff6474 43
ovidiup13 3:688b62ff6474 44 //draw the main circle and small one
ovidiup13 3:688b62ff6474 45 st7565->drawcircle(X_CENTER, Y_CENTER, RADIUS, 20);
ovidiup13 3:688b62ff6474 46 st7565->drawcircle(X_CENTER, Y_CENTER, 2, 20);
ovidiup13 3:688b62ff6474 47
ovidiup13 3:688b62ff6474 48 //draw the lines
ovidiup13 3:688b62ff6474 49 st7565->drawline(X_CENTER, Y_CENTER, x_temp, y_temp, 20); //draw line from center to coordinates
ovidiup13 3:688b62ff6474 50 st7565->drawline(X_CENTER, Y_CENTER - RADIUS, X_CENTER, Y_CENTER - 15, 20); //north line
ovidiup13 3:688b62ff6474 51 st7565->drawline(X_CENTER, Y_CENTER + RADIUS, X_CENTER, Y_CENTER + 15, 20); //south line
ovidiup13 3:688b62ff6474 52 st7565->drawline(X_CENTER + RADIUS, Y_CENTER, X_CENTER + 15, Y_CENTER, 20); //east line
ovidiup13 3:688b62ff6474 53 st7565->drawline(X_CENTER - RADIUS, Y_CENTER, X_CENTER - 15, Y_CENTER, 20); //west line
ovidiup13 3:688b62ff6474 54
ovidiup13 3:688b62ff6474 55 //draw the initials
ovidiup13 3:688b62ff6474 56 st7565->drawstring(X_CENTER - 2, 1, "N");
ovidiup13 3:688b62ff6474 57 st7565->drawstring(X_CENTER - 2, 7, "S");
ovidiup13 3:688b62ff6474 58 st7565->drawstring(X_CENTER + 21, 4, "E");
ovidiup13 3:688b62ff6474 59 st7565->drawstring(X_CENTER - 25, 4, "W");
ovidiup13 3:688b62ff6474 60
ovidiup13 3:688b62ff6474 61 //display pointing direction
ovidiup13 3:688b62ff6474 62 st7565->drawstring(0, 2, "Pointing:");
ovidiup13 3:688b62ff6474 63 char * pointer = get_direction(degrees);
ovidiup13 3:688b62ff6474 64 st7565->drawstring(0, 4, pointer);
ovidiup13 3:688b62ff6474 65
ovidiup13 3:688b62ff6474 66 //display degrees and radians in bottom left corner
ovidiup13 3:688b62ff6474 67 char s_deg[10], s_rad[10];
ovidiup13 3:688b62ff6474 68 sprintf(s_deg, "DEG:%g", degrees);
ovidiup13 3:688b62ff6474 69 sprintf(s_rad, "RAD:%.2g", rad);
ovidiup13 3:688b62ff6474 70 st7565->drawstring(1, 6, s_deg);
ovidiup13 3:688b62ff6474 71 st7565->drawstring(1, 7, s_rad);
ovidiup13 3:688b62ff6474 72
ovidiup13 3:688b62ff6474 73 st7565->display();
ovidiup13 3:688b62ff6474 74 }