BarGraph

Dependencies:   mbed

Committer:
Wizo
Date:
Thu Nov 15 17:23:34 2018 +0000
Revision:
0:a4839c6a1bf5
BarGraph

Who changed what in which revision?

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