Some improvements
Add return-values for some graphic function for error handling. Improved some graphic functions to reduce needed flash. Update readme for flash size values
Dieser Commit ist enthalten in:
Ursprung
a8fb621eff
Commit
d684610c00
93
lcd.c
93
lcd.c
@ -384,42 +384,47 @@ void lcd_puts_p(const char* progmem_s){
|
|||||||
#ifdef GRAPHICMODE
|
#ifdef GRAPHICMODE
|
||||||
#pragma mark -
|
#pragma mark -
|
||||||
#pragma mark GRAPHIC FUNCTIONS
|
#pragma mark GRAPHIC FUNCTIONS
|
||||||
void lcd_drawPixel(uint8_t x, uint8_t y, uint8_t color){
|
uint8_t lcd_drawPixel(uint8_t x, uint8_t y, uint8_t color){
|
||||||
if( x > DISPLAY_WIDTH-1 || y > (DISPLAY_HEIGHT-1)) return; // out of Display
|
if( x > DISPLAY_WIDTH-1 || y > (DISPLAY_HEIGHT-1)) return 1; // out of Display
|
||||||
|
|
||||||
if( color == WHITE){
|
if( color == WHITE){
|
||||||
displayBuffer[(y / 8)][x] |= (1 << (y % 8));
|
displayBuffer[(y / 8)][x] |= (1 << (y % 8));
|
||||||
} else {
|
} else {
|
||||||
displayBuffer[(y / 8)][x] &= ~(1 << (y % 8));
|
displayBuffer[(y / 8)][x] &= ~(1 << (y % 8));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
void lcd_drawLine(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2, uint8_t color){
|
uint8_t lcd_drawLine(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2, uint8_t color){
|
||||||
if( x1 > DISPLAY_WIDTH-1 ||
|
uint8_t result;
|
||||||
x2 > DISPLAY_WIDTH-1 ||
|
|
||||||
y1 > DISPLAY_HEIGHT-1 ||
|
|
||||||
y2 > DISPLAY_HEIGHT-1) return;
|
|
||||||
int dx = abs(x2-x1), sx = x1<x2 ? 1 : -1;
|
int dx = abs(x2-x1), sx = x1<x2 ? 1 : -1;
|
||||||
int dy = -abs(y2-y1), sy = y1<y2 ? 1 : -1;
|
int dy = -abs(y2-y1), sy = y1<y2 ? 1 : -1;
|
||||||
int err = dx+dy, e2; /* error value e_xy */
|
int err = dx+dy, e2; /* error value e_xy */
|
||||||
|
|
||||||
while(1){
|
while(1){
|
||||||
lcd_drawPixel(x1, y1, color);
|
result = lcd_drawPixel(x1, y1, color);
|
||||||
if (x1==x2 && y1==y2) break;
|
if (x1==x2 && y1==y2) break;
|
||||||
e2 = 2*err;
|
e2 = 2*err;
|
||||||
if (e2 > dy) { err += dy; x1 += sx; } /* e_xy+e_x > 0 */
|
if (e2 > dy) { err += dy; x1 += sx; } /* e_xy+e_x > 0 */
|
||||||
if (e2 < dx) { err += dx; y1 += sy; } /* e_xy+e_y < 0 */
|
if (e2 < dx) { err += dx; y1 += sy; } /* e_xy+e_y < 0 */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
void lcd_drawRect(uint8_t px1, uint8_t py1, uint8_t px2, uint8_t py2, uint8_t color){
|
uint8_t lcd_drawRect(uint8_t px1, uint8_t py1, uint8_t px2, uint8_t py2, uint8_t color){
|
||||||
if( px1 > DISPLAY_WIDTH-1 ||
|
uint8_t result;
|
||||||
px2 > DISPLAY_WIDTH-1 ||
|
|
||||||
py1 > DISPLAY_HEIGHT-1 ||
|
result = lcd_drawLine(px1, py1, px2, py1, color);
|
||||||
py2 > DISPLAY_HEIGHT-1) return;
|
result = lcd_drawLine(px2, py1, px2, py2, color);
|
||||||
lcd_drawLine(px1, py1, px2, py1, color);
|
result = lcd_drawLine(px2, py2, px1, py2, color);
|
||||||
lcd_drawLine(px2, py1, px2, py2, color);
|
result = lcd_drawLine(px1, py2, px1, py1, color);
|
||||||
lcd_drawLine(px2, py2, px1, py2, color);
|
|
||||||
lcd_drawLine(px1, py2, px1, py1, color);
|
return result;
|
||||||
}
|
}
|
||||||
void lcd_fillRect(uint8_t px1, uint8_t py1, uint8_t px2, uint8_t py2, uint8_t color){
|
uint8_t lcd_fillRect(uint8_t px1, uint8_t py1, uint8_t px2, uint8_t py2, uint8_t color){
|
||||||
|
uint8_t result;
|
||||||
|
|
||||||
if( px1 > px2){
|
if( px1 > px2){
|
||||||
uint8_t temp = px1;
|
uint8_t temp = px1;
|
||||||
px1 = px2;
|
px1 = px2;
|
||||||
@ -429,24 +434,24 @@ void lcd_fillRect(uint8_t px1, uint8_t py1, uint8_t px2, uint8_t py2, uint8_t co
|
|||||||
py2 = temp;
|
py2 = temp;
|
||||||
}
|
}
|
||||||
for (uint8_t i=0; i<=(py2-py1); i++){
|
for (uint8_t i=0; i<=(py2-py1); i++){
|
||||||
lcd_drawLine(px1, py1+i, px2, py1+i, color);
|
result = lcd_drawLine(px1, py1+i, px2, py1+i, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
void lcd_drawCircle(uint8_t center_x, uint8_t center_y, uint8_t radius, uint8_t color){
|
uint8_t lcd_drawCircle(uint8_t center_x, uint8_t center_y, uint8_t radius, uint8_t color){
|
||||||
if( ((center_x + radius) > DISPLAY_WIDTH-1) ||
|
uint8_t result;
|
||||||
((center_y + radius) > DISPLAY_HEIGHT-1) ||
|
|
||||||
center_x < radius ||
|
|
||||||
center_y < radius) return;
|
|
||||||
int16_t f = 1 - radius;
|
int16_t f = 1 - radius;
|
||||||
int16_t ddF_x = 1;
|
int16_t ddF_x = 1;
|
||||||
int16_t ddF_y = -2 * radius;
|
int16_t ddF_y = -2 * radius;
|
||||||
int16_t x = 0;
|
int16_t x = 0;
|
||||||
int16_t y = radius;
|
int16_t y = radius;
|
||||||
|
|
||||||
lcd_drawPixel(center_x , center_y+radius, color);
|
result = lcd_drawPixel(center_x , center_y+radius, color);
|
||||||
lcd_drawPixel(center_x , center_y-radius, color);
|
result = lcd_drawPixel(center_x , center_y-radius, color);
|
||||||
lcd_drawPixel(center_x+radius, center_y , color);
|
result = lcd_drawPixel(center_x+radius, center_y , color);
|
||||||
lcd_drawPixel(center_x-radius, center_y , color);
|
result = lcd_drawPixel(center_x-radius, center_y , color);
|
||||||
|
|
||||||
while (x<y) {
|
while (x<y) {
|
||||||
if (f >= 0) {
|
if (f >= 0) {
|
||||||
@ -458,32 +463,36 @@ void lcd_drawCircle(uint8_t center_x, uint8_t center_y, uint8_t radius, uint8_t
|
|||||||
ddF_x += 2;
|
ddF_x += 2;
|
||||||
f += ddF_x;
|
f += ddF_x;
|
||||||
|
|
||||||
lcd_drawPixel(center_x + x, center_y + y, color);
|
result = lcd_drawPixel(center_x + x, center_y + y, color);
|
||||||
lcd_drawPixel(center_x - x, center_y + y, color);
|
result = lcd_drawPixel(center_x - x, center_y + y, color);
|
||||||
lcd_drawPixel(center_x + x, center_y - y, color);
|
result = lcd_drawPixel(center_x + x, center_y - y, color);
|
||||||
lcd_drawPixel(center_x - x, center_y - y, color);
|
result = lcd_drawPixel(center_x - x, center_y - y, color);
|
||||||
lcd_drawPixel(center_x + y, center_y + x, color);
|
result = lcd_drawPixel(center_x + y, center_y + x, color);
|
||||||
lcd_drawPixel(center_x - y, center_y + x, color);
|
result = lcd_drawPixel(center_x - y, center_y + x, color);
|
||||||
lcd_drawPixel(center_x + y, center_y - x, color);
|
result = lcd_drawPixel(center_x + y, center_y - x, color);
|
||||||
lcd_drawPixel(center_x - y, center_y - x, color);
|
result = lcd_drawPixel(center_x - y, center_y - x, color);
|
||||||
}
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
void lcd_fillCircle(uint8_t center_x, uint8_t center_y, uint8_t radius, uint8_t color) {
|
uint8_t lcd_fillCircle(uint8_t center_x, uint8_t center_y, uint8_t radius, uint8_t color) {
|
||||||
|
uint8_t result;
|
||||||
for(uint8_t i=0; i<= radius;i++){
|
for(uint8_t i=0; i<= radius;i++){
|
||||||
lcd_drawCircle(center_x, center_y, i, color);
|
result = lcd_drawCircle(center_x, center_y, i, color);
|
||||||
}
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
void lcd_drawBitmap(uint8_t x, uint8_t y, const uint8_t *picture, uint8_t width, uint8_t height, uint8_t color){
|
uint8_t lcd_drawBitmap(uint8_t x, uint8_t y, const uint8_t *picture, uint8_t width, uint8_t height, uint8_t color){
|
||||||
uint8_t i,j, byteWidth = (width+7)/8;
|
uint8_t result,i,j, byteWidth = (width+7)/8;
|
||||||
for (j = 0; j < height; j++) {
|
for (j = 0; j < height; j++) {
|
||||||
for(i=0; i < width;i++){
|
for(i=0; i < width;i++){
|
||||||
if(pgm_read_byte(picture + j * byteWidth + i / 8) & (128 >> (i & 7))){
|
if(pgm_read_byte(picture + j * byteWidth + i / 8) & (128 >> (i & 7))){
|
||||||
lcd_drawPixel(x+i, y+j, color);
|
result = lcd_drawPixel(x+i, y+j, color);
|
||||||
} else {
|
} else {
|
||||||
lcd_drawPixel(x+i, y+j, !color);
|
result = lcd_drawPixel(x+i, y+j, !color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
void lcd_display() {
|
void lcd_display() {
|
||||||
#if defined (SSD1306) || defined (SSD1309)
|
#if defined (SSD1306) || defined (SSD1309)
|
||||||
|
16
lcd.h
16
lcd.h
@ -69,7 +69,7 @@ extern "C" {
|
|||||||
|
|
||||||
// using 7-bit-adress for lcd-library
|
// using 7-bit-adress for lcd-library
|
||||||
// if you use your own library for twi check I2C-adress-handle
|
// if you use your own library for twi check I2C-adress-handle
|
||||||
#define LCD_I2C_ADR (0x7a >> 1) // 7 bit slave-adress without r/w-bit
|
#define LCD_I2C_ADR (0x78 >> 1) // 7 bit slave-adress without r/w-bit
|
||||||
// r/w-bit are set/unset by library
|
// r/w-bit are set/unset by library
|
||||||
// e.g. 8 bit slave-adress:
|
// e.g. 8 bit slave-adress:
|
||||||
// 0x78 = adress 0x3C with cleared r/w-bit (write-mode)
|
// 0x78 = adress 0x3C with cleared r/w-bit (write-mode)
|
||||||
@ -130,13 +130,13 @@ extern "C" {
|
|||||||
// at GRAPHICMODE print character to buffer
|
// at GRAPHICMODE print character to buffer
|
||||||
void lcd_charMode(uint8_t mode); // set size of chars
|
void lcd_charMode(uint8_t mode); // set size of chars
|
||||||
#if defined GRAPHICMODE
|
#if defined GRAPHICMODE
|
||||||
void lcd_drawPixel(uint8_t x, uint8_t y, uint8_t color);
|
uint8_t lcd_drawPixel(uint8_t x, uint8_t y, uint8_t color);
|
||||||
void lcd_drawLine(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2, uint8_t color);
|
uint8_t lcd_drawLine(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2, uint8_t color);
|
||||||
void lcd_drawRect(uint8_t px1, uint8_t py1, uint8_t px2, uint8_t py2, uint8_t color);
|
uint8_t lcd_drawRect(uint8_t px1, uint8_t py1, uint8_t px2, uint8_t py2, uint8_t color);
|
||||||
void lcd_fillRect(uint8_t px1, uint8_t py1, uint8_t px2, uint8_t py2, uint8_t color);
|
uint8_t lcd_fillRect(uint8_t px1, uint8_t py1, uint8_t px2, uint8_t py2, uint8_t color);
|
||||||
void lcd_drawCircle(uint8_t center_x, uint8_t center_y, uint8_t radius, uint8_t color);
|
uint8_t lcd_drawCircle(uint8_t center_x, uint8_t center_y, uint8_t radius, uint8_t color);
|
||||||
void lcd_fillCircle(uint8_t center_x, uint8_t center_y, uint8_t radius, uint8_t color);
|
uint8_t lcd_fillCircle(uint8_t center_x, uint8_t center_y, uint8_t radius, uint8_t color);
|
||||||
void lcd_drawBitmap(uint8_t x, uint8_t y, const uint8_t picture[], uint8_t width, uint8_t height, uint8_t color);
|
uint8_t lcd_drawBitmap(uint8_t x, uint8_t y, const uint8_t picture[], uint8_t width, uint8_t height, uint8_t color);
|
||||||
void lcd_display(void); // copy buffer to display RAM
|
void lcd_display(void); // copy buffer to display RAM
|
||||||
void lcd_clear_buffer(void); // clear display buffer
|
void lcd_clear_buffer(void); // clear display buffer
|
||||||
uint8_t lcd_check_buffer(uint8_t x, uint8_t y); // read a pixel value from the display buffer
|
uint8_t lcd_check_buffer(uint8_t x, uint8_t y); // read a pixel value from the display buffer
|
||||||
|
@ -24,7 +24,7 @@ Memory:
|
|||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>I2C-Core</td>
|
<td>I2C-Core</td>
|
||||||
<td>234 Bytes</td>
|
<td>220 Bytes</td>
|
||||||
<td>0 Bytes</td>
|
<td>0 Bytes</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
@ -34,12 +34,12 @@ Memory:
|
|||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>OLED (Text-Mode)</td>
|
<td>OLED (Text-Mode)</td>
|
||||||
<td>1449 Bytes</td>
|
<td>1395 Bytes</td>
|
||||||
<td>3 Bytes</td>
|
<td>3 Bytes</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>OLED (Graphic-Mode)</td>
|
<td>OLED (Graphic-Mode)</td>
|
||||||
<td>2403 Bytes</td>
|
<td>2541 Bytes</td>
|
||||||
<td>1027 Bytes</td>
|
<td>1027 Bytes</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
Laden…
x
In neuem Issue referenzieren
Einen Benutzer sperren