Example #1
0
def _inputAttach(button, realCallback, thisList=None):
    global _internalListUpCallback, _internalListDownCallback, activeList
    activeList = thisList
    if button == JOY_UP:
        _internalListUpCallback = realCallback
        buttons.attach(JOY_UP, _internalGlobalUpCallback)
    if button == JOY_DOWN:
        _internalListDownCallback = realCallback
        buttons.attach(JOY_DOWN, _internalGlobalDownCallback)
Example #2
0
def _inputAttach(button, realCallback,thisList=None):
	global _internalListUpCallback, _internalListDownCallback, activeList
	activeList = thisList
	if button == BTN_B:
		_internalListUpCallback = realCallback
		buttons.attach(BTN_B, _internalGlobalUpCallback)
	if button == BTN_C:
		_internalListDownCallback = realCallback
		buttons.attach(BTN_C, _internalGlobalDownCallback)
Example #3
0
def input_attach(button, callback=None):
	global activeList, listUpCallback, listDownCallback
	if button < 0 or button > 7:
		return
	doAttach = True
	if button == BTN_B:
		listUpCallback = callback
		if activeList:
			doAttach = False
	elif button == BTN_C:
		listDownCallback = callback
		if activeList:
			doAttach = False
	if doAttach:
		buttons.attach(button, callback)
Example #4
0
def skippabletext(text, color=(255, 255, 255), pos=None, width=-1):

    buttons.attach(buttons.BTN_A, _abort_scroll)
    buttons.attach(buttons.BTN_B, _abort_scroll)

    display.drawText(0, 0, text)

    delay_loop = 50
    global abort
    abort = False

    while (not abort) and (delay_loop >= 0):
        time.sleep(0.1)
        delay_loop -= 1

    buttons.clear_button_mapping()
Example #5
0
def main():
    buttons.attach(buttons.BTN_A, action_exit)
    buttons.attach(buttons.BTN_B, action_exit)
    try:
        buttons.attach(buttons.BTN_START, action_exit)
    except:
        pass
    show_names()
    sys.stdin.read(1)  #Wait for any key
    action_exit(True)
Example #6
0
# 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))

# buttons.pushMapping()  # alle mappings loeschen
def show(newTitle, initialText, cbAccept, cbCancel=None):
    global cx, cy, text, originalText, title, cursorPos, _cbAccept, _cbCancel, mode, active, __drawChanged
    if not active:
        active = True
        mode = 0
        title = newTitle
        display.drawFill(0xFFFFFF)
        cx = 0
        cy = 0
        text = initialText
        originalText = initialText
        _cbAccept = cbAccept
        _cbCancel = cbCancel
        __drawChanged = True
        cursorPos = len(text)
        buttons.pushMapping()
        buttons.attach(buttons.BTN_A, __onA)
        buttons.attach(buttons.BTN_B, __onB)
        buttons.attach(buttons.BTN_SELECT, __onSelect)
        buttons.attach(buttons.BTN_START, __onStart)
        buttons.attach(buttons.BTN_DOWN, __onDown)
        buttons.attach(buttons.BTN_RIGHT, __onRight)
        buttons.attach(buttons.BTN_UP, __onUp)
        buttons.attach(buttons.BTN_LEFT, __onLeft)
        buttons.attach(buttons.KEY_BACKSPACE, __onBackspace)
        buttons.attach(buttons.KEY_SHIFT, __onShift)
        buttons.attach(buttons.KEY_SHIELD, __onShield)
        buttons.attach(buttons.KEY_FN, __onFn)
        buttons.attach(buttons.KEY_ANY, __onInput)
        draw()
        _thread.start_new_thread("threadDraw", __drawThread, ())
Example #8
0
def main():
    buttons.attach(buttons.BTN_HOME, action_exit)
    buttons.attach(buttons.BTN_MENU, action_exit)

    show_names()
Example #9
0
def _confirmation_dialog_register_callbacks():
    buttons.attach(buttons.BTN_A, _confirmation_dialog_yes_callback)
    buttons.attach(buttons.BTN_B, _confirmation_dialog_no_callback)
import machine, time, display, buttons, system


def home(pressed):
    if pressed:
        system.home()


buttons.attach(buttons.BTN_A, home)
buttons.attach(buttons.BTN_B, home)

display.orientation(90)
display.drawFill(0x000000)
display.flush()
display.backlight(255)

gpios = [2, 12, 15, 13, 32, 33, 27]
names = ["U", "D", "L", "R", "A", "B", "C"]

thist = []
touch = []
for i in gpios:
    touch.append(machine.TouchPad(machine.Pin(i)))
    thist.append([0] * 5)

while 1:
    line = 0
    display.drawFill(0x000000)
    display.drawRect(0, 0, display.width() - 1, 20, True, 0xFFFF00)
    display.drawText(0, 0, "TOUCH DEMO", 0x000000, "ocra16")
    for i in touch:
Example #11
0
    global animation_type
    if pressed:
        animation_type = 1
    elif animation_type == 1:
        animation_type = 0


def btnB(pressed):
    global animation_type
    if pressed:
        animation_type = 2
    elif animation_type == 2:
        animation_type = 0


def btnC(pressed):
    global animation_type
    if pressed:
        animation_type = 3
    elif animation_type == 3:
        animation_type = 0


buttons.attach(buttons.BTN_0, btnB)
buttons.attach(buttons.BTN_1, btnA)
buttons.attach(buttons.BTN_BOOT, btnC)

song = "20thCenFox:d=16,o=5,b=140:b,8p,b,b,2b,p,c6,32p,b,32p,c6,32p,b,32p,c6,32p,b,8p,b,b,b,32p,b,32p,b,32p,b,32p,b,32p,b,32p,b,32p,g#,32p,a,32p,b,8p,b,b,2b,4p,8e,8g#,8b,1c#6,8f#,8a,8c#6,1e6,8a,8c#6,8e6,1e6,8b,8g#,8a,2b"

buzzer.play(song)
Example #12
0
def onB(pressed):
	if pressed:
		display.drawFill(0x000000)
		drawMessageBox("Starting launcher...")
		display.flush()
		system.launcher()

# Launcher
orientation.landscape()
display.drawFill(0x000000)
drawMessageBox("Loading...")
display.flush()
term.header(True, "Loading...")

buttons.attach(buttons.BTN_LEFT,  onLeft)
buttons.attach(buttons.BTN_RIGHT, onRight)
buttons.attach(buttons.BTN_A,     onA)
try:
	buttons.attach(buttons.BTN_START, onB)
except:
	pass
buttons.attach(buttons.BTN_B,     onB)

def showMenu():
	global currentApp, apps
	apps = listApps()
	currentApp = 0
	if len(apps)>0:
		drawApp(apps[0],0,len(apps))
	else:
Example #13
0
            display.flush()
            # prompt is a blocking call, waits here for the message
            message = term.prompt("message:", 0, 1)
            if len(message) > 0:
                self.client.publish(topic, message)
                self.client.send_queue()
                print("\nmessage sent")
                display.drawText(0, 16, "message sent", 0xFFFFFF, "7x5")
            # wait and clear
            utime.sleep_ms(500)
            self.clear()

    def main(self):
        """The main refresh loop for microham."""
        while True:
            utime.sleep_ms(500)
            if self.client.is_conn_issue():
                self.client.reconnect()
            self.client.check_msg()
            self.client.send_queue()

        # end
        self.client.disconnect()


m = microham()
buttons.attach(buttons.BTN_A, m.send_message)
buttons.attach(buttons.BTN_UP, m.channel_up)
buttons.attach(buttons.BTN_DOWN, m.channel_down)
m.main()
Example #14
0
    'splash', 'ledApp'
)  # Application which shows a LED animation while the splash screen is visible


# Button callbacks
def cbStartLauncher(pressed):
    if pressed:
        system.launcher(True)


def cbFeedPowerManagement(pressed):
    pm.feed()
    #pass


buttons.attach(buttons.BTN_OK, cbStartLauncher)
buttons.attach(buttons.BTN_BACK, cbFeedPowerManagement)
buttons.attach(buttons.BTN_DOWN, cbFeedPowerManagement)
buttons.attach(buttons.BTN_RIGHT, cbFeedPowerManagement)
buttons.attach(buttons.BTN_UP, cbFeedPowerManagement)
buttons.attach(buttons.BTN_LEFT, cbFeedPowerManagement)

# Scheduler
virtualtimers.activate(25)


# Power management
def cbSleep(idleTime=None):
    if idleTime == None:
        idleTime = virtualtimers.idle_time()
    gui_redraw = True
dataPoints2 = [0] * 64

ledState = False


def toggleLeds(pressed):
    global ledState
    if pressed:
        ledState = not ledState
        if ledState:
            neopixel.send(bytes([0xFF, 0xFF, 0xFF] * 12))
        else:
            neopixel.send(bytes([0, 0, 0] * 12))


buttons.attach(buttons.BTN_A, toggleLeds)


def draw(vbatt, vusb):
    display.drawFill(0x000000)
    display.drawText(0, 0, "Battery")
    display.drawText(0, 15, "USB")
    display.drawText(50, 0, str(vbatt) + "v")
    display.drawText(50, 15, str(vusb) + "v")

    dataPoints.pop(0)
    dataPoints.append(round(vbatt * 8))
    for i in range(64):
        display.drawPixel(i, display.height() - 1 - dataPoints[i], 0xFFFFFF)

    dataPoints2.pop(0)
        _ = _thread.start_new_thread("DEMO", demoThread, ())
    else:
        demoThreadRunning = False

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


display.orientation(90)
buttons.attach(buttons.BTN_A, onButtonA)
buttons.attach(buttons.BTN_B, onButtonB)
drawNickname()

# Demo :-)

def demoThread():
    global demoThreadRunning
    counter = 0
    fpsTrig = False
    
    w, h, _, _ = display.pngInfo(mascot.snek)
    
    display.drawFill(0xFFFF00)
    
    prev = time.ticks_ms()
Example #17
0
    server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    server_socket.bind(("", PORT))
    server_socket.listen(1)

    return ip, server_socket


def send_client(client_socket, button, push):
    "Send an encoded state to the client."
    client_socket.send(bytes([encode_action(button, push)]))


def display_connection(ip):
    "Prints connection details on the display."
    display.drawFill(0x000000)
    display.drawText(5, 5, "{}:{}".format(ip, PORT), 0xFFFFFF)
    display.flush()


ip, server_socket = create_server()
display_connection(ip)

while True:
    client_socket, _ = server_socket.accept()

    for button, code in BUTTONS.items():
        buttons.detach(button)
        buttons.attach(
            button, lambda push, button=button: send_client(client_socket, button, push)
        )
                message += "Available          : "+info["name"]+" (Build "+str(info["build"])+")"
            else:
                easydraw.messageCentered("Your badge is up-to-date!\n\nPress A to start update\nPress B to cancel", False)
                title = "Up-to-date"
                message = "You are up-to-date.\n"
                message += "Currently installed: "+version.name+" (Build "+str(version.build)+")\n"
                message += "Available          : "+info["name"]+" (Build "+str(info["build"])+")"
    else:
        easydraw.messageCentered("Unable to check for states\n\nPress A to start update\nPress B to cancel", False)
        title = "Update check"
        message = "An error occured while fetching information. You can still choose to start the OTA procedure."

def start(pressed):
    if pressed:
        system.ota()
        
def cancel(pressed):
    if pressed:
        system.launcher()

buttons.attach(buttons.BTN_A, start)
try:
    buttons.attach(buttons.BTN_START, cancel)
except:
    pass
buttons.attach(buttons.BTN_B, cancel)

items = ["Cancel", "Start OTA update"]
callbacks = [system.home, system.ota]
callbacks[term.menu(title, items, 0, message)](True)
Example #19
0
def show(new_TITLE, initial_TEXT, cbAccept, cbCancel=None):
    '''
	Show a _TEXT input dialog to the user
	:param _TITLE: _TITLE of the dialog
	:param _TEXT: Intial value (can be "")
	:param cbAccept: Callback executed when the user accepts
	:param cbCancel: (optional) Callback executed when the user cancels
	'''
    global _TEXT, _TEXT_ORIG, _TITLE, _CURSOR_X, _CURSOR_Y, _CB_ACCEPT, _CB_CANCEL, _MODE, _LASTPARTMOVEUP
    _MODE = 0
    _TITLE = new_TITLE
    _display.drawFill(0xFFFFFF)
    _TEXT = initial_TEXT
    _TEXT_ORIG = initial_TEXT
    _CB_ACCEPT = cbAccept
    _CB_CANCEL = cbCancel
    _CURSOR_Y = len(_TEXT.split("\n")) - 1
    _CURSOR_X = len(_TEXT.split("\n")[-1]) + 1
    _LASTPARTMOVEUP = True
    _VISIBLELINE = 0
    _buttons.pushMapping()
    _buttons.attach(_buttons.BTN_A, _onA)
    _buttons.attach(_buttons.BTN_B, _onB)
    _buttons.attach(_buttons.BTN_DOWN, _onDown)
    _buttons.attach(_buttons.BTN_RIGHT, _onRight)
    _buttons.attach(_buttons.BTN_UP, _onUp)
    _buttons.attach(_buttons.BTN_LEFT, _onLeft)
    _buttons.attach(_buttons.BTN_SELECT, _onSelect)
    _draw()
Example #20
0
			neopixel.send(bytes([0x00]*3*12))
		else:
			pm.disable()
			neopixel.send(bytes([0xFF]*3*12))

		if led_app:
			try:
				if flashlightStatus:
					led_app.resume()
				else:
					led_app.pause()
			except:
				pass
		flashlightStatus = not flashlightStatus
try:
	buttons.attach(buttons.BTN_A,      cbFeedPowerManagement)
except:
	pass
try:
	buttons.attach(buttons.BTN_B,      cbFeedPowerManagement)
except:
	pass
try:
	buttons.attach(buttons.BTN_DOWN,   cbFeedPowerManagement)
except:
	pass
try:
	buttons.attach(buttons.BTN_RIGHT,  cbFeedPowerManagement)
except:
	pass
try:
Example #21
0
def _menu_register_callbacks():
    buttons.attach(buttons.BTN_A, _menu_select_callback)
    buttons.attach(buttons.BTN_B, _menu_back_callback)
    buttons.attach(buttons.BTN_UP, _menu_up_callback)
    buttons.attach(buttons.BTN_DOWN, _menu_down_callback)
    buttons.attach(buttons.BTN_LEFT, _menu_left_callback)
    buttons.attach(buttons.BTN_RIGHT, _menu_right_callback)
Example #22
0
def show(newTitle, initialText, cbAccept, cbCancel=None):
    global cx, cy, text, originalText, title, cursorPos, _cbAccept, _cbCancel, mode
    mode = 0
    title = newTitle
    display.drawFill(0xFFFFFF)
    cx = 0
    cy = 0
    text = initialText
    originalText = initialText
    _cbAccept = cbAccept
    _cbCancel = cbCancel
    cursorPos = len(text)
    buttons.pushMapping()
    buttons.attach(buttons.BTN_A, onA)
    buttons.attach(buttons.BTN_B, onB)
    buttons.attach(buttons.BTN_SELECT, onSelect)
    buttons.attach(buttons.BTN_START, onStart)
    buttons.attach(buttons.BTN_DOWN, onDown)
    buttons.attach(buttons.BTN_RIGHT, onRight)
    buttons.attach(buttons.BTN_UP, onUp)
    buttons.attach(buttons.BTN_LEFT, onLeft)
    draw()
Example #23
0
def _text_input_register_callbacks():
    buttons.attach(buttons.BTN_A, _text_input_confirm_callback)
    buttons.attach(buttons.BTN_B, _text_input_cancel_callback)
    buttons.attach(buttons.BTN_UP, _text_input_up_callback)
    buttons.attach(buttons.BTN_DOWN, _text_input_down_callback)
    buttons.attach(buttons.BTN_LEFT, _text_input_left_callback)
    buttons.attach(buttons.BTN_RIGHT, _text_input_right_callback)
Example #24
0
                            green = 0xff if i == (11 - minutes) else 0x00
                            blue = 0xff if i == (11 - seconds) else 0x00
                            red = 0xff if i == (11 - hours) else 0x00
                            ledData[3 * i] = green >> self.dimmer
                            ledData[3 * i + 1] = red >> self.dimmer
                            ledData[3 * i + 2] = blue >> self.dimmer
                    neopixel.send(bytes(ledData))
                    ledState = ledState + 1
                    if ledState > 254:
                        ledState = 0
                    time.sleep_ms(20)

    def light_intensity_up(self, pressed):
        if pressed:
            self.dimmer = max(0, self.dimmer - 1)
            display_connected(["Dimmer: %d (lf,rt)" % self.dimmer])

    def light_intensity_down(self, pressed):
        if pressed:
            self.dimmer = min(7, self.dimmer + 1)
            display_connected(["Dimmer: %d (lf,rt)" % self.dimmer])


a = clock()
buttons.attach(buttons.BTN_LEFT, a.light_intensity_down)
buttons.attach(buttons.BTN_RIGHT, a.light_intensity_up)
buttons.attach(buttons.BTN_UP, reconnect)
buttons.attach(buttons.BTN_DOWN, a.sync_ntp)

a.ledProc()
Example #25
0
                "name"] + " (Build " + str(info["build"]) + ")"
        else:
            easydraw.messageCentered(
                "Up-to-date!\n(" + info["name"] +
                ")\n\nPress OK to update\nPress BACK to cancel", False)
            title = "Up-to-date"
            message = "You are up-to-date.\n"
            message += "Currently installed: " + version.name + " (Build " + str(
                version.build) + ")\n"
            message += "Available          : " + info[
                "name"] + " (Build " + str(info["build"]) + ")"
    else:
        easydraw.messageCentered(
            "Unknown status!\n\n\nPress OK to update\nPress BACK to cancel",
            False)
        title = "Update check"
        message = "An error occured while fetching information. You can still choose to start the OTA procedure."
else:
    easydraw.messageCentered(
        "No WiFi available!\n\n\nPress OK to update\nPress BACK to cancel",
        False)
    title = "Update check"
    message = "Could not connect to the WiFi network. You can still choose to start the OTA procedure."

buttons.attach(buttons.BTN_OK, start)
buttons.attach(buttons.BTN_BACK, cancel)

items = ["Cancel", "Start OTA update"]
callbacks = [system.home, system.ota]
callbacks[term.menu(title, items, 0, message)](True)