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)
Example #2
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
def draw_dashed_line(x0, y0, x1, y1, color=0x000000, space=12):
    vx, vy = x1 - x0, y1 - y0
    l2 = sqrt(vx**2 + vy**2)
    vec_x, vec_y = vx / l2 * space, vy / l2 * space

    lx0, ly0 = x0, y0
    while True:
        lx1, ly1 = min(lx0 + vec_x, x1), min(ly0 + vec_y, y1)
        display.drawLine(int(lx0), int(ly0), int(min(lx0 + vec_x / 2, x1)),
                         int(min(ly0 + vec_y / 2, y1)), color)
        if lx1 == x1 and ly1 == y1:
            break
        lx0, ly0 = lx1, ly1
    display.drawPixel(x1, y1, color)
Example #4
0
    def _connect_wifi(self):
        dp.drawPixel(0, 0, 0x0044BB)
        dp.flush()
        if not wifi.status():
            audio.play('/cache/system/wifi_connecting.mp3')
            wifi.connect()

            dp.drawPixel(1, 0, 0x0044BB)
            dp.flush()

            wifi.wait()
            if not wifi.status():
                dp.drawLine(0, 0, 1, 0, 0xFF0000)
                dp.flush()
                audio.play('/cache/system/wifi_failed.mp3',
                           on_finished=system.launcher)
def draw_history_graph_plot(rect, history):
    x, y, w, h = rect

    if len(history) == 0:
        return

    sample_min, sample_max = min(history), max(history)
    sample_scale = 1.0 / max((sample_max - sample_min), 1)
    plot = [
        (x + i + (w - len(history)),
         y + int(h - (sample - sample_min) * sample_scale * h - 1))
        # history[-1] is the most recent sample.
        for i, sample in enumerate(history[max(-w, -len(history)):-1])
    ]
    for (x0, y0), (x1, y1) in zip(plot, plot[1:]):
        display.drawLine(x0, y0, x1, y1, 0x000000)
Example #6
0
def rounded_box(x,y,w,h,r,color):
	display.drawLine(x+r,   y,     x+w-1-r, y,       color)
	display.drawLine(x+r,   y+h-1, x+w-1-r, y+h-1,   color)
	display.drawLine(x,     y+r,   x,       y+h-1-r, color)
	display.drawLine(x+w-1, y+r,   x+w-1,   y+h-1-r, color)
	display.drawCircle(x+r,     y+r,     r, 270, 359, False, color)
	display.drawCircle(x+w-1-r, y+r,     r, 0,   90,  False, color)
	display.drawCircle(x+r,     y+h-1-r, r, 180, 270, False, color)
	display.drawCircle(x+w-1-r, y+h-1-r, r, 90,  180, False, color)
Example #7
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 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
Example #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:
            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
Example #10
0
def line(x0, y0, x1, y1, color):
	display.drawLine(x0, y0, x1, y1, color)
Example #11
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
import display
display.drawText(0, 0, "Hello world", 0xFFFFFF, "7x5")
display.drawLine(0,0,128,64,0xFFFFFF)
display.flush()