build(boards): micropython板卡执行 npm run build:prod

This commit is contained in:
王立帮
2025-05-30 00:41:34 +08:00
parent e4b3c3be5b
commit 382d158b88
156 changed files with 1146 additions and 582 deletions

View File

@@ -16,6 +16,7 @@ _CI_ID_NUM = const(0x06)
_CI_ID_CLE = const(0x07)
_CI_ID_PACTRL = const(0x09)
_CI_ID_END = const(0x5A)
_TIME_SNUM = const(0x75)
class CI130X:
def __init__(self, i2c_bus, addr=_CI_ADDRESS):
@@ -65,7 +66,7 @@ class CI130X:
"""播放命令词对应ID语音"""
self._wreg(bytes([_CI_ID_SET, value, 0, _CI_ID_END]))
while blocking:
time.sleep_ms(10)
time.sleep_ms(15)
if not self.status()[1]:
break
@@ -89,6 +90,31 @@ class CI130X:
self.play_id(end)
time.sleep_ms(delay)
def play_time(self, times=None, detail=True, delay=10):
"""播报时间"""
data = time.localtime() if times is None else times
if detail:
for i in range(0, 3): #年 月 日
self.play_num(data[i])
time.sleep_ms(delay)
self.play_id(_TIME_SNUM + i)
time.sleep_ms(delay)
for i in range(3, 5): #时 分
self.play_num(data[i])
time.sleep_ms(delay)
self.play_id(_TIME_SNUM + i)
time.sleep_ms(delay)
if detail:
self.play_num(data[5]) #秒
time.sleep_ms(delay)
self.play_id(_TIME_SNUM + 5)
time.sleep_ms(delay)
self.play_id(_TIME_SNUM + 6) #星期
time.sleep_ms(delay)
self.play_num(data[6] + 1)
def pa_ctrl(self, value=True, delay=10):
self._wreg(bytes([_CI_ID_PACTRL, int(value), 0, _CI_ID_END]))
if value: time.sleep_ms(delay)

View File

@@ -0,0 +1,49 @@
"""
Simple Keypad
Micropython library for the Simple Keypad
=======================================================
#Based on Author: 'Teeraphat Kullanankanjana'
@dahanzimin From the Mixly Team
"""
from machine import Pin
from time import sleep
class Keypad:
def __init__(self, row_pins, column_pins, keys):
"""Initialize the keypad object."""
if not all(isinstance(pin, Pin) for pin in row_pins):
raise ValueError("Row pins must be instances of Pin.")
if not all(isinstance(pin, Pin) for pin in column_pins):
raise ValueError("Column pins must be instances of Pin.")
if not isinstance(keys, list) or not all(isinstance(row, list) for row in keys):
raise ValueError("Keys must be a 2D list.")
self.row_pins = row_pins
self.column_pins = column_pins
self.keys = keys
for pin in self.row_pins:
pin.init(Pin.IN, Pin.PULL_UP)
for pin in self.column_pins:
pin.init(Pin.OUT)
if len(self.row_pins) > len(self.keys) or len(self.column_pins) > len(self.keys[0]):
raise ValueError("Number of row/column pins does not match the key layout size.")
def read_keypad(self):
"""Read the keypad and return the pressed key."""
for col_pin in self.column_pins:
col_pin.value(0)
for i, row_pin in enumerate(self.row_pins):
if not row_pin.value():
key_pressed = self.keys[i][self.column_pins.index(col_pin)]
col_pin.value(1)
return key_pressed
col_pin.value(1)
return None

View File

@@ -225,7 +225,7 @@
"micropython"
],
"__file__": true,
"__size__": 2770,
"__size__": 3484,
"__name__": "ci130x.py"
},
"debugnet": {
@@ -371,6 +371,15 @@
"__size__": 7002,
"__name__": "irremote.py"
},
"keypad": {
"__require__": [
"machine",
"time"
],
"__file__": true,
"__size__": 1725,
"__name__": "keypad.py"
},
"ltr308al": {
"__require__": [
"time",
@@ -607,7 +616,7 @@
"json"
],
"__file__": true,
"__size__": 3356,
"__size__": 3477,
"__name__": "ollama.py"
},
"onenet": {
@@ -905,7 +914,7 @@
"framebuf"
],
"__file__": true,
"__size__": 21298,
"__size__": 21078,
"__name__": "uframebuf.py"
},
"umqtt": {

View File

@@ -12,6 +12,7 @@ class Ollama():
"Content-Type": "application/json"
}
self._url = url
self._chat_url = "{}/api/chat".format(self._url)
self._max_retries = 1
self._max_history_num = max_history_num
self._timeout = 10000
@@ -30,6 +31,7 @@ class Ollama():
def set_custom_url(self, url):
self._url = url
self._chat_url = "{}/api/chat".format(self._url)
def select_model(self, model_name):
self._data["model"] = model_name
@@ -57,7 +59,7 @@ class Ollama():
data = json.dumps(self._data).encode('utf-8')
for i in range(0, self._max_retries):
response = urequests.post(
self._url, headers=self._heads, data=data)
self._chat_url, headers=self._heads, data=data)
if response.status_code == 200:
break
time.sleep(1)

View File

@@ -161,66 +161,33 @@ class FrameBuffer_Base(FrameBuffer):
self.width = width
self.height = height
self._buffer = buf
self.auto_show = True
def __getitem__(self, key):
x, y = key
return self.pixel(x, y)
def __setitem__(self, key, value):
x, y = key
self.pixel(x, y, value)
def show(self):
print("External inheritance is required to override this method")
def shift(self, x, y, rotate=False):
def write(self):
self.show()
def shift(self, x, y, sync=True):
"""Shift pixels by x and y"""
if x > 0: # Shift Right
for _ in range(x):
for row in range(0, self.height):
last_pixel = self[self.width - 1, row] if rotate else 0
for col in range(self.width - 1, 0, -1):
self[col, row] = self[col - 1, row]
self[0, row] = last_pixel
elif x < 0: # Shift Left
for _ in range(-x):
for row in range(0, self.height):
last_pixel = self[0, row] if rotate else 0
for col in range(0, self.width - 1):
self[col, row] = self[col + 1, row]
self[self.width - 1, row] = last_pixel
if y > 0: # Shift Up
for _ in range(y):
for col in range(0, self.width):
last_pixel = self[col, self.height - 1] if rotate else 0
for row in range(self.height - 1, 0, -1):
self[col, row] = self[col, row - 1]
self[col, 0] = last_pixel
elif y < 0: # Shift Down
for _ in range(-y):
for col in range(0, self.width):
last_pixel = self[col, 0] if rotate else 0
for row in range(0, self.height - 1):
self[col, row] = self[col, row + 1]
self[col, self.height - 1] = last_pixel
if self.auto_show: self.show()
super().scroll(x, y)
if sync: self.show()
def shift_right(self, num, rotate=False):
def shift_right(self, num, sync=True):
"""Shift all pixels right"""
self.shift(num, 0, rotate)
self.shift(num, 0, sync)
def shift_left(self, num, rotate=False):
def shift_left(self, num, sync=True):
"""Shift all pixels left"""
self.shift(-num, 0, rotate)
self.shift(-num, 0, sync)
def shift_up(self, num, rotate=False):
def shift_up(self, num, sync=True):
"""Shift all pixels up"""
self.shift(0, -num, rotate)
self.shift(0, -num, sync)
def shift_down(self, num, rotate=False):
def shift_down(self, num, sync=True):
"""Shift all pixels down"""
self.shift(0, num, rotate)
self.shift(0, num, sync)
def map_invert(self, own):
"""Graph invert operation"""
@@ -252,21 +219,57 @@ class FrameBuffer_Base(FrameBuffer):
else:
raise ValueError("This graphic operation is not supported")
def set_buffer(self, buffer):
def set_buffer(self, buffer, sync=True):
for i in range(min(len(buffer),len(self._buffer))):
self._buffer[i] = self._buffer[i] | buffer[i]
if sync: self.show()
def get_buffer(self):
return self._buffer
def pointern(self, x=None, y=None, l=None, angle=0, color=0xffff, bg_color=0x0):
def pointern(self, x=None, y=None, l=None, angle=0, color=0xffff, bg_color=0x0, sync=True):
x = self.width // 2 if x is None else x
y = self.height // 2 if y is None else y
l = min(self.height // 2 , self.width // 2) if l is None else l
radian = math.radians(angle)
if self.auto_show: self.fill(bg_color)
self.line(x, y, round(x + l * math.sin(radian)), round(y - l * math.cos(radian)), color)
if self.auto_show: self.show()
if sync: super().fill(bg_color)
super().line(x, y, round(x + l * math.sin(radian)), round(y - l * math.cos(radian)), color)
if sync: self.show()
def pixel(self, x, y, color=None, sync=True):
if color is None:
return super().pixel(x, y)
else:
super().pixel(x, y, color)
if sync: self.show()
def vline(self, x, y, h, c, sync=True):
super().vline(x, y, h, c)
if sync: self.show()
def hline(self, x, y, w, c, sync=True):
super().hline(x, y, w, c)
if sync: self.show()
def line(self, x1, y1, x2, y2, c, sync=True):
super().line(x1, y1, x2, y2, c)
if sync: self.show()
def rect(self, x, y, w, h, c, sync=True):
super().rect(x, y, w, h, c)
if sync: self.show()
def fill_rect(self, x, y, w, h, c, sync=True):
super().fill_rect(x, y, w, h, c)
if sync: self.show()
def ellipse(self, x, y, xr, yr, c, f=False, sync=True):
super().ellipse(x, y, xr, yr, c, f)
if sync: self.show()
def fill(self, c, sync=True):
super().fill(c)
if sync: self.show()
class FrameBuffer_Ascall(FrameBuffer_Base):
'''FrameBuffer for Ascall'''
@@ -282,22 +285,21 @@ class FrameBuffer_Ascall(FrameBuffer_Base):
for char_x in range(width):
for char_y in range(height):
if (buffer_info[char_x] >> char_y) & 0x1:
self.pixel(x + char_x, y + char_y, 1) if height <= self.height else self.pixel(y + char_y, self.height-(x + char_x), 1)
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 shows(self, data, space=0, center=True):
def shows(self, data, space=0, center=True, sync=True):
"""Display character"""
if data is not None:
self.fill(0)
self.fill(0, sync=False)
if type(data) in [list, bytes, tuple, bytearray]:
self.set_buffer(data)
if self.auto_show: self.show()
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 self.auto_show: self.show()
x = self._font.font_width + x + space
if sync: self.show()
def frame(self, data, delay=500):
"""Display one frame per character"""
@@ -305,15 +307,14 @@ class FrameBuffer_Ascall(FrameBuffer_Base):
if type(data) in [list,tuple]:
for dat in data:
if type(dat) in [list,bytes,tuple,bytearray]:
self.fill(0)
self.set_buffer(dat)
self.show()
self.fill(0, sync=False)
self.set_buffer(data, True)
time.sleep_ms(delay)
else:
data=str(data)
x=(self.width - self._font.font_width) // 2
for char in data:
self.fill(0)
self.fill(0, sync=False)
self.bitmap(self._font.chardata(char), x)
self.show()
time.sleep_ms(delay)
@@ -325,7 +326,7 @@ class FrameBuffer_Ascall(FrameBuffer_Base):
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)
self.fill(0, sync=False)
for char in data:
self.bitmap(self._font.chardata(char),x)
x = self._font.font_width + x + space
@@ -334,11 +335,11 @@ class FrameBuffer_Ascall(FrameBuffer_Base):
class FrameBuffer_Uincode(FrameBuffer_Base):
'''FrameBuffer for Uincode'''
def font(self, font_address):
def font(self, font_address=0x700000):
"""Font selection or externally defined font code"""
self._font = Font_Uincode(font_address)
def image(self, path, x=None, y=None, size=None, invert=0, color=0xffff):
def image(self, path, x=None, y=None, size=None, invert=0, color=0xffff, bold=0, sync=True):
"""Set buffer to value of Python Imaging Library image"""
if type(path) is str :
buffer_info, (width, height) = Image().load(path, invert)
@@ -352,11 +353,11 @@ class FrameBuffer_Uincode(FrameBuffer_Base):
size = max(round(size), 1)
x =(self.width - width * size) // 2 if x is None else x
y =(self.height - height * size) // 2 if y is None else y
if self.auto_show: self.fill_rect(x, y, width * size, height * size, 0)
self.bitmap((buffer_info,(width, height)), x, y, size, color)
if self.auto_show: self.show()
if sync: self.fill_rect(x, y, width * size, height * size, 0, sync=False)
self.bitmap((buffer_info,(width, height)), x, y, size, bold, color)
if sync: self.show()
def bitmap(self, buffer, x=0, y=0, size=1, color=0xffff):
def bitmap(self, buffer, x=0, y=0, size=1, bold=0, color=0xffff):
"""Graphic model display(buffer,(width,height))"""
buffer_info,(width,height)=buffer
if x < -width*size or x >= self.width or y < -height*size or y >= self.height:
@@ -365,7 +366,7 @@ class FrameBuffer_Uincode(FrameBuffer_Base):
for j in range(height):
for i in range(width):
if buffer_info[j * bytewidth + i // 8] & (0x80 >> (i & 7)):
self.fill_rect(x + i * size, y + j * size, size, size, color)
self.fill_rect(x + i * size, y + j * size, int(size + bold), int(size + bold), color, sync=False)
def _take_buffer(self, strs, space, size=1):
'''Get character lattice information first'''
@@ -377,13 +378,12 @@ class FrameBuffer_Uincode(FrameBuffer_Base):
font_len = font_len + buffer[1][0] * size + space
return font_len, font_buffer
def shows(self, data, space=0, center=True, x=0, y=None, size=None, color=0xffff, bg_color=0x0):
def shows(self, data, space=0, center=True, x=0, y=None, size=None, color=0xffff, bold=0, bg_color=0x0, sync=True):
"""Display character"""
if data is not None:
if type(data) in [list, bytes, tuple, bytearray]:
if self.auto_show: self.fill(bg_color)
self.set_buffer(data)
if self.auto_show: self.show()
if sync: self.fill(bg_color, sync=False)
self.set_buffer(data, sync)
else:
yy = y
if size is None:
@@ -393,20 +393,20 @@ class FrameBuffer_Uincode(FrameBuffer_Base):
font_len, font_buffer = self._take_buffer(str(data), space, size)
x = (self.width - font_len + space) // 2 if center else x
y = (self.height - self._font.height * size) // 2 if y is None else y
if self.auto_show:
if sync:
if yy is None:
self.fill(bg_color)
self.fill(bg_color, sync=False)
else:
self.fill_rect(x - 1, y - 1, font_len + 2, font_buffer[0][1][1] * size + 2, bg_color)
self.fill_rect(x - 1, y - 1, font_len + 2, font_buffer[0][1][1] * size + 2, bg_color, sync=False)
for buffer in font_buffer: #Display character
self.bitmap(buffer, x, y, size, color)
self.bitmap(buffer, x, y, size, bold, color)
x = buffer[1][0] * size + x + space
if self.auto_show: self.show()
if sync: self.show()
def texts(self, data, space_x=0, space_y=1, x=0, y=0, size=1, color=0xffff, bg_color=0x0):
def texts(self, data, space_x=0, space_y=1, x=0, y=0, size=1, color=0xffff, bold=0, bg_color=0x0, sync=True):
size = max(round(size), 1)
lines = data.split('\n')
if self.auto_show: self.fill(bg_color)
if sync: self.fill(bg_color, sync=False)
for line in lines:
for char in line:
buffer = self._font.chardata(char)
@@ -414,23 +414,22 @@ class FrameBuffer_Uincode(FrameBuffer_Base):
x = 0
y = buffer[1][1] * size + y + space_y
if y > self.height:
if self.auto_show: self.show()
if sync: self.show()
return None
self.bitmap(buffer, x, y, size, color)
self.bitmap(buffer, x, y, size, bold, color)
x = buffer[1][0] * size + x + space_x
x = 0
y = self._font.height * size + y + space_y
if self.auto_show: self.show()
if sync: self.show()
def frame(self, data, delay=500, size=None, color=0xffff, bg_color=0x0):
def frame(self, data, delay=500, size=None, color=0xffff, bold=0, bg_color=0x0):
"""Display one frame per character"""
if data is not None:
if type(data) in [list, tuple]:
for dat in data:
if type(dat) in [list, bytes, tuple, bytearray]:
if self.auto_show: self.fill(bg_color)
self.set_buffer(dat)
self.show()
self.fill(bg_color, sync=False)
self.set_buffer(data, True)
time.sleep_ms(delay)
else:
size = self.height // (self._font.height * 3) if size is None else size
@@ -439,12 +438,12 @@ class FrameBuffer_Uincode(FrameBuffer_Base):
for buffer in font_buffer:
x=(self.width - buffer[1][0] * size) // 2
y=(self.height - buffer[1][1] * size) // 2
if self.auto_show: self.fill(bg_color)
self.bitmap(buffer, x, y, size, color)
self.fill(bg_color, sync=False)
self.bitmap(buffer, x, y, size, bold, color)
self.show()
time.sleep_ms(delay)
def scroll(self, data, space=0, speed=20, y=None, size=None, step= None, color=0xffff, bg_color=0x0):
def scroll(self, data, space=0, speed=20, y=None, size=None, step= None, color=0xffff, bold=0, bg_color=0x0):
"""Scrolling characters"""
if data is not None:
size = self.height // (self._font.height * 3) if size is None else size
@@ -454,9 +453,9 @@ class FrameBuffer_Uincode(FrameBuffer_Base):
for i in range(0, font_len - space + self.width, step):
x = -i + self.width
y = (self.height - self._font.height * size) // 2 if y is None else y
if self.auto_show: self.fill_rect(x - 2 , y - 2 , self.width -x + 4, font_buffer[0][1][1] * size + 4, bg_color)
self.fill_rect(x - 2 , y - 2 , self.width -x + 4, font_buffer[0][1][1] * size + 4, bg_color, sync=False)
for buffer in font_buffer:
self.bitmap(buffer, x, y, size, color)
self.bitmap(buffer, x, y, size, bold, color)
x = buffer[1][0] * size + x + space
self.show()
time.sleep_ms(speed)