示例#1
0
def draw(mode, goingToSleep=False):
    if mode:
        # We flush the buffer and wait
        ugfx.flush(ugfx.LUT_FULL)
        badge.eink_busy_wait()
    else:
        # We prepare the screen refresh
        ugfx.clear(ugfx.WHITE)
        if goingToSleep:
            info1 = 'Sleeping...'
            info2 = 'Press any key to wake up'
        else:
            info1 = 'Press start to open the launcher'
            if otac.available(False):
                info2 = 'Press select to start OTA update'
            else:
                info2 = ''
        l = ugfx.get_string_width(info1,"Roboto_Regular12")
        ugfx.string(296-l, 0, info1, "Roboto_Regular12",ugfx.BLACK)
        l = ugfx.get_string_width(info2,"Roboto_Regular12")
        ugfx.string(296-l, 12, info2, "Roboto_Regular12",ugfx.BLACK)
        
        easydraw.nickname()
        
        vUsb = badge.usb_volt_sense()
        vBatt = badge.battery_volt_sense()
        vBatt += vDrop
        charging = badge.battery_charge_status()

        easydraw.battery(vUsb, vBatt, charging)
        
        if vBatt>500:
            ugfx.string(52, 0, str(round(vBatt/1000, 1)) + 'v','Roboto_Regular12',ugfx.BLACK)
示例#2
0
def clear_ghosting():
    ugfx.clear(ugfx.BLACK)
    ugfx.flush()
    badge.eink_busy_wait()
    ugfx.clear(ugfx.WHITE)
    ugfx.flush()
    badge.eink_busy_wait()
示例#3
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)
示例#4
0
def passInputDone(passIn):
    badge.nvs_set_str("system", "wifi.password", passIn)
    ugfx.clear(ugfx.WHITE)
    ugfx.string(100, 50, 'Restarting!', 'Roboto_Regular18', ugfx.BLACK)
    ugfx.flush()
    badge.eink_busy_wait()
    system.reboot()
示例#5
0
def sleep(duration=0, status=False):
    import time, os, badge
    #---BADGE specific---
    try:
        os.umountsd()
    except:
        pass
    badge.setPower(False)
    machine.RTC().wake_on_ext0(pin=machine.Pin(39),
                               level=0)  #Navigation buttons
    machine.RTC().wake_on_ext1(
        [machine.Pin(34, machine.Pin.IN),
         machine.Pin(35, machine.Pin.IN)], 0)  #Keyboard
    badge.eink_busy_wait()
    #---
    if (duration >= 86400000):  #One day
        duration = 0
    if status:
        import term
        if duration < 1:
            term.header(True, "Sleeping until button is pressed...")
        else:
            term.header(True, "Sleeping for " + str(duration) + "ms...")
    time.sleep(0.05)
    machine.deepsleep(duration)
示例#6
0
def reboot():
    try:
        import badge
        badge.eink_busy_wait()
    except:
        pass
    import machine
    machine.deepsleep(2)
示例#7
0
def await_network():
    while True:
        easywifi.enable()
        if easywifi.state:
            break
        show('No internet!')
        badge.eink_busy_wait()
        show('Checking connection...', speed='fast')
示例#8
0
 def display():
     for x in range(0, width):
         for y in range(0, height):
             if grid[x][y]:
                 ugfx.area(x * cell_width, y * cell_height, cell_width - 1,
                           cell_height - 1, ugfx.BLACK)
             else:
                 ugfx.area(x * cell_width, y * cell_height, cell_width - 1,
                           cell_height - 1, ugfx.WHITE)
     badge.eink_busy_wait()
     ugfx.flush()
示例#9
0
def draw(entries):
    debug("Will now draw")
    y = 10
    ugfx.clear(ugfx.WHITE)
    for entry in entries:
        extension = entry[0]
        name = entry[1]
        ugfx.string(10, y, extension + " -> " + name, "Roboto_Regular12", 0)
        y += 20
    ugfx.flush()
    badge.eink_busy_wait()
示例#10
0
def draw_task():
    global drawCallback  #The function that allows us to hook into our host
    global drawCallbacks  #The functions of the services
    requestedInterval = 99999999
    y = ugfx.height()

    drawCallback(False)  # Prepare draw

    deleted = []

    for i in range(0, len(drawCallbacks)):
        rqi = 0
        try:
            cb = drawCallbacks[i].draw
            try:
                [rqi, space_used] = cb(y, False)
            except:
                [rqi, space_used] = cb(y)
            y = y - space_used
        except BaseException as e:
            print("[SERVICES] Exception in service draw:")
            sys.print_exception(e)
            deleted.append(cb)
            continue
        if rqi > 0 and rqi < requestedInterval:
            # Service wants to loop again in rqi ms
            requestedInterval = rqi
        elif rqi <= 0:
            # Service doesn't want to draw again until next wakeup
            deleted.append(cb)

    for i in range(0, len(deleted)):
        dcb = deleted[i]
        print("[DEBUG] Deleted draw callback: ", dcb)
        drawCallbacks = list(dcb for dcb in drawCallbacks if dcb != deleted[i])

    badge.eink_busy_wait()

    if requestedInterval < 1000:
        #Draw at most once a second
        print("[SERVICES] Can't draw more than once a second!")
        requestedInterval = 1000

    if requestedInterval >= 99999999:
        print("[SERVICES] No draw interval returned.")
        requestedInterval = -1

    retVal = 0

    if len(drawCallbacks) > 0 and requestedInterval >= 0:
        print("[SERVICES] New draw requested in " + str(requestedInterval))
        retVal = requestedInterval
    drawCallback(True)  # Complete draw
    return retVal
示例#11
0
def start_app(pushed):
    if (pushed):
        ugfx.clear(ugfx.BLACK)
        ugfx.string(40, 25, "Running:", "Roboto_BlackItalic24", ugfx.WHITE)
        ugfx.string(100, 75, packages[options.selected_index()]["name"],
                    "PermanentMarker22", ugfx.WHITE)
        ugfx.flush()
        selected = packages[options.selected_index()]["slug"]
        esp.rtcmem_write_string(selected)
        badge.eink_busy_wait()
        esp.start_sleeping(1)
示例#12
0
def run_it(pushed):
    if (pushed):
        selected = options.selected_text()
        options.destroy()

        ugfx.clear(ugfx.BLACK)
        ugfx.string(40, 25, "Running:", "Roboto_BlackItalic24", ugfx.WHITE)
        ugfx.string(100, 75, selected, "PermanentMarker22", ugfx.WHITE)
        ugfx.flush()
        badge.eink_busy_wait()
        esp.rtcmem_write_string(selected)
        esp.start_sleeping(1)
示例#13
0
def start_sleeping(sleepTime=0):
    machine.RTC().wake_on_ext0(pin=machine.Pin(25), level=0)

    term.header(True, "Going to sleep...")
    if (sleepTime >= 86400000):  #One day
        sleepTime = 0
    if (sleepTime < 1):
        print("Sleeping until touchbutton is pressed...")
    else:
        print("Sleeping for " + str(sleepTime) + "ms...")
    time.sleep(0.05)
    badge.eink_busy_wait()
    machine.deepsleep(sleepTime)
示例#14
0
def switchme(pushed):
    global switch
    if (pushed):
        if switch:
            print("ToorCamp")
            switch = False
            #clearGhosting()
            ugfx.clear(ugfx.WHITE)
            badge.eink_png(0, 0, '/lib/toorcamp/toorcamp.png')
            badge.eink_busy_wait()
        else:
            print("ToorCon")
            switch = True
            #clearGhosting()
            ugfx.clear(ugfx.WHITE)
            badge.eink_png(0, 0, '/lib/toorcamp/toorcon.png')
            badge.eink_busy_wait()
示例#15
0
def draw(mode, goingToSleep=False):
    ugfx.orientation(0)
    if mode:
        # We flush the buffer and wait
        ugfx.flush(ugfx.LUT_FULL)
        badge.eink_busy_wait()
    else:
        # We prepare the screen refresh
        ugfx.clear(ugfx.WHITE)
        if goingToSleep:
            info1 = 'Sleeping...'
            info2 = 'Press any key to wake up'
        else:
            info1 = 'Press start to open the launcher'
            if otac.available(False):
                info2 = 'Press select to start OTA update'
            else:
                info2 = ''

        def disp_string_right(y, s):
            l = ugfx.get_string_width(s, "Roboto_Regular12")
            ugfx.string(296 - l, y, s, "Roboto_Regular12", ugfx.BLACK)

        disp_string_right(0, info1)
        disp_string_right(12, info2)

        if badge.safe_mode():
            disp_string_right(92, "Safe Mode - services disabled")
            disp_string_right(104,
                              "Sleep disabled - will drain battery quickly")
            disp_string_right(116, "Press Reset button to exit")

        nickname()

        on_usb = pm.usb_attached()
        vBatt = badge.battery_volt_sense()
        vBatt += vDrop
        charging = badge.battery_charge_status()

        battery(on_usb, vBatt, charging)

        if vBatt > 500:
            ugfx.string(52, 0,
                        str(round(vBatt / 1000, 1)) + 'v', 'Roboto_Regular12',
                        ugfx.BLACK)
示例#16
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)

    badge.eink_busy_wait()
    appglue.home()
示例#17
0
def sleep(duration=0, status=False):
    import machine, time
    machine.RTC().wake_on_ext0(pin=machine.Pin(25), level=0)
    machine.RTC().wake_on_ext1(
        [machine.Pin(12, machine.Pin.IN, machine.Pin.PULL_UP)], 0)
    if (duration >= 86400000):  #One day
        duration = 0
    if status:
        import term
        if duration < 1:
            term.header(True, "Sleeping until touchbutton is pressed...")
        else:
            term.header(True, "Sleeping for " + str(duration) + "ms...")
    time.sleep(0.05)
    try:
        import badge
        badge.eink_busy_wait()
    except:
        pass
    machine.deepsleep(duration)
示例#18
0
def sleep(duration=0, status=False):
    import time, os, badge
    #---SHA2017 specific---
    try:
        os.umountsd()
    except:
        pass
    badge.setPower(False)
    badge.eink_busy_wait()
    machine.RTC().wake_on_ext0(pin=machine.Pin(25), level=0)
    machine.RTC().wake_on_ext1(
        [machine.Pin(12, machine.Pin.IN, machine.Pin.PULL_UP)], 0)
    #---
    if (duration >= 86400000):  #One day
        duration = 0
    if status:
        import term
        if duration < 1:
            term.header(True, "Sleeping until touchbutton is pressed...")
        else:
            term.header(True, "Sleeping for " + str(duration) + "ms...")
    time.sleep(0.05)
    machine.deepsleep(duration)
示例#19
0
def start_sleeping(time=0):
    badge.eink_busy_wait()
    machine.deepsleep(time)
示例#20
0
def reboot():
    badge.eink_busy_wait()
    machine.deepsleep(1)
示例#21
0
def start_sleeping(time=0):
    pin = machine.Pin(25)
    rtc = machine.RTC()
    rtc.wake_on_ext0(pin=pin, level=0)
    badge.eink_busy_wait()
    machine.deepsleep(time)
示例#22
0
if nick:
    badge.nvs_set_str("owner", "name", nick)

#Nice clean screen
ugfx.clear(ugfx.BLACK)
ugfx.flush()
ugfx.clear(ugfx.WHITE)
ugfx.flush()

ugfx.string_box(0, 10, 296, 26, "STILL", "Roboto_BlackItalic24", ugfx.BLACK,
                ugfx.justifyCenter)
ugfx.string_box(0, 45, 296, 38, nick, "PermanentMarker36", ugfx.BLACK,
                ugfx.justifyCenter)
ugfx.string_box(0, 94, 296, 26, "Anyway", "Roboto_BlackItalic24", ugfx.BLACK,
                ugfx.justifyCenter)

#the line under the text
str_len = ugfx.get_string_width(nick, "PermanentMarker36")
line_begin = int((296 - str_len) / 2)
line_end = str_len + line_begin
ugfx.line(line_begin, 83, line_end, 83, ugfx.BLACK)

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

ugfx.flush(ugfx.LUT_FULL)

import deepsleep, badge
badge.eink_busy_wait()
deepsleep.start_sleeping(60000)
示例#23
0
def set_message(text):
    ugfx.clear(ugfx.WHITE)
    ugfx.string(10, 10, text, "Roboto_Regular12", 0)
    ugfx.flush()
    badge.eink_busy_wait()