void lcd_drawLine(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2, uint8_t color) { if (((x1 || x2) > DISPLAY_WIDTH - 1) || ((y1 || y2) > DISPLAY_HEIGHT - 1)) return; int dx = abs(x2 - x1), sx = x1 < x2 ? 1 : -1; int dy = -abs(y2 - y1), sy = y1 < y2 ? 1 : -1; int err = dx + dy, e2; /* error value e_xy */ while (1) { lcd_drawPixel(x1, y1, color); if (x1 == x2 && y1 == y2) break; e2 = 2 * err; if (e2 > dy) { err += dy; x1 += sx; } /* e_xy+e_x > 0 */ if (e2 < dx) { err += dx; y1 += sy; } /* e_xy+e_y < 0 */ } }
void lcd_drawCircle(uint8_t center_x, uint8_t center_y, uint8_t radius, uint8_t color) { if (((center_x - radius) > DISPLAY_WIDTH - 1) || ((center_y - radius) > DISPLAY_HEIGHT - 1) || center_x < radius || center_y < radius) return; int16_t f = 1 - radius; int16_t ddF_x = 1; int16_t ddF_y = -2 * radius; int16_t x = 0; int16_t y = radius; lcd_drawPixel(center_x, center_y + radius, color); lcd_drawPixel(center_x, center_y - radius, color); lcd_drawPixel(center_x + radius, center_y, color); lcd_drawPixel(center_x - radius, center_y, color); while (x < y) { if (f >= 0) { y--; ddF_y += 2; f += ddF_y; } x++; ddF_x += 2; f += ddF_x; lcd_drawPixel(center_x + x, center_y + y, color); lcd_drawPixel(center_x - x, center_y + y, color); lcd_drawPixel(center_x + x, center_y - y, color); lcd_drawPixel(center_x - x, center_y - y, color); lcd_drawPixel(center_x + y, center_y + x, color); lcd_drawPixel(center_x - y, center_y + x, color); lcd_drawPixel(center_x + y, center_y - x, color); lcd_drawPixel(center_x - y, center_y - x, color); } }
void lcd_printf (char *s, unsigned short color) { while (*s) { switch (*s) { case '\n': { lcd_screen_x=0; lcd_screen_y++; if (lcd_screen_y==17) { lcd_screen_y=0; } break; } default: { char newcdata[5]; int i=0; char oldcdata[5]; unsigned char rewrite = lcd_screen_chars_color[lcd_screen_x][lcd_screen_y] != color; for (i=0;i<5;i++) { newcdata[i]=lcd_char_data[lcd_char_map[*s]][i]; if (!rewrite) oldcdata[i] =lcd_char_data[lcd_screen_chars[lcd_screen_x][lcd_screen_y]][i]; } int x_base = lcd_screen_x * 5; int y_base = lcd_screen_y * 8; int x=0,y=0; unsigned short c=0; unsigned short oldc=0; for (y=0;y<8;y++) for (x=0;x<5;x++) { c=lcd_screencolor; if (newcdata[x] & (1<<y)) c=color; if (rewrite) { lcd_drawPixel(x_base+x, y_base+y, c); } else { oldc=lcd_screencolor; if (oldcdata[x] & (1<<y)) oldc=color; if (oldc!=c) lcd_drawPixel(x_base+x, y_base+y, c); } } lcd_screen_x++; if (lcd_screen_x==26) { lcd_screen_x=0; lcd_screen_y++; if (lcd_screen_y==17) { lcd_screen_y=0; } } } } s++; } }