epaper
Dependents: epaper_mbed_test_copy1
Fork of EaEpaper by
EaEpaper.cpp@0:fedcef5319f5, 2013-11-09 (annotated)
- Committer:
- dreschpe
- Date:
- Sat Nov 09 23:37:43 2013 +0000
- Revision:
- 0:fedcef5319f5
Lib for using a E-Paper display from Pervasive Displays.; There is a interface board from Embedded Artists.; It can handle graphic and text drawing and is using external fonts.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dreschpe | 0:fedcef5319f5 | 1 | |
dreschpe | 0:fedcef5319f5 | 2 | #include "EaEpaper.h" |
dreschpe | 0:fedcef5319f5 | 3 | |
dreschpe | 0:fedcef5319f5 | 4 | #define EA_IMG_BUF_SZ (5808) // 264 x 176 / 8 = 5808 |
dreschpe | 0:fedcef5319f5 | 5 | |
dreschpe | 0:fedcef5319f5 | 6 | #define LM75A_ADDRESS (0x92) // 0x49 << 1 |
dreschpe | 0:fedcef5319f5 | 7 | #define LM75A_CMD_TEMP 0x00 |
dreschpe | 0:fedcef5319f5 | 8 | |
dreschpe | 0:fedcef5319f5 | 9 | static uint8_t _oldImage[EA_IMG_BUF_SZ]; |
dreschpe | 0:fedcef5319f5 | 10 | static uint8_t _newImage[EA_IMG_BUF_SZ]; |
dreschpe | 0:fedcef5319f5 | 11 | |
dreschpe | 0:fedcef5319f5 | 12 | EaEpaper::EaEpaper(PinName p_on, PinName border, PinName discharge, PinName reset, PinName busy, PinName cs, |
dreschpe | 0:fedcef5319f5 | 13 | PinName pwm, |
dreschpe | 0:fedcef5319f5 | 14 | PinName mosi, PinName miso, PinName sck, |
dreschpe | 0:fedcef5319f5 | 15 | PinName sda, PinName scl, |
dreschpe | 0:fedcef5319f5 | 16 | const char* name): |
dreschpe | 0:fedcef5319f5 | 17 | epd_(EPD_2_7, |
dreschpe | 0:fedcef5319f5 | 18 | p_on, // panel_on_pin |
dreschpe | 0:fedcef5319f5 | 19 | border, // border_pin |
dreschpe | 0:fedcef5319f5 | 20 | discharge, // discharge_pin |
dreschpe | 0:fedcef5319f5 | 21 | pwm, // pwm_pin |
dreschpe | 0:fedcef5319f5 | 22 | reset, // reset_pin |
dreschpe | 0:fedcef5319f5 | 23 | busy, // busy_pin |
dreschpe | 0:fedcef5319f5 | 24 | cs, // chip_select_pin |
dreschpe | 0:fedcef5319f5 | 25 | mosi, // mosi |
dreschpe | 0:fedcef5319f5 | 26 | miso, // miso |
dreschpe | 0:fedcef5319f5 | 27 | sck), // sck |
dreschpe | 0:fedcef5319f5 | 28 | i2c_(sda, scl), |
dreschpe | 0:fedcef5319f5 | 29 | GraphicsDisplay(name) |
dreschpe | 0:fedcef5319f5 | 30 | { |
dreschpe | 0:fedcef5319f5 | 31 | draw_mode = NORMAL; |
dreschpe | 0:fedcef5319f5 | 32 | memset(_oldImage, 0, EA_IMG_BUF_SZ); |
dreschpe | 0:fedcef5319f5 | 33 | memset(_newImage, 0, EA_IMG_BUF_SZ); |
dreschpe | 0:fedcef5319f5 | 34 | } |
dreschpe | 0:fedcef5319f5 | 35 | |
dreschpe | 0:fedcef5319f5 | 36 | |
dreschpe | 0:fedcef5319f5 | 37 | int EaEpaper::width() |
dreschpe | 0:fedcef5319f5 | 38 | { |
dreschpe | 0:fedcef5319f5 | 39 | return 264; |
dreschpe | 0:fedcef5319f5 | 40 | } |
dreschpe | 0:fedcef5319f5 | 41 | |
dreschpe | 0:fedcef5319f5 | 42 | int EaEpaper::height() |
dreschpe | 0:fedcef5319f5 | 43 | { |
dreschpe | 0:fedcef5319f5 | 44 | return 176; |
dreschpe | 0:fedcef5319f5 | 45 | } |
dreschpe | 0:fedcef5319f5 | 46 | |
dreschpe | 0:fedcef5319f5 | 47 | |
dreschpe | 0:fedcef5319f5 | 48 | // erase pixel after power up |
dreschpe | 0:fedcef5319f5 | 49 | void EaEpaper::clear() |
dreschpe | 0:fedcef5319f5 | 50 | { |
dreschpe | 0:fedcef5319f5 | 51 | epd_.begin(); |
dreschpe | 0:fedcef5319f5 | 52 | epd_.setFactor(readTemperature()/100); |
dreschpe | 0:fedcef5319f5 | 53 | epd_.clear(); |
dreschpe | 0:fedcef5319f5 | 54 | epd_.end(); |
dreschpe | 0:fedcef5319f5 | 55 | |
dreschpe | 0:fedcef5319f5 | 56 | memset(_oldImage, 0, EA_IMG_BUF_SZ); |
dreschpe | 0:fedcef5319f5 | 57 | memset(_newImage, 0, EA_IMG_BUF_SZ); |
dreschpe | 0:fedcef5319f5 | 58 | } |
dreschpe | 0:fedcef5319f5 | 59 | |
dreschpe | 0:fedcef5319f5 | 60 | // update screen _newImage -> _oldImage |
dreschpe | 0:fedcef5319f5 | 61 | void EaEpaper::write_disp(void) |
dreschpe | 0:fedcef5319f5 | 62 | { |
dreschpe | 0:fedcef5319f5 | 63 | epd_.begin(); |
dreschpe | 0:fedcef5319f5 | 64 | epd_.setFactor(readTemperature()/100); |
dreschpe | 0:fedcef5319f5 | 65 | epd_.image(_oldImage, _newImage); |
dreschpe | 0:fedcef5319f5 | 66 | epd_.end(); |
dreschpe | 0:fedcef5319f5 | 67 | |
dreschpe | 0:fedcef5319f5 | 68 | memcpy(_oldImage, _newImage, EA_IMG_BUF_SZ); |
dreschpe | 0:fedcef5319f5 | 69 | } |
dreschpe | 0:fedcef5319f5 | 70 | |
dreschpe | 0:fedcef5319f5 | 71 | // read LM75A sensor on board to calculate display speed |
dreschpe | 0:fedcef5319f5 | 72 | int32_t EaEpaper::readTemperature() |
dreschpe | 0:fedcef5319f5 | 73 | { |
dreschpe | 0:fedcef5319f5 | 74 | char buf[2]; |
dreschpe | 0:fedcef5319f5 | 75 | int32_t t = 0; |
dreschpe | 0:fedcef5319f5 | 76 | char reg = LM75A_CMD_TEMP; |
dreschpe | 0:fedcef5319f5 | 77 | |
dreschpe | 0:fedcef5319f5 | 78 | i2c_.write(LM75A_ADDRESS, ®, 1); |
dreschpe | 0:fedcef5319f5 | 79 | i2c_.read(LM75A_ADDRESS, buf, 2); |
dreschpe | 0:fedcef5319f5 | 80 | |
dreschpe | 0:fedcef5319f5 | 81 | t = ((buf[0] << 8) | (buf[1])); |
dreschpe | 0:fedcef5319f5 | 82 | |
dreschpe | 0:fedcef5319f5 | 83 | return ((t * 100) >> 8); |
dreschpe | 0:fedcef5319f5 | 84 | } |
dreschpe | 0:fedcef5319f5 | 85 | |
dreschpe | 0:fedcef5319f5 | 86 | // set one pixel in buffer _newImage |
dreschpe | 0:fedcef5319f5 | 87 | |
dreschpe | 0:fedcef5319f5 | 88 | void EaEpaper::pixel(int x, int y, int color) |
dreschpe | 0:fedcef5319f5 | 89 | { |
dreschpe | 0:fedcef5319f5 | 90 | // first check parameter |
dreschpe | 0:fedcef5319f5 | 91 | if(x > 263 || y > 175 || x < 0 || y < 0) return; |
dreschpe | 0:fedcef5319f5 | 92 | |
dreschpe | 0:fedcef5319f5 | 93 | if(draw_mode == NORMAL) { |
dreschpe | 0:fedcef5319f5 | 94 | if(color == 0) |
dreschpe | 0:fedcef5319f5 | 95 | _newImage[(x / 8) + ((y-1) * 33)] &= ~(1 << (x%8)); // erase pixel |
dreschpe | 0:fedcef5319f5 | 96 | else |
dreschpe | 0:fedcef5319f5 | 97 | _newImage[(x / 8) + ((y-1) * 33)] |= (1 << (x%8)); // set pixel |
dreschpe | 0:fedcef5319f5 | 98 | } else { // XOR mode |
dreschpe | 0:fedcef5319f5 | 99 | if(color == 1) |
dreschpe | 0:fedcef5319f5 | 100 | _newImage[(x / 8) + ((y-1) * 33)] ^= (1 << (x%8)); // xor pixel |
dreschpe | 0:fedcef5319f5 | 101 | } |
dreschpe | 0:fedcef5319f5 | 102 | } |
dreschpe | 0:fedcef5319f5 | 103 | |
dreschpe | 0:fedcef5319f5 | 104 | // clear screen |
dreschpe | 0:fedcef5319f5 | 105 | void EaEpaper::cls(void) |
dreschpe | 0:fedcef5319f5 | 106 | { |
dreschpe | 0:fedcef5319f5 | 107 | memset(_newImage, 0, EA_IMG_BUF_SZ); // clear display buffer |
dreschpe | 0:fedcef5319f5 | 108 | } |
dreschpe | 0:fedcef5319f5 | 109 | |
dreschpe | 0:fedcef5319f5 | 110 | // print line |
dreschpe | 0:fedcef5319f5 | 111 | void EaEpaper::line(int x0, int y0, int x1, int y1, int color) |
dreschpe | 0:fedcef5319f5 | 112 | { |
dreschpe | 0:fedcef5319f5 | 113 | int dx = 0, dy = 0; |
dreschpe | 0:fedcef5319f5 | 114 | int dx_sym = 0, dy_sym = 0; |
dreschpe | 0:fedcef5319f5 | 115 | int dx_x2 = 0, dy_x2 = 0; |
dreschpe | 0:fedcef5319f5 | 116 | int di = 0; |
dreschpe | 0:fedcef5319f5 | 117 | |
dreschpe | 0:fedcef5319f5 | 118 | dx = x1-x0; |
dreschpe | 0:fedcef5319f5 | 119 | dy = y1-y0; |
dreschpe | 0:fedcef5319f5 | 120 | |
dreschpe | 0:fedcef5319f5 | 121 | if (dx > 0) { |
dreschpe | 0:fedcef5319f5 | 122 | dx_sym = 1; |
dreschpe | 0:fedcef5319f5 | 123 | } else { |
dreschpe | 0:fedcef5319f5 | 124 | dx_sym = -1; |
dreschpe | 0:fedcef5319f5 | 125 | } |
dreschpe | 0:fedcef5319f5 | 126 | |
dreschpe | 0:fedcef5319f5 | 127 | if (dy > 0) { |
dreschpe | 0:fedcef5319f5 | 128 | dy_sym = 1; |
dreschpe | 0:fedcef5319f5 | 129 | } else { |
dreschpe | 0:fedcef5319f5 | 130 | dy_sym = -1; |
dreschpe | 0:fedcef5319f5 | 131 | } |
dreschpe | 0:fedcef5319f5 | 132 | |
dreschpe | 0:fedcef5319f5 | 133 | dx = dx_sym*dx; |
dreschpe | 0:fedcef5319f5 | 134 | dy = dy_sym*dy; |
dreschpe | 0:fedcef5319f5 | 135 | |
dreschpe | 0:fedcef5319f5 | 136 | dx_x2 = dx*2; |
dreschpe | 0:fedcef5319f5 | 137 | dy_x2 = dy*2; |
dreschpe | 0:fedcef5319f5 | 138 | |
dreschpe | 0:fedcef5319f5 | 139 | if (dx >= dy) { |
dreschpe | 0:fedcef5319f5 | 140 | di = dy_x2 - dx; |
dreschpe | 0:fedcef5319f5 | 141 | while (x0 != x1) { |
dreschpe | 0:fedcef5319f5 | 142 | |
dreschpe | 0:fedcef5319f5 | 143 | pixel(x0, y0, color); |
dreschpe | 0:fedcef5319f5 | 144 | x0 += dx_sym; |
dreschpe | 0:fedcef5319f5 | 145 | if (di<0) { |
dreschpe | 0:fedcef5319f5 | 146 | di += dy_x2; |
dreschpe | 0:fedcef5319f5 | 147 | } else { |
dreschpe | 0:fedcef5319f5 | 148 | di += dy_x2 - dx_x2; |
dreschpe | 0:fedcef5319f5 | 149 | y0 += dy_sym; |
dreschpe | 0:fedcef5319f5 | 150 | } |
dreschpe | 0:fedcef5319f5 | 151 | } |
dreschpe | 0:fedcef5319f5 | 152 | pixel(x0, y0, color); |
dreschpe | 0:fedcef5319f5 | 153 | } else { |
dreschpe | 0:fedcef5319f5 | 154 | di = dx_x2 - dy; |
dreschpe | 0:fedcef5319f5 | 155 | while (y0 != y1) { |
dreschpe | 0:fedcef5319f5 | 156 | pixel(x0, y0, color); |
dreschpe | 0:fedcef5319f5 | 157 | y0 += dy_sym; |
dreschpe | 0:fedcef5319f5 | 158 | if (di < 0) { |
dreschpe | 0:fedcef5319f5 | 159 | di += dx_x2; |
dreschpe | 0:fedcef5319f5 | 160 | } else { |
dreschpe | 0:fedcef5319f5 | 161 | di += dx_x2 - dy_x2; |
dreschpe | 0:fedcef5319f5 | 162 | x0 += dx_sym; |
dreschpe | 0:fedcef5319f5 | 163 | } |
dreschpe | 0:fedcef5319f5 | 164 | } |
dreschpe | 0:fedcef5319f5 | 165 | pixel(x0, y0, color); |
dreschpe | 0:fedcef5319f5 | 166 | } |
dreschpe | 0:fedcef5319f5 | 167 | } |
dreschpe | 0:fedcef5319f5 | 168 | |
dreschpe | 0:fedcef5319f5 | 169 | // print rect |
dreschpe | 0:fedcef5319f5 | 170 | void EaEpaper::rect(int x0, int y0, int x1, int y1, int color) |
dreschpe | 0:fedcef5319f5 | 171 | { |
dreschpe | 0:fedcef5319f5 | 172 | |
dreschpe | 0:fedcef5319f5 | 173 | if (x1 > x0) line(x0,y0,x1,y0,color); |
dreschpe | 0:fedcef5319f5 | 174 | else line(x1,y0,x0,y0,color); |
dreschpe | 0:fedcef5319f5 | 175 | |
dreschpe | 0:fedcef5319f5 | 176 | if (y1 > y0) line(x0,y0,x0,y1,color); |
dreschpe | 0:fedcef5319f5 | 177 | else line(x0,y1,x0,y0,color); |
dreschpe | 0:fedcef5319f5 | 178 | |
dreschpe | 0:fedcef5319f5 | 179 | if (x1 > x0) line(x0,y1,x1,y1,color); |
dreschpe | 0:fedcef5319f5 | 180 | else line(x1,y1,x0,y1,color); |
dreschpe | 0:fedcef5319f5 | 181 | |
dreschpe | 0:fedcef5319f5 | 182 | if (y1 > y0) line(x1,y0,x1,y1,color); |
dreschpe | 0:fedcef5319f5 | 183 | else line(x1,y1,x1,y0,color); |
dreschpe | 0:fedcef5319f5 | 184 | } |
dreschpe | 0:fedcef5319f5 | 185 | |
dreschpe | 0:fedcef5319f5 | 186 | // print filled rect |
dreschpe | 0:fedcef5319f5 | 187 | void EaEpaper::fillrect(int x0, int y0, int x1, int y1, int color) |
dreschpe | 0:fedcef5319f5 | 188 | { |
dreschpe | 0:fedcef5319f5 | 189 | int l,c,i; |
dreschpe | 0:fedcef5319f5 | 190 | if(x0 > x1) { |
dreschpe | 0:fedcef5319f5 | 191 | i = x0; |
dreschpe | 0:fedcef5319f5 | 192 | x0 = x1; |
dreschpe | 0:fedcef5319f5 | 193 | x1 = i; |
dreschpe | 0:fedcef5319f5 | 194 | } |
dreschpe | 0:fedcef5319f5 | 195 | |
dreschpe | 0:fedcef5319f5 | 196 | if(y0 > y1) { |
dreschpe | 0:fedcef5319f5 | 197 | i = y0; |
dreschpe | 0:fedcef5319f5 | 198 | y0 = y1; |
dreschpe | 0:fedcef5319f5 | 199 | y1 = i; |
dreschpe | 0:fedcef5319f5 | 200 | } |
dreschpe | 0:fedcef5319f5 | 201 | |
dreschpe | 0:fedcef5319f5 | 202 | for(l = x0; l<= x1; l ++) { |
dreschpe | 0:fedcef5319f5 | 203 | for(c = y0; c<= y1; c++) { |
dreschpe | 0:fedcef5319f5 | 204 | pixel(l,c,color); |
dreschpe | 0:fedcef5319f5 | 205 | } |
dreschpe | 0:fedcef5319f5 | 206 | } |
dreschpe | 0:fedcef5319f5 | 207 | } |
dreschpe | 0:fedcef5319f5 | 208 | |
dreschpe | 0:fedcef5319f5 | 209 | // print circle |
dreschpe | 0:fedcef5319f5 | 210 | void EaEpaper::circle(int x0, int y0, int r, int color) |
dreschpe | 0:fedcef5319f5 | 211 | { |
dreschpe | 0:fedcef5319f5 | 212 | int x = -r, y = 0, err = 2-2*r, e2; |
dreschpe | 0:fedcef5319f5 | 213 | do { |
dreschpe | 0:fedcef5319f5 | 214 | pixel(x0-x, y0+y,color); |
dreschpe | 0:fedcef5319f5 | 215 | pixel(x0+x, y0+y,color); |
dreschpe | 0:fedcef5319f5 | 216 | pixel(x0+x, y0-y,color); |
dreschpe | 0:fedcef5319f5 | 217 | pixel(x0-x, y0-y,color); |
dreschpe | 0:fedcef5319f5 | 218 | e2 = err; |
dreschpe | 0:fedcef5319f5 | 219 | if (e2 <= y) { |
dreschpe | 0:fedcef5319f5 | 220 | err += ++y*2+1; |
dreschpe | 0:fedcef5319f5 | 221 | if (-x == y && e2 <= x) e2 = 0; |
dreschpe | 0:fedcef5319f5 | 222 | } |
dreschpe | 0:fedcef5319f5 | 223 | if (e2 > x) err += ++x*2+1; |
dreschpe | 0:fedcef5319f5 | 224 | } while (x <= 0); |
dreschpe | 0:fedcef5319f5 | 225 | |
dreschpe | 0:fedcef5319f5 | 226 | } |
dreschpe | 0:fedcef5319f5 | 227 | |
dreschpe | 0:fedcef5319f5 | 228 | // print filled circle |
dreschpe | 0:fedcef5319f5 | 229 | void EaEpaper::fillcircle(int x0, int y0, int r, int color) |
dreschpe | 0:fedcef5319f5 | 230 | { |
dreschpe | 0:fedcef5319f5 | 231 | int x = -r, y = 0, err = 2-2*r, e2; |
dreschpe | 0:fedcef5319f5 | 232 | do { |
dreschpe | 0:fedcef5319f5 | 233 | line(x0-x, y0-y, x0-x, y0+y, color); |
dreschpe | 0:fedcef5319f5 | 234 | line(x0+x, y0-y, x0+x, y0+y, color); |
dreschpe | 0:fedcef5319f5 | 235 | e2 = err; |
dreschpe | 0:fedcef5319f5 | 236 | if (e2 <= y) { |
dreschpe | 0:fedcef5319f5 | 237 | err += ++y*2+1; |
dreschpe | 0:fedcef5319f5 | 238 | if (-x == y && e2 <= x) e2 = 0; |
dreschpe | 0:fedcef5319f5 | 239 | } |
dreschpe | 0:fedcef5319f5 | 240 | if (e2 > x) err += ++x*2+1; |
dreschpe | 0:fedcef5319f5 | 241 | } while (x <= 0); |
dreschpe | 0:fedcef5319f5 | 242 | } |
dreschpe | 0:fedcef5319f5 | 243 | |
dreschpe | 0:fedcef5319f5 | 244 | // set drawing mode |
dreschpe | 0:fedcef5319f5 | 245 | void EaEpaper::setmode(int mode) |
dreschpe | 0:fedcef5319f5 | 246 | { |
dreschpe | 0:fedcef5319f5 | 247 | draw_mode = mode; |
dreschpe | 0:fedcef5319f5 | 248 | } |
dreschpe | 0:fedcef5319f5 | 249 | |
dreschpe | 0:fedcef5319f5 | 250 | // set cursor position |
dreschpe | 0:fedcef5319f5 | 251 | void EaEpaper::locate(int x, int y) |
dreschpe | 0:fedcef5319f5 | 252 | { |
dreschpe | 0:fedcef5319f5 | 253 | char_x = x; |
dreschpe | 0:fedcef5319f5 | 254 | char_y = y; |
dreschpe | 0:fedcef5319f5 | 255 | } |
dreschpe | 0:fedcef5319f5 | 256 | |
dreschpe | 0:fedcef5319f5 | 257 | // calc char columns |
dreschpe | 0:fedcef5319f5 | 258 | int EaEpaper::columns() |
dreschpe | 0:fedcef5319f5 | 259 | { |
dreschpe | 0:fedcef5319f5 | 260 | return width() / font[1]; |
dreschpe | 0:fedcef5319f5 | 261 | } |
dreschpe | 0:fedcef5319f5 | 262 | |
dreschpe | 0:fedcef5319f5 | 263 | // calc char rows |
dreschpe | 0:fedcef5319f5 | 264 | int EaEpaper::rows() |
dreschpe | 0:fedcef5319f5 | 265 | { |
dreschpe | 0:fedcef5319f5 | 266 | return height() / font[2]; |
dreschpe | 0:fedcef5319f5 | 267 | } |
dreschpe | 0:fedcef5319f5 | 268 | |
dreschpe | 0:fedcef5319f5 | 269 | // print char |
dreschpe | 0:fedcef5319f5 | 270 | int EaEpaper::_putc(int value) |
dreschpe | 0:fedcef5319f5 | 271 | { |
dreschpe | 0:fedcef5319f5 | 272 | if (value == '\n') { // new line |
dreschpe | 0:fedcef5319f5 | 273 | char_x = 0; |
dreschpe | 0:fedcef5319f5 | 274 | char_y = char_y + font[2]; |
dreschpe | 0:fedcef5319f5 | 275 | if (char_y >= height() - font[2]) { |
dreschpe | 0:fedcef5319f5 | 276 | char_y = 0; |
dreschpe | 0:fedcef5319f5 | 277 | } |
dreschpe | 0:fedcef5319f5 | 278 | } else { |
dreschpe | 0:fedcef5319f5 | 279 | character(char_x, char_y, value); |
dreschpe | 0:fedcef5319f5 | 280 | } |
dreschpe | 0:fedcef5319f5 | 281 | return value; |
dreschpe | 0:fedcef5319f5 | 282 | } |
dreschpe | 0:fedcef5319f5 | 283 | |
dreschpe | 0:fedcef5319f5 | 284 | // paint char out of font |
dreschpe | 0:fedcef5319f5 | 285 | void EaEpaper::character(int x, int y, int c) |
dreschpe | 0:fedcef5319f5 | 286 | { |
dreschpe | 0:fedcef5319f5 | 287 | unsigned int hor,vert,offset,bpl,j,i,b; |
dreschpe | 0:fedcef5319f5 | 288 | unsigned char* zeichen; |
dreschpe | 0:fedcef5319f5 | 289 | unsigned char z,w; |
dreschpe | 0:fedcef5319f5 | 290 | |
dreschpe | 0:fedcef5319f5 | 291 | if ((c < 31) || (c > 127)) return; // test char range |
dreschpe | 0:fedcef5319f5 | 292 | |
dreschpe | 0:fedcef5319f5 | 293 | // read font parameter from start of array |
dreschpe | 0:fedcef5319f5 | 294 | offset = font[0]; // bytes / char |
dreschpe | 0:fedcef5319f5 | 295 | hor = font[1]; // get hor size of font |
dreschpe | 0:fedcef5319f5 | 296 | vert = font[2]; // get vert size of font |
dreschpe | 0:fedcef5319f5 | 297 | bpl = font[3]; // bytes per line |
dreschpe | 0:fedcef5319f5 | 298 | |
dreschpe | 0:fedcef5319f5 | 299 | if (char_x + hor > width()) { |
dreschpe | 0:fedcef5319f5 | 300 | char_x = 0; |
dreschpe | 0:fedcef5319f5 | 301 | char_y = char_y + vert; |
dreschpe | 0:fedcef5319f5 | 302 | if (char_y >= height() - font[2]) { |
dreschpe | 0:fedcef5319f5 | 303 | char_y = 0; |
dreschpe | 0:fedcef5319f5 | 304 | } |
dreschpe | 0:fedcef5319f5 | 305 | } |
dreschpe | 0:fedcef5319f5 | 306 | |
dreschpe | 0:fedcef5319f5 | 307 | zeichen = &font[((c -32) * offset) + 4]; // start of char bitmap |
dreschpe | 0:fedcef5319f5 | 308 | w = zeichen[0]; // width of actual char |
dreschpe | 0:fedcef5319f5 | 309 | // construct the char into the buffer |
dreschpe | 0:fedcef5319f5 | 310 | for (j=0; j<vert; j++) { // vert line |
dreschpe | 0:fedcef5319f5 | 311 | for (i=0; i<hor; i++) { // horz line |
dreschpe | 0:fedcef5319f5 | 312 | z = zeichen[bpl * i + ((j & 0xF8) >> 3)+1]; |
dreschpe | 0:fedcef5319f5 | 313 | b = 1 << (j & 0x07); |
dreschpe | 0:fedcef5319f5 | 314 | if (( z & b ) == 0x00) { |
dreschpe | 0:fedcef5319f5 | 315 | pixel(x+i,y+j,0); |
dreschpe | 0:fedcef5319f5 | 316 | } else { |
dreschpe | 0:fedcef5319f5 | 317 | pixel(x+i,y+j,1); |
dreschpe | 0:fedcef5319f5 | 318 | } |
dreschpe | 0:fedcef5319f5 | 319 | |
dreschpe | 0:fedcef5319f5 | 320 | } |
dreschpe | 0:fedcef5319f5 | 321 | } |
dreschpe | 0:fedcef5319f5 | 322 | |
dreschpe | 0:fedcef5319f5 | 323 | char_x += w; |
dreschpe | 0:fedcef5319f5 | 324 | } |
dreschpe | 0:fedcef5319f5 | 325 | |
dreschpe | 0:fedcef5319f5 | 326 | // set actual font |
dreschpe | 0:fedcef5319f5 | 327 | void EaEpaper::set_font(unsigned char* f) |
dreschpe | 0:fedcef5319f5 | 328 | { |
dreschpe | 0:fedcef5319f5 | 329 | font = f; |
dreschpe | 0:fedcef5319f5 | 330 | } |
dreschpe | 0:fedcef5319f5 | 331 | |
dreschpe | 0:fedcef5319f5 | 332 | void EaEpaper::print_bm(Bitmap bm, int x, int y) |
dreschpe | 0:fedcef5319f5 | 333 | { |
dreschpe | 0:fedcef5319f5 | 334 | int h,v,b; |
dreschpe | 0:fedcef5319f5 | 335 | char d; |
dreschpe | 0:fedcef5319f5 | 336 | |
dreschpe | 0:fedcef5319f5 | 337 | for(v=0; v < bm.ySize; v++) { // lines |
dreschpe | 0:fedcef5319f5 | 338 | for(h=0; h < bm.xSize; h++) { // pixel |
dreschpe | 0:fedcef5319f5 | 339 | if(h + x > width()) break; |
dreschpe | 0:fedcef5319f5 | 340 | if(v + y > height()) break; |
dreschpe | 0:fedcef5319f5 | 341 | d = bm.data[bm.Byte_in_Line * v + ((h & 0xF8) >> 3)]; |
dreschpe | 0:fedcef5319f5 | 342 | b = 0x80 >> (h & 0x07); |
dreschpe | 0:fedcef5319f5 | 343 | if((d & b) == 0) { |
dreschpe | 0:fedcef5319f5 | 344 | pixel(x+h,y+v,0); |
dreschpe | 0:fedcef5319f5 | 345 | } else { |
dreschpe | 0:fedcef5319f5 | 346 | pixel(x+h,y+v,1); |
dreschpe | 0:fedcef5319f5 | 347 | } |
dreschpe | 0:fedcef5319f5 | 348 | } |
dreschpe | 0:fedcef5319f5 | 349 | } |
dreschpe | 0:fedcef5319f5 | 350 | |
dreschpe | 0:fedcef5319f5 | 351 | } |
dreschpe | 0:fedcef5319f5 | 352 | |
dreschpe | 0:fedcef5319f5 | 353 |