更新CE支持汉字滚动显示,及MINI的显示方向
This commit is contained in:
@@ -31,7 +31,9 @@ _Uincode_ADDR = const(0x3A0000)
|
||||
|
||||
class BOT035(FrameBuffer):
|
||||
def __init__(self, i2c_bus, brightness=0.8):
|
||||
self._i2c= i2c_bus
|
||||
self._i2c = i2c_bus
|
||||
self._way = 2
|
||||
self._speed = 100
|
||||
self._buffer = bytearray(12)
|
||||
self._brightness = brightness
|
||||
self._touchs = [self.touch(0), self.touch(1)]
|
||||
@@ -51,7 +53,7 @@ class BOT035(FrameBuffer):
|
||||
def _uincode(self, ch):
|
||||
'''uincode code font reading data'''
|
||||
uni = ord(ch)
|
||||
if 0x20 <= uni <= 0x2642 :
|
||||
if 0x20 <= uni <= 0x2642 :
|
||||
_address = 0x28 + (uni - 0x20) * 4
|
||||
elif 0x3001 <= uni <= 0x9fa0 :
|
||||
_address = 0x98b4 + (uni - 0x3001) * 4
|
||||
@@ -62,11 +64,11 @@ class BOT035(FrameBuffer):
|
||||
buffer = bytearray(4)
|
||||
flash_read(_Uincode_ADDR + _address, buffer)
|
||||
font_info = buffer[3] << 24 | buffer[2] << 16 | buffer[1] << 8 | buffer[0]
|
||||
font_address = font_info & 0X3FFFFFF
|
||||
font_address = font_info & 0x3FFFFFF
|
||||
font_width = font_info >> 26
|
||||
buffer = bytearray( 12 * (font_width // 8 + 1))
|
||||
flash_read(_Uincode_ADDR + font_address, buffer)
|
||||
return buffer, font_width
|
||||
buffer = bytearray(12 * (font_width // 8 + 1))
|
||||
flash_read(_Uincode_ADDR + font_address, buffer)
|
||||
return buffer, font_width, 12
|
||||
|
||||
def shift(self, x, y, rotate=False):
|
||||
"""Shift pixels by x and y"""
|
||||
@@ -141,20 +143,58 @@ class BOT035(FrameBuffer):
|
||||
for i in range(len(buffer)):
|
||||
self._buffer[i] = self._buffer[i] | buffer[i]
|
||||
|
||||
def _ascall_bitmap(self, buffer, x=0):
|
||||
if -_FONT_W <= x <= _LEDS_W:
|
||||
for _x in range(_FONT_W):
|
||||
for _y in range(_FONT_H):
|
||||
if (buffer[_x] >> _y) & 0x1:
|
||||
self.pixel(x + _x, _y, 1)
|
||||
def _ascall_bitmap(self, data, x=0 ,space=0):
|
||||
for char in data:
|
||||
buf = self._chardata(char)
|
||||
if -_FONT_W <= x <= _LEDS_W:
|
||||
for _x in range(_FONT_W):
|
||||
for _y in range(_FONT_H):
|
||||
if (buf[_x] >> _y) & 0x1:
|
||||
self.pixel(x + _x, _y, 1)
|
||||
x = _FONT_W + x + space
|
||||
self.show()
|
||||
|
||||
def _uincode_bitmap(self, buffer, x=0):
|
||||
_buffer, width = buffer
|
||||
if -width < x < _LEDS_H:
|
||||
for _y in range(12):
|
||||
for _x in range(width):
|
||||
if _buffer[_y * ((width + 7) // 8) + _x // 8] & (0x80 >> (_x & 7)):
|
||||
self.pixel(_y, _LEDS_H - (x + _x), 1)
|
||||
def _uincode_scroll(self, buffer, space):
|
||||
_len = 0
|
||||
for buf in buffer:
|
||||
_len = _len + space + (buf[2] if self._way <= 1 else buf[1])
|
||||
for i in range(_len - space + (_LEDS_W if self._way <= 1 else _LEDS_H)):
|
||||
_step = (_LEDS_W - 1 if self._way <= 1 else _LEDS_H) - i
|
||||
self.fill(0)
|
||||
for buf in buffer:
|
||||
_buf, width, high = buf
|
||||
_xx = (_LEDS_W - width) // 2
|
||||
if -high < _step < _LEDS_W:
|
||||
for _y in range(12):
|
||||
for _x in range(width):
|
||||
if _buf[_y * ((width + 7) // 8) + _x // 8] & (0x80 >> (_x & 7)):
|
||||
if self._way == 0:
|
||||
self.pixel( _LEDS_W - (_xx + _x) - 2, _LEDS_H - (_step + _y), 1)
|
||||
elif self._way == 1:
|
||||
self.pixel(_xx + _x + 1, _step + _y, 1)
|
||||
elif self._way == 2:
|
||||
self.pixel(_y, _LEDS_H - (_step + _x), 1)
|
||||
elif self._way == 3:
|
||||
self.pixel(_LEDS_W - _y - 1, (_step + _x), 1)
|
||||
_step = _step + space + (high if self._way <= 1 else width)
|
||||
self.show()
|
||||
time.sleep_ms(self._speed)
|
||||
|
||||
def _gb2312_scroll(self, data, space):
|
||||
for char in data:
|
||||
if ord(char) >= 0xFF:
|
||||
font_buffer = []
|
||||
for c in data:
|
||||
_buffer = self._uincode(c)
|
||||
font_buffer.append(_buffer)
|
||||
self._uincode_scroll(font_buffer, space)
|
||||
return True
|
||||
|
||||
def scroll_way(self, way=1, speed=None):
|
||||
"""0,1竖,2,3横"""
|
||||
self._way = way % 4
|
||||
if speed is not None:
|
||||
self._speed = speed
|
||||
|
||||
def shows(self, data, space=1, center=True):
|
||||
"""Display character"""
|
||||
@@ -165,11 +205,9 @@ class BOT035(FrameBuffer):
|
||||
self.show()
|
||||
else:
|
||||
data = str(data)
|
||||
x = (_LEDS_W - len(data) * (_FONT_W + space) + space) // 2 if center else 0
|
||||
for char in data:
|
||||
self._ascall_bitmap(self._chardata(char), x)
|
||||
x = _FONT_W + x + space
|
||||
self.show()
|
||||
if not self._gb2312_scroll(data, space):
|
||||
x = (_LEDS_W - len(data) * (_FONT_W + space) + space) // 2 if center else 0
|
||||
self._ascall_bitmap(data, x)
|
||||
|
||||
def frame(self, data, delay=500):
|
||||
"""Display one frame per character"""
|
||||
@@ -177,44 +215,28 @@ class BOT035(FrameBuffer):
|
||||
data = str(data)
|
||||
for char in data:
|
||||
self.fill(0)
|
||||
self._ascall_bitmap(self._chardata(char), (_LEDS_W - _FONT_W) // 2)
|
||||
self.show()
|
||||
if ord(char) >= 0xFF:
|
||||
_way = self._way
|
||||
self._way = 1
|
||||
self._uincode_scroll([self._uincode(char)], 0)
|
||||
self._way = _way
|
||||
else:
|
||||
self._ascall_bitmap([char], (_LEDS_W - _FONT_W) // 2)
|
||||
time.sleep_ms(delay)
|
||||
|
||||
def scroll(self, data, space=0, speed=100):
|
||||
def scroll(self, data, space=0, speed=None):
|
||||
"""Scrolling characters"""
|
||||
if speed is not None:
|
||||
self._speed = speed
|
||||
if data is not None:
|
||||
data = str(data)
|
||||
uincode = False
|
||||
for char in data:
|
||||
if ord(char) >= 0xff:
|
||||
uincode =True
|
||||
break
|
||||
if uincode:
|
||||
font_buffer = []
|
||||
str_len = 0
|
||||
for c in data:
|
||||
_buffer = self._uincode(c)
|
||||
font_buffer.append(_buffer)
|
||||
str_len = str_len + _buffer[1] + space
|
||||
for i in range(str_len + _LEDS_H - space):
|
||||
x = _LEDS_H - i
|
||||
self.fill(0)
|
||||
for buffer in font_buffer:
|
||||
self._uincode_bitmap(buffer, x)
|
||||
x = buffer[1] + x + space
|
||||
self.show()
|
||||
time.sleep_ms(speed)
|
||||
else:
|
||||
if not self._gb2312_scroll(data, space):
|
||||
str_len = len(data) * (_FONT_W + space) - space
|
||||
for i in range(str_len + _LEDS_W + 1):
|
||||
x = _LEDS_W -i
|
||||
x = _LEDS_W - i
|
||||
self.fill(0)
|
||||
for char in data:
|
||||
self._ascall_bitmap(self._chardata(char), x)
|
||||
x = _FONT_W + x + space
|
||||
self.show()
|
||||
time.sleep_ms(speed)
|
||||
self._ascall_bitmap(data, x)
|
||||
time.sleep_ms(self._speed)
|
||||
|
||||
def pointern(self, x=_LEDS_W // 2, y=_LEDS_H // 2, l=_LEDS_H // 2, angle=0):
|
||||
radian = math.radians(angle)
|
||||
|
||||
Reference in New Issue
Block a user