def load(self):
     if self.is_load == False:
         #print(case.load)
         self.is_load = True
         sample_page.btn.enable = False
         self.btn = sipeed_button()
         self.agent = agent()
         self.agent.event(150, self.key_event)
 def load(self):
     if self.is_load == False:
         self.is_load = True
         sample_page.btn.enable = False
         self.btn = sipeed_button()
         # self.btn.config(23, 20, 31)
         self.agent = agent()
         self.agent.event(150, self.key_event)
         #self.agent.event(500, sample_page.next)
     elif Report.RearSensor_Test:
         sample_page.next()
Exemple #3
0
class ai_camera():

    index, model, models = 0, ai_sample, [
        ai_sample, FaceDetect, FaceReco, find_color, HowMany, MaybeIs,
        MoblieNet, Minist
    ]
    btn, replace = sipeed_button(), False
    backlight = 1

    def reload():
        if ai_camera.model:
            ai_camera.model.free()
            ai_camera.model = ai_camera.models[ai_camera.index]
            ai_camera.model.load()

    def back():
        ai_camera.index -= 1
        ai_camera.replace = True

    def next():
        ai_camera.index += 1
        ai_camera.replace = True

    def jump(index):
        ai_camera.index = index
        ai_camera.replace = True

    def exit():
        sipeed_led.w.value(1)

    def ai_draw():
        ai_camera.btn.event()

        if ai_camera.btn.home() == 2:
            ai_camera.backlight = not ai_camera.backlight
            sipeed_led.w.value(ai_camera.backlight)

        if ai_camera.btn.back() == 2:
            ai_camera.back()
        elif ai_camera.btn.next() == 2:
            ai_camera.next()

        ai_camera.index = ai_camera.index % len(ai_camera.models)

        if ai_camera.replace:
            ai_camera.reload()
            ai_camera.replace = False

        tmp = camera.obj.get_image()
        if ai_camera.model and ai_camera.model.is_load:
            ai_camera.model.work(tmp)

        ui.canvas.draw_image(tmp, 0, 0)
    def load(self):
        if self.is_load == False:
            self.is_load = True
            sample_page.btn.enable = False
            self.btn = sipeed_button()
            # self.btn.config(23, 20, 31)
            self.agent = agent()
            self.agent.event(150, self.key_event)
            #self.agent.event(500, sample_page.next)
        elif Report.Audio_Test:
            sample_page.next()

        Report.Audio_Test = False
        if AudioTest.PlayTest and AudioTest.RecordTest:
            Report.Audio_Test = True
 def load(self):
     if Report.RearSensor_Test:
         sample_page.next()
     if self.is_load == False:
         sipeed_led.init(13, 12, 14, 32)
         sipeed_led.w.value(1)
         sample_page.btn.enable = False
         self.btn = sipeed_button()
         # self.btn.config(23, 20, 31)
         self.get_image = None
         self.isError = None
         self.agent = agent()
         self.agent.event(150, self.check)
         self.agent.event(8000, self.test_event)
         self.is_load = True
 def load(self):
     if Report.Key_Test:
         sample_page.next()
     if self.is_load == False:
         #print(case.load)
         self.is_load = True
         sample_page.btn.enable = False
         sipeed_led.init(13, 12, 14, 32)
         self.btn = sipeed_button()
         # self.btn.config(23, 20, 31)
         self.agent = agent()
         self.agent.event(150, self.key_event)
         self.agent.event(16000, lambda: sample_page.next())
         KeyTest.home_click = 0
         KeyTest.back_click = 0
         KeyTest.next_click = 0
Exemple #7
0
    class test:

        btn = sipeed_button()

        info = 'this is test text.\n change to test.info'

        def info_draw():

            ui.canvas.draw_string(10, 120, test.info, scale=2, mono_space=1)

            if test.info != "working":
                test.info = "working"
                raise Exception(info_draw)

            test.btn.event()
            if test.btn.back() | test.btn.home() | test.btn.next():
                raise Exception(btn)
 def load(self):
     if Report.Audio_Test:
         sample_page.next()
     if self.is_load == False:
         # i2c init()
         sample_page.btn.enable = False
         self.isconnected = False
         self.isError = None
         self.is_play = False
         self.is_record = False
         self.state = 0
         self.fft_amp = None
         self.btn = sipeed_button()
         # self.btn.config(23, 20, 31)
         self.count += 1
         self.agent = agent()
         self.agent.event(150, self.key_event)
         self.agent.event(500, self.check)
         self.agent.event(16000, self.test_event)
         self.is_load = True
Exemple #9
0
class launcher:

  alpha = 0
  app_select = 0
  app_sets = [
      icon(40, 50, os.getcwd() + "/res/icons/app_camera.bmp"),
      icon(140, 50, os.getcwd() + "/res/icons/app_settings.bmp"),
      icon(40, 150, os.getcwd() + "/res/icons/app_explorer.bmp"),
      icon(140, 150, os.getcwd() + "/res/icons/app_system_info.bmp")
  ]

  btn = sipeed_button()
  agent = agent()

  def init():
    launcher.agent.event(150, launcher.key_event)

  def key_event():
    launcher.btn.event()

    if launcher.btn.back() == 1:
        launcher.app_select -= 1
    elif launcher.btn.next() == 1:
        launcher.app_select += 1
    elif launcher.btn.home() == 1:
        print('start', launcher.app_select)
        # ui.canvas.draw_string(15, 120, '(%s)' % launcher.app_sets[launcher.app_select])

    launcher.app_select = launcher.app_select % 4  # lock pos


  def draw():
    launcher.agent.parallel_cycle()

    value = math.cos(math.pi * launcher.alpha / 12) * 50 + 200
    launcher.alpha = (launcher.alpha + 1) % 24

    for pos in range(0, 4):
        checked = (pos == launcher.app_select)
        launcher.app_sets[pos].draw(checked, value if checked else 255)
Exemple #10
0
class CubeListBox:

  btn = sipeed_button()
  files = OS.listdir('/') + ["/"]
  paths = ["/"]
  info = ""

  def load_explorer(path='/'):
    if '../' == path:  # return
        #print(2, CubeListBox.paths, CubeListBox.files)
        CubeListBox.paths.pop(-1)
        if len(CubeListBox.paths) > 1:
            CubeListBox.files = OS.listdir(CubeListBox.get_path(CubeListBox.paths[-1]))
            CubeListBox.files.insert(0, '../')
        else:
            CubeListBox.files = OS.listdir('/')
            CubeListBox.files.insert(0, '/')
        #print(3, CubeListBox.paths, CubeListBox.files)
        return  # !

    if CubeListBox.paths[-1] != path:  # >>>
        if path[0] != '/':
          path = '/' + path
        CubeListBox.paths.append(path)
        #print(0, CubeListBox.get_path(CubeListBox.paths), OS.listdir(CubeListBox.get_path(CubeListBox.paths)))
        CubeListBox.files = OS.listdir(CubeListBox.get_path(CubeListBox.paths))
        CubeListBox.files.insert(0, '../')
        #print(1, CubeListBox.paths, CubeListBox.files)
        return  # !

  def get_path(paths=[]):
      tmp_path = ''
      for p in CubeListBox.paths:
          tmp_path += p if p != '/' else ''
      return tmp_path

  process, state, selected, limit = 0, 1, 0, 4

  def on_draw():

    CubeListBox.btn.expand_event()

    if CubeListBox.btn.next() == 2:
        CubeListBox.selected = CubeListBox.selected - 1
        if CubeListBox.selected < 0:
            CubeListBox.selected = 0
            list_rshift(CubeListBox.files)

    elif CubeListBox.btn.back() == 2:
        CubeListBox.selected = CubeListBox.selected + 1

        real_len = CubeListBox.limit
        if len(CubeListBox.files) < real_len:
            real_len = len(CubeListBox.files)

        if CubeListBox.selected > real_len - 1:
            CubeListBox.selected = real_len - 1
            list_lshift(CubeListBox.files)

    elif CubeListBox.btn.home() == 2:
        tmp = CubeListBox.files[CubeListBox.selected]
        # if tmp == '/':
        #     raise Exception('exit CubeListBox...')
        if tmp in ["../"] or tmp.find('.') == -1:
            CubeListBox.load_explorer(tmp)
            #list_lshift(CubeListBox.files)
        else:
            CubeListBox.info = tmp

    ui.canvas.draw_string(10, 5, str(CubeListBox.get_path(CubeListBox.paths)), scale=1)

    ui.canvas.draw_string(10, 225, str(CubeListBox.info), scale=1)

    CubeListBox.process = CubeListBox.process + 1 % 24
    tmp = 5 * math.cos(CubeListBox.process * (math.pi / 12))

    view_len = len(CubeListBox.files)
    if view_len > CubeListBox.limit:
        view_len = CubeListBox.limit

    for i in range(view_len):
        pos = draw_dialog_alpha(ui.canvas, 20, int(tmp) + 40 + i * 50, 200, 20, 10, color=(0,255,0) if CubeListBox.selected == i else (255, 0, 0), alpha=255 - i * 30)
        ui.canvas.draw_string(pos[0] + 10, pos[1] + 10, CubeListBox.files[i], scale=2, color=(0,0,0))
Exemple #11
0
class app:

    layer = 0  # set help_draw to top
    ctrl = agent()
    btn = sipeed_button()
    loop = 0
    loading = False
    toth = Touch(480, 320, 50)
    touch_select = 0
    msa301 = None
    i2c4 = None

    touch_left = b"\x00\x00\x00\x00\x03\x0F\x3F\xFF\xFF\x3F\x0F\x03\x00\x00\x00\x00\x07\x0F\x3F\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x3F\x0F\x03"
    touch_right = b"\xE0\xF0\xFC\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFC\xF0\xC0\x00\x00\x00\x00\xC0\xF0\xFC\xFF\xFF\xFC\xF0\xC0\x00\x00\x00\x00"
    touch_close = b"\x00\x1C\x3C\x78\x7C\x6E\x07\x03\x03\x07\x6E\x7C\x78\x3C\x1C\x00\x00\x38\x3C\x1E\x3E\x76\xE0\xC0\xC0\xE0\x76\x3E\x1E\x3C\x38\x00"

    def touch_draw():
        app.toth.event()

        app.loop = (app.loop + 1) % 200

        value = math.cos(math.pi * app.loop / 32) * 8

        # temp code
        tmp_x, tmp_l, tmp_r = 0, 0, 0

        if app.toth.state == 2:
            print(app.toth.state, app.toth.points)
            p = app.toth.points[1]
            if p[0] > 430 and p[1] > 260:
                app.layer -= 1
                app.exit_application()
            elif p[0] < 60 and p[1] < 60:
                app.touch_select = -1
                #print(app.touch_select)
                if launcher.app_select == 1:
                    app.current.page -= 1
                elif launcher.app_select == 3:
                    photos.image_last()
                elif launcher.app_select == 0:
                    ai_camera.back()
            elif p[0] > 420 and p[1] < 60:
                app.touch_select = +1
                #print(app.touch_select)
                if launcher.app_select == 1:
                    app.current.page -= 1
                elif launcher.app_select == 3:
                    photos.image_last()
                elif launcher.app_select == 0:
                    ai_camera.next()

        if app.toth.state == 1:
            p = app.toth.points[1]
            if p[0] > 430 and p[1] > 270:
                tmp_x = int(value) + 30
            elif p[0] < 50 and p[1] < 50:
                tmp_l = int(value) + 30
            elif p[0] > 430 and p[1] < 50:
                tmp_r = int(value) + 30

        ui.canvas.draw_circle(ui.height,
                              0,
                              40 + tmp_x,
                              thickness=8,
                              fill=False,
                              color=(100, 100, 100))
        ui.canvas.draw_circle(ui.height,
                              0,
                              38 + tmp_x,
                              fill=True,
                              color=(255, 255, 255))
        #ui.canvas.draw_string(ui.height - 15, 5, "x", scale=2, color=(0, 0, 0))
        ui.canvas.draw_font(ui.height - 22,
                            8,
                            16,
                            16,
                            app.touch_close,
                            scale=1,
                            color=(155, 155, 0))

        ui.canvas.draw_circle(0,
                              ui.weight,
                              40 + tmp_l,
                              thickness=8,
                              fill=False,
                              color=(100, 100, 100))
        ui.canvas.draw_circle(0,
                              ui.weight,
                              38 + tmp_l,
                              fill=True,
                              color=(255, 255, 100))
        #ui.canvas.draw_string(10, ui.weight - 30, "<", scale=2, color=(0, 0, 0))
        ui.canvas.draw_font(8,
                            ui.weight - 25,
                            16,
                            16,
                            app.touch_left,
                            scale=1,
                            color=(155, 155, 0))

        ui.canvas.draw_circle(ui.height,
                              ui.weight,
                              40 + tmp_r,
                              thickness=8,
                              fill=False,
                              color=(100, 100, 100))
        ui.canvas.draw_circle(ui.height,
                              ui.weight,
                              38 + tmp_r,
                              fill=True,
                              color=(100, 255, 255))
        #ui.canvas.draw_string(ui.height - 15, ui.weight - 30, ">", scale=2, color=(0, 0, 0))
        ui.canvas.draw_font(ui.height - 20,
                            ui.weight - 25,
                            16,
                            16,
                            app.touch_right,
                            scale=1,
                            color=(0, 155, 155))

    #@ui.warp_template(CubeAudio.event)
    @ui.warp_template(ui.bg_in_draw)
    #@ui.warp_template(ui.help_in_draw)
    def draw_load():

        app.loop = (app.loop + 1) % 200

        value = math.cos(math.pi * app.loop / 8) * 6

        #print(value)
        if app.loading or app.loop > 20:

            ui.canvas.draw_string(200 - int(value) * 2,
                                  68 + (int(value) % 8) * 2,
                                  "A",
                                  color=(64, 64, 64),
                                  scale=8,
                                  mono_space=0)
            ui.canvas.draw_string(200 - int(value),
                                  72 + (int(value) % 8),
                                  "A",
                                  color=(0x2d, 0x85, 0xf0),
                                  scale=8,
                                  mono_space=0)
        else:
            ui.canvas.draw_string(203,
                                  73,
                                  "A",
                                  color=(64, 64, 64),
                                  scale=8,
                                  mono_space=0)

        if app.loading or app.loop > 40:

            ui.canvas.draw_string(203,
                                  72 - int(value) * 5 - 9,
                                  "  m",
                                  color=(64, 64, 64),
                                  scale=8,
                                  mono_space=0)
            ui.canvas.draw_string(200,
                                  70 - int(value) * 4 - 8,
                                  "  m",
                                  color=(0xf4, 0x43, 0x3c),
                                  scale=8,
                                  mono_space=0)
        else:
            ui.canvas.draw_string(203,
                                  72,
                                  "  m",
                                  color=(64, 64, 64),
                                  scale=8,
                                  mono_space=0)

        if app.loading or app.loop > 40:

            ui.canvas.draw_string(203,
                                  72,
                                  "    i",
                                  color=(64, 64, 64),
                                  scale=8,
                                  mono_space=0)
            ui.canvas.draw_string(200,
                                  70,
                                  "    i",
                                  color=(0xff, 0xbc, 0x32),
                                  scale=8,
                                  mono_space=0)

            ui.canvas.draw_rectangle((304, 77, 12, 12),
                                     color=(0x70, 0x70, 0x70),
                                     fill=True)

            ui.canvas.draw_string(259,
                                  44 + int(value),
                                  "    .    ",
                                  color=(64, 64, 64),
                                  scale=4,
                                  mono_space=0)
            ui.canvas.draw_string(256,
                                  42 + int(value),
                                  "    .    ",
                                  color=(0xff, 0xbc, 0x32),
                                  scale=4,
                                  mono_space=0)
        else:
            ui.canvas.draw_string(203,
                                  72,
                                  "    i",
                                  color=(64, 64, 64),
                                  scale=8,
                                  mono_space=0)
            ui.canvas.draw_rectangle((304, 77, 12, 12),
                                     color=(0x70, 0x70, 0x70),
                                     fill=True)
            ui.canvas.draw_string(259,
                                  44,
                                  "    .    ",
                                  color=(64, 64, 64),
                                  scale=4,
                                  mono_space=0)

        if app.loading or app.loop > 60:

            ui.canvas.draw_string(203 + int(value) * 2 + 10,
                                  72,
                                  "     g",
                                  color=(64, 64, 64),
                                  scale=8,
                                  mono_space=0)
            ui.canvas.draw_string(200 + int(value) * 2 + 10,
                                  70,
                                  "     g",
                                  color=(0x0a + int(value) * 50, 0xa8,
                                         0x58 + int(value) * 50),
                                  scale=8,
                                  mono_space=0)
        else:
            ui.canvas.draw_string(203,
                                  72,
                                  "     g",
                                  color=(64, 64, 64),
                                  scale=8,
                                  mono_space=0)

        if app.loading or app.loop > 60:

            ui.canvas.draw_string(203 - int(value) * 2 + 20,
                                  72,
                                  "       o",
                                  color=(64, 64, 64),
                                  scale=8,
                                  mono_space=0)
            ui.canvas.draw_string(200 - int(value) * 2 + 20,
                                  70,
                                  "       o",
                                  color=(0xf4, 0x43 + int(value) * 50, 0x3c),
                                  scale=8,
                                  mono_space=0)
        else:
            ui.canvas.draw_string(203,
                                  72,
                                  "       o",
                                  color=(64, 64, 64),
                                  scale=8,
                                  mono_space=0)

        if app.loading == False and app.loop < 20:

            ui.canvas.draw_string(203,
                                  73,
                                  "Amigo",
                                  color=(64 + int(value) * 2,
                                         64 + int(value) * 2,
                                         64 + int(value) * 2),
                                  scale=8,
                                  mono_space=0)

        if app.loop > 70:
            app.loading = True
            ui.canvas.draw_string(320,
                                  280,
                                  "Now Loading...",
                                  color=(164 + int(value) * 8,
                                         164 + int(value) * 8,
                                         164 + int(value) * 8),
                                  scale=2,
                                  mono_space=0)

        if app.loop == 100:
            app.layer += 1

        ui.display()

    # @ui.warp_template(ui.bg_in_draw) # ui_3d_launcher need remove
    @ui.warp_template(launcher.draw)
    #@ui.warp_template(taskbar.mem_draw)
    @ui.warp_template(taskbar.battery_draw)
    @ui.warp_template(ui.bg_in_draw)
    def draw_launcher():
        ui.display()

    #@ui.warp_template(CubeAudio.event)
    @ui.warp_template(ui.grey_draw)
    @ui.warp_template(ui.anime_draw)
    @ui.warp_template(touch_draw)
    #@ui.warp_template(CubeAudio.event)
    #@ui.warp_template(taskbar.mem_draw)
    # @ui.warp_template(system_info.info_draw)
    def draw_pages():
        if app.current != None:
            app.current.draw()

        app.loop = (app.loop + 1) % 200

        value = math.cos(math.pi * app.loop / 12) * 2 + 20
        for i in range(100):
            try:
                #ui.canvas.draw_rectangle((240, 0, 240, 320), fill=False, thickness=3, color=(175, 175, 175))
                if app.msa301 != None:
                    accel = app.msa301.acceleration
                    x, y = 240, 160  # center
                    #print(accel)
                    ui.canvas.draw_circle(
                        x + int(accel[0] * 15),
                        y + int(accel[1] * 20),
                        int(value),
                        fill=True,
                        color=(150 + int(accel[0] * 20),
                               150 + int(accel[1] * 20),
                               100 + int(accel[2] * 20)))  # 10ms
                    ui.canvas.draw_circle(x + int(accel[0] * 15),
                                          y + int(accel[1] * 20),
                                          int(value) + 1,
                                          thickness=3,
                                          fill=False,
                                          color=(0, 0, 0))  # 10ms
                else:

                    app.msa301 = MSA301(app.i2c3)
                break
            except Exception as e:
                pass
                # gc.collect()
        #ui.canvas.draw_string(240 + 10, 140, "x", (255, 0, 0), scale=2)
        #ui.canvas.draw_string(240 + 10, 140, "x", (255, 0, 0), scale=2)
        #ui.canvas.draw_line(240 + 120, 150, 120 + int(accel[0] * 8), 150, color=(41, 131, 255))
        #ui.canvas.draw_string(240 + 10, 160, "y", (0, 255, 0), scale=2)
        #ui.canvas.draw_line(240 + 120, 170, 120 + int(accel[1] * 8), 170, color=(141, 31, 255))
        #ui.canvas.draw_string(240 + 10, 180, "z", (0, 0, 255), scale=2)
        #ui.canvas.draw_line(240 + 120, 190, 120 + int(accel[2] * 8), 190, color=(241, 131, 55))

        ui.display()

    photos_title = "/"
    photos_temp = None

    #@ui.warp_template(taskbar.time_draw)
    #@ui.warp_template(sample_page.sample_draw)
    #@ui.warp_template(ui.grey_draw)
    #@ui.warp_template(CubeAudio.event)
    #@ui.warp_template(touch_draw)
    def draw_photos():
        if photos.photos_len() > 0:

            if app.photos_title != photos.image_path():
                app.photos_title = photos.image_path()
                if app.photos_temp != None:
                    tmp = app.photos_temp
                    del tmp
                    app.photos_temp = None
            if app.photos_temp:
                ui.canvas.draw_image(app.photos_temp, 0, 0)
            else:
                app.photos_temp = image.Image(app.photos_title)

            # [mem < 800*1024]
            #t, ui.canvas = ui.canvas, None
            #del t
            #ui.canvas = image.Image(photos.image_path())

            ui.canvas.draw_string(2,
                                  2,
                                  app.photos_title,
                                  color=(255, 255, 255),
                                  scale=1,
                                  mono_space=0)
        else:
            ui.canvas.draw_string(40,
                                  120,
                                  "Please put pictures\n in '/sd/imgs' folder",
                                  color=(255, 255, 255),
                                  scale=3,
                                  mono_space=0)
        app.touch_draw()
        ui.display()

    sht3x = None
    sidu = None
    temp = 0
    points = []
    isconnected = False

    @ui.warp_template(touch_draw)
    #@ui.warp_template(taskbar.mem_draw)
    #@ui.warp_template(taskbar.time_draw)
    @ui.warp_template(CubeAudio.event)
    #@ui.warp_template(explorer.draw)
    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

    def draw_camera():
        try:
            gc.collect()
            ai_camera.ai_draw()
            for model in ai_camera.models:
                #print(model.__qualname__, ai_camera.model.__qualname__)
                if 'ai_sample' == ai_camera.model.__qualname__:
                    ui.canvas.draw_string(340, 80, "  AI\nDemo", scale=5)
                    ui.canvas.draw_string(
                        50,
                        260,
                        "Press Left (<) or Right (>) to View",
                        scale=2)
                    pass

                elif 'FaceDetect' == ai_camera.model.__qualname__:

                    if ai_camera.model.bbox != None:
                        bbox = ai_camera.model.bbox
                        ui.canvas.draw_string(50,
                                              260,
                                              "Face Detect %d" % len(bbox),
                                              scale=5)
                        for pos in range(len(bbox)):
                            i = bbox[pos]
                            # print(i.x(), i.y(), i.w(), i.h())
                            face_cut = ui.canvas.cut(i.x(), i.y(), i.w(),
                                                     i.h())
                            face_cut_128 = face_cut.resize(80, 80)
                            ui.canvas.draw_image(face_cut_128, 320 + int(
                                (pos % 2) * 80), int((pos // 2) * 80))
                    else:
                        ui.canvas.draw_string(50, 260, "Find Detect", scale=5)

                elif 'FaceReco' == ai_camera.model.__qualname__:
                    ui.canvas.draw_string(50, 260, "Face Recognition", scale=5)

                elif 'find_color' == ai_camera.model.__qualname__:

                    ui.canvas.draw_string(
                        50,
                        260,
                        "Find Color For Red (53, 31, 44, 82, 18, 78)",
                        scale=2)
                    ui.canvas.draw_string(50,
                                          260,
                                          "                         Red",
                                          color=(255, 0, 0),
                                          scale=2)

                    ui.canvas.draw_string(340,
                                          30,
                                          "Red\nSum\n  %d" %
                                          len(ai_camera.model.blobs),
                                          scale=5)

                elif 'HowMany' == ai_camera.model.__qualname__:

                    if ai_camera.model.things != None:
                        ui.canvas.draw_string(340,
                                              30,
                                              "How\nMany\n  %d" %
                                              len(ai_camera.model.things),
                                              scale=5)

                    ui.canvas.draw_string(50,
                                          260,
                                          "How many things are there?",
                                          scale=2)

                elif 'MaybeIs' == ai_camera.model.__qualname__:

                    ui.canvas.draw_string(340, 50, "Maybe\n   Is\n", scale=3)
                    ui.canvas.draw_string(340,
                                          150,
                                          "%s" % str(ai_camera.model.result),
                                          scale=2)
                    ui.canvas.draw_string(50,
                                          260,
                                          "What is likely to be?",
                                          scale=2)

                elif 'MoblieNet' == ai_camera.model.__qualname__:

                    ui.canvas.draw_string(340,
                                          50,
                                          "MoblieNet\n   1000class\n",
                                          scale=3)
                    ui.canvas.draw_string(340,
                                          150,
                                          "What is likely to be?",
                                          scale=2)

            app.touch_draw()
            ui.display()
        except Exception as e:
            # ai_camera.next()
            # protect.restart() # temp patch
            app.layer -= 1
            raise e
            #raise Exception("This is a Easter egg(Known Bug) This error requires a  restart. It will soon be resolved. :)")

    current = None

    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()

    def exec_application():
        try:
            if launcher.app_select == 0:
                app.draw_camera()
            if launcher.app_select == 1:
                app.draw_pages()
            if launcher.app_select == 2:
                app.draw_demo()
            if launcher.app_select == 3:
                app.draw_photos()
        except Exception as e:
            app.layer -= 1
            raise e

    def exit_application():
        try:
            if launcher.app_select == 0:
                ai_camera.exit()
                ai_camera.jump(0)
                ai_camera.reload()
            elif launcher.app_select == 1:
                pass
            elif launcher.app_select == 2:
                t, app.sidu = app.sidu, None  # Clear
                del t
            elif launcher.app_select == 3:
                t, app.photos_temp = app.photos_temp, None  # Clear
                del t
        except Exception as e:
            app.layer -= 1
            raise e

    rgb = 0

    def rgb_change(rgb):
        sipeed_led.r.value(rgb & 0b001)
        sipeed_led.g.value(rgb & 0b010)
        sipeed_led.b.value(rgb & 0b100)

    def on_event():
        #app.btn.event()
        app.btn.expand_event()
        if app.btn.home(
        ) == 2 or launcher.app_run:  # click button release to 2
            launcher.app_run = False
            # print('into', app.layer)
            if app.layer == 1:
                app.layer += 1
                # launcher into application
                app.load_application(launcher.app_select)
            elif app.layer == 2:
                if app.btn.interval() > 1000:  # long press
                    app.layer -= 1
                    app.exit_application()
                # application return launcher
            else:
                app.layer += 1
                # help into launcher
        #launcher.btn.enable = True

        #if launcher.app_run:
        #launcher.app_run = False
        #print('launcher.app_select', launcher.app_select)

        if app.btn.next() == 1:
            app.rgb = (app.rgb + 1) % 8
            app.rgb_change(app.rgb)
            if launcher.app_select == 3:
                photos.image_next()

        if app.btn.back() == 1:
            app.rgb = (app.rgb - 1) % 8
            app.rgb_change(app.rgb)
            if launcher.app_select == 3:
                photos.image_last()

    @ui.warp_template(ui.blank_draw)
    #@ui.warp_template(ui.grey_draw)
    @catch
    def draw():
        app.on_event()
        ui.canvas.draw_rectangle((0, 0, ui.height, ui.weight),
                                 fill=True,
                                 color=(0x70, 0x70, 0x70))

        # gc.collect()
        if app.layer == 0:
            app.draw_load()
        elif app.layer == 1:
            app.draw_launcher()
        elif app.layer == 2:
            app.exec_application()

    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)
Exemple #12
0
class app:

    layer = 0 # set help_draw to top
    ctrl = agent()
    btn = sipeed_button()


    @ui.warp_template(ui.bg_in_draw)
    @ui.warp_template(ui.help_in_draw)
    def draw_load():
        ui.display()

    #
    #@ui.warp_template(ui.bg_in_draw) # ui_3d_launcher need remove
    @ui.warp_template(CubeAudio.event)
    @ui.warp_template(taskbar.battery_draw)
    @ui.warp_template(CubeAudio.event)
    @ui.warp_template(launcher.draw)
    @ui.warp_template(CubeAudio.event)
    def draw_launcher():
        ui.display()

    #
    @ui.warp_template(CubeAudio.event)
    @ui.warp_template(ui.anime_draw)
    @ui.warp_template(CubeAudio.event)
    @ui.warp_template(taskbar.mem_draw)
    @ui.warp_template(CubeAudio.event)
    # @ui.warp_template(system_info.info_draw)
    def draw_pages():
        if app.current != None:
            app.current.draw()
        ui.display()


    @ui.warp_template(taskbar.time_draw)
    @ui.warp_template(sample_page.sample_draw)
    def draw_samples():
        ui.display()

    @ui.warp_template(CubeAudio.event)
    @ui.warp_template(explorer.draw)
    @ui.warp_template(CubeAudio.event)
    def draw_explorer():
        # if explorer.info != "":
        #     protect.stop()
        #     print(explorer.get_path(explorer.paths) + '/' + explorer.info)
        #     # with open(explorer.get_path(explorer.paths) + '/' + tmp, 'rb') as target:
        #     #     # exec(target.read(), locals())
        #     #     exec(target.read())
        #     execfile(explorer.get_path(explorer.paths) + '/' + explorer.info)
        #     protect.start()
        ui.display()

    def draw_camera():
        try:
            ai_camera.ai_draw()
            ui.display()
        except Exception as e:
            app.layer = 1
            raise e

    current = None

    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:
            sample_page.add_sample(sample_shtxx())
            sample_page.add_demo()


    @ui.warp_template(CubeAudio.event)
    def exec_application():
        if launcher.app_select == 0:
            app.draw_camera()
        if launcher.app_select == 1:
            app.draw_pages()
        if launcher.app_select == 2:
            app.draw_explorer()
        if launcher.app_select == 3:
            try:
                app.draw_samples()
            except Exception as e:
                app.layer -= 1

    rgb = 0
    def rgb_change(rgb):
        sipeed_led.r.value(rgb & 0b001)
        sipeed_led.g.value(rgb & 0b010)
        sipeed_led.b.value(rgb & 0b100)

    @ui.warp_template(CubeAudio.event)
    @ui.warp_template(ui.grey_draw)
    @ui.warp_template(CubeAudio.event)
    @catch
    def draw():
        #app.btn.event()
        app.btn.expand_event()

        if app.btn.home() == 2: # click button release to 2
            print('into', app.layer)
            if app.layer == 0:
                #CubeAudio.load("/flash/one.wav", 75)
                pass
            if app.layer == 1:
                app.layer += 1
                # launcher into application
                app.load_application(launcher.app_select)
            elif app.layer == 2:
                if app.btn.interval() > 1000: # long press
                    app.layer -= 1
                # application return launcher
            else:
                app.layer += 1
                # help into launcher

        if app.btn.next() == 1:
            app.rgb = (app.rgb + 1) % 8
            app.rgb_change(app.rgb)

        if app.btn.back() == 1:
            app.rgb = (app.rgb - 1) % 8
            app.rgb_change(app.rgb)

        if app.layer == 0:
            app.draw_load()
        elif app.layer == 1:
            app.draw_launcher()
        elif app.layer == 2:
            app.exec_application()

    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)
Exemple #13
0
class app:

    layer = 0  # set help_draw to top
    ctrl = agent()
    btn = sipeed_button()

    @ui.warp_template(ui.bg_in_draw)
    @ui.warp_template(ui.help_in_draw)
    def draw_load():
        ui.display()

    # @ui.warp_template(ui.bg_in_draw) # ui_3d_launcher need remove
    @ui.warp_template(launcher.draw)
    #@ui.warp_template(taskbar.mem_draw)
    @ui.warp_template(taskbar.battery_draw)
    # @ui.warp_template(taskbar.mem_draw)
    def draw_launcher():
        ui.display()

    @ui.warp_template(CubeAudio.event)
    @ui.warp_template(ui.anime_draw)
    @ui.warp_template(CubeAudio.event)
    @ui.warp_template(taskbar.mem_draw)
    # @ui.warp_template(system_info.info_draw)
    def draw_pages():
        if app.current != None:
            app.current.draw()
        ui.display()

    @ui.warp_template(CubeAudio.event)
    @ui.warp_template(taskbar.time_draw)
    @ui.warp_template(sample_page.sample_draw)
    @ui.warp_template(CubeAudio.event)
    def draw_samples():
        ui.display()

    @ui.warp_template(explorer.draw)
    def draw_explorer():
        # if explorer.info != "":
        #     protect.stop()
        #     print(explorer.get_path(explorer.paths) + '/' + explorer.info)
        #     # with open(explorer.get_path(explorer.paths) + '/' + tmp, 'rb') as target:
        #     #     # exec(target.read(), locals())
        #     #     exec(target.read())
        #     execfile(explorer.get_path(explorer.paths) + '/' + explorer.info)
        #     protect.start()

        ui.display()

    def draw_camera():
        try:
            ai_camera.ai_draw()
            for model in ai_camera.models:
                #print(model.__qualname__, ai_camera.model.__qualname__)
                if 'ai_sample' == ai_camera.model.__qualname__:
                    ui.canvas.draw_string(60, 170, "AI Demo", scale=3)
                    ui.canvas.draw_string(10,
                                          210,
                                          "Press (<) or (>) to View",
                                          scale=2)
                    pass

                elif 'FaceReco' == ai_camera.model.__qualname__:

                    if ai_camera.model.bbox != None:
                        bbox = ai_camera.model.bbox
                        ui.canvas.draw_string(10,
                                              210,
                                              "Find Face %d" % len(bbox),
                                              scale=2)
                    else:
                        ui.canvas.draw_string(10,
                                              210,
                                              "Find Face Reco",
                                              scale=2)

                elif 'find_color' == ai_camera.model.__qualname__:

                    ui.canvas.draw_string(10,
                                          210,
                                          "Find Color For Red", (255, 0, 0),
                                          scale=2)

                elif 'HowMany' == ai_camera.model.__qualname__:

                    if ai_camera.model.things != None:
                        ui.canvas.draw_string(10,
                                              210,
                                              "How many %d" %
                                              len(ai_camera.model.things),
                                              scale=2)

                    ui.canvas.draw_string(10, 210, "How many?", scale=2)

                elif 'MaybeIs' == ai_camera.model.__qualname__:

                    ui.canvas.draw_string(10,
                                          210,
                                          "Maybe Is %s" %
                                          str(ai_camera.model.result),
                                          scale=2)

            ui.display()
        except Exception as e:
            app.layer = 1
            gc.collect()
            raise e

    current = None

    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()

    def exec_application():
        if launcher.app_select == 0:
            app.draw_camera()
        if launcher.app_select == 1:
            app.draw_pages()
        if launcher.app_select == 2:
            app.draw_explorer()
        if launcher.app_select == 3:
            try:
                app.draw_samples()
            except Exception as e:
                app.layer -= 1

    rgb = 0

    def rgb_change(rgb):
        sipeed_led.r.value(rgb & 0b001)
        sipeed_led.g.value(rgb & 0b010)
        sipeed_led.b.value(rgb & 0b100)

    @ui.warp_template(ui.blank_draw)
    #@ui.warp_template(ui.grey_draw)
    @catch
    def draw():
        ui.canvas.draw_rectangle((0, 0, ui.height, ui.weight),
                                 fill=True,
                                 color=(10, 10, 10))

        #app.btn.event()
        app.btn.expand_event()

        if app.btn.home() == 2:  # click button release to 2
            print('into', app.layer)
            if app.layer == 1:
                app.layer += 1
                # launcher into application
                app.load_application(launcher.app_select)
            elif app.layer == 2:
                if app.btn.interval() > 1000:  # long press
                    app.layer -= 1
                    if launcher.app_select == 1:
                        ui.anime = None  # Clear
                # application return launcher
            else:
                app.layer += 1
                # help into launcher

        if app.btn.next() == 1:
            app.rgb = (app.rgb + 1) % 8
            app.rgb_change(app.rgb)

        if app.btn.back() == 1:
            app.rgb = (app.rgb - 1) % 8
            app.rgb_change(app.rgb)

        if app.layer == 0:
            app.draw_load()
        elif app.layer == 1:
            # gc.collect()
            app.draw_launcher()
        elif app.layer == 2:
            app.exec_application()

    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)
Exemple #14
0
class explorer:

    btn = sipeed_button()
    files = OS.listdir('/') + ["/"]
    paths = ["/"]
    info = ""

    def load_explorer(path='/'):
        if '../' == path:  # return
            #print(2, explorer.paths, explorer.files)
            explorer.paths.pop(-1)
            if len(explorer.paths) > 1:
                explorer.files = OS.listdir(
                    explorer.get_path(explorer.paths[-1]))
                explorer.files.insert(0, '../')
            else:
                explorer.files = OS.listdir('/')
                explorer.files.insert(0, '/')
            #print(3, explorer.paths, explorer.files)
            return  # !

        if explorer.paths[-1] != path:  # >>>
            if path[0] != '/':
                path = '/' + path
            explorer.paths.append(path)
            #print(0, explorer.get_path(explorer.paths), OS.listdir(explorer.get_path(explorer.paths)))
            explorer.files = OS.listdir(explorer.get_path(explorer.paths))
            explorer.files.insert(0, '../')
            #print(1, explorer.paths, explorer.files)
            return  # !

    def get_path(paths=[]):
        tmp_path = ''
        for p in explorer.paths:
            tmp_path += p if p != '/' else ''
        return tmp_path

    def draw():
        explorer.btn.event()

        if explorer.btn.back() == 2:
            list_rshift(explorer.files)
        elif explorer.btn.next() == 2:
            list_lshift(explorer.files)
        elif explorer.btn.home() == 2:
            tmp = explorer.files[0]
            # if tmp == '/':
            #     raise Exception('exit explorer...')
            if tmp in ["../"] or tmp.find('.') == -1:
                explorer.load_explorer(tmp)
                list_lshift(explorer.files)
            else:
                explorer.info = tmp

        ui.canvas.draw_rectangle((0, 0, 240, 240),
                                 fill=True,
                                 color=(50, 50, 50))

        ui.canvas.draw_string(10,
                              5,
                              str(explorer.get_path(explorer.paths)),
                              scale=1)

        ui.canvas.draw_string(10, 225, str(explorer.info), scale=1)

        list_size = len(explorer.files)

        if list_size > 4:
            tmp = (150, 150, 150)
            ui.canvas.draw_rectangle((65, 25, 200, 25),
                                     fill=True,
                                     color=(75, 75, 75))
            ui.canvas.draw_string(70,
                                  30,
                                  str(explorer.files[-2]),
                                  scale=1,
                                  color=tmp)
            ui.canvas.draw_rectangle((65, 195, 200, 25),
                                     fill=True,
                                     color=(75, 75, 75))
            ui.canvas.draw_string(70,
                                  200,
                                  str(explorer.files[+2]),
                                  scale=1,
                                  color=tmp)

        if list_size > 2:
            tmp = (200, 200, 200)
            ui.canvas.draw_rectangle((45, 55, 200, 35),
                                     fill=True,
                                     color=(100, 100, 100))
            ui.canvas.draw_string(50,
                                  60,
                                  str(explorer.files[-1]),
                                  scale=2,
                                  color=tmp)
            ui.canvas.draw_rectangle((45, 155, 200, 35),
                                     fill=True,
                                     color=(100, 100, 100))
            ui.canvas.draw_string(50,
                                  160,
                                  str(explorer.files[+1]),
                                  scale=2,
                                  color=tmp)

        if list_size > 0:
            tmp = (255, 255, 255)
            #ui.canvas.draw_ellipse(120, 120, 200, 25, 0, color=(226, 205, 223), thickness=2, fill=True)
            ui.canvas.draw_rectangle((20, 95, 220, 55),
                                     fill=True,
                                     color=(0x5b, 0x86, 0xec))
            ui.canvas.draw_string(30,
                                  105,
                                  str(explorer.files[0]),
                                  scale=3,
                                  color=tmp)
Exemple #15
0
class FaceReco():

    is_load = False
    img_face = None
    task_fd, task_ld, task_fe = None, None, None
    record_ftr = []
    record_ftrs = []
    btn = sipeed_button()
    names = ['Mr.1', 'Mr.2', 'Mr.3', 'Mr.4', 'Mr.5', 'Mr.6', 'Mr.7', 'Mr.8']
    dst_point = [(44, 59), (84, 59), (64, 82), (47, 105),
                 (81, 105)]  # standard face key point position
    start_processing = False

    def set_key_state(*_):
        FaceReco.start_processing = True

    def load():
        if FaceReco.is_load == False:
            FaceReco.task_fd = kpu.load(0x2C0000)
            FaceReco.task_ld = kpu.load(0x580000)
            FaceReco.task_fe = kpu.load(0x340000)

            a = kpu.init_yolo2(FaceReco.task_fd, 0.5, 0.3, 5, anchor)

            FaceReco.img_face = image.Image(size=(128, 128))
            a = FaceReco.img_face.pix_to_ai()

            FaceReco.start_processing = False

            from Maix import GPIO
            button_io.home_button.irq(
                FaceReco.set_key_state, GPIO.IRQ_RISING, GPIO.WAKEUP_NOT_SUPPORT)

            FaceReco.is_load = True

    def work(img):
        img.pix_to_ai()

        code = kpu.run_yolo2(FaceReco.task_fd, img)
        if code:
            #for i in code:
            start = 0
            for pos in range(len(code)):
                i = code[pos]
                #print(i)
                # Cut face and resize to 128x128
                a = img.draw_rectangle(i.x(), i.y(), i.w(), i.h())
                face_cut = img.cut(i.x(), i.y(), i.w(), i.h())
                face_cut_128 = face_cut.resize(128, 128)
                a = face_cut_128.pix_to_ai()

                #a = ui.canvas.draw_image(face_cut, (320,0))
                #print(i)

                # Landmark for face 5 points
                fmap = kpu.forward(FaceReco.task_ld, face_cut_128)
                plist = fmap[:]
                le = (int(i.x() + plist[0]*i.w() - 5),
                      int(i.y() + plist[1]*i.h()))
                re = (int(i.x() + plist[2]*i.w()), int(i.y() + plist[3]*i.h()))
                nose = (int(i.x() + plist[4]*i.w()),
                        int(i.y() + plist[5]*i.h()))
                lm = (int(i.x() + plist[6]*i.w()), int(i.y() + plist[7]*i.h()))
                rm = (int(i.x() + plist[8]*i.w()), int(i.y() + plist[9]*i.h()))
                #print(le, re, nose, lm, rm)
                a = img.draw_circle(int(le[0]), int(le[1]), 2)
                a = img.draw_circle(int(re[0]), int(re[1]), 2)
                a = img.draw_circle(int(nose[0]), int(nose[1]), 2)
                a = img.draw_circle(int(lm[0]), int(lm[1]), 2)
                a = img.draw_circle(int(rm[0]), int(rm[1]), 2)
                # align face to standard position
                src_point = [le, re, nose, lm, rm]
                T = image.get_affine_transform(src_point, FaceReco.dst_point)
                a = image.warp_affine_ai(img, FaceReco.img_face, T)
                a = FaceReco.img_face.ai_to_pix()
                #a = ui.canvas.draw_image(FaceReco.img_face, (320,128))

                if ui.height > 240:
                    gc.collect()
                    tmp = face_cut_128.resize(80, 80)
                    #a = ui.canvas.draw_image(face_cut_128, (start, 240))
                    ui.canvas.draw_image(
                        tmp, 320 + int((pos % 2)*80), int((pos // 2)*80))
                    del(tmp)
                    #start = start + 80
                del(face_cut_128)

                # calculate face feature vector
                fmap = kpu.forward(FaceReco.task_fe, FaceReco.img_face)
                feature = kpu.face_encode(fmap[:])
                reg_flag = False
                scores = []
                for j in range(len(FaceReco.record_ftrs)):
                   score = kpu.face_compare(FaceReco.record_ftrs[j], feature)
                   scores.append(score)
                max_score = 0
                index = 0
                for k in range(len(scores)):
                   if max_score < scores[k]:
                       max_score = scores[k]
                       index = k
                if max_score > 85:
                    a = img.draw_string(i.x(), i.y(), ("%s:%2.1f" % (
                        FaceReco.names[index], max_score)), color=(0, 255, 0), scale=2)
                    if ui.height > 240:
                        a = ui.canvas.draw_string(100 * (pos % 3), 240 + 30 * (pos // 3), ("%s :%2.1f" % (
                            FaceReco.names[index], max_score)), color=(0, 255, 0), scale=2)
                else:
                    a = img.draw_string(i.x(), i.y(), ("X:%2.1f" % (
                        max_score)), color=(255, 0, 0), scale=2)
                    if ui.height > 240:
                        a = ui.canvas.draw_string(100 * (pos % 3), 240 + 30 * (pos // 3), ("X :%2.1f" % (
                            max_score)), color=(255, 0, 0), scale=2)

                if FaceReco.start_processing:
                    FaceReco.record_ftr = feature
                    if len(FaceReco.record_ftrs) == len(FaceReco.names):
                        FaceReco.record_ftrs = []
                    FaceReco.record_ftrs.append(FaceReco.record_ftr)
                    FaceReco.start_processing = False

        # img.draw_string(10, 2, 'FaceReco free %d kb' % (
        #     utils.heap_free() / 1024), (127, 255, 255), scale=2)

    def free():
        try:
            if FaceReco.is_load:
                tmp = kpu.deinit(FaceReco.task_fd)
                tmp = kpu.deinit(FaceReco.task_ld)
                tmp = kpu.deinit(FaceReco.task_fe)
                #t, FaceReco.task_fd = FaceReco.task_fd, None
                #del t
                #t, FaceReco.task_ld = FaceReco.task_ld, None
                #del t
                #t, FaceReco.task_fe = FaceReco.task_fe, None
                #del t
                t, FaceReco.img_face = FaceReco.img_face, None
                del t

                FaceReco.record_ftr = []
                FaceReco.record_ftrs = []

                button_io.home_button.disirq()
                FaceReco.start_processing = False

                FaceReco.is_load = False
                gc.collect()
        except Exception as e:
            print(e)  # see py_kpu_deinit error will mp_raise_TypeError
Exemple #16
0
 def __init__(self):
     self.btn = sipeed_button()
     self.page_info = sys_info()
     self.page = 0
     self.tips = "Weclome to MaixCube"
Exemple #17
0
class launcher:

    effect = []
    alpha = 0
    app_select = 0
    app_run = False
    app_sets = [
        Camera(60, 200),
        System(160, 200),
        Demo(260, 200),
        Photo(360, 200),
    ]

    toth = Touch(480, 320, 50)
    btn = sipeed_button()
    agent = agent()

    def init():
        launcher.agent.event(150, launcher.key_event)
        launcher.agent.event(50, launcher.touch_event)

    def touch_event():
        launcher.toth.event()
        #print(launcher.toth.state, launcher.toth.points)
        if launcher.toth.state == 1:
            old = launcher.toth.points[0]
            sel = launcher.toth.points[1]
            #if len(launcher.effect) > 8:
            #launcher.effect.pop(0)
            #launcher.effect.append((old[0], old[1]))
            if 250 < sel[2] - old[2] and sel[2] - old[2] < 500:
                launcher.toth.state = 2
        if launcher.toth.state == 2:
            #print(launcher.toth.state, launcher.toth.points)
            #launcher.effect = []
            old = launcher.toth.points[0]
            sel = launcher.toth.points[1]
            #print(sel, old, sel[2] - old[2])
            if sel[2] - old[2] < 1000:
                # start
                #if 136 < sel[1] and sel[1] < 200:
                for i in range(len(launcher.app_sets)):
                    p = launcher.app_sets[i]
                    x, y = p.x, 320 - p.y
                    # print(x, p.w, y, p.h)
                    if x < sel[0] and sel[1] < y and sel[
                            0] < x + p.w and y - p.h < sel[1]:
                        launcher.app_select = i
                        if sel[2] - old[2] < 250:
                            print('launcher.app_select', launcher.app_select)
                            launcher.app_run = True

    def key_event():
        launcher.btn.event()

        if launcher.btn.back() == 1:
            launcher.app_select -= 1
        elif launcher.btn.next() == 1:
            launcher.app_select += 1
        elif launcher.btn.home() == 1:
            print('start', launcher.app_select)
            # launcher.app_run = True
            # ui.canvas.draw_string(15, 120, '(%s)' % launcher.app_sets[launcher.app_select])

        launcher.app_select = launcher.app_select % len(
            launcher.app_sets)  # lock pos

    a = b'\x00\x00\x03\x03\x07\x07\x0E\x0E\x1C\x1F\x38\x38\x70\xF0\x00\x00\x00\x00\xC0\xC0\xE0\xE0\x70\x70\x38\xF8\x1C\x1C\x0E\x0F\x00\x00'
    m = b'\x00\x00\x00\x00\x00\x67\x7F\x61\x61\x61\x61\x61\x61\x61\x00\x00\x00\x00\x00\x00\x00\x1C\xFE\x86\x86\x86\x86\x86\x86\x86\x00\x00'
    i = b'\x00\x00\x01\x00\x00\x01\x01\x01\x01\x01\x01\x01\x01\x01\x00\x00\x00\x00\x80\x00\x00\x80\x80\x80\x80\x80\x80\x80\x80\x80\x00\x00'
    g = b'\x00\x00\x00\x00\x00\x07\x1C\x18\x38\x1C\x1F\x30\x1F\x30\x70\x1F\x00\x00\x00\x00\x00\xCE\x72\x30\x38\x70\xC0\x00\xF8\x0C\x0E\xF8'
    o = b'\x00\x00\x00\x00\x00\x03\x1E\x38\x70\x70\x70\x38\x1C\x03\x00\x00\x00\x00\x00\x00\x00\xC0\x78\x1C\x0C\x0E\x0E\x1C\x38\xC0\x00\x00'

    def draw():
        launcher.agent.parallel_cycle()

        #ui.canvas.draw_rectangle((0, 0, ui.height, ui.weight),
        #fill = True, color = (0, 0, 0))
        #ui.canvas.draw_rectangle((0, 0, ui.height, ui.weight), fill = True, color = (0x70, 0x80, 0x90))
        ui.canvas.draw_rectangle((0, 0, ui.height, ui.weight),
                                 fill=True,
                                 color=(215, 228, 181))
        #ui.canvas.draw_rectangle((0, 0, ui.height, ui.weight),
        #fill = True, color = (37, 40, 55))
        #ui.canvas.draw_string(203, 73, "Amigo",
        #color=(64, 64, 64), scale=8, mono_space=0)
        ui.canvas.draw_font(182,
                            82,
                            16,
                            16,
                            launcher.a,
                            scale=5,
                            color=(37, 40, 55))
        ui.canvas.draw_font(180,
                            80,
                            16,
                            16,
                            launcher.a,
                            scale=5,
                            color=(0x2d, 0x85, 0xf0))
        ui.canvas.draw_font(252,
                            82,
                            16,
                            16,
                            launcher.m,
                            scale=4,
                            color=(37, 40, 55))
        ui.canvas.draw_font(250,
                            80,
                            16,
                            16,
                            launcher.m,
                            scale=4,
                            color=(0xf4, 0x43, 0x3c))
        ui.canvas.draw_font(292,
                            82,
                            16,
                            16,
                            launcher.i,
                            scale=4,
                            color=(37, 40, 55))
        ui.canvas.draw_font(290,
                            80,
                            16,
                            16,
                            launcher.i,
                            scale=4,
                            color=(0xff, 0xbc, 0x32))
        ui.canvas.draw_font(332,
                            77,
                            16,
                            16,
                            launcher.g,
                            scale=4,
                            color=(37, 40, 55))
        ui.canvas.draw_font(330,
                            75,
                            16,
                            16,
                            launcher.g,
                            scale=4,
                            color=(0x0a, 0xa8, 0x58))
        ui.canvas.draw_font(392,
                            82,
                            16,
                            16,
                            launcher.o,
                            scale=4,
                            color=(37, 40, 55))
        ui.canvas.draw_font(390,
                            80,
                            16,
                            16,
                            launcher.o,
                            scale=4,
                            color=(0xf4, 0x43, 0x3c))
        #ui.canvas.draw_string(200, 70, "A",
        #color=(0x2d, 0x85, 0xf0), scale=8, mono_space=0)
        #ui.canvas.draw_string(200, 70, "  m",
        #color=(0xf4, 0x43, 0x3c), scale=8, mono_space=0)
        #ui.canvas.draw_string(200, 70, "    i",
        #color=(0xff, 0xbc, 0x32), scale=8, mono_space=0)
        #ui.canvas.draw_string(200, 70, "     g",
        #color=(0x0a, 0xa8, 0x58), scale=8, mono_space=0)
        #ui.canvas.draw_string(200, 70, "       o",
        #color=(0xf4, 0x43, 0x3c), scale=8, mono_space=0)

        value = math.cos(math.pi * launcher.alpha / 12) * 50 + 200
        launcher.alpha = (launcher.alpha + 1) % 24

        for pos in range(0, len(launcher.app_sets)):
            checked = (pos == launcher.app_select)
            launcher.app_sets[pos].draw(checked, value if checked else 255)

        #for pos in range(len(launcher.effect)):
        #tmp = launcher.effect[pos]
        #cor = (pos + 1) * 32
        #ui.canvas.draw_circle(tmp[0], 320 - tmp[1], (pos + 1) * 3, thickness=1, fill=False, color=(cor, cor, cor))

        launcher.agent.parallel_cycle()
Exemple #18
0
class launcher:

    alpha = 0
    app_select = 0
    app_sets = [
        icon(40, 50,
             os.getcwd() + "/res/icons/app_camera.bmp"),
        icon(140, 50,
             os.getcwd() + "/res/icons/app_settings.bmp"),
        icon(40, 150,
             os.getcwd() + "/res/icons/app_explorer.bmp"),
        icon(140, 150,
             os.getcwd() + "/res/icons/app_system_info.bmp")
    ]

    btn = sipeed_button()
    agent = agent()

    def init():
        launcher.agent.event(100, launcher.key_event)

    def key_event():
        launcher.btn.event()

        if launcher.btn.back() == 1:
            if launcher.goal == 0:
                launcher.goal = -30
        elif launcher.btn.next() == 1:
            if launcher.goal == 0:
                launcher.goal = +30
        # elif launcher.btn.home() == 2:
        #     print('start', launcher.app_select)

        # ui.canvas.draw_string(15, 120, '(%s)' % launcher.app_sets[launcher.app_select])

        #launcher.goal = launcher.goal % 120 # lock pos

    pos, goal = 0, 0

    def load(app_pos, app_select):
        pos = app_pos * (math.pi / 60)
        tmp = (120 * math.sin(pos), 30 * math.cos(pos + 0.35))

        #ui.canvas.draw_line(120, 100, 120 + int(tmp[0]), 120 + int(tmp[1]), color=(150, 150, 150))
        #ui.canvas.draw_circle((100, 60, 5), color=(255, 136, 210))
        #ui.canvas.draw_line(100, 60, 100, 100, color=(255, 136, 210))

        x, y = (120 + int(tmp[0] - 30)), (120 + int(tmp[1] - 30))
        s = (y / 120) * 1.5
        #if int(y * s - y - 60) > 0:
        alpha = int((y / 100)**4 * 100 + 40)
        # print('alpha', alpha)
        launcher.app_sets[app_select].draw(is_check=False,
                                           alpha=alpha,
                                           x=x - 15,
                                           y=int(y * s - y),
                                           scale=s)

    def draw():
        launcher.agent.parallel_cycle()
        launcher.app_select = int(launcher.pos / 30)

        if launcher.goal == 0:
            pass
        elif launcher.goal > 0:
            launcher.goal -= 5
            launcher.pos += 5
        elif launcher.goal < 0:
            launcher.goal += 5
            launcher.pos -= 5

        launcher.pos = launcher.pos % 120  # lock pos

        value = (launcher.pos % 30)

        color = (100 + 5 * value, 100 + 5 * value, 100 + 5 * value)
        #print(color)
        ui.canvas.draw_ellipse(130,
                               150,
                               90 + (value % 20 - 10),
                               40 + (value % 20 - 10),
                               -10,
                               color=color,
                               thickness=2 + value % 5,
                               fill=False)
        # gc.collect()
        launcher.load(launcher.pos, 0)
        launcher.load(launcher.pos - 30, 1)
        launcher.load(launcher.pos - 60, 2)
        launcher.load(launcher.pos - 90, 3)
Exemple #19
0
    def warp(warp=None):
        try:
            func()
        except Exception as e:
            try:
                btn = sipeed_button()

                import uio
                string_io = uio.StringIO()
                sys.print_exception(e, string_io)
                s = string_io.getvalue()
                ui.canvas.draw_rectangle(
                    (10, 10, ui.height - 20, ui.weight - 20),
                    fill=True,
                    color=(50, 50, 50))
                msg = "** " + str(e)
                chunks, chunk_size = len(msg), 29
                msg_lines = [
                    msg[i:i + chunk_size]
                    for i in range(0, chunks, chunk_size)
                ]
                x_offset, y_offset = 10 + 5, 20
                ui.canvas.draw_string(x_offset + 24,
                                      y_offset + 5,
                                      "A problem has been detected",
                                      color=(0, 255, 0))
                ui.canvas.draw_string(x_offset + 3, y_offset + 16,
                                      "------------------------------",
                                      (255, 255, 255))

                current_y = y_offset + 10 + 5 + 16
                for line in msg_lines:
                    ui.canvas.draw_string(x_offset,
                                          current_y,
                                          line,
                                          color=(255, 0, 0))
                    current_y += 16
                    if current_y >= ui.canvas.height():
                        break

                ui.canvas.draw_string(x_offset,
                                      y_offset + current_y,
                                      s,
                                      color=(0, 255, 0))
                lcd.display(ui.canvas)

                happen = time.ticks_ms()
                while (happen + 5000) > time.ticks_ms():
                    info = "(%d)" % (5 -
                                     (int)(time.ticks_ms() - happen) / 1000)
                    btn.event()
                    if btn.back() == 2 or btn.home() == 2 or btn.next() == 2:
                        break
                    ui.canvas.draw_rectangle(
                        (x_offset, y_offset + 5, len(info) * 8, 12),
                        fill=True,
                        color=(50, 50, 50))
                    ui.canvas.draw_string(x_offset,
                                          y_offset + 5,
                                          info,
                                          color=(0, 255, 0))
                    lcd.display(ui.canvas)
                    time.sleep_ms(100)
                ui.display()
                # gc.collect()
            except Exception as e:
                print(e)