Пример #1
0
def uninstall():
    global options
    selected = options.selected_index()
    options.destroy()
    
    global currentListTitles
    global currentListTargets
        
    if currentListTargets[selected]["category"] == "system":
        #dialogs.notice("System apps can not be removed!","Can not uninstall '"+currentListTitles[selected]+"'")
        easydraw.msg("System apps can not be removed!","Error",True)
        time.sleep(2)
        start()
        return
    
    def perform_uninstall(ok):
        global install_path
        if ok:
            easydraw.msg("Removing "+currentListTitles[selected]+"...", "Removing...",True)
            install_path = get_install_path()
            for rm_file in os.listdir("%s/%s" % (install_path, currentListTargets[selected]["file"])):
                easydraw.msg("Deleting '"+rm_file+"'...")
                os.remove("%s/%s/%s" % (install_path, currentListTargets[selected]["file"], rm_file))
            easydraw.msg("Deleting folder...")
            os.rmdir("%s/%s" % (install_path, currentListTargets[selected]["file"]))
            easydraw.msg("Uninstall completed!")
        start()
	easydraw.msg("","Uninstall",True)
    dialogs.prompt_boolean('Remove %s?' % currentListTitles[selected], cb=perform_uninstall)
def setup():
    import badge
    import easydraw
    import machine

    easydraw.msg("Setting weather overview as boot app")
    badge.nvs_set_str('boot', 'splash', 'WeekWeather')
    machine.deepsleep(1)
Пример #3
0
def wait_for_network():
    # Handle network connection
    if not wifi.sta_if.isconnected():
        while not wifi.sta_if.isconnected():
            easydraw.msg('Waiting for network')
            log('Waiting for network')
            time.sleep(1)
        log('Connected!')
def show_description(active):
    if active:
        easydraw.msg(packages[options.selected_index()]["description"],
                     "Details", True)
    else:
        options.visible(0)
        options.visible(1)
    ugfx.flush()
Пример #5
0
def install():
    easydraw.msg("Installing resources...")
    if not easywifi.status():
        if not easywifi.enable():
            return False
    import woezel
    woezel.install("resources")
    appglue.home()
Пример #6
0
def install():
    if not easywifi.status():
        if not easywifi.enable():
            return False
    print("[SPONSORS] Installing...")
    easydraw.msg("Installing sponsors...")
    import woezel
    woezel.install("sponsors")
    easydraw.msg("OK")
Пример #7
0
def configure():
    import easywifi
    import easydraw
    import ntp
    if not easywifi.status():
        if not easywifi.enable():
            return False
    easydraw.msg("Configuring clock...")
    ntp.set_NTP_time()
    easydraw.msg("Done")
    return True
Пример #8
0
    def perform_uninstall(ok):
        global install_path
        if ok:
            easydraw.msg("Removing "+currentListTitles[selected]+"...", "Removing...",True)
            install_path = get_install_path()
            for rm_file in os.listdir("%s/%s" % (install_path, currentListTargets[selected]["file"])):
                easydraw.msg("Deleting '"+rm_file+"'...")
                os.remove("%s/%s/%s" % (install_path, currentListTargets[selected]["file"], rm_file))
            easydraw.msg("Deleting folder...")
            os.rmdir("%s/%s" % (install_path, currentListTargets[selected]["file"]))
            easydraw.msg("Uninstall completed!")
        start()
	easydraw.msg("","Uninstall",True)
Пример #9
0
def asked_nickname(value):
    if value:
        badge.nvs_set_str("owner", "name", value)

        # Do the firstboot magic
        newState = 1 if badge.nvs_get_u8('badge', 'setup.state', 0) == 0 else 3
        badge.nvs_set_u8('badge', 'setup.state', newState)

        # Show the user that we are done
        easydraw.msg("Hi " + value + "!",
                     'Your nick has been stored to flash!')
        time.sleep(0.5)
    else:
        badge.nvs_set_u8('badge', 'setup.state', 2)  # Skip the sponsors
        badge.nvs_set_u8('sponsors', 'shown', 1)

    appglue.home()
Пример #10
0
def show_names():
    global names
    c = False
    y = 10

    term.header(True, "About")
    for n in range(0, len(names)):
        if (names[n] == "-  -  -"):
            print("")
            continue
        print(names[n], end="   ")

    easydraw.msg("Your badge was made possible by the following people:",
                 "ABOUT", True)

    for n in range(0, len(names)):
        easydraw.msg(names[n])
        time.sleep(0.8)
Пример #11
0
def connectWiFi():
    nw = network.WLAN(network.STA_IF)
    if not nw.isconnected():
        nw.active(True)
        ssid = badge.nvs_get_str('badge', 'wifi.ssid', '')
        password = badge.nvs_get_str('badge', 'wifi.password', '')
        nw.connect(ssid, password) if password else nw.connect(ssid)

        easydraw.msg("Connecting to wifi...", "Loading...", True)

        timeout = 150
        while not nw.isconnected():
            time.sleep(0.1)
            timeout = timeout - 1
            if (timeout < 1):
                easydraw.msg("Timeout :(")
                nw.active(True)
                return False
    return True
Пример #12
0
def show_names():
	global names
	c = False
	y = 10
	ugfx.clear()
	
	term.header(True, "About")
	print("Developers:")
	for n in range(0, len(names)):
		if (names[n]==" "):
			break
		print(" - "+names[n])
	
	easydraw.msg("Your badge has been made possible by the following people:", "About", True)
	
	for n in range(0, len(names)):
		if easydraw.msg(names[n]):
			time.sleep(0.5)
	
	easydraw.msg("Press back or start to quit!")
Пример #13
0
def show_category(pressed=True):
	global category
	if pressed:
		categories_list.visible(False)
		categories_list.enabled(False)
		slug = categories[categories_list.selected_index()]["slug"]
		easydraw.msg("Loading "+slug+"...", "Loading...", True)
		#Clean up list
		while category_list.count() > 0:
			category_list.remove_item(0)
		try:
			print("Loading "+slug+"...")
			f = open(woezel_repo+"/"+slug+".json")
			category = json.loads(f.read())
			f.close()
			gc.collect()
			for package in category:
				category_list.add_item("%s rev. %s" % (package["name"], package["revision"]))
			category_list.selected_index(0)
			category_list.visible(True)
			category_list.enabled(True)
			#Input handling
			ugfx.input_attach(ugfx.BTN_START, btn_home)
			ugfx.input_attach(ugfx.BTN_SELECT, btn_unhandled)
			ugfx.input_attach(ugfx.BTN_A, install_app)
			ugfx.input_attach(ugfx.BTN_B, show_categories)
			ugfx.input_attach(ugfx.JOY_UP, btn_unhandled)
			ugfx.input_attach(ugfx.JOY_DOWN, btn_unhandled)
			ugfx.input_attach(ugfx.JOY_LEFT, btn_unhandled)
			ugfx.input_attach(ugfx.JOY_RIGHT, btn_unhandled)
			#Hint
			easydraw.disp_string_right_bottom(0, "START:  Home")
			easydraw.disp_string_right_bottom(1, "B:      Back")
			easydraw.disp_string_right_bottom(2, "A:      Install")
			#Flush screen
			ugfx.flush()
		except BaseException as e:
			sys.print_exception(e)
			easydraw.msg("", "Error", True)
			time.sleep(1)
			show_categories()
Пример #14
0
def enable(showStatus=True):
    global failed, state, nw
    if not state:
        if not nw.isconnected():
            nw.active(True)
            ssid = badge.nvs_get_str('system', 'wifi.ssid', 'hackerhotel-insecure')
            password = badge.nvs_get_str('system', 'wifi.password')
            if showStatus:
                easydraw.msg("Connecting to '"+ssid+"'...")
            nw.connect(ssid, password) if password else nw.connect(ssid)
            timeout = badge.nvs_get_u8('system', 'wifi.timeout', 5)
            while not nw.isconnected():
                time.sleep(1)
                timeout = timeout - 1
                if (timeout<1):
                    if showStatus:
                        easydraw.msg("Error: could not connect!")
                    disable()
                    failed = True
                    return False
            state = True
            failed = False
            if showStatus:
                easydraw.msg("Connected!")
    return True
Пример #15
0
def list_apps(slug):
    global options
    global packages

    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)

    while options.count() > 0:
        options.remove_item(0)
    easydraw.msg("Loading list...", "Loading...", True)
    ugfx.flush(ugfx.LUT_FULL)

    try:
        f = urequests.get("https://badge.disobey.fi/eggs/category/%s/json" %
                          slug,
                          timeout=30)
        try:
            packages = f.json()
        finally:
            f.close()
    except BaseException as e:
        print("[Installer] Failed to download list of eggs:")
        sys.print_exception(e)
        easydraw.msg("Failed :(")
        ugfx.flush(ugfx.LUT_FULL)
        list_categories()
        gc.collect()
        return

    for package in packages:
        options.add_item("%s rev. %s" % (package["name"], package["revision"]))
    options.selected_index(0)

    ugfx.input_attach(ugfx.JOY_RIGHT, show_description)
    ugfx.input_attach(ugfx.BTN_START, install_app)
    ugfx.input_attach(ugfx.BTN_B, lambda pushed: list_categories()
                      if pushed else False)
    gc.collect()
Пример #16
0
def install_app(pressed=True):
	global category
	slug = category[category_list.selected_index()]["slug"]
	category = None
	gc.collect()
	
	if pressed:
		category_list.visible(False)
		category_list.enabled(False)
		#Input handling
		ugfx.input_attach(ugfx.BTN_START, btn_unhandled)
		ugfx.input_attach(ugfx.BTN_SELECT, btn_unhandled)
		ugfx.input_attach(ugfx.BTN_A, btn_unhandled)
		ugfx.input_attach(ugfx.BTN_B, btn_unhandled)
		ugfx.input_attach(ugfx.JOY_UP, btn_unhandled)
		ugfx.input_attach(ugfx.JOY_DOWN, btn_unhandled)
		ugfx.input_attach(ugfx.JOY_LEFT, btn_unhandled)
		ugfx.input_attach(ugfx.JOY_RIGHT, btn_unhandled)
		if not wifi.status():
			wifi.connect()
			wifi.wait()
			if not wifi.status():
				easydraw.msg("No WiFi.")
				time.sleep(2)
				show_category()
		easydraw.msg(slug,"Installing...", True)
		try:
			woezel.install(slug)
		except woezel.LatestInstalledError:
			easydraw.msg("Already on latest.")
			time.sleep(2)
			show_category()
		except:
			easydraw.msg("Failed.")
			time.sleep(2)
			show_category()
		easydraw.msg("Done.")
		show_category()
Пример #17
0
def show_names():
	global names
	c = False
	y = 10
	nos = 0
	ugfx.clear()
	
	term.header(True, "About")
	print("Developers:")
	for n in range(0, len(names)):
		if (names[n]==""):
			break
		print(" - "+names[n])
	
	nos = 9999
	
	for n in range(0, len(names)):
		if (nos > 3):
			if (nos < 900):
				time.sleep(2)
			nos = 0
			easydraw.msg("", "Thank you!", True)
		easydraw.msg(names[n])
		nos += 1
Пример #18
0
def main():
    """Main loop, should never exit."""

    easydraw.msg('setting up WiFi...')
    if not init_wifi():
        easydraw.msg('could not set up WiFi')
        return

    easydraw.msg('setting up RTC...')
    clock = Clock()

    easydraw.msg('setting up MQTT...')
    alerts = Alerts(topic_info=TOPIC_INFO)

    utime.sleep(1)

    output = Output()

    while True:
        output.draw(alerts.get(), clock.get())
        utime.sleep(1)
Пример #19
0
def enable(showStatus=True):
    global failed
    global state
    if not state:
        nw = network.WLAN(network.STA_IF)
        if not nw.isconnected():
            nw.active(True)
            ssid = badge.nvs_get_str('badge', 'wifi.ssid', '')
            password = badge.nvs_get_str('badge', 'wifi.password', '')
            if showStatus:
                easydraw.msg("Connecting to '" + ssid + "'...")
            result = "?"
            if password:
                nw.connect(ssid, password)
            else:
                nw.connect(ssid)
            timeout = badge.nvs_get_u8('badge', 'wifi.timeout', 30)
            show = round(timeout / 5)
            while not nw.isconnected():
                newShow = round(timeout / 5)
                if show != newShow:
                    easydraw.msg("(" + str(round(timeout / 2)) + " seconds)")
                    show = newShow
                time.sleep(0.5)
                timeout = timeout - 1
                if (timeout < 1):
                    if showStatus:
                        easydraw.msg("Error: could not connect!")
                    disable()
                    failed = True
                    return False
            state = True
            failed = False
            if showStatus:
                easydraw.msg("Connected!")
    return True
Пример #20
0
def download_info():
    import urequests as requests
    easydraw.msg("Checking for firmware updates...")
    result = False
    try:
        data = requests.get(version.otacheckurl)
    except:
        easydraw.msg("Error: can not fetch information.")
        time.sleep(5)
        return False
    try:
        result = data.json()
    except:
        data.close()
        easydraw.msg("")
        time.sleep(5)
        return False
    data.close()
    return result
Пример #21
0
def download_info():
    import urequests as requests
    easydraw.msg("Checking for updates...")
    result = False
    try:
        data = requests.get("https://badge.sha2017.org/version")
    except:
        easydraw.msg("Error: could not download JSON!")
        time.sleep(5)
        return False
    try:
        result = data.json()
    except:
        data.close()
        easydraw.msg("Error: could not decode JSON!")
        time.sleep(5)
        return False
    data.close()
    return result
Пример #22
0
def list_categories():
    global options
    global categories

    try:
        categories
    except:
        ugfx.input_init()
        easydraw.msg('Getting categories', "Loading...", True)
        try:
            f = urequests.get("https://badge.disobey.fi/eggs/categories/json",
                              timeout=30)
            categories = f.json()
        except:
            easydraw.msg('Failed :(')
            appglue.start_app('launcher', False)

            f.close()
        easydraw.msg('Success :)')
        options = ugfx.List(0, 0, int(ugfx.width()), ugfx.height())

    ugfx.input_attach(ugfx.JOY_UP, dummy_button_cb)
    ugfx.input_attach(ugfx.JOY_DOWN, dummy_button_cb)
    ugfx.input_attach(ugfx.BTN_START, select_category)
    ugfx.input_attach(
        ugfx.BTN_B, lambda pushed: appglue.start_app("launcher", False)
        if pushed else False)

    ugfx.clear(ugfx.WHITE)
    ugfx.flush()

    while options.count() > 0:
        options.remove_item(0)
    for category in categories:
        options.add_item("%s (%d) >" % (category["name"], category["eggs"]))
    options.selected_index(0)
    ugfx.flush(ugfx.LUT_FULL)
    gc.collect()
Пример #23
0
import ugfx, woezel, easywifi, easydraw, appglue, time, os


def stop():
    time.sleep(2)
    appglue.start_app("launcher")


easydraw.msg("Welcome!", "Updating...", True)

if not easywifi.status():
    if not easywifi.enable():
        stop()

try:
    apps = os.listdir('lib')
except OSError:
    easydraw.msg("There are no apps installed.")
    stop()

for app in apps:
    easydraw.msg("Updating '" + app + "'...")
    try:
        woezel.install(app)
        easydraw.msg("Done!")
    except:
        print("failed update. Already newest version?")

easydraw.msg("All your apps are now up-to-date!")
stop()
Пример #24
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)
Пример #25
0
import tasks.otacheck as otacheck, easydraw, term, appglue, time, version, easywifi, badge, ugfx, orientation

orientation.default()

term.header(True, "Update check")
print("Checking for updates...")
print("")
print("Currently installed:", version.name,
      "(Build " + str(version.build) + ")")

easydraw.msg("Current version:", "Update check", True)
easydraw.msg_nosplit(str(version.build) + ") " + version.name)
time.sleep(3)
available = 0

badge.nvs_set_u8('badge', 'OTA.ready', 0)


def start(pressed):
    if pressed:
        appglue.start_ota()


if not easywifi.status():
    if not easywifi.enable():
        easydraw.msg("Error: could not connect to WiFi!")

title = "Update check"
message = "?? Unknown state ??"

if easywifi.status():
Пример #26
0
import network, term, appglue, sys, version, time, json, gc, urequests, easydraw, machine

easydraw.msg(
    "This app can only be controlled using the USB-serial connection.",
    "Notice", True)

#Teminal installer
#V1 Kliment

#categories_fake=json.loads('[{"name":"stupid","eggs":1,"slug":"stupid"},{"name":"trolley","eggs":3,"slug":"trolley"},{"name":"empty","eggs":0,"slug":"empty"}]')
#eggs_fake=None#json.loads('[{"name":"app1","description":"This is app 1","slug":"app1"},{"name":"app2","description":"This is app 2","slug":"app2"}]')

#categories=None#categories_fake


def connectWiFi():
    nw = network.WLAN(network.STA_IF)
    if not nw.isconnected():
        nw.active(True)
        ssid = machine.nvs_getstr('system', 'wifi.ssid') or ''
        password = machine.nvs_getstr('system', 'wifi.password')
        nw.connect(ssid, password) if password else nw.connect(ssid)

        print("Connecting to '" + ssid + "'...")

        timeout = 150
        while not nw.isconnected():
            time.sleep(0.1)
            timeout = timeout - 1
            if (timeout < 1):
                print("Timeout while connecting!")
Пример #27
0
def install_app(active):
    if active:
        global options
        global packages
        global selected_app

        index = options.selected_index()

        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)

        easydraw.msg(packages[index]["name"], "Installing...", True)

        latest = False
        import woezel
        selected_app = packages[index]["slug"]
        try:
            woezel.install(selected_app)
        except woezel.LatestInstalledError:
            latest = True
        except:
            easydraw.msg("Failed :(")
            time.sleep(4)
            list_categories()
            return

        if latest:
            easydraw.msg("Already installed!")
        else:
            easydraw.msg("Installed!")
        easydraw.msg(packages[index]["name"])
        easydraw.msg("[BACK]                    [RUN]")
        ugfx.input_attach(ugfx.BTN_START, start_app)
        ugfx.input_attach(ugfx.BTN_B, start_categories)
        gc.collect()
Пример #28
0
            appglue.start_app('launcher', False)

            f.close()
        easydraw.msg('Success :)')
        options = ugfx.List(0, 0, int(ugfx.width()), ugfx.height())

    ugfx.input_attach(ugfx.JOY_UP, dummy_button_cb)
    ugfx.input_attach(ugfx.JOY_DOWN, dummy_button_cb)
    ugfx.input_attach(ugfx.BTN_START, select_category)
    ugfx.input_attach(
        ugfx.BTN_B, lambda pushed: appglue.start_app("launcher", False)
        if pushed else False)

    ugfx.clear(ugfx.WHITE)
    ugfx.flush()

    while options.count() > 0:
        options.remove_item(0)
    for category in categories:
        options.add_item("%s (%d) >" % (category["name"], category["eggs"]))
    options.selected_index(0)
    ugfx.flush(ugfx.LUT_FULL)
    gc.collect()


if not connectWiFi():
    easydraw.msg('WiFi failure :(')
    appglue.start_app('launcher', False)
else:
    list_categories()
Пример #29
0
            splash = splash[7:len(splash)]
            badge.mount_sdcard()

        def back_button_default_action(pressed):
            if pressed:
                esp.rtcmem_write_string("")
                machine.deepsleep(1)

        ugfx.input_attach(ugfx.BTN_B, back_button_default_action)

        __import__(splash)
    else:
        ugfx.clear(ugfx.WHITE)
        ugfx.flush(ugfx.LUT_FULL)
except BaseException as e:
    sys.print_exception(e)
    import easydraw
    easydraw.msg("", "Fatal exception", True)

    # if we started the splash screen and it is not the default splash screen,
    # then revert to original splash screen.
    if splash == badge.nvs_get_str('boot', 'splash',
                                   'splash') and splash != 'splash':
        print(">> Restored default splashscreen! <<")
        badge.nvs_erase_key('boot', 'splash')
    easydraw.msg(str(e))
    import time
    time.sleep(5)
    import appglue
    appglue.home()
Пример #30
0
def start_app(app, display = True):
	if display:
		easydraw.msg(app, "Loading...", True)
		term.header(True, "Loading application "+app+"...")
	esp.rtcmem_write_string(app)
	deepsleep.reboot()