Ejemplo n.º 1
0
def battery(vUsb, vBatt, charging):
    vMin = badge.nvs_get_u16('batt', 'vmin', 3500)  # mV
    vMax = badge.nvs_get_u16('batt', 'vmax', 4100)  # mV
    if charging and vUsb > 4000:
        try:
            badge.eink_png(0, 0, '/lib/resources/chrg.png')
        except:
            ugfx.string(0, 0, "CHRG", 'Roboto_Regular12', ugfx.BLACK)
    elif vUsb > 4000:
        try:
            badge.eink_png(0, 0, '/lib/resources/usb.png')
        except:
            ugfx.string(0, 0, "USB", 'Roboto_Regular12', ugfx.BLACK)
    else:
        width = round((vBatt - vMin) / (vMax - vMin) * 44)
        if width < 0:
            width = 0
        elif width > 38:
            width = 38
        ugfx.box(2, 2, 46, 18, ugfx.BLACK)
        ugfx.box(48, 7, 2, 8, ugfx.BLACK)
        ugfx.area(3, 3, width, 16, ugfx.BLACK)
Ejemplo n.º 2
0
import ugfx
import time

ugfx.init()

ugfx.clear(ugfx.BLACK)

ugfx.fill_circle(60, 60, 50, ugfx.WHITE)
ugfx.fill_circle(60, 60, 40, ugfx.BLACK)
ugfx.fill_circle(60, 60, 30, ugfx.WHITE)
ugfx.fill_circle(60, 60, 20, ugfx.BLACK)
ugfx.fill_circle(60, 60, 10, ugfx.WHITE)

ugfx.thickline(1, 1, 100, 100, ugfx.WHITE, 10, 5)
ugfx.box(30, 30, 50, 50, ugfx.WHITE)

ugfx.string(150, 25, "STILL", "Roboto_BlackItalic24", ugfx.WHITE)
ugfx.string(130, 50, "Hacking", "PermanentMarker22", ugfx.WHITE)
len = ugfx.get_string_width("Hacking", "PermanentMarker22")
ugfx.line(130, 72, 144 + len, 72, ugfx.WHITE)
ugfx.line(140 + len, 52, 140 + len, 70, ugfx.WHITE)
ugfx.string(140, 75, "Anyway", "Roboto_BlackItalic24", ugfx.WHITE)

ugfx.flush()


def render(text, pushed):
    if (pushed):
        ugfx.string(100, 10, text, "PermanentMarker22", ugfx.WHITE)
    else:
        ugfx.string(100, 10, text, "PermanentMarker22", ugfx.BLACK)
Ejemplo n.º 3
0
### Author: Lars Weiler
### Description: progress bar
### Category: fun
### License: THE NERD-WARE LICENSE (Revision 2)
### Appname: progressbar

import pyb
import ugfx

ugfx.init()
h = ugfx.height()
w = ugfx.width()

ugfx.clear(ugfx.BLACK)

lw = 240    # progress bar width
lh = 40     # progress bar height
m = 5       # margin
s = 1       # step

ugfx.box((w//2)-(lw//2), (h//2)-(lh//2), lw, lh, ugfx.WHITE)
for i in range(m, lw-2*m, s):
    # use the 30bit random number, bitshift by 24 bits, which will give 0-65
    # and use this number for the delay in milliseconds
    pyb.delay(pyb.rng()>>24)
    ugfx.area((w//2)-(lw//2-m), (h//2)-(lh//2-m), i, (lh-2*m), ugfx.WHITE)
# wait 500ms and blank the screen
pyb.delay(500)
ugfx.clear(ugfx.BLACK)

Ejemplo n.º 4
0
def selectColour():
    global shades
    global hues
    global scroll
    global huesToShow
    global colourI
    global colourJ
    global maxHeight
    boxHeight = int((ugfx.height() - maxHeight) / huesToShow)
    boxWidth = int(ugfx.width() / shades)
    (r, g, b) = getColour(colourI / shades, colourJ / hues)
    ugfx.box(colourI * boxWidth, maxHeight + ((colourJ - scroll) * boxHeight),
             boxWidth, boxHeight, (int(31 * (1 - r)) << 11) +
             (int(63 * (1 - g)) << 5) + int(31 * (1 - b)))

    while not Buttons.is_pressed(Buttons.JOY_Center):
        positionChanged = False
        scrollChanged = False
        oldI = colourI
        oldJ = colourJ

        if Buttons.is_pressed(Buttons.JOY_Right) and (colourI < (shades - 1)):
            colourI += 1
            positionChanged = True
            while Buttons.is_pressed(Buttons.JOY_Right):
                pass
        elif Buttons.is_pressed(Buttons.JOY_Left) and (colourI > 0):
            colourI -= 1
            positionChanged = True
            while Buttons.is_pressed(Buttons.JOY_Left):
                pass

        if Buttons.is_pressed(Buttons.JOY_Down) and (colourJ < (hues - 1)):
            if (colourJ - scroll) == 1:
                scroll += 1
                scrollChanged = True
            colourJ += 1
            positionChanged = True
            while Buttons.is_pressed(Buttons.JOY_Down):
                pass
        elif Buttons.is_pressed(Buttons.JOY_Up) and (colourJ > 0):
            if (colourJ - scroll) == 0:
                scroll -= 1
                scrollChanged = True
            colourJ -= 1
            positionChanged = True
            while Buttons.is_pressed(Buttons.JOY_Up):
                pass

        if scrollChanged or positionChanged:
            if scrollChanged:
                showColourChangeMenu()
            elif positionChanged:
                (r, g, b) = getColour(oldI / shades, oldJ / hues)
                ugfx.box(oldI * boxWidth,
                         maxHeight + ((oldJ - scroll) * boxHeight), boxWidth,
                         boxHeight, (int(31 * r) << 11) + (int(63 * g) << 5) +
                         int(31 * b))

            (r, g, b) = getColour(colourI / shades, colourJ / hues)
            ugfx.box(colourI * boxWidth,
                     maxHeight + ((colourJ - scroll) * boxHeight), boxWidth,
                     boxHeight, (int(31 * (1 - r)) << 11) +
                     (int(63 * (1 - g)) << 5) + int(31 * (1 - b)))

        sleep(0.05)

    while Buttons.is_pressed(Buttons.JOY_Center):
        pass

    (r, g, b) = getColour(colourI / shades, colourJ / hues)
    ugfx.box(colourI * boxWidth, maxHeight + ((colourJ - scroll) * boxHeight),
             boxWidth, boxHeight,
             (int(31 * r) << 11) + (int(63 * g) << 5) + int(31 * b))
    return (int(31 * r) << 11) + (int(63 * g) << 5) + int(31 * b)
Ejemplo n.º 5
0
ugfx.init()
h = ugfx.height()
w = ugfx.width()

bgcolor = ugfx.BLACK    # foreground colour
fgcolor = ugfx.WHITE    # background colour

ugfx.clear(bgcolor)

pw = 40     # progress bar width
ph = h - 20 # progress bar height
pm = 5      # progress bar margin

# draw the boxes for the progress bars
ugfx.box((w//2)-(w//4)-(pw//2), (h//2)-(ph//2), pw, ph, fgcolor)
ugfx.box((w//2)-(pw//2), (h//2)-(ph//2), pw, ph, fgcolor)
ugfx.box((w//2)+(w//4)-(pw//2), (h//2)-(ph//2), pw, ph, fgcolor)

# label the progress bars
ugfx.text((w//2)-(w//4)-(pw//2)-15, (h//2), 'x', fgcolor)
ugfx.text((w//2)-(pw//2)-15,        (h//2), 'y', fgcolor)
ugfx.text((w//2)+(w//4)-(pw//2)-15, (h//2), 'z', fgcolor)

while not buttons.is_pressed("BTN_MENU"):
    accel = imu.get_acceleration()
    accel_x = accel.get('x')
    accel_y = accel.get('y')
    accel_z = accel.get('z')

    # if acceleration exceeds abs(1), paint the progress bar red
Ejemplo n.º 6
0
def drawCursor(i):
    ugfx.box(applistOffset[0] + i * (10 + iconSize) - 3, applistOffset[1] - 17,
             iconSize + 6, iconSize + 20, 0)
Ejemplo n.º 7
0
def drawCursor(i):
    ugfx.box(applistOffset[0] + i * (10 + iconSize) - 3, applistOffset[1] - 17,
             iconSize + 6, iconSize + 20, 0)


def drawBattery(percent):
    bw = int(20 * (percent / 100))
    ugfx.area(w - 22, 1, bw, 10, 0)


# statusbar
ugfx.string(1, 0, "Sun, 18.06.2017", font, 0)
ugfx.string_box(0, 0, w, 13, "doebi", font, 0, ugfx.justifyCenter)
ugfx.line(0, 12, w, 12, 0)
ugfx.box(w - 22, 1, 20, 10, 0)
drawBattery(50)

# applist
apps = ["nametag", "weather", "fahrplan", "foo", "bar"]
for i, app in enumerate(apps):
    ugfx.string_box(applistOffset[0] + i * (10 + iconSize),
                    applistOffset[1] - 17, iconSize, 14, app, font, 0,
                    ugfx.justifyCenter)
    ugfx.box(applistOffset[0] + i * (10 + iconSize), applistOffset[1],
             iconSize, iconSize, 0)

drawCursor(2)

ugfx.line(0, 90, w, 90, 0)
Ejemplo n.º 8
0
 def draw_border(self):
     ugfx.box(5, 5, 287, 120, ugfx.BLACK)
Ejemplo n.º 9
0
#based on Working Clock
import easyrtc
import ugfx
import badge
import time
import wifi
import appglue
import urandom

badge.init()
ugfx.init()
wifi.init()
easyrtc.configure()

ugfx.clear(ugfx.WHITE)
ugfx.string(0, 0, "Hey look at my c**ck", "PermanentMarker24", ugfx.BLACK)
t = easyrtc.string()
n = urandom.getrandbits(2)

ugfx.box(120, 40, 120, 60, ugfx.BLACK)
ugfx.area(120, 40, 120, 60, ugfx.BLACK)
#ugfx.string(130, 50, t, "PermanentMarker36", ugfx.WHITE)
ugfx.string(100, 20, str(n), "PermanentMarker36", ugfx.WHITE)

ugfx.flush()
time.sleep(20)
appglue.home()