コード例 #1
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"))
コード例 #2
0
def start():
	ugfx.input_init()
	ugfx.set_lut(ugfx.LUT_FASTER)
	ugfx.clear(ugfx.WHITE)

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

	global options
	global install_path
	options = None
	install_path = None

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

	populate_apps()
	populate_category()
	populate_options()

	# do a greyscale flush on start
	ugfx.flush(ugfx.GREYSCALE)
コード例 #3
0
def messageCentered(message, firstLineTitle=True, png=None):
    try:
        display.drawFill(0xFFFFFF)
        color = 0x000000
        font1 = "Roboto_Regular18"
        font2 = "Roboto_Regular12"
        font1Height = display.getTextHeight(" ", font1)
        font2Height = display.getTextHeight(" ", font2)

        message = message.split("\n")
        lines = []
        for i in range(len(message)):
            line = message[i]
            if len(line) < 1:
                lines.append("")
            else:
                if firstLineTitle and i == 0:
                    lines.extend(lineSplit(line, display.width(), font1))
                else:
                    lines.extend(lineSplit(line, display.width(), font2))

        pngSize = (0, 0)
        if png != None:
            try:
                pngSize = display.pngInfo(png)
                pngSize = [pngSize[0],
                           pngSize[1] + 2]  #Little bit of extra offset
            except BaseException as e:
                #print("Error in PNG height",e)
                pass

        textHeight = len(lines) * font2Height

        if firstLineTitle:
            textHeight -= font2Height
            textHeight += font1Height

        offset_y = (display.height() - pngSize[1] - textHeight) // 2

        if png != None:
            try:
                display.drawPng((display.width() - pngSize[0]) // 2, offset_y,
                                png)
                offset_y += pngSize[1]
            except BaseException as e:
                print("Error in PNG draw", e)

        for i in range(len(lines)):
            if firstLineTitle and i == 0:
                lineCentered(offset_y, lines[i], font1, color)
                offset_y += font1Height
            else:
                lineCentered(offset_y, lines[i], font2, color)
                offset_y += font2Height

        display.flush(display.FLAG_LUT_FASTEST)
    except BaseException as e:
        print("Error in messageCentered!", e)
コード例 #4
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
コード例 #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)
コード例 #6
0
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(display.FLAG_LUT_FASTEST)
コード例 #7
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
コード例 #8
0
def msg_nosplit(message, title='Loading...', reset=False):
    """Show a terminal style loading screen with title

	title can be optionaly set when resetting or first call
	"""
    global messageHistory, lastTitle

    num_lines = ((display.height() - 16) //
                 display.getTextHeight(" ", version.font_default)) - 2

    if reset:
        lastTitle = title

    try:
        messageHistory
        if reset:
            raise exception
    except:
        display.drawFill(0xFFFFFF)
        messageHistory = []
        lastTitle = title

    lineHeight = int(display.getTextHeight(" ", version.font_default) / 2) + 5

    if len(messageHistory) < num_lines:
        display.drawText(0, 16 + (len(messageHistory) * lineHeight), message,
                         0x000000, version.font_default)
        messageHistory.append(message)
    else:
        messageHistory.pop(0)
        messageHistory.append(message)
        display.drawRect(0, 16, display.width(),
                         display.height() - 15, True, 0xFFFFFF)
        for i, message in enumerate(messageHistory):
            display.drawText(0, 16 + (i * lineHeight), message, 0x000000,
                             version.font_default)

    display.drawRect(0, 0, display.width(), 14, True, 0)
    display.drawText(0, 0, lastTitle, 0xFFFFFF, "Roboto_Regular12")
    #h = display.getTextHeight(" ", version.font_header)
    #display.drawLine(0, h, display.width(), h, 0x000000)

    display.flush(display.FLAG_LUT_FASTEST)

    return len(messageHistory) >= num_lines - 1
コード例 #9
0
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)
コード例 #10
0
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")
コード例 #11
0
def showLoadingScreen(app=""):
	hourglass = b"\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x005\x00\x00\x00Z\x01\x00\x00\x00\x000?#R\x00\x00\x00jIDAT(\xcf\xad\xd2A\x12\x80 \x08\x05Po\xc0\x95\xbd\xc1\xbf.\xbb\x1f\x91\x8d5\x90:\x15.\xde\x02\xc6\x01\xb4\x94Y\xd0B\x07NB\xbdN\x7f\x10@\xea\x99W\xcdmy!XS\xb9\xcbje2P\x05\x95\xa9t\xed\x12\xf9$\xec\\\xee\x0bZ\x1f\xf4~\xd0\xfa\xba\x0b\x9b\x03}\x9e`\xdf'\x1e\\\xdb\xe3\xea{\x1c\x11m\xf9\xd7\xffm\xfc\xef6\x03^\xc2\x1c\x0eD=\xf5\x00\x00\x00\x00IEND\xaeB`\x82"
	try:
		display.drawFill(0xFFFFFF)
		text = "Loading...\n\n{}".format(app)
		display.drawText(91, (display.height()-display.getTextHeight(text, "ocra16"))//2, text, 0x000000, "ocra16")
		display.drawPng(19,19,hourglass)
		display.flush(display.FLAG_LUT_FASTEST)
	except:
		pass
コード例 #12
0
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')
コード例 #13
0
def msg_nosplit(message, title='Loading...', reset=False):
    """Show a terminal style loading screen with title

	title can be optionaly set when resetting or first call
	"""
    global messageHistory, lastTitle

    num_lines = ((display.height() - 11) // display.getTextHeight(" ", "7x5"))

    if reset:
        lastTitle = title

    try:
        messageHistory
        if reset:
            raise exception
    except:
        display.drawFill(0x000000)
        messageHistory = []
        lastTitle = title

    lineHeight = display.getTextHeight(" ", "7x5")

    if len(messageHistory) < num_lines:
        display.drawText(0, 11 + (len(messageHistory) * lineHeight), message,
                         0xFFFFFF, "7x5")
        messageHistory.append(message)
    else:
        messageHistory.pop(0)
        messageHistory.append(message)
        display.drawRect(0, 11, display.width(),
                         display.height() - 15, True, 0x000000)
        for i, message in enumerate(messageHistory):
            display.drawText(0, 11 + (i * lineHeight), message, 0xFFFFFF,
                             "7x5")

    display.drawRect(0, 0, display.width(), 10, True, 0xFFFFFF)
    display.drawText(2, 0, lastTitle, 0x000000, "org18")

    display.flush(display.FLAG_LUT_FASTEST)

    return len(messageHistory) >= num_lines - 1
コード例 #14
0
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)
コード例 #15
0
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")
コード例 #16
0
	def __init__(self, x, y, w, h):
		self.x = x
		self.y = y
		self.w = w
		self.h = h
		self.items = []
		self.selected = 0
		global activeList
		activeList = self
		self.lines = self.h // (display.getTextHeight(" ", "roboto_regular12")+6)
		self.offset = 0
		self.visible(True)
		self.enabled(True)
コード例 #17
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
コード例 #18
0
def msg(message, title = "Loading...", reset = False, wait = 0):
	num_lines = ((display.height() - 16)//display.getTextHeight(" ", version.font_default)) - 2
	scroll = False
	try:
		lines = lineSplit(str(message))
		for i in range(len(lines)):
			if i > 0:
				scroll = msg_nosplit(lines[i])
			else:
				scroll = msg_nosplit(lines[i], title, reset)
			if (i > 1) and (wait > 0):
				time.sleep(wait)
	except BaseException as e:
		print("!!! Exception in easydraw.msg !!!")
		print(e)
	return scroll
コード例 #19
0
def draw_history_graph(rect, history, x_axis_labels):
    x, y, w, h = rect
    clear_rect(rect)

    txt_h = display.getTextHeight('-') + 2
    x_label_h = txt_h

    sample_min, sample_max = min(history), max(history)
    display.drawText(x, y, '%dppm' % sample_max, 0x000000)
    display.drawText(x, y - txt_h + h - x_label_h, '%dppm' % sample_min,
                     0x000000)
    draw_dashed_line(x, y, x + w - 1, y, 0x000000)
    draw_dashed_line(x, y + h - 1 - x_label_h, x + w - 1,
                     y + h - 1 - x_label_h, 0x000000)

    for sample_offset, label in x_axis_labels.items():
        lx = x + w - sample_offset
        if lx > display.size()[0]:
            continue
        draw_dashed_line(lx, y, lx, y + h - 1 - x_label_h, 0x000000)
        display.drawText(lx, y + h - txt_h, label)

    draw_history_graph_plot((x, y, w, h - x_label_h), history)
コード例 #20
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
コード例 #21
0
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
コード例 #22
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...'
            owner = machine.nvs_getstr("owner", "name")
            fontlist = [
                "permanentmarker22", "Roboto_Regular18", "Roboto_Regular12"
            ]
            if (owner):
                display.drawFill(COLOR_BG)
                for font in fontlist:
                    if font == fontlist[-1]:
                        display.drawText(0, 0, owner, COLOR_FG, font)
                    elif display.getTextWidth(owner, font) <= display.width():
                        display.drawText(
                            (display.width() -
                             display.getTextWidth(owner, font)) // 2, 0, owner,
                            COLOR_FG, font)
                        break
        #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
コード例 #23
0
def get_string_height(text, font=None):
	if font:
		return display.getTextHeight(text, font)
	else:
		return display.getTextHeight(text)
コード例 #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
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:
コード例 #26
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)
コード例 #27
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
コード例 #28
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()