LCD implementation of our project.

Dependencies:   mbed mbed-rtos MLX90614

Committer:
ovidiup13
Date:
Wed Jun 03 17:42:47 2015 +0000
Revision:
10:97389d774ae1
Parent:
9:4bed81856c2f
working version, comment out thermo in main;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ovidiup13 3:688b62ff6474 1 #include "LevelMeter.h"
ovidiup13 3:688b62ff6474 2
ovidiup13 8:81ed1135ba02 3 LevelMeter::LevelMeter(ST7565 *lcd, Item * back, DigitalOut *gyro, DigitalOut *thermo)
ovidiup13 5:5b1a8ad6c187 4 {
ovidiup13 5:5b1a8ad6c187 5 this->st7565 = lcd;
ovidiup13 5:5b1a8ad6c187 6 this->title = " Level meter";
ovidiup13 5:5b1a8ad6c187 7 this->back = back;
ovidiup13 8:81ed1135ba02 8 this->gyro = gyro;
ovidiup13 8:81ed1135ba02 9 this->thermo = thermo;
ovidiup13 5:5b1a8ad6c187 10 lt = NULL;
ovidiup13 5:5b1a8ad6c187 11 }
ovidiup13 5:5b1a8ad6c187 12
ovidiup13 5:5b1a8ad6c187 13 void LevelMeter::display(void)
ovidiup13 5:5b1a8ad6c187 14 {
ovidiup13 5:5b1a8ad6c187 15 //create a new thread to get and update compass - do later
ovidiup13 5:5b1a8ad6c187 16 if(lt != NULL) return;//thread is already running
ovidiup13 8:81ed1135ba02 17 thermo->write(0); gyro->write(1);
ovidiup13 5:5b1a8ad6c187 18 lt = new Thread(&LevelMeter::lt_start, this);
ovidiup13 5:5b1a8ad6c187 19 lt->signal_set(START_THREAD);
ovidiup13 3:688b62ff6474 20 }
ovidiup13 3:688b62ff6474 21
ovidiup13 5:5b1a8ad6c187 22 //trigger for starting the thread
ovidiup13 5:5b1a8ad6c187 23 void LevelMeter::lt_start(void const *args)
ovidiup13 5:5b1a8ad6c187 24 {
ovidiup13 5:5b1a8ad6c187 25 LevelMeter *l = (LevelMeter*)args;
ovidiup13 5:5b1a8ad6c187 26 l->update_cross();
ovidiup13 3:688b62ff6474 27 }
ovidiup13 3:688b62ff6474 28
ovidiup13 5:5b1a8ad6c187 29 void LevelMeter::update_cross()
ovidiup13 5:5b1a8ad6c187 30 {
ovidiup13 5:5b1a8ad6c187 31 lt->signal_wait(START_THREAD); //wait for signal to start thread
ovidiup13 6:49a007861c76 32 initSensors();
ovidiup13 6:49a007861c76 33 Result_avrg result;
ovidiup13 5:5b1a8ad6c187 34 //draw the static circle
ovidiup13 6:49a007861c76 35 //int i = 0, j = 0;
ovidiup13 5:5b1a8ad6c187 36 while(true) {
ovidiup13 6:49a007861c76 37 calc_avrg_or(&result,2);
ovidiup13 6:49a007861c76 38 draw_elements(result.x, result.y);
ovidiup13 8:81ed1135ba02 39 printf("%0.0f, %0.0f\n", result.x, result.y);
ovidiup13 6:49a007861c76 40 Thread::wait(15);
ovidiup13 5:5b1a8ad6c187 41 st7565->clear();
ovidiup13 5:5b1a8ad6c187 42 }
ovidiup13 5:5b1a8ad6c187 43 }
ovidiup13 5:5b1a8ad6c187 44
ovidiup13 5:5b1a8ad6c187 45 void LevelMeter::draw_elements(double rx, double ry){
ovidiup13 5:5b1a8ad6c187 46 int cross_x, cross_y;
ovidiup13 3:688b62ff6474 47
ovidiup13 3:688b62ff6474 48 //draw the circles
ovidiup13 5:5b1a8ad6c187 49 st7565->drawcircle(X0, Y0, RADIUS_lvl, 1);
ovidiup13 5:5b1a8ad6c187 50
ovidiup13 5:5b1a8ad6c187 51 //draw middle cross
ovidiup13 3:688b62ff6474 52 st7565->drawline(X0 - 2, Y0, X0 + 2, Y0, 20);
ovidiup13 3:688b62ff6474 53 st7565->drawline(X0, Y0 - 2, X0, Y0 + 2, 20);
ovidiup13 3:688b62ff6474 54
ovidiup13 5:5b1a8ad6c187 55 //check if rotation in negative interval
ovidiup13 5:5b1a8ad6c187 56 if(rx >= 270) rx -= 360;
ovidiup13 5:5b1a8ad6c187 57 if(ry >= 270) ry -= 360;
ovidiup13 5:5b1a8ad6c187 58
ovidiup13 5:5b1a8ad6c187 59 //calculate coordinates
ovidiup13 6:49a007861c76 60 cross_x = (int) ((2*rx * SCREEN_WIDTH)/360.0) + X0;
ovidiup13 6:49a007861c76 61 cross_y = (int) ((2*ry * SCREEN_HEIGHT)/360.0) + Y0;
ovidiup13 5:5b1a8ad6c187 62
ovidiup13 6:49a007861c76 63 //printf("Coordinates for cross are: %d, %d\n", cross_x, cross_y);
ovidiup13 5:5b1a8ad6c187 64
ovidiup13 5:5b1a8ad6c187 65 //draw the cross
ovidiup13 6:49a007861c76 66 st7565->drawline(cross_x, cross_y - RADIUS_lvl*3, cross_x, cross_y + RADIUS_lvl*3, DEFAULT_COLOR);
ovidiup13 6:49a007861c76 67 st7565->drawline(cross_x - RADIUS_lvl*3, cross_y, cross_x + RADIUS_lvl*3, cross_y, DEFAULT_COLOR);
ovidiup13 6:49a007861c76 68
ovidiup13 6:49a007861c76 69 //draw results
ovidiup13 6:49a007861c76 70 char *rsx = (char*)malloc(sizeof(char)*7);
ovidiup13 6:49a007861c76 71 char *rsy = (char*)malloc(sizeof(char)*7);
ovidiup13 6:49a007861c76 72 sprintf(rsx, "X: %0.0f", rx);
ovidiup13 6:49a007861c76 73 sprintf(rsy, "Y: %0.0f", ry);
ovidiup13 6:49a007861c76 74 st7565->drawstring(3, 7, rsx);
ovidiup13 6:49a007861c76 75 st7565->drawstring(SCREEN_WIDTH - 38, 7, rsy);
ovidiup13 5:5b1a8ad6c187 76
ovidiup13 5:5b1a8ad6c187 77 //display
ovidiup13 3:688b62ff6474 78 st7565->display();
ovidiup13 9:4bed81856c2f 79 //free(rsx);
ovidiup13 9:4bed81856c2f 80 //free(rsy);
ovidiup13 5:5b1a8ad6c187 81 }
ovidiup13 5:5b1a8ad6c187 82
ovidiup13 5:5b1a8ad6c187 83 void LevelMeter::update(char c)
ovidiup13 5:5b1a8ad6c187 84 {
ovidiup13 5:5b1a8ad6c187 85 if(c == 'y') {
ovidiup13 5:5b1a8ad6c187 86 lt->terminate();
ovidiup13 5:5b1a8ad6c187 87 free(lt); lt = NULL;
ovidiup13 8:81ed1135ba02 88 gyro->write(0);
ovidiup13 5:5b1a8ad6c187 89 st7565->clear();
ovidiup13 5:5b1a8ad6c187 90 this->setSelectedScreen(back);
ovidiup13 5:5b1a8ad6c187 91 }
ovidiup13 3:688b62ff6474 92 }