class dot21: width = 21 height = 21 img = bytearray(b"\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xD6\xDC\x85\x38"\ b"\x5C\x76\x44\x35\x54\x96\x95\xD9\x9D\xD9\xAD\xF9\xDF\x1D\xFF\xDF"\ b"\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"\ b"\xFF\xFF\xD6\xDC\x5C\x35\x33\xD4\x54\xF7\x55\x18\x55\x18\x5D\x38"\ b"\x85\xFA\x85\xFA\x9E\x3B\x7D\x38\x85\x17\xDF\x1D\xFF\xFF\xFF\xFF"\ b"\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xAD\xFA\x2B\x12\x3C\x56"\ b"\x55\x18\x55\x18\x55\x18\x55\x18\x65\x38\x9E\x5B\xA6\x5B\x96\x1A"\ b"\x8E\x1A\x95\xFA\x54\x15\xA5\xD9\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"\ b"\xFF\xFF\xAD\xFA\x1A\xD2\x3C\x15\x5D\x18\x55\x18\x55\x18\x55\x18"\ b"\x55\x18\x55\x18\x5D\x38\x6D\x79\x85\xDA\xA6\x5B\x96\x1A\x7D\x99"\ b"\x2A\xF2\x9D\x98\xFF\xFF\xFF\xFF\xFF\xFF\xD6\xFC\x1A\xB1\x1B\x33"\ b"\x55\x18\x55\x18\x55\x18\x55\x18\x55\x18\x55\x18\x55\x18\x54\xF8"\ b"\x54\xF7\x54\xF7\x75\x79\x8D\xFA\x75\x99\x7D\x58\x3B\x73\xB6\x3A"\ b"\xFF\xFF\xFF\xFF\x53\xF4\x02\x30\x44\x56\x5D\x18\x55\x18\x55\x18"\ b"\x55\x18\x55\x18\x55\x18\x55\x18\x55\x18\x55\x18\x55\x18\x54\xF7"\ b"\x5D\x38\xA6\x5B\x85\xBA\x64\x76\x4B\xB4\xF7\xBE\xDF\x1C\x01\xCF"\ b"\x12\xB1\x54\xF7\x55\x18\x55\x18\x55\x18\x55\x18\x55\x18\x55\x18"\ b"\x55\x18\x55\x18\x55\x18\x55\x18\x55\x18\x54\xF8\x85\xDA\xA6\x5B"\ b"\x64\xB7\x43\x73\xA5\xD9\x85\x17\x01\xCF\x1A\xD2\x5D\x38\x55\x18"\ b"\x55\x18\x55\x18\x55\x18\x55\x18\x55\x18\x55\x18\x55\x18\x55\x18"\ b"\x55\x18\x55\x18\x55\x18\x5D\x38\xAE\x7B\x64\xB7\x4B\xB4\x64\x35"\ b"\x43\x93\x01\xEF\x1A\xF2\x5D\x38\x55\x18\x55\x18\x55\x18\x55\x18"\ b"\x55\x18\x55\x18\x55\x18\x55\x18\x55\x18\x55\x18\x55\x18\x55\x18"\ b"\x54\xF8\x96\x1A\x6C\xD7\x54\x15\x2A\xF2\x1A\x91\x01\xEF\x12\xB1"\ b"\x55\x18\x55\x18\x55\x18\x55\x18\x55\x18\x55\x18\x55\x18\x55\x18"\ b"\x55\x18\x55\x18\x55\x18\x55\x18\x55\x18\x55\x18\x85\xDA\x74\xF7"\ b"\x4B\xF5\x12\x70\x0A\x2F\x01\xF0\x0A\x71\x44\x76\x55\x18\x55\x18"\ b"\x55\x18\x55\x18\x55\x18\x55\x18\x55\x18\x55\x18\x55\x18\x55\x18"\ b"\x55\x18\x55\x18\x55\x18\x75\x79\x53\xF5\x3B\x73\x0A\x30\x22\xD1"\ b"\x01\xEF\x02\x10\x2B\x94\x5D\x18\x55\x18\x55\x18\x55\x18\x55\x18"\ b"\x55\x18\x55\x18\x55\x18\x55\x18\x55\x18\x55\x18\x55\x18\x55\x18"\ b"\x34\x15\x01\xAF\x01\xCF\x0A\x2F\x4B\x93\x01\xEF\x01\xEF\x0A\x91"\ b"\x44\x96\x55\x18\x55\x18\x55\x18\x55\x18\x55\x18\x55\x18\x55\x18"\ b"\x55\x18\x55\x18\x55\x18\x55\x18\x4C\xD7\x0A\x71\x01\xEF\x01\xEF"\ b"\x33\x32\x8D\x38\x01\xCF\x02\x10\x01\xEF\x1A\xF2\x4C\xB7\x5D\x18"\ b"\x55\x18\x55\x18\x55\x18\x55\x18\x55\x18\x55\x18\x55\x18\x5D\x38"\ b"\x54\xD7\x1A\xF2\x01\xEF\x02\x10\x01\xEF\x6C\x76\xE7\x5D\x01\xCF"\ b"\x02\x10\x02\x10\x02\x10\x12\xB1\x44\x56\x5D\x38\x5D\x18\x55\x18"\ b"\x55\x18\x55\x18\x5D\x18\x5D\x38\x44\x56\x12\xB1\x02\x10\x02\x10"\ b"\x01\xEF\x1A\x91\xB6\x3A\xFF\xFF\x6C\x76\x01\xAF\x02\x10\x02\x10"\ b"\x02\x10\x02\x30\x1A\xF2\x3C\x15\x4C\x96\x54\xD7\x4C\xB7\x3C\x15"\ b"\x1A\xF2\x02\x50\x02\x10\x02\x10\x02\x10\x01\xEF\x4B\xD4\xFF\xFF"\ b"\xFF\xFF\xE7\x5E\x22\xB1\x01\xEF\x02\x10\x02\x10\x02\x10\x02\x10"\ b"\x02\x10\x02\x10\x02\x10\x02\x10\x02\x10\x02\x10\x02\x10\x02\x10"\ b"\x02\x10\x01\xF0\x1A\x91\xD6\xDC\xFF\xFF\xFF\xFF\xFF\xFF\xBE\x7B"\ b"\x12\x70\x01\xEF\x02\x10\x02\x10\x02\x10\x02\x10\x02\x10\x02\x10"\ b"\x02\x10\x02\x10\x02\x10\x02\x10\x02\x10\x01\xF0\x0A\x50\xAD\xD9"\ b"\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xB6\x3B\x22\xD1\x02\x10"\ b"\x01\xEF\x02\x10\x02\x10\x02\x10\x02\x10\x02\x10\x02\x10\x02\x10"\ b"\x01\xEF\x01\xEF\x1A\x91\xAD\xF9\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"\ b"\xFF\xFF\xFF\xFF\xFF\xFF\xD6\xFC\x5C\x35\x22\xB1\x01\xEF\x01\xEF"\ b"\x01\xEF\x01\xEF\x01\xEF\x01\xCF\x02\x10\x1A\xB1\x53\xF4\xDF\x1C"\ b"\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"\ b"\xFF\xFF\xFF\xFF\xC6\x7B\x7C\xF7\x43\x93\x22\xB1\x1A\x91\x22\xB1"\ b"\x43\x93\x7C\xF7\xBE\x7B\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"\ b"\xFF\xFF") Fb = framebuf.FrameBuffer(img, width, height, framebuf.RGB565)
def char(char, x, y, color=0xffff, background=0x0000): #取frame画图 global png global Letter global l w = 16 buffer = bytearray(int(w * w / 8)) framebuffer = framebuf.FrameBuffer(buffer, w, w, framebuf.MONO_HLSB) print(char, bytearray(char)) print("buf before", buffer) framebuffer.text(char, 0, 0) print("buf after", buffer) k = 1 for i in range(13): if i % 2 == 0: print("buf ", i, buffer[i]) a = (bin(buffer[i]))[2:] b = 7 - len(a) print(b) c = '0' for i in range(b): #补0 c = c + '0' a = c + a #print(a) png[k] = png[k] + a k = k + 1
def test(): import framebuf, gc, micropython # direct display access test (display.fill(colors.BGR565_WHITE)) display.fill_rectangle(20, 20, 90, 90, colors.BGR565_RED) display.fill_rectangle(200, 20, 90, 90, colors.BGR565_GREEN) display.fill_rectangle(114, 130, 90, 90, colors.BGR565_BLUE) display.text("test 1 2 3", 20, 20, colors.BGR565_BLACK, colors.BGR565_WHITE) # framebuffered access tesst rawbuffer = bytearray(display.width * display.height * 2) fb = framebuf.FrameBuffer(rawbuffer, display.width, display.height, framebuf.RGB565) fb.fill(colors.BGR565_RED) display.blit_buffer(rawbuffer, 0, 0, display.width, display.height) fb.fill(colors.BGR565_GREEN) display.blit_buffer(rawbuffer, 0, 0, display.width, display.height) fb.fill(colors.BGR565_BLUE) display.blit_buffer(rawbuffer, 0, 0, display.width, display.height) fb.fill(colors.BGR565_BLACK) display.blit_buffer(rawbuffer, 0, 0, display.width, display.height) # Higher level access text() fb.fill(colors.BGR565_BLACK) display.blit_buffer(rawbuffer, 0, 0, display.width, display.height) display.text("Random plot", 10, 10, colors.BGR565_BLACK, colors.BGR565_WHITE) graph() micropython.mem_info() fb = None rawbuffer = None gc.collect() micropython.mem_info()
def img_read(filename): img = open(filename, 'rb') px = img.read() px = px[62:] array = bytearray(px) imgbuf = framebuf.FrameBuffer(array, 128,int((len(px)/16)), framebuf.MONO_HLSB) return(imgbuf)
def char(self, data): # check CR code if data == '\r': self.cursor_x = 0 self.cursor_y += 8 * self.textsize if self.cursor_y >= self._height: return 0 elif ord(data) < 0x20 or self.cursor_y >= self._height: return 0 # set character data else: if self.cursor_x + 8 >= self._width: self.cursor_x = 0 self.cursor_y += 8 * self.textsize if self.cursor_y >= self._height: return 0 w = 8 h = 8 b = self.textbgcolor b = (b & 0xff) * 256 + (b >> 8) c = self.textcolor c = (c & 0xff) * 256 + (c >> 8) buf1_len = w * h * 2 view_charbuf = memoryview(self.__class__.charbuf) buf1 = memoryview(view_charbuf[:buf1_len]) fb = framebuf.FrameBuffer(buf1, w, h, framebuf.RGB565) fb.fill(b) fb.text(data, 0, 0, c) self.drawPblk(self.cursor_x, self.cursor_y, w, h, buf1) self.cursor_x += 8 return 1
def __init__(self, i2c, address=0x3c, width=128, height=64): self._i2c = i2c self._address = address self.width = width self.height = height pages = height // 8 self._command = bytearray(b'\x21\x00\x7f\x22\x00\x0f') self._command[2] = width - 1 if width == 64: self._command[1] += 32 self._command[2] += 32 self._command[5] = pages - 1 self._i2c.writeto_mem( self._address, 0x00, b'\xae\x20\x00\x40\x00\xa1' b'\xc8\xd3\x00\xd5\x80\xd9\xf1\xdb\x30\x8d\x14' b'\x81\xff\xa4\xa6') self._word[0] = 0xa8 self._word[1] = height - 1 self._i2c.writeto_mem(self._address, 0x00, self._word) self._word[0] = 0xda self._word[1] = 0x02 if height == 32 else 0x12 self._i2c.writeto_mem(self._address, 0x00, self._word) self.active(True) buffer = bytearray(width * pages) self.fb = framebuf.FrameBuffer(buffer, width, height, framebuf.MVLSB) self._buffer = buffer
def __init__(self, file): with open('symbols/' + file, 'rb') as f: f.readline() f.readline() f.readline() data = bytearray(f.read()) self.fbuf = framebuf.FrameBuffer(data, 20, 20, framebuf.MONO_HLSB)
def __init__(self, spi, dc, cs=None, width=128, height=64): self._spi = spi self._cs = cs or (lambda x: x) self._dc = dc self.width = width self.height = height pages = height // 8 self._command = bytearray(b'\x21\x00\x7f\x22\x00\x0f') self._command[2] = width - 1 if width == 64: self._command[1] += 32 self._command[2] += 32 self._command[5] = pages - 1 self._write(b'\xae\x20\x00\x40\x00\xa1' b'\xc8\xd3\x00\xd5\x80\xd9\xf1\xdb\x30\x8d\x14' b'\x81\xff\xa4\xa6') self._word[0] = 0xa8 self._word[1] = height - 1 self._write(self._word) self._word[0] = 0xda self._word[1] = 0x02 if height == 32 else 0x12 self._write(self._word) self.active(True) buffer = bytearray(width * pages) self.fb = framebuf.FrameBuffer(buffer, width, height, framebuf.MVLSB) self._buffer = buffer
def render_bmp_(tft, x=12, y=0, w=215, h=215): global tch f = open('test3.bmp', 'rb') f.seek(0x8a) ss = f.read((w + 1) * 2) n = 0 y0 = y y = y + h bs = bytearray() while ss: if tch: break n += 1 #bs=bytearray() bx = ss[:-2] while bx: bs.append(bx[0]) bs.append(bx[1]) bx = bx[2:] if tch: break #frm = framebuf.FrameBuffer(bytearray( #tft.blit_buffer(bs,x,y,w,1) ss = f.read((w + 1) * 2) y -= 1 if y <= y0: break frm = framebuf.FrameBuffer(bs, w, h, framebuf.RGB565) tft.blit(frm, x, 0) tft.show() print('n:%s' % n)
def app_start(): oled.fill(0) sprites = loadPBM('./sprites.pbm') oled.blit(sprites, 0, 0) sprites = [] for i in range(6): # split sprites fbuf = framebuf.FrameBuffer(bytearray(32), 16, 16, framebuf.MONO_HLSB) for yy in range(16): for xx in range(16): if oled.pixel(i * 16 + xx, yy): fbuf.pixel(xx, yy, 1) sprites.append(fbuf) objs = [] for i in range(randint(5, 15)): objs.append([0, 0, 65, 1]) # sprite,x,y,vy while btn.B.value(): oled.fill(0) for o in objs: o[2] += o[3] if o[2] > 64: # reset obj o[0] = randint(0, 5) o[1] = randint(0, 110) o[2] = -16 o[3] = randint(1, 10) oled.blit(sprites[o[0]], o[1], o[2], 0) oled.fill_rect(20, 55, 90, 8, 0) oled.hctext('[B] to Quit', 56, 1) oled.show() sleep_ms(10)
def __init__(self, width, height, external_vcc): """ Consstructor of SSD1306. Args: width : Screen width (unit is dot) height : Screen height (unit is dot) external_vcc : Boolean value is False when using external vcc, or else True using internal vcc """ self.width = width self.height = height self.external_vcc = external_vcc self.pages = self.height // 8 self.buffer = bytearray(self.pages * self.width) fb = framebuf.FrameBuffer(self.buffer, self.width, self.height, framebuf.MONO_VLSB) self.framebuf = fb # Provide methods for accessing FrameBuffer graphics primitives. This is a # workround because inheritance from a native class is currently unsupported. # http://docs.micropython.org/en/latest/pyboard/library/framebuf.html self.fill = fb.fill self.pixel = fb.pixel self.hline = fb.hline self.vline = fb.vline self.line = fb.line self.rect = fb.rect self.fill_rect = fb.fill_rect self.text = fb.text self.scroll = fb.scroll self.blit = fb.blit self.init_display()
def render_boot_image(): boot_image_path = get_boot_image() if boot_image_path == None: import hal_screen hal_screen.refresh() boot_image_path = DEFAULT_BOOT_ICON if boot_image_path != "": from graphic import framebuf_helper import framebuf, hal_screen if boot_image_path == DEFAULT_BOOT_ICON: from buildin_resource.image.play32_icon import PLAY32_ICON_DATA iw, ih, idata = PLAY32_ICON_DATA else: from graphic import pbm with open(boot_image_path, 'rb') as ifile: iw, ih, _, idata = pbm.read_image(ifile)[:4] image = framebuf.FrameBuffer(idata, iw, ih, framebuf.MONO_HLSB) image = framebuf_helper.ensure_same_format( image, framebuf_helper.MONO_HLSB, iw, ih, hal_screen.get_format(), framebuf_helper.get_white_color(hal_screen.get_format())) sw, sh = hal_screen.get_size() frame = hal_screen.get_framebuffer() frame.fill(0) frame.blit(image, (sw - iw) // 2, (sh - ih) // 2, 0) hal_screen.refresh() del idata, image, iw, ih, sw, sh return True return False
def disZHString(ssd, data, x, y): icon_keys = font2.hanzi_16x16.keys() for k, v in enumerate(data): if v in icon_keys: fbuf = framebuf.FrameBuffer(bytearray(font2.hanzi_16x16[v]), 16, 16, framebuf.MONO_HLSB) ssd.blit(fbuf, x + 16 * k, y)
def load_image(filename): with open(filename, 'rb') as file: file.readline() # magic number: P4 file.readline() # creator comment width, height = [int(value) for value in file.readline().split()] image = bytearray(file.read()) return framebuf.FrameBuffer(image, width, height, framebuf.MONO_HLSB)
def __init__(self): self.reset_pin = Pin(RST_PIN, Pin.OUT) self.dc_pin = Pin(DC_PIN, Pin.OUT) self.busy_pin = Pin(BUSY_PIN, Pin.IN, Pin.PULL_UP) self.cs_pin = Pin(CS_PIN, Pin.OUT) self.width = EPD_WIDTH self.height = EPD_HEIGHT self.spi = SPI(1) self.spi.init(baudrate=4000_000) self.buffer_balck = bytearray(self.height * self.width // 8) self.buffer_red = bytearray(self.height * self.width // 8) self.imageblack = framebuf.FrameBuffer(self.buffer_balck, self.width, self.height, framebuf.MONO_HLSB) self.imagered = framebuf.FrameBuffer(self.buffer_red, self.width, self.height, framebuf.MONO_HLSB) self.init()
def __init__(self, pin_scl=machine.Pin(22), pin_sda=machine.Pin(21), height=32, external_vcc=True, i2c_devid=DEVID): self.pin_scl = pin_scl self.pin_sda = pin_sda self.external_vcc = external_vcc self.height = 32 if height == 32 else 64 self.pages = int(self.height / 8) self.columns = 128 self.i2c = machine.SoftI2C(scl=self.pin_scl, sda=self.pin_sda, freq=400000) self.devid = i2c_devid # used to reserve an extra byte in the image buffer AND as a way to # infer the interface type # I2C command buffer self.cbuffer = bytearray(2) self.cbuffer[0] = CTL_CMD self.temp = bytearray(2) self.widthh = 128 self.heightt = 64 self.pagess = self.heightt // 8 self.bufferr = bytearray(self.pagess * self.widthh) self.framebuf = framebuf.FrameBuffer(self.bufferr, self.widthh, self.heightt, framebuf.MVLSB) self.poweron() self.init_display()
def __init__(self, spi, cs, num): """ Driver for cascading MAX7219 8x8 LED matrices. >>> import max7219 >>> from machine import Pin, SPI >>> spi = SPI(1) >>> display = max7219.Matrix8x8(spi, Pin('X5'), 4) >>> display.text('1234',0,0,1) >>> display.show() """ self.spi = spi self.cs = cs self.cs.init(cs.OUT, True) self.buffer = bytearray(8 * num) self.num = num fb = framebuf.FrameBuffer(self.buffer, 8 * num, 8, framebuf.MONO_HLSB) self.framebuf = fb # Provide methods for accessing FrameBuffer graphics primitives. This is a workround # because inheritance from a native class is currently unsupported. # http://docs.micropython.org/en/latest/pyboard/library/framebuf.html self.fill = fb.fill # (col) self.pixel = fb.pixel # (x, y[, c]) self.hline = fb.hline # (x, y, w, col) self.vline = fb.vline # (x, y, h, col) self.line = fb.line # (x1, y1, x2, y2, col) self.rect = fb.rect # (x, y, w, h, col) self.fill_rect = fb.fill_rect # (x, y, w, h, col) self.text = fb.text # (string, x, y, col=1) self.scroll = fb.scroll # (dx, dy) self.blit = fb.blit # (fbuf, x, y[, key]) self.init()
def __init__(self, width, height, *args, main_process=False, ignore_pygame_event=False, **kws): self.width = width self.height = height self.__scale = 8 self.__main_process = main_process self.__ignore_pygame_event = ignore_pygame_event # sub process self.__loop = None self.__loop_queue = None self.__loop_event_queue = None # main process self.__request_list = [] self.__pygame_event = [] self.__screen = None # internal self.__power = True # init buffer self.pages = self.height // 8 if height % 8 != 0: self.pages = self.pages + 1 self.buffer = bytearray(self.pages * self.width) if self.__main_process: self.__screen_buffer = bytearray(self.pages * self.width) else: self.__screen_buffer = Array('b', self.pages * self.width) super().__init__(self.buffer, self.width, self.height, framebuf.MONO_VLSB) self.__screen_frame = framebuf.FrameBuffer(self.__screen_buffer, self.width, self.height, framebuf.MONO_VLSB) # init display self._init_display()
def __init__(self, reset, dc, busy, cs, clk, mosi): # initialize the frame buffer self.buffer = bytearray(EPD_WIDTH * EPD_HEIGHT // 2) #setup framebuf.FrameBuffer self.fbuf = framebuf.FrameBuffer(self.buffer, EPD_WIDTH, EPD_HEIGHT, framebuf.GS4_HMSB) self.reset_pin = reset self.reset_pin.mode(Pin.OUT) self.dc_pin = dc self.dc_pin.mode(Pin.OUT) self.busy_pin = busy self.busy_pin.mode(Pin.IN) self.cs_pin = cs self.cs_pin.mode(Pin.OUT) self.cs_pin.pull(Pin.PULL_UP) self.spi = SPI(0, mode=SPI.MASTER, baudrate=2000000, polarity=0, phase=0, pins=(clk, mosi, None)) self.width = EPD_WIDTH self.height = EPD_HEIGHT self.rotate = ROTATE_0
def __init__(self, i2c, address=0x70): # self.i2c = i2c # self.address = address # self._temp = bytearray(1) # self.buffer = bytearray(17) # #self.buffer[0] = 0x00 # self.framebuf = framebuf.FrameBuffer(self.buffer, 16, 8, framebuf.MONO_HMSB) # self.fill(0) # self._write_cmd(_DISPLAY_OSCILATOR_ON) # self.blink_rate(0) # self.brightness(15) self.i2c = i2c self.address = address self._temp = bytearray(1) self.buffer = bytearray(16) # self.buffer2 = bytearray(17) # self.buffer2[0] = 0x00 self._write_cmd(_DISPLAY_OSCILATOR_ON) self.blink_rate(0) self.brightness(15) self._fb_buffer = bytearray(self.WIDTH * self.HEIGHT * self.FB_BPP // 8) self.framebuf = framebuf.FrameBuffer(self._fb_buffer, self.WIDTH, self.HEIGHT, self.FORMAT) self.framebuf.fill(0) self._pixel = self.framebuf.pixel self.fill = self.framebuf.fill
def __init__(self, spi, dc, res, cs, busy): # SPI self.rate = 2 * 1024 * 1024 # 2MHz self.spi = spi # other pin self.dc_pin = dc self.reset_pin = res self.cs_pin = cs self.busy_pin = busy # self.width = EPD_WIDTH self.height = EPD_HEIGHT # frame buffer self.buffer = bytearray(EPD_HEIGHT * EPD_WIDTH // 8) fb = framebuf.FrameBuffer(self.buffer, self.width, self.height, framebuf.MONO_HLSB) self.framebuf = fb self.fill = fb.fill self.pixel = fb.pixel self.hline = fb.hline self.vline = fb.vline self.line = fb.line self.rect = fb.rect self.fill_rect = fb.fill_rect self.text = fb.text self.scroll = fb.scroll self.blit = fb.blit self.init_display()
def text(self, text, x=None, y=None, color=None, background=None): if background is None: background = self._bg if color is None: color = self._fg if x is None: x = self.x if y is None: y = self.y x = min(self.width - 1, max(0, x)) y = min(self.height - 1, max(0, y)) lines = text.splitlines() longest = 0 for line in lines: longest = max(longest, len(line)) h = min(self.height - y, 8) buffer = bytearray(longest * 8 * 8 * 2) fb = framebuf.FrameBuffer(buffer, 8 * longest, 8, framebuf.RGB565) for line in lines: fb.fill(background) fb.text(line, 0, 0, color) self.blit_buffer(buffer, x, y, len(line) * 8, h) y += 8 if y >= self.height: break
def DispChar_font(self, font, s, x, y, invert=False): """ custom font display.Ref by , https://github.com/peterhinch/micropython-font-to-py :param font: use font_to_py.py script convert to `py` from `ttf` or `otf`. """ screen_width = self.width screen_height = self.height text_row = x text_col = y text_length = 0 if font.hmap(): font_map = framebuf.MONO_HMSB if font.reverse( ) else framebuf.MONO_HLSB else: raise ValueError('Font must be horizontally mapped.') for c in s: glyph, char_height, char_width = font.get_ch(c) buf = bytearray(glyph) if invert: for i, v in enumerate(buf): buf[i] = 0xFF & ~v fbc = framebuf.FrameBuffer(buf, char_width, char_height, font_map) if text_row + char_width > screen_width - 1: text_length += screen_width - text_row text_row = 0 text_col += char_height if text_col + char_height > screen_height + 2: text_col = 0 super().blit(fbc, text_row, text_col) text_row = text_row + char_width + 1 text_length += char_width + 1 return (text_length - 1, (text_row - 1, text_col))
def __init__(self): self.reset_pin = Pin(RST_PIN, Pin.OUT) self.busy_pin = Pin(BUSY_PIN, Pin.IN, Pin.PULL_UP) self.cs_pin = Pin(CS_PIN, Pin.OUT) self.width = EPD_WIDTH self.height = EPD_HEIGHT self.lut_vcom0 = EPD_4IN2_lut_vcom0 self.lut_ww = EPD_4IN2_lut_ww self.lut_bw = EPD_4IN2_lut_bw self.lut_wb = EPD_4IN2_lut_wb self.lut_bb = EPD_4IN2_lut_bb self.lut_Partial_vcom = EPD_4IN2_Partial_lut_vcom1 self.lut_Partial_ww = EPD_4IN2_Partial_lut_ww1 self.lut_Partial_bw = EPD_4IN2_Partial_lut_bw1 self.lut_Partial_wb = EPD_4IN2_Partial_lut_wb1 self.lut_Partial_bb = EPD_4IN2_Partial_lut_bb1 self.lut_4Gray_vcom = EPD_4IN2_4Gray_lut_vcom self.lut_4Gray_ww = EPD_4IN2_4Gray_lut_ww self.lut_4Gray_bw = EPD_4IN2_4Gray_lut_bw self.lut_4Gray_wb = EPD_4IN2_4Gray_lut_wb self.lut_4Gray_bb = EPD_4IN2_4Gray_lut_bb self.black = 0x00 self.white = 0xff self.darkgray = 0xaa self.grayish = 0x55 self.spi = SPI(1) self.spi.init(baudrate=4000_000) self.dc_pin = Pin(DC_PIN, Pin.OUT) self.buffer_1Gray_DATA = [0x00] * (self.height * self.width // 8) self.buffer_1Gray = bytearray(self.height * self.width // 8) self.buffer_4Gray = bytearray(self.height * self.width // 4) self.image1Gray = framebuf.FrameBuffer(self.buffer_1Gray, self.width, self.height, framebuf.MONO_HLSB) self.image4Gray = framebuf.FrameBuffer(self.buffer_4Gray, self.width, self.height, framebuf.GS2_HMSB) self.EPD_4IN2_Init_4Gray() self.EPD_4IN2_Clear() utime.sleep_ms(500)
def display_window(self, fb_black, fb_yellow, x, y, w, h): progress = ('|', '\\', '-', '/') fbb = framebuf.FrameBuffer(fb_black, EPD_WIDTH, EPD_HEIGHT, framebuf.MONO_HLSB) fby = framebuf.FrameBuffer(fb_yellow, EPD_WIDTH, EPD_HEIGHT, framebuf.MONO_HLSB) # Draw black frame buffer part for i in reversed(range(15)): pygame.display.set_caption( 'EPD {} x {} - REDRAWING BLACK ({})'.format( self.width, self.height, progress[i % len(progress)])) color = ((i * 8, i * 8, i * 8), (255 - i * 8, 255 - i * 8, 255 - i * 8), (0, 0, 0)) a = i % 2 for yy in range(EPD_HEIGHT): for xx in range(EPD_WIDTH): if (xx >= x) and (yy >= y) and (xx < x + w) and (yy < y + h): self._draw_pixel( xx, yy, color[fbb.pixel(xx, yy) * fby.pixel(xx, yy) + a]) pygame.display.flip() self._clock.tick(4 if i > 7 else 2) # Draw yellow frame buffer part for i in reversed(range(1, 16)): pygame.display.set_caption( 'EPD {} x {} - REDRAWING YELLOW ({})'.format( self.width, self.height, progress[i % len(progress)])) a = i % 2 color = ((i * 8, i * 8, i * 8), (255 - i * 8, 255 - i * 8, 0)) for yy in range(EPD_HEIGHT): for xx in range(EPD_WIDTH): c = fby.pixel(xx, yy) if not c and (xx >= x) and (yy >= y) and (xx < x + w) and ( yy < y + h): self._draw_pixel(xx, yy, color[a]) pygame.display.flip() self._clock.tick(4 if i > 7 else 2) pygame.display.set_caption('EPD {} x {}'.format( self.width, self.height))
def __init__(self, width, height, external_vcc): self.width = width self.height = height self.external_vcc = external_vcc self.pages = self.height // 8 self.buffer = bytearray(self.pages * self.width) self.framebuf = framebuf.FrameBuffer(self.buffer, self.width, self.height, framebuf.MVLSB) self.init_display()
def __init__(self, color, epd): print("\tFB%d - [ OK ]" % color) self.buf = bytearray((epd.width * epd.height + 7) // 8) self.canvas = framebuf.FrameBuffer(self.buf, epd.width, epd.height, framebuf.MONO_HLSB) self.epd = epd self._bit = 1 if color == YELLOW else 0
def draw(): buffer = bytearray( b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xe0\x10\x8a\n0\x10$\xc8\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00x\xfe\xff?\xfe\xfd|\xfb\xf8\xfc\xff|\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\xc0@\xe0\xe0\xe0\xc0\xc1c\x9f\xff\x0f\xce\xff\xff\xcf\xe3\xf0pp\xa0\xe0\xe0\xc0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xf0\xff\xfb\xe7\xdf\x8e\x9e\xfd\x95"$%\x00\xfe\xff\xff\xed\xdd\xce\xce\xff\xe7\xe7\xf7\xfb\xf9\xfep\xe0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00@6\x9bg7\xcfo\x9d\xdb?\xbbws\xf7\xfa\xfa\xf9\xf4\xfd\xf7\xf3\xf1\xfdsy\xbd;\xd9\x9do\xcc6g\x9b6@\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x02\x01\x04\x03\t\x06\x13\x0c&\x19\r\x1b\x1b\r\x19&\x0c\x13\x06\t\x03\x04\x01\x02\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' ) fb = framebuf.FrameBuffer(buffer, 48, 48, framebuf.MVLSB) display.fill(0) display.framebuf.blit(fb, 8, 0) display.show()
def __init__(self, width, height, external_vcc): self.width = width self.height = height self.external_vcc = external_vcc self.buffer = bytearray(self.width * self.height // 2) self.framebuf = framebuf.FrameBuffer(self.buffer, self.width, self.height, framebuf.GS4_HMSB) self.poweron() self.init_display()
def __init__(self): # setup I2C self._i2c = I2C(scl=Pin('X9'), sda=Pin('X10')) # setup buffer self._fbuf = framebuf.FrameBuffer(bytearray(64 * 32 // 8), 64, 32, framebuf.MONO_HLSB)