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