hellomqttt to thingspeak mqtt and ifttt

Dependencies:   Servo MQTTPacket FP

Committer:
jasonberry
Date:
Wed May 05 14:48:01 2021 +0000
Revision:
25:ca1b1098c77f
TEST

Who changed what in which revision?

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