更新CE支持汉字滚动显示,及MINI的显示方向
This commit is contained in:
@@ -12,9 +12,10 @@ from ht16k33 import HT16K33
|
|||||||
|
|
||||||
class Matrix(HT16K33):
|
class Matrix(HT16K33):
|
||||||
"""A single matrix."""
|
"""A single matrix."""
|
||||||
def __init__(self, i2c, address=0x70, brightness=0.3, font="5x8", width=16, height=8):
|
def __init__(self, i2c, address=0x70, brightness=0.3, font="5x8", font_address=0x3A0000, width=16, height=8):
|
||||||
super().__init__(i2c, address, brightness, width, height)
|
super().__init__(i2c, address, brightness, width, height)
|
||||||
self.font(font)
|
self.font(font)
|
||||||
|
self.uin_font(font_address)
|
||||||
|
|
||||||
"""Graph module"""
|
"""Graph module"""
|
||||||
HEART=b' \x02p\x07\xf8\x0f\xf8\x0f\xf0\x07\xe0\x03\xc0\x01\x80\x00'
|
HEART=b' \x02p\x07\xf8\x0f\xf8\x0f\xf0\x07\xe0\x03\xc0\x01\x80\x00'
|
||||||
|
|||||||
@@ -161,6 +161,8 @@ class FrameBuffer_Base(FrameBuffer):
|
|||||||
self.width = width
|
self.width = width
|
||||||
self.height = height
|
self.height = height
|
||||||
self._buffer = buf
|
self._buffer = buf
|
||||||
|
self._way = 1
|
||||||
|
self._speed = 100
|
||||||
|
|
||||||
def show(self):
|
def show(self):
|
||||||
print("External inheritance is required to override this method")
|
print("External inheritance is required to override this method")
|
||||||
@@ -304,6 +306,16 @@ class FrameBuffer_Ascall(FrameBuffer_Base):
|
|||||||
"""Font selection or externally defined font code"""
|
"""Font selection or externally defined font code"""
|
||||||
self._font = Font_Ascall(font)
|
self._font = Font_Ascall(font)
|
||||||
|
|
||||||
|
def uin_font(self, font_address=0x3A0000):
|
||||||
|
"""Uincode encoding font code"""
|
||||||
|
self._ufont = Font_Uincode(font_address)
|
||||||
|
|
||||||
|
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 bitmap(self, buffer, x=0, y=0):
|
def bitmap(self, buffer, x=0, y=0):
|
||||||
"""Graphic model display(buffer,(width,height))"""
|
"""Graphic model display(buffer,(width,height))"""
|
||||||
buffer_info, (width, height) = buffer
|
buffer_info, (width, height) = buffer
|
||||||
@@ -314,6 +326,45 @@ class FrameBuffer_Ascall(FrameBuffer_Base):
|
|||||||
if (buffer_info[char_x] >> char_y) & 0x1:
|
if (buffer_info[char_x] >> char_y) & 0x1:
|
||||||
self.pixel(x + char_x, y + char_y, 1, sync=False) if height <= self.height else self.pixel(y + char_y, self.height - (x + char_x), 1, sync=False)
|
self.pixel(x + char_x, y + char_y, 1, sync=False) if height <= self.height else self.pixel(y + char_y, self.height - (x + char_x), 1, sync=False)
|
||||||
|
|
||||||
|
def _uincode_scroll(self, buffer, space):
|
||||||
|
"""Scroll to display uincode encoded characters"""
|
||||||
|
_len = 0
|
||||||
|
for buf in buffer:
|
||||||
|
_len = _len + space + (buf[1][1] if self._way <= 1 else buf[1][0])
|
||||||
|
for i in range(_len - space + (self.width if self._way <= 1 else self.height)):
|
||||||
|
_step = (self.width - 1 if self._way <= 1 else self.height) - i
|
||||||
|
self.fill(0, sync=False)
|
||||||
|
for buf in buffer:
|
||||||
|
_buf, (width, height) = buf
|
||||||
|
_xx = (self.width - width) // 2
|
||||||
|
_yy = (self.width - height) // 2
|
||||||
|
if -width < _step < self.width or -height < _step < self.height :
|
||||||
|
for _y in range(height):
|
||||||
|
for _x in range(width):
|
||||||
|
if _buf[_y * ((width + 7) // 8) + _x // 8] & (0x80 >> (_x & 7)):
|
||||||
|
if self._way == 0:
|
||||||
|
self.pixel(self.width - (_x + _xx) - 2, self.height - (_step + _y), 1, sync=False)
|
||||||
|
elif self._way == 1:
|
||||||
|
self.pixel(_xx + _x + 1, _step + _y, 1, sync=False)
|
||||||
|
elif self._way == 2:
|
||||||
|
self.pixel(_y +_yy, self.height - (_step + _x), 1, sync=False)
|
||||||
|
elif self._way == 3:
|
||||||
|
self.pixel(self.width - (_y +_yy) - 1, (_step + _x), 1, sync=False)
|
||||||
|
_step = _step + space + (height if self._way <= 1 else width)
|
||||||
|
self.show()
|
||||||
|
time.sleep_ms(self._speed)
|
||||||
|
|
||||||
|
def _gb2312_scroll(self, data, space):
|
||||||
|
"""Determine if the uincode is encoded"""
|
||||||
|
for char in data:
|
||||||
|
if ord(char) >= 0xFF:
|
||||||
|
font_buffer = []
|
||||||
|
for c in data:
|
||||||
|
_buffer = self._ufont.chardata(c)
|
||||||
|
font_buffer.append(_buffer)
|
||||||
|
self._uincode_scroll(font_buffer, space)
|
||||||
|
return True
|
||||||
|
|
||||||
def shows(self, data, space=0, center=True, sync=True):
|
def shows(self, data, space=0, center=True, sync=True):
|
||||||
"""Display character"""
|
"""Display character"""
|
||||||
if data is not None:
|
if data is not None:
|
||||||
@@ -322,11 +373,12 @@ class FrameBuffer_Ascall(FrameBuffer_Base):
|
|||||||
self.set_buffer(data, sync)
|
self.set_buffer(data, sync)
|
||||||
else:
|
else:
|
||||||
data=str(data)
|
data=str(data)
|
||||||
x = (self.width - len(data) * (self._font.font_width + space) + space) // 2 if center else 0
|
if not self._gb2312_scroll(data, space):
|
||||||
for char in data:
|
x = (self.width - len(data) * (self._font.font_width + space) + space) // 2 if center else 0
|
||||||
self.bitmap(self._font.chardata(char), x)
|
for char in data:
|
||||||
x = self._font.font_width + x + space
|
self.bitmap(self._font.chardata(char), x)
|
||||||
if sync: self.show()
|
x = self._font.font_width + x + space
|
||||||
|
if sync: self.show()
|
||||||
|
|
||||||
def frame(self, data, delay=500):
|
def frame(self, data, delay=500):
|
||||||
"""Display one frame per character"""
|
"""Display one frame per character"""
|
||||||
@@ -339,26 +391,34 @@ class FrameBuffer_Ascall(FrameBuffer_Base):
|
|||||||
time.sleep_ms(delay)
|
time.sleep_ms(delay)
|
||||||
else:
|
else:
|
||||||
data=str(data)
|
data=str(data)
|
||||||
x=(self.width - self._font.font_width) // 2
|
|
||||||
for char in data:
|
for char in data:
|
||||||
self.fill(0, sync=False)
|
self.fill(0, sync=False)
|
||||||
self.bitmap(self._font.chardata(char), x)
|
if ord(char) >= 0xFF:
|
||||||
self.show()
|
_way = self._way
|
||||||
|
self._way = 1
|
||||||
|
self._uincode_scroll([self._ufont.chardata(char)], 0)
|
||||||
|
self._way = _way
|
||||||
|
else:
|
||||||
|
self.bitmap(self._font.chardata(char), (self.width - self._font.font_width) // 2 )
|
||||||
|
self.show()
|
||||||
time.sleep_ms(delay)
|
time.sleep_ms(delay)
|
||||||
|
|
||||||
def scroll(self, data, space=0, speed=100):
|
def scroll(self, data, space=0, speed=None):
|
||||||
"""Scrolling characters"""
|
"""Scrolling characters"""
|
||||||
|
if speed is not None:
|
||||||
|
self._speed = speed
|
||||||
if data is not None:
|
if data is not None:
|
||||||
data = str(data)
|
data = str(data)
|
||||||
str_len = len(data) * (self._font.font_width + space) - space
|
if not self._gb2312_scroll(data, space):
|
||||||
for i in range(str_len + self.width + 1):
|
str_len = len(data) * (self._font.font_width + space) - space
|
||||||
x = -i + self.width
|
for i in range(str_len + self.width + 1):
|
||||||
self.fill(0, sync=False)
|
x = -i + self.width
|
||||||
for char in data:
|
self.fill(0, sync=False)
|
||||||
self.bitmap(self._font.chardata(char),x)
|
for char in data:
|
||||||
x = self._font.font_width + x + space
|
self.bitmap(self._font.chardata(char),x)
|
||||||
self.show()
|
x = self._font.font_width + x + space
|
||||||
time.sleep_ms(speed)
|
self.show()
|
||||||
|
time.sleep_ms(self._speed)
|
||||||
|
|
||||||
class FrameBuffer_Uincode(FrameBuffer_Base):
|
class FrameBuffer_Uincode(FrameBuffer_Base):
|
||||||
'''FrameBuffer for Uincode'''
|
'''FrameBuffer for Uincode'''
|
||||||
|
|||||||
@@ -31,7 +31,9 @@ _Uincode_ADDR = const(0x3A0000)
|
|||||||
|
|
||||||
class BOT035(FrameBuffer):
|
class BOT035(FrameBuffer):
|
||||||
def __init__(self, i2c_bus, brightness=0.8):
|
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._buffer = bytearray(12)
|
||||||
self._brightness = brightness
|
self._brightness = brightness
|
||||||
self._touchs = [self.touch(0), self.touch(1)]
|
self._touchs = [self.touch(0), self.touch(1)]
|
||||||
@@ -51,7 +53,7 @@ class BOT035(FrameBuffer):
|
|||||||
def _uincode(self, ch):
|
def _uincode(self, ch):
|
||||||
'''uincode code font reading data'''
|
'''uincode code font reading data'''
|
||||||
uni = ord(ch)
|
uni = ord(ch)
|
||||||
if 0x20 <= uni <= 0x2642 :
|
if 0x20 <= uni <= 0x2642 :
|
||||||
_address = 0x28 + (uni - 0x20) * 4
|
_address = 0x28 + (uni - 0x20) * 4
|
||||||
elif 0x3001 <= uni <= 0x9fa0 :
|
elif 0x3001 <= uni <= 0x9fa0 :
|
||||||
_address = 0x98b4 + (uni - 0x3001) * 4
|
_address = 0x98b4 + (uni - 0x3001) * 4
|
||||||
@@ -62,11 +64,11 @@ class BOT035(FrameBuffer):
|
|||||||
buffer = bytearray(4)
|
buffer = bytearray(4)
|
||||||
flash_read(_Uincode_ADDR + _address, buffer)
|
flash_read(_Uincode_ADDR + _address, buffer)
|
||||||
font_info = buffer[3] << 24 | buffer[2] << 16 | buffer[1] << 8 | buffer[0]
|
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
|
font_width = font_info >> 26
|
||||||
buffer = bytearray( 12 * (font_width // 8 + 1))
|
buffer = bytearray(12 * (font_width // 8 + 1))
|
||||||
flash_read(_Uincode_ADDR + font_address, buffer)
|
flash_read(_Uincode_ADDR + font_address, buffer)
|
||||||
return buffer, font_width
|
return buffer, font_width, 12
|
||||||
|
|
||||||
def shift(self, x, y, rotate=False):
|
def shift(self, x, y, rotate=False):
|
||||||
"""Shift pixels by x and y"""
|
"""Shift pixels by x and y"""
|
||||||
@@ -141,20 +143,58 @@ class BOT035(FrameBuffer):
|
|||||||
for i in range(len(buffer)):
|
for i in range(len(buffer)):
|
||||||
self._buffer[i] = self._buffer[i] | buffer[i]
|
self._buffer[i] = self._buffer[i] | buffer[i]
|
||||||
|
|
||||||
def _ascall_bitmap(self, buffer, x=0):
|
def _ascall_bitmap(self, data, x=0 ,space=0):
|
||||||
if -_FONT_W <= x <= _LEDS_W:
|
for char in data:
|
||||||
for _x in range(_FONT_W):
|
buf = self._chardata(char)
|
||||||
for _y in range(_FONT_H):
|
if -_FONT_W <= x <= _LEDS_W:
|
||||||
if (buffer[_x] >> _y) & 0x1:
|
for _x in range(_FONT_W):
|
||||||
self.pixel(x + _x, _y, 1)
|
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):
|
def _uincode_scroll(self, buffer, space):
|
||||||
_buffer, width = buffer
|
_len = 0
|
||||||
if -width < x < _LEDS_H:
|
for buf in buffer:
|
||||||
for _y in range(12):
|
_len = _len + space + (buf[2] if self._way <= 1 else buf[1])
|
||||||
for _x in range(width):
|
for i in range(_len - space + (_LEDS_W if self._way <= 1 else _LEDS_H)):
|
||||||
if _buffer[_y * ((width + 7) // 8) + _x // 8] & (0x80 >> (_x & 7)):
|
_step = (_LEDS_W - 1 if self._way <= 1 else _LEDS_H) - i
|
||||||
self.pixel(_y, _LEDS_H - (x + _x), 1)
|
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):
|
def shows(self, data, space=1, center=True):
|
||||||
"""Display character"""
|
"""Display character"""
|
||||||
@@ -165,11 +205,9 @@ class BOT035(FrameBuffer):
|
|||||||
self.show()
|
self.show()
|
||||||
else:
|
else:
|
||||||
data = str(data)
|
data = str(data)
|
||||||
x = (_LEDS_W - len(data) * (_FONT_W + space) + space) // 2 if center else 0
|
if not self._gb2312_scroll(data, space):
|
||||||
for char in data:
|
x = (_LEDS_W - len(data) * (_FONT_W + space) + space) // 2 if center else 0
|
||||||
self._ascall_bitmap(self._chardata(char), x)
|
self._ascall_bitmap(data, x)
|
||||||
x = _FONT_W + x + space
|
|
||||||
self.show()
|
|
||||||
|
|
||||||
def frame(self, data, delay=500):
|
def frame(self, data, delay=500):
|
||||||
"""Display one frame per character"""
|
"""Display one frame per character"""
|
||||||
@@ -177,44 +215,28 @@ class BOT035(FrameBuffer):
|
|||||||
data = str(data)
|
data = str(data)
|
||||||
for char in data:
|
for char in data:
|
||||||
self.fill(0)
|
self.fill(0)
|
||||||
self._ascall_bitmap(self._chardata(char), (_LEDS_W - _FONT_W) // 2)
|
if ord(char) >= 0xFF:
|
||||||
self.show()
|
_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)
|
time.sleep_ms(delay)
|
||||||
|
|
||||||
def scroll(self, data, space=0, speed=100):
|
def scroll(self, data, space=0, speed=None):
|
||||||
"""Scrolling characters"""
|
"""Scrolling characters"""
|
||||||
|
if speed is not None:
|
||||||
|
self._speed = speed
|
||||||
if data is not None:
|
if data is not None:
|
||||||
data = str(data)
|
data = str(data)
|
||||||
uincode = False
|
if not self._gb2312_scroll(data, space):
|
||||||
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:
|
|
||||||
str_len = len(data) * (_FONT_W + space) - space
|
str_len = len(data) * (_FONT_W + space) - space
|
||||||
for i in range(str_len + _LEDS_W + 1):
|
for i in range(str_len + _LEDS_W + 1):
|
||||||
x = _LEDS_W -i
|
x = _LEDS_W - i
|
||||||
self.fill(0)
|
self.fill(0)
|
||||||
for char in data:
|
self._ascall_bitmap(data, x)
|
||||||
self._ascall_bitmap(self._chardata(char), x)
|
time.sleep_ms(self._speed)
|
||||||
x = _FONT_W + x + space
|
|
||||||
self.show()
|
|
||||||
time.sleep_ms(speed)
|
|
||||||
|
|
||||||
def pointern(self, x=_LEDS_W // 2, y=_LEDS_H // 2, l=_LEDS_H // 2, angle=0):
|
def pointern(self, x=_LEDS_W // 2, y=_LEDS_H // 2, l=_LEDS_H // 2, angle=0):
|
||||||
radian = math.radians(angle)
|
radian = math.radians(angle)
|
||||||
|
|||||||
Reference in New Issue
Block a user