LCD implementation of our project.

Dependencies:   mbed mbed-rtos MLX90614

Revision:
8:81ed1135ba02
Parent:
7:11675c1dce4f
--- a/Compass.cpp	Wed Jun 03 12:22:46 2015 +0000
+++ b/Compass.cpp	Wed Jun 03 16:37:21 2015 +0000
@@ -1,11 +1,14 @@
 #include "Compass.h"
 
 //constructor
-Compass::Compass(ST7565 * lcd, Item * back)
+Compass::Compass(ST7565 * lcd, Item * back, DigitalOut *gyro, DigitalOut *thermo)
 {
     this->title = " Compass";
     this->st7565= lcd;
     this->back = back;
+    this->gyro = gyro;
+    this->thermo = thermo;
+    
     ct = NULL;
 }
 
@@ -14,6 +17,7 @@
 {
     //create a new thread to get and update compass - do later
     if(ct != NULL) return; //thread is already running
+    thermo->write(0); gyro->write(1);
     ct = new Thread(&Compass::ct_start, this);
     ct->signal_set(START_THREAD);
 }
@@ -37,7 +41,7 @@
         #ifdef LSM303_on
             LSM303(&state);
         #endif
-        draw_compass(state.heading - 33 + 90); //offset
+        draw_compass(state.heading - 33); //add offset
         Thread::wait(30);
         st7565->clear();
     }
@@ -50,8 +54,8 @@
     //kill thread and go back
     if(c == 'y') {
         ct->terminate();
-        free(ct);
-        ct = NULL;
+        free(ct); ct = NULL;
+        gyro->write(0);
         st7565->clear();//clear everything
         this->setSelectedScreen(back);
     } else
@@ -84,7 +88,7 @@
 {
     //variables
     int x_temp, y_temp;
-    double rad = degrees * M_PI / 180; //radians
+    double rad = (degrees + 90) * M_PI / 180; //radians
 
     //calculate coordinates to point
     x_temp = X_CENTER + (int) (POINTER_LENGTH * cos(rad));
@@ -109,13 +113,13 @@
 
     //display pointing direction
     st7565->drawstring(0, 2, "Pointing:");
-    char * pointer = get_direction(degrees);
+    char * pointer = get_direction(degrees + 90);
     st7565->drawstring(0, 4, pointer);
 
     //display degrees and radians in bottom left corner
     char s_deg[10], s_rad[10];
-    sprintf(s_deg, "DEG:%0.2g", degrees);
-    sprintf(s_rad, "RAD:%.2g", rad);
+    sprintf(s_deg, "DEG:%d", (int)degrees % 360);
+    sprintf(s_rad, "RAD:%0.2f", (int)degrees % 360 * M_PI / 180.0);
     st7565->drawstring(1, 6, s_deg);
     st7565->drawstring(1, 7, s_rad);