Exemplo n.º 1
0
def start():
    ugfx.input_init()
    ugfx.set_lut(ugfx.LUT_FASTER)
    ugfx.clear(ugfx.WHITE)
    
    badge.backlight(255)

    global options
    global install_path
    options = None
    install_path = None

    ugfx.input_attach(ugfx.BTN_START, input_run)
    ugfx.input_attach(ugfx.BTN_B, input_home)
    ugfx.input_attach(ugfx.JOY_UP, input_other)
    ugfx.input_attach(ugfx.JOY_DOWN, input_other)
    ugfx.input_attach(ugfx.JOY_LEFT, input_uninstall)
    ugfx.input_attach(ugfx.JOY_RIGHT, input_other)

    populate_apps()
    populate_category()
    populate_options()

    # do a greyscale flush on start
    ugfx.flush(ugfx.GREYSCALE)
Exemplo n.º 2
0
def connectClick(pushed):
    if pushed:
        selected = options.selected_text().encode()
        print('selected')
        options.destroy()

        ssidType = scanResults[ssidList.index(selected)][4]
        print(ssidType)
        print(ssidList.index(selected))
        ugfx.clear(ugfx.WHITE)
        ugfx.string(100, 50, selected, 'Roboto_Regular18', ugfx.BLACK)
        ugfx.flush()
        if ssidType == 5:
            clearGhosting()
            ugfx.clear(ugfx.WHITE)
            ugfx.string(20, 50, 'WPA Enterprise unsupported...',
                        'Roboto_Regular18', ugfx.BLACK)
            ugfx.set_lut(ugfx.LUT_FULL)
            ugfx.flush()
            badge.eink_busy_wait()
            system.reboot()

        badge.nvs_set_str("system", "wifi.ssid", selected)

        if ssidType == 0:
            badge.nvs_set_str("system", "wifi.password", '')
            system.reboot()
        else:
            clearGhosting()
            dialogs.prompt_text("WiFi password", cb=passInputDone)
Exemplo n.º 3
0
def start():
	ugfx.set_lut(ugfx.LUT_FASTER)
	ugfx.clear(ugfx.WHITE)
	x0 = int(display.width()/2)
	display.drawText(x0+10, 0, "Recovery mode!", 0x000000, "roboto_regular12")

	global options
	global install_path
	options = None
	install_path = None

	ugfx.input_attach(ugfx.BTN_A, input_a)
	ugfx.input_attach(ugfx.BTN_B, input_b)
	ugfx.input_attach(ugfx.BTN_SELECT, input_select)
	ugfx.input_attach(ugfx.JOY_UP, input_other)
	ugfx.input_attach(ugfx.JOY_DOWN, input_other)
	ugfx.input_attach(ugfx.JOY_LEFT, input_other)
	ugfx.input_attach(ugfx.JOY_RIGHT, input_other)
	ugfx.input_attach(ugfx.BTN_START, input_other)

	populate_apps()
	populate_category()
	populate_options()

	# do a greyscale flush on start
	ugfx.flush(ugfx.GREYSCALE)
Exemplo n.º 4
0
def start():
	ugfx.input_init()
	ugfx.set_lut(ugfx.LUT_FASTER)
	ugfx.clear(ugfx.WHITE)

	# Instructions
	if orientation.isLandscape():
		if display.width() > 128:
			x0 = int(display.width()/2)
			currentY = 20
			
			display.drawText(x0+((display.width()-x0)//2)-(display.getTextWidth("BADGE.TEAM", "fairlight12")//2), currentY, "BADGE.TEAM\n", 0x000000, "fairlight12")
			currentY += display.getTextHeight("BADGE.TEAM", "fairlight12")
			
			display.drawText(x0+int((display.width()-x0)/2)-int(display.getTextWidth("ESP32 platform", "roboto_regular12")/2), currentY, "ESP32 platform\n", 0x000000, "roboto_regular12")
			display.drawLine(x0,0,x0,display.height()-1,0x000000)
			pixHeight = display.getTextHeight(" ", "roboto_regular12")
			currentY = pixHeight*5
			
			lineY = display.height()-pixHeight*6-pixHeight//2
			display.drawLine(x0, lineY, display.width()-1, lineY, 0x000000)
			
			display.drawText(x0+5, display.height()-pixHeight*6, "A: Run\n", 0x000000, "roboto_regular12")
			display.drawText(x0+5, display.height()-pixHeight*5, "START: Return to home\n", 0x000000, "roboto_regular12")
			display.drawText(x0+5, display.height()-pixHeight*4, "SELECT: Uninstall app\n", 0x000000, "roboto_regular12")
			
			lineY = display.height()-pixHeight*2-pixHeight//2
			display.drawLine(x0, lineY, display.width()-1, lineY, 0x000000)
			display.drawText(x0+5, display.height()-pixHeight*2, consts.INFO_FIRMWARE_NAME, 0x000000, "roboto_regular12")
			display.drawText(x0+5, display.height()-pixHeight, "Build "+str(consts.INFO_FIRMWARE_BUILD), 0x000000, "roboto_regular12")
	else:
		pixHeight = display.getTextHeight(" ", "roboto_regular12")
		display.drawLine(0, display.height()-18*4, display.width(), display.height()-18*4, ugfx.BLACK)
		display.drawText(0, display.height()-pixHeight*6, "A: Run\n", 0x000000, "roboto_regular12")
		display.drawText(0, display.height()-pixHeight*5, "START: Home\n", 0x000000, "roboto_regular12")
		display.drawText(0, display.height()-pixHeight*4, "SELECT: Uninstall\n", 0x000000, "roboto_regular12")
		
		lineY = display.height()-pixHeight*2-pixHeight//2
		display.drawLine(0, lineY, display.width()-1, lineY, 0x000000)
		display.drawText(0, display.height()-pixHeight*2, consts.INFO_FIRMWARE_NAME, 0x000000, "roboto_regular12")
		display.drawText(0, display.height()-pixHeight, "Build "+str(consts.INFO_FIRMWARE_BUILD), 0x000000, "roboto_regular12")

	global options
	global install_path
	options = None
	install_path = None

	ugfx.input_attach(ugfx.BTN_OK,    input_a)
	ugfx.input_attach(ugfx.BTN_BACK,  input_b)
	ugfx.input_attach(ugfx.JOY_UP,    input_other)
	ugfx.input_attach(ugfx.JOY_DOWN,  input_other)
	ugfx.input_attach(ugfx.JOY_RIGHT, input_a)
	ugfx.input_attach(ugfx.JOY_LEFT, input_select)

	populate_apps()
	populate_category()
	populate_options()

	# do a greyscale flush on start
	ugfx.flush(ugfx.GREYSCALE)
Exemplo n.º 5
0
def start():
    ugfx.input_init()
    ugfx.set_lut(ugfx.LUT_FASTER)
    ugfx.clear(ugfx.WHITE)

    # Instructions
    if orientation.isLandscape():
        ugfx.line(148, 78, 296, 78, ugfx.BLACK)
        ugfx.string_box(148, 78, 148, 18, " A: Run", "Roboto_Regular12",
                        ugfx.BLACK, ugfx.justifyLeft)
        ugfx.string_box(148, 78, 148, 18, " B: Return to home",
                        "Roboto_Regular12", ugfx.BLACK, ugfx.justifyRight)
        ugfx.string_box(148, 92, 148, 18, " SELECT: Uninstall",
                        "Roboto_Regular12", ugfx.BLACK, ugfx.justifyLeft)
        ugfx.line(148, 110, 296, 110, ugfx.BLACK)
        ugfx.string_box(148, 110, 148, 18, " " + version.name,
                        "Roboto_Regular12", ugfx.BLACK, ugfx.justifyLeft)
    else:
        ugfx.line(0,
                  ugfx.height() - 18 * 4, ugfx.width(),
                  ugfx.height() - 18 * 4, ugfx.BLACK)
        ugfx.string_box(0,
                        ugfx.height() - 18 * 4, ugfx.width(), 18, " A: Run",
                        "Roboto_Regular12", ugfx.BLACK, ugfx.justifyLeft)
        ugfx.string_box(0,
                        ugfx.height() - 18 * 3, ugfx.width(), 18,
                        " B: Return to home", "Roboto_Regular12", ugfx.BLACK,
                        ugfx.justifyLeft)
        ugfx.string_box(0,
                        ugfx.height() - 18 * 2, ugfx.width(), 18,
                        " SELECT: Uninstall", "Roboto_Regular12", ugfx.BLACK,
                        ugfx.justifyLeft)
        ugfx.line(0,
                  ugfx.height() - 18 * 1, ugfx.width(),
                  ugfx.height() - 18 * 1, ugfx.BLACK)
        ugfx.string_box(0,
                        ugfx.height() - 18 * 1, ugfx.width(), 18,
                        " " + version.name, "Roboto_Regular12", ugfx.BLACK,
                        ugfx.justifyLeft)

    global options
    global install_path
    options = None
    install_path = None

    ugfx.input_attach(ugfx.BTN_A, input_a)
    ugfx.input_attach(ugfx.BTN_B, input_b)
    ugfx.input_attach(ugfx.BTN_SELECT, input_select)
    ugfx.input_attach(ugfx.JOY_UP, input_other)
    ugfx.input_attach(ugfx.JOY_DOWN, input_other)
    ugfx.input_attach(ugfx.JOY_LEFT, input_other)
    ugfx.input_attach(ugfx.JOY_RIGHT, input_other)
    ugfx.input_attach(ugfx.BTN_START, input_other)

    populate_apps()
    populate_category()
    populate_options()

    # do a greyscale flush on start
    ugfx.flush(ugfx.GREYSCALE)
Exemplo n.º 6
0
def program_main():
    print("--- SPONSORS APP ---")
    ugfx.init()
    ugfx.set_lut(ugfx.LUT_FULL)
    ugfx.clear(ugfx.BLACK)
    ugfx.flush()
    show_sponsors()
    appglue.start_app("")  # Return home
Exemplo n.º 7
0
def start():
    ugfx.input_init()
    ugfx.set_lut(ugfx.LUT_FASTER)
    ugfx.clear(ugfx.BLACK)
    ugfx.flush()
    ugfx.clear(ugfx.WHITE)
    ugfx.flush()

    ugfx.string_box(148, 0, 148, 26, "STILL", "Roboto_BlackItalic24",
                    ugfx.BLACK, ugfx.justifyCenter)
    ugfx.string_box(148, 23, 148, 23, "Hacking", "PermanentMarker22",
                    ugfx.BLACK, ugfx.justifyCenter)
    ugfx.string_box(148, 48, 148, 26, "Anyway", "Roboto_BlackItalic24",
                    ugfx.BLACK, ugfx.justifyCenter)

    #the line under the text
    str_len = ugfx.get_string_width("Hacking", "PermanentMarker22")
    line_begin = 148 + int((148 - str_len) / 2)
    line_end = str_len + line_begin
    ugfx.line(line_begin, 46, line_end, 46, ugfx.BLACK)

    #the cursor past the text
    cursor_pos = line_end + 5
    ugfx.line(cursor_pos, 22, cursor_pos, 44, ugfx.BLACK)

    # Instructions
    ugfx.line(148, 78, 296, 78, ugfx.BLACK)
    ugfx.string_box(148, 78, 148, 18, " A: Run", "Roboto_Regular12",
                    ugfx.BLACK, ugfx.justifyLeft)
    ugfx.string_box(148, 78, 148, 18, " B: Return to home", "Roboto_Regular12",
                    ugfx.BLACK, ugfx.justifyRight)
    ugfx.string_box(148, 92, 148, 18, " SELECT: Uninstall", "Roboto_Regular12",
                    ugfx.BLACK, ugfx.justifyLeft)
    ugfx.line(148, 110, 296, 110, ugfx.BLACK)
    ugfx.string_box(148, 110, 148, 18, " " + version.name, "Roboto_Regular12",
                    ugfx.BLACK, ugfx.justifyLeft)

    global options
    global install_path
    options = None
    install_path = None

    ugfx.input_attach(ugfx.BTN_A, input_a)
    ugfx.input_attach(ugfx.BTN_B, input_b)
    ugfx.input_attach(ugfx.BTN_SELECT, input_select)
    ugfx.input_attach(ugfx.JOY_UP, input_other)
    ugfx.input_attach(ugfx.JOY_DOWN, input_other)
    ugfx.input_attach(ugfx.JOY_LEFT, input_other)
    ugfx.input_attach(ugfx.JOY_RIGHT, input_other)
    ugfx.input_attach(ugfx.BTN_START, input_other)

    populate_apps()
    populate_category()
    populate_options()

    ugfx.flush(ugfx.LUT_FULL)
Exemplo n.º 8
0
def draw_batterylow(percent):
    ugfx.clear(ugfx.WHITE)
    ugfx.string(0, 0,
                str(percent) + "%  - BATTERY LOW, PLEASE CHARGE!",
                "Roboto_Regular12", ugfx.BLACK)
    #ugfx.string(0, 15, "BATTERY LOW! PLEASE CHARGE THE BATTERY!","Roboto_Regular12",ugfx.BLACK)
    nick = badge.nvs_get_str("owner", "name", "Hacker1337")
    ugfx.string(0, 40, nick, "PermanentMarker36", ugfx.BLACK)
    ugfx.set_lut(ugfx.LUT_FASTER)
    ugfx.flush()
Exemplo n.º 9
0
def app_main():
    ugfx.init()

    clear()
    ugfx.set_lut(ugfx.LUT_FASTEST)

    badge.vibrator_init()

    ugfx.input_attach(ugfx.BTN_A, lambda pressed: badge.vibrator_activate(0xd))
    ugfx.input_attach(ugfx.BTN_START, lambda pressed: appglue.home())

    loop()
Exemplo n.º 10
0
def draw_msg(msg):
    global line_number
    try:
        line_number
    except:
        line_number = 0
        ugfx.clear(ugfx.WHITE)
        ugfx.string(0, 0, 'Still Loading Anyway...', "PermanentMarker22",
                    ugfx.BLACK)
        ugfx.set_lut(ugfx.LUT_FASTER)
        draw_msg(msg)
    else:
        ugfx.string(0, 30 + (line_number * 15), msg, "Roboto_Regular12",
                    ugfx.BLACK)
        ugfx.flush()
        line_number += 1
Exemplo n.º 11
0
def setup():
    global background
    badge.init()
    ugfx.init()
    ugfx.input_init()
    ugfx.input_attach(ugfx.BTN_SELECT, reboot)
    ugfx.input_attach(ugfx.BTN_START, reboot)
    ugfx.input_attach(ugfx.JOY_DOWN, invert)
    ugfx.input_attach(ugfx.JOY_UP, invert)
    ugfx.input_attach(ugfx.JOY_RIGHT, invert)
    ugfx.input_attach(ugfx.JOY_LEFT, invert)
    ugfx.input_attach(ugfx.BTN_A, invert)
    ugfx.input_attach(ugfx.BTN_B, invert)
    ugfx.set_lut(ugfx.LUT_NORMAL)
    ugfx.clear(background)
    ugfx.flush()
    flip()
Exemplo n.º 12
0
def draw_home(percent, cstate, status):
    ugfx.clear(ugfx.WHITE)
    if (cstate):
        ugfx.string(0, 0,
                    str(percent) + "% & Charging... | " + status,
                    "Roboto_Regular12", ugfx.BLACK)
    else:
        ugfx.string(0, 0,
                    str(percent) + "% | " + status, "Roboto_Regular12",
                    ugfx.BLACK)

    htext = badge.nvs_get_str("owner", "htext", "")
    if (htext != ""):
        draw_logo(160, 25, htext)

    nick = badge.nvs_get_str("owner", "name", "Anonymous")
    ugfx.string(0, 40, nick, "PermanentMarker36", ugfx.BLACK)

    ugfx.set_lut(ugfx.LUT_FULL)
    ugfx.flush()
    ugfx.set_lut(ugfx.LUT_FASTER)
Exemplo n.º 13
0
def prompt_text(description,
                init_text="",
                true_text="OK",
                false_text="Back",
                width=300,
                height=200,
                font="Roboto_BlackItalic24"):
    """Shows a dialog and keyboard that allows the user to input/change a string

	Returns None if user aborts with button B

	The caller is responsible for flushing the display after processing the response.
	"""
    global wait_for_interrupt, button_pushed

    window = ugfx.Container(int((ugfx.width() - width) / 2),
                            int((ugfx.height() - height) / 2), width, height)
    window.show()

    ugfx.set_default_font("Roboto_Regular12")
    kb_height = int(height / 2) + 30
    kb = ugfx.Keyboard(0, height - kb_height, width, kb_height, parent=window)

    ugfx.set_default_font("Roboto_Regular18")
    edit_height = 25
    edit = ugfx.Textbox(5,
                        height - kb_height - 5 - edit_height,
                        int(width * 4 / 5) - 10,
                        edit_height,
                        text=init_text,
                        parent=window)
    ugfx.set_default_font("Roboto_Regular12")
    button_height = 25

    def okay(evt):
        # We'd like promises here, but for now this should do
        global wait_for_interrupt
        button_pushed = "A"
        wait_for_interrupt = False

    button_yes = ugfx.Button(int(width * 4 / 5),
                             height - kb_height - button_height,
                             int(width * 1 / 5) - 3,
                             button_height,
                             true_text,
                             parent=window,
                             cb=okay)
    button_no = ugfx.Button(int(width * 4 / 5),
                            height - kb_height - button_height - button_height,
                            int(width / 5) - 3,
                            button_height,
                            false_text,
                            parent=window) if false_text else None
    ugfx.set_default_font(font)
    label = ugfx.Label(5,
                       1,
                       int(width * 4 / 5),
                       height - kb_height - 5 - edit_height - 5,
                       description,
                       parent=window)

    def vkey_backspace():
        edit.backspace()
        ugfx.flush()

    focus = 0

    def toggle_focus(pressed):
        if pressed:
            if focus == 0:
                edit.set_focus()
                kb.enabled(1)
                ugfx.input_attach(
                    ugfx.BTN_B, lambda pressed: vkey_backspace()
                    if pressed else 0)
                ugfx.input_attach(
                    ugfx.BTN_A, lambda pressed: 0 if pressed else ugfx.flush())
                focus = 1
            elif focus == 1 or not button_no:
                button_yes.set_focus()
                kb.enabled(0)
                ugfx.input_attach(ugfx.BTN_A, pressed_a)
                ugfx.input_attach(ugfx.BTN_B, pressed_b)
                focus = (2 if button_no else 0)
            else:
                button_no.set_focus()
                kb.enabled(0)
                ugfx.input_attach(ugfx.BTN_A, pressed_a)
                ugfx.input_attach(ugfx.BTN_B, pressed_b)
                focus = 0
            ugfx.flush()

    ugfx.input_init()
    ugfx.input_attach(ugfx.BTN_SELECT, toggle_focus)
    ugfx.input_attach(ugfx.JOY_LEFT, lambda pressed: ugfx.flush()
                      if pressed else 0)
    ugfx.input_attach(ugfx.JOY_RIGHT, lambda pressed: ugfx.flush()
                      if pressed else 0)
    ugfx.input_attach(ugfx.JOY_UP, lambda pressed: ugfx.flush()
                      if pressed else 0)
    ugfx.input_attach(ugfx.JOY_DOWN, lambda pressed: ugfx.flush()
                      if pressed else 0)

    toggle_focus(True)

    ugfx.set_lut(ugfx.LUT_NORMAL)
    ugfx.flush()

    wait_for_interrupt = True
    while wait_for_interrupt:
        time.sleep(0.2)

    def done(value):
        window.hide()
        window.destroy()
        button_yes.destroy()
        if button_no: button_no.destroy()
        label.destroy()
        kb.destroy()
        edit.destroy()
        return value

    if (focus == 0 and no_button) or button_pushed == "B": return done(False)
    return done(edit.text())
Exemplo n.º 14
0
def prompt_boolean(text,
                   title="SHA2017",
                   true_text="Yes",
                   false_text="No",
                   width=296,
                   height=128,
                   font="Roboto_Regular12"):
    """A simple one and two-options dialog

	if 'false_text' is set to None only one button is displayed.
	If both 'false_text' and 'true_text' are given a boolean is returned, press B for false, A for true.

	The caller is responsible for flushing the display after processing the response.
	"""
    global wait_for_interrupt, button_pushed

    window = ugfx.Container((ugfx.width() - width) // 2,
                            (ugfx.height() - height) // 2, width, height)
    window.show()
    ugfx.set_default_font(font)
    window.text(5, 10, title, ugfx.BLACK)
    window.line(0, 30, width, 30, ugfx.BLACK)

    if false_text:
        false_text = "B: " + false_text
        true_text = "A: " + true_text

    label = ugfx.Label(5,
                       30,
                       width - 10,
                       height - 80,
                       text=text,
                       parent=window)
    button_no = ugfx.Button(
        5, height - 40, width // 2 -
        15, 30, false_text, parent=window) if false_text else None
    button_yes = ugfx.Button(width // 2 + 5 if true_text else 5,
                             height - 40,
                             width // 2 - 15 if false_text else width - 10,
                             30,
                             true_text,
                             parent=window)
    button_yes.set_focus()

    ugfx.input_init()

    window.show()
    ugfx.set_lut(ugfx.LUT_NORMAL)
    ugfx.flush()

    def done(value):
        window.hide()
        window.destroy()
        button_yes.destroy()
        if button_no: button_no.destroy()
        label.destroy()
        return value

    if button_no: ugfx.input_attach(ugfx.BTN_B, pressed_b)
    ugfx.input_attach(ugfx.BTN_A, pressed_a)

    wait_for_interrupt = True
    while wait_for_interrupt:
        time.sleep(0.2)

    if button_pushed == "B": return done(False)
    if button_pushed == "A": return done(True)
Exemplo n.º 15
0
def start():
    ugfx.input_init()
    ugfx.set_lut(ugfx.LUT_FASTER)
    ugfx.clear(ugfx.WHITE)

    # Instructions
    if orientation.isLandscape():
        x0 = int(display.width() / 2)
        display.font("fairlight8")
        currentY = 20
        display.cursor(
            x0 + int((display.width() - x0) / 2) -
            int(display.get_string_width("BADGE.TEAM") / 2), currentY)
        display.print("BADGE.TEAM\n")
        display.font("pixelade9")
        (_, currentY) = display.cursor()
        display.cursor(
            x0 + int((display.width() - x0) / 2) -
            int(display.get_string_width("ESP32 platform") / 2), currentY)
        display.print("ESP32 platform\n")
        display.line(x0, 0, x0, display.height() - 1, 0x000000)
        display.textColor(0x000000)
        display.font("pixelade9")
        currentY = display.get_string_height(" ") * 5 - 5
        display.line(x0, currentY, display.width() - 1, currentY, 0x000000)
        display.cursor(x0 + 5, currentY + 5)
        display.print("A: Run\n")
        display.print("B: Return to home\n")
        display.print("SELECT: Uninstall app\n")
        (_, currentY) = display.cursor()
        display.line(x0, currentY, display.width() - 1, currentY, 0x000000)
        _ = display.cursor(x0 + 5, currentY + 5)
        display.print(consts.INFO_FIRMWARE_NAME)
    else:
        ugfx.line(0,
                  ugfx.height() - 18 * 4, ugfx.width(),
                  ugfx.height() - 18 * 4, ugfx.BLACK)
        ugfx.string_box(0,
                        ugfx.height() - 18 * 4, ugfx.width(), 18, " A: Run",
                        "Roboto_Regular12", ugfx.BLACK, ugfx.justifyLeft)
        ugfx.string_box(0,
                        ugfx.height() - 18 * 3, ugfx.width(), 18,
                        " B: Return to home", "Roboto_Regular12", ugfx.BLACK,
                        ugfx.justifyLeft)
        ugfx.string_box(0,
                        ugfx.height() - 18 * 2, ugfx.width(), 18,
                        " SELECT: Uninstall", "Roboto_Regular12", ugfx.BLACK,
                        ugfx.justifyLeft)
        ugfx.line(0,
                  ugfx.height() - 18 * 1, ugfx.width(),
                  ugfx.height() - 18 * 1, ugfx.BLACK)
        ugfx.string_box(0,
                        ugfx.height() - 18 * 1, ugfx.width(), 18,
                        " " + consts.INFO_FIRMWARE_NAME, "Roboto_Regular12",
                        ugfx.BLACK, ugfx.justifyLeft)

    global options
    global install_path
    options = None
    install_path = None

    ugfx.input_attach(ugfx.BTN_A, input_a)
    ugfx.input_attach(ugfx.BTN_B, input_b)
    ugfx.input_attach(ugfx.BTN_SELECT, input_select)
    ugfx.input_attach(ugfx.JOY_UP, input_other)
    ugfx.input_attach(ugfx.JOY_DOWN, input_other)
    ugfx.input_attach(ugfx.JOY_LEFT, input_other)
    ugfx.input_attach(ugfx.JOY_RIGHT, input_other)
    ugfx.input_attach(ugfx.BTN_START, input_other)

    populate_apps()
    populate_category()
    populate_options()

    # do a greyscale flush on start
    ugfx.flush(ugfx.GREYSCALE)
Exemplo n.º 16
0
window = ugfx.Container(0, 0, ugfx.width(), ugfx.height())

ugfx.input_attach(ugfx.JOY_UP, show_description)
ugfx.input_attach(ugfx.JOY_DOWN, show_description)
ugfx.input_attach(ugfx.BTN_A, woezel_it)
ugfx.input_attach(ugfx.BTN_B, woezel_it)

ugfx.input_attach(ugfx.BTN_START, start_app)

ugfx.input_attach(ugfx.JOY_LEFT, lambda pushed: ugfx.flush() if pushed else 0)
ugfx.input_attach(ugfx.JOY_RIGHT, lambda pushed: ugfx.flush() if pushed else 0)

text = ugfx.Textbox(int(ugfx.width() / 2), 0, int(ugfx.width() / 2),
                    ugfx.height())

ugfx.set_lut(ugfx.LUT_FULL)
ugfx.flush()
badge.eink_busy_wait()
ugfx.set_lut(ugfx.LUT_FASTER)

gc.collect()

f = requests.get("https://badge.sha2017.org/eggs/list/json")
try:
    packages = f.json()
finally:
    f.close()

gc.collect()

options = ugfx.List(0, 0, int(ugfx.width() / 2), ugfx.height())
Exemplo n.º 17
0
def prompt_boolean(text, title="SHA2017", true_text="Yes", false_text="No", width = 296, height = 128, font="Roboto_Regular12", cb=None):
	"""A simple one and two-options dialog

	if 'false_text' is set to None only one button is displayed.
	If both 'false_text' and 'true_text' are given a boolean is returned, press B for false, A for true.

	Pass along a 'cb' callback to make the dialog async, which is needed to make input work when used from a callback

	The caller is responsible for flushing the display after processing the response.
	"""
	global wait_for_interrupt, button_pushed

	window = ugfx.Container((ugfx.width() - width) // 2, (ugfx.height() - height) // 2,  width, height)
	window.show()
	ugfx.set_default_font(font)
	window.text(5, 10, title, ugfx.BLACK)
	window.line(0, 30, width, 30, ugfx.BLACK)

	if false_text:
		false_text = "B: " + false_text
		true_text = "A: " + true_text

	def done(result):
		window.destroy()
		if cb:
			cb(result)
		return result

	def syncSuccess(evt):
		if evt:
			# We'd like promises here, but for now this should do
			global wait_for_interrupt, button_pushed
			button_pushed = "A"
			wait_for_interrupt = False
	def syncCancel(evt):
		if evt:
			# We'd like promises here, but for now this should do
			global wait_for_interrupt, button_pushed
			button_pushed = "B"
			wait_for_interrupt = False

	def asyncSuccess(evt):
		if evt:
			done(True)
	def asyncCancel(evt):
		if evt:
			done(False)

	label = ugfx.Label(5, 30, width - 10, height - 80, text = text, parent=window)
	button_no = ugfx.Button(5, height - 40, width // 2 - 15, 30, false_text, parent=window) if false_text else None
	button_yes = ugfx.Button(width // 2 + 5 if true_text else 5, height - 40, width // 2 - 15 if false_text else width - 10, 30, true_text, parent=window)
	button_yes.set_focus()

	ugfx.input_init()

	window.show()
	ugfx.set_lut(ugfx.LUT_NORMAL)
	ugfx.flush()

	if button_no: ugfx.input_attach(ugfx.BTN_B, asyncCancel if cb else syncCancel)
	ugfx.input_attach(ugfx.BTN_A, asyncSuccess if cb else syncSuccess)

	if cb:
		return
	else:
		wait_for_interrupt = True
		while wait_for_interrupt:
			time.sleep(0.2)

		if button_pushed == "B": return done(False)
		return done(True)
Exemplo n.º 18
0
def clear():
    ugfx.set_lut(ugfx.LUT_FULL)
    ugfx.clear(ugfx.BLACK)
    ugfx.flush()
    ugfx.clear(ugfx.WHITE)
    ugfx.flush()
Exemplo n.º 19
0
def prompt_text(description,
                init_text="",
                true_text="OK",
                false_text="Back",
                width=ugfx.width(),
                height=ugfx.height(),
                font="Roboto_BlackItalic24",
                cb=None):
    """Shows a dialog and keyboard that allows the user to input/change a string

	Calls the 'cb' callback or return None if user aborts with button B. Using a callback is highly recommended as it's not
	possible to process events inside an event callback.

	The caller is responsible for flushing the display after processing the response.
	"""
    global wait_for_interrupt, button_pushed

    window = ugfx.Container(int((ugfx.width() - width) / 2),
                            int((ugfx.height() - height) / 2), width, height)
    window.show()

    ugfx.set_default_font("Roboto_Regular12")
    kb_height = int(height / 2) + 30
    kb = ugfx.Keyboard(0, height - kb_height, width, kb_height, parent=window)

    ugfx.set_default_font("Roboto_Regular18")
    edit_height = 25
    edit = ugfx.Textbox(5,
                        height - kb_height - 5 - edit_height,
                        int(width * 4 / 5) - 10,
                        edit_height,
                        text=init_text,
                        parent=window)
    ugfx.set_default_font("Roboto_Regular12")
    button_height = 25

    def done(result):
        window.destroy()
        if cb:
            cb(result)
        return result

    def syncSuccess(evt):
        if evt:
            # We'd like promises here, but for now this should do
            global wait_for_interrupt, button_pushed
            button_pushed = "A"
            wait_for_interrupt = False

    def syncCancel(evt):
        if evt:
            # We'd like promises here, but for now this should do
            global wait_for_interrupt, button_pushed
            button_pushed = "B"
            wait_for_interrupt = False

    def asyncSuccess(evt):
        if evt:
            done(edit.text())

    def asyncCancel(evt):
        if evt:
            done(None)

    button_yes = ugfx.Button(int(width * 4 / 5),
                             height - kb_height - button_height,
                             int(width * 1 / 5) - 3,
                             button_height,
                             true_text,
                             parent=window,
                             cb=asyncSuccess if cb else syncSuccess)
    button_no = ugfx.Button(int(width * 4 / 5),
                            height - kb_height - button_height - button_height,
                            int(width / 5) - 3,
                            button_height,
                            false_text,
                            parent=window) if false_text else None
    ugfx.set_default_font(font)
    label = ugfx.Label(5,
                       1,
                       int(width * 4 / 5),
                       height - kb_height - 5 - edit_height - 5,
                       description,
                       parent=window)

    def vkey_backspace():
        edit.backspace()
        ugfx.flush()

    focus = 0

    def toggle_focus(pressed):
        if pressed:
            if focus == 0:
                edit.set_focus()
                kb.enabled(1)
                ugfx.input_attach(
                    version.btn_cancel, lambda pressed: vkey_backspace()
                    if pressed else 0)
                ugfx.input_attach(
                    version.btn_ok, lambda pressed: 0
                    if pressed else ugfx.flush())
                focus = 1
            elif focus == 1 or not button_no:
                button_yes.set_focus()
                kb.enabled(0)
                ugfx.input_attach(version.btn_ok,
                                  asyncSuccess if cb else syncSuccess)
                ugfx.input_attach(version.btn_cancel,
                                  asyncCancel if cb else syncCancel)
                focus = (2 if button_no else 0)
            else:
                button_no.set_focus()
                kb.enabled(0)
                ugfx.input_attach(version.btn_ok,
                                  asyncCancel if cb else syncCancel)
                ugfx.input_attach(version.btn_cancel,
                                  asyncCancel if cb else syncCancel)
                focus = 0
            ugfx.flush()

    ugfx.input_init()
    ugfx.input_attach(ugfx.BTN_SELECT, toggle_focus)
    ugfx.input_attach(ugfx.JOY_LEFT, lambda pressed: ugfx.flush()
                      if pressed else 0)
    ugfx.input_attach(ugfx.JOY_RIGHT, lambda pressed: ugfx.flush()
                      if pressed else 0)
    ugfx.input_attach(ugfx.JOY_UP, lambda pressed: ugfx.flush()
                      if pressed else 0)
    ugfx.input_attach(ugfx.JOY_DOWN, lambda pressed: ugfx.flush()
                      if pressed else 0)

    toggle_focus(True)

    ugfx.set_lut(ugfx.LUT_NORMAL)
    ugfx.flush()

    wait_for_interrupt = True
    if cb:
        return
    else:
        while wait_for_interrupt:
            time.sleep(0.2)

        if (focus == 0 and no_button) or button_pushed == "B":
            return done(False)
        return done(edit.text())
Exemplo n.º 20
0
ugfx.string(0, 0, "SHA2017 Badge", "PermanentMarker22", ugfx.BLACK)
ugfx.string(0, 25, "Please join us for a short talk on how the",
            "Roboto_Regular12", ugfx.BLACK)
ugfx.string(0, 25 + 13, "official SHA2017 badge was designed,",
            "Roboto_Regular12", ugfx.BLACK)
ugfx.string(0, 25 + 13 * 2, "some nice numbers and an overview of what all",
            "Roboto_Regular12", ugfx.BLACK)
ugfx.string(0, 25 + 13 * 3, "of you are doing with it.", "Roboto_Regular12",
            ugfx.BLACK)

ugfx.string(0, 25 + 13 * 5, "The events starts now, in room 'Pa'!",
            "Roboto_Regular12", ugfx.BLACK)
ugfx.string(0,
            ugfx.height() - 13, "Press any key to close reminder.",
            "Roboto_Regular12", ugfx.BLACK)
ugfx.set_lut(ugfx.LUT_FULL)
ugfx.flush()

ugfx.input_init()
ugfx.input_attach(ugfx.JOY_UP, exit)
ugfx.input_attach(ugfx.JOY_DOWN, exit)
ugfx.input_attach(ugfx.JOY_LEFT, exit)
ugfx.input_attach(ugfx.JOY_RIGHT, exit)
ugfx.input_attach(ugfx.BTN_SELECT, exit)
ugfx.input_attach(ugfx.BTN_START, exit)
ugfx.input_attach(ugfx.BTN_A, exit)
ugfx.input_attach(ugfx.BTN_B, exit)


def led(on):
    ledVal = 0
Exemplo n.º 21
0
def prompt_boolean(text,
                   title=version.dialog_title,
                   true_text="Yes",
                   false_text="No",
                   width=ugfx.width(),
                   height=ugfx.height(),
                   font="Roboto_Regular12",
                   cb=None):
    global wait_for_interrupt, button_pushed

    easydraw.msg(text, title, True)
    easydraw.msg_nosplit("[" + false_text + "/" + true_text + "]")

    def done(result):
        ugfx.input_attach(ugfx.JOY_LEFT, dummy_button_cb)
        ugfx.input_attach(ugfx.JOY_RIGHT, dummy_button_cb)
        ugfx.input_attach(ugfx.JOY_UP, dummy_button_cb)
        ugfx.input_attach(ugfx.JOY_DOWN, dummy_button_cb)
        ugfx.input_attach(ugfx.BTN_B, dummy_button_cb)
        ugfx.input_attach(ugfx.BTN_START, dummy_button_cb)
        if cb:
            cb(result)
        return result

    def syncSuccess(evt):
        if evt:
            # We'd like promises here, but for now this should do
            global wait_for_interrupt, button_pushed
            button_pushed = "A"
            wait_for_interrupt = False

    def syncCancel(evt):
        if evt:
            # We'd like promises here, but for now this should do
            global wait_for_interrupt, button_pushed
            button_pushed = "B"
            wait_for_interrupt = False

    def asyncSuccess(evt):
        if evt:
            done(True)

    def asyncCancel(evt):
        if evt:
            done(False)

    ugfx.input_init()

    ugfx.set_lut(ugfx.LUT_NORMAL)
    ugfx.flush()

    ugfx.input_attach(ugfx.JOY_LEFT, dummy_button_cb)
    ugfx.input_attach(ugfx.JOY_RIGHT, dummy_button_cb)
    ugfx.input_attach(ugfx.JOY_UP, dummy_button_cb)
    ugfx.input_attach(ugfx.JOY_DOWN, dummy_button_cb)
    ugfx.input_attach(ugfx.BTN_B, dummy_button_cb)
    ugfx.input_attach(ugfx.BTN_START, dummy_button_cb)

    if false_text != None:
        ugfx.input_attach(version.btn_cancel,
                          asyncCancel if cb else syncCancel)
    ugfx.input_attach(version.btn_ok, asyncSuccess if cb else syncSuccess)

    if cb:
        return
    else:
        wait_for_interrupt = True
        while wait_for_interrupt:
            time.sleep(0.2)

        if button_pushed == "B": return done(False)
        return done(True)
Exemplo n.º 22
0
    # Imagebox centers the image on the screen
    box = ugfx.Imagebox(0, 0, ugfx.width(), ugfx.height(), tmpfile)
    ugfx.flush()
    box.destroy()


def try_draw_url(url):
    try:
        download_screen_data(imageurl)
        update_screen()
    except BaseException as e:
        log('Failed to download and draw image: ' + str(e))


# Prepare device
ugfx.set_lut(ugfx.GREYSCALE)
ugfx.init()
wifi.init()
badge.init()
ugfx.input_init()

ugfx.input_attach(ugfx.BTN_B, lambda pressed: btn_b(pressed))


def btn_b(pressed):
    if pressed:
        import appglue
        appglue.start_app('clean_repl')


# Show splash