diff --git a/components/ssd1306/ssd1306.c b/components/ssd1306/ssd1306.c index d45b99a..e310ac3 100644 --- a/components/ssd1306/ssd1306.c +++ b/components/ssd1306/ssd1306.c @@ -93,24 +93,104 @@ void ssd1306_display_text(SSD1306_t * dev, int page, char * text, int text_len, int _text_len = text_len; if (_text_len > 16) _text_len = 16; - uint8_t seg = 0; + int seg = 0; uint8_t image[8]; - for (uint8_t i = 0; i < _text_len; i++) { + for (int i = 0; i < _text_len; i++) { memcpy(image, font8x8_basic_tr[(uint8_t)text[i]], 8); if (invert) ssd1306_invert(image, 8); if (dev->_flip) ssd1306_flip(image, 8); ssd1306_display_image(dev, page, seg, image, 8); -#if 0 - if (dev->_address == SPI_ADDRESS) { - spi_display_image(dev, page, seg, image, 8); - } else { - i2c_display_image(dev, page, seg, image, 8); - } -#endif seg = seg + 8; } } +void ssd1306_display_text_box1(SSD1306_t * dev, int page, int seg, char * text, int box_width, int text_len, bool invert, int delay) +{ + if (page >= dev->_pages) return; + int text_box_pixel = box_width * 8; + if (seg + text_box_pixel > dev->_width) return; + + int _seg = seg; + uint8_t image[8]; + for (int i = 0; i < box_width; i++) { + memcpy(image, font8x8_basic_tr[(uint8_t)text[i]], 8); + if (invert) ssd1306_invert(image, 8); + if (dev->_flip) ssd1306_flip(image, 8); + ssd1306_display_image(dev, page, _seg, image, 8); + _seg = _seg + 8; + } + vTaskDelay(delay); + + // Horizontally scroll inside the box + for (int _text=box_width;_text_flip) ssd1306_flip(image, 8); + for (int _bit=0;_bit<8;_bit++) { + for (int _pixel=0;_pixel_page[page]._segs[_pixel+seg] = dev->_page[page]._segs[_pixel+seg+1]; + } + dev->_page[page]._segs[seg+text_box_pixel-1] = image[_bit]; + ssd1306_display_image(dev, page, seg, &dev->_page[page]._segs[seg], text_box_pixel); + vTaskDelay(delay); + } + } +} + +void ssd1306_display_text_box2(SSD1306_t * dev, int page, int seg, char * text, int box_width, int text_len, bool invert, int delay) +{ + if (page >= dev->_pages) return; + int text_box_pixel = box_width * 8; + if (seg + text_box_pixel > dev->_width) return; + + int _seg = seg; + uint8_t image[8]; + + // Fill the text box with blanks + for (int i = 0; i < box_width; i++) { + //memcpy(image, font8x8_basic_tr[(uint8_t)text[i]], 8); + memcpy(image, font8x8_basic_tr[0x20], 8); + if (invert) ssd1306_invert(image, 8); + if (dev->_flip) ssd1306_flip(image, 8); + ssd1306_display_image(dev, page, _seg, image, 8); + _seg = _seg + 8; + } + vTaskDelay(delay); + + // Horizontally scroll inside the box + for (int _text=0;_text_flip) ssd1306_flip(image, 8); + for (int _bit=0;_bit<8;_bit++) { + for (int _pixel=0;_pixel_page[page]._segs[_pixel+seg] = dev->_page[page]._segs[_pixel+seg+1]; + } + dev->_page[page]._segs[seg+text_box_pixel-1] = image[_bit]; + ssd1306_display_image(dev, page, seg, &dev->_page[page]._segs[seg], text_box_pixel); + vTaskDelay(delay); + } + } + + // Horizontally scroll inside the box + for (int _text=0;_text_flip) ssd1306_flip(image, 8); + for (int _bit=0;_bit<8;_bit++) { + for (int _pixel=0;_pixel_page[page]._segs[_pixel+seg] = dev->_page[page]._segs[_pixel+seg+1]; + } + dev->_page[page]._segs[seg+text_box_pixel-1] = image[_bit]; + ssd1306_display_image(dev, page, seg, &dev->_page[page]._segs[seg], text_box_pixel); + vTaskDelay(delay); + } + } +} + // by Coert Vonk void ssd1306_display_text_x3(SSD1306_t * dev, int page, char * text, int text_len, bool invert) @@ -119,9 +199,9 @@ ssd1306_display_text_x3(SSD1306_t * dev, int page, char * text, int text_len, bo int _text_len = text_len; if (_text_len > 5) _text_len = 5; - uint8_t seg = 0; + int seg = 0; - for (uint8_t nn = 0; nn < _text_len; nn++) { + for (int nn = 0; nn < _text_len; nn++) { uint8_t const * const in_columns = font8x8_basic_tr[(uint8_t)text[nn]]; @@ -129,12 +209,12 @@ ssd1306_display_text_x3(SSD1306_t * dev, int page, char * text, int text_len, bo out_column_t out_columns[8]; memset(out_columns, 0, sizeof(out_columns)); - for (uint8_t xx = 0; xx < 8; xx++) { // for each column (x-direction) + for (int xx = 0; xx < 8; xx++) { // for each column (x-direction) uint32_t in_bitmask = 0b1; uint32_t out_bitmask = 0b111; - for (uint8_t yy = 0; yy < 8; yy++) { // for pixel (y-direction) + for (int yy = 0; yy < 8; yy++) { // for pixel (y-direction) if (in_columns[xx] & in_bitmask) { out_columns[xx].u32 |= out_bitmask; } @@ -144,10 +224,10 @@ ssd1306_display_text_x3(SSD1306_t * dev, int page, char * text, int text_len, bo } // render character in 8 column high pieces, making them 3x as wide - for (uint8_t yy = 0; yy < 3; yy++) { // for each group of 8 pixels high (y-direction) + for (int yy = 0; yy < 3; yy++) { // for each group of 8 pixels high (y-direction) uint8_t image[24]; - for (uint8_t xx = 0; xx < 8; xx++) { // for each column (x-direction) + for (int xx = 0; xx < 8; xx++) { // for each column (x-direction) image[xx*3+0] = image[xx*3+1] = image[xx*3+2] = out_columns[xx].u8[yy]; @@ -456,7 +536,7 @@ void _ssd1306_bitmaps(SSD1306_t * dev, int xpos, int ypos, uint8_t * bitmap, int uint8_t page = (ypos / 8); uint8_t _seg = xpos; uint8_t dstBits = (ypos % 8); - ESP_LOGD(TAG, "ypos=%d page=%d dstBits=%d", ypos, page, dstBits); + ESP_LOGD(TAG, "_width=%d ypos=%d page=%d dstBits=%d", _width, ypos, page, dstBits); int offset = 0; for(int _height=0;_height_flip) wk2 = ssd1306_rotate_byte(wk2); - ESP_LOGD(TAG, "index=%d offset=%d page=%d _seg=%d, wk2=%02x", index, offset, page, _seg, wk2); + ESP_LOGD(TAG, "index=%d offset=%d wk1=0x%x page=%d _seg=%d, wk2=%02x", index, offset, wk1, page, _seg, wk2); dev->_page[page]._segs[_seg] = wk2; _seg++; } diff --git a/components/ssd1306/ssd1306.h b/components/ssd1306/ssd1306.h index fe8ff3f..baffb76 100644 --- a/components/ssd1306/ssd1306.h +++ b/components/ssd1306/ssd1306.h @@ -125,6 +125,8 @@ void ssd1306_set_buffer(SSD1306_t * dev, uint8_t * buffer); void ssd1306_get_buffer(SSD1306_t * dev, uint8_t * buffer); void ssd1306_display_image(SSD1306_t * dev, int page, int seg, uint8_t * images, int width); void ssd1306_display_text(SSD1306_t * dev, int page, char * text, int text_len, bool invert); +void ssd1306_display_text_box1(SSD1306_t * dev, int page, int seg, char * text, int box_width, int text_len, bool invert, int delay); +void ssd1306_display_text_box2(SSD1306_t * dev, int page, int seg, char * text, int box_width, int text_len, bool invert, int delay); void ssd1306_display_text_x3(SSD1306_t * dev, int page, char * text, int text_len, bool invert); void ssd1306_clear_screen(SSD1306_t * dev, bool invert); void ssd1306_clear_line(SSD1306_t * dev, int page, bool invert);