LCD implementation of our project.
Dependencies: mbed mbed-rtos MLX90614
Diff: Compass.cpp
- Revision:
- 4:024e6a9c2ebf
- Parent:
- 3:688b62ff6474
- Child:
- 5:5b1a8ad6c187
--- a/Compass.cpp Sun Apr 26 16:29:53 2015 +0000 +++ b/Compass.cpp Mon May 25 14:46:39 2015 +0000 @@ -1,14 +1,48 @@ #include "Compass.h" +//constructor +Compass::Compass(ST7565 * lcd, Item * back) { + this->title = " Compass"; + this->st7565= lcd; + this->back = back; + ct = NULL; +} + +//display function, starts the thread and displays the compass void Compass::display(void){ //create a new thread to get and update compass - do later - draw_compass(0); + ct = new Thread(&Compass::ct_start, this, osPriorityNormal, 1024); + ct->signal_set(START_THREAD); +} + +//trigger for starting the thread +void Compass::ct_start(void const *args){ + Compass *c = (Compass*)args; + c->compass_update(); } +//function that the thread runs, waits for the signal before starting +void Compass::compass_update(){ + ct->signal_wait(START_THREAD); + //lock the mutex so that no other thread may access the lcd + + int i = 0; + //get degrees from other functions and display the compass + while(true){ + draw_compass(i++); + st7565->clear(); + Thread::wait(30); + } +} + +//update function handles updates from the user - cancels the thread +//and returns to main menu void Compass::update(char c){ //kill thread and go back - if(c == 'y') + if(c == 'y'){ + ct->terminate(); this->setSelectedScreen(back); + } } //get direction @@ -35,7 +69,7 @@ void Compass::draw_compass(double degrees){ //variables int x_temp, y_temp; - double rad = degrees * M_PI / 180; + double rad = degrees * M_PI / 180; //radians //calculate coordinates to point x_temp = X_CENTER + (int) (POINTER_LENGTH * cos(rad));