Exemplo n.º 1
0
def main():
    # initialize display driver
    epd = epd2in13b.EPD()
    epd.init()

    # clear the frame buffer
    frame_black = [0xFF] * (epd.width * epd.height / 8)
    frame_red = [0xFF] * (epd.width * epd.height / 8)

    # initialize buffer with qrcode
    frame_black = epd.get_frame_buffer(Image.open(sys.argv[1]))

    # define font locations
    font = ImageFont.truetype('/usr/share/fonts/TTF/Roboto-Regular.ttf', 16)
    fa = ImageFont.truetype('/usr/share/fonts/TTF/fontawesome-brands.ttf', 22)

    # get date time
    date = datetime.datetime.now().strftime("%b %d, %Y")

    # draw OpenWallet PI banner
    epd.draw_filled_rectangle(frame_red, 0, 0, 128, 24, COLORED)
    epd.draw_string_at(frame_red, 2, 0, "OpenWallet PI", font, UNCOLORED)

    # write strings to the buffer
    epd.draw_string_at(frame_black, 6, 30, "Balance:", font, COLORED)
    epd.draw_string_at(frame_black, 4, 50, unichr(int('f42e', 16)), fa,
                       COLORED)
    epd.draw_string_at(frame_black, 20, 50, sys.argv[2], font, COLORED)
    epd.draw_string_at(frame_black, 6, 70, "Checked on:", font, COLORED)
    epd.draw_string_at(frame_black, 6, 90, date, font, COLORED)

    # display the frames
    epd.display_frame(frame_black, frame_red)
Exemplo n.º 2
0
def demo():
    epd = epd2in13b.EPD()
    epd.init()

    # clear the frame buffer
    frame_black = [0xFF] * (epd.width * epd.height / 8)
    frame_red = [0xFF] * (epd.width * epd.height / 8)

    # For simplicity, the arguments are explicit numerical coordinates
    epd.draw_rectangle(frame_black, 10, 60, 50, 100, COLORED)
    epd.draw_line(frame_black, 10, 60, 50, 100, COLORED)
    epd.draw_line(frame_black, 50, 60, 10, 100, COLORED)
    epd.draw_circle(frame_black, 80, 80, 15, COLORED)
    epd.draw_filled_rectangle(frame_red, 10, 120, 50, 180, COLORED)
    epd.draw_filled_rectangle(frame_red, 0, 6, 128, 26, COLORED)
    epd.draw_filled_circle(frame_red, 80, 150, 15, COLORED)

    # write strings to the buffer
    font = ImageFont.truetype(
        '/usr/share/fonts/truetype/freefont/FreeMono.ttf', 12)
    epd.draw_string_at(frame_black, 4, 30, "e-Paper Demo", font, COLORED)
    epd.draw_string_at(frame_red, 6, 10, "Hello world!", font, UNCOLORED)
    # display the frames
    epd.display_frame(frame_black, frame_red)

    # display images
    frame_black = epd.get_frame_buffer(Image.open('black.bmp'))
    frame_red = epd.get_frame_buffer(Image.open('red.bmp'))
    epd.display_frame(frame_black, frame_red)
Exemplo n.º 3
0
def show_image(black_image, red_image):
    epd = epd2in13b.EPD()
    epd.init()

    frame_black = epd.get_frame_buffer(black_image)
    frame_red = epd.get_frame_buffer(red_image)
    epd.display_frame(frame_black, frame_red)
Exemplo n.º 4
0
def main():
    
    config = load_config()

    epd = epd2in13b.EPD()
    epd.init()
    epd.set_rotate(1)

    # clear the frame buffer
    frame_black = [0xFF] * (epd.width * epd.height / 8)
    frame_red = [0xFF] * (epd.width * epd.height / 8)

    epd.draw_filled_rectangle(frame_red, 0, 0, 250, 55, COLORED);

    font = ImageFont.truetype('/usr/share/fonts/AmaticSC-Bold.ttf', 38)
    epd.draw_string_at(frame_red, 25, 10, config["caption"], font, UNCOLORED)

    data = get_location( config["user_number"], config["auth_token"] )
    ds = "unknown"
    print(data)

    if(u'description' in data):
           print(data["description"])
           ds = data["description"]

    epd.draw_string_at(frame_black, 25, 60, ds, font, COLORED)

    epd.display_frame(frame_black, frame_red)
Exemplo n.º 5
0
def main():
    epd = epd2in13b.EPD()
    epd.init()
    # clear the frame buffer
    frame_black = [0xFF] * (epd.width * epd.height / 8)
    frame_red = [0xFF] * (epd.width * epd.height / 8)
    # For simplicity, the arguments are explicit numerical coordinates
    image = Image.new('1', (epd2in13b.EPD_WIDTH, epd2in13b.EPD_HEIGHT),
                      255)  # 255: clear the frame
    #image = image.rotate(90)
    draw = ImageDraw.Draw(image)
    font = ImageFont.truetype(
        '/usr/share/fonts/truetype/freefont/FreeMonoBold.ttf', 12)
    draw.rectangle((0, 10, 128, 30), fill=0)
    draw.text((20, 14), 'Hello world!', font=font, fill=255)
    draw.text((20, 36), 'e-Paper Demo', font=font, fill=0)
    font = ImageFont.truetype('/usr/share/fonts/truetype/wyq/wqy-microhei.ttc',
                              18)
    draw.text((10, 56), u'你好,树莓派', font=font, fill=0)
    font = ImageFont.truetype('/usr/share/fonts/truetype/wyq/wqy-zenhei.ttc',
                              24)
    draw.text((20, 80), u'微雪电子', font=font, fill=0)
    print "你好"

    #epd.clear_frame_memory(0xFF)
    #epd.set_frame_memory(image , 0, 0)
    epd.display_frame(frame_black, frame_red)

    epd.delay_ms(2000)
Exemplo n.º 6
0
def displayPhraseOnScreen(newPhrase, rotation):

    #font size variable and position of text
    fontSize = 14
    yPosition = 40
    xPosition = 7

    print(len(newPhrase))

    if len(newPhrase) in range(15, 19):
        fontSize = 19

    if len(newPhrase) in range(12, 15):
        fontSize = 23

    if len(newPhrase) in range(8, 12):
        fontSize = 30

    elif len(newPhrase) in range(6, 8):
        fontSize = 43
        yPosition = 30
        xPosition = 1

    elif len(newPhrase) in range(4, 6):
        fontSize = 60
        yPosition = 25
        xPosition = 8

    elif len(newPhrase) in range(3, 4):
        fontSize = 67
        yPosition = 10
        xPosition = 30

    elif len(newPhrase) in range(1, 3):
        fontSize = 80
        yPosition = 12
        xPosition = 50

    epd = epd2in13b.EPD()
    epd.init()

    # clear the frame buffer
    frame_black = [0xFF] * (epd.height * epd.width / 8)
    frame_red = [0xFF] * (epd.height * epd.width / 8)

    if newPhrase == "nameOfImage":
        frame_black = epd.get_frame_buffer(Image.open('nameOfImage.png'))
        epd.display_frame(frame_black, frame_red)

    else:
        epd.set_rotate(rotation)
        font = ImageFont.truetype(
            '/usr/share/fonts/truetype/freefont/FreeMonoBoldOblique.ttf',
            fontSize)
        epd.draw_string_at(frame_black, xPosition + 1, yPosition + 1,
                           newPhrase, font, COLORED)
        epd.draw_string_at(frame_red, xPosition, yPosition, newPhrase, font,
                           COLORED)
        epd.display_frame(frame_black, frame_red)
Exemplo n.º 7
0
def main():
    print "initing screen..."
    epd = epd2in13b.EPD()
    epd.init()
    try:
        update(epd)
    finally:
        print "sleeping epd before leaving"
        epd.sleep()
Exemplo n.º 8
0
def draw_epaper_horizontal(black_image, red_image):
    logger.info("Sending images to e-Paper")
    epd = epd2in13b.EPD()
    epd.init()
    # epd.Clear()
    epd.display(epd.getbuffer(black_image.rotate(180)),
                epd.getbuffer(red_image.rotate(180)))
    epd.wait_until_idle()
    epd.sleep()
    logger.info("Done")
Exemplo n.º 9
0
def main():
    epd = epd2in13b.EPD()
    epd.init()

    # clear the frame buffer
    frame_black = [0xFF] * (epd.width * epd.height / 8)
    frame_red = [0xFF] * (epd.width * epd.height / 8)

    # For simplicity, the arguments are explicit numerical coordinates
    #epd.draw_rectangle(frame_black, 10, 60, 50, 100, COLORED);
    #epd.draw_line(frame_black, 10, 60, 50, 100, COLORED);
    #epd.draw_line(frame_black, 50, 60, 10, 100, COLORED);
    #epd.draw_circle(frame_black, 80, 80, 15, COLORED);
    #epd.draw_filled_rectangle(frame_red, 10, 120, 50, 180, COLORED);
    #epd.draw_filled_rectangle(frame_red, 0, 6, 128, 26, COLORED);
    #epd.draw_filled_circle(frame_red, 80, 150, 15, COLORED);

    # get ip address :
    ip_address = get_ip_address("wlxe84e0638e14f")
    str_ip = str(ip_address)

    # get datetime
    year = datetime.datetime.now().year
    month = datetime.datetime.now().month
    day = datetime.datetime.now().day
    date = str(year) + "." + str(month) + "." + str(day)

    # write strings to the buffer
    font = ImageFont.truetype(
        '/usr/share/fonts/truetype/noto/NotoMono-Regular.ttf', 12)
    epd.draw_string_at(frame_red, 20, 10, date, font, COLORED)
    epd.draw_string_at(frame_red, 5, 30, "WLAN Info:", font, COLORED)

    font = ImageFont.truetype(
        "/usr/share/fonts/truetype/noto/NotoMono-Regular.ttf", 10)
    epd.draw_string_at(frame_red, 5, 50, "Device name :", font, COLORED)
    epd.draw_string_at(frame_red, 10, 60, "wlxe84e0638e14f", font, COLORED)

    epd.draw_string_at(frame_red, 5, 80, "IP Address :", font, COLORED)
    epd.draw_string_at(frame_red, 10, 90, str_ip, font, COLORED)

    font = ImageFont.truetype(
        "/usr/share/fonts/truetype/noto/NotoMono-Regular.ttf", 12)

    # display the frames
    epd.display_frame(frame_black, frame_red)
Exemplo n.º 10
0
    def __init__(self, image_path, slogan_path):
        super(EBadge, self).__init__()
        self.epd = epd2in13b.EPD()
        self.epd.init()
        self.pause = False
        self.interval = 5

        # store color
        self.red = 0
        self.green = 0
        self.blue = 0

        # paths
        self.image_path = image_path
        self.slogan_path = slogan_path

        # rotate before proceeding
        self.epd.set_rotate(epd2in13b.ROTATE_90)
Exemplo n.º 11
0
def main():

    config = load_config()

    print(config)

    epd = epd2in13b.EPD()
    epd.init()
    epd.set_rotate(3)

    # clear the frame buffer
    frame_black = [0xFF] * (epd.width * epd.height / 8)
    frame_red = [0xFF] * (epd.width * epd.height / 8)

    epd.draw_filled_rectangle(frame_black, 0, 0, 250, 55, COLORED)

    font = ImageFont.truetype('/usr/share/fonts/marvinVisions.otf', 21)
    epd.draw_string_at(frame_black, 68, 25, config["caption"], font, UNCOLORED)

    data = get_location(config["user_number"], config["auth_token"])
    # Add this to config to make it customisable
    ds = "MCUK (Probably)"
    print(data)

    if (u'description' in data):
        print(data["description"])
        ds = data["description"]

    print(type(ds))
    print(type(config["caption"]))
    print(len(ds))
    print(len(config["caption"]))

    if (len(ds) > len(config["caption"])):
        font1 = ImageFont.truetype('/usr/share/fonts/marvinVisions.otf', 13)
        epd.draw_string_at(frame_black, 72, 65, ds, font1, COLORED)
    else:
        epd.draw_string_at(frame_black, 72, 65, ds, font, COLORED)

    if (config["old_ds"] != ds):
        epd.display_frame(frame_black, frame_red)

    save_config(ds)
Exemplo n.º 12
0
#!/usr/bin/python
# -*- coding:utf-8 -*-

import epd2in13b
import time
from PIL import Image, ImageDraw, ImageFont
import traceback
import sys

try:
    epd = epd2in13b.EPD()
    epd.init()
    print("Clear...")
    epd.Clear()
    image = Image.open(sys.argv[1])
    epd.display(epd.getbuffer(image, 0), epd.getbuffer(image, 1))
    epd.sleep()

except:
    print('traceback.format_exc():\n%s', traceback.format_exc())
    exit()
Exemplo n.º 13
0
def main():
    epd = epd2in13b.EPD()
    while True:

        # Get Weather data from OWM
        obs = owm.weather_at_id(city_id)
        location = obs.get_location().get_name()
        weather = obs.get_weather()
        reftime = weather.get_reference_time()
        description = weather.get_detailed_status()
        temperature = weather.get_temperature(unit='fahrenheit')
        humidity = weather.get_humidity()
        pressure = weather.get_pressure()
        clouds = weather.get_clouds()
        wind = weather.get_wind()
        rain = weather.get_rain()
        sunrise = weather.get_sunrise_time()
        sunset = weather.get_sunset_time()

        print("location: " + location)
        print("weather: " + str(weather))
        print("description: " + description)
        print("temperature: " + str(temperature))
        print("humidity: " + str(humidity))
        print("pressure: " + str(pressure))
        print("clouds: " + str(clouds))
        print("wind: " + str(wind))
        print("rain: " + str(rain))
        print("sunrise: " + time.strftime( '%H:%M', time.localtime(sunrise)))
        print("sunset: " + time.strftime( '%H:%M', time.localtime(sunset)))

        try:
            epd = epd2in13b.EPD()
            epd.init()
            print("Clear...")
            epd.Clear()

            print("Drawing")
            ####### Drawing on the Horizontal image
            HBlackimage = Image.new('1', (epd2in13b.EPD_HEIGHT, epd2in13b.EPD_WIDTH), 255)  # 298*126
            HRedimage = Image.new('1', (epd2in13b.EPD_HEIGHT, epd2in13b.EPD_WIDTH), 255)  # 298*126
            drawblack = ImageDraw.Draw(HBlackimage)
            drawred = ImageDraw.Draw(HRedimage)
            font30 = ImageFont.truetype('/usr/share/fonts/truetype/noto/NotoMono-Regular.ttf', 30)
            font25 = ImageFont.truetype('/usr/share/fonts/truetype/noto/NotoMono-Regular.ttf', 25)
            font15 = ImageFont.truetype('/usr/share/fonts/truetype/noto/NotoMono-Regular.ttf', 15)
            datetime = time.strftime("%H:%M %d/%m")

            drawred.rectangle((0, 0, 212, 50 ), fill = 0)
            drawred.rectangle((0, 90, 212, 104), fill = 0)

            drawred.text((55, 2), 'Hello!', font = font30, fill = 1)
            drawred.text((8, 30), 'The time and date is:', font = font15, fill = 1)
            drawblack.text((20, 56), datetime, font = font25, fill = 0)

            epd.display(epd.getbuffer(HBlackimage.rotate(180)), epd.getbuffer(HRedimage.rotate(180)))
            #epd.display(epd.getbuffer(HRedimage.rotate(180)), epd.getbuffer(HBlackimage.rotate(180)))
            time.sleep(2)


            epd.sleep()

        except:
            print('traceback.format_exc():\n%s',traceback.format_exc())
            exit()
Exemplo n.º 14
0
def main():
    epd = epd2in13b.EPD()
    epd.init()
    print('epd.init done')

    # clear the frame buffer
    frame_black = [0x00] * int(epd.width * epd.height / 8)
    frame_red = [0x00] * int(epd.width * epd.height / 8)
    for i in range(int(epd.width * epd.height / 16)):
        frame_black[i] = 0xFF

        if i > int(epd.width * epd.height / 32):
            frame_black[i] = 0x00
        frame_red[i] = 0xFF - frame_black[i]
        #if i> int(epd.width * epd.height / 32):
        #    frame_red[i] = 0x80
    # For simplicity, the arguments are explicit numerical coordinates
    '''
	epd.draw_rectangle(frame_black, 10, 60, 50, 100, COLORED);
	epd.draw_line(frame_black, 10, 60, 50, 100, COLORED);
	epd.draw_line(frame_black, 50, 60, 10, 100, COLORED);
	epd.draw_circle(frame_black, 80, 80, 15, COLORED);
	epd.draw_filled_rectangle(frame_red, 10, 120, 50, 180, COLORED);
	epd.draw_filled_rectangle(frame_red, 0, 6, 128, 26, COLORED);
	epd.draw_filled_circle(frame_red, 80, 150, 15, COLORED);
	'''
    # write strings to the buffer
    #font = ImageFont.truetype('/usr/share/fonts/truetype/freefont/FreeMono.ttf', 12)
    #epd.draw_string_at(frame_black, 4, 30, "e-Paper Demo", font, COLORED)
    #epd.draw_string_at(frame_red, 6, 10, "IP:", font, UNCOLORED)
    # display the frames

    #epd.display_frame(frame_black, frame_red)

    # display images
    #frame_black = epd.get_frame_buffer(Image.open('black.bmp'))
    #frame_red = epd.get_frame_buffer(Image.open('red.bmp'))
    #epd.display_frame(frame_black, frame_red)

    # You can get frame buffer from an image or import the buffer directly:
    #epd.display_frame(imagedata.IMAGE_BLACK, imagedata.IMAGE_RED)
    while True:
        # 格式化成2016-03-20 11:45:39形式
        shape = (epd.width, epd.height)
        imgB = cv.drGray(shape, 255)
        imgY = cv.drGray(shape, 255)
        str = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        print(str)
        imgY = cv.drPutText(imgY, str, (15, 15))
        cv.putText(imgY,
                   str, (15, 15),
                   cv.FONT_HERSHEY_PLAIN,
                   1.0, (0, 0, 0),
                   thickness=2,
                   lineType=cv.LINE_AA)
        cv.putText(imgB,
                   str, (16, 16),
                   cv.FONT_HERSHEY_PLAIN,
                   1.0, (0, 0, 0),
                   lineType=cv.LINE_AA)
        #imgB=cv.imread('black.png',cv.IMREAD_GRAYSCALE)#,cv.IMREAD_GRAYSCALE
        #imgY=cv.imread('red.png',cv.IMREAD_GRAYSCALE)#,cv.IMREAD_GRAYSCALE
        outB = get_frame_buffer(epd, imgB)
        outY = get_frame_buffer(epd, imgY)
        epd.display_frame(outB, outY)
Exemplo n.º 15
0
def updatedisplay(reloadit=False, clearfirst=False):
    try:
        global currentEvent, nextEvent, calendarCache
        path = os.path.dirname(os.path.abspath(__file__))
        epd = epd2in13b.EPD()
        epd.init()
        if clearfirst:
            epd.Clear()
            epd.sleep()
            reloadit = True
        unsetNext = True
        try:
            icalurl = open(path + "/ICAL_URL", "r")
            calendar = events(icalurl.readline())
            calendarCache = calendar
        except:
            calendar = calendarCache
        index = 0
        calendar.sort(key=lambda x: x.start)
        for event in calendar:
            if index == 0:
                if event.start < datetime.now(
                        timezone.utc
                ):  # room is occupied at the moment, event is current event
                    reloadit = reloadit or currentEvent == None or not eventsequal(
                        event, currentEvent)
                    currentEvent = event
                else:  # room is free, event is next event
                    if currentEvent:  # old event still in cache
                        currentEvent = None
                        reloadit = True
                    unsetNext = False
                    reloadit = reloadit or nextEvent == None or not eventsequal(
                        event, nextEvent)
                    nextEvent = event
                    break
            if index == 1:
                reloadit = reloadit or nextEvent == None or not eventsequal(
                    event, nextEvent)
                nextEvent = event
                unsetNext = False
                break
            index = index + 1
        if unsetNext and nextEvent:
            nextEvent = None
            reloadit = True
        if (nextEvent or currentEvent) and len(calendar) == 0:
            nextEvent = None
            currentEvent = None
            reloadit = True
        HBlackimage = Image.new('1',
                                (epd2in13b.EPD_HEIGHT, epd2in13b.EPD_WIDTH),
                                255)
        HRedimage = Image.new('1', (epd2in13b.EPD_HEIGHT, epd2in13b.EPD_WIDTH),
                              255)
        drawblack = ImageDraw.Draw(HBlackimage)
        drawred = ImageDraw.Draw(HRedimage)
        fontTiny = ImageFont.truetype(path + '/ProggyTiny.ttf', 16)
        fontSmall = ImageFont.truetype(path + '/ProggyClean.ttf', 16)
        fontBig = ImageFont.truetype(path + '/Roboto-Regular.ttf', 32)
        fontHuge = ImageFont.truetype(path + '/Roboto-Regular.ttf', 44)
        meetingimage = Image.open(path + '/meeting.bmp')
        if currentEvent:
            drawred.rectangle(
                (1, 1, epd2in13b.EPD_HEIGHT - 2, epd2in13b.EPD_WIDTH - 41),
                fill=0)
            x = 20
            y = 4
            drawred.text((x + 48, y - 2), 'BELEGT', font=fontBig, fill=1)
            drawred.bitmap(bitmap=meetingimage, xy=(x, y), fill=1)
            circimage = Image.open(path + '/circ14.bmp')
            drawred.bitmap(bitmap=circimage, xy=(x + 10, y + 0), fill=1)
            wrongwayimage = Image.open(path + '/wrongway.bmp')
            drawblack.bitmap(bitmap=wrongwayimage, xy=(x + 11, y + 1))
            drawred.text(
                (8, epd2in13b.EPD_WIDTH - 63),
                'Noch bis ' + currentEvent.end.replace(
                    tzinfo=timezone.utc).astimezone(tz=None).strftime("%H:%M"),
                font=fontTiny,
                fill=1)
            if currentEvent.private:
                drawred.text((8, epd2in13b.EPD_WIDTH - 52),
                             'privater Termin',
                             font=fontTiny,
                             fill=1)
            else:
                drawred.text((8, epd2in13b.EPD_WIDTH - 52),
                             currentEvent.summary[:32],
                             font=fontTiny,
                             fill=1)
        else:
            x = 30
            y = 14
            drawblack.bitmap(bitmap=meetingimage, xy=(x, y), fill=0)
            checkimage = Image.open(path + '/check.bmp')
            drawblack.bitmap(bitmap=checkimage, xy=(x + 10, y + 3), fill=0)
            drawblack.text((x + 54, y - 7), 'FREI', font=fontHuge, fill=0)
        drawblack.rectangle(
            (0, 0, epd2in13b.EPD_HEIGHT - 1, epd2in13b.EPD_WIDTH - 40),
            outline=0)
        if nextEvent:
            hourstillevent = (nextEvent.start -
                              datetime.now(timezone.utc)).seconds // 3600
            minutestillevent = (nextEvent.start -
                                datetime.now(timezone.utc)).seconds // 60 % 60
            if nextEvent.private:
                drawblack.text((8, epd2in13b.EPD_WIDTH - 18),
                               'privater Termin',
                               font=fontSmall)
            else:
                drawblack.text((8, epd2in13b.EPD_WIDTH - 18),
                               nextEvent.summary[:28],
                               font=fontSmall)
            if hourstillevent == 0 and minutestillevent <= 15:
                reloadit = True
                drawblack.text((8, epd2in13b.EPD_WIDTH - 32),
                               'Nächste Belegung in',
                               font=fontTiny)
                drawred.text((8, epd2in13b.EPD_WIDTH - 32),
                             '                    ' + str(minutestillevent) +
                             ' Minuten',
                             font=fontTiny)
                drawred.text((9, epd2in13b.EPD_WIDTH - 32),
                             '                    ' + str(minutestillevent),
                             font=fontTiny)
            else:
                drawblack.text(
                    (8, epd2in13b.EPD_WIDTH - 32),
                    'Nächste Belegung um ' +
                    nextEvent.start.replace(tzinfo=timezone.utc).astimezone(
                        tz=None).strftime("%H:%M"),
                    font=fontTiny)
        else:
            drawblack.text((8, epd2in13b.EPD_WIDTH - 26),
                           'Demnächst keine Belegung',
                           font=fontSmall)
        if reloadit:
            epd.display(epd.getbuffer(HBlackimage.rotate(180)),
                        epd.getbuffer(HRedimage.rotate(180)))
            epd.sleep()

    except:
        print('traceback.format_exc():\n%s', traceback.format_exc())
        exit()
Exemplo n.º 16
0
def main():
    epd = epd2in13b.EPD()
    while True:

        # Get Weather data from OWM
        obs = owm.weather_at_id(city_id)
        location = obs.get_location().get_name()
        weather = obs.get_weather()
        reftime = weather.get_reference_time()
        description = weather.get_detailed_status()
        temperature = weather.get_temperature(unit='celsius')
        humidity = weather.get_humidity()
        pressure = weather.get_pressure()
        clouds = weather.get_clouds()
        wind = weather.get_wind()
        rain = weather.get_rain()
        sunrise = weather.get_sunrise_time()
        sunset = weather.get_sunset_time()

        print("location: " + location)
        print("weather: " + str(weather))
        print("description: " + description)
        print("temperature: " + str(temperature))
        print("humidity: " + str(humidity))
        print("pressure: " + str(pressure))
        print("clouds: " + str(clouds))
        print("wind: " + str(wind))
        print("rain: " + str(rain))
        print("sunrise: " + time.strftime('%H:%M', time.localtime(sunrise)))
        print("sunset: " + time.strftime('%H:%M', time.localtime(sunset)))

        # Display Weather Information on e-Paper Display
        try:
            print("Clear...")
            epd.init()
            epd.Clear()

            # Drawing on the Horizontal image
            HBlackimage = Image.new(
                '1', (epd2in13b.EPD_HEIGHT, epd2in13b.EPD_WIDTH),
                255)  # 298*126
            HRedimage = Image.new('1',
                                  (epd2in13b.EPD_HEIGHT, epd2in13b.EPD_WIDTH),
                                  255)  # 298*126

            print("Drawing")
            drawblack = ImageDraw.Draw(HBlackimage)
            drawred = ImageDraw.Draw(HRedimage)
            font24 = ImageFont.truetype(
                '/home/pi/ProtoStax_Weather_Station_Demo/fonts/arial.ttf', 20)
            font16 = ImageFont.truetype(
                '/home/pi/ProtoStax_Weather_Station_Demo/fonts/fonts/arial.ttf',
                12)
            font20 = ImageFont.truetype(
                '/home/pi/ProtoStax_Weather_Station_Demo/fonts/fonts/arial.ttf',
                16)
            fontweather = ImageFont.truetype(
                '/home/pi/ProtoStax_Weather_Station_Demo/fonts/fonts/meteocons-webfont.ttf',
                24)
            fontweatherbig = ImageFont.truetype(
                '/home/pi/ProtoStax_Weather_Station_Demo/fonts/fonts/meteocons-webfont.ttf',
                48)

            w1, h1 = font24.getsize(location)
            w2, h2 = font20.getsize(description)
            w3, h3 = fontweatherbig.getsize(
                weather_icon_dict[weather.get_weather_code()])

            drawblack.text(
                (10, 0),
                location + time.strftime(' - %d %b', time.localtime(reftime)),
                font=font24,
                fill=0)
            drawblack.text((10, 25), description, font=font20, fill=0)
            drawred.text((212 - w3 - 10, 0),
                         weather_icon_dict[weather.get_weather_code()],
                         font=fontweatherbig,
                         fill=0)
            #drawblack.text((10, 45), "Observed at: " , font = font16, fill = 0)

            tempstr = str("{0}{1}C".format(int(round(temperature['temp'])),
                                           u'\u00b0'))
            print(tempstr)
            w4, h4 = font24.getsize(tempstr)
            drawblack.text((20, 55), tempstr, font=font24, fill=0)
            drawred.text((20 + w4, 55), "'", font=fontweather, fill=0)
            drawblack.text((120, 55),
                           str("{0}{1} | {2}{3}".format(
                               int(round(temperature['temp_min'])), u'\u00b0',
                               int(round(temperature['temp_max'])),
                               u'\u00b0')),
                           font=font24,
                           fill=0)

            #drawblack.text((10, 60), str("{} hPA".format(int(round(pressure['press'])))), font = font20, fill = 0)
            #drawblack.text((120, 60), str("{}% RH".format(int(round(humidity)))), font = font20, fill = 0)

            drawred.text((5, 78), "A", font=fontweather, fill=0)
            drawred.text((110, 78), "J", font=fontweather, fill=0)
            drawblack.text((30, 83),
                           time.strftime('%I:%M %p', time.localtime(sunrise)),
                           font=font20,
                           fill=0)
            drawblack.text((135, 83),
                           time.strftime('%I:%M %p', time.localtime(sunset)),
                           font=font20,
                           fill=0)

            epd.display(epd.getbuffer(HBlackimage.rotate(180)),
                        epd.getbuffer(HRedimage.rotate(180)))
            time.sleep(2)

            epd.sleep()

        except IOError as e:
            print('traceback.format_exc():\n%s', traceback.format_exc())
            epdconfig.module_init()
            epdconfig.module_exit()
            exit()

        # Sleep for 10 minutes - loop will continue after 10 minutes
        time.sleep(600)  # Wake up every 10 minutes to update weather display
Exemplo n.º 17
0
def main():
    epd = epd2in13b.EPD()
    epd.init()

    font = ImageFont.truetype(
        '/usr/share/fonts/truetype/freefont/FreeMono.ttf', 12)

    # weather stuff
    noaa_result = pywapi.get_weather_from_noaa('KBOS')
    temp = noaa_result['temp_f'] + " Degrees F"
    pressure = noaa_result['pressure_in'] + "inHg"
    wind_mph = noaa_result['wind_mph'] + ' mph'
    wind_dir = noaa_result['wind_dir']
    #wind = wind_mph + wind_dir
    weather = noaa_result['weather']
    obv_time = noaa_result['observation_time_rfc822']

    # clear the frame buffer
    frame_black = [0xFF] * (epd.width * epd.height / 8)
    frame_red = [0xFF] * (epd.width * epd.height / 8)

    # For simplicity, the arguments are explicit numerical coordinates
    epd.draw_filled_rectangle(frame_red, 1, 1, 102, 20, COLORED)
    #epd.draw_rectangle(frame_black, 1, 21, 102, 50, COLORED);
    epd.draw_rectangle(frame_red, 1, 150, 102, 220, COLORED)
    # Day of Week
    epd.draw_string_at(frame_black, 2, 22,
                       datetime.date.today().strftime("%A"), font, COLORED)
    # Day of Month
    epd.draw_string_at(frame_black, 2, 34,
                       datetime.date.today().strftime("%d"), font, COLORED)
    # Month
    epd.draw_string_at(frame_black, 20, 34,
                       datetime.date.today().strftime("%B"), font, COLORED)
    # Year
    # epd.draw_string_at(frame_black, 50, 34, datetime.date.today().strftime("%Y"), font, COLORED)

    # Display Weather Stuff
    epd.draw_string_at(frame_black, 2, 50, temp, font, COLORED)
    epd.draw_string_at(frame_black, 2, 70, wind_mph, font, COLORED)
    epd.draw_string_at(frame_black, 30, 90, wind_dir, font, COLORED)
    epd.draw_string_at(frame_black, 2, 110, pressure, font, COLORED)
    epd.draw_string_at(frame_black, 2, 130, weather, font, COLORED)
    #epd.draw_string_at(frame_red, 2, 150, obv_time, font, COLORED)
    #epd.draw_string_at(frame_red, 2, 170, temp, font, COLORED)

    epd.display_frame(frame_black, frame_red)
    """
    epd.draw_line(frame_black, 10, 60, 50, 100, COLORED);
    epd.draw_line(frame_black, 50, 60, 10, 100, COLORED);
    epd.draw_circle(frame_black, 80, 80, 15, COLORED);
    epd.draw_filled_rectangle(frame_red, 10, 120, 50, 180, COLORED);
    epd.draw_filled_rectangle(frame_red, 0, 6, 128, 26, COLORED);
    epd.draw_filled_circle(frame_red, 80, 150, 15, COLORED);
    """

    # write strings to the buffer
    """
    font = ImageFont.truetype('/usr/share/fonts/truetype/freefont/FreeMono.ttf', 12)
    epd.draw_string_at(frame_black, 4, 30, "Saturday, June 30th", font, COLORED)
    epd.draw_string_at(frame_red, 6, 10, "Hi Caitie!!!", font, UNCOLORED)
    # display the frames
    epd.display_frame(frame_black, frame_red)
    """

    # display images
    """
    frame_black = epd.get_frame_buffer(Image.open('black.bmp'))
    frame_red = epd.get_frame_buffer(Image.open('red.bmp'))
    epd.display_frame(frame_black, frame_red)
    """
    # My Image Tests
    """
Exemplo n.º 18
0
def main():

    epd = epd2in13b.EPD()
    epd.init()

    # clear the frame buffer
    frame_black = [0xFF] * int(epd.width * epd.height / 8)
    frame_red = [0xFF] * int(epd.width * epd.height / 8)

    # display images
    #frame_black = epd.get_frame_buffer(Image.open('black.bmp'))
    frame_red = epd.get_frame_buffer(Image.open('black.bmp'))
    epd.display_frame(frame_black, frame_red)

    # You can get frame buffer from an image or import the buffer directly:
    #epd.display_frame(imagedata.IMAGE_BLACK, imagedata.IMAGE_RED)
    # clear the frame buffer
    #frame_black = [0xFF] * int(epd.width * epd.height / 8)
    #frame_red = [0xFF] * int(epd.width * epd.height / 8)
    epd.set_rotate(1)
    font = ImageFont.truetype('/usr/share/fonts/truetype/wyq/wqy-microhei.ttc',
                              16)

    #start to get air data
    ser = serial.Serial('/dev/ttyAMA0', 9600, timeout=1)
    print(ser.port)
    print(ser.baudrate)
    refreshlcd = 0
    data = []
    try:
        while True:
            print("----------------------------------------------")
            datalen = ser.inWaiting()
            #print ("datalen:", datalen)
            if datalen != 0:
                #Read
                data = ser.read(datalen)
                ser.flushInput()
                #print 'received:', data
                bit_head = data[0]
                bit_funcd = data[1]
                bit_len = data[2]
                int_CO2_H = int.from_bytes(data[3:4], byteorder='big')
                int_CO2_L = int.from_bytes(data[4:5], byteorder='big')
                co2 = int_CO2_H * 256 + int_CO2_L
                int_TVOC_H = int.from_bytes(data[5:6], byteorder='big')
                int_TVOC_L = int.from_bytes(data[6:7], byteorder='big')
                tvoc = (int_TVOC_H * 256 + int_TVOC_L) / 10.0
                int_CH2O_H = int.from_bytes(data[7:8], byteorder='big')
                int_CH2O_L = int.from_bytes(data[8:9], byteorder='big')
                ch2o = (int_CH2O_H * 256 + int_CH2O_L) / 10.0
                int_PM25_H = int.from_bytes(data[9:10], byteorder='big')
                int_PM25_L = int.from_bytes(data[10:11], byteorder='big')
                pm25 = int_PM25_H * 256 + int_PM25_L
                int_humidity_H = int.from_bytes(data[11:12], byteorder='big')
                int_humidity_L = int.from_bytes(data[12:13], byteorder='big')
                humidity = Decimal(-6 + 125 *
                                   (int_humidity_H * 256 + int_humidity_L) /
                                   (2**16)).quantize(Decimal('0.0'))
                int_temp_H = int.from_bytes(data[13:14], byteorder='big')
                int_temp_L = int.from_bytes(data[14:15], byteorder='big')
                temperature = Decimal(-46.84 + 175.72 *
                                      (int_temp_H * 256 + int_temp_L) /
                                      (2**16)).quantize(Decimal('0.0'))
                int_PM10_H = int.from_bytes(data[15:16], byteorder='big')
                int_PM10_L = int.from_bytes(data[16:17], byteorder='big')
                pm10 = int_PM10_H * 256 + int_PM10_L
                print("温度(0C)", temperature)
                print("湿度(%RH)", humidity)
                print("PM2.5(ug/m3):", pm25)
                print("PM10:", pm10)
                print("甲醛CH2O(ug/m3):", ch2o)
                print("总挥发性有机物TVOC(ug/m3):", tvoc)
                print("二氧化碳CO2(ppm):", co2)
                time.sleep(1)
                refreshlcd = refreshlcd + 1
                if refreshlcd >= 10:
                    refreshlcd = 0
                    # write strings to the buffer
                    # clear the frame buffer
                    frame_black = [0xFF] * int(epd.width * epd.height / 8)
                    #frame_red = [0xFF] * int(epd.width * epd.height / 8)
                    epd.draw_string_at(frame_black, 100, 2,
                                       u'PM2.5: ' + str(pm25), font, COLORED)
                    epd.draw_string_at(frame_black, 2, 27,
                                       u'温度: ' + str(temperature), font,
                                       COLORED)
                    epd.draw_string_at(frame_black, 100, 27,
                                       u'湿度: ' + str(humidity) + '%', font,
                                       COLORED)
                    epd.draw_string_at(frame_black, 2, 52, u'甲醛: ' + str(ch2o),
                                       font, COLORED)
                    epd.draw_string_at(frame_black, 100, 52,
                                       u'PM10:' + str(pm10), font, COLORED)
                    epd.draw_string_at(frame_black, 2, 77,
                                       u'TVOC: ' + str(tvoc), font, COLORED)
                    epd.draw_string_at(frame_black, 100, 77,
                                       u'二氧化碳: ' + str(co2), font, COLORED)
                    # display the frames
                    epd.display_frame(frame_black, frame_red)
    except KeyboardInterrupt:
        if ser != None:
            ser.close()

    if ser != None:
        ser.close()
Exemplo n.º 19
0
 def __init__(self):
     self.epd = epd2in13b.EPD()
     self.epd.init()