Esempio n. 1
0
def __chk_recovery():
    try:
        try:
            recovery_button = buttons.BTN_START
        except:
            # This badge does not have a START button, use the B button instead
            recovery_button = buttons.BTN_B
        return machine.wake_reason() == (7,
                                         0) and buttons.value(recovery_button)
    except:
        return False
Esempio n. 2
0
__chk_recovery = False
fc_level = machine.nvs_getint("system", 'factory_checked') or 0
recovery_button = None

if fc_level >= 3:
    try:
        import buttons
        try:
            #Use the START button if available
            recovery_button = buttons.BTN_START
        except:
            #Else use the B button
            recovery_button = buttons.BTN_B
        __chk_recovery = machine.wake_reason() == (
            7, 0) and buttons.value(recovery_button)
    except:
        pass

#Application starting
if __chk_recovery:
    app = "dashboard.recovery"
else:
    app = rtc.read_string()
    if not app:
        if fc_level < 3:
            app = "factory_checks"
        else:
            app = machine.nvs_getstr("system", 'default_app')
            if not app:
                app = 'dashboard.home'
Esempio n. 3
0
rtc = machine.RTC()
rtc.write(0, 0)
rtc.write(1, 0)

device.prepareForWakeup()

__chk_recovery = False
__chk_develop = False

if machine.wake_reason() == (7, 0) and machine.nvs_getint(
        "system", 'factory_checked'):
    try:
        recovery_button = buttons.BTN_START  #Use the START button if available
    except:
        recovery_button = buttons.BTN_B  #Else use the B button
    __chk_recovery = buttons.value(recovery_button)
    __chk_develop = buttons.value(buttons.BTN_LEFT)

if __chk_recovery:
    app = "dashboard.recovery"
elif __chk_develop:
    app = "dev"
else:
    app = rtc.read_string()
    if not app:
        if not machine.nvs_getint("system", 'factory_checked') == 2:
            app = "factory_checks"
        else:
            app = machine.nvs_getstr("system", 'default_app')
            if not app:
                app = 'dashboard.home'
Esempio n. 4
0
# https://docs.badge.team/esp32-app-development/api-reference/buttons/

# button definitions: python_modules/lasertag/buttons.py

# Wichtig: das menuzeug scheint buttons bereits mit der buttons.py aus dem lasertag root dir zu initialisieren. danach kann ich mit meiner eigenen buttens.py machen was ich will, die reagieren nicht. loesung: buttons.py im root dir ersetzen.

print('Test: buttons\n')

import buttons  # in der konsole ist es definiert, hier muss es wohl gemacht werden!?

print('Initial state:')
print('A links:', buttons.value(buttons.BTN_A))
print('B mitte:', buttons.value(buttons.BTN_B))
print('C rechts:', buttons.value(buttons.BTN_C))
print('PEW:', buttons.value(buttons.BTN_PEW))

print('\nNow press buttons to test callback-functions:')


def a_btn_pressed(pushed):
    if (pushed):  # down
        print('A', pushed)
    else:  # up
        print('A', pushed)


buttons.attach(buttons.BTN_A, a_btn_pressed)
buttons.attach(buttons.BTN_B, lambda pressed: print('B', pressed))
buttons.attach(buttons.BTN_C, lambda pressed: print('C', pressed))
buttons.attach(buttons.BTN_PEW, lambda pressed: print('PEW', pressed))
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
Esempio n. 6
0
import machine, sys, system, time, buttons, samd

rtc = machine.RTC()
rtc.write(0,0)
rtc.write(1,0)

__chk_recovery = False

if machine.nvs_getint("system", 'factory_checked'):
	__chk_recovery = machine.wake_reason() == (7, 0) and buttons.value(buttons.BTN_OK)

samd.backlight(255)

#Application starting
if __chk_recovery:
	app = "dashboard.recovery"
else:
	app = rtc.read_string()
	if not app:
		if not machine.nvs_getint("system", 'factory_checked') == 2:
			app = "factory_checks"
		else:
			app = machine.nvs_getstr("system", 'default_app')
			if not app:
				app = 'dashboard.home'

if app and not app == "shell":
	try:
		print("Starting app '%s'..." % app)
		system.__current_app__ = app
		if app: