Skip to content
Snippets Groups Projects
Commit 8b6b23b9 authored by Tobias Ullerich's avatar Tobias Ullerich
Browse files

Extract Image classes into separated file; improve lib imports

parent 73fca131
No related branches found
No related tags found
No related merge requests found
Showing
with 72 additions and 73 deletions
#!/usr/bin/python
# -*- coding:utf-8 -*-
import sys
import os
picdir = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'lib/pic')
libdir = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'lib/lib')
if os.path.exists(libdir):
sys.path.append(libdir)
import logging
from waveshare_epd import epd4in2bc
import time
from PIL import Image, ImageDraw, ImageFont
import sys
from PIL import Image, ImageDraw
class AbstractImage:
......@@ -101,60 +86,3 @@ class DebugImage(AbstractImage):
def get_red_image(self):
return self.__image
logging.basicConfig(level=logging.DEBUG)
# python3 test.py debug
debugMode = sys.argv[1] == "debug" if len(sys.argv) == 2 else False
if debugMode:
logging.warning("Running in debug mode")
try:
epd = epd4in2bc.EPD()
image = DebugImage(epd.width, epd.height)
if not debugMode:
logging.info("init and Clear")
epd.init()
epd.Clear()
time.sleep(1)
image = EPDImage(epd.width, epd.height)
font24 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 24)
font18 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 18)
blackImage = Image.new('1', (epd.width, epd.height), 255) # 298*126
redImage = Image.new('1', (epd.width, epd.height), 255) # 298*126 ryimage: red or yellow image
drawBlack = ImageDraw.Draw(blackImage)
drawRed = ImageDraw.Draw(redImage)
if debugMode:
drawRed = drawBlack
image.text((10, 0), 'Jenkins Build Status', font=font24, fill=AbstractImage.BLACK)
image.line((20, 50, 70, 100), fill=AbstractImage.BLACK)
image.line((70, 50, 20, 100), fill=AbstractImage.BLACK)
image.rectangle((20, 50, 70, 100), outline=0, fill=AbstractImage.BLACK)
image.line((165, 50, 165, 100), fill=AbstractImage.RED)
image.line((140, 75, 190, 75), fill=AbstractImage.RED)
image.rectangle((80, 50, 130, 100), outline=0, fill=AbstractImage.RED)
if debugMode:
image.get_black_image().save("img.png")
else:
epd.display(epd.getbuffer(image.get_black_image()), epd.getbuffer(image.get_red_image()))
time.sleep(2)
logging.info("Goto Sleep...")
if not debugMode:
epd.sleep()
except IOError as e:
logging.info(e)
except KeyboardInterrupt:
logging.info("ctrl + c:")
epd4in2bc.epdconfig.module_exit()
exit()
#!/usr/bin/python
# -*- coding:utf-8 -*-
import sys
import os
import logging
import time
import sys
from PIL import Image, ImageDraw, ImageFont
from libs.lib.waveshare_epd import epd4in2bc
from Image import DebugImage, EPDImage, AbstractImage
logging.basicConfig(level=logging.DEBUG)
# python3 Main.py debug
debugMode = sys.argv[1] == "debug" if len(sys.argv) == 2 else False
if debugMode:
logging.warning("Running in debug mode")
try:
epd = epd4in2bc.EPD()
image = DebugImage(epd.width, epd.height)
if not debugMode:
logging.info("init and Clear")
epd.init()
epd.Clear()
time.sleep(1)
image = EPDImage(epd.width, epd.height)
picdir = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'libs/pic')
font24 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 24)
font18 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 18)
blackImage = Image.new('1', (epd.width, epd.height), 255) # 298*126
redImage = Image.new('1', (epd.width, epd.height), 255) # 298*126 ryimage: red or yellow image
drawBlack = ImageDraw.Draw(blackImage)
drawRed = ImageDraw.Draw(redImage)
if debugMode:
drawRed = drawBlack
image.text((10, 0), 'Jenkins Build Status', font=font24, fill=AbstractImage.BLACK)
image.line((20, 50, 70, 100), fill=AbstractImage.BLACK)
image.line((70, 50, 20, 100), fill=AbstractImage.BLACK)
image.rectangle((20, 50, 70, 100), outline=0, fill=AbstractImage.BLACK)
image.line((165, 50, 165, 100), fill=AbstractImage.RED)
image.line((140, 75, 190, 75), fill=AbstractImage.RED)
image.rectangle((80, 50, 130, 100), outline=0, fill=AbstractImage.RED)
if debugMode:
image.get_black_image().save("img.png")
else:
epd.display(epd.getbuffer(image.get_black_image()), epd.getbuffer(image.get_red_image()))
time.sleep(2)
logging.info("Goto Sleep...")
if not debugMode:
epd.sleep()
except IOError as e:
logging.info(e)
except KeyboardInterrupt:
logging.info("ctrl + c:")
epd4in2bc.epdconfig.module_exit()
exit()
File moved
File moved
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment