build(boards): micropython板卡执行 npm run build:prod
This commit is contained in:
Binary file not shown.
BIN
boards/default/micropython_esp32s3/build/Mixgo_Sant-v1.13.0.bin
Normal file
BIN
boards/default/micropython_esp32s3/build/Mixgo_Sant-v1.13.0.bin
Normal file
Binary file not shown.
Binary file not shown.
106
boards/default/micropython_esp32s3/build/lib/ai_camera.py
Normal file
106
boards/default/micropython_esp32s3/build/lib/ai_camera.py
Normal file
@@ -0,0 +1,106 @@
|
||||
"""
|
||||
AI-Camera (Inherit C module)
|
||||
|
||||
MicroPython library for the AI-Camera(Inherit C module)
|
||||
=======================================================
|
||||
@dahanzimin From the Mixly Team
|
||||
"""
|
||||
|
||||
import esp_ai
|
||||
from micropython import const
|
||||
|
||||
CODE_DETECTION = const(0)
|
||||
COLOR_DETECTION = const(1)
|
||||
MOTION_DEECTION = const(2)
|
||||
CAT_FACE_DETECTION = const(3)
|
||||
FACE_DETECTION = const(4)
|
||||
FACE_RECOGNITION = const(5)
|
||||
|
||||
class AI:
|
||||
def __init__(self, function):
|
||||
self._func = function
|
||||
self._ai = None
|
||||
self._once = True
|
||||
|
||||
def _init(self, *args):
|
||||
if self._func == CODE_DETECTION:
|
||||
self._ai = esp_ai.code_recognition()
|
||||
elif self._func == COLOR_DETECTION:
|
||||
self._ai = esp_ai.color_detection(color=args[0])
|
||||
elif self._func == MOTION_DEECTION:
|
||||
self._ai = esp_ai.motion_recognition(threshold=args[0])
|
||||
elif self._func == CAT_FACE_DETECTION:
|
||||
self._ai = esp_ai.cat_detection()
|
||||
elif self._func == FACE_DETECTION:
|
||||
self._ai = esp_ai.face_detection()
|
||||
elif self._func == FACE_RECOGNITION:
|
||||
self._ai = esp_ai.face_recognition()
|
||||
else:
|
||||
raise AttributeError('AI model is not supported')
|
||||
self._ai.start() #启动检测,可以通过LCD观察结果
|
||||
self._once = False
|
||||
|
||||
def _result(self, res, _t, _s=0, _n=0): #_s:第几个, _n:细分第几个
|
||||
if not res: return None
|
||||
if _t == 'len':
|
||||
return res[0]
|
||||
elif _t == 'pos':
|
||||
if len(res) >= (5 + _s * 4):
|
||||
return res[(1 + _s * 4):(5 + _s * 4)]
|
||||
elif _t == 'keypoint':
|
||||
if len(res) >= (7 + _s * 14 + _n * 2):
|
||||
return res[(5 + _s * 14 + _n * 2):(7 + _s * 14 + _n * 2)]
|
||||
|
||||
def code_recognition(self):
|
||||
if self._func == CODE_DETECTION:
|
||||
if self._once: self._init()
|
||||
return self._ai.read()
|
||||
else:
|
||||
raise AttributeError('This model can only run QR code detection')
|
||||
|
||||
def color_detection(self, color=0, event='pos', num=0):
|
||||
if self._func == COLOR_DETECTION:
|
||||
if self._once: self._init(color)
|
||||
return self._result(self._ai.read(), event, num)
|
||||
else:
|
||||
raise AttributeError('This model can only run color detection')
|
||||
|
||||
def motion_recognition(self, threshold=50):
|
||||
if self._func == MOTION_DEECTION:
|
||||
if self._once: self._init(threshold)
|
||||
return self._ai.read()
|
||||
else:
|
||||
raise AttributeError('This model can only run motion recognition')
|
||||
|
||||
def cat_detection(self, event='pos', num=0):
|
||||
if self._func == CAT_FACE_DETECTION:
|
||||
if self._once: self._init()
|
||||
return self._result(self._ai.read(), event, num)
|
||||
else:
|
||||
raise AttributeError('This model can only run cat face detection')
|
||||
|
||||
def face_detection(self, event='pos', num=0, point=0):
|
||||
if self._func == FACE_DETECTION:
|
||||
if self._once: self._init()
|
||||
return self._result(self._ai.read(), event, num, point)
|
||||
else:
|
||||
raise AttributeError('This model can only run face detection')
|
||||
|
||||
def face_recognition(self, event='pos', num=0, point=0):
|
||||
if self._func == FACE_RECOGNITION:
|
||||
if self._once: self._init()
|
||||
return self._result(self._ai.recognize(), event, num, point)
|
||||
else:
|
||||
raise AttributeError('This model can only run face recognition')
|
||||
|
||||
def face_enroll(self):
|
||||
if self._func == FACE_RECOGNITION:
|
||||
return self._ai.enroll()
|
||||
else:
|
||||
raise AttributeError('This model can only run face recognition')
|
||||
|
||||
def face_delete(self, _id):
|
||||
if self._func == FACE_RECOGNITION:
|
||||
self._ai.delete(_id)
|
||||
else:
|
||||
raise AttributeError('This model can only run face recognition')
|
||||
34
boards/default/micropython_esp32s3/build/lib/camera.py
Normal file
34
boards/default/micropython_esp32s3/build/lib/camera.py
Normal file
@@ -0,0 +1,34 @@
|
||||
"""
|
||||
Camera GC032A/FrameBuffer(Inherit C module)
|
||||
|
||||
MicroPython library for the GC032A(Inherit C module)
|
||||
=======================================================
|
||||
@dahanzimin From the Mixly Team
|
||||
"""
|
||||
|
||||
import time
|
||||
from sensor import *
|
||||
from machine import SoftI2C, Pin
|
||||
from mixgo_sant import onboard_bot
|
||||
|
||||
class GC032A(Camera):
|
||||
def __init__(self, framesize=LCD, hmirror=None):
|
||||
onboard_bot.cam_en(1, 500)
|
||||
super().__init__()
|
||||
super().set_framesize(framesize)
|
||||
time.sleep_ms(100)
|
||||
if hmirror is not None:
|
||||
super().set_hmirror(hmirror)
|
||||
time.sleep_ms(100)
|
||||
SoftI2C(scl=Pin(47), sda=Pin(48), freq=400000)
|
||||
SoftI2C(scl=Pin(47), sda=Pin(38), freq=400000)
|
||||
|
||||
def deinit(self):
|
||||
super().deinit()
|
||||
onboard_bot.cam_en(0, 100)
|
||||
|
||||
def display(self, show=True):
|
||||
if show:
|
||||
super().display()
|
||||
else:
|
||||
super().display_stop()
|
||||
31
boards/default/micropython_esp32s3/build/lib/ci1302x.py
Normal file
31
boards/default/micropython_esp32s3/build/lib/ci1302x.py
Normal file
@@ -0,0 +1,31 @@
|
||||
"""
|
||||
CI1302(继承ci130x)
|
||||
|
||||
MicroPython library for the CI130Xx (ASR-I2C)
|
||||
=======================================================
|
||||
@dahanzimin From the Mixly Team
|
||||
"""
|
||||
from ci130x import CI130X
|
||||
|
||||
class CI1302(CI130X):
|
||||
def __init__(self, i2c_bus, func, addr=0x64):
|
||||
self._device = i2c_bus
|
||||
self._address = addr
|
||||
self._cmd_id = None
|
||||
self._func = func
|
||||
|
||||
def _wreg(self, reg):
|
||||
'''Write memory address'''
|
||||
try:
|
||||
self._device.writeto(self._address, reg)
|
||||
except:
|
||||
self._func(1, 700) #Power on
|
||||
self._device.writeto(self._address, reg)
|
||||
|
||||
def _rreg(self, reg, nbytes=1):
|
||||
'''Read memory address'''
|
||||
try:
|
||||
return self._device.readfrom_mem(self._address, reg, nbytes)
|
||||
except:
|
||||
self._func(1, 700) #Power on
|
||||
return self._device.readfrom_mem(self._address, reg, nbytes)
|
||||
@@ -1,4 +1,32 @@
|
||||
{
|
||||
"ai_camera": {
|
||||
"__require__": [
|
||||
"esp_ai",
|
||||
"micropython"
|
||||
],
|
||||
"__file__": true,
|
||||
"__size__": 3981,
|
||||
"__name__": "ai_camera.py"
|
||||
},
|
||||
"camera": {
|
||||
"__require__": [
|
||||
"time",
|
||||
"sensor",
|
||||
"machine",
|
||||
"mixgo_sant"
|
||||
],
|
||||
"__file__": true,
|
||||
"__size__": 964,
|
||||
"__name__": "camera.py"
|
||||
},
|
||||
"ci1302x": {
|
||||
"__require__": [
|
||||
"ci130x"
|
||||
],
|
||||
"__file__": true,
|
||||
"__size__": 811,
|
||||
"__name__": "ci1302x.py"
|
||||
},
|
||||
"es8374": {
|
||||
"__require__": [
|
||||
"time",
|
||||
@@ -52,18 +80,17 @@
|
||||
"gc",
|
||||
"st7789_cf",
|
||||
"math",
|
||||
"ws2812",
|
||||
"music",
|
||||
"ws2812x",
|
||||
"musicx",
|
||||
"sant_bot",
|
||||
"sc7a20",
|
||||
"mk_pb4023",
|
||||
"ltr553als",
|
||||
"shtc3",
|
||||
"mmc5603",
|
||||
"spl06_001",
|
||||
"ci130x"
|
||||
"ci1302x"
|
||||
],
|
||||
"__file__": true,
|
||||
"__size__": 6782,
|
||||
"__size__": 6354,
|
||||
"__name__": "mixgo_sant.py"
|
||||
},
|
||||
"mixgo_zero": {
|
||||
@@ -102,6 +129,15 @@
|
||||
"__size__": 3173,
|
||||
"__name__": "mixgo_zero_voice.py"
|
||||
},
|
||||
"musicx": {
|
||||
"__require__": [
|
||||
"time",
|
||||
"machine"
|
||||
],
|
||||
"__file__": true,
|
||||
"__size__": 6992,
|
||||
"__name__": "musicx.py"
|
||||
},
|
||||
"music_spk": {
|
||||
"__require__": [
|
||||
"time",
|
||||
@@ -127,7 +163,7 @@
|
||||
"micropython"
|
||||
],
|
||||
"__file__": true,
|
||||
"__size__": 3783,
|
||||
"__size__": 5065,
|
||||
"__name__": "sant_bot.py"
|
||||
},
|
||||
"sant_g2": {
|
||||
@@ -141,6 +177,17 @@
|
||||
"__size__": 729,
|
||||
"__name__": "sant_g2.py"
|
||||
},
|
||||
"sant_gx": {
|
||||
"__require__": [
|
||||
"gc",
|
||||
"machine",
|
||||
"rc522",
|
||||
"cbr817"
|
||||
],
|
||||
"__file__": true,
|
||||
"__size__": 731,
|
||||
"__name__": "sant_gx.py"
|
||||
},
|
||||
"sdcard": {
|
||||
"__require__": [
|
||||
"time",
|
||||
@@ -166,11 +213,18 @@
|
||||
"__require__": [
|
||||
"time",
|
||||
"uframebuf",
|
||||
"machine",
|
||||
"micropython"
|
||||
"tftlcd"
|
||||
],
|
||||
"__file__": true,
|
||||
"__size__": 2825,
|
||||
"__size__": 1518,
|
||||
"__name__": "st7789_cf.py"
|
||||
},
|
||||
"ws2812x": {
|
||||
"__require__": [
|
||||
"time"
|
||||
],
|
||||
"__file__": true,
|
||||
"__size__": 1617,
|
||||
"__name__": "ws2812x.py"
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
"""
|
||||
mixgo_sant Onboard resources
|
||||
mixgo_sant Onboard resources(v1.9)
|
||||
|
||||
Micropython library for the mixgo_sant Onboard resources
|
||||
=======================================================
|
||||
@@ -13,93 +13,83 @@ import time, gc, st7789_cf, math
|
||||
rtc_clock = RTC()
|
||||
|
||||
'''I2C-onboard'''
|
||||
#onboard_i2c = I2C(0)
|
||||
onboard_i2c = SoftI2C(scl=Pin(47), sda=Pin(48), freq=400000)
|
||||
#inboard_i2c = I2C(0)
|
||||
inboard_i2c = SoftI2C(scl=Pin(47), sda=Pin(48), freq=400000)
|
||||
onboard_i2c = SoftI2C(scl=Pin(47), sda=Pin(38), freq=400000)
|
||||
|
||||
'''BOT035-Sensor'''
|
||||
try :
|
||||
import sant_bot
|
||||
onboard_bot = sant_bot.BOT035(onboard_i2c)
|
||||
onboard_bot = sant_bot.BOT035(inboard_i2c)
|
||||
except Exception as e:
|
||||
print("Warning: Failed to communicate with BOT035 (Coprocessor) or",e)
|
||||
|
||||
'''SPI-onboard'''
|
||||
onboard_spi = SPI(1, baudrate=80000000, polarity=1, phase=1)
|
||||
|
||||
onboard_bot.tft_reset(0)
|
||||
time.sleep_ms(50)
|
||||
onboard_bot.tft_reset(1)
|
||||
time.sleep_ms(150)
|
||||
|
||||
'''SPI-onboard'''
|
||||
onboard_spi = SPI(1, baudrate=80000000, polarity=1, phase=1)
|
||||
|
||||
'''TFT/240*240'''
|
||||
onboard_tft = st7789_cf.ST7789(onboard_spi, 240, 240, dc_pin=40, backlight=onboard_bot.tft_brightness, font_address=0xE00000)
|
||||
onboard_tft = st7789_cf.ST7789(reset=onboard_bot.tft_reset, backlight=onboard_bot.tft_brightness, font_address=0xE00000)
|
||||
|
||||
'''ACC-Sensor'''
|
||||
try :
|
||||
import sc7a20
|
||||
onboard_acc = sc7a20.SC7A20(onboard_i2c)
|
||||
onboard_acc = sc7a20.SC7A20(inboard_i2c)
|
||||
except Exception as e:
|
||||
print("Warning: Failed to communicate with SC7A20H (ACC) or",e)
|
||||
|
||||
'''ALS_PS_CS-Sensor'''
|
||||
'''ALS_PS-Sensor *2'''
|
||||
try :
|
||||
import mk_pb4023
|
||||
onboard_als = mk_pb4023.MK_PB4023(onboard_i2c)
|
||||
import ltr553als
|
||||
onboard_als_l = ltr553als.LTR_553ALS(onboard_i2c)
|
||||
except Exception as e:
|
||||
print("Warning: Failed to communicate with MK_PB4023 (ALS&PS&CS) or",e)
|
||||
print("Warning: Failed to communicate with TR_553ALS-L (ALS&PS) or",e)
|
||||
|
||||
try :
|
||||
#import ltr553als
|
||||
onboard_als_r = ltr553als.LTR_553ALS(inboard_i2c)
|
||||
except Exception as e:
|
||||
print("Warning: Failed to communicate with TR_553ALS-R (ALS&PS) or",e)
|
||||
|
||||
'''THS-Sensor'''
|
||||
try :
|
||||
import shtc3
|
||||
onboard_ths = shtc3.SHTC3(onboard_i2c)
|
||||
onboard_ths = shtc3.SHTC3(inboard_i2c)
|
||||
except Exception as e:
|
||||
print("Warning: Failed to communicate with GXHTC3 (THS) or",e)
|
||||
|
||||
'''MGS-Sensor'''
|
||||
try :
|
||||
import mmc5603
|
||||
onboard_mgs = mmc5603.MMC5603(onboard_i2c)
|
||||
onboard_mgs = mmc5603.MMC5603(inboard_i2c)
|
||||
except Exception as e:
|
||||
print("Warning: Failed to communicate with MMC5603 (MGS) or",e)
|
||||
|
||||
'''BPS-Sensor'''
|
||||
try :
|
||||
import spl06_001
|
||||
onboard_bps = spl06_001.SPL06(onboard_i2c)
|
||||
except Exception as e:
|
||||
print("Warning: Failed to communicate with SPL06-001 (BPS) or",e)
|
||||
|
||||
'''ASR-Sensor'''
|
||||
try :
|
||||
import ci130x
|
||||
onboard_asr = ci130x.CI130X(onboard_i2c)
|
||||
from ci1302x import CI1302
|
||||
onboard_asr = CI1302(inboard_i2c, onboard_bot.asr_en)
|
||||
except Exception as e:
|
||||
print("Warning: Failed to communicate with CI130X (ASR) or",e)
|
||||
|
||||
'''2RGB_WS2812'''
|
||||
from ws2812 import NeoPixel
|
||||
onboard_rgb = NeoPixel(Pin(21), 4)
|
||||
from ws2812x import NeoPixel
|
||||
onboard_rgb = NeoPixel(onboard_bot.rgb_sync, 4)
|
||||
|
||||
'''1Buzzer-Music'''
|
||||
from music import MIDI
|
||||
onboard_music = MIDI(16, pa_ctrl=onboard_asr.pa_ctrl)
|
||||
from musicx import MIDI
|
||||
onboard_music = MIDI(46, pa_ctrl=onboard_bot.spk_en)
|
||||
|
||||
'''5KEY_Sensor'''
|
||||
class KEYSensor:
|
||||
def __init__(self, pin, range):
|
||||
self.pin = pin
|
||||
self.adc = ADC(Pin(pin), atten=ADC.ATTN_0DB)
|
||||
self.adc = ADC(Pin(pin))
|
||||
self.adc.atten(ADC.ATTN_0DB)
|
||||
self.range = range
|
||||
self.flag = True
|
||||
|
||||
|
||||
def _value(self):
|
||||
values = []
|
||||
for _ in range(50):
|
||||
for _ in range(25):
|
||||
values.append(self.adc.read())
|
||||
time.sleep_us(2)
|
||||
time.sleep_us(5)
|
||||
return (self.range-200) < min(values) < (self.range+200)
|
||||
|
||||
def get_presses(self, delay = 1):
|
||||
@@ -135,26 +125,22 @@ class Button(KEYSensor):
|
||||
return not self.key.value()
|
||||
|
||||
B1key = Button(0)
|
||||
B2key = KEYSensor(15,0)
|
||||
A1key = KEYSensor(15,2300)
|
||||
A2key = KEYSensor(15,1650)
|
||||
A3key = KEYSensor(15,850)
|
||||
A4key = KEYSensor(15,2900)
|
||||
B2key = KEYSensor(17, 0)
|
||||
A1key = KEYSensor(17, 1600)
|
||||
A2key = KEYSensor(17, 1100)
|
||||
A3key = KEYSensor(17, 550)
|
||||
A4key = KEYSensor(17, 2100)
|
||||
|
||||
'''2-LED'''
|
||||
class LED:
|
||||
def __init__(self, pins=[]):
|
||||
self._pins = [PWM(Pin(pin), duty_u16=0) for pin in pins]
|
||||
self._brightness = [0 for _ in range(len(self._pins))]
|
||||
def __init__(self, func):
|
||||
self._func = func
|
||||
|
||||
def setbrightness(self, index, val):
|
||||
if not 0 <= val <= 100:
|
||||
raise ValueError("Brightness must be in the range: 0-100%")
|
||||
self._brightness[index - 1] = val
|
||||
self._pins[index - 1].duty_u16(val * 65535 // 100)
|
||||
self._func(index, val)
|
||||
|
||||
def getbrightness(self, index):
|
||||
return self._brightness[index - 1]
|
||||
return self._func(index)
|
||||
|
||||
def setonoff(self, index, val):
|
||||
if val == -1:
|
||||
@@ -167,7 +153,7 @@ class LED:
|
||||
def getonoff(self, index):
|
||||
return True if self.getbrightness(index) > 50 else False
|
||||
|
||||
onboard_led = LED(pins=[45, 46])
|
||||
onboard_led = LED(onboard_bot.led_pwm)
|
||||
|
||||
class Voice_Energy:
|
||||
def read(self):
|
||||
|
||||
162
boards/default/micropython_esp32s3/build/lib/musicx.py
Normal file
162
boards/default/micropython_esp32s3/build/lib/musicx.py
Normal file
@@ -0,0 +1,162 @@
|
||||
"""
|
||||
Music buzzer
|
||||
|
||||
Micropython library for the Music buzzer
|
||||
=======================================================
|
||||
|
||||
#Based on Author: qiren123(MIDI Music) 20220618
|
||||
#Make changes to instantiation 20220622
|
||||
#Increase level reversal selection 20220716
|
||||
|
||||
dahanzimin From the Mixly Team
|
||||
"""
|
||||
|
||||
from time import sleep_ms
|
||||
from machine import Pin, PWM
|
||||
|
||||
normal_tone = {
|
||||
'A1': 55, 'B1': 62, 'C1': 33, 'D1': 37, 'E1': 41, 'F1': 44, 'G1': 49,
|
||||
'A2': 110, 'B2': 123, 'C2': 65, 'D2': 73, 'E2': 82, 'F2': 87, 'G2': 98,
|
||||
'A3': 220, 'B3': 247, 'C3': 131, 'D3': 147, 'E3': 165, 'F3': 175, 'G3': 196,
|
||||
'A4': 440, 'B4': 494, 'C4': 262, 'D4': 294, 'E4': 330, 'F4': 349, 'G4': 392,
|
||||
'A5': 880, 'B5': 988, 'C5': 523, 'D5': 587, 'E5': 659, 'F5': 698, 'G5': 784,
|
||||
'A6': 1760, 'B6': 1976, 'C6': 1047, 'D6': 1175, 'E6': 1319, 'F6': 1397, 'G6': 1568,
|
||||
'A7': 3520, 'B7': 3951, 'C7': 2093, 'D7': 2349, 'E7': 2637, 'F7': 2794, 'G7': 3135,
|
||||
'A8': 7040, 'B8': 7902, 'C8': 4186, 'D8': 4699, 'E8': 5274, 'F8': 5588, 'G8': 6271,
|
||||
'A9': 14080, 'B9': 15804 }
|
||||
|
||||
Letter = 'ABCDEFG#R'
|
||||
|
||||
class MIDI():
|
||||
def __init__(self, pin, volume=100, invert=0, pa_ctrl=None):
|
||||
self.reset()
|
||||
self._invert=invert
|
||||
self._pin = pin
|
||||
self._volume = volume
|
||||
self._pwm = None
|
||||
self._pa_ctrl = pa_ctrl
|
||||
|
||||
def set_volume(self,volume):
|
||||
if not 0 <= volume <= 100:
|
||||
raise ValueError("Volume value is in the range: 0-100")
|
||||
self._volume=volume
|
||||
|
||||
def set_tempo(self, ticks=4, bpm=120):
|
||||
self.ticks = ticks
|
||||
self.bpm = bpm
|
||||
self.beat = 60000 / self.bpm / self.ticks
|
||||
|
||||
def set_octave(self, octave=4):
|
||||
self.octave = octave
|
||||
|
||||
def set_duration(self, duration=4):
|
||||
self.duration = duration
|
||||
|
||||
def get_tempo(self):
|
||||
return (self.ticks, self.bpm)
|
||||
|
||||
def get_octave(self):
|
||||
return self.octave
|
||||
|
||||
def get_duration(self):
|
||||
return self.duration
|
||||
|
||||
def reset(self):
|
||||
self.set_duration()
|
||||
self.set_octave()
|
||||
self.set_tempo()
|
||||
|
||||
def parse(self, tone, dict):
|
||||
time = self.beat * self.duration
|
||||
pos = tone.find(':')
|
||||
if pos != -1:
|
||||
time = self.beat * int(tone[(pos + 1):])
|
||||
tone = tone[:pos]
|
||||
freq, tone_size = 1, len(tone)
|
||||
if 'R' in tone:
|
||||
freq = 40000
|
||||
elif tone_size == 1:
|
||||
freq = dict[tone[0] + str(self.octave)]
|
||||
elif tone_size == 2:
|
||||
freq = dict[tone]
|
||||
self.set_octave(tone[1:])
|
||||
return int(freq), int(time)
|
||||
|
||||
def midi(self, tone):
|
||||
pos = tone.find('#')
|
||||
if pos != -1:
|
||||
return self.parse(tone.replace('#', ''), normal_tone)
|
||||
pos = tone.find('B')
|
||||
if pos != -1 and pos != 0:
|
||||
return self.parse(tone.replace('B', ''), normal_tone)
|
||||
return self.parse(tone, normal_tone)
|
||||
|
||||
def set_default(self, tone):
|
||||
pos = tone.find(':')
|
||||
if pos != -1:
|
||||
self.set_duration(int(tone[(pos + 1):]))
|
||||
tone = tone[:pos]
|
||||
|
||||
def play(self, tune, duration=None):
|
||||
if self._pa_ctrl: self._pa_ctrl(1)
|
||||
self._pwm = PWM(Pin(self._pin), duty=1023 if self._invert else 0)
|
||||
if duration is None:
|
||||
self.set_default(tune[0])
|
||||
else:
|
||||
self.set_duration(duration)
|
||||
for tone in tune:
|
||||
tone = tone.upper()
|
||||
if tone[0] not in Letter:
|
||||
continue
|
||||
midi = self.midi(tone)
|
||||
self._pwm.duty(1023-self._volume) if self._invert else self._pwm.duty(self._volume)
|
||||
self._pwm.freq(midi[0])
|
||||
sleep_ms(midi[1])
|
||||
self._pwm.freq(40000)
|
||||
sleep_ms(1)
|
||||
if self._pa_ctrl: self._pa_ctrl(0)
|
||||
self._pwm.deinit()
|
||||
sleep_ms(10)
|
||||
|
||||
def pitch(self, freq):
|
||||
if self._pa_ctrl: self._pa_ctrl(1)
|
||||
self._pwm = PWM(Pin(self._pin))
|
||||
self._pwm.duty(1023-self._volume) if self._invert else self._pwm.duty(self._volume)
|
||||
self._pwm.freq(int(freq))
|
||||
|
||||
def pitch_time(self, freq, delay):
|
||||
if self._pa_ctrl: self._pa_ctrl(1)
|
||||
self._pwm = PWM(Pin(self._pin))
|
||||
self._pwm.duty(1023-self._volume) if self._invert else self._pwm.duty(self._volume)
|
||||
self._pwm.freq(int(freq))
|
||||
sleep_ms(delay)
|
||||
if self._pa_ctrl: self._pa_ctrl(0)
|
||||
self._pwm.deinit()
|
||||
sleep_ms(10)
|
||||
|
||||
def stop(self):
|
||||
if self._pa_ctrl: self._pa_ctrl(0)
|
||||
if self._pwm: self._pwm.deinit()
|
||||
sleep_ms(10)
|
||||
|
||||
DADADADUM=['r4:2','g','g','g','eb:8','r:2','f','f','f','d:8']
|
||||
ENTERTAINER=['d4:1','d#','e','c5:2','e4:1','c5:2','e4:1','c5:3','c:1','d','d#','e','c','d','e:2','b4:1','d5:2','c:4']
|
||||
PRELUDE=['c4:1','e','g','c5','e','g4','c5','e','c4','e','g','c5','e','g4','c5','e','c4','d','g','d5','f','g4','d5','f','c4','d','g','d5','f','g4','d5','f','b3','d4','g','d5','f','g4','d5','f','b3','d4','g','d5','f','g4','d5','f','c4','e','g','c5','e','g4','c5','e','c4','e','g','c5','e','g4','c5','e']
|
||||
ODE=['e4','e','f','g','g','f','e','d','c','c','d','e','e:6','d:2','d:8','e:4','e','f','g','g','f','e','d','c','c','d','e','d:6','c:2','c:8']
|
||||
NYAN=['f#5:1','g#','c#:1','d#:2','b4:1','d5:1','c#','b4:2','b','c#5','d','d:1','c#','b4:1','c#5:1','d#','f#','g#','d#','f#','c#','d','b4','c#5','b4','d#5:2','f#','g#:1','d#','f#','c#','d#','b4','d5','d#','d','c#','b4','c#5','d:2','b4:1','c#5','d#','f#','c#','d','c#','b4','c#5:2','b4','c#5','b4','f#:1','g#','b:2','f#:1','g#','b','c#5','d#','b4','e5','d#','e','f#','b4:2','b','f#:1','g#','b','f#','e5','d#','c#','b4','f#','d#','e','f#','b:2','f#:1','g#','b:2','f#:1','g#','b','b','c#5','d#','b4','f#','g#','f#','b:2','b:1','a#','b','f#','g#','b','e5','d#','e','f#','b4:2','c#5']
|
||||
RINGTONE=['c4:1','d','e:2','g','d:1','e','f:2','a','e:1','f','g:2','b','c5:4']
|
||||
FUNK=['c2:2','c','d#','c:1','f:2','c:1','f:2','f#','g','c','c','g','c:1','f#:2','c:1','f#:2','f','d#']
|
||||
BLUES=['c2:2','e','g','a','a#','a','g','e','c2:2','e','g','a','a#','a','g','e','f','a','c3','d','d#','d','c','a2','c2:2','e','g','a','a#','a','g','e','g','b','d3','f','f2','a','c3','d#','c2:2','e','g','e','g','f','e','d']
|
||||
BIRTHDAY=['c4:4','c:1','d:4','c:4','f','e:8','c:3','c:1','d:4','c:4','g','f:8','c:3','c:1','c5:4','a4','f','e','d','a#:3','a#:1','a:4','f','g','f:8']
|
||||
WEDDING=['c4:4','f:3','f:1','f:8','c:4','g:3','e:1','f:8','c:4','f:3','a:1','c5:4','a4:3','f:1','f:4','e:3','f:1','g:8']
|
||||
FUNERAL=['c3:4','c:3','c:1','c:4','d#:3','d:1','d:3','c:1','c:3','b2:1','c3:4']
|
||||
PUNCHLINE=['c4:3','g3:1','f#','g','g#:3','g','r','b','c4']
|
||||
PYTHON=['d5:1','b4','r','b','b','a#','b','g5','r','d','d','r','b4','c5','r','c','c','r','d','e:5','c:1','a4','r','a','a','g#','a','f#5','r','e','e','r','c','b4','r','b','b','r','c5','d:5','d:1','b4','r','b','b','a#','b','b5','r','g','g','r','d','c#','r','a','a','r','a','a:5','g:1','f#:2','a:1','a','g#','a','e:2','a:1','a','g#','a','d','r','c#','d','r','c#','d:2','r:3']
|
||||
BADDY=['c3:3','r','d:2','d#','r','c','r','f#:8']
|
||||
CHASE=['a4:1','b','c5','b4','a:2','r','a:1','b','c5','b4','a:2','r','a:2','e5','d#','e','f','e','d#','e','b4:1','c5','d','c','b4:2','r','b:1','c5','d','c','b4:2','r','b:2','e5','d#','e','f','e','d#','e']
|
||||
BA_DING=['b5:1','e6:3']
|
||||
WAWAWAWAA=['e3:3','r:1','d#:3','r:1','d:4','r:1','c#:8']
|
||||
JUMP_UP=['c5:1','d','e','f','g']
|
||||
JUMP_DOWN=['g5:1','f','e','d','c']
|
||||
POWER_UP=['g4:1','c5','e4','g5:2','e5:1','g5:3']
|
||||
POWER_DOWN=['g5:1','d#','c','g4:2','b:1','c5:3']
|
||||
@@ -1,7 +1,7 @@
|
||||
"""
|
||||
SANT_WCH
|
||||
|
||||
Micropython library for the SANT_WCH(---)
|
||||
Micropython library for the SANT_WCH(--V1.8--)
|
||||
=======================================================
|
||||
@dahanzimin From the Mixly Team
|
||||
"""
|
||||
@@ -11,55 +11,65 @@ from micropython import const
|
||||
_BOT035_ADDRESS = const(0x13)
|
||||
_BOT5_TOUCH = const(0x01)
|
||||
_BOT035_ADC = const(0x05)
|
||||
_BOT035_PWM = const(0x07)
|
||||
_BOT035_LED = const(0x0C)
|
||||
_BOT035_CMD = const(0x0D)
|
||||
_BOT035_KB = const(0x10)
|
||||
_BOT035_MS = const(0x14)
|
||||
_BOT035_STR = const(0x18)
|
||||
_BOT035_PWM = const(0x09)
|
||||
_BOT035_LED = const(0x0F)
|
||||
_BOT035_STA = const(0x12)
|
||||
_BOT035_CMD = const(0x13)
|
||||
_BOT035_RGB = const(0x14)
|
||||
_BOT035_KB = const(0x20)
|
||||
_BOT035_MS = const(0x24)
|
||||
_BOT035_STR = const(0x28)
|
||||
|
||||
class BOT035:
|
||||
def __init__(self, i2c_bus):
|
||||
self._i2c = i2c_bus
|
||||
self._touchs = [self.touch(0), self.touch(1)]
|
||||
self.reset()
|
||||
|
||||
def _wreg(self, reg, val):
|
||||
def _wreg(self, reg, val, digit=1):
|
||||
'''Write memory address'''
|
||||
self._i2c.writeto_mem(_BOT035_ADDRESS, reg, val.to_bytes(1, 'little'))
|
||||
self._i2c.writeto_mem(_BOT035_ADDRESS, reg, val.to_bytes(digit, 'little'))
|
||||
|
||||
def _rreg(self, reg, nbytes=1):
|
||||
'''Read memory address'''
|
||||
self._i2c.writeto(_BOT035_ADDRESS, reg.to_bytes(1, 'little'))
|
||||
return self._i2c.readfrom(_BOT035_ADDRESS, nbytes)[0]
|
||||
return int.from_bytes(self._i2c.readfrom(_BOT035_ADDRESS, nbytes), 'little')
|
||||
|
||||
def _bits(self, offset, mask, value=None, delay=100, reg=_BOT035_CMD):
|
||||
if value is None:
|
||||
return (self._rreg(reg) & mask) >> offset
|
||||
else:
|
||||
self._wreg(reg, (self._rreg(reg) & (~ mask & 0xFF)) | (value << offset))
|
||||
time.sleep_ms(delay)
|
||||
|
||||
def reset(self):
|
||||
self._i2c.writeto_mem(_BOT035_ADDRESS, _BOT035_PWM, b' Ndddd\x00\x00\x00\x8c\xb0')
|
||||
|
||||
def key_adc(self):
|
||||
return (self._rreg(_BOT035_ADC) | self._rreg(_BOT035_ADC + 1) << 8)
|
||||
return self._rreg(_BOT035_ADC, 2)
|
||||
|
||||
def touch(self, index, value=None):
|
||||
index = max(min(index, 1), 0)
|
||||
touch = 4095 - (self._rreg(_BOT5_TOUCH + index * 2) | self._rreg(_BOT5_TOUCH + index * 2 + 1) << 8)
|
||||
touch = 4095 - self._rreg(_BOT5_TOUCH + index * 2, 2)
|
||||
return touch > value if value else touch
|
||||
|
||||
def touched(self, index, value=600):
|
||||
return self.touch(index, value)
|
||||
|
||||
def touch_slide(self, comp=1.2):
|
||||
def touch_slide(self):
|
||||
values = []
|
||||
for i in range(30):
|
||||
values.append((self.touch(1) - self._touchs[1]) * comp - (self.touch(0) - self._touchs[0]))
|
||||
return round(sorted(values)[15] / 10)
|
||||
for i in range(20):
|
||||
values.append((self.touch(1) - self._touchs[1]) - (self.touch(0) - self._touchs[0]))
|
||||
return round(sorted(values)[10] / 10)
|
||||
|
||||
def usben(self, index=1, duty=None, freq=None):
|
||||
index = max(min(index, 3), 1) - 1
|
||||
index = max(min(index, 4), 1)
|
||||
if duty is not None:
|
||||
duty = max(min(duty, 100), 0)
|
||||
self._wreg(_BOT035_PWM + index + 2, int(duty))
|
||||
self._wreg(_BOT035_PWM + index + 1, int(max(min(duty, 100), 0)))
|
||||
if freq is not None:
|
||||
freq = max(min(freq, 65535), 10)
|
||||
self._wreg(_BOT035_PWM, freq & 0xFF)
|
||||
self._wreg(_BOT035_PWM + 1, freq >> 8)
|
||||
self._wreg(_BOT035_PWM, max(min(freq, 65535), 10), 2)
|
||||
if freq is None and duty is None:
|
||||
return self._rreg(_BOT035_PWM + index + 2), self._rreg(_BOT035_PWM) | self._rreg(_BOT035_PWM + 1) << 8
|
||||
return self._rreg(_BOT035_PWM + index + 1), self._rreg(_BOT035_PWM ,2)
|
||||
|
||||
def tft_brightness(self, brightness=None):
|
||||
if brightness is None:
|
||||
@@ -67,8 +77,35 @@ class BOT035:
|
||||
else:
|
||||
self._wreg(_BOT035_LED, max(min(brightness, 100), 0))
|
||||
|
||||
def tft_reset(self, value):
|
||||
self._wreg(_BOT035_CMD, (self._rreg(_BOT035_CMD) & 0x7F) | (value << 7))
|
||||
def led_pwm(self, index=1, duty=None):
|
||||
index = max(min(index, 2), 1)
|
||||
if duty is None:
|
||||
return self._rreg(_BOT035_LED + index)
|
||||
else:
|
||||
self._wreg(_BOT035_LED + index, max(min(duty, 100), 0))
|
||||
|
||||
def tft_reset(self, value=None, delay=50):
|
||||
return self._bits(7, 0x80, value, delay)
|
||||
|
||||
def spk_en(self, value=None, delay=10):
|
||||
return self._bits(6, 0x40, value, delay)
|
||||
|
||||
def cam_en(self, value=None, delay=500):
|
||||
"""Convert to high level effective"""
|
||||
value = value if value is None else ~ value & 0x01
|
||||
return self._bits(5, 0x20, value, delay)
|
||||
|
||||
def cam_reset(self, value=None, delay=50):
|
||||
return self._bits(4, 0x10, value, delay)
|
||||
|
||||
def asr_en(self, value=None, delay=700):
|
||||
return self._bits(2, 0x0C, value, delay)
|
||||
|
||||
def uart_select(self, value=None, delay=50):
|
||||
return self._bits(0, 0x03, value, delay)
|
||||
|
||||
def rgb_sync(self, buffer, n=12):
|
||||
self._i2c.writeto_mem(_BOT035_ADDRESS, _BOT035_RGB, buffer if len(buffer) < n else buffer[:n])
|
||||
|
||||
def hid_keyboard(self, special=0, general=0, release=True):
|
||||
self._buf = bytearray(4)
|
||||
@@ -90,7 +127,7 @@ class BOT035:
|
||||
time.sleep_ms(20 + delay)
|
||||
|
||||
def hid_keyboard_state(self):
|
||||
state = self._rreg(_BOT035_CMD)
|
||||
state = self._rreg(_BOT035_STA)
|
||||
return bool(state & 0x10), bool(state & 0x20), bool(state & 0x40)
|
||||
|
||||
def hid_mouse(self, keys=0, move=(0, 0), wheel=0, release=True):
|
||||
|
||||
30
boards/default/micropython_esp32s3/build/lib/sant_gx.py
Normal file
30
boards/default/micropython_esp32s3/build/lib/sant_gx.py
Normal file
@@ -0,0 +1,30 @@
|
||||
"""
|
||||
SANT GX -MixGo SANT EXT G3
|
||||
|
||||
MicroPython library for the SANT GX (Expansion board for MixGo SANT)
|
||||
=======================================================
|
||||
@dahanzimin From the Mixly Team
|
||||
"""
|
||||
|
||||
import gc
|
||||
from machine import Pin, SoftI2C
|
||||
|
||||
'''i2c-extboard'''
|
||||
ext_i2c = SoftI2C(scl=Pin(18), sda=Pin(21), freq=400000)
|
||||
|
||||
'''RFID_Sensor'''
|
||||
try :
|
||||
import rc522
|
||||
ext_rfid = rc522.RC522(ext_i2c)
|
||||
except Exception as e:
|
||||
print("Warning: Failed to communicate with SI522A (RFID) or",e)
|
||||
|
||||
'''RADAR_Sensor'''
|
||||
try :
|
||||
import cbr817
|
||||
ext_mmw = cbr817.CBR817(ext_i2c)
|
||||
except Exception as e:
|
||||
print("Warning: Failed to communicate with CBR817 (RADAR) or",e)
|
||||
|
||||
'''Reclaim memory'''
|
||||
gc.collect()
|
||||
@@ -1,75 +1,27 @@
|
||||
"""
|
||||
ST7789/FrameBuffer
|
||||
ST7789/FrameBuffer(Inherit C module)
|
||||
|
||||
MicroPython library for the ST7789(TFT-SPI)
|
||||
MicroPython library for the ST7789(Inherit C module)
|
||||
=======================================================
|
||||
@dahanzimin From the Mixly Team
|
||||
"""
|
||||
import time, uframebuf
|
||||
from machine import Pin, PWM
|
||||
from micropython import const
|
||||
|
||||
_CMD_SWRESET = const(0x01)
|
||||
_CMD_SLPIN = const(0x10)
|
||||
_CMD_SLPOUT = const(0x11)
|
||||
_CMD_PTLON = const(0x12)
|
||||
_CMD_NORON = const(0x13)
|
||||
_CMD_INVOFF = const(0x20)
|
||||
_CMD_INVON = const(0x21)
|
||||
_CMD_DISPOFF = const(0x28)
|
||||
_CMD_DISPON = const(0x29)
|
||||
_CMD_CASET = const(0x2A)
|
||||
_CMD_RASET = const(0x2B)
|
||||
_CMD_RAMWR = const(0x2C)
|
||||
_CMD_RAMRD = const(0x2E)
|
||||
_CMD_PTLAR = const(0x30)
|
||||
_CMD_VSCRDEF = const(0x33)
|
||||
_CMD_COLMOD = const(0x3A)
|
||||
_CMD_MADCTL = const(0x36)
|
||||
from tftlcd import LCD15
|
||||
|
||||
class ST7789(uframebuf.FrameBuffer_Uincode):
|
||||
def __init__(self, spi, width, height, dc_pin=None, backlight=None, font_address=0x700000):
|
||||
self.spi = spi
|
||||
self.dc = Pin(dc_pin, Pin.OUT, value=1)
|
||||
def __init__(self, width=240, height=240, reset=None, backlight=None, direction=1, font_address=0x700000):
|
||||
if reset is not None:
|
||||
reset(0, 50)
|
||||
reset(1, 100)
|
||||
self.display = LCD15(portrait=direction)
|
||||
self._width = width
|
||||
self._height = height
|
||||
self._buffer = bytearray(width * height * 2)
|
||||
super().__init__(self._buffer, width, height, uframebuf.RGB565)
|
||||
self.font(font_address)
|
||||
self._init()
|
||||
self.show()
|
||||
self._backlight = backlight
|
||||
self.set_brightness(0.5)
|
||||
|
||||
def _write(self, cmd, dat=None):
|
||||
self.dc.off()
|
||||
self.spi.write(bytearray([cmd]))
|
||||
if dat is not None:
|
||||
self.dc.on()
|
||||
self.spi.write(dat)
|
||||
|
||||
def _init(self):
|
||||
"""Display initialization configuration"""
|
||||
for cmd, data, delay in [
|
||||
##(_CMD_SWRESET, None, 20000),
|
||||
(_CMD_SLPOUT, None, 120000),
|
||||
(_CMD_MADCTL, b'\x00', 50),
|
||||
(_CMD_COLMOD, b'\x05', 50),
|
||||
(0xB2, b'\x0c\x0c\x00\x33\x33', 10),
|
||||
(0xB7, b'\x35', 10),
|
||||
(0xBB, b'\x19', 10),
|
||||
(0xC0, b'\x2C', 10),
|
||||
(0xC2, b'\x01', 10),
|
||||
(0xC3, b'\x12', 10),
|
||||
(0xC4, b'\x20', 10),
|
||||
(0xC6, b'\x0F', 10),
|
||||
(0xD0, b'\xA4\xA1', 10),
|
||||
(0xE0, b'\xD0\x04\x0D\x11\x13\x2B\x3F\x54\x4C\x18\x0D\x0B\x1F\x23', 10),
|
||||
(0xE1, b'\xD0\x04\x0C\x11\x13\x2C\x3F\x44\x51\x2F\x1F\x1F\x20\x23', 10),
|
||||
(_CMD_INVON, None, 10),
|
||||
(_CMD_DISPON, None, 10),
|
||||
]:
|
||||
self._write(cmd, data)
|
||||
if delay:
|
||||
time.sleep_us(delay)
|
||||
if backlight: self.set_brightness(0.5)
|
||||
|
||||
def get_brightness(self):
|
||||
return self._backlight() / 100
|
||||
@@ -86,8 +38,9 @@ class ST7789(uframebuf.FrameBuffer_Uincode):
|
||||
else:
|
||||
return (red & 0xf8) << 8 | (green & 0xfc) << 3 | blue >> 3
|
||||
|
||||
def picture(self, x, y, path):
|
||||
self.display.Picture(x, y, path)
|
||||
|
||||
def show(self):
|
||||
"""Refresh the display and show the changes."""
|
||||
self._write(_CMD_CASET, b'\x00\x00\x00\xef')
|
||||
self._write(_CMD_RASET, b'\x00\x00\x00\xef')
|
||||
self._write(_CMD_RAMWR, self._buffer)
|
||||
self.display.write_buf(self._buffer, 0, 0, self._width, self._height)
|
||||
|
||||
66
boards/default/micropython_esp32s3/build/lib/ws2812x.py
Normal file
66
boards/default/micropython_esp32s3/build/lib/ws2812x.py
Normal file
@@ -0,0 +1,66 @@
|
||||
"""
|
||||
WS2812 RGB(x035)
|
||||
|
||||
Micropython library for the WS2812 NeoPixel-RGB(method inheritance)
|
||||
=======================================================
|
||||
@dahanzimin From the Mixly Team
|
||||
"""
|
||||
from time import sleep
|
||||
|
||||
class NeoPixel:
|
||||
def __init__(self, func, n, bpp=3, ORDER=(0, 1, 2, 3)):
|
||||
self.func = func
|
||||
self.bpp = bpp
|
||||
self.rgbs = n
|
||||
self.ORDER = ORDER
|
||||
self.rgb_buf = bytearray(self.rgbs * bpp)
|
||||
self.write()
|
||||
|
||||
def __len__(self):
|
||||
return self.rgbs
|
||||
|
||||
def __setitem__(self, n, v):
|
||||
for i in range(self.bpp):
|
||||
self.rgb_buf[n * self.bpp + self.ORDER[i]] = v[i]
|
||||
|
||||
def __getitem__(self, n):
|
||||
return tuple(self.rgb_buf[n * self.bpp + self.ORDER[i]] for i in range(self.bpp))
|
||||
|
||||
def fill(self, v):
|
||||
for i in range(self.bpp):
|
||||
j = self.ORDER[i]
|
||||
while j < self.rgbs * self.bpp:
|
||||
self.rgb_buf[j] = v[i]
|
||||
j += self.bpp
|
||||
|
||||
def write(self):
|
||||
self.func(self.rgb_buf)
|
||||
|
||||
def color_chase(self,R, G, B, wait):
|
||||
for i in range(self.rgbs):
|
||||
self.__setitem__(i,(R, G, B))
|
||||
self.write()
|
||||
sleep(wait/1000)
|
||||
|
||||
def rainbow_cycle(self, wait, clear=True):
|
||||
for j in range(255):
|
||||
for i in range(self.rgbs):
|
||||
rc_index = (i * 256 // self.rgbs) + j
|
||||
self.__setitem__(i,self.wheel(rc_index & 255))
|
||||
self.write()
|
||||
sleep(wait / 1000 / 256)
|
||||
if clear:
|
||||
self.fill((0, 0, 0))
|
||||
self.write()
|
||||
|
||||
def wheel(self,pos):
|
||||
if pos < 0 or pos > 255:
|
||||
return (0, 0, 0)
|
||||
elif pos < 85:
|
||||
return (pos * 3, 255 - pos * 3, 0)
|
||||
elif pos < 170:
|
||||
pos -= 85
|
||||
return (255 - pos * 3, 0, pos * 3)
|
||||
else:
|
||||
pos -= 170
|
||||
return (0, pos * 3, 255 - pos * 3)
|
||||
Reference in New Issue
Block a user