def __init__(self, config, logFilename = None, syslog = None): logging.basicConfig(filename=syslog, level=logging.DEBUG) self.lastNetworkFailure = True self.lastDomoticzFailure = True self.lastBrokenDependencies = [] self.networkFailure = False self.domoticzFailure = True self.iconSize = 20 self.networkIcon = Image.open("/home/wim/projects/therminator/images/network.png").resize((self.iconSize, self.iconSize)) self.domoticzIcon = Image.open("/home/wim/projects/therminator/images/domoticz.png").resize((self.iconSize, self.iconSize)) self.connectorIcon = Image.open("/home/wim/projects/therminator/images/connector.png").resize((self.iconSize, self.iconSize)) self.monitorIcon = Image.open("/home/wim/projects/therminator/images/monitor.png").resize((self.iconSize, self.iconSize)) self.thermostatIcon = Image.open("/home/wim/projects/therminator/images/thermostat.png").resize((self.iconSize, self.iconSize)) self.isSleeping = False self.epd = epd7in5bc.EPD() self.epd.init() self.epd.Clear() self.WHITE = 1 self.BLACK = 0 super().__init__(config, logFilename, syslog) self.pingTopic = "therminator/in/ping" self.client.subscribe(self, [(self.pingTopic, 2)]) self.networkFailure = not self.ping("192.168.0.183") self.client.publish("therminator/request", "ping") time.sleep(30) self.fullUpdate = True self.update() initCount = 0 while True: time.sleep(self.fullUpdateInterval) self.fullUpdate = True doUpdate = False if self.lastNetworkFailure != self.networkFailure: logging.debug("{:} Network status changed to {:}".format(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), self.networkFailure)) doUpdate = True self.lastNetworkFailure = self.networkFailure if self.lastDomoticzFailure != self.domoticzFailure: logging.debug("{:} Domoticz status changed to {:}".format(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), self.domoticzFailure)) doUpdate = True self.lastDomoticzFailure = self.domoticzFailure if self.lastBrokenDependencies != self.watchdog.brokenDependencies: logging.debug("{:} Dependency status changed to {:}".format(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), self.watchdog.brokenDependencies)) doUpdate = True self.lastBrokenDependencies = self.watchdog.brokenDependencies if doUpdate: self.update() time.sleep(10) self.networkFailure = not self.ping("192.168.0.183") logging.debug("{:} Network status : {:}".format(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), not self.networkFailure)) self.domoticzFailure = True logging.debug("{:} Requesting ping".format(datetime.now().strftime("%Y-%m-%d %H:%M:%S"))) self.client.publish("therminator/request", "ping")
def write_to_screen(image, sleep_seconds): logging.info("Weather Display") epd = epd7in5bc.EPD() h_image = Image.new('1', (epd.width, epd.height), 255) hr_image = Image.new('1', (epd.width, epd.height), 255) # Open the template screen_output_file = Image.open(os.path.join(picdir, image)) # Initialize the drawing context with template as background h_image.paste(screen_output_file, (0, 0)) epd.display(epd.getbuffer(h_image), epd.getbuffer(hr_image)) # Sleep print('Sleeping for ' + str(sleep_seconds) + '.') time.sleep(sleep_seconds)
import pytz import io import screen import os, sys libdir = "/home/pi/e-Paper/RaspberryPi_JetsonNano/python/lib/" sys.path.append(libdir) from waveshare_epd import epd7in5bc if __name__ == '__main__': """ Draw the current time """ try: epd = epd7in5bc.EPD() epd.init() epd.Clear() timestamp = datetime.now(pytz.timezone('Europe/Copenhagen')) HBlackimage, HRYimage = screen.get_image() buffer_bw = epd.getbuffer(HBlackimage) buffer_r = epd.getbuffer(HRYimage) epd.display(buffer_bw, buffer_r) time.sleep(2) except Exception as e: print("Failed to render", e)
def drawpic(head, state, qrcode, todaytime): try: try: img_src1 = head.decode('utf-8','strict') response1 = req.get(img_src1) image_head = Image.open(BytesIO(response1.content)) except: image_head = Image.open(os.path.join(picdir, error)) try: img_src2 = qrcode.decode('utf-8','strict') response2 = req.get(img_src2) image_QRcode = Image.open(BytesIO(response2.content)) except: image_QRcode = Image.open(os.path.join(picdir, error)) try: state = state.decode('utf-8','strict') stateimage = Image.open(os.path.join(picdir, state)) except: stateimage = Image.open(os.path.join(picdir, error)) image_QRcode = image_QRcode.resize((x_QRcode,y_QRcode), Image.ANTIALIAS) stateimage = stateimage.resize((x_state,y_state), Image.ANTIALIAS) image_head = image_head.resize((x_head,y_head), Image.ANTIALIAS) epd = epd7in5bc.EPD() epd.init() print("Clear") epd.Clear() #Drawing on the Horizontal image HBlackimage = Image.new('1', (epd.width, epd.height), 255) HRedimage = Image.new('1', (epd.width, epd.height), 255) #horizontal print("Drawing") drawblack = ImageDraw.Draw(HBlackimage) drawred = ImageDraw.Draw(HRedimage) font24 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 24) print("Drawline") drawblack.line(((0,0), (0,383)), fill=0, width=5) drawblack.line(((0,0), (639,0)), fill=0, width=5) drawblack.line(((639,383), (0,383)), fill=0, width=5) drawblack.line(((639,0), (639,383)), fill=0, width=5) drawblack.line(((319,0), (319,383)), fill=0, width=5) drawblack.line(((0,283), (319,283)), fill=0, width=5) drawblack.line(((319,233), (639,233)), fill=0, width=5) #headpic print("head") HBlackimage.paste(image_head, (0,0)) #data print("date") font18 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 18) drawblack.text((70, 323), todaytime, font=font18, fill=0) #state print("state") drawblack.text((339,20), 'state', font=font18, fill=0) HBlackimage.paste(stateimage, (420,110)) if state=="1": drawblack.text((400,80), u'暫時外出', font=font18, fill=0) elif state=="2": drawblack.text((400,80), u'休假中', font=font18, fill=0) elif state=="3": drawblack.text((400,80), u'請留言', font=font18, fill=0) elif state=="4": drawblack.text((400,80), u'會議中', font=font18, fill=0) elif state=="5": drawblack.text((400,80), u'敲門請進', font=font18, fill=0) else: drawblack.text((400,80), state, font=font18, fill=0) #QRCODE print("QRCODE") drawblack.text((339,263), u'聯絡老師', font=font18, fill=0) HBlackimage.paste(image_QRcode, (450,240)) epd.display(epd.getbuffer(HBlackimage), epd.getbuffer(HRedimage)) except IOError as e: logging.info(e) except KeyboardInterrupt: logging.info("ctrl + c:") epd7in5bc.epdconfig.module_exit() exit()