Ejemplo n.º 1
0
def show_start():
    ugfx.display_image(0, 0, LOCAL_FOLDER % "main.gif")
    sleep.sleep_ms(2000)

    loop_notice("Please insert a coin to\nlearn your personal lucky melody.",
                "main.gif")
    show_next_step()
Ejemplo n.º 2
0
def show_melody():
    ugfx.display_image(0, 0, LOCAL_FOLDER % "main.gif")
    sleep.sleep_ms(1000)

    dialogs.notice("You will now hear your personal lucky melody.", title=APP_TITLE)
    ugfx.display_image(0, 0, LOCAL_FOLDER % "main.gif")
    play_melody()

    show_next_step()
Ejemplo n.º 3
0
def show_std():
    ugfx.display_image(0, 0, LOCAL_FOLDER % "main.gif")
    dialogs.prompt_boolean("Did you have STDs?", title=APP_TITLE)
    ugfx.display_image(0, 0, LOCAL_FOLDER % "main.gif")

    with dialogs.WaitingMessage("Please wait a moment.", title="Processing..."):
        sleep.sleep_ms(6000)

    show_next_step()
Ejemplo n.º 4
0
    def tick(self):
        self.update()

        if self.should_redraw:
            if self.station_data == None:
                self.show_error()
            else:
                self.show_trains()
        else:
            self._destroy_old_names()

        sleep.sleep_ms(500)

        return self.next_state
Ejemplo n.º 5
0
def show_repeat():
    dialogs.notice("Please repeat your personal lucky melody.",
                   title=APP_TITLE)
    ugfx.display_image(0, 0, LOCAL_FOLDER % "rec.gif")
    sleep.sleep_ms(3000)

    dialogs.notice("PLEASE REPEAT YOUR PERSONAL LUCKY MELODY.",
                   title=APP_TITLE)
    ugfx.display_image(0, 0, LOCAL_FOLDER % "rec.gif")
    sleep.sleep_ms(4000)

    dialogs.notice("Please repeat your personal lucky melody a bit louder.",
                   title=APP_TITLE)
    ugfx.display_image(0, 0, LOCAL_FOLDER % "rec.gif")
    sleep.sleep_ms(4000)

    dialogs.notice(
        "Unfortunately, this tone\nwas wrong. Please repeat\nyour personal lucky melody\nonce again.",
        title=APP_TITLE)
    ugfx.display_image(0, 0, LOCAL_FOLDER % "rec.gif")
    sleep.sleep_ms(6000)

    dialogs.notice(
        "This lucky melody will help you in every situation.\nMany thanks.",
        title=APP_TITLE)

    show_next_step()
Ejemplo n.º 6
0
def choose_wifi(dialog_title='TiLDA'):
    filtered_aps = []
    with dialogs.WaitingMessage(text='Scanning for networks...',
                                title=dialog_title):
        visible_aps = None
        while not visible_aps:
            visible_aps = nic().scan()
            print(visible_aps)
            sleep.sleep_ms(300)
            #todo: timeout
        visible_aps.sort(key=lambda x: x[3], reverse=True)
        # We'll get one result for each AP, so filter dupes
        for ap in visible_aps:
            title = ap[0]
            security = "?"  # todo: re-add get_security_level(ap)
            if security:
                title = title + ' (%s)' % security
            ap = {
                'title': title,
                'ssid': ap[0],
                'security': ap[4],
            }
            if ap['ssid'] not in [a['ssid'] for a in filtered_aps]:
                filtered_aps.append(ap)
        del visible_aps

    ap = dialogs.prompt_option(filtered_aps,
                               text='Choose wifi network',
                               title=dialog_title)
    if ap:
        key = None
        if ap['security'] != 0:
            # Backward compat
            if ap['security'] == None:
                ap['security'] = 'wifi'

            key = dialogs.prompt_text("Enter %s key" % ap['security'])
        with open("wifi.json", "wt") as file:
            if key:
                conn_details = {"ssid": ap['ssid'], "pw": key}
            else:
                conn_details = {"ssid": ap['ssid']}

            file.write(json.dumps(conn_details))
        os.sync()
Ejemplo n.º 7
0
def connect_wifi(details, timeout, wait=False):
    if 'user' in details:
        nic().connect(details['ssid'],
                      details['pw'],
                      enterprise=True,
                      entuser=details['user'],
                      entmethod=nic().EAP_METHOD_PEAP0_MSCHAPv2,
                      entserverauth=False)
    elif 'pw' in details:
        nic().connect(details['ssid'], details['pw'])
    else:
        nic().connect(details['ssid'])

    if wait:
        wait_until = time.ticks_ms() + timeout * 1000
        while not nic().isconnected():
            #nic().update() # todo: do we need this?
            if (time.ticks_ms() > wait_until):
                raise OSError("Timeout while trying to connect to wifi")
            sleep.sleep_ms(100)
Ejemplo n.º 8
0
def show_weight():
    ugfx.display_image(0, 0, LOCAL_FOLDER % "main.gif")
    sleep.sleep_ms(1000)

    while True:
        input = dialogs.prompt_text("Please enter your weight.", false_text="Cancel")
        if is_int(input):
            break

        sleep.wfi()

    ugfx.display_image(0, 0, LOCAL_FOLDER % "main.gif")
    sleep.sleep_ms(1000)

    while True:
        input = dialogs.prompt_text("Please enter your correct weight.", false_text="Cancel")
        if is_int(input):
            break

        sleep.wfi()

    ugfx.display_image(0, 0, LOCAL_FOLDER % "main.gif")

    with dialogs.WaitingMessage("Please wait.", title="Processing..."):
        sleep.sleep_ms(2000)

    show_next_step()
Ejemplo n.º 9
0
def mode_buttons():
    global octave
    global delay
    # render_ui()

    alive = True
    while alive:
        speaker.enabled(True)

        if is_pressed(Buttons.JOY_Up):
            delay += 10
        if is_pressed(Buttons.JOY_Down):
            if delay > 10:
                delay -= 10

        if is_pressed(Buttons.JOY_Left):
            if 1 < octave:
                octave -= 1
        if is_pressed(Buttons.JOY_Right):
            if octave < 6:
                octave += 1

        rand_temp = str(Sensors.get_hdc_temperature()).split('.')[-1]

        rand_num = int(rand_temp) % len(notes)

        rest_delay = int(rand_temp) % 100

        note_to_play = notes[rand_num]
        render_ui(note_to_play, delay, octave, rest_delay)
        # octave = random.randint(1,5)
        speaker.note("{}{}".format(note_to_play, octave))
        sleep.sleep_ms(delay)

        speaker.enabled(False)
        sleep.sleep_ms(rest_delay)
Ejemplo n.º 10
0
 def test_sleep_ms(self):
     sleep_ms = 3000
     time_before = time.ticks_ms()
     time_after = time_before + sleep_ms
     sleep.sleep_ms(sleep_ms)
     self.assertTrue(time.ticks_ms() >= time_after)
Ejemplo n.º 11
0
 def test_sleep(self):
     sleep.sleep_ms(100)
Ejemplo n.º 12
0
def flicker_new_answer(new_answer):
    polygon = polygons[new_answer]
    sleep.sleep_ms(100)
    draw_polygon(polygon, polygon.colour)
    sleep.sleep_ms(100)
    draw_polygon(polygon, ugfx.BLACK)
    sleep.sleep_ms(100)
    draw_polygon(polygon, polygon.colour)
    sleep.sleep_ms(100)
    draw_polygon(polygon, ugfx.BLACK)
    sleep.sleep_ms(100)
    draw_polygon(polygon, polygon.colour)
    sleep.sleep_ms(500)
    draw_polygon(polygon, ugfx.BLACK)
    sleep.sleep_ms(100)
    draw_polygon(polygon, polygon.colour)
    sleep.sleep_ms(2000)
Ejemplo n.º 13
0
def play_note(note, duration):
    speaker.note(note)
    sleep.sleep_ms(duration)
Ejemplo n.º 14
0
def show_spash_screen():
    if ENABLE_SPLASH_SCREEN:
        ugfx.display_image(0, 0, LOCAL_FOLDER % "splash.gif")
        sleep.sleep_ms(1000)
Ejemplo n.º 15
0
                      "shared/nyan/3.png",
                      "shared/nyan/4.png",
                      "shared/nyan/5.png"]
                      
___categories___   = ["Homescreens", "Other"]

import ugfx_helper, os, wifi, ugfx, http, time, sleep, app
from tilda import Buttons

# initialize screen
ugfx_helper.init()
ugfx.clear(ugfx.BLACK)

ugfx.backlight(100)

n = 0
r = 270
while True:
    ugfx.display_image( 0, 90, "shared/nyan/{}.png".format(n) )
    n = (n+1) % 6
    sleep.sleep_ms(10)
    
    if Buttons.is_pressed(Buttons.BTN_B):
      break
    elif Buttons.is_pressed(Buttons.BTN_A):
      r = (r + 180) % 360
      ugfx.clear(ugfx.BLACK)
      ugfx.orientation(r)

ugfx.clear()
app.restart_to_default()
Ejemplo n.º 16
0
               string_temp,
               justification=ugfx.Label.CENTER)

    hum = Sensors.get_hdc_humidity()
    string_hum = "%.1f %% humidity" % hum
    ugfx.Label(0,
               ugfx.height() - 60,
               ugfx.width(),
               60,
               string_hum,
               justification=ugfx.Label.CENTER)

    if count < 58:
        array_temp.append(temp_cal)
        array_hum.append(hum)
    else:
        array_temp.pop(0)
        array_hum.pop(0)
        array_temp.append(temp_cal)
        array_hum.append(hum)
    for time, temp in enumerate(array_temp):
        ugfx.area(int((time + 1) * grid_size), 180 - int(
            (temp + 1) * grid_size), grid_size - 2, grid_size - 2, ugfx.RED)
    for time, hum in enumerate(array_hum):
        ugfx.area(int((time + 1) * grid_size), 200 - int(
            (hum / 4 + 1) * grid_size), grid_size - 2, grid_size - 2,
                  ugfx.BLUE)
    count = count + 1
    sleep.sleep_ms(10000)

restart_to_default()