TINF_MittelwerteUeberwachung

Dependencies:   mbed

Committer:
martwerl
Date:
Thu Nov 15 18:24:11 2018 +0000
Revision:
0:fb8791842ef8
TINF_MittelwerteUeberwachung

Who changed what in which revision?

UserRevisionLine numberNew contents of line
martwerl 0:fb8791842ef8 1 /* mbed library for the mbed Lab Board 128*32 pixel LCD
martwerl 0:fb8791842ef8 2 * use C12832 controller
martwerl 0:fb8791842ef8 3 * Copyright (c) 2012 Peter Drescher - DC2PD
martwerl 0:fb8791842ef8 4 * Released under the MIT License: http://mbed.org/license/mit
martwerl 0:fb8791842ef8 5 *
martwerl 0:fb8791842ef8 6 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
martwerl 0:fb8791842ef8 7 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
martwerl 0:fb8791842ef8 8 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
martwerl 0:fb8791842ef8 9 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
martwerl 0:fb8791842ef8 10 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
martwerl 0:fb8791842ef8 11 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
martwerl 0:fb8791842ef8 12 * THE SOFTWARE.
martwerl 0:fb8791842ef8 13 */
martwerl 0:fb8791842ef8 14
martwerl 0:fb8791842ef8 15 // 13.10.12 initial design
martwerl 0:fb8791842ef8 16 // 25.10.12 add autorefresh of screen
martwerl 0:fb8791842ef8 17 // 25.10.12 add standart font
martwerl 0:fb8791842ef8 18 // 20.12.12 add bitmap graphics
martwerl 0:fb8791842ef8 19
martwerl 0:fb8791842ef8 20 // optional defines :
martwerl 0:fb8791842ef8 21 // #define debug_lcd 1
martwerl 0:fb8791842ef8 22
martwerl 0:fb8791842ef8 23 #include "C12832.h"
martwerl 0:fb8791842ef8 24 #include "mbed.h"
martwerl 0:fb8791842ef8 25 #include "stdio.h"
martwerl 0:fb8791842ef8 26 #include "Small_7.h"
martwerl 0:fb8791842ef8 27
martwerl 0:fb8791842ef8 28 #define BPP 1 // Bits per pixel
martwerl 0:fb8791842ef8 29
martwerl 0:fb8791842ef8 30
martwerl 0:fb8791842ef8 31 C12832::C12832(PinName mosi, PinName sck, PinName reset, PinName a0, PinName ncs, const char* name)
martwerl 0:fb8791842ef8 32 : _spi(mosi,NC,sck),_reset(reset),_A0(a0),_CS(ncs),GraphicsDisplay(name)
martwerl 0:fb8791842ef8 33 {
martwerl 0:fb8791842ef8 34 orientation = 1;
martwerl 0:fb8791842ef8 35 draw_mode = NORMAL;
martwerl 0:fb8791842ef8 36 char_x = 0;
martwerl 0:fb8791842ef8 37 lcd_reset();
martwerl 0:fb8791842ef8 38 }
martwerl 0:fb8791842ef8 39
martwerl 0:fb8791842ef8 40
martwerl 0:fb8791842ef8 41 int C12832::width()
martwerl 0:fb8791842ef8 42 {
martwerl 0:fb8791842ef8 43 if (orientation == 0 || orientation == 2) return 32;
martwerl 0:fb8791842ef8 44 else return 128;
martwerl 0:fb8791842ef8 45 }
martwerl 0:fb8791842ef8 46
martwerl 0:fb8791842ef8 47 int C12832::height()
martwerl 0:fb8791842ef8 48 {
martwerl 0:fb8791842ef8 49 if (orientation == 0 || orientation == 2) return 128;
martwerl 0:fb8791842ef8 50 else return 32;
martwerl 0:fb8791842ef8 51 }
martwerl 0:fb8791842ef8 52
martwerl 0:fb8791842ef8 53
martwerl 0:fb8791842ef8 54 void C12832::invert(unsigned int o)
martwerl 0:fb8791842ef8 55 {
martwerl 0:fb8791842ef8 56 if(o == 0) wr_cmd(0xA6);
martwerl 0:fb8791842ef8 57 else wr_cmd(0xA7);
martwerl 0:fb8791842ef8 58 }
martwerl 0:fb8791842ef8 59
martwerl 0:fb8791842ef8 60
martwerl 0:fb8791842ef8 61 void C12832::set_contrast(unsigned int o)
martwerl 0:fb8791842ef8 62 {
martwerl 0:fb8791842ef8 63 contrast = o;
martwerl 0:fb8791842ef8 64 wr_cmd(0x81); // set volume
martwerl 0:fb8791842ef8 65 wr_cmd(o & 0x3F);
martwerl 0:fb8791842ef8 66 }
martwerl 0:fb8791842ef8 67
martwerl 0:fb8791842ef8 68 unsigned int C12832::get_contrast(void)
martwerl 0:fb8791842ef8 69 {
martwerl 0:fb8791842ef8 70 return(contrast);
martwerl 0:fb8791842ef8 71 }
martwerl 0:fb8791842ef8 72
martwerl 0:fb8791842ef8 73
martwerl 0:fb8791842ef8 74 // write command to lcd controller
martwerl 0:fb8791842ef8 75
martwerl 0:fb8791842ef8 76 void C12832::wr_cmd(unsigned char cmd)
martwerl 0:fb8791842ef8 77 {
martwerl 0:fb8791842ef8 78 _A0 = 0;
martwerl 0:fb8791842ef8 79 _CS = 0;
martwerl 0:fb8791842ef8 80 _spi.write(cmd);
martwerl 0:fb8791842ef8 81 _CS = 1;
martwerl 0:fb8791842ef8 82 }
martwerl 0:fb8791842ef8 83
martwerl 0:fb8791842ef8 84 // write data to lcd controller
martwerl 0:fb8791842ef8 85
martwerl 0:fb8791842ef8 86 void C12832::wr_dat(unsigned char dat)
martwerl 0:fb8791842ef8 87 {
martwerl 0:fb8791842ef8 88 _A0 = 1;
martwerl 0:fb8791842ef8 89 _CS = 0;
martwerl 0:fb8791842ef8 90 _spi.write(dat);
martwerl 0:fb8791842ef8 91 _CS = 1;
martwerl 0:fb8791842ef8 92 }
martwerl 0:fb8791842ef8 93
martwerl 0:fb8791842ef8 94 // reset and init the lcd controller
martwerl 0:fb8791842ef8 95
martwerl 0:fb8791842ef8 96 void C12832::lcd_reset()
martwerl 0:fb8791842ef8 97 {
martwerl 0:fb8791842ef8 98
martwerl 0:fb8791842ef8 99 _spi.format(8,3); // 8 bit spi mode 3
martwerl 0:fb8791842ef8 100 _spi.frequency(20000000); // 19,2 Mhz SPI clock
martwerl 0:fb8791842ef8 101 _A0 = 0;
martwerl 0:fb8791842ef8 102 _CS = 1;
martwerl 0:fb8791842ef8 103 _reset = 0; // display reset
martwerl 0:fb8791842ef8 104 wait_us(50);
martwerl 0:fb8791842ef8 105 _reset = 1; // end reset
martwerl 0:fb8791842ef8 106 wait_ms(5);
martwerl 0:fb8791842ef8 107
martwerl 0:fb8791842ef8 108 /* Start Initial Sequence ----------------------------------------------------*/
martwerl 0:fb8791842ef8 109
martwerl 0:fb8791842ef8 110 wr_cmd(0xAE); // display off
martwerl 0:fb8791842ef8 111 wr_cmd(0xA2); // bias voltage
martwerl 0:fb8791842ef8 112
martwerl 0:fb8791842ef8 113 wr_cmd(0xA0);
martwerl 0:fb8791842ef8 114 wr_cmd(0xC8); // colum normal
martwerl 0:fb8791842ef8 115
martwerl 0:fb8791842ef8 116 wr_cmd(0x22); // voltage resistor ratio
martwerl 0:fb8791842ef8 117 wr_cmd(0x2F); // power on
martwerl 0:fb8791842ef8 118 //wr_cmd(0xA4); // LCD display ram
martwerl 0:fb8791842ef8 119 wr_cmd(0x40); // start line = 0
martwerl 0:fb8791842ef8 120 wr_cmd(0xAF); // display ON
martwerl 0:fb8791842ef8 121
martwerl 0:fb8791842ef8 122 wr_cmd(0x81); // set contrast
martwerl 0:fb8791842ef8 123 wr_cmd(0x17); // set contrast
martwerl 0:fb8791842ef8 124
martwerl 0:fb8791842ef8 125 wr_cmd(0xA6); // display normal
martwerl 0:fb8791842ef8 126
martwerl 0:fb8791842ef8 127
martwerl 0:fb8791842ef8 128 // clear and update LCD
martwerl 0:fb8791842ef8 129 memset(buffer,0x00,512); // clear display buffer
martwerl 0:fb8791842ef8 130 copy_to_lcd();
martwerl 0:fb8791842ef8 131 auto_up = 1; // switch on auto update
martwerl 0:fb8791842ef8 132 // dont do this by default. Make the user call
martwerl 0:fb8791842ef8 133 //claim(stdout); // redirekt printf to lcd
martwerl 0:fb8791842ef8 134 locate(0,0);
martwerl 0:fb8791842ef8 135 set_font((unsigned char*)Small_7); // standart font
martwerl 0:fb8791842ef8 136 }
martwerl 0:fb8791842ef8 137
martwerl 0:fb8791842ef8 138 // set one pixel in buffer
martwerl 0:fb8791842ef8 139
martwerl 0:fb8791842ef8 140 void C12832::pixel(int x, int y, int color)
martwerl 0:fb8791842ef8 141 {
martwerl 0:fb8791842ef8 142 // first check parameter
martwerl 0:fb8791842ef8 143 if(x > 128 || y > 32 || x < 0 || y < 0) return;
martwerl 0:fb8791842ef8 144
martwerl 0:fb8791842ef8 145 if(draw_mode == NORMAL) {
martwerl 0:fb8791842ef8 146 if(color == 0)
martwerl 0:fb8791842ef8 147 buffer[x + ((y/8) * 128)] &= ~(1 << (y%8)); // erase pixel
martwerl 0:fb8791842ef8 148 else
martwerl 0:fb8791842ef8 149 buffer[x + ((y/8) * 128)] |= (1 << (y%8)); // set pixel
martwerl 0:fb8791842ef8 150 } else { // XOR mode
martwerl 0:fb8791842ef8 151 if(color == 1)
martwerl 0:fb8791842ef8 152 buffer[x + ((y/8) * 128)] ^= (1 << (y%8)); // xor pixel
martwerl 0:fb8791842ef8 153 }
martwerl 0:fb8791842ef8 154 }
martwerl 0:fb8791842ef8 155
martwerl 0:fb8791842ef8 156 // update lcd
martwerl 0:fb8791842ef8 157
martwerl 0:fb8791842ef8 158 void C12832::copy_to_lcd(void)
martwerl 0:fb8791842ef8 159 {
martwerl 0:fb8791842ef8 160
martwerl 0:fb8791842ef8 161 int i=0;
martwerl 0:fb8791842ef8 162
martwerl 0:fb8791842ef8 163 //page 0
martwerl 0:fb8791842ef8 164 wr_cmd(0x00); // set column low nibble 0
martwerl 0:fb8791842ef8 165 wr_cmd(0x10); // set column hi nibble 0
martwerl 0:fb8791842ef8 166 wr_cmd(0xB0); // set page address 0
martwerl 0:fb8791842ef8 167 _A0 = 1;
martwerl 0:fb8791842ef8 168 for(i=0; i<128; i++) {
martwerl 0:fb8791842ef8 169 wr_dat(buffer[i]);
martwerl 0:fb8791842ef8 170 }
martwerl 0:fb8791842ef8 171
martwerl 0:fb8791842ef8 172 // page 1
martwerl 0:fb8791842ef8 173 wr_cmd(0x00); // set column low nibble 0
martwerl 0:fb8791842ef8 174 wr_cmd(0x10); // set column hi nibble 0
martwerl 0:fb8791842ef8 175 wr_cmd(0xB1); // set page address 1
martwerl 0:fb8791842ef8 176 _A0 = 1;
martwerl 0:fb8791842ef8 177 for(i=128; i<256; i++) {
martwerl 0:fb8791842ef8 178 wr_dat(buffer[i]);
martwerl 0:fb8791842ef8 179 }
martwerl 0:fb8791842ef8 180
martwerl 0:fb8791842ef8 181 //page 2
martwerl 0:fb8791842ef8 182 wr_cmd(0x00); // set column low nibble 0
martwerl 0:fb8791842ef8 183 wr_cmd(0x10); // set column hi nibble 0
martwerl 0:fb8791842ef8 184 wr_cmd(0xB2); // set page address 2
martwerl 0:fb8791842ef8 185 _A0 = 1;
martwerl 0:fb8791842ef8 186 for(i=256; i<384; i++) {
martwerl 0:fb8791842ef8 187 wr_dat(buffer[i]);
martwerl 0:fb8791842ef8 188 }
martwerl 0:fb8791842ef8 189
martwerl 0:fb8791842ef8 190 //page 3
martwerl 0:fb8791842ef8 191 wr_cmd(0x00); // set column low nibble 0
martwerl 0:fb8791842ef8 192 wr_cmd(0x10); // set column hi nibble 0
martwerl 0:fb8791842ef8 193 wr_cmd(0xB3); // set page address 3
martwerl 0:fb8791842ef8 194 _A0 = 1;
martwerl 0:fb8791842ef8 195
martwerl 0:fb8791842ef8 196 _CS = 0;
martwerl 0:fb8791842ef8 197
martwerl 0:fb8791842ef8 198 for(i=384; i<512; i++) {
martwerl 0:fb8791842ef8 199 wr_dat(buffer[i]);
martwerl 0:fb8791842ef8 200 }
martwerl 0:fb8791842ef8 201
martwerl 0:fb8791842ef8 202 }
martwerl 0:fb8791842ef8 203
martwerl 0:fb8791842ef8 204 void C12832::cls(void)
martwerl 0:fb8791842ef8 205 {
martwerl 0:fb8791842ef8 206 memset(buffer,0x00,512); // clear display buffer
martwerl 0:fb8791842ef8 207 copy_to_lcd();
martwerl 0:fb8791842ef8 208 }
martwerl 0:fb8791842ef8 209
martwerl 0:fb8791842ef8 210
martwerl 0:fb8791842ef8 211 void C12832::line(int x0, int y0, int x1, int y1, int color)
martwerl 0:fb8791842ef8 212 {
martwerl 0:fb8791842ef8 213 int dx = 0, dy = 0;
martwerl 0:fb8791842ef8 214 int dx_sym = 0, dy_sym = 0;
martwerl 0:fb8791842ef8 215 int dx_x2 = 0, dy_x2 = 0;
martwerl 0:fb8791842ef8 216 int di = 0;
martwerl 0:fb8791842ef8 217
martwerl 0:fb8791842ef8 218 dx = x1-x0;
martwerl 0:fb8791842ef8 219 dy = y1-y0;
martwerl 0:fb8791842ef8 220
martwerl 0:fb8791842ef8 221 // if (dx == 0) { /* vertical line */
martwerl 0:fb8791842ef8 222 // if (y1 > y0) vline(x0,y0,y1,color);
martwerl 0:fb8791842ef8 223 // else vline(x0,y1,y0,color);
martwerl 0:fb8791842ef8 224 // return;
martwerl 0:fb8791842ef8 225 // }
martwerl 0:fb8791842ef8 226
martwerl 0:fb8791842ef8 227 if (dx > 0) {
martwerl 0:fb8791842ef8 228 dx_sym = 1;
martwerl 0:fb8791842ef8 229 } else {
martwerl 0:fb8791842ef8 230 dx_sym = -1;
martwerl 0:fb8791842ef8 231 }
martwerl 0:fb8791842ef8 232 // if (dy == 0) { /* horizontal line */
martwerl 0:fb8791842ef8 233 // if (x1 > x0) hline(x0,x1,y0,color);
martwerl 0:fb8791842ef8 234 // else hline(x1,x0,y0,color);
martwerl 0:fb8791842ef8 235 // return;
martwerl 0:fb8791842ef8 236 // }
martwerl 0:fb8791842ef8 237
martwerl 0:fb8791842ef8 238 if (dy > 0) {
martwerl 0:fb8791842ef8 239 dy_sym = 1;
martwerl 0:fb8791842ef8 240 } else {
martwerl 0:fb8791842ef8 241 dy_sym = -1;
martwerl 0:fb8791842ef8 242 }
martwerl 0:fb8791842ef8 243
martwerl 0:fb8791842ef8 244 dx = dx_sym*dx;
martwerl 0:fb8791842ef8 245 dy = dy_sym*dy;
martwerl 0:fb8791842ef8 246
martwerl 0:fb8791842ef8 247 dx_x2 = dx*2;
martwerl 0:fb8791842ef8 248 dy_x2 = dy*2;
martwerl 0:fb8791842ef8 249
martwerl 0:fb8791842ef8 250 if (dx >= dy) {
martwerl 0:fb8791842ef8 251 di = dy_x2 - dx;
martwerl 0:fb8791842ef8 252 while (x0 != x1) {
martwerl 0:fb8791842ef8 253
martwerl 0:fb8791842ef8 254 pixel(x0, y0, color);
martwerl 0:fb8791842ef8 255 x0 += dx_sym;
martwerl 0:fb8791842ef8 256 if (di<0) {
martwerl 0:fb8791842ef8 257 di += dy_x2;
martwerl 0:fb8791842ef8 258 } else {
martwerl 0:fb8791842ef8 259 di += dy_x2 - dx_x2;
martwerl 0:fb8791842ef8 260 y0 += dy_sym;
martwerl 0:fb8791842ef8 261 }
martwerl 0:fb8791842ef8 262 }
martwerl 0:fb8791842ef8 263 pixel(x0, y0, color);
martwerl 0:fb8791842ef8 264 } else {
martwerl 0:fb8791842ef8 265 di = dx_x2 - dy;
martwerl 0:fb8791842ef8 266 while (y0 != y1) {
martwerl 0:fb8791842ef8 267 pixel(x0, y0, color);
martwerl 0:fb8791842ef8 268 y0 += dy_sym;
martwerl 0:fb8791842ef8 269 if (di < 0) {
martwerl 0:fb8791842ef8 270 di += dx_x2;
martwerl 0:fb8791842ef8 271 } else {
martwerl 0:fb8791842ef8 272 di += dx_x2 - dy_x2;
martwerl 0:fb8791842ef8 273 x0 += dx_sym;
martwerl 0:fb8791842ef8 274 }
martwerl 0:fb8791842ef8 275 }
martwerl 0:fb8791842ef8 276 pixel(x0, y0, color);
martwerl 0:fb8791842ef8 277 }
martwerl 0:fb8791842ef8 278 if(auto_up) copy_to_lcd();
martwerl 0:fb8791842ef8 279 }
martwerl 0:fb8791842ef8 280
martwerl 0:fb8791842ef8 281 void C12832::rect(int x0, int y0, int x1, int y1, int color)
martwerl 0:fb8791842ef8 282 {
martwerl 0:fb8791842ef8 283
martwerl 0:fb8791842ef8 284 if (x1 > x0) line(x0,y0,x1,y0,color);
martwerl 0:fb8791842ef8 285 else line(x1,y0,x0,y0,color);
martwerl 0:fb8791842ef8 286
martwerl 0:fb8791842ef8 287 if (y1 > y0) line(x0,y0,x0,y1,color);
martwerl 0:fb8791842ef8 288 else line(x0,y1,x0,y0,color);
martwerl 0:fb8791842ef8 289
martwerl 0:fb8791842ef8 290 if (x1 > x0) line(x0,y1,x1,y1,color);
martwerl 0:fb8791842ef8 291 else line(x1,y1,x0,y1,color);
martwerl 0:fb8791842ef8 292
martwerl 0:fb8791842ef8 293 if (y1 > y0) line(x1,y0,x1,y1,color);
martwerl 0:fb8791842ef8 294 else line(x1,y1,x1,y0,color);
martwerl 0:fb8791842ef8 295
martwerl 0:fb8791842ef8 296 if(auto_up) copy_to_lcd();
martwerl 0:fb8791842ef8 297 }
martwerl 0:fb8791842ef8 298
martwerl 0:fb8791842ef8 299 void C12832::fillrect(int x0, int y0, int x1, int y1, int color)
martwerl 0:fb8791842ef8 300 {
martwerl 0:fb8791842ef8 301 int l,c,i;
martwerl 0:fb8791842ef8 302 if(x0 > x1) {
martwerl 0:fb8791842ef8 303 i = x0;
martwerl 0:fb8791842ef8 304 x0 = x1;
martwerl 0:fb8791842ef8 305 x1 = i;
martwerl 0:fb8791842ef8 306 }
martwerl 0:fb8791842ef8 307
martwerl 0:fb8791842ef8 308 if(y0 > y1) {
martwerl 0:fb8791842ef8 309 i = y0;
martwerl 0:fb8791842ef8 310 y0 = y1;
martwerl 0:fb8791842ef8 311 y1 = i;
martwerl 0:fb8791842ef8 312 }
martwerl 0:fb8791842ef8 313
martwerl 0:fb8791842ef8 314 for(l = x0; l<= x1; l ++) {
martwerl 0:fb8791842ef8 315 for(c = y0; c<= y1; c++) {
martwerl 0:fb8791842ef8 316 pixel(l,c,color);
martwerl 0:fb8791842ef8 317 }
martwerl 0:fb8791842ef8 318 }
martwerl 0:fb8791842ef8 319 if(auto_up) copy_to_lcd();
martwerl 0:fb8791842ef8 320 }
martwerl 0:fb8791842ef8 321
martwerl 0:fb8791842ef8 322
martwerl 0:fb8791842ef8 323
martwerl 0:fb8791842ef8 324 void C12832::circle(int x0, int y0, int r, int color)
martwerl 0:fb8791842ef8 325 {
martwerl 0:fb8791842ef8 326
martwerl 0:fb8791842ef8 327 int draw_x0, draw_y0;
martwerl 0:fb8791842ef8 328 int draw_x1, draw_y1;
martwerl 0:fb8791842ef8 329 int draw_x2, draw_y2;
martwerl 0:fb8791842ef8 330 int draw_x3, draw_y3;
martwerl 0:fb8791842ef8 331 int draw_x4, draw_y4;
martwerl 0:fb8791842ef8 332 int draw_x5, draw_y5;
martwerl 0:fb8791842ef8 333 int draw_x6, draw_y6;
martwerl 0:fb8791842ef8 334 int draw_x7, draw_y7;
martwerl 0:fb8791842ef8 335 int xx, yy;
martwerl 0:fb8791842ef8 336 int di;
martwerl 0:fb8791842ef8 337 //WindowMax();
martwerl 0:fb8791842ef8 338 if (r == 0) { /* no radius */
martwerl 0:fb8791842ef8 339 return;
martwerl 0:fb8791842ef8 340 }
martwerl 0:fb8791842ef8 341
martwerl 0:fb8791842ef8 342 draw_x0 = draw_x1 = x0;
martwerl 0:fb8791842ef8 343 draw_y0 = draw_y1 = y0 + r;
martwerl 0:fb8791842ef8 344 if (draw_y0 < height()) {
martwerl 0:fb8791842ef8 345 pixel(draw_x0, draw_y0, color); /* 90 degree */
martwerl 0:fb8791842ef8 346 }
martwerl 0:fb8791842ef8 347
martwerl 0:fb8791842ef8 348 draw_x2 = draw_x3 = x0;
martwerl 0:fb8791842ef8 349 draw_y2 = draw_y3 = y0 - r;
martwerl 0:fb8791842ef8 350 if (draw_y2 >= 0) {
martwerl 0:fb8791842ef8 351 pixel(draw_x2, draw_y2, color); /* 270 degree */
martwerl 0:fb8791842ef8 352 }
martwerl 0:fb8791842ef8 353
martwerl 0:fb8791842ef8 354 draw_x4 = draw_x6 = x0 + r;
martwerl 0:fb8791842ef8 355 draw_y4 = draw_y6 = y0;
martwerl 0:fb8791842ef8 356 if (draw_x4 < width()) {
martwerl 0:fb8791842ef8 357 pixel(draw_x4, draw_y4, color); /* 0 degree */
martwerl 0:fb8791842ef8 358 }
martwerl 0:fb8791842ef8 359
martwerl 0:fb8791842ef8 360 draw_x5 = draw_x7 = x0 - r;
martwerl 0:fb8791842ef8 361 draw_y5 = draw_y7 = y0;
martwerl 0:fb8791842ef8 362 if (draw_x5>=0) {
martwerl 0:fb8791842ef8 363 pixel(draw_x5, draw_y5, color); /* 180 degree */
martwerl 0:fb8791842ef8 364 }
martwerl 0:fb8791842ef8 365
martwerl 0:fb8791842ef8 366 if (r == 1) {
martwerl 0:fb8791842ef8 367 return;
martwerl 0:fb8791842ef8 368 }
martwerl 0:fb8791842ef8 369
martwerl 0:fb8791842ef8 370 di = 3 - 2*r;
martwerl 0:fb8791842ef8 371 xx = 0;
martwerl 0:fb8791842ef8 372 yy = r;
martwerl 0:fb8791842ef8 373 while (xx < yy) {
martwerl 0:fb8791842ef8 374
martwerl 0:fb8791842ef8 375 if (di < 0) {
martwerl 0:fb8791842ef8 376 di += 4*xx + 6;
martwerl 0:fb8791842ef8 377 } else {
martwerl 0:fb8791842ef8 378 di += 4*(xx - yy) + 10;
martwerl 0:fb8791842ef8 379 yy--;
martwerl 0:fb8791842ef8 380 draw_y0--;
martwerl 0:fb8791842ef8 381 draw_y1--;
martwerl 0:fb8791842ef8 382 draw_y2++;
martwerl 0:fb8791842ef8 383 draw_y3++;
martwerl 0:fb8791842ef8 384 draw_x4--;
martwerl 0:fb8791842ef8 385 draw_x5++;
martwerl 0:fb8791842ef8 386 draw_x6--;
martwerl 0:fb8791842ef8 387 draw_x7++;
martwerl 0:fb8791842ef8 388 }
martwerl 0:fb8791842ef8 389 xx++;
martwerl 0:fb8791842ef8 390 draw_x0++;
martwerl 0:fb8791842ef8 391 draw_x1--;
martwerl 0:fb8791842ef8 392 draw_x2++;
martwerl 0:fb8791842ef8 393 draw_x3--;
martwerl 0:fb8791842ef8 394 draw_y4++;
martwerl 0:fb8791842ef8 395 draw_y5++;
martwerl 0:fb8791842ef8 396 draw_y6--;
martwerl 0:fb8791842ef8 397 draw_y7--;
martwerl 0:fb8791842ef8 398
martwerl 0:fb8791842ef8 399 if ( (draw_x0 <= width()) && (draw_y0>=0) ) {
martwerl 0:fb8791842ef8 400 pixel(draw_x0, draw_y0, color);
martwerl 0:fb8791842ef8 401 }
martwerl 0:fb8791842ef8 402
martwerl 0:fb8791842ef8 403 if ( (draw_x1 >= 0) && (draw_y1 >= 0) ) {
martwerl 0:fb8791842ef8 404 pixel(draw_x1, draw_y1, color);
martwerl 0:fb8791842ef8 405 }
martwerl 0:fb8791842ef8 406
martwerl 0:fb8791842ef8 407 if ( (draw_x2 <= width()) && (draw_y2 <= height()) ) {
martwerl 0:fb8791842ef8 408 pixel(draw_x2, draw_y2, color);
martwerl 0:fb8791842ef8 409 }
martwerl 0:fb8791842ef8 410
martwerl 0:fb8791842ef8 411 if ( (draw_x3 >=0 ) && (draw_y3 <= height()) ) {
martwerl 0:fb8791842ef8 412 pixel(draw_x3, draw_y3, color);
martwerl 0:fb8791842ef8 413 }
martwerl 0:fb8791842ef8 414
martwerl 0:fb8791842ef8 415 if ( (draw_x4 <= width()) && (draw_y4 >= 0) ) {
martwerl 0:fb8791842ef8 416 pixel(draw_x4, draw_y4, color);
martwerl 0:fb8791842ef8 417 }
martwerl 0:fb8791842ef8 418
martwerl 0:fb8791842ef8 419 if ( (draw_x5 >= 0) && (draw_y5 >= 0) ) {
martwerl 0:fb8791842ef8 420 pixel(draw_x5, draw_y5, color);
martwerl 0:fb8791842ef8 421 }
martwerl 0:fb8791842ef8 422 if ( (draw_x6 <=width()) && (draw_y6 <= height()) ) {
martwerl 0:fb8791842ef8 423 pixel(draw_x6, draw_y6, color);
martwerl 0:fb8791842ef8 424 }
martwerl 0:fb8791842ef8 425 if ( (draw_x7 >= 0) && (draw_y7 <= height()) ) {
martwerl 0:fb8791842ef8 426 pixel(draw_x7, draw_y7, color);
martwerl 0:fb8791842ef8 427 }
martwerl 0:fb8791842ef8 428 }
martwerl 0:fb8791842ef8 429 if(auto_up) copy_to_lcd();
martwerl 0:fb8791842ef8 430 }
martwerl 0:fb8791842ef8 431
martwerl 0:fb8791842ef8 432 void C12832::fillcircle(int x, int y, int r, int color)
martwerl 0:fb8791842ef8 433 {
martwerl 0:fb8791842ef8 434 int i,up;
martwerl 0:fb8791842ef8 435 up = auto_up;
martwerl 0:fb8791842ef8 436 auto_up = 0; // off
martwerl 0:fb8791842ef8 437 for (i = 0; i <= r; i++)
martwerl 0:fb8791842ef8 438 circle(x,y,i,color);
martwerl 0:fb8791842ef8 439 auto_up = up;
martwerl 0:fb8791842ef8 440 if(auto_up) copy_to_lcd();
martwerl 0:fb8791842ef8 441 }
martwerl 0:fb8791842ef8 442
martwerl 0:fb8791842ef8 443 void C12832::setmode(int mode)
martwerl 0:fb8791842ef8 444 {
martwerl 0:fb8791842ef8 445 draw_mode = mode;
martwerl 0:fb8791842ef8 446 }
martwerl 0:fb8791842ef8 447
martwerl 0:fb8791842ef8 448 void C12832::locate(int x, int y)
martwerl 0:fb8791842ef8 449 {
martwerl 0:fb8791842ef8 450 char_x = x;
martwerl 0:fb8791842ef8 451 char_y = y;
martwerl 0:fb8791842ef8 452 }
martwerl 0:fb8791842ef8 453
martwerl 0:fb8791842ef8 454
martwerl 0:fb8791842ef8 455
martwerl 0:fb8791842ef8 456 int C12832::columns()
martwerl 0:fb8791842ef8 457 {
martwerl 0:fb8791842ef8 458 return width() / font[1];
martwerl 0:fb8791842ef8 459 }
martwerl 0:fb8791842ef8 460
martwerl 0:fb8791842ef8 461
martwerl 0:fb8791842ef8 462
martwerl 0:fb8791842ef8 463 int C12832::rows()
martwerl 0:fb8791842ef8 464 {
martwerl 0:fb8791842ef8 465 return height() / font[2];
martwerl 0:fb8791842ef8 466 }
martwerl 0:fb8791842ef8 467
martwerl 0:fb8791842ef8 468
martwerl 0:fb8791842ef8 469
martwerl 0:fb8791842ef8 470 int C12832::_putc(int value)
martwerl 0:fb8791842ef8 471 {
martwerl 0:fb8791842ef8 472 if (value == '\n') { // new line
martwerl 0:fb8791842ef8 473 char_x = 0;
martwerl 0:fb8791842ef8 474 char_y = char_y + font[2];
martwerl 0:fb8791842ef8 475 if (char_y >= height() - font[2]) {
martwerl 0:fb8791842ef8 476 char_y = 0;
martwerl 0:fb8791842ef8 477 }
martwerl 0:fb8791842ef8 478 } else {
martwerl 0:fb8791842ef8 479 character(char_x, char_y, value);
martwerl 0:fb8791842ef8 480 if(auto_up) copy_to_lcd();
martwerl 0:fb8791842ef8 481 }
martwerl 0:fb8791842ef8 482 return value;
martwerl 0:fb8791842ef8 483 }
martwerl 0:fb8791842ef8 484
martwerl 0:fb8791842ef8 485 void C12832::character(int x, int y, int c)
martwerl 0:fb8791842ef8 486 {
martwerl 0:fb8791842ef8 487 unsigned int hor,vert,offset,bpl,j,i,b;
martwerl 0:fb8791842ef8 488 unsigned char* zeichen;
martwerl 0:fb8791842ef8 489 unsigned char z,w;
martwerl 0:fb8791842ef8 490
martwerl 0:fb8791842ef8 491 if ((c < 31) || (c > 127)) return; // test char range
martwerl 0:fb8791842ef8 492
martwerl 0:fb8791842ef8 493 // read font parameter from start of array
martwerl 0:fb8791842ef8 494 offset = font[0]; // bytes / char
martwerl 0:fb8791842ef8 495 hor = font[1]; // get hor size of font
martwerl 0:fb8791842ef8 496 vert = font[2]; // get vert size of font
martwerl 0:fb8791842ef8 497 bpl = font[3]; // bytes per line
martwerl 0:fb8791842ef8 498
martwerl 0:fb8791842ef8 499 if (char_x + hor > width()) {
martwerl 0:fb8791842ef8 500 char_x = 0;
martwerl 0:fb8791842ef8 501 char_y = char_y + vert;
martwerl 0:fb8791842ef8 502 if (char_y >= height() - font[2]) {
martwerl 0:fb8791842ef8 503 char_y = 0;
martwerl 0:fb8791842ef8 504 }
martwerl 0:fb8791842ef8 505 }
martwerl 0:fb8791842ef8 506
martwerl 0:fb8791842ef8 507 zeichen = &font[((c -32) * offset) + 4]; // start of char bitmap
martwerl 0:fb8791842ef8 508 w = zeichen[0]; // width of actual char
martwerl 0:fb8791842ef8 509 // construct the char into the buffer
martwerl 0:fb8791842ef8 510 for (j=0; j<vert; j++) { // vert line
martwerl 0:fb8791842ef8 511 for (i=0; i<hor; i++) { // horz line
martwerl 0:fb8791842ef8 512 z = zeichen[bpl * i + ((j & 0xF8) >> 3)+1];
martwerl 0:fb8791842ef8 513 b = 1 << (j & 0x07);
martwerl 0:fb8791842ef8 514 if (( z & b ) == 0x00) {
martwerl 0:fb8791842ef8 515 pixel(x+i,y+j,0);
martwerl 0:fb8791842ef8 516 } else {
martwerl 0:fb8791842ef8 517 pixel(x+i,y+j,1);
martwerl 0:fb8791842ef8 518 }
martwerl 0:fb8791842ef8 519
martwerl 0:fb8791842ef8 520 }
martwerl 0:fb8791842ef8 521 }
martwerl 0:fb8791842ef8 522
martwerl 0:fb8791842ef8 523 char_x += w;
martwerl 0:fb8791842ef8 524 }
martwerl 0:fb8791842ef8 525
martwerl 0:fb8791842ef8 526
martwerl 0:fb8791842ef8 527 void C12832::set_font(unsigned char* f)
martwerl 0:fb8791842ef8 528 {
martwerl 0:fb8791842ef8 529 font = f;
martwerl 0:fb8791842ef8 530 }
martwerl 0:fb8791842ef8 531
martwerl 0:fb8791842ef8 532 void C12832::set_auto_up(unsigned int up)
martwerl 0:fb8791842ef8 533 {
martwerl 0:fb8791842ef8 534 if(up ) auto_up = 1;
martwerl 0:fb8791842ef8 535 else auto_up = 0;
martwerl 0:fb8791842ef8 536 }
martwerl 0:fb8791842ef8 537
martwerl 0:fb8791842ef8 538 unsigned int C12832::get_auto_up(void)
martwerl 0:fb8791842ef8 539 {
martwerl 0:fb8791842ef8 540 return (auto_up);
martwerl 0:fb8791842ef8 541 }
martwerl 0:fb8791842ef8 542
martwerl 0:fb8791842ef8 543 void C12832::print_bm(Bitmap bm, int x, int y)
martwerl 0:fb8791842ef8 544 {
martwerl 0:fb8791842ef8 545 int h,v,b;
martwerl 0:fb8791842ef8 546 char d;
martwerl 0:fb8791842ef8 547
martwerl 0:fb8791842ef8 548 for(v=0; v < bm.ySize; v++) { // lines
martwerl 0:fb8791842ef8 549 for(h=0; h < bm.xSize; h++) { // pixel
martwerl 0:fb8791842ef8 550 if(h + x > 127) break;
martwerl 0:fb8791842ef8 551 if(v + y > 31) break;
martwerl 0:fb8791842ef8 552 d = bm.data[bm.Byte_in_Line * v + ((h & 0xF8) >> 3)];
martwerl 0:fb8791842ef8 553 b = 0x80 >> (h & 0x07);
martwerl 0:fb8791842ef8 554 if((d & b) == 0) {
martwerl 0:fb8791842ef8 555 pixel(x+h,y+v,0);
martwerl 0:fb8791842ef8 556 } else {
martwerl 0:fb8791842ef8 557 pixel(x+h,y+v,1);
martwerl 0:fb8791842ef8 558 }
martwerl 0:fb8791842ef8 559 }
martwerl 0:fb8791842ef8 560 }
martwerl 0:fb8791842ef8 561
martwerl 0:fb8791842ef8 562 }
martwerl 0:fb8791842ef8 563
martwerl 0:fb8791842ef8 564