import machine, display, time, system

currentState = machine.nvs_getint('system', 'factory_checked')

display.drawFill(0xFFFFFF)
display.drawText(0, 0, "Welcome to the BADGE.TEAM platform firmware!",
                 0x000000, "7x5")
display.drawText(0, 6, "Please wait while we're setting things up...",
                 0x000000, "7x5")
display.flush()
time.sleep(2)

# Install icons to the filesystem if needed
try:
    media = uos.listdir("/media")
    icons = [
        "alert", "bell", "bug", "busy", "charge", "crown", "earth", "flag",
        "music", "ok", "wifi", "usb"
    ]
    for icon in icons:
        if not icon + ".png" in media:
            raise (BaseException(""))
except:
    import dashboard.resources.png_icons

# We have completed the factory script
machine.nvs_setint('system', 'factory_checked', 3)
system.home()
Esempio n. 2
0
import hid, keypad, display, time

display.drawFill(0x0000FF)
display.flush()
global fix
fix = False


def on_key(key_index, pressed):
    global fix
    print('key event')
    if (pressed):
        hid.keyboard_type("Cyber")


keypad.add_handler(on_key)
        ugfx.input_attach(ugfx.JOY_LEFT, btn_unhandled)
        ugfx.input_attach(ugfx.JOY_RIGHT, btn_unhandled)
        category = []
        selectBox.clear()
        easydraw.messageCentered("Installing...\n" + slug, True,
                                 "/media/busy.png")
        with open("/cache/installList", "w") as f:
            f.write(slug)
        system.start("dashboard._installer_exec")


# ----

orientation.default()
selectBox = ugfx.List(0, 0, ugfx.width(), ugfx.height())
repo = woezel_repo

lastCategory = 0

easydraw.messageCentered("Loading...", True, "/media/busy.png")
display.drawFill()
if not repo.load():
    if not repo.update():
        if repo.lastUpdate == 0:
            easydraw.messageCentered("Repository not available!", False,
                                     "/media/alert.png")
            display.drawFill()
            system.launcher()

show_categories()
Esempio n. 4
0
def display_connection(ip):
    "Prints connection details on the display."
    display.drawFill(0x000000)
    display.drawText(5, 5, "{}:{}".format(ip, PORT), 0xFFFFFF)
    display.flush()
Esempio n. 5
0
def onB(pressed):
	if pressed:
		display.drawFill(0x000000)
		drawMessageBox("Starting launcher...")
		display.flush(display.FLAG_LUT_FASTEST)
		system.launcher()
Esempio n. 6
0
def drawTitle():
	display.drawFill(0x000000)
	display.drawRect(0,0,display.width(), 10, True, 0xFFFFFF)
	display.drawText(2, 0, "SD card tool", 0x000000, "org18")
	if pressed:
		display.drawFill(0x000000)
		drawMessageBox("Loading app...")
		display.flush()
		system.start(apps[currentApp]["path"])

def onB(pressed):
	if pressed:
		display.drawFill(0x000000)
		drawMessageBox("Loading homescreen...")
		display.flush()
		system.home()

# Launcher
orientation.landscape()
display.drawFill(0x000000)
drawMessageBox("Loading...")
display.flush()
term.header(True, "Loading...")
apps = listApps()
amountOfUserApps = len(apps)
apps.append({"path":"dashboard.home",                  "name":"Home",               "icon":home_icon,      "category":"system"})
apps.append({"path":"dashboard.installer",             "name":"Installer",          "icon":installer_icon, "category":"system"})
if amountOfUserApps > 0:
	apps.append({"path":"dashboard.tools.uninstall",       "name":"Remove an app",      "icon":trash_icon,     "category":"system"})
	apps.append({"path":"dashboard.tools.update_apps",     "name":"Update apps",        "icon":installer_icon, "category":"system"})
if haveSD:
	apps.append({"path":"dashboard.tools.movetosd",        "name":"Move from/to SD",    "icon":settings_icon, "category":"system"})
apps.append({"path":"dashboard.tools.update_firmware", "name":"Update firmware",    "icon":installer_icon, "category":"system"})
apps.append({"path":"dashboard.settings.nickname",     "name":"Configure nickname", "icon":nickname_icon,  "category":"system"})
apps.append({"path":"dashboard.settings.wifi",         "name":"WiFi setup",         "icon":settings_icon,  "category":"system"})
Esempio n. 8
0
def drawTask(onSleep=False):
    global gui_redraw, cfg_nickname, gui_apps, gui_app_current, ota_available
    if gui_redraw or onSleep:
        gui_redraw = False
        display.drawFill(COLOR_BG)
        currHeight = 0
        noLine = False
        if gui_app_current < 0:
            if cfg_logo:
                if cfg_nickname:
                    # Logo and nickename enabled, first print nickname
                    display.drawText((display.width() - display.getTextWidth(
                        cfg_nick_text, "roboto_regular12")) // 2, currHeight,
                                     cfg_nick_text, COLOR_FG,
                                     "roboto_regular12")
                    currHeight += display.getTextHeight(
                        cfg_nick_text,
                        "roboto_regular12")  #easydraw.nickname()
                    currHeight += 4
                    display.drawLine(0, currHeight,
                                     display.width() - 1, currHeight, COLOR_FG)
                    currHeight += 4
                #Print logo
                app_height = display.height() - 16 - currHeight
                logoHeight = drawLogo(currHeight, app_height, True)
                if logoHeight > 0:
                    noLine = True
                if logoHeight < 1:
                    #Logo enabled but failed to display
                    title = "BADGE.TEAM"
                    subtitle = "PLATFORM"
                    logoHeight = display.getTextHeight(
                        title, "permanentmarker22") + display.getTextHeight(
                            subtitle, "fairlight12")
                    display.drawText(
                        (display.width() -
                         display.getTextWidth(title, "permanentmarker22")) //
                        2, currHeight + (app_height - logoHeight) // 2, title,
                        COLOR_FG, "permanentmarker22")
                    currHeight += display.getTextHeight(
                        title, "permanentmarker22")
                    display.drawText(
                        (display.width() -
                         display.getTextWidth(subtitle, "fairlight12")) // 2,
                        currHeight + (app_height - logoHeight) // 2, subtitle,
                        COLOR_FG, "fairlight12")
                    currHeight += display.getTextHeight(
                        subtitle, "fairlight12")
            else:
                noLine = True
                display.drawPng(0, 0, LOGO)
        else:
            display_app(currHeight)

        if onSleep:
            info = 'Sleeping...'
        #elif not rtc.isSet():
        #	info = "RTC not available"
        elif ota_available:
            info = "Update available!"
        #elif wifi_status_curr:
        #	info = "WiFi connected"
        else:
            info = ""  #'Press START'
        if not noLine:
            display.drawLine(0,
                             display.height() - 16, display.width(),
                             display.height() - 16, COLOR_FG)
        easydraw.disp_string_right_bottom(0, info)
        if len(gui_apps) > 0:
            drawPageIndicator(len(gui_apps), gui_app_current)
        if cfg_greyscale:
            display.flush(display.FLAG_LUT_GREYSCALE)
        else:
            display.flush(display.FLAG_LUT_NORMAL)
    return 1000
Esempio n. 9
0
def drawTask(onSleep=False):
    global gui_redraw, cfg_nickname, gui_apps, gui_app_current, ota_available
    if gui_redraw or onSleep:
        gui_redraw = False
        display.drawFill(0xFFFFFF)
        currHeight = 0
        noLine = False
        if gui_app_current < 0:
            nick = machine.nvs_getstr("owner", "name")
            if cfg_logo and cfg_nickname:
                display.drawText(
                    (display.width() -
                     display.getTextWidth(nick, "roboto_regular12")) // 2,
                    currHeight, nick, 0x000000, "roboto_regular12")
                currHeight += display.getTextHeight(
                    nick, "roboto_regular12")  #easydraw.nickname()
                currHeight += 4
                display.drawLine(0, currHeight,
                                 display.width() - 1, currHeight, 0x000000)
                currHeight += 4
            app_height = display.height() - 16 - currHeight
            logoHeight = drawLogo(currHeight, app_height, True)
            if logoHeight > 0:
                noLine = True
            if (not cfg_logo) and cfg_nickname and nick:
                noLine = True
                display.drawText(
                    (display.width() -
                     display.getTextWidth(nick, "roboto_regular12")) // 2,
                    currHeight, nick, 0x000000, "roboto_regular12")
                currHeight += display.getTextHeight(nick, "roboto_regular12")
            else:
                title = "BADGE.TEAM"
                subtitle = consts.INFO_FIRMWARE_NAME
                logoHeight = display.getTextHeight(
                    title, "fairlight12") + display.getTextHeight(
                        subtitle, "roboto_regular12")
                display.drawText(
                    (display.width() -
                     display.getTextWidth(title, "fairlight12")) // 2,
                    currHeight + (app_height - logoHeight) // 2, title,
                    0x000000, "fairlight12")
                currHeight += display.getTextHeight(title, "fairlight12")
                display.drawText(
                    (display.width() -
                     display.getTextWidth(subtitle, "roboto_regular12")) // 2,
                    currHeight + (app_height - logoHeight) // 2, subtitle,
                    0x000000, "roboto_regular12")
                currHeight += display.getTextHeight(subtitle,
                                                    "roboto_regular12")
        else:
            display_app(currHeight)

        if onSleep:
            info = 'Sleeping...'
        #elif not rtc.isSet():
        #	info = "RTC not available"
        elif ota_available:
            info = "Update available!"
        #elif wifi_status_curr:
        #	info = "WiFi connected"
        else:
            info = 'Press OK'
        if not noLine:
            display.drawLine(0,
                             display.height() - 16, display.width(),
                             display.height() - 16, 0x000000)
        easydraw.disp_string_right_bottom(0, info)
        if len(gui_apps) > 0:
            drawPageIndicator(len(gui_apps), gui_app_current)
        if cfg_greyscale:
            display.flush(display.FLAG_LUT_GREYSCALE)
        else:
            display.flush(display.FLAG_LUT_NORMAL)
    return 1000
Esempio n. 10
0
def clear(arg=None):
	if arg != None:
		display.drawFill(arg)
	else:
		display.drawFill()
Esempio n. 11
0
def msg(text1, text2=""):
    display.drawFill(0x000000)
    display.drawText(0, 0, text1, 0xFFFFFF, "7x5")
    display.drawText(0, 8, text2, 0xFFFFFF, "7x5")
    display.flush()
Esempio n. 12
0
s.bind(("0.0.0.0", 42))

font = "7x5"
bgColor = 0x000000
fgColor = 0xFFFFFF

while (True):
    bytesAddressPair = s.recvfrom(bufferSize)
    message = bytesAddressPair[0]
    address = bytesAddressPair[1]
    #print(address, message)
    try:
        if (message.startswith(b"T")):
            text = message.decode("utf-8")[1:]
            print("Text", text)
            display.drawFill(bgColor)
            y = 0
            if font.lower() == "ocra16":
                y = -1
            if font.lower() == "roboto_regular18":
                y = -3
            if font.lower() == "roboto_regular12":
                y = -3
            if font.lower() == "dejavusans20":
                y = -4
            display.drawText(0, y, text, fgColor, font)
            display.flush()
        elif (message.startswith(b"I")):
            print("Invert")
            bgColor = 0xFFFFFF
            fgColor = 0x000000
Esempio n. 13
0
def _draw():
    global _TEXT, _CURSOR_X, _CURSOR_Y, _TITLE, _MODE, _XPOS, _LASTPARTMOVEUP, _VISIBLELINE

    _MODE_TEXT = "INP"
    if _MODE == 1:
        _MODE_TEXT = "CUR"
    if _MODE == 2:
        _MODE_TEXT = "ACT"

    _display.drawFill(0xFFFFFF)
    _display.drawRect(0, 0, _display.width(), 14, True, 0x000000)
    _display.drawText(0, 0, _TITLE, 0xFFFFFF, _FONT_KEY)
    _display.drawText(128 - 24, 0, _MODE_TEXT, 0xFFFFFF, _FONT_KEY)

    offsetX1 = 0
    arrow1 = False
    offsetX2 = 0
    arrow2 = False

    cursorPos = _calcPos()

    _TEXTWithCursor = _TEXT[:cursorPos] + "|" + _TEXT[cursorPos:]

    _TEXTWithCursorLines = _TEXTWithCursor.split("\n")
    _TEXTWithCursorLines.append("")

    lineWithCursorLength = _display.getTextWidth(
        _TEXTWithCursorLines[_CURSOR_Y], _FONT_TEXT)
    lineWithCursorLengthUntilCursor = _display.getTextWidth(
        _TEXTWithCursorLines[_CURSOR_Y][:_CURSOR_X], _FONT_TEXT)

    if (lineWithCursorLength < _display.width()):
        offsetX = 0
    else:
        offsetX = lineWithCursorLengthUntilCursor + _display.getTextWidth(
            " ", _FONT_TEXT) - _display.width() // 2
        if offsetX < -_display.getTextWidth(" ", _FONT_TEXT):
            offsetX = -_display.getTextWidth(" ", _FONT_TEXT)

    arrow = lineWithCursorLength - offsetX > _display.width()

    if _VISIBLELINE + 1 < _CURSOR_Y:
        _VISIBLELINE = _CURSOR_Y - 1

    if _VISIBLELINE < 0:
        _VISIBLELINE = 0

    if _CURSOR_Y < _VISIBLELINE:
        _VISIBLELINE = _CURSOR_Y

    for i in range(len(_TEXTWithCursorLines)):
        v = "-"
        if i == _VISIBLELINE:
            v = ">"

    arrow1L = False
    arrow2L = False

    if _CURSOR_Y == _VISIBLELINE:
        offsetX1 = offsetX
        if offsetX > 0:
            arrow1L = True
        if arrow:
            arrow1 = True
    else:
        if _display.getTextWidth(_TEXTWithCursorLines[_VISIBLELINE],
                                 _FONT_TEXT) > _display.width():
            arrow1 = True
    if _CURSOR_Y == _VISIBLELINE + 1:
        offsetX2 = offsetX
        if offsetX > 0:
            arrow2L = True
        if arrow:
            arrow2 = True
    else:
        if _display.getTextWidth(_TEXTWithCursorLines[_VISIBLELINE + 1],
                                 _FONT_TEXT) > _display.width():
            arrow2 = True

    _display.drawText(-offsetX1, 17 + 0 * 13,
                      _TEXTWithCursorLines[_VISIBLELINE], 0x000000, _FONT_TEXT)
    _display.drawText(-offsetX2, 17 + 1 * 13,
                      _TEXTWithCursorLines[_VISIBLELINE + 1], 0x000000,
                      _FONT_TEXT)

    if arrow1:
        _display.drawRect(119, 17 + 0 * 13, 9,
                          _display.getTextHeight(" ", _FONT_TEXT), True,
                          0x000000)
        _display.drawText(120, 17 + 0 * 13, ">", 0xFFFFFF, _FONT_TEXT)

    if arrow2:
        _display.drawRect(119, 17 + 1 * 13, 9,
                          _display.getTextHeight(" ", _FONT_TEXT), True,
                          0x000000)
        _display.drawText(120, 17 + 1 * 13, ">", 0xFFFFFF, _FONT_TEXT)

    if arrow1L:
        _display.drawRect(0, 17 + 0 * 13, 9,
                          _display.getTextHeight(" ", _FONT_TEXT), True,
                          0x000000)
        _display.drawText(0, 17 + 0 * 13, "<", 0xFFFFFF, _FONT_TEXT)

    if arrow2L:
        _display.drawRect(0, 17 + 1 * 13, 9,
                          _display.getTextHeight(" ", _FONT_TEXT), True,
                          0x000000)
        _display.drawText(0, 17 + 1 * 13, "<", 0xFFFFFF, _FONT_TEXT)

    _display.drawRect(0,
                      _display.height() - 15, _display.width(), 15, True,
                      0x000000)
    if _MODE == 0:
        for i in range(9):
            item = _XPOS + (i - 4)
            if item < 0:
                item = len(_CHAR_MAP) + item
            if item >= len(_CHAR_MAP):
                item = item % len(_CHAR_MAP)
            if _XPOS == item:
                _display.drawRect(i * 14 + 1,
                                  _display.height() - 14, 14, 14, True,
                                  0xFFFFFF)
                _display.drawRect(i * 14 + 1,
                                  _display.height() - 14, 14, 14, False,
                                  0x000000)
                _display.drawText(i * 14 + 1 + 3,
                                  _display.height() - 14, _CHAR_MAP[item],
                                  0x000000, _FONT_KEY)
            else:
                _display.drawRect(i * 14 + 1,
                                  _display.height() - 14, 14, 14, True,
                                  0x000000)
                _display.drawText(i * 14 + 1 + 3,
                                  _display.height() - 14, _CHAR_MAP[item],
                                  0xFFFFFF, _FONT_KEY)
    elif _MODE == 1:
        _display.drawText(0,
                          _display.height() - 14, "CURSOR, A: NL, B: RM",
                          0xFFFFFF, _FONT_KEY)
    elif _MODE == 2:
        _display.drawText(0,
                          _display.height() - 14, "A: OK, B: CANCEL", 0xFFFFFF,
                          _FONT_KEY)
    else:
        _display.drawText(0,
                          _display.height() - 14, "Processing...", 0xFFFFFF,
                          _FONT_KEY)

    _display.flush(_display.FLAG_LUT_FASTEST)
Esempio n. 14
0
def drawTask(onSleep=False):
    global gui_redraw, cfg_nickname, gui_apps, gui_app_current, ota_available
    if gui_redraw or onSleep:
        gui_redraw = False
        display.drawFill(COLOR_BG)
        currHeight = 0
        noLine = False
        if gui_app_current < 0:
            if cfg_logo:
                #Print logo
                app_height = display.height() - 16 - currHeight
                logoHeight = drawLogo(currHeight, app_height, True)
                if logoHeight > 0:
                    noLine = True
                if logoHeight < 1:
                    #Logo enabled but failed to display
                    title = "BADGE.TEAM"
                    subtitle = "PLATFORM"
                    logoHeight = display.getTextHeight(
                        title, "permanentmarker22") + display.getTextHeight(
                            subtitle, "fairlight12")
                    display.drawText(
                        (display.width() -
                         display.getTextWidth(title, "permanentmarker22")) //
                        2, currHeight + (app_height - logoHeight) // 2, title,
                        COLOR_FG, "permanentmarker22")
                    currHeight += display.getTextHeight(
                        title, "permanentmarker22")
                    display.drawText(
                        (display.width() -
                         display.getTextWidth(subtitle, "fairlight12")) // 2,
                        currHeight + (app_height - logoHeight) // 2, subtitle,
                        COLOR_FG, "fairlight12")
                    currHeight += display.getTextHeight(
                        subtitle, "fairlight12")
            else:
                noLine = True
                textWidth = display.getTextWidth(cfg_nick_text, "ocra22")
                textHeight = display.getTextHeight(cfg_nick_text, "ocra22")
                textX = (display.width() - textWidth) // 2
                textY = (display.height() - textHeight) // 2
                display.drawText(textX, textY, cfg_nick_text, COLOR_FG,
                                 "ocra22")
        else:
            display_app(currHeight)

        if onSleep:
            info = 'Zzz...'
        elif ota_available:
            info = "(Firmware update available!)"
        else:
            info = ""  #'Press START to open the menu.'
        if not noLine:
            display.drawLine(0,
                             display.height() - 16, display.width(),
                             display.height() - 16, COLOR_FG)
        easydraw.disp_string_right_bottom(0, info)
        if len(gui_apps) > 0:
            drawPageIndicator(len(gui_apps), gui_app_current)
        if cfg_greyscale:
            display.flush(display.FLAG_LUT_GREYSCALE)
        else:
            display.flush(display.FLAG_LUT_NORMAL)
    return 1000
def onB(pressed):
	if pressed:
		display.drawFill(0x000000)
		drawMessageBox("Loading homescreen...")
		display.flush()
		system.home()
Esempio n. 16
0
#import virtualtimers, display
#virtualtimers.activate(25)
#COLOR_FG = 0xFFFFFF
#COLOR_BG = 0x000000
#cfg_logo = False
#cfg_nickname = True
#cfg_nick_text = "Hello world"

# Text scroller
display.windowCreate(
    "scroller", 512,
    32)  #Workaround!!! windows get corrupted when size is not in units of 8
display.windowShow("scroller")
display.windowMove("scroller", 65,
                   display.height() - 22)  # Move out of visible screen
display.drawFill("scroller", COLOR_BG)
display.drawText("scroller", 0, 0, cfg_nick_text, COLOR_FG,
                 "permanentmarker22")

scrollerStartPos = 129
scrollerEndPos = -display.getTextWidth(cfg_nick_text,
                                       "permanentmarker22") - 128
scrollerPos = scrollerStartPos

offsetTest = 0


def scrollerTask():
    global scrollerPos, scrollerEndPos, scrollerStartPos, offsetTest
    display.windowMove("scroller", scrollerPos,
                       display.height() - 22 - offsetTest)
Esempio n. 17
0
    def draw(self, alert, datetime):
        """Draw either the alert if one is given, or the date & time.

        Clear the screen to prevent ghosting:
            - When the date changes.
            - When entering an alert.
            - When leaving an alert.
        """
        if alert:
            if alert == self._old_alert:
                if self._neopixels:
                    self._neopixels_off()
                else:
                    self._neopixels_pink()
                return

            self._old_alert = alert
            self._old_time_str = ''

            # clear the screen to prevent ghosting.
            display.drawFill(BLACK)
            display.flush()

            display.drawFill(WHITE)

            width = display.width()
            y = 0
            words = alert.split(' ')
            chunk = words[0]
            for word in words[1:]:
                joined = chunk + ' ' + word
                if (display.getTextWidth(joined, FONTS['7x5']) * 3) >= width:
                    display.drawText(0, y, chunk, BLACK, FONTS['7x5'], 3, 3)
                    chunk = word

                    text_height = display.getTextHeight(
                        chunk, FONTS['7x5']) * 3
                    line_height = int(text_height * 1.4)
                    y += line_height
                else:
                    chunk = joined
            display.drawText(0, y, chunk, BLACK, FONTS['7x5'], 3, 3)
            display.flush()
        else:
            time_str = self._format_time(datetime)
            date_str = self._format_date(datetime)

            if time_str == self._old_time_str:
                return

            if self._old_alert or date_str != self._old_date_str:
                # we've come out of an alert or the date changed,
                # so clear the screen to prevent ghosting.
                display.drawFill(BLACK)
                display.flush()

            self._old_alert = ''
            self._old_date_str = date_str
            self._old_time_str = time_str
            self._neopixels_off()

            display.drawFill(WHITE)
            display.drawText(0, 0, time_str, BLACK, FONTS['7x5'], 5, 5)

            bottom = display.height() - 2  # the bottom pixel seems to clip.
            date_y = bottom - \
                (display.getTextHeight(date_str, FONTS['7x5']) * 3)
            display.drawText(0, date_y, date_str, BLACK, FONTS['7x5'], 3, 3)
            display.flush()