diff --git a/img/backgroundv1.bmp b/img/backgroundv1.bmp new file mode 100644 index 0000000..c34a234 Binary files /dev/null and b/img/backgroundv1.bmp differ diff --git a/img/backgroundv2.bmp b/img/backgroundv2.bmp new file mode 100644 index 0000000..b3e6eb6 Binary files /dev/null and b/img/backgroundv2.bmp differ diff --git a/octomonitor.py b/octomonitor.py index 5240b6a..3032537 100644 --- a/octomonitor.py +++ b/octomonitor.py @@ -8,7 +8,9 @@ from secrets import * pluginpath="plugin/DisplayLayerProgress/values" +printerpath="api/printer" fullurl=f"{octoprint}/{pluginpath}?apikey={apikey}" +fullurltwo=f"{octoprint}/{printerpath}?apikey={apikey}" # CODED FOR WAVESHARE 4.2" 400x300 B&W ePaper Display # Requires the DisplayLayerProgress plugin @@ -16,8 +18,7 @@ fullurl=f"{octoprint}/{pluginpath}?apikey={apikey}" import sys import os -import json -import requests +import requests,datetime imgdir = "/home/pi/epaper/img"#os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))), 'img')#dontask libdir = "/home/pi/epaper/lib"#os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))), 'lib') if os.path.exists(libdir): @@ -34,56 +35,82 @@ from urllib3.exceptions import InsecureRequestWarning requests.packages.urllib3.disable_warnings(category=InsecureRequestWarning) logging.basicConfig(level=logging.DEBUG) +#logging.basicConfig(level=logging.INFO) + +def timestr(time): + return f"{datestr(time)} {time.hour:02}:{time.minute:02}" +def datestr(time): + return f"{time.year}-{time.month:02}-{time.day:02}" def getData(): jsondata=requests.get(fullurl, verify=False).json() + jsondatatwo=requests.get(fullurltwo, verify=False).json() jobdata={ - "file":jsondata["currentFilename"], + "file":jsondata["currentFilename"].split('/')[-1], "layer":jsondata["layer"]["current"], "layers":jsondata["layer"]["total"], "lastlayertime":jsondata["layer"]["lastLayerDuration"], "percent":jsondata["print"]["progress"], "eta":jsondata["print"]["timeLeft"], - "remaining":jsondata["print"]["timeLeftInSeconds"] } - return jobdata + "remaining":jsondata["print"]["timeLeftInSeconds"], + "bedtemp":jsondatatwo["temperature"]["bed"]["actual"], + "bedtarget":jsondatatwo["temperature"]["bed"]["target"], + "temp":jsondatatwo["temperature"]["tool0"]["actual"], + "target":jsondatatwo["temperature"]["tool0"]["target"], + } + return (jobdata,datetime.datetime.now()) -print(getData()) -sys.exit(0) try: -logging.info("Octopi print monitor starting...") - + logging.info("Octopi print monitor starting...") + # INIT epd = epd4in2.EPD() logging.info("init and Clear") epd.init() epd.Clear() + font14 = ImageFont.truetype(os.path.join(imgdir, 'Font.ttc'), 14) + font16 = ImageFont.truetype(os.path.join(imgdir, 'Font.ttc'), 16) font18 = ImageFont.truetype(os.path.join(imgdir, 'Font.ttc'), 18) + font20 = ImageFont.truetype(os.path.join(imgdir, 'Font.ttc'), 20) font24 = ImageFont.truetype(os.path.join(imgdir, 'Font.ttc'), 24) - font35 = ImageFont.truetype(os.path.join(imgdir, 'Font.ttc'), 35) - - # Drawing on the Horizontal image - logging.info("1.Drawing on the Horizontal image...") - Himage = Image.new('1', (epd.width, epd.height), 255) # 255: clear the frame - draw = ImageDraw.Draw(Himage) - draw.text((10, 0), 'hello world', font = font24, fill = 0) - draw.text((10, 20), '4.2inch e-Paper', font = font24, fill = 0) - draw.text((150, 0), u'微雪电子', font = font24, fill = 0) - draw.line((20, 50, 70, 100), fill = 0) - draw.line((70, 50, 20, 100), fill = 0) - draw.rectangle((20, 50, 70, 100), outline = 0) - draw.line((165, 50, 165, 100), fill = 0) - draw.line((140, 75, 190, 75), fill = 0) - draw.arc((140, 50, 190, 100), 0, 360, fill = 0) - draw.rectangle((80, 50, 130, 100), fill = 0) - draw.chord((200, 50, 250, 100), 0, 360, fill = 0) - epd.display(epd.getbuffer(Himage)) - time.sleep(2) - -# logging.info("3.read bmp file") -# Himage = Image.open(os.path.join(imgdir, '4in2.bmp')) -# epd.display(epd.getbuffer(Himage)) -# time.sleep(2) - + # LOCS + # filename (60,6) file + # percent (125,45) percent + # eta (265,45) eta + # layer (125,85) layer + # total (125,125) layers + # lastlayer (125,162) lastlayertime + # lastupdate (117,250) + # lastrefresh (117,278) + + # MONITOR LOOP + while True: + (jobdata,lastupdate)=getData() + paper = Image.new('1', (epd.width, epd.height), 255) # 255: clear the frame + draw = ImageDraw.Draw(paper) + # LOAD OUR BACKGROUND + bg = Image.open(os.path.join(imgdir, 'backgroundv2.bmp')) + paper.paste(bg, (0, 0)) + # ADD OUR TEXT + if len(jobdata['file']) < 20: + draw.text((60, 6), jobdata['file'], font = font18, fill = 0) + else: + draw.text((60, 1), jobdata['file'][0:35], font = font18, fill = 0) + draw.text((60, 17), jobdata['file'][35:70], font = font18, fill = 0) + draw.text((125,42), f"{jobdata['percent']}%", font=font24, fill=0) + draw.text((268,42),jobdata['eta'],font=font24,fill=0) + draw.text((125,82),jobdata['layer'],font=font24,fill=0) + draw.text((125,122),jobdata['layers'],font=font24,fill=0) + draw.text((125,162),jobdata['lastlayertime'],font=font20,fill=0) + draw.text((117,250),timestr(lastupdate),font=font14,fill=0) + draw.text((117,278),timestr(datetime.datetime.now()),font=font14,fill=0) + # (240,82) under ETA + draw.text((25,228),f"{jobdata['bedtemp']}°c/{jobdata['bedtarget']}°c {jobdata['temp']}°c/{jobdata['target']}°c",font=font14,fill=0) + # DISPLAY OUR MASTERPIECE + epd.display(epd.getbuffer(paper)) + epd.sleep() + #time.sleep(30) + sys.exit(0) # logging.info("4.read bmp file on window") # Himage2 = Image.new('1', (epd.height, epd.width), 255) # 255: clear the frame # bmp = Image.open(os.path.join(imgdir, '100x100.bmp')) @@ -91,9 +118,6 @@ logging.info("Octopi print monitor starting...") # epd.display(epd.getbuffer(Himage2)) # time.sleep(2) - epd.Clear() - logging.info("Goto Sleep...") - epd.sleep() except IOError as e: logging.info(e)