def displayUpdate():

    global cpu_temp
    global cpu_load

    image_1 = bt81x.Bitmap(
        1, 0, (bt81x.ARGB4, RLOGO_W * 2),
        (bt81x.BILINEAR, bt81x.BORDER, bt81x.BORDER, RLOGO_W, RLOGO_H))
    bt81x.dl_start()
    bt81x.load_image(0, 0, 'rlogo.png')
    bt81x.clear(1, 1, 1)
    bt81x.set_background(255, 255, 255)
    image_1.prepare_draw()
    image_1.draw((248, 35), vertex_fmt=0)
    txt_temp = bt81x.Text(
        500,
        260,
        31,
        bt81x.OPT_RIGHTX | bt81x.OPT_CENTERY,
        "Temperature : %2.1f" % cpu_temp,
    )
    txt_load = bt81x.Text(
        500,
        320,
        31,
        bt81x.OPT_RIGHTX | bt81x.OPT_CENTERY,
        "Load : %2.1f" % cpu_load,
    )
    bt81x.add_text(txt_temp)
    bt81x.add_text(txt_load)
    bt81x.display()
    bt81x.swap_and_empty()
def showSpinner(msg):

    # start
    bt81x.dl_start()
    bt81x.clear(1, 1, 1)

    # text
    txt = bt81x.Text(
        400,
        350,
        30,
        bt81x.OPT_CENTERX | bt81x.OPT_CENTERY,
        msg,
    )
    bt81x.add_text(txt)

    # spinner
    bt81x.spinner(400, 240, bt81x.SPINNER_CIRCLE, 0)

    # display
    bt81x.display()
    bt81x.swap_and_empty()

    # wait a second - just to improve UI experience ;)
    sleep(1000)
def showAuthScreen():

    # start
    bt81x.dl_start()
    bt81x.clear(1, 1, 1)

    # image
    image = bt81x.Bitmap(
        1, 0, (bt81x.ARGB4, 420 * 2),
        (bt81x.BILINEAR, bt81x.BORDER, bt81x.BORDER, 420, 480))
    image.prepare_draw()
    image.draw((0, 0), vertex_fmt=0)

    # text
    txt = bt81x.Text(
        590,
        220,
        28,
        bt81x.OPT_CENTERX | bt81x.OPT_CENTERY,
        "Press the push-link button of the Hue",
    )
    bt81x.add_text(txt)
    txt.text = "bridge you want to connect to"
    txt.x = 590
    txt.y = 260
    bt81x.add_text(txt)

    # display
    bt81x.display()
    bt81x.swap_and_empty()
def displaySpinner(operation, info):
    bt81x.dl_start()
    bt81x.clear(1, 1, 1)
    txt_oper = bt81x.Text(
        400,
        260,
        24,
        bt81x.OPT_CENTERX | bt81x.OPT_CENTERY,
        operation,
    )
    txt_info = bt81x.Text(
        400,
        300,
        24,
        bt81x.OPT_CENTERX | bt81x.OPT_CENTERY,
        info,
    )
    bt81x.add_text(txt_oper)
    bt81x.add_text(txt_info)
    bt81x.spinner(400, 160, bt81x.SPINNER_LINE, 0)
    bt81x.display()
    bt81x.swap_and_empty()
def showMessage(text):

    # start
    bt81x.dl_start()
    bt81x.clear(1, 1, 1)

    #text
    txt = bt81x.Text(
        400,
        240,
        31,
        bt81x.OPT_CENTERX | bt81x.OPT_CENTERY,
        text,
    )
    bt81x.add_text(txt)

    # display
    bt81x.display()
    bt81x.swap_and_empty()
def pinScreen(pin):

    pin_masked = "****"
    pin_length = len(pin)

    # start
    bt81x.dl_start()
    bt81x.clear(1, 1, 1)

    #text
    #drawing instructions
    txt = bt81x.Text(
        200,
        150,
        31,
        bt81x.OPT_CENTERX | bt81x.OPT_CENTERY,
        "Enter Pin:",
    )
    bt81x.add_text(txt)

    #drawing user pin
    txt.text = pin_masked[:pin_length]
    txt.x = 200
    txt.y = 200
    txt.font = 31
    bt81x.add_text(txt)

    # keys
    bt81x.track(430, 50, 350, 70, 0)
    bt81x.add_keys(430, 50, 350, 70, 30, 0, "123")
    bt81x.add_keys(430, 130, 350, 70, 30, 0, "456")
    bt81x.add_keys(430, 210, 350, 70, 30, 0, "789")
    bt81x.add_keys(430, 290, 350, 70, 30, 0, ".0C")

    # connect button
    btn = bt81x.Button(430, 370, 350, 70, 30, 0, "Connect")
    bt81x.tag(1)
    bt81x.add_button(btn)

    # display
    bt81x.display()
    bt81x.swap_and_empty()
def showAddrScreen(ip):

    # start
    bt81x.dl_start()
    bt81x.clear(1, 1, 1)

    # image
    image = bt81x.Bitmap(
        1, 0, (bt81x.ARGB4, 200 * 2),
        (bt81x.BILINEAR, bt81x.BORDER, bt81x.BORDER, 200, 200))
    image.prepare_draw()
    image.draw((0, 255), vertex_fmt=0)

    # text
    txt = bt81x.Text(
        225,
        120,
        29,
        bt81x.OPT_CENTERX | bt81x.OPT_CENTERY,
        "Enter IP address of HUE Bridge:",
    )
    bt81x.add_text(txt)
    txt.text = ip
    txt.x = 225
    txt.y = 195
    txt.font = 31
    bt81x.add_text(txt)

    # keys
    bt81x.track(450, 350, 280, 60, 0)
    bt81x.add_keys(450, 70, 280, 60, 30, 0, "123")
    bt81x.add_keys(450, 140, 280, 60, 30, 0, "456")
    bt81x.add_keys(450, 210, 280, 60, 30, 0, "789")
    bt81x.add_keys(450, 280, 280, 60, 30, 0, ".0C")

    # connect button
    btn = bt81x.Button(450, 350, 280, 60, 30, 0, "Connect")
    bt81x.tag(1)
    bt81x.add_button(btn)

    bt81x.display()
    bt81x.swap_and_empty()
Beispiel #8
0
widget_choice_evt = threading.Event()
widget_selection_keys = "123456789"
widget_selection_keys = widget_selection_keys[:len(widgets)]


def widget_choice_cbk(_widget_choice, _):
    global widget_choice
    widget_choice = _widget_choice - __ORD('0')
    widget_choice_evt.set()


palette_default = bt81x.Palette((0xff, 0xff, 0xff),
                                foreground=(0x3c, 0x82, 0x82))
txt = bt81x.Text(0,
                 0,
                 31,
                 bt81x.OPT_CENTERX | bt81x.OPT_CENTERY,
                 "",
                 palette=palette_default)

streams.serial()  # open serial channel to display debug messages

print('> Init chip')
bt81x.init(SPI0, D4, D33, D34)
bt81x.touch_loop(
    ((-1, widget_choice_cbk),
     ))  # listen to touch events and make widget_choice_cbk process them


def widget_selection():
    bt81x.dl_start()
    bt81x.clear(1, 1, 1)
def showMainMenu(saturation, hue, brightness):

    # start
    bt81x.dl_start()
    bt81x.clear(1, 1, 1)

    # image
    image = bt81x.Bitmap(1, 0, (bt81x.ARGB4, 800 * 2),
                         (bt81x.BILINEAR, bt81x.BORDER, bt81x.BORDER, 800, 50))
    image.prepare_draw()
    image.draw((0, 0), vertex_fmt=0)

    # buttons
    btn = bt81x.Button(0, 0, 170, 70, 31, 0, "")
    for button in buttons:
        btn.text = button["text"]
        btn.font = button["size"]
        btn.x = button["x_cord"]
        btn.y = button["y_cord"]
        btn.width = button["width"]
        btn.height = button["height"]
        bt81x.track(btn.x, btn.y, button["width"], button["height"],
                    button["tag_id"])
        bt81x.tag(button["tag_id"])
        bt81x.add_button(btn)

    # text labels
    txt = bt81x.Text(0, 0, 0, 30, "")
    for label in labels:
        txt.text = label["text"]
        txt.x = label["x_cord"]
        txt.y = label["y_cord"]
        txt.font = label["size"]
        txt.options = label["options"]
        bt81x.add_text(txt)

    # saturation value label
    txt.text = str(int((saturation / 240) * 100)) + '%'
    txt.x = 622
    txt.y = 175
    txt.font = 30
    txt.options = bt81x.OPT_CENTER
    bt81x.add_text(txt)

    # hue value label
    txt.text = str(int((hue / 65500) * 100)) + '%'
    txt.x = 622
    txt.y = 275
    txt.font = 30
    txt.options = bt81x.OPT_CENTER
    bt81x.add_text(txt)

    # brightness value label
    txt.text = str(int((brightness / 240) * 100)) + '%'
    txt.x = 622
    txt.y = 375
    txt.font = 30
    txt.options = bt81x.OPT_CENTER
    bt81x.add_text(txt)

    # display
    bt81x.display()
    bt81x.swap_and_empty()