示例#1
0
def render(d):
    d.clear()

    year, month, mday, hour, min, sec, wday, yday = utime.localtime()

    if MODE == CHANGE_YEAR:
        render_num(d, year // 100, 1)
        render_num(d, year % 100, 13)
    elif MODE == CHANGE_MONTH:
        render_num(d, month, 13)
    elif MODE == CHANGE_DAY:
        render_num(d, mday, 13)
    else:
        render_num(d, hour, 1)
        render_num(d, min, 13)

    if MODE not in (CHANGE_YEAR, CHANGE_MONTH, CHANGE_DAY) and sec % 2 == 0:
        render_colon(d)

    formatted_date = "{:02}.".format(mday) + MONTH_STRING[month - 1] + str(year)[2:]
    render_text(d, formatted_date, None)
    render_battery(d, os.read_battery())
    render_charging(d)
    render_bar(d, sec)

    d.update()
示例#2
0
def animate():
    teeth = False
    fps = False
    shadow = True
    pressed = False
    ms1 = utime.time_ms()
    with display.open() as disp:
        while True:
            t = utime.localtime()
            ms0 = ms1
            ms1 = utime.time_ms() % 1000
            disp.clear()
            volt = os.read_battery()
            charge = (volt - 3.4) / 0.8
            draw_spring(disp, charge, shadow)
            draw_gears(disp, t, ms1, teeth, shadow)
            draw_hands(disp, t, shadow)
            if fps:
                disp.print("{:.1f} fps".format(1000.0 / (ms1 - ms0)),
                           posx=100,
                           posy=60)
            disp.update()
            butt = buttons.read(buttons.BOTTOM_LEFT | buttons.BOTTOM_RIGHT
                                | buttons.TOP_RIGHT)
            if butt == 0:
                pressed = False
            if not pressed and butt & buttons.BOTTOM_LEFT != 0:
                teeth = not teeth
                pressed = True
            if not pressed and butt & buttons.BOTTOM_RIGHT != 0:
                fps = not fps
                pressed = True
            if not pressed and butt & buttons.TOP_RIGHT != 0:
                shadow = not shadow
                pressed = True
示例#3
0
def render_battery(display, pos_x=140, pos_y=72):
    v = os.read_battery()
    c = get_bat_color(v)

    if not c:
        return
    display.rect(pos_x, pos_y, pos_x + 15, pos_y + 7, filled=True, col=c)
    display.rect(pos_x + 15,
                 pos_y + 2,
                 pos_x + 17,
                 pos_y + 5,
                 filled=True,
                 col=c)
    if v < 4.0:
        display.rect(pos_x + 11,
                     pos_y + 1,
                     pos_x + 14,
                     pos_y + 6,
                     filled=True,
                     col=[0, 0, 0])
    if v < 3.8:
        display.rect(pos_x + 6,
                     pos_y + 1,
                     pos_x + 11,
                     pos_y + 6,
                     filled=True,
                     col=[0, 0, 0])
    if v < 3.6:
        display.rect(pos_x + 1,
                     pos_y + 1,
                     pos_x + 6,
                     pos_y + 6,
                     filled=True,
                     col=[0, 0, 0])
    render_charging(display, pos_x + 6, pos_y)
示例#4
0
def render(d):
    d.clear()

    ltime = utime.localtime()
    years = ltime[0]
    months = ltime[1]
    days = ltime[2]
    hours = ltime[3]
    mins = ltime[4]
    secs = ltime[5]

    if MODE == CHANGE_YEAR:
        renderNum(d, years // 100, 1)
        renderNum(d, years % 100, 13)
    elif MODE == CHANGE_MONTH:
        renderNum(d, months, 13)
    elif MODE == CHANGE_DAY:
        renderNum(d, days, 13)
    else:
        renderNum(d, hours, 1)
        renderNum(d, mins, 13)

    if MODE not in (CHANGE_YEAR, CHANGE_MONTH, CHANGE_DAY) and secs % 2 == 0:
        renderColon(d)

    formatted_date = "{:02}.".format(days) + MONTH_STRING[months -
                                                          1] + str(years)[2:]
    renderText(d, formatted_date, None)
    # renderText(d, NAME, None)
    render_battery(d, os.read_battery())
    renderBar(d, secs)

    d.update()
示例#5
0
def get_bat_color(bat):
    # shamelessly copied from https://badge.team/projects/card10_nickname
    try:
        v = os.read_battery()
        if v > 3.8:
            return bat[1]
        if v > 3.6:
            return bat[2]
        return bat[3]
    except AttributeError:
        return False
示例#6
0
def powerstats():
    with display.open() as disp:
        while True:
            volt = os.read_battery()
            curr = power.read_battery_current() * 1000
            powr = volt * curr
            perc = (volt - 3.4) / 0.8 * 100
            disp.clear()
            disp.print("{:.1f} %".format(perc), posx=0, posy=0)
            disp.print("{:.3f} V".format(volt), posx=0, posy=20)
            disp.print("{:.1f} mA".format(curr), posx=0, posy=40)
            disp.print("{:.1f} mW".format(powr), posx=0, posy=60)
            disp.update()
            utime.sleep(1)
示例#7
0
def loop():
    while True:
        mac = get_mac()
        with display.open() as disp:
            disp.clear()
            disp.print('battery v')
            disp.print(str(os.read_battery()), posy=22)
            if mac != '':
                print('print mac')
                disp.print('mac', posy=44)
                disp.print(mac, posy=66)
            disp.update()
            disp.close()
        utime.sleep(1)
示例#8
0
def get_bat_color():
    """
    Function determines the color of the battery indicator. Colors can be set in config.
    Voltage threshold's are currently estimates as voltage isn't that great of an indicator for
    battery charge.
    :return: false if old firmware, RGB color array otherwise
    """
    try:
        v = os.read_battery()
        if v > 3.8:
            return battery_color_good
        if v > 3.6:
            return battery_color_ok
        return battery_color_bad
    except AttributeError:
        return False
示例#9
0
def get_bat_color(bat):
    """
    Function determines the color of the battery indicator. Colors can be set in config.
    Voltage threshold's are currently estimates as voltage isn't that great of an indicator for
    battery charge.
    :param bat: battery config tuple (boolean: indicator on/off, array: good rgb, array: ok rgb, array: bad rgb)
    :return: battery status tuple (float: battery voltage, false if old firmware, RGB color array otherwise)
    """
    try:
        v = os.read_battery()
        if v > 3.8:
            return (v, bat[1])
        if v > 3.6:
            return (v, bat[2])
        return (v, bat[3])
    except AttributeError:
        return (0, False)
示例#10
0
 def update_clock(self, display):
     fgcol = (55 * BRIGHTNESS, 55 * BRIGHTNESS, 55 * BRIGHTNESS)
     display.clear()
     (year, month, day, hour, minute, seconds, weekday, _yday) = utime.localtime()
     self.renderNum(display, hour, 1, fgcol)
     self.renderNum(display, minute, 13, fgcol)
     self.renderColon(display, fgcol)
     self.render_battery(display, os.read_battery())
     temperature, humidity, pressure, resistance = bme680.get_data()
     self.render_temperature(display, temperature)
     ccc_day = get_ccc_day()
     if ccc_day:
         date = 'Day {}'.format(ccc_day[0])
         date_color = ccc_day[1]
     else:
         date = '{}.{}'.format(day, MONTH_STRING[month - 1])
         date_color = (255, 255, 255)
     self.render_date(display, date, date_color)
     display.update()
示例#11
0
def render_battery(disp):
    """
    Adds the battery indicator to the display. Does not call update or clear so it can be used in addition to
    other display code.
    :param disp: open display
    """
    c = get_bat_color()
    if not c:
        return
    disp.line(141, 62, 155, 62, col=c)
    disp.line(155, 62, 155, 68, col=c)
    disp.line(155, 68, 141, 68, col=c)
    disp.line(141, 68, 141, 62, col=c)
    disp.rect(156, 64, 157, 66, filled=True, col=c)
    try:
        charging = (power.read_chargein_voltage() > 1)
    except AttributeError:
        charging = False
    try:
        v = os.read_battery()
        fillWidth = round(max(min(v - 3.6, 0.44), 0) * 32.5)
        if not charging:
            disp.rect(142, 63, 141 + fillWidth, 67, filled=True, col=c)
        else:
            for i in range(13):
                if not BATTERY_FLASH[i]:
                    if fillWidth > i:
                        disp.line(142 + i, 63, 142 + i, 67, col=c)
                else:
                    if fillWidth > i:
                        y = min(BATTERY_FLASH[i]) - 2
                        if y >= 0:
                            disp.line(142 + i, 63, 142 + i, 63 + y, col=c)
                        y = max(BATTERY_FLASH[i]) + 2
                        if y <= 4:
                            disp.line(142 + i, 63 + y, 142 + i, 68, col=c)
                    for y in BATTERY_FLASH[i]:
                        disp.pixel(142 + i, 63 + y, col=c)
    except AttributeError:
        return
示例#12
0
def render_battery(disp):
    """
    Adds the battery indicator to the display. Does not call update or clear so it can be used in addition to
    other display code.
    :param disp: open display
    """
    c = get_bat_color()
    if not c:
        return
    disp.rect(140, 2, 155, 9, filled=True, col=c)
    disp.rect(155, 4, 157, 7, filled=True, col=c)
    try:
        v = os.read_battery()
        disp.print("{:.4} V".format(v), posy=40, fg=c)
        if v < 4.0:
            disp.rect(151, 3, 154, 8, filled=True, col=[0, 0, 0])
        if v < 3.8:
            disp.rect(146, 3, 151, 8, filled=True, col=[0, 0, 0])
        if v < 3.6:
            disp.rect(141, 3, 146, 8, filled=True, col=[0, 0, 0])
    except AttributeError:
        return
示例#13
0
    if pressed & buttons.BOTTOM_LEFT != 0:
        brightness = max(0, brightness - 3)
        waitAfterUpdate = True

    if pressed & buttons.BOTTOM_RIGHT != 0:
        brightness = min(255, brightness + 3)
        waitAfterUpdate = True

    if pressed & buttons.TOP_RIGHT != 0:
        mode = mode + 1
        if mode > 2:
            mode = 0
        waitAfterUpdate = True

    voltage = os.read_battery()
    batteryPercent = (voltage - minVoltage) / (maxVoltage - minVoltage)
    batteryLevel = max(0, min(1, batteryPercent))

    if mode == 0:
        disp.print("Battery:")
        disp.print("%f%%" % (batteryLevel * 100), posy=20)
        disp.print("%fV" % voltage, posy=40, posx=14)

    if mode == 1:
        chargeCurrent = power.read_chargein_current()
        chargeVoltage = power.read_chargein_voltage()
        disp.print("Charging:", posy=0)
        if chargeCurrent < 0.01:
            disp.print("NEIN", posy=20, fg=[255, 0, 0])
        else:
示例#14
0
def run_loop():
    bat = [1, [0, 230, 00], [255, 215, 0], [255, 0, 0]]
    anim = 0
    write_timer = 0
    with display.open() as disp:
        disp.clear()
        disp.backlight(5)
        disp.print("@derfnull", posy=0)
        disp.update()
        disp.close()
    while True:
        pressed = buttons.read(buttons.BOTTOM_LEFT | buttons.BOTTOM_RIGHT)
        if pressed & buttons.BOTTOM_LEFT:
            anim += 1
        if pressed & buttons.BOTTOM_RIGHT:
            anim += 2
        if pressed:
            if anim > 4:
                anim = 0
            if anim == 0:
                leds.clear()
                leds.set_rocket(0, 0)
                leds.set_rocket(1, 0)
                leds.set_rocket(2, 0)
            if anim == 1:
                leds.set_rocket(0, 0)
                leds.set_rocket(1, 0)
                leds.set_rocket(2, 0)
                leds.gay(0.2)
            if anim == 2:
                leds.clear()
                leds.set_rocket(0, 2)
                leds.set_rocket(1, 15)
                leds.set_rocket(2, 15)
            if anim == 3:
                leds.clear()
                leds.set_rocket(0, 15)
                leds.set_rocket(1, 15)
                leds.set_rocket(2, 15)
            if anim == 4:
                leds.clear()
                leds.set_rocket(0, 0)
                leds.set_rocket(1, 0)
                leds.set_rocket(2, 0)
                leds.set(11, [127, 127, 127])
                leds.set(12, [127, 127, 127])
                leds.set(13, [127, 127, 127])
                leds.set(14, [127, 127, 127])
        sensor_data = bme680.get_data()
        ambient_light = light_sensor.get_reading()
        battery_voltage = os.read_battery()
        with display.open() as disp:
            disp.clear()
            render_battery(disp, bat, battery_voltage)
            disp.print("@derfnull", posy=0)
            disp.print("{:2.1f} C {:2.0f} %".format(sensor_data[0],
                                                    sensor_data[1]),
                       posy=20)
            disp.print("{:5.1f} hPa ".format(sensor_data[2]), posy=40)
            disp.print("{:4.1f} kOhm ".format(sensor_data[3] / 1000), posy=60)
            disp.update()
            disp.close()
        write_timer += 1
        if write_timer == 5:
            with open('sensorlog.txt', 'a') as f:
                f.write('{} {} {} {} {} {} {}\n'.format(
                    utime.time_ms(), sensor_data[0], sensor_data[1],
                    sensor_data[2], sensor_data[3], ambient_light,
                    battery_voltage))
            write_timer = 0
        utime.sleep(2)