Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: ELEC2645_JoystickLCD_LPC1768_2021
lib/Road.cpp@3:cbe2dcca5058, 2021-03-19 (annotated)
- Committer:
- alex_20
- Date:
- Fri Mar 19 20:04:39 2021 +0000
- Revision:
- 3:cbe2dcca5058
- Parent:
- 2:18fd28044860
- Child:
- 4:def20a1665d1
everything in N5110
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| alex_20 | 1:2ae7a8b01771 | 1 | #include "Road.h" |
| alex_20 | 3:cbe2dcca5058 | 2 | #include <vector> |
| alex_20 | 1:2ae7a8b01771 | 3 | |
| alex_20 | 1:2ae7a8b01771 | 4 | // constructure |
| alex_20 | 2:18fd28044860 | 5 | Road::Road() {} |
| alex_20 | 2:18fd28044860 | 6 | |
| alex_20 | 2:18fd28044860 | 7 | void Road::init() { |
| alex_20 | 2:18fd28044860 | 8 | //initialize parameters |
| alex_20 | 2:18fd28044860 | 9 | int direction = 0; |
| alex_20 | 2:18fd28044860 | 10 | int inclination = 0; |
| alex_20 | 2:18fd28044860 | 11 | |
| alex_20 | 2:18fd28044860 | 12 | _direction = direction; |
| alex_20 | 2:18fd28044860 | 13 | _inclination = inclination; |
| alex_20 | 2:18fd28044860 | 14 | } |
| alex_20 | 2:18fd28044860 | 15 | |
| alex_20 | 2:18fd28044860 | 16 | void Road::set_inclination(int inclination) { |
| alex_20 | 2:18fd28044860 | 17 | _inclination = inclination; |
| alex_20 | 1:2ae7a8b01771 | 18 | } |
| alex_20 | 1:2ae7a8b01771 | 19 | |
| alex_20 | 3:cbe2dcca5058 | 20 | void Road::draw(N5110 &lcd, int direction) { |
| alex_20 | 3:cbe2dcca5058 | 21 | |
| alex_20 | 3:cbe2dcca5058 | 22 | if (direction == 0) { |
| alex_20 | 3:cbe2dcca5058 | 23 | lcd.drawLine( 0,12,84,12, FILL_BLACK); |
| alex_20 | 3:cbe2dcca5058 | 24 | lcd.drawLine(28,12,12,48, FILL_BLACK); |
| alex_20 | 3:cbe2dcca5058 | 25 | lcd.drawLine(56,12,72,48, FILL_BLACK); |
| alex_20 | 1:2ae7a8b01771 | 26 | } |
| alex_20 | 2:18fd28044860 | 27 | |
| alex_20 | 3:cbe2dcca5058 | 28 | else { |
| alex_20 | 3:cbe2dcca5058 | 29 | lcd.drawLine (0,12,84,12, FILL_BLACK); |
| alex_20 | 3:cbe2dcca5058 | 30 | std::vector<Vector2Df> curve_points_1 = lcd.getCurve(12,48,20 + 5 * direction, 30 - abs(direction),28,12); |
| alex_20 | 3:cbe2dcca5058 | 31 | std::vector<Vector2Df> curve_points_2 = lcd.getCurve(72,48,64 + 5 * direction, 30 - abs(direction),56,12); |
| alex_20 | 3:cbe2dcca5058 | 32 | |
| alex_20 | 3:cbe2dcca5058 | 33 | lcd.drawCurve(curve_points_1, 0, 1, TYPE_SOLID); |
| alex_20 | 3:cbe2dcca5058 | 34 | lcd.drawCurve(curve_points_2, 0, 1, TYPE_SOLID); |
| alex_20 | 3:cbe2dcca5058 | 35 | } |
| alex_20 | 3:cbe2dcca5058 | 36 | } |
| alex_20 | 3:cbe2dcca5058 | 37 | |
| alex_20 | 3:cbe2dcca5058 | 38 | |
| alex_20 | 3:cbe2dcca5058 | 39 | void Road::draw_warn(N5110 &lcd, int warn_position) { |
| alex_20 | 3:cbe2dcca5058 | 40 | const int warn_sign[12][12] = { |
| alex_20 | 3:cbe2dcca5058 | 41 | { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, |
| alex_20 | 3:cbe2dcca5058 | 42 | { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }, |
| alex_20 | 3:cbe2dcca5058 | 43 | { 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1 }, |
| alex_20 | 3:cbe2dcca5058 | 44 | { 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1 }, |
| alex_20 | 3:cbe2dcca5058 | 45 | { 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1 }, |
| alex_20 | 3:cbe2dcca5058 | 46 | { 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1 }, |
| alex_20 | 3:cbe2dcca5058 | 47 | { 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1 }, |
| alex_20 | 3:cbe2dcca5058 | 48 | { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }, |
| alex_20 | 3:cbe2dcca5058 | 49 | { 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1 }, |
| alex_20 | 3:cbe2dcca5058 | 50 | { 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1 }, |
| alex_20 | 3:cbe2dcca5058 | 51 | { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }, |
| alex_20 | 3:cbe2dcca5058 | 52 | { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, |
| alex_20 | 2:18fd28044860 | 53 | }; |
| alex_20 | 2:18fd28044860 | 54 | |
| alex_20 | 2:18fd28044860 | 55 | // if ball comes from the left side |
| alex_20 | 2:18fd28044860 | 56 | if (warn_position == 0) { |
| alex_20 | 3:cbe2dcca5058 | 57 | lcd.drawSprite(0,18,12,12,(int *)warn_sign); |
| alex_20 | 1:2ae7a8b01771 | 58 | } |
| alex_20 | 2:18fd28044860 | 59 | |
| alex_20 | 2:18fd28044860 | 60 | // if ball comes from the top |
| alex_20 | 2:18fd28044860 | 61 | if (warn_position == 1) { |
| alex_20 | 3:cbe2dcca5058 | 62 | lcd.drawSprite(36,0,12,12,(int *)warn_sign); |
| alex_20 | 2:18fd28044860 | 63 | } |
| alex_20 | 2:18fd28044860 | 64 | |
| alex_20 | 2:18fd28044860 | 65 | // if ball comes from the right side |
| alex_20 | 2:18fd28044860 | 66 | if (warn_position == 2) { |
| alex_20 | 3:cbe2dcca5058 | 67 | lcd.drawSprite(72,18,12,12,(int *)warn_sign); |
| alex_20 | 2:18fd28044860 | 68 | } |
| alex_20 | 2:18fd28044860 | 69 | } |
| alex_20 | 2:18fd28044860 | 70 |