更新MINI的PCM获取函数名称

This commit is contained in:
dahanzimin
2025-07-12 10:24:04 +08:00
parent 65aff62c17
commit b7b2cf33b3

View File

@@ -348,12 +348,13 @@ class BOT035(FrameBuffer):
print("Warning: Please upgrade the coprocessor firmware to use this feature")
def mic_pga(self, value=None):
'''0:4x, 1:8x, 2:16x, 3:32x, 4:OFF'''
if value is None:
return self._rreg(_BOT035_FLAG) >> 4
else:
self._wreg(_BOT035_FLAG, (self._rreg(_BOT035_FLAG) & 0x0F) | (value & 0x03) << 4)
def pcm_power(self, power=None):
def pcm_en(self, power=None):
if self._version >= 3:
if power is None:
return bool(self._rreg(_BOT035_STA) & 0x08)
@@ -362,28 +363,28 @@ class BOT035(FrameBuffer):
else:
print("Warning: Please upgrade the coprocessor firmware to use this feature")
def pcm_state(self, power=None):
def pcm_any(self):
return bool(self._rreg(_BOT035_STA) & 0x80)
def pcm_data(self, ibuf=1600):
def pcm_read(self, ibuf=1600):
return self._rreg(_BOT035_PCM, ibuf)
def pcm_record(self, path='mixly.wav', seconds=5, ibuf=1600, timeout=2000):
if self._version >= 3:
self.pcm_power(True)
self.pcm_en(True)
_star = time.ticks_ms()
_size = int(ibuf * seconds * 10)
_header = b'RIFF' + (36 + _size).to_bytes(4, 'little') + b'WAVEfmt \x10\x00\x00\x00\x01\x00\x01\x00' + (ibuf * 5).to_bytes(4, 'little') + (ibuf * 10).to_bytes(4, 'little') + b'\x02\x00\x10\x00data' + _size.to_bytes(4, 'little')
with open(path, 'wb') as f:
f.write(_header)
while _size > 0:
if self.pcm_state():
f.write(self.pcm_data(ibuf))
if self.pcm_any():
f.write(self.pcm_read(ibuf))
_size -= ibuf
_star = time.ticks_ms()
if time.ticks_diff(time.ticks_ms(), _star) > timeout:
raise OSError("Timeout write error")
self.pcm_power(False)
self.pcm_en(False)
else:
print("Warning: Please upgrade the coprocessor firmware to use this feature")