![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Allows users to seamlessly write to 2 or 3 uLCD screens as if they were one large screen.
Dependencies: 4DGL-uLCD-SE mbed-rtos mbed
uLCD_Multiscreen.cpp@0:15002a72309b, 2015-03-11 (annotated)
- Committer:
- Mkuchnik3
- Date:
- Wed Mar 11 21:33:18 2015 +0000
- Revision:
- 0:15002a72309b
First Commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Mkuchnik3 | 0:15002a72309b | 1 | #include "uLCD_Multiscreen.h" |
Mkuchnik3 | 0:15002a72309b | 2 | #include "mbed.h" |
Mkuchnik3 | 0:15002a72309b | 3 | uLCD_Multiscreen::uLCD_Multiscreen(vector<uLCD_4DGL*> screens) : virtualScreen(screens, 128, 128 * screens.size()) |
Mkuchnik3 | 0:15002a72309b | 4 | { |
Mkuchnik3 | 0:15002a72309b | 5 | printf("Multiscreen Booting."); |
Mkuchnik3 | 0:15002a72309b | 6 | } |
Mkuchnik3 | 0:15002a72309b | 7 | |
Mkuchnik3 | 0:15002a72309b | 8 | void uLCD_Multiscreen::unfilledRectangle(int x, int y, int w, int h, int color) |
Mkuchnik3 | 0:15002a72309b | 9 | { |
Mkuchnik3 | 0:15002a72309b | 10 | for(int i = x; i <= x + w; i++) { |
Mkuchnik3 | 0:15002a72309b | 11 | virtualScreen.setPixel(i, y, color); |
Mkuchnik3 | 0:15002a72309b | 12 | } |
Mkuchnik3 | 0:15002a72309b | 13 | for(int i = x; i <= x + w; i++) { |
Mkuchnik3 | 0:15002a72309b | 14 | virtualScreen.setPixel(i, y + h, color); |
Mkuchnik3 | 0:15002a72309b | 15 | } |
Mkuchnik3 | 0:15002a72309b | 16 | |
Mkuchnik3 | 0:15002a72309b | 17 | for(int i = y; i <= y + h; i++) { |
Mkuchnik3 | 0:15002a72309b | 18 | virtualScreen.setPixel(x, i, color); |
Mkuchnik3 | 0:15002a72309b | 19 | } |
Mkuchnik3 | 0:15002a72309b | 20 | for(int i = y; i <= y + h; i++) { |
Mkuchnik3 | 0:15002a72309b | 21 | virtualScreen.setPixel(x + w, i, color); |
Mkuchnik3 | 0:15002a72309b | 22 | } |
Mkuchnik3 | 0:15002a72309b | 23 | |
Mkuchnik3 | 0:15002a72309b | 24 | } |
Mkuchnik3 | 0:15002a72309b | 25 | |
Mkuchnik3 | 0:15002a72309b | 26 | void uLCD_Multiscreen::drawLine(int x1, int y1, int x2, int y2, int color) |
Mkuchnik3 | 0:15002a72309b | 27 | { |
Mkuchnik3 | 0:15002a72309b | 28 | int delta_x(x2 - x1); |
Mkuchnik3 | 0:15002a72309b | 29 | // if x1 == x2, then it does not matter what we set here |
Mkuchnik3 | 0:15002a72309b | 30 | signed char const ix((delta_x > 0) - (delta_x < 0)); |
Mkuchnik3 | 0:15002a72309b | 31 | delta_x = std::abs(delta_x) << 1; |
Mkuchnik3 | 0:15002a72309b | 32 | |
Mkuchnik3 | 0:15002a72309b | 33 | int delta_y(y2 - y1); |
Mkuchnik3 | 0:15002a72309b | 34 | // if y1 == y2, then it does not matter what we set here |
Mkuchnik3 | 0:15002a72309b | 35 | signed char const iy((delta_y > 0) - (delta_y < 0)); |
Mkuchnik3 | 0:15002a72309b | 36 | delta_y = std::abs(delta_y) << 1; |
Mkuchnik3 | 0:15002a72309b | 37 | |
Mkuchnik3 | 0:15002a72309b | 38 | virtualScreen.setPixel(x1, y1, color); |
Mkuchnik3 | 0:15002a72309b | 39 | |
Mkuchnik3 | 0:15002a72309b | 40 | if (delta_x >= delta_y) |
Mkuchnik3 | 0:15002a72309b | 41 | { |
Mkuchnik3 | 0:15002a72309b | 42 | // error may go below zero |
Mkuchnik3 | 0:15002a72309b | 43 | int error(delta_y - (delta_x >> 1)); |
Mkuchnik3 | 0:15002a72309b | 44 | |
Mkuchnik3 | 0:15002a72309b | 45 | while (x1 != x2) |
Mkuchnik3 | 0:15002a72309b | 46 | { |
Mkuchnik3 | 0:15002a72309b | 47 | if ((error >= 0) && (error || (ix > 0))) |
Mkuchnik3 | 0:15002a72309b | 48 | { |
Mkuchnik3 | 0:15002a72309b | 49 | error -= delta_x; |
Mkuchnik3 | 0:15002a72309b | 50 | y1 += iy; |
Mkuchnik3 | 0:15002a72309b | 51 | } |
Mkuchnik3 | 0:15002a72309b | 52 | // else do nothing |
Mkuchnik3 | 0:15002a72309b | 53 | |
Mkuchnik3 | 0:15002a72309b | 54 | error += delta_y; |
Mkuchnik3 | 0:15002a72309b | 55 | x1 += ix; |
Mkuchnik3 | 0:15002a72309b | 56 | |
Mkuchnik3 | 0:15002a72309b | 57 | virtualScreen.setPixel(x1, y1, color); |
Mkuchnik3 | 0:15002a72309b | 58 | } |
Mkuchnik3 | 0:15002a72309b | 59 | } |
Mkuchnik3 | 0:15002a72309b | 60 | else |
Mkuchnik3 | 0:15002a72309b | 61 | { |
Mkuchnik3 | 0:15002a72309b | 62 | // error may go below zero |
Mkuchnik3 | 0:15002a72309b | 63 | int error(delta_x - (delta_y >> 1)); |
Mkuchnik3 | 0:15002a72309b | 64 | |
Mkuchnik3 | 0:15002a72309b | 65 | while (y1 != y2) |
Mkuchnik3 | 0:15002a72309b | 66 | { |
Mkuchnik3 | 0:15002a72309b | 67 | if ((error >= 0) && (error || (iy > 0))) |
Mkuchnik3 | 0:15002a72309b | 68 | { |
Mkuchnik3 | 0:15002a72309b | 69 | error -= delta_y; |
Mkuchnik3 | 0:15002a72309b | 70 | x1 += ix; |
Mkuchnik3 | 0:15002a72309b | 71 | } |
Mkuchnik3 | 0:15002a72309b | 72 | // else do nothing |
Mkuchnik3 | 0:15002a72309b | 73 | |
Mkuchnik3 | 0:15002a72309b | 74 | error += delta_x; |
Mkuchnik3 | 0:15002a72309b | 75 | y1 += iy; |
Mkuchnik3 | 0:15002a72309b | 76 | |
Mkuchnik3 | 0:15002a72309b | 77 | virtualScreen.setPixel(x1, y1, color); |
Mkuchnik3 | 0:15002a72309b | 78 | } |
Mkuchnik3 | 0:15002a72309b | 79 | } |
Mkuchnik3 | 0:15002a72309b | 80 | } |
Mkuchnik3 | 0:15002a72309b | 81 | |
Mkuchnik3 | 0:15002a72309b | 82 | void uLCD_Multiscreen::unfilledCircle(int x0, int y0, int radius, int color) |
Mkuchnik3 | 0:15002a72309b | 83 | { |
Mkuchnik3 | 0:15002a72309b | 84 | int x = radius; |
Mkuchnik3 | 0:15002a72309b | 85 | int y = 0; |
Mkuchnik3 | 0:15002a72309b | 86 | int radiusError = 1-x; |
Mkuchnik3 | 0:15002a72309b | 87 | |
Mkuchnik3 | 0:15002a72309b | 88 | while(x >= y) |
Mkuchnik3 | 0:15002a72309b | 89 | { |
Mkuchnik3 | 0:15002a72309b | 90 | virtualScreen.setPixel(x + x0, y + y0, color); |
Mkuchnik3 | 0:15002a72309b | 91 | virtualScreen.setPixel(y + x0, x + y0, color); |
Mkuchnik3 | 0:15002a72309b | 92 | virtualScreen.setPixel(-x + x0, y + y0, color); |
Mkuchnik3 | 0:15002a72309b | 93 | virtualScreen.setPixel(-y + x0, x + y0, color); |
Mkuchnik3 | 0:15002a72309b | 94 | virtualScreen.setPixel(-x + x0, -y + y0, color); |
Mkuchnik3 | 0:15002a72309b | 95 | virtualScreen.setPixel(-y + x0, -x + y0, color); |
Mkuchnik3 | 0:15002a72309b | 96 | virtualScreen.setPixel(x + x0, -y + y0, color); |
Mkuchnik3 | 0:15002a72309b | 97 | virtualScreen.setPixel(y + x0, -x + y0, color); |
Mkuchnik3 | 0:15002a72309b | 98 | y++; |
Mkuchnik3 | 0:15002a72309b | 99 | if (radiusError<0) |
Mkuchnik3 | 0:15002a72309b | 100 | { |
Mkuchnik3 | 0:15002a72309b | 101 | radiusError += 2 * y + 1; |
Mkuchnik3 | 0:15002a72309b | 102 | } |
Mkuchnik3 | 0:15002a72309b | 103 | else |
Mkuchnik3 | 0:15002a72309b | 104 | { |
Mkuchnik3 | 0:15002a72309b | 105 | x--; |
Mkuchnik3 | 0:15002a72309b | 106 | radiusError += 2 * (y - x) + 1; |
Mkuchnik3 | 0:15002a72309b | 107 | } |
Mkuchnik3 | 0:15002a72309b | 108 | } |
Mkuchnik3 | 0:15002a72309b | 109 | } |
Mkuchnik3 | 0:15002a72309b | 110 | |
Mkuchnik3 | 0:15002a72309b | 111 | void uLCD_Multiscreen::cls() { |
Mkuchnik3 | 0:15002a72309b | 112 | virtualScreen.clearScreen(); |
Mkuchnik3 | 0:15002a72309b | 113 | } |
Mkuchnik3 | 0:15002a72309b | 114 | |
Mkuchnik3 | 0:15002a72309b | 115 | |
Mkuchnik3 | 0:15002a72309b | 116 | void uLCD_Multiscreen::changeBackground(int color) { |
Mkuchnik3 | 0:15002a72309b | 117 | virtualScreen.background_color(color); |
Mkuchnik3 | 0:15002a72309b | 118 | } |
Mkuchnik3 | 0:15002a72309b | 119 | void uLCD_Multiscreen::setBaudRate(int rate) { |
Mkuchnik3 | 0:15002a72309b | 120 | virtualScreen.setBaudRate(rate); |
Mkuchnik3 | 0:15002a72309b | 121 | } |