你这太没效率了显示一行得花1秒多
你这太没效率了显示一行得花1秒多
我帮你改了下
这一个函数就可以显示字库里面的中英文字体了不需要写那么多:)
PCToLCD2002设置列行式,逆向再放到字库就可以了
def display(self,string, x_axis, y_axis, font_size=8):
if font_size == 8:
self.text(string, x_axis,y_axis)
return
if font_size not in self._fonts:
return
offset = 0
for k in string:
data_code = k.encode("utf-8")
code = int.from_bytes(data_code, 'big', False)
byte_data = self._fonts[font_size][code]
if len(data_code)==3:
fb= framebuf.FrameBuffer(bytearray(byte_data), font_size, font_size, framebuf.MONO_VLSB)
self.blit(fb,x_axis + offset,y_axis)
offset += font_size
else:
fb= framebuf.FrameBuffer(bytearray(byte_data), font_size//2, font_size, framebuf.MONO_VLSB)
self.blit(fb,x_axis + offset,y_axis)
offset += font_size//2
可以提交修改合并到仓库中呢
这东西还不会用。。。修改已经上传不知道对不对
Hello, I'm testing the Library and I found it's taking a lot of time to change more than 1 second also, have you merged the addition to the library, or has anybody found a solution because I have three OLEDs this ( in total around 3 seconds to update the screens)
I found a solution
for my project I need only font with 32 pixel height but it can extended further-more So I edited ascii32.py
def display(oled, string, x_axis, y_axis):
offset = 0
for k in string:
byte_data = _get_ch(k)
fb= framebuf.FrameBuffer(bytearray(byte_data), 16, 32, framebuf.MONO_VLSB)
oled.blit(fb,x_axis + offset,y_axis)
offset += 16
in ops.py the following method should be added
def blit(fb,x,y,key=-1, palette=None):
global _oled
_oled.blit(fb,x,y,key,pallette)
The font Text ascii32.txt file must be rewritten to work with framebuffer configuration I used PCtoLCD2002
depending on the outcome of the font text file you need to change in _get_ch(ch): in ascii32.py the seek command offset must be changed
def _get_ch(ch):
global _file
if _file is None:
_file = open('lib/ssd1306py/ascii32fb.txt', 'r')
_file.seek((ord(ch)) * ❗332❗)
get_line1 = _file.readline()
get_line2 = _file.readline()
data = []
n = 0
for v in get_line1.split(','):
data.append(int(v,16))
n += 1
if n == 32:
break
n = 0
for v in get_line2.split(','):
data.append(int(v,16))
n += 1
if n == 32:
break
return data
example of characters in the font text file:
0,0x00,0x00,0x00,0x80,0xC0,0xE0,0xE0,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xE0,0xF8,0xFE,0xFF,0x1F,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#
0x00,0x00,0x1F,0xFF,0xFF,0xFF,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x0F,0x1F,0x3E,0x38,0x20,0x00,0x00,0x00,0x00,0x00,0x00,#"(",08
0x00,0x20,0xE0,0xE0,0xC0,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x1F,0xFF,0xFE,0xFC,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#
0x00,0x00,0x00,0x00,0xC0,0xFF,0xFF,0xFF,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x38,0x3E,0x1F,0x0F,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#")",09
0x80,0x80,0x00,0x00,0xE0,0xE0,0xE0,0x00,0x00,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x01,0x11,0x19,0x3F,0x0F,0x07,0x0F,0x3F,0x19,0x11,0x01,0x00,0x00,0x00,0x00,0x00,#
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#"*",10
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xFE,0xFE,0xFE,0xFE,0xC0,0xC0,0xC0,0xC0,0xC0,#
0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x3F,0x3F,0x3F,0x3F,0x01,0x01,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#"+",11
notice I added left zeros in the index number to make the jump equal in all characters
I'm not expert in github to merge my modifications to the original code