增加TVOC检测库,修复ASR声音采集
This commit is contained in:
39
boards/default_src/micropython/origin/build/lib/tvoc07s.py
Normal file
39
boards/default_src/micropython/origin/build/lib/tvoc07s.py
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
"""
|
||||||
|
TVOC
|
||||||
|
|
||||||
|
Micropython library for the TVOC(UART)
|
||||||
|
=======================================================
|
||||||
|
@dahanzimin From the Mixly Team
|
||||||
|
"""
|
||||||
|
import time
|
||||||
|
|
||||||
|
class TVOC:
|
||||||
|
def __init__(self, uart):
|
||||||
|
self._uart = uart
|
||||||
|
self._uart.init(baudrate=9600)
|
||||||
|
self._tvoc = (0, 0 ,0) #TVOC mg/m3, CH2O mg/m3, C02 ppm
|
||||||
|
self._flag = False
|
||||||
|
if not self._chip_id():
|
||||||
|
raise AttributeError("Cannot find a TOVC")
|
||||||
|
|
||||||
|
def _rreg(self):
|
||||||
|
'''Read data'''
|
||||||
|
if self._uart.any():
|
||||||
|
eec = 0
|
||||||
|
buf = self._uart.read(9)
|
||||||
|
for i in buf[:8]:
|
||||||
|
eec += i
|
||||||
|
if (eec & 0xFF) == buf[8] and buf[0] == 0x2C:
|
||||||
|
self._tvoc=((buf[2] << 8 | buf[3]) * 0.001, (buf[4] << 8 | buf[5]) * 0.001, buf[6] << 8 | buf[7] )
|
||||||
|
return True
|
||||||
|
|
||||||
|
def _chip_id(self):
|
||||||
|
for _ in range(5):
|
||||||
|
if self._rreg():
|
||||||
|
return True
|
||||||
|
time.sleep(1)
|
||||||
|
return False
|
||||||
|
|
||||||
|
def read(self):
|
||||||
|
self._rreg()
|
||||||
|
return self._tvoc
|
||||||
@@ -104,3 +104,7 @@ class AI:
|
|||||||
self._ai.delete(_id)
|
self._ai.delete(_id)
|
||||||
else:
|
else:
|
||||||
raise AttributeError('This model can only run face recognition')
|
raise AttributeError('This model can only run face recognition')
|
||||||
|
|
||||||
|
def stop(self):
|
||||||
|
if self._ai is not None:
|
||||||
|
self._ai.stop()
|
||||||
|
|||||||
@@ -156,9 +156,11 @@ class LED:
|
|||||||
onboard_led = LED(onboard_bot.led_pwm)
|
onboard_led = LED(onboard_bot.led_pwm)
|
||||||
|
|
||||||
class Voice_Energy:
|
class Voice_Energy:
|
||||||
def read(self):
|
def read(self, samples=10):
|
||||||
_dat = onboard_asr._rreg(0x08, 3) #在语音识别里获取
|
values = []
|
||||||
return (_dat[0] | _dat[1] << 8) // 10
|
for _ in range(samples):
|
||||||
|
values.append(int.from_bytes(onboard_asr._rreg(0x08, 3)[:2], 'little')) #在语音识别里获取
|
||||||
|
return sorted(values)[samples // 2]
|
||||||
|
|
||||||
onboard_sound = Voice_Energy()
|
onboard_sound = Voice_Energy()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user