You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
105 lines
3.3 KiB
105 lines
3.3 KiB
2 years ago
|
#!/usr/bin/python3
|
||
|
# -*- coding:utf-8 -*-
|
||
|
|
||
|
# secrets.py:
|
||
|
# octoprint="https://your.octoprint.ip.address.or.domain.name"
|
||
|
# apikey="your-octoprint-api-key"
|
||
|
|
||
|
from secrets import *
|
||
|
|
||
|
pluginpath="plugin/DisplayLayerProgress/values"
|
||
|
fullurl=f"{octoprint}/{pluginpath}?apikey={apikey}"
|
||
|
|
||
|
# CODED FOR WAVESHARE 4.2" 400x300 B&W ePaper Display
|
||
|
# Requires the DisplayLayerProgress plugin
|
||
|
# https://github.com/OllisGit/OctoPrint-DisplayLayerProgress
|
||
|
|
||
|
import sys
|
||
|
import os
|
||
|
import json
|
||
|
import requests
|
||
|
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):
|
||
|
sys.path.append(libdir)
|
||
|
|
||
|
import logging
|
||
|
from waveshare_epd import epd4in2
|
||
|
import time
|
||
|
from PIL import Image,ImageDraw,ImageFont
|
||
|
import traceback
|
||
|
|
||
|
# https://stackoverflow.com/a/32282390
|
||
|
from urllib3.exceptions import InsecureRequestWarning
|
||
|
requests.packages.urllib3.disable_warnings(category=InsecureRequestWarning)
|
||
|
|
||
|
logging.basicConfig(level=logging.DEBUG)
|
||
|
|
||
|
def getData():
|
||
|
jsondata=requests.get(fullurl, verify=False).json()
|
||
|
jobdata={
|
||
|
"file":jsondata["currentFilename"],
|
||
|
"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
|
||
|
|
||
|
print(getData())
|
||
|
sys.exit(0)
|
||
|
try:
|
||
|
logging.info("Octopi print monitor starting...")
|
||
|
|
||
|
epd = epd4in2.EPD()
|
||
|
logging.info("init and Clear")
|
||
|
epd.init()
|
||
|
epd.Clear()
|
||
|
|
||
|
font18 = ImageFont.truetype(os.path.join(imgdir, 'Font.ttc'), 18)
|
||
|
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)
|
||
|
|
||
|
# 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'))
|
||
|
# Himage2.paste(bmp, (50,10))
|
||
|
# epd.display(epd.getbuffer(Himage2))
|
||
|
# time.sleep(2)
|
||
|
|
||
|
epd.Clear()
|
||
|
logging.info("Goto Sleep...")
|
||
|
epd.sleep()
|
||
|
|
||
|
except IOError as e:
|
||
|
logging.info(e)
|
||
|
|
||
|
except KeyboardInterrupt:
|
||
|
logging.info("ctrl + c:")
|
||
|
epd4in2.epdconfig.module_exit()
|
||
|
exit()
|