diff --git a/boards/default_src/micropython/origin/build/lib/matrix16x8.py b/boards/default_src/micropython/origin/build/lib/matrix16x8.py index ed658f29..195a49bd 100644 --- a/boards/default_src/micropython/origin/build/lib/matrix16x8.py +++ b/boards/default_src/micropython/origin/build/lib/matrix16x8.py @@ -12,9 +12,10 @@ from ht16k33 import HT16K33 class Matrix(HT16K33): """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) self.font(font) + self.uin_font(font_address) """Graph module""" HEART=b' \x02p\x07\xf8\x0f\xf8\x0f\xf0\x07\xe0\x03\xc0\x01\x80\x00' diff --git a/boards/default_src/micropython/origin/build/lib/uframebuf.py b/boards/default_src/micropython/origin/build/lib/uframebuf.py index c5678999..bb02c104 100644 --- a/boards/default_src/micropython/origin/build/lib/uframebuf.py +++ b/boards/default_src/micropython/origin/build/lib/uframebuf.py @@ -161,6 +161,8 @@ class FrameBuffer_Base(FrameBuffer): self.width = width self.height = height self._buffer = buf + self._way = 1 + self._speed = 100 def show(self): 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""" 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): """Graphic model display(buffer,(width,height))""" buffer_info, (width, height) = buffer @@ -314,6 +326,45 @@ class FrameBuffer_Ascall(FrameBuffer_Base): 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) + 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): """Display character""" if data is not None: @@ -322,11 +373,12 @@ class FrameBuffer_Ascall(FrameBuffer_Base): self.set_buffer(data, sync) else: data=str(data) - x = (self.width - len(data) * (self._font.font_width + space) + space) // 2 if center else 0 - for char in data: - self.bitmap(self._font.chardata(char), x) - x = self._font.font_width + x + space - if sync: self.show() + if not self._gb2312_scroll(data, space): + x = (self.width - len(data) * (self._font.font_width + space) + space) // 2 if center else 0 + for char in data: + self.bitmap(self._font.chardata(char), x) + x = self._font.font_width + x + space + if sync: self.show() def frame(self, data, delay=500): """Display one frame per character""" @@ -339,26 +391,34 @@ class FrameBuffer_Ascall(FrameBuffer_Base): time.sleep_ms(delay) else: data=str(data) - x=(self.width - self._font.font_width) // 2 for char in data: self.fill(0, sync=False) - self.bitmap(self._font.chardata(char), x) - self.show() + if ord(char) >= 0xFF: + _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) - 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) - str_len = len(data) * (self._font.font_width + space) - space - for i in range(str_len + self.width + 1): - x = -i + self.width - self.fill(0, sync=False) - for char in data: - self.bitmap(self._font.chardata(char),x) - x = self._font.font_width + x + space - self.show() - time.sleep_ms(speed) + if not self._gb2312_scroll(data, space): + str_len = len(data) * (self._font.font_width + space) - space + for i in range(str_len + self.width + 1): + x = -i + self.width + self.fill(0, sync=False) + for char in data: + self.bitmap(self._font.chardata(char),x) + x = self._font.font_width + x + space + self.show() + time.sleep_ms(self._speed) class FrameBuffer_Uincode(FrameBuffer_Base): '''FrameBuffer for Uincode''' diff --git a/boards/default_src/micropython_esp32c2/origin/build/lib/mini_bot.py b/boards/default_src/micropython_esp32c2/origin/build/lib/mini_bot.py index dca92853..500d3b13 100644 --- a/boards/default_src/micropython_esp32c2/origin/build/lib/mini_bot.py +++ b/boards/default_src/micropython_esp32c2/origin/build/lib/mini_bot.py @@ -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)