LCD implementation of our project.
Dependencies: mbed mbed-rtos MLX90614
Measure.cpp@3:688b62ff6474, 2015-04-26 (annotated)
- Committer:
- ovidiup13
- Date:
- Sun Apr 26 16:29:53 2015 +0000
- Revision:
- 3:688b62ff6474
- Child:
- 7:11675c1dce4f
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?
User | Revision | Line number | New contents of line |
---|---|---|---|
ovidiup13 | 3:688b62ff6474 | 1 | #include "Measure.h" |
ovidiup13 | 3:688b62ff6474 | 2 | |
ovidiup13 | 3:688b62ff6474 | 3 | void Measure::display(void){ |
ovidiup13 | 3:688b62ff6474 | 4 | this->display_items(); |
ovidiup13 | 3:688b62ff6474 | 5 | } |
ovidiup13 | 3:688b62ff6474 | 6 | |
ovidiup13 | 3:688b62ff6474 | 7 | void Measure::update(char c){ |
ovidiup13 | 3:688b62ff6474 | 8 | //select down |
ovidiup13 | 3:688b62ff6474 | 9 | if(c == 's'){ |
ovidiup13 | 3:688b62ff6474 | 10 | if(selected == 2) return; //do nothing |
ovidiup13 | 3:688b62ff6474 | 11 | printf("measure - going down"); |
ovidiup13 | 3:688b62ff6474 | 12 | selected = 2; |
ovidiup13 | 3:688b62ff6474 | 13 | current_line = 7; |
ovidiup13 | 3:688b62ff6474 | 14 | } |
ovidiup13 | 3:688b62ff6474 | 15 | //select up |
ovidiup13 | 3:688b62ff6474 | 16 | else if(c == 'w'){ |
ovidiup13 | 3:688b62ff6474 | 17 | if(selected == 1) return; //do nothing |
ovidiup13 | 3:688b62ff6474 | 18 | selected = 1; |
ovidiup13 | 3:688b62ff6474 | 19 | current_line = 6; |
ovidiup13 | 3:688b62ff6474 | 20 | } |
ovidiup13 | 3:688b62ff6474 | 21 | //go to next screen |
ovidiup13 | 3:688b62ff6474 | 22 | else if(c == 'y'){ |
ovidiup13 | 3:688b62ff6474 | 23 | if(selected == 1) |
ovidiup13 | 3:688b62ff6474 | 24 | this->setSelectedScreen(next); |
ovidiup13 | 3:688b62ff6474 | 25 | else if(selected == 2) |
ovidiup13 | 3:688b62ff6474 | 26 | this->setSelectedScreen(back); |
ovidiup13 | 3:688b62ff6474 | 27 | else |
ovidiup13 | 3:688b62ff6474 | 28 | return; |
ovidiup13 | 3:688b62ff6474 | 29 | } |
ovidiup13 | 3:688b62ff6474 | 30 | //display items |
ovidiup13 | 3:688b62ff6474 | 31 | display_items(); |
ovidiup13 | 3:688b62ff6474 | 32 | } |
ovidiup13 | 3:688b62ff6474 | 33 | |
ovidiup13 | 3:688b62ff6474 | 34 | void Measure::display_description(char * r){ |
ovidiup13 | 3:688b62ff6474 | 35 | st7565->drawstring(0, 2, description); //description |
ovidiup13 | 3:688b62ff6474 | 36 | //result |
ovidiup13 | 3:688b62ff6474 | 37 | if(hasResult) |
ovidiup13 | 3:688b62ff6474 | 38 | st7565->drawstring(30, 5, r); |
ovidiup13 | 3:688b62ff6474 | 39 | } |
ovidiup13 | 3:688b62ff6474 | 40 | |
ovidiup13 | 3:688b62ff6474 | 41 | void Measure::display_items(void){ |
ovidiup13 | 3:688b62ff6474 | 42 | //clear screen |
ovidiup13 | 3:688b62ff6474 | 43 | st7565->clear(); |
ovidiup13 | 3:688b62ff6474 | 44 | |
ovidiup13 | 3:688b62ff6474 | 45 | //display result if it is a result screen |
ovidiup13 | 3:688b62ff6474 | 46 | float r = 5; |
ovidiup13 | 3:688b62ff6474 | 47 | char result[15]; |
ovidiup13 | 3:688b62ff6474 | 48 | if(hasResult){ |
ovidiup13 | 3:688b62ff6474 | 49 | //calculate result |
ovidiup13 | 3:688b62ff6474 | 50 | sprintf(result, "%.2f Meters", r); |
ovidiup13 | 3:688b62ff6474 | 51 | } |
ovidiup13 | 3:688b62ff6474 | 52 | |
ovidiup13 | 3:688b62ff6474 | 53 | //display description |
ovidiup13 | 3:688b62ff6474 | 54 | display_description(result); |
ovidiup13 | 3:688b62ff6474 | 55 | |
ovidiup13 | 3:688b62ff6474 | 56 | //draw items |
ovidiup13 | 3:688b62ff6474 | 57 | st7565->drawstring(LEFT_MARGIN * 2, SELECTION_LINE, nextName); |
ovidiup13 | 3:688b62ff6474 | 58 | st7565->drawstring(LEFT_MARGIN * 2, SELECTION_LINE + 1, backName); |
ovidiup13 | 3:688b62ff6474 | 59 | |
ovidiup13 | 3:688b62ff6474 | 60 | //set first as selected |
ovidiup13 | 3:688b62ff6474 | 61 | st7565->drawcircle(2, (current_line * 8) + 3, 2, 20); |
ovidiup13 | 3:688b62ff6474 | 62 | st7565->display(); |
ovidiup13 | 3:688b62ff6474 | 63 | } |