Ejemplo n.º 1
0
def ledThread():
    global spaces
    while 1:
        for i in range(len(spaces)):
            # Position
            xR, yR = spaces[i]["red"]
            xG, yG = spaces[i]["grn"]
            state = spaces[i]["state"]

            # Get LEDs
            R = display.getPixel(xR, yR) >> 16
            G = display.getPixel(xG, yG) >> 16

            red_brightness = 0x15
            if state == 3:
                red_brightness = 0x30

            tgtR = ((state == 1) or (state == 3)) * red_brightness
            tgtG = ((state == 2) or (state == 3)) * 0x10

            # Set LEDs
            if R < tgtR:
                R = R + 1
            elif R > tgtR:
                R = R - 1

            if G < tgtG:
                G = G + 1
            elif G > tgtG:
                G = G - 1

            display.drawPixel(xR, yR, color(R))
            display.drawPixel(xG, yG, color(G))
        display.flush()
        time.sleep_ms(5)
Ejemplo n.º 2
0
def draw():
    global counter

    if blinking:
        counter += 1

    for y in range(4):
        for x in range(4):
            color = settings['color_off']
            if pattern[x + y * 4] == 1:
                color = settings['color_on']

            elif pattern[x + y * 4] == 2:
                if counter % 2 == 0:
                    color = settings['color_off']
                else:
                    color = settings['color_on']

            elif pattern[x + y * 4] == 3:
                if counter % 2 == 0:
                    color = settings['color_on']
                else:
                    color = settings['color_off']

            display.drawPixel(x, y, color)
    display.flush()

    return interval
Ejemplo n.º 3
0
def draw():
    global counter

    for y in range(4):
        for x in range(4):
            color = color_off
            if pattern[x + y * 4] == 1:
                color = color_on

            elif pattern[x + y * 4] == 2:
                if counter % 2 == 0:
                    color = color_off
                else:
                    color = color_on

            elif pattern[x + y * 4] == 3:
                if counter % 2 == 0:
                    color = color_on
                else:
                    color = color_off

            display.drawPixel(x,y,color)
    display.flush()
    counter += 1
    return blink_interval
Ejemplo n.º 4
0
def draw(button, active, error=False):
	x = button %  4
	y = button // 4
	color = 0xFFFFFF
	if error:
		color = 0xFF0000
	display.drawPixel(x, y, color if active else 0x000000)
	display.flush()
def drawApps():
    display.drawFill(0x00)
    for index in range(0, 16):
        app = get_app(index)
        if app:
            x = index % 4
            y = int(index / 4)
            colour = int(app['colour'].replace("#", "0x"), 16)
            display.drawPixel(x, y, colour)
    display.flush()
Ejemplo n.º 6
0
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)
Ejemplo n.º 7
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)
Ejemplo n.º 8
0
def paintbuttons():
    global transitions, scenes, curtrans, curscene
    y = 0
    for x in range(0, len(transitions)):
        if curtrans == transitions[x]:
            display.drawPixel(x, y, 0x00FF00)
        else:
            display.drawPixel(x, y, 0xFF0000)
    for x in range(len(transitions), 4):
        display.drawPixel(x, y, 0x00000)
    for num in range(0, len(scenes)):
        x, y = num % 4, int(num / 4) + 1
        if curscene == scenes[num]:
            display.drawPixel(x, y, 0x0000FF)
        else:
            display.drawPixel(x, y, 0xFF8C00)
    display.flush()
Ejemplo n.º 9
0
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)
	dataPoints2.append(round(vusb*8))
	for i in range(64):
		display.drawPixel(64+i,display.height()-1-dataPoints2[i],0xFFFFFF)
		
	display.flush()
Ejemplo n.º 10
0
def animation_task():
    global animation_step, animation_type
    if animation_type == 0:
        if animation_step == 0:
            display.drawFill()
            drawEye(0, 0xFFFFFF)
            drawEye(7, 0xFFFFFF)
            display.flush()
            animation_step += 1
        elif animation_step < 10:
            animation_step += 1
        else:
            display.drawFill()
            drawEye(0, 0xFFFFFF)
            drawEyeClosed(7, 0xFFFFFF)
            display.flush()
            animation_step = 0
    elif animation_type == 1:
        display.drawFill(animation_step | (animation_step << 8)
                         | (animation_step << 16))
        animation_step += 1
        if animation_step > 0xFF:
            animation_step = 0
    elif animation_type == 2:
        if animation_step == 0:
            display.drawFill()
            drawEye(0, 0xFFFFFF)
            drawEye(7, 0xFFFFFF)
            display.flush()
            animation_step += 1
        elif animation_step < 10:
            animation_step += 1
        else:
            display.drawFill()
            drawEyeClosed(0, 0xFFFFFF)
            drawEyeClosed(7, 0xFFFFFF)
            display.flush()
            animation_step = 0
    elif animation_type == 3:
        for x in range(14):
            for y in range(5):
                color = x + (y * 14)
                display.drawPixel(x, y, color | (color << 8) | (color << 16))
    return 100
def blink(state):
    for i in range(len(leds)):
        red = leds[i]["red"]
        grn = leds[i]["grn"]
        if state == 0:
            display.drawPixel(red[0], red[1], 0x010101)
            display.drawPixel(grn[0], grn[1], 0x000000)
        else:
            display.drawPixel(red[0], red[1], 0x000000)
            display.drawPixel(grn[0], grn[1], 0x010101)
    display.flush()
Ejemplo n.º 12
0
    def draw_board(self):
        '''
        method that draws the actual board in the terminal
        '''
        state = ""

        print('\n' * 1)
        for row_no, row in enumerate(self._grid):
            for col_no, column in enumerate(row):
                #print ('debug: ',col_no, row_no)
                if (column.get_print_character()):
                    display.drawPixel(col_no, row_no, self._colour)
                    state += "1"
                else:
                    display.drawPixel(col_no, row_no, 0x000000)
                    state += "0"

                print(column.get_print_character(), end='')
            print()  # to create a new line pr. row.

        display.flush()  # write to framebuffer

        # Check state
        result = 0
        if (state == self._state):
            self._state_count = self._state_count + 1
            if (self._state_count > 3):
                result = 1
            if (state ==
                    "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
                ):
                result = 1
        else:
            self._state_count = 0

        # Save state for next iteration
        self._state = state

        return result
Ejemplo n.º 13
0
def animation_task():
    global animation_step, animation_type
    if animation_type == 0:
        if animation_step == 0:
            display.drawFill()
            drawEye(0, 0xFFFFFF)
            drawEye(7, 0xFFFFFF)
            display.flush()
            animation_step += 1
        elif animation_step < 10:
            animation_step += 1
        else:
            display.drawFill()
            drawEye(0, 0xFFFFFF)
            drawEyeClosed(7, 0xFFFFFF)
            display.flush()
            animation_step = 0
    elif animation_type == 1:
        x = animation_step
        y = 0
        while x > 13:
            x -= 13
            y += 1
        if y > 4:
            y = 0
            x = 0
            animation_step = 0
        display.drawFill(0)
        display.drawPixel(x, y, 0xFFFFFF)
        display.flush()
        animation_step += 1
    elif animation_type == 2:
        animation_step = 0
        for x in range(14):
            for y in range(5):
                color = x + (y * 14)
                display.drawPixel(x, y, color | (color << 8) | (color << 16))
        display.flush()
    return 100
Ejemplo n.º 14
0
def on_key(key_index, is_pressed):
    global pattern

    if is_pressed:
        x,y = keypad.index_to_coords(key_index)
        pattern[x + y * 4] = (pattern[x + y * 4] + 1) % 4
        if pattern[x + y * 4] == 0:
            display.drawPixel(x,y,0x400000)
        elif pattern[x + y * 4] == 1:
            display.drawPixel(x,y,0x004000)
        elif pattern[x + y * 4] == 2:
            display.drawPixel(x,y,0x004040)
        elif pattern[x + y * 4] == 3:
            display.drawPixel(x,y,0x404000)
        display.flush()
Ejemplo n.º 15
0
def on_key(key_index, is_pressed):
    global pattern

    if is_pressed:
        x, y = keypad.index_to_coords(key_index)
        pattern[x + y * 4] = (pattern[x + y * 4] + 1) % 4
        if pattern[x + y * 4] == 0:
            display.drawPixel(x, y, 0x400000)
            tone = 396
        elif pattern[x + y * 4] == 1:
            display.drawPixel(x, y, 0x004000)
            tone = 440
        elif pattern[x + y * 4] == 2:
            display.drawPixel(x, y, 0x004040)
            tone = 495
        elif pattern[x + y * 4] == 3:
            display.drawPixel(x, y, 0x404000)
            tone = 528
        display.flush()
        sndmixer.freq(synth, tone)
        sndmixer.play(synth)
        sndmixer.volume(synth, 64)
        virtualtimers.new(100, sound_off, False)
Ejemplo n.º 16
0
            if font == "5":
                font = "dejavusans20"
            print("Font", font)
        elif (message.startswith(b"C")):
            print("Clear")
            display.drawFill(bgColor)
            display.flush()
        elif (message.startswith(b"A")):
            print("Fill")
            display.drawFill(fgColor)
            display.flush()
        elif (message.startswith(b"P")):
            x = 0
            y = 0
            for i in range(len(message) - 1):
                for j in range(8):
                    if message[1 + i] & (1 << (7 - j)):
                        display.drawPixel(x, y, fgColor)
                    else:
                        display.drawPixel(x, y, bgColor)
                    x += 1
                    if x >= display.width():
                        x = 0
                        y += 1
            display.flush()
        else:
            print("unknown", message)

    except BaseException as e:
        print("Error", e)
Ejemplo n.º 17
0
    def on_right(p):
        global page
        page = 1

    r = 0xa10000
    g = 0x23a100
    b = 0x0010a1

    clear()
    load_settings()

    tcp = CZ20_TCP_Client()
    tcp.connect(settings["server_ip"], settings["server_port"])

    dp.drawPixel(0, 0, r)
    dp.drawPixel(1, 0, r)
    dp.drawPixel(2, 0, r)
    dp.drawPixel(0, 1, g)
    dp.drawPixel(1, 1, g)
    dp.drawPixel(2, 1, g)
    dp.drawPixel(0, 2, b)
    dp.drawPixel(1, 2, b)
    dp.drawPixel(2, 2, b)
    dp.drawPixel(3, 3, 0xBB004B)
    dp.drawPixel(0, 3, 0xE3A300)
    dp.flush()

    keypad.add_handler(on_key)

    touchpads.on(touchpads.LEFT, on_left)
Ejemplo n.º 18
0
def drawEye(offset, color):
    display.drawPixel(3 + offset, 0, color)
    display.drawPixel(2 + offset, 1, color)
    display.drawPixel(4 + offset, 1, color)
    display.drawPixel(2 + offset, 2, color)
    display.drawPixel(4 + offset, 2, color)
    display.drawPixel(2 + offset, 3, color)
    display.drawPixel(4 + offset, 3, color)
    display.drawPixel(3 + offset, 4, color)
Ejemplo n.º 19
0
def drawEyeClosed(offset, color):
    display.drawPixel(2 + offset, 2, color)
    display.drawPixel(3 + offset, 2, color)
    display.drawPixel(4 + offset, 2, color)
Ejemplo n.º 20
0
import machine

machine.nvs_setint('system', 'splash_played', 1)

try:
    import display, audio, keypad, time, system

    audio.play('/cache/boot/splash.mp3')
    sleeptime = 0.25

    for _ in range(2):
        for i in range(7, 3, -1):
            display.drawFill(0x00)
            x, y = keypad.index_to_coords(i)
            display.drawPixel(x, y, 0x707070)
            x, y = keypad.index_to_coords(15 - i)
            display.drawPixel(x, y, 0x707070)
            display.flush()
            time.sleep(sleeptime)

        for i in range(0, 4):
            display.drawFill(0x00)
            x, y = keypad.index_to_coords(i)
            display.drawPixel(x, y, 0x707070)
            x, y = keypad.index_to_coords(15 - i)
            display.drawPixel(x, y, 0x707070)
            display.flush()
            time.sleep(sleeptime)

    for i in range(4):
        display.drawFill(0x00)
Ejemplo n.º 21
0
pattern = [0, 1, 1, 0, 1, 2, 2, 1, 1, 2, 2, 1, 0, 1, 1, 0]
counter = 0

color_on = 0x808080
color_off = 0x000000

while True:
    for y in range(4):
        for x in range(4):
            color = color_off
            if pattern[x + y * 4] == 1:
                color = color_on

            elif pattern[x + y * 4] == 2:
                if counter % 2 == 0:
                    color = color_off
                else:
                    color = color_on

            elif pattern[x + y * 4] == 3:
                if counter % 2 == 0:
                    color = color_on
                else:
                    color = color_off

            display.drawPixel(x, y, color)
    display.flush()
    counter += 1
    time.sleep(1)
Ejemplo n.º 22
0
                elif msg['update-type'] == 'PreviewSceneChanged':
                    pass
                elif msg['update-type'] == 'SwitchScenes':
                    curscene = msg['scene-name']
                    paintbuttons()
                elif msg['update-type'] == 'SwitchTransition':
                    curtrans = msg['transition-name']
                    paintbuttons()
                elif msg['update-type'] == 'TransitionListChanged':
                    gettransitions()
                    paintbuttons()
            print(msg)
        except OSError:
            pass
        if blink:
            blink += 1
            if blink == 2:
                scenenum = scenes.index(toscene)
                x, y = scenenum % 4, int(scenenum / 4)
                display.drawPixel(x, y + 1, 0x0000FF)
                display.flush()
            elif blink == 4:
                scenenum = scenes.index(toscene)
                x, y = scenenum % 4, int(scenenum / 4)
                display.drawPixel(x, y + 1, 0xFF8C00)
                display.flush()
            elif blink == 6:
                blink = 1

print("Error")
Ejemplo n.º 23
0
def pixel(x,y,color):
	display.drawPixel(x,y,color)