Esempio n. 1
0
    def run():
        # debug into app_select
        # launcher.app_select = 2
        # app.layer = 1

        ui.height, ui.weight = 480, 320
        # button_io.config(23, 20, 31) # amigo tft
        button_io.config(16, 23, 20)  # amigo ips
        sipeed_led.init(14, 15, 17, 32)

        app.i2c3 = I2C(I2C.I2C3, freq=100 * 1000, scl=24, sda=27)
        app.i2c4 = I2C(I2C.I2C4, freq=100 * 1000, scl=9, sda=7)

        TouchLow.config(i2c3=app.i2c3)  # amigo

        #if AXP173_ADDR in i2c.scan():
        axp173 = AXP173(i2c_dev=app.i2c3)
        axp173.enable_adc(True)
        # 默认充电限制在 4.2V, 190mA 档位
        axp173.setEnterChargingControl(True)
        axp173.exten_output_enable()
        # amigo sensor config.
        axp173.writeREG(0x27, 0x20)
        axp173.writeREG(0x28, 0x0C)
        taskbar.init(axp173)

        CubeAudio.init(app.i2c3)
        if CubeAudio.check():
            CubeAudio.ready()
            fm.register(13, fm.fpioa.I2S0_MCLK, force=True)
            fm.register(21, fm.fpioa.I2S0_SCLK, force=True)
            fm.register(18, fm.fpioa.I2S0_WS, force=True)
            fm.register(35, fm.fpioa.I2S0_IN_D0, force=True)
            fm.register(34, fm.fpioa.I2S0_OUT_D2, force=True)

        #app.ctrl.event(100, lambda *args: time.sleep(1))
        #app.ctrl.event(10, app.on_event)
        app.ctrl.event(5, app.draw)
        #ui.enable = False
        while True:
            last = 0
            while True:
                try:
                    # print((int)(1000 / (time.ticks_ms() - last)), 'fps')
                    # last = time.ticks_ms()
                    # print_mem_free()
                    gc.collect()
                    app.ctrl.cycle()
                    protect.keep()
                    #time.sleep(0.1)
                except KeyboardInterrupt:
                    protect.stop()
                    raise KeyboardInterrupt()
                except Exception as e:
                    # gc.collect()
                    print(e)
Esempio n. 2
0
    def work(self):
        self.agent.parallel_cycle()

        ui.canvas.draw_string(10, 30, "9 Audio Test", (127, 127, 255), scale=3)
        ui.canvas.draw_string(10,
                              70,
                              "isconnected: %s" % (str)(self.isconnected),
                              (255, 127, 0),
                              scale=2)

        ui.canvas.draw_string(10,
                              100,
                              "Test: %s" %
                              ('play' if self.state == 0 else 'record'),
                              (255, 127, 0),
                              scale=3)

        #print(time.ticks_ms())

        if self.isconnected:
            if self.state == 0 and self.is_play:
                if CubeAudio.event() == False:
                    CubeAudio.load(os.getcwd() + "/res/sound/loop.wav", 100)
                    #print('self.count', self.count)
                    if self.count > 1:
                        CubeAudio.i2s.set_sample_rate(22050)
                    else:
                        # pass
                        CubeAudio.i2s.set_sample_rate(22050)
            elif self.state == 1:
                ui.canvas.draw_string(10,
                                      200,
                                      "Press Any-Key \n Start", (255, 127, 0),
                                      scale=3)
            elif self.state == 2 and self.is_record:
                tmp = CubeAudio.i2s.record(1024)
                fft_res = FFT.run(tmp.to_bytes(), 512)
                fft_amp = FFT.amplitude(fft_res)
                if fft_amp[50] > 100 and fft_amp[100] > 100:
                    AudioTest.RecordTest = True
                    sample_page.next()
                for x_shift in range(240):
                    hist_height = fft_amp[x_shift]
                    ui.canvas.draw_rectangle((x_shift, 0, 1, hist_height),
                                             [255, 255, 255], 1, True)
                    #print((x_shift, 0, 1, hist_height))

        if self.isError != None:
            ui.canvas.draw_string(40,
                                  80,
                                  self.isError, (255, 255, 255),
                                  scale=2)
            sample_page.next()
Esempio n. 3
0
    def run():
        # debug into app_select
        #launcher.app_select = 0
        #app.layer = 2

        button_io.config()
        sipeed_led.init(13, 12, 14, 32)
        sample_page.key_init()

        fm.register(30, fm.fpioa.I2C1_SCLK, force=True)
        fm.register(31, fm.fpioa.I2C1_SDA, force=True)

        axp173 = AXP173()
        axp173.enable_adc(True)
        # 默认充电限制在 4.2V, 190mA 档位
        axp173.setEnterChargingControl(True)
        axp173.exten_output_enable()
        taskbar.init(axp173)

        if CubeAudio.check():
            CubeAudio.ready()
            fm.register(19, fm.fpioa.I2S0_MCLK, force=True)
            fm.register(35, fm.fpioa.I2S0_SCLK, force=True)
            fm.register(33, fm.fpioa.I2S0_WS, force=True)
            fm.register(34, fm.fpioa.I2S0_IN_D0, force=True)
            fm.register(18, fm.fpioa.I2S0_OUT_D2, force=True)

        #app.ctrl.event(100, lambda *args: time.sleep(1))
        #app.ctrl.event(10, app.btn.event)
        app.ctrl.event(5, app.draw)
        while True:
            #import time
            #last = time.ticks_ms()
            while True:
                try:
                    #print((int)(1000 / (time.ticks_ms() - last)), 'fps')
                    #last = time.ticks_ms()
                    #print_mem_free()
                    gc.collect()
                    app.ctrl.cycle()
                    protect.keep()
                    #time.sleep(0.1)
                except KeyboardInterrupt:
                    protect.stop()
                    raise KeyboardInterrupt()
                except Exception as e:
                    # gc.collect()
                    print(e)
Esempio n. 4
0
    def load_application(selected):
        if app.current != None:  # clear last application
            del app.current
            app.current = None
        if selected == 0:
            pass

        elif selected == 1:
            app.current = pages()
            app.current.tips = "Weclome to Maix Amigo"
        elif selected == 2:
            CubeAudio.load(os.getcwd() + "/res/sound/loop.wav", 100)
            app.points = []
            pass
            #app.layer -= 1 # return last layer
            #raise Exception("Settings Unrealized.")
        elif selected == 3:
            photos.scan()
Esempio n. 5
0
    def load_application(selected):
        if app.current != None:  # clear last application
            del app.current
            app.current = None
        if selected == 0:
            pass

        elif selected == 1:
            app.current = pages()
        elif selected == 2:
            pass
            #app.layer -= 1 # return last layer
            #raise Exception("Settings Unrealized.")
        elif selected == 3:
            CubeAudio.load(os.getcwd() + "/res/sound/one.wav", 100)
            sample_page.add_sample(sample_msa301())
            sample_page.add_sample(sample_spmod_test())
            sample_page.add_sample(sample_shtxx())
            sample_page.add_demo()
Esempio n. 6
0
    def run():
        CubeAudio.ready()
        # CubeAudio.load("/flash/1k.wav", 100)
        #app.ctrl.event(100, lambda *args: time.sleep(1))
        app.ctrl.event(10, app.draw)

        while True:
            import time
            last = time.ticks_ms()
            while True:
                try:
                    #print((int)(1000 / (time.ticks_ms() - last)), 'fps')
                    print((int)((time.ticks_ms() - last)))
                    last = time.ticks_ms()
                    app.ctrl.parallel_cycle()
                    protect.keep()
                    #time.sleep(0.1)
                except KeyboardInterrupt:
                    protect.stop()
                    raise KeyboardInterrupt()
                except Exception as e:
                    # gc.collect()
                    print(e)
Esempio n. 7
0
 def check(self):
     try:
         if self.isconnected == False:
             self.isconnected = CubeAudio.check()
         else:
             if self.state == 0 and self.is_play == False:
                 self.is_play = True
                 CubeAudio.ready()
                 from fpioa_manager import fm
                 fm.register(19, fm.fpioa.I2S0_MCLK, force=True)
                 fm.register(35, fm.fpioa.I2S0_SCLK, force=True)
                 fm.register(33, fm.fpioa.I2S0_WS, force=True)
                 fm.register(34, fm.fpioa.I2S0_IN_D0, force=True)
                 fm.register(18, fm.fpioa.I2S0_OUT_D2, force=True)
                 # CubeAudio.i2s.set_sample_rate(22050)
             elif self.state == 1 and self.is_record == False:
                 self.is_record = True
                 CubeAudio.ready(True)
                 CubeAudio.i2s.set_sample_rate(22050)
     except Exception as e:
         #Report.Audio_Test = False
         Report.isError = str(e)
         print(e)
Esempio n. 8
0
    def draw_demo():
        app.loop = (app.loop + 1) % 200
        value = math.cos(math.pi * app.loop / 16) * 10

        ui.canvas.draw_string(10,
                              5,
                              "Seeed Grove",
                              color=(40 + int(value) * 2, 240 + int(value) * 2,
                                     40 + int(value) * 2),
                              scale=3,
                              mono_space=0)

        try:
            CubeAudio.event()
            if app.isconnected == False:
                CubeAudio.event()

                if app.loop % 5 == 1:
                    result = app.i2c4.scan()
                    ui.canvas.draw_string(290,
                                          80,
                                          "Scan Dev: " + str(result),
                                          color=(140 + int(value) * 5,
                                                 240 + int(value) * 5,
                                                 140 + int(value) * 5),
                                          scale=2,
                                          mono_space=0)

                    if SHT3x_ADDR in result:
                        app.sht3x = SHT3x(app.i2c4, SHT3x_ADDR)
                        app.isconnected = True
                    CubeAudio.event()
                    if SHT31_ADDR in result:
                        app.sht3x = SHT3x(app.i2c4, SHT31_ADDR)
                        app.isconnected = True
                    CubeAudio.event()

                ui.canvas.draw_string(
                    280,
                    25,
                    "Wait Grove Sensor \n sht31/35 <<<  <<  <-",
                    color=(140 + int(value) * 5, 240 + int(value) * 5,
                           140 + int(value) * 5),
                    scale=2,
                    mono_space=0)

                if CubeAudio.event() == False:

                    value = math.cos(math.pi * app.loop / 100) * 50

                    tmp = int(value)
                    #print(value)

                    ui.canvas.draw_circle(0,
                                          0,
                                          100 + tmp,
                                          fill=False,
                                          color=(0, (150 + tmp) + 10, 0))
                    ui.canvas.draw_circle(0,
                                          0,
                                          100 + tmp * 2,
                                          fill=False,
                                          color=(0, (150 + tmp) + 20, 0))
                    ui.canvas.draw_circle(0,
                                          0,
                                          100 + tmp * 3,
                                          fill=False,
                                          color=(0, (150 + tmp) + 30, 0))
                    ui.canvas.draw_circle(0,
                                          0,
                                          100 + tmp * 4,
                                          fill=False,
                                          color=(0, (150 + tmp) + 40, 0))

            else:
                data = app.sht3x.read_temp_humd()
                # print(data)
                if app.sidu == None:
                    app.sidu = image.Image(os.getcwd() +
                                           "/res/images/sidu.jpg")

                ui.canvas.draw_circle(350,
                                      160,
                                      100,
                                      fill=True,
                                      color=(255, 255, 255))
                ui.canvas.draw_image(app.sidu,
                                     270,
                                     60,
                                     alpha=235 + int(value) * 2)
                ui.canvas.draw_string(330,
                                      190,
                                      "%.2d" % data[1],
                                      scale=4,
                                      color=(80, 80, 80))

                ui.canvas.draw_rectangle(60,
                                         60,
                                         180,
                                         200,
                                         thickness=4,
                                         color=(155, 155, 155))
                if len(app.points) > 18:
                    app.points.pop(0)
                elif data[0] > 1 and app.temp != int(data[0] * 10):
                    app.temp = int(data[0] * 10)
                    app.points.append(app.temp)
                for p in range(len(app.points)):
                    #print(app.points)
                    if p < 1:
                        b = (60 + int(10 * (p))), 450 - app.points[p]
                        ui.canvas.draw_circle(b[0],
                                              b[1],
                                              3,
                                              fill=True,
                                              color=(255, 155, 150))
                    else:
                        a, b = ((60 + int(10 * (p - 1))), 450 -
                                app.points[p - 1]), ((60 + int(10 * (p))),
                                                     450 - app.points[p])
                        ui.canvas.draw_circle(b[0],
                                              b[1],
                                              3,
                                              fill=False,
                                              color=(155, 155, 155))
                        ui.canvas.draw_line(a[0],
                                            a[1],
                                            b[0],
                                            b[1],
                                            thickness=4,
                                            color=(255, 255, 255))

                ui.canvas.draw_string(
                    60,
                    280,
                    "Average temperature: %s" %
                    str(sum(app.points) / len(app.points) / 10.0),
                    color=(240 + int(value) * 5, 240 + int(value) * 5,
                           240 + int(value) * 5),
                    scale=2,
                    mono_space=0)

            CubeAudio.event()
            ui.display()
        except Exception as e:
            app.layer = 1
            app.isconnected = False
            app.points = []
            raise e
Esempio n. 9
0
from machine import I2C
import nes, lcd, sys, time
from sound import CubeAudio
from fpioa_manager import fm
from Maix import FPIOA, GPIO

i2c = I2C(I2C.I2C3, freq=500 * 1000, sda=27, scl=24)
CubeAudio.init(i2c)
tmp = CubeAudio.check()
print(tmp)

CubeAudio.ready(volume=100)

fm.fpioa.set_function(13, fm.fpioa.I2S0_MCLK)
fm.fpioa.set_function(21, fm.fpioa.I2S0_SCLK)
fm.fpioa.set_function(18, fm.fpioa.I2S0_WS)
fm.fpioa.set_function(35, fm.fpioa.I2S0_IN_D0)
fm.fpioa.set_function(34, fm.fpioa.I2S0_OUT_D2)

import video
v = video.open("/sd/badapple.avi")
print(v)
v.volume(90)
while True:
    if v.play() == 0:
        print("play end")
        break
Esempio n. 10
0
    def run():
        # debug into app_select
        #launcher.app_select = 0
        #app.layer = 2

        ui.height, ui.weight = 480, 320
        button_io.config(23, 31, 20) # amigo
        cube_led.init(14, 15, 17, 32)


        app.i2c0 = I2C(I2C.I2C0, freq=100*1000)
        app.i2c1 = I2C(I2C.I2C1, freq=100*1000)
        fm.register(24,fm.fpioa.I2C1_SCLK, force=True)
        fm.register(27,fm.fpioa.I2C1_SDA, force=True)

        print('monkey patch & config for i2c')
        TouchLow.config(i2c1=app.i2c1) # amigo

        for i in range(100):
            try:
                tmp = fm.fpioa.get_Pin_num(fm.fpioa.I2C1_SDA)
                fm.register(tmp, fm.fpioa.GPIOHS15)
                sda = GPIO(GPIO.GPIOHS15, GPIO.OUT)
                sda.value(1)
                fm.register(tmp, fm.fpioa.I2C1_SDA, force=True)

                #if AXP173_ADDR in i2c.scan():
                axp173 = AXP173(i2c_dev=app.i2c1)
                axp173.enable_adc(True)
                # 默认充电限制在 4.2V, 190mA 档位
                axp173.setEnterChargingControl(True)
                axp173.exten_output_enable()
                # amigo sensor config.
                axp173.writeREG(0x27, 0x20)
                axp173.writeREG(0x28, 0x0C)
                taskbar.init(axp173)

                break
            except Exception as e:
                # gc.collect()
                pass

                #if i == 99:
                    #raise(e)

        if CubeAudio.check():
            CubeAudio.ready()
            fm.register(13,fm.fpioa.I2S0_MCLK, force=True)
            fm.register(21,fm.fpioa.I2S0_SCLK, force=True)
            fm.register(18,fm.fpioa.I2S0_WS, force=True)
            fm.register(35,fm.fpioa.I2S0_IN_D0, force=True)
            fm.register(34,fm.fpioa.I2S0_OUT_D2, force=True)

        #app.ctrl.event(100, lambda *args: time.sleep(1))
        #app.ctrl.event(10, app.on_event)
        app.ctrl.event(5, app.draw)
        #ui.enable = False
        while True:
            last = 0
            while True:
                try:
                    # gc.collect()
                    print((int)(1000 / (time.ticks_ms() - last)), 'fps')
                    last = time.ticks_ms()
                    #print_mem_free()
                    app.ctrl.cycle()
                    protect.keep()
                    #time.sleep(0.1)
                except KeyboardInterrupt:
                    protect.stop()
                    raise KeyboardInterrupt()
                except Exception as e:
                    # gc.collect()
                    print(e)
Esempio n. 11
0
 def __init__(self):
     self.is_load = False
     self.i2c = I2C(I2C.I2C1, freq=100 * 1000, scl=30, sda=31)
     CubeAudio.init(self.i2c)
     self.count = 0