Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 4873

Graphics programming • Re: SSD1306 eating my fonts!

$
0
0
Your function to write a string just writes the data for one page, where a page is 8 pixels high. If you want to draw a 16 pixel high font then you need to write the string twice, first sending the top half of the bitmap to the relevant page and then a second time just sending the bottom half to the next page.

Something like this (untested as I don't have an ssd1306),

Code:

# Modified so by default will draw either an 8 pixel high font# or the top half of a 16 pixel high font. Calling with# top_half=False will instead draw the bottom half of a 16 pixel# high font (or a blank line for 8 pixel high font)def ssd1306_oled_write_line(lsize, lstx, top_half=True):data_buf=[]for n in lstx:for m in curfont[n]:if top_half;data_buf.append(m & 0xff)else:data_buf.append(m >> 8)write_dbuf(data_buf)# New function specific to writing 16 pixel high fontsdef ssd1306_oled_write_string_tall(lsize, lstx):global global_x,global_yglobal max_lines,max_columnsfor n in lstx.split("\n"):ssd1306_oled_set_XY(global_x, global_y)ssd1306_oled_write_line(lsize, n.strip())# Don't draw the bottom half if it goes offscreenif global_y + 1 < max_lines / 8:ssd1306_oled_set_XY(global_x, global_y + 1)ssd1306_oled_write_line(lsize, n.strip(), top_half=False)global_x = 0global_y+=2if global_y >= max_lines / 8:global_y = 0

Statistics: Posted by Paeryn — Tue Dec 31, 2024 1:21 am



Viewing all articles
Browse latest Browse all 4873

Trending Articles