예제 #1
0
    def __init__(self, config):

        # Get the config
        self.__debug = config.get('debug')

        # Configure the style and layout
        ugfx.set_default_font(ugfx.FONT_MEDIUM)
        ugfx.set_default_style(dialogs.default_style_badge)
        self.__sty_tb = ugfx.Style(dialogs.default_style_badge)
        self.__sty_tb.set_enabled([
            ugfx.WHITE,
            ugfx.html_color(0xA66FB0),
            ugfx.html_color(0x5e5e5e), ugfx.RED
        ])
        self.__sty_tb.set_background(ugfx.GREY)
        self.__win_bv = ugfx.Container(0, 0, 80, 25, style=self.__sty_tb)
        self.__win_wifi = ugfx.Container(82, 0, 60, 25, style=self.__sty_tb)
        self.__win_clock = ugfx.Container(250, 0, 70, 25, style=self.__sty_tb)
        self.__win_wifi.show()
        self.__win_bv.show()
        self.__win_clock.show()

        # Init var for last RSSI
        self.__last_rssi = 0

        # Schedule next status update
        self.__next_status_update = pyb.millis() + 500
예제 #2
0
파일: main.py 프로젝트: tswsl1989/Mk4-Apps
def loading_screen():
    logo = 'praise_horse_worship_melon/loading.gif'
    ugfx.area(0,0,ugfx.width(),ugfx.height(),0xFFFF)
    ugfx.display_image(2,2,logo)
    ugfx.set_default_font(ugfx.FONT_SMALL)
    ugfx.text(60, 145, "Praise Horse (A)", ugfx.GREY)
    ugfx.text(55, 305, "Worship Melon (B)", ugfx.GREY)
예제 #3
0
def loading_screen():
    logo = 'lobstervision/lobsterpictures.gif'
    ugfx.area(0, 0, ugfx.width(), ugfx.height(), 0xFFFF)
    ugfx.display_image(0, 50, logo)
    ugfx.set_default_font(ugfx.FONT_SMALL)
    ugfx.text(15, 305, "lobstervision.tv/emf2018", ugfx.GREY)
    display_loading()
예제 #4
0
def display_datetime():
    ugfx.area(0, 215, 320, 25, 0xFFFF)
    ugfx.set_default_font(ugfx.FONT_MEDIUM_BOLD)
    (date, day) = format_selected_date()
    time = format_selected_time()
    ugfx.text(5, 220, time, ugfx.RED)
    ugfx.text(60, 220, "%s, %s" % (day, date), ugfx.GREY)
예제 #5
0
파일: main.py 프로젝트: tswsl1989/Mk4-Apps
def one_round():
    ball = Ball()
    topPaddle = Paddle(0)
    bottomPaddle = Paddle(1)

    ugfx.clear(bgColor)
    ugfx.backlight(100)

    ugfx.set_default_font(ugfx.FONT_TITLE)

    while True:
        topPaddle.update()
        bottomPaddle.update()
        ball.update(topPaddle, bottomPaddle)

        if ball.isDead():
            if(ball.y > SCREEN_HEIGHT/2):
                return [1,0]
            else:
                return [0,1]

        topPaddle.draw()
        bottomPaddle.draw()
        ball.draw()

        #draw the net
        for i in range(0,7):
            ugfx.area(int(i*2*SCREEN_WIDTH/13), int(SCREEN_HEIGHT/2-1), int(SCREEN_WIDTH/13), 3, netColor)

        ugfx.orientation(0)
        ugfx.text(130, 0, "%d " % (points[0]),netColor)
        ugfx.text(170, 0, "%d " % (points[1]),netColor)
        ugfx.orientation(270)

        time.sleep_ms(1)
예제 #6
0
def run_app(path):
	import buttons
	buttons.init()
	if not buttons.has_interrupt("BTN_MENU"):
		buttons.enable_menu_reset()
	try:
		mod = __import__(path)
		if "main" in dir(mod):
			mod.main()
	except Exception as e:
		import sys
		import uio
		import ugfx
		s = uio.StringIO()
		sys.print_exception(e, s)
		ugfx.clear()
		ugfx.set_default_font(ugfx.FONT_SMALL)
		w=ugfx.Container(0,0,ugfx.width(),ugfx.height())
		ugfx.Label(0,0,ugfx.width(),ugfx.height(),s.getvalue(),parent=w)
		w.show()
		raise(e)
	import stm
	stm.mem8[0x40002850] = 0x9C
	import pyb
	pyb.hard_reset()
예제 #7
0
def display_person(person):
    top_left_logo()

    # try:
    #     resp = http.get("https://twitter.com/"+person['contact'].lstrip("@")+"/profile_image?size=mini").raise_for_status()
    #     url2 = ure.search('href=\"([^\"]+)',resp.content).group(1).decode('ascii')
    #     print(url2)
    #     img = http.get(url2).raise_for_status().content
    #     print(img)
    #     ugfx.display_image(180, 5, bytearray(img))
    # except Exception as ex:
    #     print(ex)

    ugfx.set_default_font(ugfx.FONT_TITLE)
    ugfx.Label(5, 90, 230, 40, person["username"], justification=ugfx.Label.LEFTTOP)
    ugfx.set_default_font(ugfx.FONT_SMALL)
    ugfx.text(200, 92, person["age"], ugfx.WHITE)

    ugfx.Label(5, 120, 230, 60, person["tag_line"])

    ugfx.Label(5, 200, 230, 40, person["looking_for"])
    ugfx.text(5, 190, "Looking for...", ugfx.RED)

    ugfx.text(5, 245, person["contact"], ugfx.BLUE)

    # ugfx.Button(0, 280, 100, 40, "< Edit profile", parent=None, shape=ugfx.Button.RECT, style=None)
    ugfx.Button(160, 280, 100, 40, "Swipe >", parent=None, shape=ugfx.Button.RECT, style=None)
예제 #8
0
    def __init__(self):
        self.window = None
        self.widgets = []

        ugfx.input_init()
        ugfx.set_default_font(self.default_font)
        ugfx.input_attach(ugfx.BTN_B, self.reload)
예제 #9
0
파일: main.py 프로젝트: trandi/Mk4-Apps
    def setup_screen(self):
        """ Set up the screen and the labels that display
            values on it. 
        """
        ugfx.init()
        width=ugfx.width()
        height=ugfx.height()
        ugfx.clear(ugfx.html_color(0x800080))
        style = ugfx.Style()
        style.set_enabled([ugfx.WHITE, ugfx.html_color(0x800080), ugfx.html_color(0x800080), ugfx.html_color(0x800080)])
        style.set_background(ugfx.html_color(0x800080))
        ugfx.set_default_style(style)
        ugfx.orientation(90)
        ugfx.set_default_font(ugfx.FONT_TITLE)
        ugfx.Label(0, 0, width, 60,"Air Quality", justification=ugfx.Label.CENTER)
        label_height=45
        self.ppm10_label = ugfx.Label(0, label_height, width, label_height,"PPM 10: starting", justification=ugfx.Label.CENTER)
        self.ppm25_label = ugfx.Label(0, label_height*2, width, label_height,"PPM 2.5: starting", justification=ugfx.Label.CENTER)

        self.temp_label = ugfx.Label(0, label_height*3, width, label_height,"Temp: starting", justification=ugfx.Label.CENTER)
        self.humid_label = ugfx.Label(0, label_height*4, width, label_height,"Humid: starting", justification=ugfx.Label.CENTER)
        self.error_label = ugfx.Label(0, label_height*5, width, label_height,"", justification=ugfx.Label.CENTER)
        self.message_label = ugfx.Label(0, label_height*6, width, label_height,"", justification=ugfx.Label.CENTER)
        self.error_count = 0
        self.error_message = ""
        self.neopix = Neopix()
        self.p10_decode = ((100,0x00ff00),(250,0xffff00),(350,0xff8000),(430,0xff0000),(-1,0xcc6600))
        self.p25_decode = ((60, 0x00ff00),(91, 0xffff00), (121,0xff8000),(251,0xff0000),(-1,0xcc6600))
예제 #10
0
파일: main.py 프로젝트: Kimbsy/EMF_20016
def viewmsg():
	msgid = db.get('msgseq')
	msg = inbox.get(msgid)
	if msg == None:
		ugfx.set_default_font(ugfx.FONT_SMALL)	
		ugfx.area(0,0,ugfx.width(),ugfx.height(),0x0000)
		ugfx.text(40,100,"NO MESSAGES",ugfx.BLUE)
		pyb.delay(1000)
		return
	else:
		data = json.loads(msg)
		printmsg(data['sender'], data['payload'], data['ts'])
	while True:
		if buttons.is_triggered("JOY_UP"):
			print(msgid)
			msgid -= 1
			msg = inbox.get(msgid)
			if msg != None:
				data = json.loads(msg)
				printmsg(data['sender'], data['payload'], data['ts'])
			else:
				msgid += 1
		if buttons.is_triggered("JOY_DOWN"):
			print(msgid)
			msgid += 1
			msg = inbox.get(msgid)
			if msg != None:
				data = json.loads(msg)
				printmsg(data['sender'], data['payload'], data['ts'])
			else:
				msgid -= 1
		if buttons.is_triggered("BTN_B"):
			display()
			return
예제 #11
0
def game_over(reason):
	ugfx.clear(ugfx.BLACK)
	ugfx.set_default_font(ugfx.FONT_TITLE)
	
	ugfx.text(80,40,"Game Over!",ugfx.WHITE)
	ugfx.text(20,100,reason,ugfx.RED)
	playing=0
예제 #12
0
def drawui():
    ugfx.init()
    buttons.init()
    ugfx.clear(ugfx.html_color(0x87F717))

    ugfx.set_default_font(ugfx.FONT_MEDIUM)

    ugfx.fill_circle(50,50, 20, ugfx.WHITE)
    ugfx.fill_circle(50, 100, 20, ugfx.WHITE)

    ugfx.text(45, 45, "A", ugfx.RED)
    ugfx.text(45, 95, "B", ugfx.RED)

    ugfx.text(95, 45, "Flash the lights", ugfx.WHITE)
    ugfx.text(95, 95, "Disco Inferno", ugfx.WHITE)

    ugfx.fill_polygon(270,50, [ [0,0], [40,0], [40, 175], [0, 175] ], ugfx.RED)#  , [230, 100], [230, 60]
    ugfx.fill_polygon(270,50, [ [0,0], [-20,10], [-20, 50], [0, 40] ], ugfx.RED)#  , [230, 100], [230, 60]

    ugfx.area(283, 61, 14, 10, ugfx.WHITE)
    ugfx.area(283, 79, 14, 10, ugfx.WHITE)
    ugfx.area(283, 97, 14, 10, ugfx.WHITE)
    ugfx.area(283, 115, 14, 10, ugfx.WHITE)
    ugfx.area(283, 133, 14, 10, ugfx.WHITE)
    ugfx.area(283, 151, 14, 10, ugfx.WHITE)
    ugfx.area(283, 169, 14, 10, ugfx.WHITE)
    ugfx.area(283, 187, 14, 10, ugfx.WHITE)
예제 #13
0
def draw(x, y, window):
    global obj
    global sty
    if len(obj) == 0:

        sty = ugfx.Style()
        sty.set_enabled([ugfx.RED, ugfx.BLACK, ugfx.GREY, ugfx.GREY])

        #ugfx.Imagebox(0,0,window.width(),window.height(),"apps/home/back.bmp",0, win2)
        ugfx.set_default_font(ugfx.FONT_NAME)
        l = ugfx.Label(5,
                       20,
                       310,
                       window.height() - 20,
                       database_get("display-name", "<not actually set yet>"),
                       parent=window)
        obj.append(l)
        ugfx.set_default_font(ugfx.FONT_MEDIUM_BOLD)
        obj.append(
            ugfx.Label(5,
                       0,
                       310,
                       20,
                       "My name is...",
                       parent=window,
                       style=sty))
        #ugfx.text(40,80,database_get("display-name", "<not set yet>"),ugfx.BLUE)
        #ugfx.circle(140,150,40,ugfx.GREEN)
        #ugfx.circle(160,150,40,ugfx.GREEN)
        #ugfx.circle(180,150,40,ugfx.GREEN)
        window.show()
    else:
        window.hide()
        window.show()
예제 #14
0
def draw_fps():
    ugfx.set_default_font(ugfx.FONT_SMALL)
    #redraw_bg_range(300, 10, 320, 35)
    try:
        fps = int((len(frame_times) / (frame_times[-1] - frame_times[0])) * 1000)
    except ZeroDivisionError:
        fps = 0
    ugfx.text(300, 10, "%d" % fps, ugfx.WHITE)
예제 #15
0
파일: main.py 프로젝트: Kimbsy/EMF_20016
def display():
	logo = 'apps/nexmo~messages/nexmo_logo.gif'
	ugfx.area(0,0,ugfx.width(),ugfx.height(),0xFFFF)
	ugfx.set_default_font(ugfx.FONT_MEDIUM_BOLD)	
	ugfx.text(20,20,"My Number is...",ugfx.BLACK)
	ugfx.text(20,130,"Powered By, ",ugfx.GREY)
	ugfx.display_image(15,150,logo)
	ugfx.set_default_font(ugfx.FONT_TITLE)
	ugfx.text(40,75,mynumber+" ",ugfx.BLUE)
예제 #16
0
def tick(icon):
	global i
	i += 1
	icon.show()
	ugfx.set_default_font("c*")
	icon.area(0, 0, icon.width(), icon.height(), 0xFFFF)
	icon.text(0, 0, str(i), 0)

	return "Test: %d"% i
예제 #17
0
def show_screen(color1, color2, text, text2="", flip=False):
    if flip:
        ugfx.orientation(90)
    ugfx.clear(ugfx.html_color(color1))
    ugfx.set_default_font(ugfx.FONT_NAME)
    ugfx.text(0, 100, text, ugfx.html_color(color2))
    ugfx.set_default_font(ugfx.FONT_SMALL)
    ugfx.text(0, 200, text2, ugfx.html_color(color2))
    if flip:
        ugfx.orientation(270)
예제 #18
0
def no_more(my_profile):
    top_left_logo()

    ugfx.set_default_font(ugfx.FONT_TITLE)
    ugfx.Label(5, 90, 230, 50, "You've swiped everybody!", justification=ugfx.Label.CENTERTOP)
    ugfx.set_default_font(ugfx.FONT_SMALL)
    ugfx.Label(5, 160, 230, 20, "Soz "+my_profile["username"], justification=ugfx.Label.CENTERTOP)
    ugfx.Label(5, 180, 230, 20, "Come back later ;)", justification=ugfx.Label.CENTERTOP)

    # ugfx.Button(0, 280, 100, 40, "< Edit profile", parent=None, shape=ugfx.Button.RECT, style=None)
    ugfx.Button(160, 280, 100, 40, "Try again >", parent=None, shape=ugfx.Button.RECT, style=None)
예제 #19
0
def prompt_option(options, index=0, text = "Please select one of the following:", title=None, select_text="OK", none_text=None):
	"""Shows a dialog prompting for one of multiple options

	If none_text is specified the user can use the B or Menu button to skip the selection
	if title is specified a blue title will be displayed about the text
	"""
	global wait_for_interrupt, button_pushed

	ugfx.set_default_font("Roboto_Regular12")
	window = ugfx.Container(5, 5, ugfx.width() - 10, ugfx.height() - 10)
	window.show()

	list_y = 30
	if title:
		window.text(5, 10, title, ugfxBLACK)
		window.line(0, 25, ugfx.width() - 10, 25, ugfx.BLACK)
		window.text(5, 30, text, ugfx.BLACK)
		list_y = 50
	else:
		window.text(5, 10, text, ugfx.BLACK)

	options_list = ugfx.List(5, list_y, ugfx.width() - 25, 180 - list_y, parent = window)

	for option in options:
		if isinstance(option, dict) and option["title"]:
			options_list.add_item(option["title"])
		else:
			options_list.add_item(str(option))
	options_list.selected_index(index)

	select_text = "A: " + select_text
	if none_text:
		none_text = "B: " + none_text

	button_select = ugfx.Button(5, ugfx.height() - 50, 140 if none_text else ugfx.width() - 25, 30 , select_text, parent=window)
	button_none = ugfx.Button(ugfx.width() - 160, ugfx.height() - 50, 140, 30 , none_text, parent=window) if none_text else None

	try:
		ugfx.input_init()

		wait_for_interrupt = True
		while wait_for_interrupt:
			if button_pushed == "A": return options[options_list.selected_index()]
			if button_pushed == "B": return None
			if button_none and button_pushed == "START": return None
			time.sleep(0.2)

	finally:
		window.hide()
		window.destroy()
		options_list.destroy()
		button_select.destroy()
		if button_none: button_none.destroy()
		ugfx.poll()
예제 #20
0
파일: nomore.py 프로젝트: mjms3/emf2018
def screen(state):
    window = ugfx.Container(0, 0, 240, 320)
    window.show()

    top_left_logo()

    ugfx.set_default_font(ugfx.FONT_TITLE)
    l1 = ugfx.Label(5,
                    90,
                    230,
                    50,
                    "You've swiped everybody!",
                    parent=window,
                    justification=ugfx.Label.CENTERTOP)
    ugfx.set_default_font(ugfx.FONT_SMALL)
    l2 = ugfx.Label(5,
                    160,
                    230,
                    20,
                    "Soz " + state["profile"]["username"],
                    parent=window,
                    justification=ugfx.Label.CENTERTOP)
    l3 = ugfx.Label(5,
                    180,
                    230,
                    20,
                    "Come back later ;)",
                    parent=window,
                    justification=ugfx.Label.CENTERTOP)

    b2 = ugfx.Button(0,
                     280,
                     120,
                     40,
                     "< Edit profile",
                     parent=window,
                     shape=ugfx.Button.RECT,
                     style=None)
    b1 = ugfx.Button(120,
                     280,
                     120,
                     40,
                     "Try again >",
                     parent=window,
                     shape=ugfx.Button.RECT,
                     style=None)

    state['ui'].append(window)
    state['ui'].append(l1)
    state['ui'].append(l2)
    state['ui'].append(l3)
    state['ui'].append(b1)
    state['ui'].append(b2)
예제 #21
0
def prompt_option(options, index=0, text = "Please select one of the following:", title=None, select_text="OK", none_text=None):
	"""Shows a dialog prompting for one of multiple options

	If none_text is specified the user can use the B or Menu button to skip the selection
	if title is specified a blue title will be displayed about the text
	"""
	ugfx.set_default_font(ugfx.FONT_SMALL)
	window = ugfx.Container(5, 5, ugfx.width() - 10, ugfx.height() - 10)
	window.show()

	list_y = 30
	if title:
		window.text(5, 10, title, TILDA_COLOR)
		window.line(0, 25, ugfx.width() - 10, 25, ugfx.BLACK)
		window.text(5, 30, text, ugfx.BLACK)
		list_y = 50
	else:
		window.text(5, 10, text, ugfx.BLACK)

	options_list = ugfx.List(5, list_y, ugfx.width() - 25, 180 - list_y, parent = window)

	for option in options:
		if isinstance(option, dict) and option["title"]:
			options_list.add_item(option["title"])
		else:
			options_list.add_item(str(option))
	options_list.selected_index(index)

	select_text = "A: " + select_text
	if none_text:
		none_text = "B: " + none_text

	button_select = ugfx.Button(5, ugfx.height() - 50, 140 if none_text else ugfx.width() - 25, 30 , select_text, parent=window)
	button_none = ugfx.Button(ugfx.width() - 160, ugfx.height() - 50, 140, 30 , none_text, parent=window) if none_text else None

	try:
		buttons.init()

		while True:
			pyb.wfi()
			ugfx.poll()
			if buttons.is_triggered("BTN_A"): return options[options_list.selected_index()]
			if button_none and buttons.is_triggered("BTN_B"): return None
			if button_none and buttons.is_triggered("BTN_MENU"): return None

	finally:
		window.hide()
		window.destroy()
		options_list.destroy()
		button_select.destroy()
		if button_none: button_none.destroy()
		ugfx.poll()
def prompt_option(options, index=0, text = "Please select one of the following:", title=None, select_text="OK", none_text=None):
    """Shows a dialog prompting for one of multiple options

    If none_text is specified the user can use the B or Menu button to skip the selection
    if title is specified a blue title will be displayed about the text
    """
    ugfx.set_default_font(ugfx.FONT_SMALL)
    window = ugfx.Container(5, 5, ugfx.width() - 10, ugfx.height() - 10)
    window.show()

    list_y = 30
    if title:
        window.text(5, 10, title, TILDA_COLOR)
        window.line(0, 25, ugfx.width() - 10, 25, ugfx.BLACK)
        window.text(5, 30, text, ugfx.BLACK)
        list_y = 50
    else:
        window.text(5, 10, text, ugfx.BLACK)

    options_list = ugfx.List(5, list_y, ugfx.width() - 25, 180 - list_y, parent = window)

    for option in options:
        if isinstance(option, dict) and option["title"]:
            options_list.add_item(option["title"])
        else:
            options_list.add_item(str(option))
    options_list.selected_index(index)

    select_text = "A: " + select_text
    if none_text:
        none_text = "B: " + none_text

    button_select = ugfx.Button(5, ugfx.height() - 50, 140 if none_text else ugfx.width() - 25, 30 , select_text, parent=window)
    button_none = ugfx.Button(ugfx.width() - 160, ugfx.height() - 50, 140, 30 , none_text, parent=window) if none_text else None

    try:
        buttons.init()

        while True:
            pyb.wfi()
            ugfx.poll()
            if buttons.is_triggered("BTN_A"): return options[options_list.selected_index()]
            if button_none and buttons.is_triggered("BTN_B"): return None
            if button_none and buttons.is_triggered("BTN_MENU"): return None

    finally:
        window.hide()
        window.destroy()
        options_list.destroy()
        button_select.destroy()
        if button_none: button_none.destroy()
        ugfx.poll()
예제 #23
0
    def welcome(self):

        exit_welcome = pyb.millis() + 30000

        if self.__debug:
            print("emf_hub_mon: Drawing the welcome display")

        self.draw_background(ugfx.WHITE)

        self.__text_centre("Shows who is transmitting on the",
                           ugfx.FONT_MEDIUM, ugfx.BLACK, 115)
        self.__text_centre("\"EMF HUB\", a hub for amateur radio!",
                           ugfx.FONT_MEDIUM, ugfx.BLACK, 135)

        self.__text_centre("Press A or B to continue", ugfx.FONT_MEDIUM,
                           ugfx.BLACK, 220)

        while pyb.millis() < exit_welcome:

            self.__status.update()

            if buttons.is_triggered('BTN_A') or buttons.is_triggered('BTN_B'):
                print("emf_hub_mon: Button pressed - exiting welcome screen")
                break

        self.draw_background(ugfx.WHITE)

        ugfx.set_default_font(ugfx.FONT_MEDIUM)
        ugfx.text(20, 115, "More Info: http://hub.emfhams.org", ugfx.BLACK)
        ugfx.text(60, 155, "Brought to you by:", ugfx.BLACK)
        ugfx.text(15, 175, "2E0SIP, MM0MRU and the EMF Hams", ugfx.BLACK)

        self.__text_centre("Press A or B to continue", ugfx.FONT_MEDIUM,
                           ugfx.BLACK, 220)

        exit_welcome = pyb.millis() + 30000

        while pyb.millis() < exit_welcome:

            self.__status.update()

            if buttons.is_triggered('BTN_A') or buttons.is_triggered('BTN_B'):
                print("emf_hub_mon: Button pressed - exiting welcome screen")
                break

        if not self.__config.get('demo'):
            print("emf_hub_mon: Setting first_boot false")
            self.__config.set('first_boot', False)
            self.__config.flush()
        else:
            print("emf_hub_mon: Demo mode, skipping setting first_boot")
예제 #24
0
    def display_idle(self, lh_call="", lh_name=""):

        if self.__debug:
            print("emf_hub_mon: Drawing Idle Screen")

        self.__pending_idle = False

        ugfx.backlight(40)
        self.draw_background(ugfx.html_color(0xf7f4f4))
        ugfx.set_default_font(ugfx.FONT_TITLE)

        self.__text_centre("IDLE", ugfx.FONT_TITLE, ugfx.GREY, 120)
        self.__display_lh(lh_call, lh_name)
        self.__led.off()
예제 #25
0
    def __text_centre(self, text, size, color, y):

        if size == ugfx.FONT_TITLE:
            font_size = 13
        elif size == ugfx.FONT_MEDIUM_BOLD:
            font_size = 9
        elif size == ugfx.FONT_MEDIUM:
            font_size = 8
        else:
            font_size = 7

        ugfx.set_default_font(size)
        x = int((ugfx.width() - (len(text) * font_size)) / 2)
        ugfx.text(x, y, text, color)
예제 #26
0
def draw_badge():
	style.set_enabled([ugfx.WHITE, ugfx.html_color(0x800080), ugfx.html_color(0x800080), ugfx.html_color(0x800080)])
	style.set_background(ugfx.html_color(0x800080))
	ugfx.clear(ugfx.html_color(0x800080))
	ugfx.set_default_style(style)
	# Logo stuff
	ugfx.display_image(
		int((ugfx.width() - logo_width) / 2),
		int((ugfx.height() - logo_height) / 2),
		logo_path
	)

	# Draw for people to see
	ugfx.orientation(90)
	# Draw introduction
	ugfx.set_default_font(ugfx.FONT_TITLE)
	ugfx.Label(0, ugfx.height() - name_height - intro_height, ugfx.width(), intro_height, intro_text, justification=ugfx.Label.CENTER)
	# Process name
	name_setting = name("Set your name in the settings app")
	if len(name_setting) <= max_name:
		ugfx.set_default_font(ugfx.FONT_NAME)
	else:
		ugfx.set_default_font(ugfx.FONT_MEDIUM_BOLD)
	# Draw name
	ugfx.Label(0, ugfx.height() - name_height, ugfx.width(), name_height, name_setting, justification=ugfx.Label.CENTER)

	# Draw for wearer to see
	ugfx.orientation(270)
	ugfx.set_default_font(ugfx.FONT_SMALL)
	status = ugfx.Label(0, ugfx.height() - status_height, ugfx.width(), status_height, "", justification=ugfx.Label.LEFT)
예제 #27
0
    def Status(self, data=None):
        self.destroy()
        self.create_window()
        w = self.window
        y = 10
        gap = 5
        height = 35
        ugfx.Label(10, y, w.width() - 20, height, 'Platform: {}'.format(util.get_version()), parent=w)
        y += gap + height
        ugfx.Label(10, y, w.width() - 20, height, 'Release: {}'.format(uos.uname()[2]), parent=w)
        y += gap + height
        ugfx.Label(10, y, w.width() - 20, height, 'firmware:', parent=w)
        ugfx.set_default_font('IBMPlexMono_Bold18')
        y += height
        ugfx.Label(10, y, w.width() - 20, height + 10, '{}'.format(uos.uname()[3]), parent=w)
        ugfx.set_default_font(self.default_font)
        ugfx.set_default_font('IBMPlexSans_Regular18')
        self.create_status_box()
        ugfx.set_default_font(self.default_font)

        try:
            ota_data = ota.check_version()
        except ota.OtaException as e:
            self.set_status('Error: {}'.format(e))
        else:
            if ota_data:
                self.status_box.destroy()
                ugfx.Label(10, 180, 200, 40, text='New: {}'.format(ota_data['version']),
                    parent=w)
                self.btngroup = ButtonGroup(self.window, 190, 180, 110, 40, 10)
                self.btngroup.add('Upgrade', self.install_ota, ota_data)
                self.btngroup.end()
            else:
                self.set_status('Up to date')
def main():
    ugfx.init()

    h = htu21d.HTU21D(25, 26)

    ugfx.set_default_font('IBMPlexMono_Bold48')
    l = ugfx.Label(40, 60, 240, 120, text='')

    while True:
        try:
            l.text('{:.1f} C\n{:.1f} %'.format(h.temperature, h.humidity))
        except OSError:
            l.text('OSError')
        time.sleep(0.5)
예제 #29
0
def write_name():
    name_setting = name("Set your name in the settings app")
    if len(name_setting) <= max_name:
        ugfx.set_default_font(ugfx.FONT_NAME)
    else:
        ugfx.set_default_font(ugfx.FONT_MEDIUM_BOLD)
    # Draw name
    ugfx.orientation(90)
    ugfx.Label(0,
               ugfx.height() - name_height,
               ugfx.width(),
               name_height,
               name_setting,
               justification=ugfx.Label.CENTER,
               style=style)
예제 #30
0
    def tx(self, call, name):

        if self.__debug:
            print("emf_hub_mon: Drawing the Tx display")

        ugfx.backlight(100)

        self.draw_background(ugfx.html_color(0xaefcbd))

        ugfx.set_default_font(ugfx.FONT_TITLE)

        self.__text_centre(call, ugfx.FONT_TITLE, ugfx.BLACK, 110)
        self.__text_centre(name, ugfx.FONT_MEDIUM_BOLD, ugfx.BLACK, 140)

        self.__led.on()
예제 #31
0
파일: main.py 프로젝트: jimc13/Mk4-Apps-1
def init_label():

    ugfx.set_default_font(ugfx.FONT_MEDIUM)

    margin_v = 29
    margin_h = 18

    screen_w = 240
    screen_h = 320

    return ugfx.Label(
        margin_h,
        margin_v,  #x, y
        screen_w - (margin_h * 2),
        screen_h - (margin_v * 2),  # width, height
        _LOADING_TEXT)
예제 #32
0
def main():
    #h = DHT11(machine.Pin(33)) # J8
    h = DHT11(machine.Pin(26))  # J7

    ugfx.set_default_font('IBMPlexMono_Bold24')
    ugfx.clear()
    ugfx.Label(40, 0, 240, 60, text='DHT11/22 Demo')

    ugfx.set_default_font('IBMPlexMono_Regular24')
    l = ugfx.Label(40, 60, 240, 120, text='')

    while True:
        h.measure()
        h.temperature()
        l.text('temperature:{},humidity:{}'.format(h.temperature(),
                                                   h.humidity()))
        time.sleep(1)
예제 #33
0
파일: main.py 프로젝트: Kimbsy/EMF_20016
def printmsg(sender, text, ts):
	ugfx.set_default_font(ugfx.FONT_SMALL)	
	ugfx.area(0,0,ugfx.width(),ugfx.height(),0x0000)
	ugfx.text(10,10,"From: "+sender,ugfx.BLUE)
	timestamp = timestring(ts)
	linelen = 40
	lines = int(math.ceil(len(text)/linelen))
	for l in range(0, lines):
		pixels = l*25+35
		start = l*linelen
		end = l*linelen+linelen
		if end>len(text):
			end = len(text)
		linetext = text[start:end]
		ugfx.text(10,pixels,linetext,0xFFFF)
	ugfx.text(10,200,timestamp,ugfx.GREEN)
	return
예제 #34
0
    def __init__(self, width=ugfx.width(), height=ugfx.height()):
        # Default font
        ugfx.set_default_font(self.default_font)

        # Container
        self.container = ugfx.Container(0,
                                        0,
                                        width,
                                        height,
                                        style=styles.ibm_st)

        # Title Label
        self.title_label = ugfx.Label(5,
                                      5,
                                      310,
                                      40,
                                      text='',
                                      parent=self.container)
예제 #35
0
    def __update_wifi(self):

        ugfx.set_default_font("c*")

        try:
            rssi = wifi.nic().get_rssi()
        except:
            rssi = 0

        if rssi == 0:
            rssi = self.__last_rssi
        else:
            self.__last_rssi = rssi

        wifi_is_connected = wifi.nic().is_connected()
        wifi_timeout = 1
        self.__draw_wifi(self.__sty_tb.background(), rssi, wifi_is_connected,
                         wifi_timeout > 0, self.__win_wifi)
예제 #36
0
def setup_right_menu():
	ugfx.set_default_font(ugfx.FONT_SMALL)

	if room==1:
		if (haskey1==0):
			ugfx.text(190, 30, "The gate is locked.", ugfx.RED)
			ugfx.text(190, 50, "Maybe you should ", ugfx.RED)
			ugfx.text(190, 70, "find a key.", ugfx.RED)
		elif (haskey1==1):
			ugfx.text(190, 30, "The key fits the lock!", ugfx.RED)
			ugfx.text(190, 50, "A: Escape the Castle", ugfx.RED)
			
	if room==2:
		if orc1:
			ugfx.text(190, 30, "An orc is here.", ugfx.RED)
			ugfx.text(190, 50, "A: Kick", ugfx.RED)
			ugfx.text(190, 70, "B: Punch", ugfx.RED)
			
	if room==5:
		if orc2:
			ugfx.text(190, 30, "A slightly bigger", ugfx.RED) 
			ugfx.text(190, 50, "orc is here.", ugfx.RED)
			ugfx.text(190, 70, "A: Kick", ugfx.RED)
			ugfx.text(190, 90, "B: Tell it a joke", ugfx.RED)
	if room==6:
		ugfx.text(190, 30, "A fountain", ugfx.RED) 
		ugfx.text(190, 50, "is here.", ugfx.RED)
		ugfx.text(190, 70, "A: Drink", ugfx.RED)
		ugfx.text(190, 90, "B: Look in", ugfx.RED)
		
	if room==8:
		if orc3:
			ugfx.text(190, 30, "A humongous", ugfx.RED) 
			ugfx.text(190, 50, "orc is here.", ugfx.RED)
			ugfx.text(190, 70, "A: Kick", ugfx.RED)
			ugfx.text(190, 90, "B: Sneak past", ugfx.RED)
			
			
	if room==9:
		ugfx.text(190, 30, "A key is here.", ugfx.RED)
		ugfx.text(190, 50, "A: Take", ugfx.RED)
		ugfx.text(190, 70, "B: Eat", ugfx.RED)
		
	ugfx.text(30, 200, "HP: "+str(hp), ugfx.BLUE)
예제 #37
0
def draw_battery(back_colour,percent, win_bv):
	percent = max(0,percent)
	ugfx.set_default_font("c*")
	main_c = ugfx.WHITE #back_colour^0xFFFF
	x=3
	y=3
	win_bv.area(x+35,y,40,24,back_colour)
	if percent <= 120:
		win_bv.text(x+35,y,str(int(min(percent,100))),main_c)
	y += 2
	win_bv.area(x,y,30,11,main_c)
	win_bv.area(x+30,y+3,3,5,main_c)

	if percent > 120:
		win_bv.area(x+2,y+2,26,7,ugfx.YELLOW)
	elif percent > 2:
		win_bv.area(x+2,y+2,26,7,back_colour)
		win_bv.area(x+2,y+2,int(min(percent,100)*26/100),7,main_c)
	else:
		win_bv.area(x+2,y+2,26,7,ugfx.RED)
예제 #38
0
def showevent(stage, event):
	start = event['start_date']
	end = event['end_date']
	speaker = event['speaker']
	text = event['title']
	ugfx.set_default_font(ugfx.FONT_MEDIUM)	
	ugfx.area(0,0,ugfx.width(),ugfx.height(),0x0000)
	ugfx.text(10,10,stage,ugfx.GREY)
	ugfx.text(10,35,"Start: "+start,ugfx.GREEN)
	ugfx.text(10,60,"End: "+end,ugfx.RED)
	ugfx.text(10,85,"Speaker: "+speaker,ugfx.BLUE)
	linelen = 25
	lines = int(math.ceil(len(text)/linelen))
	for l in range(0, lines):
		pixels = l*25+110
		start = l*linelen
		end = l*linelen+linelen
		if end>len(text):
			end = len(text)
		linetext = text[start:end]
		ugfx.text(10,pixels,linetext,0xFFFF)
	return
예제 #39
0
def draw(x,y,window):
	global obj
	global sty
	if len(obj) == 0:
	
		sty = ugfx.Style()
		sty.set_enabled([ugfx.RED, ugfx.BLACK, ugfx.GREY, ugfx.GREY])
		
		
		#ugfx.Imagebox(0,0,window.width(),window.height(),"apps/home/back.bmp",0, win2)
		ugfx.set_default_font(ugfx.FONT_NAME)
		l=ugfx.Label(5,20,310,window.height()-20,database_get("display-name", "<not actually set yet>"),parent=window)
		obj.append(l)
		ugfx.set_default_font(ugfx.FONT_MEDIUM_BOLD)
		obj.append(ugfx.Label(5,0,310,20,"My name is...",parent=window,style=sty))
		#ugfx.text(40,80,database_get("display-name", "<not set yet>"),ugfx.BLUE)
		#ugfx.circle(140,150,40,ugfx.GREEN)
		#ugfx.circle(160,150,40,ugfx.GREEN)
		#ugfx.circle(180,150,40,ugfx.GREEN)
		window.show()
	else:
		window.hide()
		window.show()
예제 #40
0
def prompt_boolean(text, title="TiLDA", true_text="Yes", false_text="No", width = 260, height = 180, font=ugfx.FONT_SMALL, style=None):
	"""A simple one and two-options dialog

	if 'false_text' is set to None only one button is displayed.
	If both 'true_text' and 'false_text' are given a boolean is returned
	"""
	global default_style_dialog
	if style == None:
		style = default_style_dialog
	ugfx.set_default_font(ugfx.FONT_MEDIUM_BOLD)
	window = ugfx.Container((ugfx.width() - width) // 2, (ugfx.height() - height) // 2,  width, height, style=style)
	window.show()
	ugfx.set_default_font(font)
	window.text(5, 10, title, TILDA_COLOR)
	window.line(0, 30, width, 30, ugfx.BLACK)

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

	ugfx.set_default_font(font)
	label = ugfx.Label(5, 30, width - 10, height - 80, text = text, parent=window)
	ugfx.set_default_font(ugfx.FONT_MEDIUM_BOLD)
	button_yes = ugfx.Button(5, height - 40, width // 2 - 15 if false_text else width - 15, 30 , true_text, parent=window)
	button_no = ugfx.Button(width // 2 + 5, height - 40, width // 2 - 15, 30 , false_text, parent=window) if false_text else None

	try:
		buttons.init()

		button_yes.attach_input(ugfx.BTN_A,0)
		if button_no: button_no.attach_input(ugfx.BTN_B,0)

		window.show()

		while True:
			pyb.wfi()
			if buttons.is_triggered("BTN_A"): return True
			if buttons.is_triggered("BTN_B"): return False

	finally:
		window.hide()
		window.destroy()
		button_yes.destroy()
		if button_no: button_no.destroy()
		label.destroy()
예제 #41
0
def prompt_text(description, init_text = "", true_text="OK", false_text="Back", width = 300, height = 200, font=ugfx.FONT_MEDIUM_BOLD, style=default_style_badge):
	"""Shows a dialog and keyboard that allows the user to input/change a string

	Returns None if user aborts with button B
	"""

	window = ugfx.Container(int((ugfx.width()-width)/2), int((ugfx.height()-height)/2), width, height, style=style)

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

	if buttons.has_interrupt("BTN_MENU"):
		buttons.disable_interrupt("BTN_MENU")

	ugfx.set_default_font(ugfx.FONT_MEDIUM)
	kb = ugfx.Keyboard(0, int(height/2), width, int(height/2), parent=window)
	edit = ugfx.Textbox(5, int(height/2)-30, int(width*4/5)-10, 25, text = init_text, parent=window)
	ugfx.set_default_font(ugfx.FONT_SMALL)
	button_yes = ugfx.Button(int(width*4/5), int(height/2)-30, int(width*1/5)-3, 25 , true_text, parent=window)
	button_no = ugfx.Button(int(width*4/5), int(height/2)-30-30, int(width/5)-3, 25 , false_text, parent=window) if false_text else None
	ugfx.set_default_font(font)
	label = ugfx.Label(int(width/10), int(height/10), int(width*4/5), int(height*2/5)-60, description, parent=window)

	try:
		buttons.init()

		button_yes.attach_input(ugfx.BTN_MENU,0)
		if button_no: button_no.attach_input(ugfx.BTN_B,0)

		window.show()
		edit.set_focus()
		while True:
			pyb.wfi()
			ugfx.poll()
			#if buttons.is_triggered("BTN_A"): return edit.text()
			if buttons.is_triggered("BTN_B"): return None
			if buttons.is_triggered("BTN_MENU"): return edit.text()

	finally:
		window.hide()
		window.destroy()
		button_yes.destroy()
		if button_no: button_no.destroy()
		label.destroy()
		kb.destroy()
		edit.destroy();
	return
예제 #42
0
파일: main.py 프로젝트: wwqrd/gumshoe
 def render(self):
     global game_state
     print('render '+game_state)
     ugfx.clear()
     if game_state == 'SEARCH':
         ugfx.set_default_font(ugfx.FONT_MEDIUM_BOLD)
         ugfx.Label(5, 5, ugfx.width(), 20, "Scanning for hackers!...")
         ugfx.set_default_font(ugfx.FONT_NAME)
         ugfx.Label(5, 30, ugfx.width(), 40, self.current_battle.status())
         ugfx.set_default_font(ugfx.FONT_MEDIUM_BOLD)
         ugfx.Label(5, 100, ugfx.width(), 20, "Press (A) to battle, (B) to try to escape")
     elif game_state == 'BATTLE':
         ugfx.set_default_font(ugfx.FONT_NAME)
         ugfx.Label(5, 30, ugfx.width(), 40, self.current_battle.status())
         ugfx.set_default_font(ugfx.FONT_MEDIUM_BOLD)
         ugfx.Label(5, 100, ugfx.width(), 20, "Press (A) to continue, (B) to try to escape")
     elif game_state == 'ATTACK':
         ugfx.set_default_font(ugfx.FONT_NAME)
         ugfx.Label(5, 30, ugfx.width(), 40, self.current_battle.status())
         ugfx.set_default_font(ugfx.FONT_MEDIUM_BOLD)
         ugfx.Label(5, 100, ugfx.width(), 20, "Press (A) to continue, (B) to try to escape")
     elif game_state == 'ESCAPE':
         ugfx.set_default_font(ugfx.FONT_NAME)
         ugfx.Label(5, 30, ugfx.width(), 40, self.current_battle.status())
         ugfx.set_default_font(ugfx.FONT_MEDIUM_BOLD)
         ugfx.Label(5, 100, ugfx.width(), 20, "Press (A) to continue, (B) to try to escape")
     elif game_state == 'WIN':
         ugfx.set_default_font(ugfx.FONT_NAME)
         ugfx.Label(5, 30, ugfx.width(), 40, self.current_battle.status())
         ugfx.set_default_font(ugfx.FONT_MEDIUM_BOLD)
         ugfx.Label(5, 100, ugfx.width(), 20, "Press (A) to continue, (B) to try to escape")
     elif game_state == 'LOSE':
         ugfx.set_default_font(ugfx.FONT_NAME)
         ugfx.Label(5, 30, ugfx.width(), 40, self.current_battle.status())
         ugfx.set_default_font(ugfx.FONT_MEDIUM_BOLD)
         ugfx.Label(5, 100, ugfx.width(), 20, "Press (A) to continue, (B) to try to escape")
     elif game_state == 'INACTIVE':
         ugfx.set_default_font(ugfx.FONT_MEDIUM_BOLD)
         ugfx.Label(5, 5, ugfx.width(), 25, "Hello agent,")
         ugfx.Label(5, 25, ugfx.width(), 25, "Captures: %i" % self.gumshoe.captures)
         ugfx.Label(5, 50, ugfx.width(), 25, "XP: %i" % self.gumshoe.xp)
         ugfx.Label(5, 75, ugfx.width(), 25, "Instructions:")
         ugfx.Label(5, 100, ugfx.width(), 25, "(1) Explore the EMF site")
         ugfx.Label(5, 125, ugfx.width(), 50, "(2) When in position, press A to start a search for nearby hackers...")
         ugfx.Label(5, 175, ugfx.width(), 50, "Beware of confronting more experienced hackers!")
예제 #43
0
파일: name.py 프로젝트: Jonty/Mk3-Firmware
def display_name():
	ugfx.area(0,0,ugfx.width(),ugfx.height(),0xFFFF)
	ugfx.set_default_font("D*")
	ugfx.text(40,120,"MATT",ugfx.YELLOW)
	ugfx.circle(160,200,40,ugfx.GREEN)
예제 #44
0
def mainscreen():
	ugfx.area(0,0,ugfx.width(),ugfx.height(),0x0000)
	ugfx.set_default_font(ugfx.FONT_MEDIUM_BOLD)	
	ugfx.text(30,30,"EMF Schedule Now & Next ",ugfx.GREY)
	ugfx.text(40,75,"Press [A] to get events ",ugfx.BLUE)
	return
예제 #45
0
def home_main():
	global orientation, next_tick, tick

	ugfx.area(0,0,320,240,sty_tb.background())

	ugfx.set_default_font(ugfx.FONT_MEDIUM)
	win_bv = ugfx.Container(0,0,80,25, style=sty_tb)
	win_wifi = ugfx.Container(82,0,60,25, style=sty_tb)
	win_name = ugfx.Container(0,25,320,240-25-60, style=dialogs.default_style_badge)
	win_text = ugfx.Container(0,240-60,320,60, style=sty_tb)

	windows = [win_bv, win_wifi, win_text]

	obj_name = apps.home.draw_name.draw(0,25,win_name)

	buttons.init()

	gc.collect()
	ugfx.set_default_font(ugfx.FONT_MEDIUM_BOLD)
	hook_feeback = ugfx.List(0, 0, win_text.width(), win_text.height(), parent=win_text)

	win_bv.show()
	win_text.show()
	win_wifi.show()

	min_ctr = 28

	# Create external hooks so other apps can run code in the context of
	# the home screen.
	# To do so an app needs to have an external.py with a tick() function.
	# The tick period will default to 60 sec, unless you define something
	# else via a "period" variable in the module context (use milliseconds)
	# If you set a variable "needs_wifi" in the module context tick() will
	# only be called if wifi is available
	# If you set a variable "needs_icon" in the module context tick() will
	# be called with a reference to a 25x25 pixel ugfx container that you
	# can modify
	external_hooks = []
	icon_x = 150
	for path in get_external_hook_paths():
		try:
			module = __import__(path)
			if not hasattr(module, "tick"):
				raise Exception("%s must have a tick function" % path)

			hook = {
				"name": path[5:-9],
				"tick": module.tick,
				"needs_wifi": hasattr(module, "needs_wifi"),
				"period": module.period if hasattr(module, "period") else 60 * 1000,
				"next_tick_at": 0
			}

			if hasattr(module, "needs_icon"):
				hook["icon"] = ugfx.Container(icon_x, 0, 25, 25)
				icon_x += 27

			external_hooks.append(hook)
		except Exception as e: # Since we dont know what exception we're looking for, we cant do much
			print ("%s while parsing background task %s.  This task will not run! " % (type(e).__name__, path[5:-9]))
			sys.print_exception(e)
			continue # If the module fails to load or dies during the setup, skip it

	backlight_adjust()

	inactivity = 0
	last_rssi = 0

	## start connecting to wifi in the background
	wifi_timeout = 30 #seconds
	wifi_reconnect_timeout = 0
	try:
		wifi.connect(wait = False)
	except OSError:
		print("Creating default wifi settings file")
		wifi.create_default_config()

	while True:
		pyb.wfi()
		ugfx.poll()

		if (next_tick <= pyb.millis()):
			tick = True
			next_tick = pyb.millis() + 1000

		#if wifi still needs poking
		if (wifi_timeout > 0):
			if wifi.nic().is_connected():
				wifi_timeout = -1
				#wifi is connected, but if becomes disconnected, reconnect after 5 sec
				wifi_reconnect_timeout = 5
			else:
				wifi.nic().update()


		if tick:
			tick = False

			ledg.on()

			if (wifi_timeout > 0):
				wifi_timeout -= 1;

			# change screen orientation
			ival = imu.get_acceleration()
			if ival['y'] < -0.5:
				if orientation != 0:
					ugfx.orientation(0)
			elif ival['y'] > 0.5:
				if orientation != 180:
					ugfx.orientation(180)
			if orientation != ugfx.orientation():
				inactivity = 0
				ugfx.area(0,0,320,240,sty_tb.background())
				orientation = ugfx.orientation()
				for w in windows:
					w.hide(); w.show()
				apps.home.draw_name.draw(0,25,win_name)


			#if wifi timeout has occured and wifi isnt connected in time
			if (wifi_timeout == 0) and not (wifi.nic().is_connected()):
				print("Giving up on Wifi connect")
				wifi_timeout = -1
				wifi.nic().disconnect()  #give up
				wifi_reconnect_timeout = 30 #try again in 30sec

			wifi_connect = wifi.nic().is_connected()

			#if not connected, see if we should try again
			if not wifi_connect:
				if wifi_reconnect_timeout>0:
					wifi_reconnect_timeout -= 1
					if wifi_reconnect_timeout == 0:
						wifi_timeout = 60 #seconds
						wifi.connect(wait = False)

			ledg.on()

			# display the wifi logo
			rssi = wifi.nic().get_rssi()
			if rssi == 0:
				rssi = last_rssi
			else:
				last_rssi = rssi


			draw_wifi(sty_tb.background(),rssi, wifi_connect,wifi_timeout>0,win_wifi)

			battery_percent = onboard.get_battery_percentage()
			draw_battery(sty_tb.background(),battery_percent,win_bv)

			inactivity += 1

			# turn off after some period
			# takes longer to turn off in the 'used' position
			if ugfx.orientation() == 180:
				inactivity_limit = 120
			else:
				inactivity_limit = 30
			if battery_percent > 120:  #if charger plugged in
				if ugfx.backlight() == 0:
					ugfx.power_mode(ugfx.POWER_ON)
				ugfx.backlight(100)
			elif inactivity > inactivity_limit:
				low_power()
			else:
				backlight_adjust()

			ledg.off()

		for hook in external_hooks:
			try:
				if hook["needs_wifi"] and not wifi.nic().is_connected():
					continue;

				if hook["next_tick_at"] < pyb.millis():
					text = None
					if "icon" in hook:
						text = hook["tick"](hook["icon"])
					else:
						text = hook["tick"]()
					hook["next_tick_at"] = pyb.millis() + hook["period"]
					if text:
						if hook_feeback.count() > 10:
							hook_feeback.remove_item(0)
						hook_feeback.add_item(text)
						if hook_feeback.selected_index() >= (hook_feeback.count()-2):
							hook_feeback.selected_index(hook_feeback.count()-1)
			except Exception as e:  # if anything in the hook fails to work, we need to skip it
				print ("%s in %s background task. Not running again until next reboot! " % (type(e).__name__, hook['name']))
				sys.print_exception(e)
				external_hooks.remove(hook)
				continue

		if buttons.is_pressed("BTN_MENU"):
			pyb.delay(20)
			break
		if buttons.is_pressed("BTN_A"):
			inactivity = 0
			tick = True
		if buttons.is_pressed("BTN_B"):
			inactivity = 0
			tick = True


	for hook in external_hooks:
		if "icon" in hook:
			hook["icon"].destroy()
	for w in windows:
		w.destroy()
	apps.home.draw_name.draw_destroy(obj_name)
	win_name.destroy()
	hook_feeback.destroy()
	if ugfx.backlight() == 0:
		ugfx.power_mode(ugfx.POWER_ON)
	ugfx.backlight(100)
	ugfx.orientation(180)

	#if we havnt connected yet then give up since the periodic function wont be poked
	if wifi_timeout >= 0: # not (wifi.nic().is_connected()):
		wifi.nic().disconnect()
예제 #46
0
def file_loader():
	width = ugfx.width()
	height = ugfx.height()
	buttons.disable_menu_reset()

	# Create visual elements
	win_header = ugfx.Container(0,0,width,30)
	win_files = ugfx.Container(0,33,int(width/2),height-33)
	win_preview = ugfx.Container(int(width/2)+2,33,int(width/2)-2,height-33)
	components = [win_header, win_files, win_preview]
	ugfx.set_default_font(ugfx.FONT_TITLE)
	components.append(ugfx.Label(3,3,width-10,29,"Choose App",parent=win_header))
	ugfx.set_default_font(ugfx.FONT_MEDIUM)
	options = ugfx.List(0,30,win_files.width(),win_files.height()-30,parent=win_files)
	btnl = ugfx.Button(5,3,20,20,"<",parent=win_files)
	btnr = ugfx.Button(win_files.width()-7-20,3,20,20,">",parent=win_files)
	btnr.attach_input(ugfx.JOY_RIGHT,0)
	btnl.attach_input(ugfx.JOY_LEFT,0)
	components.append(options)
	components.append(btnr)
	components.append(btnl)
	ugfx.set_default_font(ugfx.FONT_MEDIUM_BOLD)
	l_cat = ugfx.Label(30,3,100,20,"Built-in",parent=win_files)
	components.append(l_cat)
	components.append(ugfx.Button(10,win_preview.height()-25,20,20,"A",parent=win_preview))
	components.append(ugfx.Label(35,win_preview.height()-25,50,20,"Run",parent=win_preview))
	components.append(ugfx.Button(80,win_preview.height()-25,20,20,"B",parent=win_preview))
	components.append(ugfx.Label(105,win_preview.height()-25,100,20,"Back",parent=win_preview))
	components.append(ugfx.Button(10,win_preview.height()-50,20,20,"M",parent=win_preview))
	components.append(ugfx.Label(35,win_preview.height()-50,100,20,"Pin/Unpin",parent=win_preview))
	ugfx.set_default_font(ugfx.FONT_SMALL)
	author = ugfx.Label(1,win_preview.height()-78,win_preview.width()-3,20,"by: ",parent=win_preview)
	desc = ugfx.Label(3,1,win_preview.width()-10,win_preview.height()-83,"",parent=win_preview,justification=ugfx.Label.LEFTTOP)
	components.append(author)
	components.append(desc)

	app_to_load = None

	pinned = database_get("pinned_apps", [])
	catergories = get_local_app_categories()
	c_ptr = 0

	try:
		win_header.show()
		win_files.show()
		win_preview.show()

		pinned = database_get("pinned_apps", [])
	#	apps = []
		apps_path = []

		if is_dir("apps"):
			for app in os.listdir("apps"):
				path = "apps/" + app
				if is_dir(path) and is_file(path + "/main.py"):
					apps_path.append(path + "/main.py")
		if is_dir("examples"):
			for app in os.listdir("examples"):
				path = "examples/" + app
				if is_file(path) and path.endswith(".py"):
					apps_path.append(path)

		displayed_apps = update_options(options, catergories[c_ptr], pinned)

		index_prev = -1;

		while True:
			pyb.wfi()
			ugfx.poll()

			if index_prev != options.selected_index():
				if options.selected_index() < len(displayed_apps):
					author.text("by: %s" % displayed_apps[options.selected_index()].user)
					desc.text(displayed_apps[options.selected_index()].description)
				index_prev = options.selected_index()

			if buttons.is_triggered("JOY_LEFT"):
				if c_ptr > 0:
					c_ptr -= 1
					btnl.set_focus()
					l_cat.text(catergories[c_ptr])
					displayed_apps = update_options(options, catergories[c_ptr], pinned)
					index_prev = -1

			if buttons.is_triggered("JOY_RIGHT"):
				if c_ptr < len(catergories)-1:
					c_ptr += 1
					btnr.set_focus()
					l_cat.text(catergories[c_ptr])
					displayed_apps = update_options(options, catergories[c_ptr], pinned)
					index_prev = -1

			if buttons.is_triggered("BTN_MENU"):
				app = displayed_apps[options.selected_index()]
				if app.folder_name in pinned:
					pinned.remove(app.folder_name)
				else:
					pinned.append(app.folder_name)
				update_options(options, catergories[c_ptr], pinned)
				database_set("pinned_apps", pinned)

			if buttons.is_triggered("BTN_B"):
				return None

			if buttons.is_triggered("BTN_A"):
				return displayed_apps[options.selected_index()]

	finally:
		for component in components:
			component.destroy()
예제 #47
0
		empty_local_app_cache()
		gc.collect()
		pyb.info()
		print("Loading: %s" % app_to_load)
		mod = __import__(app_to_load.main_path[:-3])
		if "main" in dir(mod):
			mod.main()
	except Exception as e:
		s = uio.StringIO()
		sys.print_exception(e, s)
		u=pyb.USB_VCP()
		if u.isconnected():
			raise(e)
		else:
			ugfx.clear()
			ugfx.set_default_font(ugfx.FONT_SMALL)
			w=ugfx.Container(0,0,ugfx.width(),ugfx.height())
			l=ugfx.Label(0,0,ugfx.width(),ugfx.height(),s.getvalue(),parent=w)
			w.show()
			while True:
				pyb.wfi()
				if (buttons.is_triggered("BTN_B")) or (buttons.is_triggered("BTN_B")) or (buttons.is_triggered("BTN_MENU")):
					break;
			#str=s.getvalue().split("\n")
			#if len(str)>=4:
			#out = "\n".join(str[4:])
			#dialogs.notice(out, width=wi-10, height=hi-10)
	onboard.semihard_reset()

	#deinit ugfx here
	#could hard reset here too
def mainscreen():
	ugfx.area(0,0,ugfx.width(),ugfx.height(),0x0000)
	ugfx.set_default_font(ugfx.FONT_MEDIUM_BOLD)	
	ugfx.text(30,30,"Whats My IP",ugfx.YELLOW)
	ugfx.text(40,75,"Press [A] to continue",ugfx.YELLOW)
	return
예제 #49
0
	arrow = [[0,0],[20,7],[0,14],[4,7]]
	win.fill_polygon(4, cursor_loc*25+18, arrow , backcolour)
	cursor_loc += x
	if cursor_loc < 0:
		cursor_loc = 0
	if cursor_loc > 2:
		cursor_loc = 2
	win.fill_polygon(4, cursor_loc*25+18, arrow ,ugfx.RED)


# Create visual elements
win_header = ugfx.Container(0,0,width,33)
win_main = ugfx.Container(0,35,width,height-35)

components = [win_header, win_main]
ugfx.set_default_font(ugfx.FONT_TITLE)
components.append(ugfx.Label(3,3,width-10,29,"Wifi Settings",parent=win_header))
ugfx.set_default_font(ugfx.FONT_MEDIUM_BOLD)
components.append(ugfx.Label(40,10,85,25,"Name:",parent=win_main))
components.append(ugfx.Label(40,35,85,25,"Password:"******"BadgeNet",parent=win_main)
lpwd = ugfx.Label(125,35,100,25,"letmein",parent=win_main)
components.append(lname)
components.append(lpwd)
ckdefault = ugfx.Checkbox(40,65,250,25,"EMF camp default",parent=win_main)
components.append(ckdefault)

win_main.show()
win_header.show()
예제 #50
0
def quick_launch_screen():
	wi = ugfx.width()
	hi = ugfx.height()

	win_header = ugfx.Container(0,0,wi,30)
	win_quick = ugfx.Container(0,33,wi,hi-33-33)
	win_help = ugfx.Container(0,hi-30,wi,30)

	DEFAULT_APPS = ["app_library", "sponsors", "changename"]
	with Database() as db:
		pinned = [App(a) for a in db.get("pinned_apps", DEFAULT_APPS)]
		pinned = [app for app in pinned if app.loadable] # Filter out deleted apps
		pinned = pinned[:7] # Limit to 7
		db.set("pinned_apps", [app.folder_name for app in pinned])

	ugfx.set_default_font(ugfx.FONT_TITLE)
	title = ugfx.Label(3,3,wi-10,45,"EMF Camp 2016",parent=win_header)

	ugfx.set_default_font(ugfx.FONT_MEDIUM_BOLD)

	pinned_buttons = []
	for i in range(0, 8):
		x = i % 2
		y = i // 2
		button_title = "View all" if i == 7 else ""
		if i < len(pinned):
			button_title = pinned[i].title
		pinned_buttons.append(ugfx.Button(35 + 155 * x, 5 + 40 * y, 120, 35, button_title, parent=win_quick))

	btn_ok = ugfx.Button(10,5,20,20,"A",parent=win_help,shape=ugfx.Button.ELLIPSE)
	l_ok = ugfx.Label(40,5,100,20,"Run",parent=win_help)

	btn_back = ugfx.Button(100,5,20,20,"B",parent=win_help,shape=ugfx.Button.ELLIPSE)
	l_back = ugfx.Label(130,5,100,20,"Back",parent=win_help)

	btn_menu = ugfx.Button(200,5,20,20,"M",parent=win_help,shape=ugfx.Button.ROUNDED)
	l_back = ugfx.Label(230,5,100,20,"Menu",parent=win_help)

	sty = dialogs.default_style_badge

	win_header.show()
	win_quick.show()
	win_help.show()

	buttons.init()
	cursor = {"x": 0, "y": 0}
	last_cursor = cursor.copy()
	_draw_cursor(0, 0, ugfx.RED, win_quick)

	app_to_load = "sponsors"

	if not database_get("quicklaunch_firstrun"):
		dialogs.notice("""This screen displays the most commonly used apps.
Apps pinned here can also interact with the name screen.
To view all apps, pin and un-pin, select 'View All'
		""", title="TiLDA - Quick Launch", close_text="Close")
		database_set("quicklaunch_firstrun", True)

	try:
		while True:
			pyb.wfi()

			if buttons.is_triggered("JOY_UP"):
				cursor["y"] = max(0, cursor["y"] - 1)
			if buttons.is_triggered("JOY_DOWN"):
				cursor["y"] = min(3, cursor["y"] + 1)
			if buttons.is_triggered("JOY_RIGHT"):
				cursor["x"] = 1
			if buttons.is_triggered("JOY_LEFT"):
				cursor["x"] = 0

			if cursor["x"] != last_cursor["x"] or cursor["y"] != last_cursor["y"]: # Has the cursor moved?
				_draw_cursor(last_cursor["x"], last_cursor["y"], dialogs.default_style_badge.background(), win_quick)
				_draw_cursor(cursor["x"], cursor["y"], ugfx.RED, win_quick)
				last_cursor = cursor.copy()

			if buttons.is_triggered("BTN_B"):
				return None

			#if buttons.is_triggered("BTN_MENU"):
			#	open unpin dialog
			#	break;

			if buttons.is_triggered("BTN_A"):
				index = cursor["x"] + cursor["y"] * 2
				if index == 7:
					return "file_loader"
				if index < len(pinned):
					return pinned[index]
	finally:
		buttons.disable_all_interrupt()

		win_header.hide()
		win_quick.hide()
		win_help.hide()
		for b in pinned_buttons:
			b.destroy()
		btn_ok.destroy()
		l_ok.destroy()
		btn_back.destroy()
		l_back.destroy()
		btn_menu.destroy()
		l_back.destroy()
		win_header.destroy()
		win_quick.destroy()
		win_help.destroy()
		title.destroy()
예제 #51
0
import ugfx
import os

#options.destroy()
#btn_ok.destroy()
#btn_menu.destroy()

ugfx.init()

ugfx.set_default_font("D*")

ugfx.text(40, 0, "EMF BADGE 2016", ugfx.PURPLE)

ugfx.set_default_font("C*")

options = ugfx.List(0,0,160,150)
btn_ok = ugfx.Button(200,50,70,30,"A: Run")
btn_menu = ugfx.Button(200,90,70,30,"M: Menu")

files = os.listdir()

for f in files:
	options.add_item(f)

btn_menu.attach_input(ugfx.BTN_MENU)
btn_ok.attach_input(ugfx.BTN_A)
예제 #52
0
파일: main.py 프로젝트: core-dd/cw_flash
### Author: core
### Description: Simple visual morse widget
### Category: morse
### License: MIT
### Appname: cw_flash

import ugfx, pyb, buttons

ugfx.init()
ugfx.clear()
ugfx.area(0,0,320,240,ugfx.html_color(0x00FF00))
buttons.init()
ugfx.set_default_font(ugfx.FONT_NAME)

t4 = pyb.Timer(4, freq=300, mode=pyb.Timer.CENTER)

SIGN_SCALING = 100
DOT = 1
DASH = 3
PAUSE_ELEMENT = DOT
PAUSE_CHARACTER = 3 * DOT - DOT
PAUSE_WORD = 7 * DOT - DOT

AF = True

def dot():
    if AF:
        ch1 = t4.channel(1, pyb.Timer.PWM, pin=pyb.Pin("BUZZ"), pulse_width=(t4.period() + 1) // 2)
    ugfx.area(100,75,90,90,ugfx.BLACK)
    pyb.delay(SIGN_SCALING*DOT)
    if AF:
예제 #53
0
    con.set_default_font(ugfx.FONT_TITLE)
    con.text(2, 50, "UNIVERSE 01", ugfx.YELLOW)

    if selectuniverse:
        con.box(0, 50, 320, 50)
    con.set_default_font(ugfx.FONT_SMALL)
    con.show()
    

print("starting")

buttons.init()
ugfx.init()
ugfx.clear(ugfx.BLACK)

"""
ugfx.set_default_font(ugfx.FONT_NAME)
ugfx.text(0, 5, "TINY-ARTNET", ugfx.GREEN)
ugfx.set_default_font(ugfx.FONT_TITLE)
ugfx.text(2, 50, "UNIVERSE 01", ugfx.YELLOW)
ugfx.set_default_font(ugfx.FONT_SMALL)
"""

textcontainer = ugfx.Container(0, 0, 320, 80)
container = ugfx.Container(0, 80,320,160)

drawtext(textcontainer)
wifi.connect()

tinyartnet()
예제 #54
0
    f=174.614
    d=146.832
    tone(d,bp,pp)
    tone(d,bp,pp)
    tone(d,bp,pp)
    tone(g,bp*4,pp)
    
    tone(d,bp,pp)
    tone(d,bp,pp)
    tone(d,bp,pp)
    tone(g,bp*4,pp)

	
			

ugfx.set_default_font(ugfx.FONT_TITLE)

ugfx.clear(ugfx.BLACK)
ugfx.text(80,40,"Adventure!",ugfx.WHITE)
ugfx.text(20,100,"Escape from the Castle!",ugfx.RED)
play_theme()
pyb.delay(2000)
room_1()
###start at this room


while True:
	playing=1

	while playing:
	
예제 #55
0
def refresh_score():
    ugfx.set_default_font(ugfx.FONT_SMALL)
    ugfx.text(10, 10, "%d" % score, ugfx.WHITE)
예제 #56
0
ugfx.set_default_style(s)

win_header = ugfx.Container(0,0,wi,33,style=s)
win_legend = ugfx.Container(0,hi-30,wi,30,style=s)


toplot = ['vbat','vunreg','light','rssi']
# scale  to fit on the y scale (range 0->150)
scale_m = [75,   75,   0.4,  1]
scale_c = [-255, -255, 0,    100]
colour =  [ugfx.RED, ugfx.ORANGE, ugfx.YELLOW, ugfx.BLUE]

buttons.disable_menu_reset()

ugfx.set_default_font(ugfx.FONT_TITLE)
title = ugfx.Label(3,3,wi-10,45,"Log Viewer",parent=win_header)
ugfx.set_default_font(ugfx.FONT_SMALL)
chk_upload = ugfx.Checkbox(190,3,130,20,"M: Enable uplink",parent=win_header)
chk_upload.attach_input(ugfx.BTN_MENU,0)
if database_get("stats_upload"):
	chk_upload.checked(1)

win_header.show()
win_legend.show()

ugfx.set_default_font(ugfx.FONT_MEDIUM)
ugfx.set_default_style(s)

graph = ugfx.Graph(0,33,wi,hi-33-33,3,3)
graph.appearance(ugfx.Graph.STYLE_POINT, ugfx.Graph.POINT_NONE, 0, 0)