def lineCentered(pos_y, line, font, color):
    if font:
        width = display.getTextWidth(line, font)
    else:
        width = display.getTextWidth(line)
    pos_x = int((display.width() - width) / 2)
    if font:
        display.drawText(pos_x, pos_y, line, color, font)
    else:
        display.drawText(pos_x, pos_y, line, color)
def drawApp(app, position, amount):
    global extended_menu, appList
    oneFourthWidth = display.width() // 4
    display.drawFill(0x000000)
    display.drawRect(0, 0,
                     display.width() // (2 if extended_menu else 1), 10, True,
                     0xFFFFFF)
    display.drawText(2, 0, "LAUNCHER", 0x000000, "org18")
    positionText = "{}/{}".format(position + 1, amount)
    if app["path"].startswith("/sd"):
        positionText = "SD " + positionText
    positionWidth = display.getTextWidth(positionText, "org18")
    display.drawText(
        display.width() // (2 if extended_menu else 1) - positionWidth - 2, 0,
        positionText, 0x000000, "org18")
    titleWidth = display.getTextWidth(app["name"], "7x5")
    display.drawText(
        (oneFourthWidth * (3 if extended_menu else 2) - titleWidth // 2),
        display.height() - 10, app["name"], 0xFFFFFF, "7x5")
    try:
        icon_data = None
        if app["icon"]:
            if not app["icon"].startswith(b"\x89PNG"):
                with open(app["path"] + "/" + app["icon"], "rb") as icon_file:
                    icon_data = icon_file.read()
            else:
                icon_data = app["icon"]
        if not icon_data:
            display.drawPng(oneFourthWidth * (3 if extended_menu else 2) - 16,
                            display.height() // 2 - 16, default_icon)
        else:
            info = display.pngInfo(icon_data)
            if info[0] == 32 and info[1] == 32:
                display.drawPng(
                    oneFourthWidth * (3 if extended_menu else 2) - 16,
                    display.height() // 2 - 16, icon_data)
            else:
                drawMessageBox("Invalid icon size\nExpected 32x32!")
    except BaseException as e:
        sys.print_exception(e)
        drawMessageBox("Icon parsing error!")

    if not extended_menu:
        if not position < 1:
            display.drawText(0,
                             display.height() // 2 - 12, "<", 0xFFFFFF,
                             "roboto_regular18")
        if not position >= (amount - 1):
            display.drawText(display.width() - 10,
                             display.height() // 2 - 12, ">", 0xFFFFFF,
                             "roboto_regular18")

    if appList:
        appList.draw()
    display.flush(display.FLAG_LUT_FASTEST)
示例#3
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
				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
示例#4
0
    def _draw(self):
        if self._visible:
            display.drawRect(self.x, self.y, self.w, self.h, True, 0x000000)
            display.drawRect(self.x, self.y, self.w, self.h, False, 0xFFFFFF)
            cursor = (self.x + 1, self.y + 1)
            totalHeight = 0
            for i in range(len(self.items) - self.offset):
                cursor = (self.x + 1, cursor[1])
                item = self.items[self.offset + i]
                lineHeight = display.getTextHeight(item, "roboto_regular12")

                while display.getTextWidth(item, "roboto_regular12") > self.w:
                    item = item[:-1]

                totalHeight += lineHeight + 6
                if totalHeight >= self.h:
                    break
                color = 0xFFFFFF
                if self.offset + i == self.selected:
                    display.drawRect(self.x, cursor[1], self.w, lineHeight + 6,
                                     True, 0xFFFFFF)
                    color = 0x000000
                cursor = (self.x, cursor[1] + 3)
                display.drawText(cursor[0] + 2, cursor[1], item + "\n", color,
                                 "roboto_regular12")
                cursor = (
                    self.x, cursor[1] + 3 +
                    display.getTextHeight(item + "\n", "roboto_regular12"))
示例#5
0
def string_box(x,
               y,
               w,
               h,
               text,
               font,
               color,
               align,
               testMode=False,
               newHeight=0):
    lines = wordWrap(text, w, font).split("\n")
    if len(lines) < 1:
        return

    for i in range(len(lines)):
        textWidth = display.getTextWidth(lines[i], font)
        textHeight = display.getTextHeight(lines[0], font)
        text_x = x + w // 2 - textWidth // 2
        text_y = y + h // 2 - textHeight // 2 + textHeight * i - (
            textHeight * (len(lines) - 1)) // 2
        if testMode:
            print("Components", y, h // 2, textHeight // 2, textHeight * i,
                  (textHeight * (len(lines) - 1)) // 2)
            print("Line", i, lines[i], text_x, text_y)
        display.drawText(text_x, text_y, lines[i], color, font)
        if testMode:
            display.drawRect(text_x, text_y, textWidth, textHeight, 0, 0)
            display.drawRect(text_x, text_y, textWidth, newHeight, 0, 0)
def drawNickname():
    owner = machine.nvs_getstr("owner", "name") or "BADGE.TEAM"
    display.drawFill(0xFFFF00)
    x = (display.width()-display.getTextWidth(owner, "ocra16"))//2
    y = (display.height()-display.getTextHeight(owner, "ocra16"))//2
    display.drawText(x,y,owner,0x000000,"ocra16")
    display.flush() # Send the new buffer to the display
    display.backlight(0xFF) # Turn on backlight
def draw_climate_labels(rect, temperature, pressure, humidity):
    x, y, w, h = rect
    clear_rect(rect)

    label = '{:.2f}C  {:.2f}%'.format(temperature, humidity)
    label_w = display.getTextWidth(label)
    label_h = display.getTextHeight(label)
    display.drawText(x + w // 2 - label_w // 2, y + h // 2 - label_h // 2,
                     label, 0x000000)
def drawMessageBox(text):
    width = display.getTextWidth(text, "org18")
    height = display.getTextHeight(text, "org18")
    display.drawRect((display.width() - width - 4) // 2,
                     (display.height() - height - 4) // 2, width + 2,
                     height + 2, True, 0xFFFFFF)
    display.drawText((display.width() - width) // 2,
                     (display.height() - height) // 2 - 2, text, 0x000000,
                     "org18")
def drawApp(app, position, amount):
	display.drawFill(0x000000)
	display.drawRect(0,0,display.width(), 10, True, 0xFFFFFF)
	display.drawText(2, 0, "RECOVERY", 0x000000, "org18")
	positionText = "{}/{}".format(position+1, amount)
	if app["path"].startswith("/sd"):
		positionText  = "SD "+positionText
	positionWidth = display.getTextWidth(positionText, "org18")
	display.drawText(display.width()-positionWidth-2, 0, positionText, 0x000000, "org18")
	titleWidth = display.getTextWidth(app["name"], "7x5")
	titleHeight = display.getTextHeight(app["name"], "7x5")
	display.drawText((display.width()-titleWidth)//2,(display.height()-titleHeight)//2, app["name"], 0xFFFFFF, "7x5")

	if not position < 1:
		display.drawText(0, display.height()//2-12, "<", 0xFFFFFF, "roboto_regular18")	
	if not position >= (amount-1):
		display.drawText(display.width()-10, display.height()//2-12, ">", 0xFFFFFF, "roboto_regular18")
	
	display.flush()
def draw_co2_label(rect, co2):
    x, y, w, h = rect
    clear_rect(rect)

    co2_label = 'CO2: %d' % co2
    co2_label_w = display.getTextWidth(co2_label, 'permanentmarker22')
    co2_label_h = display.getTextHeight(co2_label, 'permanentmarker22')
    display.drawText(x + w // 2 - co2_label_w // 2,
                     y + h // 2 - co2_label_h // 2, co2_label, 0x000000,
                     'permanentmarker22')
def draw_message_label(pos, label):
    if not label:
        return
    center_x, center_y = pos
    padding = 4
    label_w, label_h = display.getTextWidth(
        label), display.getTextHeight(label) + 4
    area_x, area_y = center_x - label_w // 2 - padding, center_y - label_h // 2 - padding
    display.drawRect(area_x, area_y, label_w + padding * 2,
                     label_h + padding * 2, True, 0)
    display.drawText(area_x + padding, area_y + padding, label, 0xffffff)
def drawMessageBox(text):
    global extended_menu
    oneFourthWidth = display.width() // 4
    width = display.getTextWidth(text, "org18")
    height = display.getTextHeight(text, "org18")
    display.drawRect(
        (oneFourthWidth * (3 if extended_menu else 2) - width - 4) // 2,
        (display.height() - height - 4) // 2, width + 2, height + 2, True,
        0xFFFFFF)
    display.drawText(
        (oneFourthWidth * (3 if extended_menu else 2) - width) // 2,
        (display.height() - height) // 2 - 2, text, 0x000000, "org18")
示例#13
0
def scrollerThread():
	scrollerStartPos = 129
	scrollerEndPos = -display.getTextWidth(cfg_nick_text, "permanentmarker22") - 128
	scrollerPos = scrollerStartPos
	global stopThreads
	while not stopThreads:
		display.windowMove("scroller", scrollerPos, display.height()-22) 
		scrollerPos-=4
		if scrollerPos < scrollerEndPos:
			scrollerPos = scrollerStartPos
		display.flush()
		time.sleep_ms(40)
示例#14
0
def nickname(y = 5, font = "Roboto_Regular18", color = 0x000000, unusedParameter=None):
	nick = machine.nvs_getstr("owner", "name")
	if not nick:
		return y
	lines = lineSplit(nick, display.width(), font)
	for i in range(len(lines)):
		line = lines[len(lines)-i-1]
		pos_x = int((display.width()-display.getTextWidth(line, font)) / 2)
		lineHeight = display.getTextHeight(line, font)
		if font:
			display.drawText(pos_x, y+lineHeight*(len(lines)-i-1), line, color, font)
		else:
			display.drawText(pos_x, y+lineHeight*(len(lines)-i-1), line, color)
	return len(lines) * lineHeight
示例#15
0
def drawApp(app, position, amount):
	display.drawFill(0x000000)
	display.drawRect(0,0,display.width(), 10, True, 0xFFFFFF)
	display.drawText(2, 0, "UNINSTALL", 0x000000, "org18")
	positionText = "{}/{}".format(position+1, amount)
	if app["path"].startswith("/sd"):
		positionText  = "SD "+positionText
	positionWidth = display.getTextWidth(positionText, "org18")
	display.drawText(display.width()-positionWidth-2, 0, positionText, 0x000000, "org18")
	titleWidth = display.getTextWidth(app["name"], "7x5")
	display.drawText((display.width()-titleWidth)//2,display.height()-10, app["name"], 0xFFFFFF, "7x5")
	try:
		icon_data = None
		if app["icon"]:
			if not app["icon"].startswith(b"\x89PNG"):
				with open(app["path"]+"/"+app["icon"], "rb") as icon_file:
					icon_data = icon_file.read()
			else:
				icon_data = app["icon"]
		if not icon_data:
			display.drawPng(48,15,default_icon)
		else:
			info = display.pngInfo(icon_data)
			if info[0] == 32 and info[1] == 32:
				display.drawPng(48,15,icon_data)
			else:
				drawMessageBox("Invalid icon size\nExpected 32x32!")
	except BaseException as e:
		sys.print_exception(e)
		drawMessageBox("Icon parsing error!")
	
	if not position < 1:
		display.drawText(0, display.height()//2-12, "<", 0xFFFFFF, "roboto_regular18")	
	if not position >= (amount-1):
		display.drawText(display.width()-10, display.height()//2-12, ">", 0xFFFFFF, "roboto_regular18")
	
	display.flush()
示例#16
0
import display as _display
import buttons as _buttons

_MODE = 0
_XPOS = 0
_LASTPARTMOVEUP = False
_VISIBLELINE = 0
_FONT_KEY = "roboto_regular12"
_FONT_TEXT = "roboto_regular12"
_CHAR_HEIGHT = _display.getTextHeight("X", _FONT_KEY)
_CHAR_WIDTH = _display.getTextWidth("X", _FONT_KEY)

_CHAR_MAP = [
    "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o",
    "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", " ", "A", "B", "C",
    "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R",
    "S", "T", "U", "V", "W", "X", "Y", "Z", " ", "0", "1", "2", "3", "4", "5",
    "6", "7", "8", "9", " ", "@", "#", "$", "%", "^", "&", "*", "(", ")", ".",
    ",", "=", "+", "-", "_", "[", "]", "?", "\\", "/", "~", "{", "}", "`", "<",
    ">", ":", ";"
]


def _calcPos():
    global _TEXT, _CURSOR_X, _CURSOR_Y
    parts = _TEXT.split("\n")
    pos = 0
    for i in range(_CURSOR_Y):
        pos += len(parts[i]) + 1
    pos += _CURSOR_X
    if len(parts[_CURSOR_Y]) < 1:
示例#17
0
#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)
    scrollerPos -= 3
    if scrollerPos < scrollerEndPos:
        scrollerPos = scrollerStartPos
    display.flush()
    return 25
示例#18
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
示例#19
0
def _centeredText(text, y, color, font):
	display.drawText((display.width()-display.getTextWidth(text, font))//2, y, text, color, font)
示例#20
0
def disp_string_right_bottom(y, s, font="Roboto_Regular12"):
    l = display.getTextWidth(s, font)
    display.drawText(display.width() - l,
                     display.height() - (y + 1) * 14, s, 0x000000, font)
示例#21
0
# https://docs.badge.team/esp32-app-development/api-reference/display/

print('Test: Display')

import display
display.flush()

display.drawFill(0x000000)
display.drawText(10, 10, "LaserTag 2 :D", 0xFFFF00, "permanentmarker22")
display.flush()

display.drawCircle(60, 60, 50, 0, 360, True, 0xFFFFFF)
display.drawCircle(60, 60, 40, 0, 360, True, 0x000000)
display.drawCircle(60, 60, 30, 0, 360, True, 0xFFFFFF)
display.drawCircle(60, 60, 20, 0, 360, True, 0x000000)
display.drawCircle(60, 60, 10, 0, 360, True, 0xFFFFFF)

display.drawLine(1, 1, 100, 100, 0xFFFFFF)
display.drawRect(30, 30, 50, 50, True, 0xFFFFFF)

display.drawText(150, 25, "STILL", 0xFFFFFF, "Roboto_BlackItalic24")
display.drawText(130, 50, "Hacking", 0xFFFFFF, "PermanentMarker22")
l = display.getTextWidth("Hacking", "PermanentMarker22")
display.drawLine(130, 72, 144 + l, 72, 0xFFFFFF)
display.drawLine(140 + l, 52, 140 + l, 70, 0xFFFFFF)
display.drawText(140, 75, "Anyway", 0xFFFFFF, "Roboto_BlackItalic24")

display.flush()

print('done')
def prompt_boolean(text,
                   title="Notice",
                   true_text="Yes",
                   false_text="No",
                   width=None,
                   height=None,
                   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, __cb

    __cb = cb

    if width == None:
        width = display.width()
    if height == None:
        height = display.height()

    x = (display.width() - width) // 2
    y = (display.height() - height) // 2
    if (x < 0):
        x = 0
    if (y < 0):
        y = 0

    display.drawFill(0xFFFFFF)
    display.drawRect(0, 0, display.width(), 14, True, 0)
    display.drawText(0, 0, title, 0xFFFFFF, "Roboto_Regular12")

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

    display.drawText(0, 36, ugfx.wordWrap(text, None, font), 0x000000, font)

    if false_text:
        _button(10, height - display.getTextHeight(false_text, font),
                false_text, 0x000000, font)
        _button((width - display.getTextWidth(true_text, font) - 10),
                height - display.getTextHeight(true_text, font), true_text,
                0x000000, font)
    else:
        _button(width - 10 - display.getTextWidth(true_text, font),
                height - display.getTextHeight(true_text, font), true_text,
                0x000000, font)

    display.flush()

    if cb:
        ugfx.input_attach(ugfx.BTN_A, __asyncSuccess)
        ugfx.input_attach(ugfx.BTN_B, __asyncCancel)
        #Done :-)
    else:
        ugfx.input_attach(buttons.BTN_A, None)
        ugfx.input_attach(buttons.BTN_B, None)

        while True:
            if buttons.value(buttons.BTN_A):
                display.drawFill(0xFFFFFF)
                display.flush()
                while buttons.value(buttons.BTN_A) or buttons.value(
                        buttons.BTN_B):
                    time.sleep(0.1)
                return True
            if buttons.value(buttons.BTN_B):
                display.drawFill(0xFFFFFF)
                display.flush()
                while buttons.value(buttons.BTN_A) or buttons.value(
                        buttons.BTN_B):
                    time.sleep(0.1)
                return False
示例#23
0
                          departureTime[x])

                name = jsonData['Departure'][x]['name']
                name = name[:2]
                if name == "RB":  #Checks if this is a replacement bus for an RB train
                    departureLine[x] = "RB"
                else:
                    departureLine[x] = jsonData['Departure'][x]['Product'][
                        'line']

                departureDir[x] = jsonData['Departure'][x]['direction']
                #print ('"direction":', departureDir)
                #print ('"line":', departureLine)

                #departureDir[x] = departureDir[x][:12] #max number of char. that can display
                while display.getTextWidth(departureDir[x],
                                           "Roboto_Black22") >= (128 + 22):
                    departureDir[x] = departureDir[x][:-1]
                    #print("Len of dir.: ",display.getTextWidth(departureDir[x],"Roboto_Black22"))
                    #print("Direction:",departureDir[x])

                print('"direction":', departureDir[x])
                print('"line":', departureLine[x])
                print("////////////////////// ", x, " //////////////////////")

            ##################################### Update display? ###############################################
            print(
                "Checking if new data available compared to what is on the display now"
            )
            updateDisplay = False
            for x in range(0, numOfDepartures):
                #check if new data is different currently displayed data
示例#24
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:
            if cfg_logo and cfg_nickname:
                currHeight += 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 logoHeight < 1 and cfg_logo:
                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,
                    0x000000, "permanentmarker22")
                currHeight += display.getTextHeight(title, "permanentmarker22")
                display.drawText(
                    (display.width() -
                     display.getTextWidth(subtitle, "fairlight12")) // 2,
                    currHeight + (app_height - logoHeight) // 2, subtitle,
                    0x000000, "fairlight12")
                currHeight += display.getTextHeight(subtitle, "fairlight12")
            if (not cfg_logo) and cfg_nickname:
                noLine = True
                nick = machine.nvs_getstr("owner", "name")
                if nick == None:
                    nick = "BADGE.TEAM"
                currHeight += (
                    display.getTextHeight(nick, "permanentmarker22") // 2) - 8
                display.drawText(
                    (display.width() -
                     display.getTextWidth(nick, "permanentmarker22")) // 2,
                    currHeight, nick, 0x000000, "permanentmarker22")
                currHeight += display.getTextHeight(nick, "permanentmarker22")
        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, 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
示例#25
0
def get_string_width(text, font=None):
	if font:
		return display.getTextWidth(text, font)
	else:
		return display.getTextWidth(text)
def start():
    ugfx.input_init()
    ugfx.set_lut(ugfx.LUT_FASTER)
    ugfx.clear(ugfx.WHITE)

    # Instructions
    if orientation.isLandscape():
        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_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_start)

    populate_apps()
    populate_category()
    populate_options()

    # do a greyscale flush on start
    ugfx.flush(ugfx.GREYSCALE)
示例#27
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)
示例#28
0
import display, buttons

shift = 0  # 0 = lower, 1 = upper, 2 = caps, 3 = numbers, 4 = symbols
mode = 0  # 0 = keyboard, 1 = select, 2 = buttons

keyFont = "roboto_regular12"
textFont = "roboto_regular18"
yOffset = display.height() - 20 * 3
charWidth = display.getTextWidth("X", keyFont)
charHeight = display.getTextHeight("X", keyFont)
charOffsetX = int((20 - charWidth))
charOffsetXDouble = int((20 - charWidth * 1.5))
charOffsetY = 5

charMap = []
charMap.append(["q", "w", "e", "r", "t", "y", "u", "i", "o", "p"])
charMap.append([" ", "a", "s", "d", "f", "g", "h", "j", "k", "l"])
charMap.append(["SHIFT", " ", "z", "x", "c", "v", "b", "n", "m", "<<"])
# Uppercase
charMap.append(["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"])
charMap.append([" ", "A", "S", "D", "F", "G", "H", "J", "K", "L"])
charMap.append(["CAPS", " ", "Z", "X", "C", "V", "B", "N", "M", "<<"])
# Caps-lock
charMap.append(["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"])
charMap.append([" ", "A", "S", "D", "F", "G", "H", "J", "K", "L"])
charMap.append(["1 2 3", " ", "Z", "X", "C", "V", "B", "N", "M", "<<"])
# Numbers
charMap.append(["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"])
charMap.append([" ", "@", "#", "$", "%", "^", "&", "*", "(", ")"])
charMap.append(["!@#$", " ", ".", ",", "=", "+", "[", "]", "?", "<<"])
# Numbers 2
示例#29
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()