ScottSturdivant / rpi_metar

METAR LED Display for a Raspberry Pi
MIT License
26 stars 16 forks source link

Add I2C OLED Displays for METARs #25

Open thommo17 opened 3 years ago

thommo17 commented 3 years ago

G'day Scott,

I've been working to try and add some little OLED I2C screens like this

https://www.livesectional.com/oled-displays-add-on/

So far it's only in early testing. I've been using Luma.OLED and PIL.

I can get text to scroll across the screen so far but eventually I want each screen to be configured through the the config file to only show one METAR from a selected airport and update alongside the rest of the code every 5 minutes.

What do you think?

import time
from demo_opts import get_device
from luma.core.virtual import viewport
from luma.core.render import canvas
from PIL import Image, ImageDraw, ImageFont

metar = 'METAR YBBN 080000Z 15006KT 110V190 9999 FEW049 22/11 Q1030'

def main():
    fnt = ImageFont.truetype("Pillow/Tests/fonts/FreeMono.ttf", 28)
    x = device.width

    # First measure the text size
    with canvas(device) as draw:
        w, h = draw.textsize(metar, fnt)

    virtual = viewport(device, width=max(device.width, w + x + x), height=max(h, device.height))

    for _ in range(2):
        with canvas(virtual) as draw:
            for i, line in enumerate(metar.split("\n")):
                draw.text((0 + (i * 10), 0), font=fnt, text=line, fill="white")

    time.sleep(2)

    # update the viewport one position below, causing a refresh,
    # giving a rolling up scroll effect when done repeatedly
    for x in range(int(w / 2)):
        virtual.set_position((x * 2, 0))
        time.sleep(0.01)

while __name__ == "__main__":
    try:
        device = get_device()
        main()
    except ValueError:
        print('OLED not found!')
thommo17 commented 2 years ago

I also just found the code Live Sectional uses for their OLED's

Maybe we can reverse engineer it to add to our code

https://github.com/markyharris/livesectional/blob/master/metar-display-v4.py