更新OLED+TFT显示器支持二维码生成显示

This commit is contained in:
dahanzimin
2025-10-21 20:15:52 +08:00
parent dd489566b9
commit 67ec10049a
2 changed files with 620 additions and 0 deletions

View File

@@ -163,6 +163,7 @@ class FrameBuffer_Base(FrameBuffer):
self._buffer = buf
self._way = 1
self._speed = 100
self._miniqr = None
def show(self):
print("External inheritance is required to override this method")
@@ -551,3 +552,20 @@ class FrameBuffer_Uincode(FrameBuffer_Base):
x = buffer[1][0] * size + x + space
self.show()
time.sleep_ms(speed)
def qrcode(self, data, x=0, y=0, size=None, bold=0, type=None, correct=0, color=0xffff, bg_color=0x0, sync=True):
if self._miniqr is None:
from adafruit_miniqr import QRCode
self._miniqr = QRCode
_qr = self._miniqr(qr_type=type, error_correct=correct)
_qr.add_data(data)
_qr.make()
if sync: self.fill(bg_color, sync=False)
size = min(self.height // _qr.matrix.height, self.width // _qr.matrix.width) if size is None else size
for j in range(_qr.matrix.height):
for i in range(_qr.matrix.width):
if _qr.matrix[i, j]:
self.fill_rect(x + i * size, y + j * size, int(size + bold), int(size + bold), color, sync=False)
del _qr
gc.collect()
if sync: self.show()