This commit is contained in:
2024-01-19 22:33:44 +01:00
parent 2b77fd723c
commit 72fcc76327
3 changed files with 100 additions and 78 deletions
+48
View File
@@ -0,0 +1,48 @@
from PIL import Image,ImageDraw,ImageFont,ImageShow
from random import randint, choice
import time
class Sheogorath:
def __init__(self):
self.width = 122
self.height = 250
try:
self.lyrics = open("lyrics.txt", "r").readlines()
except FileNotFoundError:
self.lyrics = ["Lyrics not found"]
try:
self.sheo = Image.open('res/sheo1.bmp')
except FileNotFoundError:
self.sheo = Image.new('1', (122, 122))
try:
self.font15 = ImageFont.truetype('res/Font.ttc', 15)
self.font24 = ImageFont.truetype('res/Font.ttc', 24)
except FileNotFoundError:
self.font15 = None
self.font24 = None
def get_lyric(self, max_length = 17):
lyrics = open("lyrics.txt", "r").readlines()
lyric = choice(self.lyrics)
out_lyric = ""
counter = 0
for word in lyric.split(" "):
if counter + len(word) < max_length:
counter += len(word) + 1
out_lyric += word + " "
else:
counter = len(word) + 1
out_lyric += "\n" + word + " "
return out_lyric
def get_frame(self):
time_image = Image.new('1', (self.height, self.width), 255)
time_draw = ImageDraw.Draw(time_image)
x = randint(0, 40)
lyric = self.get_lyric((300-x)//15)
time_image.paste(self.sheo, (x,randint(0, 10)))
time_draw.rectangle((160, 90, 250, 122), fill = 255)
if self.font15 and self.font24:
time_draw.text((185, 90), time.strftime('%H:%M'), font = self.font24, fill = 0)
time_draw.text((100+x, 5), lyric, font = self.font15, fill = 0)
return time_image
+20
View File
@@ -0,0 +1,20 @@
from PIL import ImageShow
class EPDummy:
def __init__(self):
self.width = 122
self.height = 250
FULL_UPDATE = 0
PART_UPDATE = 1
def display(self, image):
ImageShow.show(image)
def displayPartial(self, image):
ImageShow.show(image)
def displayPartBaseImage(self, image):
ImageShow.show(image)
def init(self, a):
pass
def Clear(self, a):
pass
def getbuffer(self, image):
return image
+30 -76
View File
@@ -2,105 +2,59 @@
# -*- coding:utf-8 -*- # -*- coding:utf-8 -*-
import sys import sys
import os import os
import logging
import time import time
import traceback import traceback
import argparse import argparse
from random import randint, choice from random import randint, choice
from PIL import Image,ImageDraw,ImageFont,ImageShow from PIL import Image,ImageDraw,ImageFont,ImageShow
from lib import application
from lib import epdummy
parser = argparse.ArgumentParser(description='e-Ink Sheogorath') parser = argparse.ArgumentParser(description='e-Ink Sheogorath')
parser.add_argument('--debug', action='store_true', help='If true, does not initialize e-Ink, shows images in window') parser.add_argument('--debug', action='store_true', help='If true, does not initialize e-Ink, shows images in window')
parser.add_argument('-d', '--delay', default=45, help='Delay between frames in seconds')
parser.add_argument('-r', '--refresh', default=10, help='Amount of frames after which to refresh the screen')
args = parser.parse_args() args = parser.parse_args()
logging.basicConfig(level=logging.DEBUG) epd = epdummy.EPDummy()
class EPDummy:
def __init__(self):
self.width = 122
self.height = 250
FULL_UPDATE = 0
PART_UPDATE = 1
def display(self, image):
ImageShow.show(image)
def displayPartial(self, image):
ImageShow.show(image)
def displayPartBaseImage(self, image):
ImageShow.show(image)
def init(self, a):
pass
def Clear(self, a):
pass
def getbuffer(self, image):
return image
epd = EPDummy()
if not args.debug: if not args.debug:
from lib import epd2in13_V2 from lib import epd2in13_V2
epd = epd2in13_V2.EPD() epd = epd2in13_V2.EPD()
app = application.Sheogorath()
try:
DELAY = int(args.delay)
except ValueError:
DELAY = 45
try:
N_REFRESH = int(args.refresh)
except ValueError:
N_REFRESH = 10
try: try:
logging.info("Sheogorath.")
epd.init(epd.FULL_UPDATE) epd.init(epd.FULL_UPDATE)
epd.Clear(0xFF) epd.Clear(0xFF)
font15 = ImageFont.truetype('res/Font.ttc', 15)
font24 = ImageFont.truetype('res/Font.ttc', 24)
image = Image.new('1', (epd.height, epd.width), 255)
draw = ImageDraw.Draw(image)
draw.rectangle([(0,0),(50,50)],outline = 0)
draw.rectangle([(55,0),(100,50)],fill = 0)
draw.line([(0,0),(50,50)], fill = 0,width = 1)
draw.line([(0,50),(50,0)], fill = 0,width = 1)
draw.chord((10, 60, 50, 100), 0, 360, fill = 0)
draw.ellipse((55, 60, 95, 100), outline = 0)
draw.pieslice((55, 60, 95, 100), 90, 180, outline = 0)
draw.pieslice((55, 60, 95, 100), 270, 360, fill = 0)
draw.polygon([(110,0),(110,50),(150,25)],outline = 0)
draw.polygon([(190,0),(190,50),(150,25)],fill = 0)
draw.text((120, 60), 'e-Paper demo', font = font15, fill = 0)
draw.text((110, 90), u'', font = font24, fill = 0)
# read bmp file on window # read bmp file on window
logging.info("3.read bmp file on window...")
epd.Clear(0xFF) epd.Clear(0xFF)
#image1 = Image.new('1', (epd.height, epd.width), 255) # 255: clear the frame
bmp = Image.open('res/sheo1.bmp')
#epd.init(epd.FULL_UPDATE)
#epd.displayPartBaseImage(epd.getbuffer(time_image))
epd.init(epd.PART_UPDATE) epd.init(epd.PART_UPDATE)
lyrics = open("lyrics.txt", "r").readlines() n = 0
def get_lyric(max_length = 17):
print(max_length)
lyric = choice(lyrics)
out_lyric = ""
counter = 0
for word in lyric.split(" "):
if counter + len(word) < max_length:
counter += len(word) + 1
out_lyric += word + " "
else:
counter = len(word) + 1
out_lyric += "\n" + word + " "
return out_lyric
while (True): while (True):
time_image = Image.new('1', (epd.height, epd.width), 255) n += 1
time_draw = ImageDraw.Draw(time_image) if n is N_REFRESH:
x = randint(0, 40) epd.init(epd.FULL_UPDATE)
lyric = get_lyric((300-x)//15) epd.Clear(0xFF)
time_image.paste(bmp, (x,randint(0, 10))) epd.Clear(0xFF)
time_draw.rectangle((160, 90, 250, 122), fill = 255) n = 0
time_draw.text((185, 90), time.strftime('%H:%M'), font = font24, fill = 0) time.sleep(1)
time_draw.text((100+x, 5), lyric, font = font15, fill = 0) epd.init(epd.PART_UPDATE)
epd.displayPartial(epd.getbuffer(time_image)) frame = epd.getbuffer(app.get_frame())
epd.displayPartial(epd.getbuffer(time_image)) epd.displayPartial(frame)
time.sleep(30) epd.displayPartial(frame)
except IOError as e: time.sleep(DELAY)
logging.info(e)
except KeyboardInterrupt: except KeyboardInterrupt:
logging.info("ctrl + c:") if not args.debug:
epd2in13_V2.epdconfig.module_exit(cleanup=True) epd2in13_V2.epdconfig.module_exit(cleanup=True)
exit() exit()