LCD implementation of our project.
Dependencies: mbed mbed-rtos MLX90614
LevelMeter.cpp@5:5b1a8ad6c187, 2015-05-28 (annotated)
- Committer:
- ovidiup13
- Date:
- Thu May 28 16:07:00 2015 +0000
- Revision:
- 5:5b1a8ad6c187
- Parent:
- 3:688b62ff6474
- Child:
- 6:49a007861c76
added levelmeter functionality and threading
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ovidiup13 | 3:688b62ff6474 | 1 | #include "LevelMeter.h" |
ovidiup13 | 3:688b62ff6474 | 2 | |
ovidiup13 | 5:5b1a8ad6c187 | 3 | LevelMeter::LevelMeter(ST7565 *lcd, Item * back) |
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 | 5:5b1a8ad6c187 | 8 | lt = NULL; |
ovidiup13 | 5:5b1a8ad6c187 | 9 | } |
ovidiup13 | 5:5b1a8ad6c187 | 10 | |
ovidiup13 | 5:5b1a8ad6c187 | 11 | void LevelMeter::display(void) |
ovidiup13 | 5:5b1a8ad6c187 | 12 | { |
ovidiup13 | 5:5b1a8ad6c187 | 13 | //create a new thread to get and update compass - do later |
ovidiup13 | 5:5b1a8ad6c187 | 14 | if(lt != NULL) return;//thread is already running |
ovidiup13 | 5:5b1a8ad6c187 | 15 | lt = new Thread(&LevelMeter::lt_start, this); |
ovidiup13 | 5:5b1a8ad6c187 | 16 | lt->signal_set(START_THREAD); |
ovidiup13 | 3:688b62ff6474 | 17 | } |
ovidiup13 | 3:688b62ff6474 | 18 | |
ovidiup13 | 5:5b1a8ad6c187 | 19 | //trigger for starting the thread |
ovidiup13 | 5:5b1a8ad6c187 | 20 | void LevelMeter::lt_start(void const *args) |
ovidiup13 | 5:5b1a8ad6c187 | 21 | { |
ovidiup13 | 5:5b1a8ad6c187 | 22 | LevelMeter *l = (LevelMeter*)args; |
ovidiup13 | 5:5b1a8ad6c187 | 23 | l->update_cross(); |
ovidiup13 | 3:688b62ff6474 | 24 | } |
ovidiup13 | 3:688b62ff6474 | 25 | |
ovidiup13 | 5:5b1a8ad6c187 | 26 | void LevelMeter::update_cross() |
ovidiup13 | 5:5b1a8ad6c187 | 27 | { |
ovidiup13 | 5:5b1a8ad6c187 | 28 | lt->signal_wait(START_THREAD); //wait for signal to start thread |
ovidiup13 | 5:5b1a8ad6c187 | 29 | //draw the static circle |
ovidiup13 | 5:5b1a8ad6c187 | 30 | int i = 0, j = 0; |
ovidiup13 | 5:5b1a8ad6c187 | 31 | while(true) { |
ovidiup13 | 5:5b1a8ad6c187 | 32 | draw_elements(i++, j++); |
ovidiup13 | 5:5b1a8ad6c187 | 33 | //do something |
ovidiup13 | 5:5b1a8ad6c187 | 34 | Thread::wait(30); |
ovidiup13 | 5:5b1a8ad6c187 | 35 | st7565->clear(); |
ovidiup13 | 5:5b1a8ad6c187 | 36 | } |
ovidiup13 | 5:5b1a8ad6c187 | 37 | } |
ovidiup13 | 5:5b1a8ad6c187 | 38 | |
ovidiup13 | 5:5b1a8ad6c187 | 39 | void LevelMeter::draw_elements(double rx, double ry){ |
ovidiup13 | 5:5b1a8ad6c187 | 40 | int cross_x, cross_y; |
ovidiup13 | 3:688b62ff6474 | 41 | |
ovidiup13 | 3:688b62ff6474 | 42 | //draw the circles |
ovidiup13 | 5:5b1a8ad6c187 | 43 | st7565->drawcircle(X0, Y0, RADIUS_lvl, 1); |
ovidiup13 | 5:5b1a8ad6c187 | 44 | |
ovidiup13 | 5:5b1a8ad6c187 | 45 | //draw middle cross |
ovidiup13 | 3:688b62ff6474 | 46 | st7565->drawline(X0 - 2, Y0, X0 + 2, Y0, 20); |
ovidiup13 | 3:688b62ff6474 | 47 | st7565->drawline(X0, Y0 - 2, X0, Y0 + 2, 20); |
ovidiup13 | 3:688b62ff6474 | 48 | |
ovidiup13 | 5:5b1a8ad6c187 | 49 | //check if rotation in negative interval |
ovidiup13 | 5:5b1a8ad6c187 | 50 | if(rx >= 270) rx -= 360; |
ovidiup13 | 5:5b1a8ad6c187 | 51 | if(ry >= 270) ry -= 360; |
ovidiup13 | 5:5b1a8ad6c187 | 52 | |
ovidiup13 | 5:5b1a8ad6c187 | 53 | //calculate coordinates |
ovidiup13 | 5:5b1a8ad6c187 | 54 | cross_x = (int) ((rx * SCREEN_WIDTH)/360.0) + 63; |
ovidiup13 | 5:5b1a8ad6c187 | 55 | cross_y = (int) ((ry * SCREEN_HEIGHT)/360.0) + 35; |
ovidiup13 | 5:5b1a8ad6c187 | 56 | |
ovidiup13 | 5:5b1a8ad6c187 | 57 | printf("Coordinates for cross are: %d, %d\n", cross_x, cross_y); |
ovidiup13 | 5:5b1a8ad6c187 | 58 | |
ovidiup13 | 5:5b1a8ad6c187 | 59 | //draw the cross |
ovidiup13 | 5:5b1a8ad6c187 | 60 | st7565->drawline(cross_x, cross_y - RADIUS_lvl/2, cross_x, cross_y + RADIUS_lvl/2, DEFAULT_COLOR); |
ovidiup13 | 5:5b1a8ad6c187 | 61 | st7565->drawline(cross_x - RADIUS_lvl/2, cross_y, cross_x + RADIUS_lvl/2, cross_y, DEFAULT_COLOR); |
ovidiup13 | 5:5b1a8ad6c187 | 62 | |
ovidiup13 | 5:5b1a8ad6c187 | 63 | //display |
ovidiup13 | 3:688b62ff6474 | 64 | st7565->display(); |
ovidiup13 | 5:5b1a8ad6c187 | 65 | } |
ovidiup13 | 5:5b1a8ad6c187 | 66 | |
ovidiup13 | 5:5b1a8ad6c187 | 67 | void LevelMeter::update(char c) |
ovidiup13 | 5:5b1a8ad6c187 | 68 | { |
ovidiup13 | 5:5b1a8ad6c187 | 69 | if(c == 'y') { |
ovidiup13 | 5:5b1a8ad6c187 | 70 | lt->terminate(); |
ovidiup13 | 5:5b1a8ad6c187 | 71 | free(lt); lt = NULL; |
ovidiup13 | 5:5b1a8ad6c187 | 72 | st7565->clear(); |
ovidiup13 | 5:5b1a8ad6c187 | 73 | this->setSelectedScreen(back); |
ovidiup13 | 5:5b1a8ad6c187 | 74 | } |
ovidiup13 | 3:688b62ff6474 | 75 | } |