A class for managing SSD1306 controlled LCD´s (cheap 128x64 models, 0.96'')
Dependents: mbed_ssd1306 USB_meter_SD_file_number_filtro_for EscanerRf escaner_RTOS ... more
Diff: ssd1306.cpp
- Revision:
- 8:09b1578f93d9
- Parent:
- 4:35757c8b7625
- Child:
- 9:57209a7e9cba
--- a/ssd1306.cpp Wed Nov 01 16:54:57 2017 +0000 +++ b/ssd1306.cpp Mon Nov 06 18:22:22 2017 +0000 @@ -342,7 +342,7 @@ for (i=896; i<1024; i++) fb[i] = 0; if (refresh) - display(); + redraw(); } void SSD1306::locate (char row, char column) @@ -364,7 +364,7 @@ idxfb++; } if (refresh) - display(); + redraw(); } void SSD1306::puts (char *s, bool refresh) @@ -385,7 +385,7 @@ } -void SSD1306::display(void) +void SSD1306::redraw (void) { int i; @@ -403,6 +403,11 @@ bus->stop(); } +void SSD1306::display (void) +{ + redraw(); +} + void SSD1306::set_contrast (char v) { command (SSD1306_SETCONTRAST); @@ -422,7 +427,7 @@ } idxfb = 0; if (refresh) - display(); + redraw(); } void SSD1306::plot (char x, char y, PlotStyle mode, bool refresh) @@ -442,7 +447,7 @@ break; } if (refresh) - display(); + redraw(); } bool SSD1306::point (char x, char y) @@ -477,7 +482,7 @@ } } if (refresh) - display(); + redraw(); } void SSD1306::circle (char x0, char y0, char r, PlotStyle mode, bool refresh) @@ -513,5 +518,67 @@ } } if (refresh) - display(); + redraw(); } + +void SSD1306::fill (char x, char y, bool refresh) +{ + unsigned char rqueue = 0, wqueue = 1; + char *qpixel_x = new char[256]; + char *qpixel_y = new char[256]; + + if (!qpixel_x || !qpixel_y) + { + if (qpixel_x) delete[] qpixel_x; + if (qpixel_y) delete[] qpixel_y; + printf ("SSD1306::fill ERROR. Not enough memory\r\n"); + return; + } + + qpixel_x[0] = x; + qpixel_y[0] = y; + scr.plot (x, y, SSD1306::Normal); + while (wqueue != rqueue) + { + x = qpixel_x[rqueue]; + y = qpixel_y[rqueue]; + rqueue++; + + if (x!=127 && !scr.point (x+1,y)) + { + scr.plot (x+1, y, SSD1306::Normal); + qpixel_x[wqueue] = x+1; + qpixel_y[wqueue] = y; + wqueue++; + } + + if (x!=0 && !scr.point (x-1,y)) + { + scr.plot (x-1, y, SSD1306::Normal); + qpixel_x[wqueue] = x-1; + qpixel_y[wqueue] = y; + wqueue++; + } + + if (y!=63 && !scr.point (x,y+1)) + { + scr.plot (x, y+1, SSD1306::Normal); + qpixel_x[wqueue] = x; + qpixel_y[wqueue] = y+1; + wqueue++; + } + + if (y!=0 && !scr.point (x,y-1)) + { + scr.plot (x, y-1, SSD1306::Normal); + qpixel_x[wqueue] = x; + qpixel_y[wqueue] = y-1; + wqueue++; + } + } + delete[] qpixel_x; + delete[] qpixel_y; + + if (refresh) + redraw(); +}