Esempio n. 1
0
buf_epaper_red   = bytearray(w * h // 8) # moved from frame buffer to match e-paper (portrait) 

import framebuf
fb_black = framebuf.FrameBuffer(buf_black, w, h, framebuf.MONO_VLSB)
fb_red   = framebuf.FrameBuffer(buf_red,   w, h, framebuf.MONO_VLSB)
black_red = 0 # will be black on buf_black, red on buf_red
white     = 1

d_b = DummyDisplay(buf_black, w, h, framebuf.MONO_VLSB)
d_r = DummyDisplay(buf_red, w, h, framebuf.MONO_VLSB)
d_b.fill(white)
d_r.fill(white)

wri_b = Writer(d_b, font10, False)
Writer.set_textpos(d_b, 6, 0)  # verbose = False to suppress console output
wri_b.printstring(quote_list[0], True)
wri_r = Writer(d_r, font10, False)
Writer.set_textpos(d_r, 110, 0) #y position 110 is max for font10
wri_r.printstring(' -'+quote_list[1], True)

# Move frame buffer bytes to e-paper buffer to match e-paper bytes organisation.
x=0; y=0; n=1; R=0
for i in range(1, 17):
    for j in range(1, 297):
        R = (n-x)+((n-y)*15)
        buf_epaper_black[R-1] = buf_black[n-1]
        buf_epaper_red[R-1] = buf_red[n-1]
        n +=1
    x = n+i-1
    y = n-1
    
Esempio n. 2
0
def update_display(display, payload):
    def calculate_width(font, text):
        w = 0
        for c in text:
            glyph, char_height, char_width = font.get_ch(c)
            w += char_width
        return w

    try:

        command = {}

        if payload is None:

            # An example command for testing
            command = {
                "heating_state": True,
                "msg": "auto",
                "inside_temp": 23.456,
                "outside_temp": -9.876
            }

        else:
            try:
                import ujson as json
                command = json.loads(payload)
            except (OSError, ValueError):
                import kiota.Util as Util
                Util.log(update_display,
                         "Can't parse payload: '{}'".format(payload))

        display.fill(0)

        ink = 1
        heating_state = command["heating_state"]

        if heating_state:
            ink = 0
            display.fill_rect(0, 0, 128, 14, 1)

        if command["msg"] is not None:
            display.text(str(command["msg"]), 0, 1, ink)

        if command["heating_state"]:
            display.text("ON", 104, 1, ink)
        else:
            display.text("OFF", 104, 1, ink)

        import KameronRegularNumbers25 as font
        from Writer import Writer
        writer = Writer(display, font)
        writer.set_clip(True, True)

        inside_temp = "--"
        try:
            inside_temp = str(int(round(float(command["inside_temp"]))))
        except:
            pass
        writer.set_textpos(23,
                           int((64 - calculate_width(font, inside_temp)) / 2))
        display.fill_rect(0, 15, 64, 41, 0)
        writer.printstring(inside_temp)

        outside_temp = "--"
        try:
            outside_temp = str(int(round(float(command["outside_temp"]))))
        except:
            pass
        writer.set_textpos(
            23, 64 + int((64 - calculate_width(font, outside_temp)) / 2))
        display.fill_rect(64, 15, 64, 41, 0)
        writer.printstring(outside_temp)

        display.text("inside", 0, 56)
        display.text("outside", 72, 56)

        display.show()

    except Exception as e:
        display.text("ERROR", 0, 0)
        display.show()
        import sys
        sys.print_exception(e)

    return True
Esempio n. 3
0
def epd_pull():
    #get the quote from the quote api function. Stored as tuple
    quote_list = quote_api.quote_pull()

    # software SPI on ESP32 Waveshare driver board
    epap_pos = Pin(18, Pin.PULL_UP)
    epap_neg = Pin(19, Pin.PULL_DOWN)
    sck = Pin(16)
    mosi = Pin(23)
    cs = Pin(5)
    busy = Pin(15)
    rst = Pin(21)
    dc = Pin(17)
    # miso is not used but must be declared. Let's take any unused gpio: 12
    miso = Pin(12)
    spi = SPI(baudrate=100000,
              polarity=0,
              phase=0,
              sck=sck,
              mosi=mosi,
              miso=miso)

    e = epap.EPD(spi, cs, dc, rst, busy)
    e.init()

    h = 128
    w = 296  # e-paper heigth and width. It will be used in landscape mode

    buf_black = bytearray(w * h // 8)  # used by frame buffer (landscape)
    buf_red = bytearray(w * h // 8)  # used by frame buffer (landscape)
    buf_epaper_black = bytearray(
        w * h // 8)  # used to display on e-paper after bytes have been
    buf_epaper_red = bytearray(
        w * h // 8)  # moved from frame buffer to match e-paper (portrait)

    fb_black = framebuf.FrameBuffer(buf_black, w, h, framebuf.MONO_VLSB)
    fb_red = framebuf.FrameBuffer(buf_red, w, h, framebuf.MONO_VLSB)
    black_red = 0  # will be black on buf_black, red on buf_red
    white = 1

    d_b = DummyDisplay(buf_black, w, h, framebuf.MONO_VLSB)
    d_r = DummyDisplay(buf_red, w, h, framebuf.MONO_VLSB)
    d_b.fill(white)
    d_r.fill(white)

    wri_b = Writer(d_b, font10, False)
    Writer.set_textpos(d_b, 6, 0)  # verbose = False to suppress console output
    wri_b.printstring(quote_list[0], True)
    wri_r = Writer(d_r, font10, False)
    #import volt
    import hour_tim
    slep_tim = hour_tim.time_corr()
    #v_reading="%.2f" % volt.voltage()
    h = '{:02d}:{:02d}.{:02d}'.format(RTC().datetime()[4],
                                      RTC().datetime()[5],
                                      RTC().datetime()[6])
    Writer.set_textpos(d_r, 110, 0)  #y position 110 is max for font10
    print(h, quote_list[1])
    wri_r.printstring(' -' + quote_list[1] + ' ' + h, True)  #+'  V='+v_reading

    # Move frame buffer bytes to e-paper buffer to match e-paper bytes organisation.
    x = 0
    y = 0
    n = 1
    R = 0
    for i in range(1, 17):
        for j in range(1, 297):
            R = (n - x) + ((n - y) * 15)
            buf_epaper_black[R - 1] = buf_black[n - 1]
            buf_epaper_red[R - 1] = buf_red[n - 1]
            n += 1
        x = n + i - 1
        y = n - 1

    buf_red = []
    buf_black = []
    print('Sending to display')
    e.display_frame(buf_epaper_black, buf_epaper_red)
    print('Done!.......')
    gc.collect()
    e.sleep()  # recommended by manufacturer to avoid damage to display
    print('E-paper sleeping!...')
    machine.deepsleep(slep_tim)

    print('END')