def run(self): if self.test_mode: images = self._generate_image() color_images = [ ImageOps.colorize(image.convert('L'), black=color, white=(255, 255, 255)) for image, color in zip(images, COLOR_LIST) ] image = Image.composite(color_images[0], color_images[1], images[1]) image.save('test.png') else: update_interval = self.config.get('update_interval', 0) epaper = epd.EPD() while True: time_begin = time.time() log.info('generating image') images = self._generate_image() buf = [epaper.getbuffer(image) for image in images] log.info('updating e-paper') epaper.init() epaper.display(*buf) epaper.sleep() time_elapsed = time.time() - time_begin log.info('update done. elapsed: %f sec' % time_elapsed) if update_interval == -1: return if time_elapsed < update_interval: time.sleep(update_interval - time_elapsed)
def main(): if (not args.debug): epd = epd7in5b.EPD() epd.init() events = [] if args.dataFilePath != None: fileData = load_json(args.dataFilePath) if 'events' in fileData and fileData['events'] != None: events += remove_past_events(fileData['events']) connpass_events = get_connpass_events(CONNPASS_GROUP_ID) if connpass_events != None: events += connpass_events events = sort_events(events) image_red = Image.new('1', (EPD_WIDTH, EPD_HEIGHT), 255) # 255: clear the frame draw_red = ImageDraw.Draw(image_red) image_black = Image.new('1', (EPD_WIDTH, EPD_HEIGHT), 255) # 255: clear the frame draw_black = ImageDraw.Draw(image_black) line_y = 0 line_x = 10 time_line_x = 200 first_line_step = 53 second_line_step = 100 font_size = 45 font = ImageFont.truetype('/usr/share/fonts/opentype/noto/NotoSansCJK-Bold.ttc', font_size) max_event_count = 2 line_y = draw_events(draw_black, font, events, line_x, line_y, first_line_step, second_line_step, max_event_count) draw_last_line(draw_black, font, len(events), line_x, time_line_x, line_y, max_event_count) if (not args.debug): epd.display_frame(epd.get_frame_buffer(image_black),epd.get_frame_buffer(image_red)) else: image_black.save('debug.jpg')
def main(): epd = epd7in5b.EPD() epd.init() # For simplicity, the arguments are explicit numerical coordinates image_red = Image.new('1', (EPD_WIDTH, EPD_HEIGHT), 255) # 255: clear the frame draw_red = ImageDraw.Draw(image_red) image_black = Image.new('1', (EPD_WIDTH, EPD_HEIGHT), 255) # 255: clear the frame draw_black = ImageDraw.Draw(image_black) font = ImageFont.truetype( '/usr/share/fonts/truetype/freefont/FreeMonoBold.ttf', 24) draw_red.rectangle((0, 6, 640, 40), fill=0) draw_red.text((200, 10), 'e-Paper demo', font=font, fill=255) draw_red.rectangle((200, 80, 600, 280), fill=0) draw_red.chord((240, 120, 580, 220), 0, 360, fill=255) draw_black.rectangle((20, 80, 160, 280), fill=0) draw_red.chord((40, 80, 180, 220), 0, 360, fill=0) epd.display_frame(epd.get_frame_buffer(image_black), epd.get_frame_buffer(image_red)) # display images frame_black = epd.get_frame_buffer(Image.open('black.bmp')) frame_red = epd.get_frame_buffer(Image.open('red.bmp')) epd.display_frame(frame_black, frame_red)
def welcome(reverse=False): #显示欢迎语 # display images #frame_black = epd.get_frame_buffer(Image.open('background.bmp')) #frame_yellow = epd.get_frame_buffer(Image.open('NULL.bmp')) #epd.display_frame(frame_black,frame_yellow) print("欢迎使用!时间:{}".format( time.strftime('%H:%M:%S', time.localtime(time.time())))) epd = epd7in5b.EPD() epd.init() image_black = Image.new('1', (EPD_WIDTH, EPD_HEIGHT), 255) # 255: clear the frame draw_black = ImageDraw.Draw(image_black) image_yellow = Image.new('1', (EPD_WIDTH, EPD_HEIGHT), 255) # 255: clear the frame draw_yellow = ImageDraw.Draw(image_yellow) font = ImageFont.truetype(Font, 100) draw_black.text((115, 100), '欢迎使用!', font=font, fill=0) font = ImageFont.truetype(Font_bd, 30) draw_yellow.text((240, 240), 'LinWang 制作', font=font, fill=0) draw_black.text((241, 241), 'LinWang 制作', font=font, fill=0) #图像翻转 if reverse == True: image_black = image_black.transpose(Image.ROTATE_180) image_yellow = image_yellow.transpose(Image.ROTATE_180) epd.display_frame(epd.get_frame_buffer(image_black), epd.get_frame_buffer(image_yellow)) print("进入界面。时间:{}".format( time.strftime('%H:%M:%S', time.localtime(time.time()))))
def main(): epd = epd7in5b.EPD() epd.init() # For simplicity, the arguments are explicit numerical coordinates image_red = Image.new('1', (EPD_WIDTH, EPD_HEIGHT), 255) # 255: clear the frame draw_red = ImageDraw.Draw(image_red) image_black = Image.new('1', (EPD_WIDTH, EPD_HEIGHT), 255) # 255: clear the frame draw_black = ImageDraw.Draw(image_black) # font = ImageFont.truetype('/usr/share/fonts/truetype/freefont/FreeMonoBold.ttf', 24) # font = ImageFont.truetype('/usr/share/fonts/truetype/takao-gothic/TakaoPGothic.ttf', 50) font = ImageFont.truetype( '/usr/share/fonts/opentype/noto/NotoSansCJK-Bold.ttc', 45) # draw_red.rectangle((0, 6, 640, 40), fill = 0) # draw_red.text((200, 10), 'e-Paper demo', font = font, fill = 255) draw_black.text((15, 10), "Hello, world. " + u"こんにちは。", font=font, fill=0) draw_red.rectangle((200, 80, 600, 280), fill=0) draw_red.chord((240, 120, 580, 220), 0, 360, fill=255) draw_black.rectangle((20, 80, 160, 280), fill=0) draw_red.chord((40, 80, 180, 220), 0, 360, fill=0) jp_now = datetime.datetime.now(pytz.timezone('Asia/Tokyo')) draw_black.text((15, 300), jp_now.strftime('%m/%d %H:%M ') + u"表示", font=font, fill=0) epd.display_frame(epd.get_frame_buffer(image_black), epd.get_frame_buffer(image_red))
def display(black_image_path, red_image_path): epd = epd7in5b.EPD() epd.init() sleep(5) black_image = Image.open(black_image_path) red_image = Image.open(red_image_path) epd.display(epd.getbuffer(black_image), epd.getbuffer(red_image)) epd.sleep()
def Draw(): # Init board = epd7in5b.EPD() board.init() # Write Display frame_black = board.get_frame_buffer(Image.open('Images/template.pbm')) frame_red = board.get_frame_buffer(Image.open('Images/%s.pbm' % getPath(displayUpdate))) board.display_frame(frame_black, frame_red) # Write to screen
def main(): global project global Debug_Mode; Debug_Mode = 0 global do_screen_update; do_screen_update = 1 global epd; epd = epd7in5b.EPD() if Debug_Mode == 0: epd.init() else: print('-= Debug Mode =-') global todo_response; todo_response = '' global cal_width; cal_width = 240 global line_start; line_start = 48 global weather_reponse global forecast_reponse # All fonts used in frames global font_cal; font_cal = ImageFont.truetype('/usr/share/fonts/truetype/freefont/FreeMonoBold.ttf', 16) global font_day; font_day = ImageFont.truetype('fonts/Roboto-Black.ttf', 110) global font_weather; font_weather = ImageFont.truetype('fonts/Roboto-Black.ttf', 20) global font_day_str; font_day_str = ImageFont.truetype('fonts/Roboto-Light.ttf', 35) global font_month_str; font_month_str = ImageFont.truetype('fonts/Roboto-Light.ttf', 25) global font_weather_icons; font_weather_icons = ImageFont.truetype('fonts/meteocons-webfont.ttf', 45) global font_tasks_list_title; font_tasks_list_title = ImageFont.truetype('fonts/Roboto-Light.ttf', 30) global font_tasks_list; font_tasks_list = ImageFont.truetype('fonts/tahoma.ttf', 12) global font_tasks_due_date; font_tasks_due_date = ImageFont.truetype('fonts/tahoma.ttf', 11) global font_tasks_priority; font_tasks_priority = ImageFont.truetype('fonts/tahoma.ttf', 9) global font_update_moment; font_update_moment = ImageFont.truetype('fonts/tahoma.ttf', 9) global icons_list; icons_list = {u'01d':u'B',u'01n':u'C',u'02d':u'H',u'02n':u'I',u'03d':u'N',u'03n':u'N',u'04d':u'Y',u'04n':u'Y',u'09d':u'R',u'09n':u'R',u'10d':u'R',u'10n':u'R',u'11d':u'P',u'11n':u'P',u'13d':u'W',u'13n':u'W',u'50d':u'M',u'50n':u'W'} calendar.setfirstweekday(0) # Monday is the first day of the week global todo_wait; todo_wait = 300 global refresh_time; refresh_time = 900 start_time = time.time() + refresh_time while True: query_todo_list() if (do_screen_update == 1): do_screen_update = 0 refresh_Screen() start_time = time.time() + refresh_time elif (time.time() - start_time) > 0: print('-= General Refresh =-') refresh_Screen() start_time = time.time() + refresh_time time.sleep(todo_wait)
def main(): epd = epd7in5b.EPD() epd.init() # For simplicity, the arguments are explicit numerical coordinates image = Image.new('L', (EPD_WIDTH, EPD_HEIGHT), 255) # 255: clear the frame draw = ImageDraw.Draw(image) font = ImageFont.truetype('/usr/share/fonts/truetype/freefont/FreeMonoBold.ttf', 24) draw.rectangle((0, 6, 640, 40), fill = 127) draw.text((200, 10), 'e-Paper demo', font = font, fill = 255) draw.rectangle((200, 80, 600, 280), fill = 127) draw.chord((240, 120, 580, 220), 0, 360, fill = 255) draw.rectangle((20, 80, 160, 280), fill = 0) draw.chord((40, 80, 180, 220), 0, 360, fill = 127) epd.display_frame(epd.get_frame_buffer(image)) # image = Image.open('640x384.bmp') image = Image.open('EnergyReporter.bmp') epd.display_frame(epd.get_frame_buffer(image))
def drawImage(imgPath, vcom): print 'load image ' + imgPath image = Image.open(imgPath) print 'epd init' epd = epd7in5b.EPD() hex_str = "0xAD4" epd.init(int(vcom)) print 'display image to screen' epd.display_frame(epd.get_frame_buffer(image)) print 'go to sleep mode' epd.sleep() print 'done'
def draw(author = "Albert Camus", title = "The Myth of Sisyphus", quote = "The struggle itself towards the heights is enough to fill a man's heart. One must imagine Sisyphus happy."): epd = epd7in5b.EPD() epd.init() image = Image.new('1', (EPD_WIDTH, EPD_HEIGHT), 1) draw = ImageDraw.Draw(image) font = ImageFont.truetype('/usr/share/fonts/truetype/freefont/FreeMonoBold.ttf', 20) #draw.rectangle((5, 5, 240, 384), fill = 0) def wrap_text(text, width, margin, offset, fill=0): for line in textwrap.wrap(text, width = 53): draw.text((margin, offset), line, font=font, fill=fill) # quote offset += font.getsize(line)[1] wrap_text(quote, 53, 5, 5) wrap_text('-{} "{}"'.format(author, title), 48, 30, 270) image = image.rotate(180) epd.display_frame(epd.get_frame_buffer(image))
def welcome1(reverse = False):#显示欢迎语 # display images #frame_black = epd.get_frame_buffer(Image.open('background.bmp')) #frame_yellow = epd.get_frame_buffer(Image.open('NULL.bmp')) #epd.display_frame(frame_black,frame_yellow) print("欢迎使用!时间:{}".format(time.strftime('%H:%M:%S', time.localtime(time.time())))) epd = epd7in5b.EPD() epd.init() image_black = Image.new('1', (EPD_WIDTH, EPD_HEIGHT), 255) # 255: clear the frame draw_black = ImageDraw.Draw(image_black) image_yellow = Image.new('1', (EPD_WIDTH, EPD_HEIGHT), 255) # 255: clear the frame draw_yellow = ImageDraw.Draw(image_yellow) font = ImageFont.truetype(Font, 80) draw_black.text((150, 100), '欢迎使用!', font = font, fill = 0) font = ImageFont.truetype(Font_bd, 30) draw_yellow.text((220,210),'LinWang 制作', font = font, fill = 0) draw_black.text((221,211),'LinWang 制作', font = font, fill = 0) font = ImageFont.truetype(Font, 20) wlan0ip = get_ip('wlan0') #eth0ip = get_ip('eth0') #strip = "wlanIP:" + wlan0ip + "\n" + "eth0IP:" + eth0ip #draw_black.text((150,340), strip, font = font, fill = 0) draw_black.text((150,340), "IP:" + wlan0ip, font = font, fill = 0) image_black = image_black.rotate(-90) image_yellow = image_yellow.rotate(-90) if reverse == True: image_black = image_black.transpose(Image.ROTATE_180) image_yellow = image_yellow.transpose(Image.ROTATE_180) epd.display_frame(epd.get_frame_buffer(image_black),epd.get_frame_buffer(image_yellow)) print("进入界面。时间:{}".format(time.strftime('%H:%M:%S', time.localtime(time.time()))))
def calibration(): """Function for Calibration""" if display_colours == "bwr": import epd7in5b epd = epd7in5b.EPD() print('_________Calibration for 3-Colour E-Paper started_________' + '\n') if display_colours == "bw": import epd7in5 epd = epd7in5.EPD() print('_________Calibration for 2-Colour E-Paper started_________' + '\n') for i in range(2): epd.init() print('Calibrating black...') epd.display_frame(epd.get_frame_buffer(black)) if display_colours == "bwr": print('calibrating red...') epd.display_frame(epd.get_frame_buffer(red)) print('Calibrating white...') epd.display_frame(epd.get_frame_buffer(white)) epd.sleep() print('Cycle', str(i + 1) + '/2', 'complete' + '\n') print('Calibration complete')
def calibration(): if display_colours == "bwr": import epd7in5b epd = epd7in5b.EPD() if display_colours == "bw": import epd7in5 epd = epd7in5.EPD() for i in range(2): epd.init() black = Image.new('1', (EPD_WIDTH, EPD_HEIGHT), 'black') print('calibrating black...') ImageDraw.Draw(black) epd.display_frame(epd.get_frame_buffer(black)) if display_colours == "bwr": red = Image.new('L', (EPD_WIDTH, EPD_HEIGHT), 'red') ImageDraw.Draw(red) print('calibrating red...') epd.display_frame(epd.get_frame_buffer(red)) white = Image.new('1', (EPD_WIDTH, EPD_HEIGHT), 'white') ImageDraw.Draw(white) print('calibrating white...') epd.display_frame(epd.get_frame_buffer(white)) epd.sleep() print('Calibration complete')
def refresh1(reverse=False): #刷新内容 epd = epd7in5b.EPD() epd.init() EPD_WIDTH = 384 EPD_HEIGHT = 640 # For simplicity, the arguments are explicit numerical coordinates image_yellow = Image.new('1', (EPD_WIDTH, EPD_HEIGHT), 255) # 255: clear the frame draw_yellow = ImageDraw.Draw(image_yellow) image_black = Image.new('1', (EPD_WIDTH, EPD_HEIGHT), 255) # 255: clear the frame draw_black = ImageDraw.Draw(image_black) draw_yellow.line((0, 90, 384, 90), fill=0, width=4) #上横线 draw_yellow.line((190, 0, 190, 90), fill=0, width=3) #上竖线 draw_yellow.line((0, 215, 384, 215), fill=0, width=4) #上2横线 draw_yellow.line((0, 390, 384, 390), fill=0, width=4) #下横线 draw_yellow.line((0, 460, 384, 460), fill=0, width=4) #下横线 #draw_yellow.line((440,0,440,115),fill=0,width=3)#上右竖线 #draw_yellow.line((0,280,640,280),fill=0,width=5)#下横线 #日期 str_year = time.strftime('%Y年%m月%d日', time.localtime(time.time())) font = ImageFont.truetype(Font, 20) draw_black.text((17, 5), str_year, font=font, fill=0) #时间 str_time = time.strftime('%H:%M', time.localtime(time.time())) font = ImageFont.truetype(Font_bd, 130) draw_black.text((15, 65), str_time, font=font, fill=0) draw_yellow.text((13, 63), str_time, font=font, fill=0) #星期 week = time.strftime('%w', time.localtime(time.time())) if week == '0': str_week = '星期日' elif week == '1': str_week = '星期一' elif week == '2': str_week = '星期二' elif week == '3': str_week = '星期三' elif week == '4': str_week = '星期四' elif week == '5': str_week = '星期五' elif week == '6': str_week = '星期六' else: str_week = 'error!' font = ImageFont.truetype(Font_bd, 45) draw_black.text((25, 25), str_week, font=font, fill=0) #天气 WF = weather() #today str_city = WF["city"] + ' ' + "今日天气" font = ImageFont.truetype(Font_bd, 15) draw_black.text((220, 5), str_city, font=font, fill=0) str_tdweather1 = WF["today1"] font = ImageFont.truetype(Font, 15) draw_black.text((210, 25), str_tdweather1, font=font, fill=0) str_tdweather2 = WF["today2"] draw_black.text((290, 25), str_tdweather2, font=font, fill=0) #1234——day font = ImageFont.truetype(Font, 11) draw_black.text((5, 395), WF["oneday"], font=font, fill=0) draw_black.text((5, 410), WF["twoday"], font=font, fill=0) draw_black.text((5, 425), WF["threeday"], font=font, fill=0) draw_black.text((5, 440), WF["fourday"], font=font, fill=0) #日历 yy = int(time.strftime('%Y', time.localtime(time.time()))) mm = int(time.strftime('%m', time.localtime(time.time()))) str_cal = calendar.month(yy, mm) font = ImageFont.truetype(Font_bd, 18) draw_black.text((13, 220), strB2Q(str_cal), font=font, fill=0) image_black = rotateimage(image_black, -90, EPD_WIDTH, EPD_HEIGHT) image_yellow = rotateimage(image_yellow, -90, EPD_WIDTH, EPD_HEIGHT) #图像翻转 if reverse == True: image_black = image_black.transpose(Image.ROTATE_180) image_yellow = image_yellow.transpose(Image.ROTATE_180) #显示 epd.display_frame(epd.get_frame_buffer(image_black), epd.get_frame_buffer(image_yellow))
def refresh(reverse=False): #刷新内容 epd = epd7in5b.EPD() epd.init() # For simplicity, the arguments are explicit numerical coordinates image_yellow = Image.new('1', (EPD_WIDTH, EPD_HEIGHT), 255) # 255: clear the frame draw_yellow = ImageDraw.Draw(image_yellow) image_black = Image.new('1', (EPD_WIDTH, EPD_HEIGHT), 255) # 255: clear the frame draw_black = ImageDraw.Draw(image_black) draw_yellow.line((0, 115, 640, 115), fill=0, width=4) #上横线 draw_yellow.line((200, 0, 200, 115), fill=0, width=3) #上左竖线 draw_yellow.line((430, 0, 430, 115), fill=0, width=3) #上右竖线 draw_yellow.line((0, 280, 640, 280), fill=0, width=5) #下横线 #font = ImageFont.truetype('/usr/share/fonts/truetype/freefont/FreeMonoBold.ttf', 24) #draw_yellow.rectangle((0, 0, 640, 40), fill = 255) #draw_yellow.text((150, 10), 'e-Paper demo for LinWang', font = font, fill = 0) #draw_yellow.rectangle((0, 45, 640, 85), fill = 0) #draw_red.rectangle((200, 80, 600, 280), fill = 0) #draw_red.chord((240, 120, 580, 220), 0, 360, fill = 255) #draw_black.rectangle((20, 80, 160, 280), fill = 0) #draw_red.chord((40, 80, 180, 220), 0, 360, fill = 0) #日期 str_year = time.strftime('%Y年%m月%d日', time.localtime(time.time())) font = ImageFont.truetype(Font, 23) draw_black.text((15, 15), str_year, font=font, fill=0) #str_date = time.strftime('%m月%d日', time.localtime(time.time())) #font = ImageFont.truetype('fonts/msyhbd.ttc', 40) #draw_black.text((25, 55), str_date, font = font, fill = 0) #时间 str_time = time.strftime('%H:%M', time.localtime(time.time())) font = ImageFont.truetype(Font_bd, 150) draw_black.text((110, 95), str_time, font=font, fill=0) draw_yellow.text((108, 93), str_time, font=font, fill=0) #时间+ #str_time = time.strftime('%H:%M', time.localtime(time.time())) #font = ImageFont.truetype('fonts/msyhbd.ttc', 150) #x=30 #y=95 #draw_black.text((x, y), str_time, font = font, fill = 0) #draw_yellow.text((x-2, y-2), str_time, font = font, fill = 0) #draw_yellow.line((470,115,470,280),fill=0,width=4)#中右竖线 #星期 week = time.strftime('%w', time.localtime(time.time())) if week == '0': str_week = '星期日' elif week == '1': str_week = '星期一' elif week == '2': str_week = '星期二' elif week == '3': str_week = '星期三' elif week == '4': str_week = '星期四' elif week == '5': str_week = '星期五' elif week == '6': str_week = '星期六' else: str_week = 'error!' font = ImageFont.truetype(Font_bd, 55) draw_black.text((17, 35), str_week, font=font, fill=0) #天气 WF = weather() #today str_city = WF["city"] + " " + "今日天气" font = ImageFont.truetype(Font_bd, 20) draw_black.text((230, 5), str_city, font=font, fill=0) str_tdweather1 = WF["today1"] font = ImageFont.truetype(Font, 20) draw_black.text((215, 33), str_tdweather1, font=font, fill=0) str_tdweather2 = WF["today2"] draw_black.text((315, 33), str_tdweather2, font=font, fill=0) #1234_day font = ImageFont.truetype(Font_l, 15) draw_black.text((50, 290), WF["oneday"], font=font, fill=0) draw_black.text((50, 310), WF["twoday"], font=font, fill=0) draw_black.text((50, 330), WF["threeday"], font=font, fill=0) draw_black.text((50, 350), WF["fourday"], font=font, fill=0) #日历 #待完善,显示不清 yy = int(time.strftime('%Y', time.localtime(time.time()))) mm = int(time.strftime('%m', time.localtime(time.time()))) str_cal = calendar.month(yy, mm) font = ImageFont.truetype(Font_bd, 15) image_cal = Image.new('1', (300, 145), 255) draw_cal = ImageDraw.Draw(image_cal) draw_cal.text((0, 0), strB2Q(str_cal), font=font, fill=0) image_cal = image_cal.resize((200, 110)) image_black.paste(image_cal, (435, 3)) #font = ImageFont.truetype('fonts/msyhbd.ttc', 10) #draw_black.text((445,0), strB2Q(str_cal), font = font, fill = 0) #天气折线图 hightem.png lowtem.png ##失败!无法清晰显示 #drawline(WF) #png_size = (400,384) #png_locate = (0,250) #highim=Image.open('hightem.png') #highimg=highim.resize(png_size) #image_black.paste(highimg,png_locate) #lowim=Image.open('lowtem.png') #lowimg=lowim.resize(png_size) #image_yellow.paste(lowimg,png_locate) #图像翻转 if reverse == True: image_black = image_black.transpose(Image.ROTATE_180) image_yellow = image_yellow.transpose(Image.ROTATE_180) #显示 epd.display_frame(epd.get_frame_buffer(image_black), epd.get_frame_buffer(image_yellow))
def main(): epd = epd7in5b.EPD() epd.init() image = Image.open('rover.bmp') epd.display_frame(epd.get_frame_buffer(image))
def main(): epd = epd7in5b.EPD() epd.init() day_number = datetime.today().weekday() days = [ "Poniedzialek", "Wtorek", "Sroda", "Czwartek", "Piatek", "Weekend", "Weekend" ] day_info = "{}".format(days[day_number]) print day_info skm_timetable_file = os.path.abspath( "/home/pi/eink/raspberrypi/python/skm.csv") image = Image.new('L', (EPD_WIDTH, EPD_HEIGHT), 255) # 255: clear the frame draw = ImageDraw.Draw(image) font = ImageFont.truetype( '/usr/share/fonts/truetype/freefont/FreeMonoBold.ttf', 35) day_font = ImageFont.truetype( '/usr/share/fonts/truetype/freefont/FreeMonoBold.ttf', 38) col_w = 120 col_h = 39 cols = 2 rows = 9 cal_w = 1 + ((col_w + 1) * cols) cal_h = 1 + ((col_h + 1) * rows) cal_x = EPD_WIDTH - cal_w - 2 cal_y = 2 # Paint out a black rectangle onto which we'll draw our canvas draw.rectangle((cal_x, cal_y, cal_x + cal_w - 1, cal_y + cal_h - 1), fill=255, outline=0) # Draw the vertical lines which separate the columns # and also draw the day names into the table header for x in range(cols): # Figure out the left edge of the column o_x = (col_w + 1) * x o_x += cal_x # Offset to the right side of the column and draw the vertical line o_x += col_w + 1 draw.line((o_x, cal_y, o_x, cal_h), fill=0) # Draw the horizontal lines which separate the rows for y in range(rows): o_y = (col_h + 1) * y o_y += cal_y + col_h + 1 draw.line((cal_x, o_y, cal_w + cal_x - 1, o_y), fill=0) skm_data = [] skm_timetable = open(skm_timetable_file, 'r') skm_reader = csv.reader(skm_timetable, delimiter='\t', lineterminator='\n') for row in skm_reader: skm_data.append(row) skm_from = 0 skm_to = skm_from + rows closest_trains = skm_data[skm_from:skm_to] def print_digit(position, text, colour): o_x, o_y = position draw.text((o_x, o_y), text, font=font, fill=colour) for row, train in enumerate(closest_trains): y = (col_h + 1) * row y += cal_y + 1 for col, number in enumerate(train): x = (col_w + 1) * col x += cal_x + 1 number = 'S' + number if col == 1 else number if int(train[1]) == 1: draw.rectangle((x, y, x + col_w - 1, y + col_h - 1), fill=127) print_digit((x + 3, y + 3), number, 255) else: print_digit((x + 3, y + 3), number, 127 if col == 1 else 0) draw.text((20, 20), day_info, font=day_font, fill=0) epd.display_frame(epd.get_frame_buffer(image)) GPIO.cleanup()
#!/usr/bin/python # -*- coding:utf-8 -*- import epd7in5b import time from PIL import Image,ImageDraw,ImageFont import traceback try: epd = epd7in5b.EPD() epd.init() print("Clear...") epd.Clear(0xFF) # Drawing on the Horizontal image HBlackimage = Image.new('1', (epd7in5b.EPD_WIDTH, epd7in5b.EPD_HEIGHT), 255) # 298*126 HRedimage = Image.new('1', (epd7in5b.EPD_WIDTH, epd7in5b.EPD_HEIGHT), 255) # 298*126 # Horizontal print "Drawing" drawblack = ImageDraw.Draw(HBlackimage) drawred = ImageDraw.Draw(HRedimage) font24 = ImageFont.truetype('/usr/share/fonts/truetype/wqy/wqy-microhei.ttc', 24) drawblack.text((10, 0), 'hello world', font = font24, fill = 0) drawblack.text((10, 20), '7.5inch e-Paper B', font = font24, fill = 0) drawblack.text((150, 0), u'微雪电子', font = font24, fill = 0) drawblack.line((20, 50, 70, 100), fill = 0) drawblack.line((70, 50, 20, 100), fill = 0) drawblack.rectangle((20, 50, 70, 100), outline = 0) drawred.line((165, 50, 165, 100), fill = 0) drawred.line((140, 75, 190, 75), fill = 0)
def render(name): """Render selected image.""" epd = epd7in5b.EPD() epd.init() display(name, epd)
def main(): try: epd = epd7in5b.EPD() epd.init() #print("Clear...") epd.Clear(0xFF) print("Done Clearing") # Drawing on the Vertical image HBlackimage = Image.new('1', (epd7in5b.EPD_HEIGHT, epd7in5b.EPD_WIDTH), 255) # 298*126 HRedimage = Image.new('1', (epd7in5b.EPD_HEIGHT, epd7in5b.EPD_WIDTH), 255) # 298*126 # Vertical drawblack = ImageDraw.Draw(HBlackimage) drawred = ImageDraw.Draw(HRedimage) font_title = ImageFont.truetype( '/usr/share/fonts/truetype/freefont/FreeSans.ttf', 24) font_message = ImageFont.truetype( '/usr/share/fonts/truetype/freefont/FreeSans.ttf', 22) font_date = ImageFont.truetype( '/usr/share/fonts/truetype/freefont/FreeSans.ttf', 18) font_meeting = ImageFont.truetype( '/usr/share/fonts/truetype/freefont/FreeSans.ttf', 17) font_time_slot = ImageFont.truetype( '/usr/share/fonts/truetype/freefont/FreeSans.ttf', 16) font_time_small = ImageFont.truetype( '/usr/share/fonts/truetype/freefont/FreeSans.ttf', 14) drawred.text((68, 4), 'Main Conference Room', font=font_title, fill=0) drawblack.line((70, 29, 314, 29), fill=0) # Bottom Border for Title drawred.line((3, 60, 380, 60), fill=0) drawred.line((3, 61, 380, 61), fill=0) drawblack.line((2, 62, 381, 62), fill=0) drawred.line((0, 63, 384, 63), fill=0) drawred.line((0, 64, 384, 64), fill=0) # Top Border for Title drawred.line((0, 0, 384, 0), fill=0) drawred.line((0, 1, 384, 1), fill=0) drawblack.line((2, 2, 381, 2), fill=0) drawred.line((3, 3, 380, 3), fill=0) drawred.line((3, 4, 380, 4), fill=0) # Right Border for Title drawred.line((379, 5, 379, 59), fill=0) drawred.line((380, 5, 380, 59), fill=0) drawblack.line((381, 2, 381, 62), fill=0) drawred.line((382, 2, 382, 62), fill=0) drawred.line((383, 2, 383, 64), fill=0) # Left Border for Title drawred.line((0, 2, 0, 64), fill=0) drawred.line((1, 2, 1, 63), fill=0) drawblack.line((2, 2, 2, 62), fill=0) drawred.line((3, 3, 3, 59), fill=0) drawred.line((4, 3, 4, 59), fill=0) drawblack.line((383, 65, 383, 640), fill=0) drawblack.line((382, 65, 382, 640), fill=0) drawblack.line((0, 65, 0, 640), fill=0) drawblack.line((1, 65, 1, 640), fill=0) ###Time Slot Lines & Text### normal_tick_x2 = 5 thirty_tick_x2 = 9 time_text_x = 10 # 9am Ticks & Text y_nine = 64 drawblack.line((0, (y_nine + 10), normal_tick_x2, (y_nine + 10))) drawblack.line((0, (y_nine + 21), normal_tick_x2, (y_nine + 21))) drawblack.line((0, (y_nine + 32), thirty_tick_x2, (y_nine + 32))) drawblack.line((0, (y_nine + 43), normal_tick_x2, (y_nine + 43))) drawblack.line((0, (y_nine + 54), normal_tick_x2, (y_nine + 54))) drawblack.text((time_text_x, (y_nine + 1)), '9am', font=font_time_slot, fill=0) # 10am Line y_ten = 128 drawblack.line((0, y_ten, 384, y_ten), fill=0) # 10am Ticks & Text drawblack.line((0, (y_ten + 10), normal_tick_x2, (y_ten + 10))) drawblack.line((0, (y_ten + 21), normal_tick_x2, (y_ten + 21))) drawblack.line((0, (y_ten + 32), thirty_tick_x2, (y_ten + 32))) drawblack.line((0, (y_ten + 43), normal_tick_x2, (y_ten + 43))) drawblack.line((0, (y_ten + 54), normal_tick_x2, (y_ten + 54))) drawblack.text((time_text_x, (y_ten + 1)), '10am', font=font_time_slot, fill=0) # 11am Line y_eleven = 192 drawblack.line((0, y_eleven, 384, y_eleven), fill=0) # 11am Ticks & Text drawblack.line((0, (y_eleven + 10), normal_tick_x2, (y_eleven + 10))) drawblack.line((0, (y_eleven + 21), normal_tick_x2, (y_eleven + 21))) drawblack.line((0, (y_eleven + 32), thirty_tick_x2, (y_eleven + 32))) drawblack.line((0, (y_eleven + 43), normal_tick_x2, (y_eleven + 43))) drawblack.line((0, (y_eleven + 54), normal_tick_x2, (y_eleven + 54))) drawblack.text((time_text_x, (y_eleven + 1)), '11am', font=font_time_slot, fill=0) # 12pm Line y_twelve = 256 drawblack.line((0, y_twelve, 384, y_twelve), fill=0) # 12pm Ticks & Text drawblack.line((0, (y_twelve + 10), normal_tick_x2, (y_twelve + 10))) drawblack.line((0, (y_twelve + 20), normal_tick_x2, (y_twelve + 20))) drawblack.line((0, (y_twelve + 31), thirty_tick_x2, (y_twelve + 31))) drawblack.line((0, (y_twelve + 42), normal_tick_x2, (y_twelve + 42))) drawblack.line((0, (y_twelve + 53), normal_tick_x2, (y_twelve + 53))) drawblack.text((time_text_x, (y_twelve + 1)), '12pm', font=font_time_slot, fill=0) # 1pm Line y_one = 319 drawblack.line((0, y_one, 384, y_one), fill=0) # 1pm Ticks & Text drawblack.line((0, (y_one + 10), normal_tick_x2, (y_one + 10))) drawblack.line((0, (y_one + 21), normal_tick_x2, (y_one + 21))) drawblack.line((0, (y_one + 32), thirty_tick_x2, (y_one + 32))) drawblack.line((0, (y_one + 43), normal_tick_x2, (y_one + 43))) drawblack.line((0, (y_one + 54), normal_tick_x2, (y_one + 54))) drawblack.text((time_text_x, (y_one + 1)), '1pm', font=font_time_slot, fill=0) # 2pm Line y_two = 383 drawblack.line((0, y_two, 384, y_two), fill=0) # 2pm Ticks & Text drawblack.line((0, (y_two + 10), normal_tick_x2, (y_two + 10))) drawblack.line((0, (y_two + 21), normal_tick_x2, (y_two + 21))) drawblack.line((0, (y_two + 32), thirty_tick_x2, (y_two + 32))) drawblack.line((0, (y_two + 43), normal_tick_x2, (y_two + 43))) drawblack.line((0, (y_two + 54), normal_tick_x2, (y_two + 54))) drawblack.text((time_text_x, (y_two + 1)), '2pm', font=font_time_slot, fill=0) # 3pm Line y_three = 447 drawblack.line((0, y_three, 384, y_three), fill=0) # 3pm Ticks & Textblack drawblack.line((0, (y_three + 10), normal_tick_x2, (y_three + 10))) drawblack.line((0, (y_three + 21), normal_tick_x2, (y_three + 21))) drawblack.line((0, (y_three + 32), thirty_tick_x2, (y_three + 32))) drawblack.line((0, (y_three + 43), normal_tick_x2, (y_three + 43))) drawblack.line((0, (y_three + 54), normal_tick_x2, (y_three + 54))) drawblack.text((time_text_x, (y_three + 1)), '3pm', font=font_time_slot, fill=0) # 4pm Line y_four = 511 drawblack.line((0, y_four, 384, y_four), fill=0) # 4pm Ticks & Text drawblack.line((0, (y_four + 10), normal_tick_x2, (y_four + 10))) drawblack.line((0, (y_four + 21), normal_tick_x2, (y_four + 21))) drawblack.line((0, (y_four + 32), thirty_tick_x2, (y_four + 32))) drawblack.line((0, (y_four + 43), normal_tick_x2, (y_four + 43))) drawblack.line((0, (y_four + 54), normal_tick_x2, (y_four + 54))) drawblack.text((time_text_x, (y_four + 1)), '4pm', font=font_time_slot, fill=0) # 5pm Line y_five = 575 drawblack.line((0, y_five, 384, y_five), fill=0) # 5pm Ticks & Text drawblack.line((0, (y_five + 10), normal_tick_x2, (y_five + 10))) drawblack.line((0, (y_five + 21), normal_tick_x2, (y_five + 21))) drawblack.line((0, (y_five + 32), thirty_tick_x2, (y_five + 32))) drawblack.line((0, (y_five + 43), normal_tick_x2, (y_five + 43))) drawblack.line((0, (y_five + 54), normal_tick_x2, (y_five + 54))) drawblack.text((time_text_x, (y_five + 1)), '5pm', font=font_time_slot, fill=0) #6pm Text drawblack.text((time_text_x, 623), '6pm', font=font_time_slot, fill=0) update_check = [] date_reg = '' date_x_reg = 0 refresh = True startup = True loop = True # should always be true while loop: t = strftime("%Y-%m-%d %H:%M:%S", gmtime()) print(t) month, date_x = monthName(int(t[5:7])) day = dayFix(t[8:10], t[11:13]) date = month + ' ' + day + ', ' + t[0:4] if date != date_reg and date_reg != '': epd, drawblack, drawred, HBlackimage, HRedimage = new_day_redraw( ) # Draws back over old date in white to make it disappear drawred.text((date_x_reg, 32), date_reg, font=font_title, fill=255) drawred.text((date_x, 32), date, font=font_title, fill=0) #Date date_reg = date date_x_reg = date_x ## CALENDAR DATA PROCESSING ### events_temp = quickstart.main() events_official_start = { } # Final dict to store event data --> key: meeting name, value: time events_official_end = {} for event_tup in events_temp: if int(event_tup[1][8:10]) == int(day): start_time = event_tup[1][11:16] end_time = event_tup[2][11:16] # Makes time into an int without ':' as the value corresponding to its key # for sorting purposes. Leading zero's are eliminated as well. events_official_start[event_tup[0]] = int( start_time.replace(':', '')) events_official_end[event_tup[0]] = int( end_time.replace(':', '')) # events_sorted will be a list of tuples sorted by second element in each tuple (time) events_sorted_start = sorted(events_official_start.items(), key=operator.itemgetter(1)) events_sorted_end = sorted(events_official_end.items(), key=operator.itemgetter(1)) meetings = [] # List of meetings in order start_times = [ ] # List of times corresponding to their associated meetings in order for tup in events_sorted_start: meetings.append(tup[0]) time_str = str(tup[1]) start_time = time_str[0:2] + ':' + time_str[ 2:] # Assumes current hour is before 10am hour = int(time_str[0:2]) if len( time_str ) == 3: # Fixes current time variable if its 10am or after start_time = time_str[0] + ':' + time_str[1:] hour = int(time_str[0]) xm = 'am' # Assumes its before 12pm due to military time if hour > 11: xm = 'pm' # Catches if its 12pm or later if hour > 12: # Checks to see if convert from military to normal time is needed hr = hour - 12 start_time = str(hr) + ':' + time_str[2:] start_times.append(start_time + ' ' + xm) end_times = [] for tup in events_sorted_end: time_str = str(tup[1]) end_time = time_str[0:2] + ':' + time_str[2:] hour = int(time_str[0:2]) if len(time_str) == 3: end_time = time_str[0] + ':' + time_str[1:] hour = int(time_str[0]) xm = 'am' if hour > 11: xm = 'pm' if hour > 12: hr = hour - 12 end_time = str(hr) + ':' + time_str[2:] end_times.append(end_time + ' ' + xm) print(start_times) print(end_times) print(meetings) print("Meetings length: " + str(len(meetings))) print("UpdateCheck length: " + str(len(update_check))) if len(meetings) == len(update_check): for i in range(len(meetings)): if meetings[i] != update_check[i]: refresh = True break refresh = False else: refresh = True if refresh: for i in range(len(start_times)): t1 = start_times[i] t2 = end_times[i] if t1[1] == ':': h1 = int(t1[0]) m1 = int(t1[2:4]) start_time_y = time_y_coord(h1, m1) else: h1 = int(t1[0:2]) m1 = int(t1[3:5]) start_time_y = time_y_coord(h1, m1) if t2[1] == ':': h2 = int(t2[0]) m2 = int(t2[2:4]) end_time_y = time_y_coord(h2, m2) else: h2 = int(t2[0:2]) m2 = int(t2[3:5]) end_time_y = time_y_coord(h2, m2) meeting_y = ((start_time_y + end_time_y) // 2) - 7 erase_y = None if h1 != 12: if (h2 - h1) == 1: er_y = { 10: 128, 11: 192, 12: 256, 1: 319, 2: 383, 3: 447, 4: 511, 5: 575 } erase_y = er_y.get(h2, None) elif (h2 - h1) == 2: er_y = { 10: 128, 11: 128, 12: 192, 1: 256, 2: 319, 3: 383, 4: 447, 5: 511, 6: 575 } erase_y = er_y.get(h2, None) if erase_y is not None: drawblack.line((50, erase_y, 381, erase_y), fill=255) else: if h2 == 1: drawblack.line((50, y_one, 381, y_one), fill=255) elif h2 == 2: drawblack.line((50, y_two, 381, y_two), fill=255) ### Start Time Lines ### # 9am if start_time_y < 81 and start_time_y > 64: drawred.line((1, start_time_y, 9, start_time_y), fill=0) drawred.line( (1, start_time_y + 1, 9, start_time_y + 1), fill=0) drawred.line((41, start_time_y, 382, start_time_y), fill=0) drawred.line( (41, start_time_y + 1, 382, start_time_y + 1), fill=0) # 10am elif start_time_y < 145 and start_time_y > 128: drawred.line((1, start_time_y, 10, start_time_y), fill=0) drawred.line( (1, start_time_y + 1, 10, start_time_y + 1), fill=0) drawred.line((50, start_time_y, 382, start_time_y), fill=0) drawred.line( (50, start_time_y + 1, 382, start_time_y + 1), fill=0) # 11am elif start_time_y < 209 and start_time_y > 192: drawred.line((1, start_time_y, 10, start_time_y), fill=0) drawred.line( (1, start_time_y + 1, 10, start_time_y + 1), fill=0) drawred.line((50, start_time_y, 382, start_time_y), fill=0) drawred.line( (50, start_time_y + 1, 382, start_time_y + 1), fill=0) # 12pm elif start_time_y < 275 and start_time_y > 256: drawred.line((1, start_time_y, 10, start_time_y), fill=0) drawred.line( (1, start_time_y + 1, 10, start_time_y + 1), fill=0) drawred.line((50, start_time_y, 382, start_time_y), fill=0) drawred.line( (50, start_time_y + 1, 382, start_time_y + 1), fill=0) # 1pm elif start_time_y < 338 and start_time_y > 319: drawred.line((1, start_time_y, 10, start_time_y), fill=0) drawred.line( (1, start_time_y + 1, 10, start_time_y + 1), fill=0) drawred.line((41, start_time_y, 382, start_time_y), fill=0) drawred.line( (41, start_time_y + 1, 382, start_time_y + 1), fill=0) # 2pm elif start_time_y < 402 and start_time_y > 383: drawred.line((1, start_time_y, 9, start_time_y), fill=0) drawred.line( (1, start_time_y + 1, 9, start_time_y + 1), fill=0) drawred.line((41, start_time_y, 382, start_time_y), fill=0) drawred.line( (41, start_time_y + 1, 382, start_time_y + 1), fill=0) # 3pm elif start_time_y < 466 and start_time_y > 447: drawred.line((1, start_time_y, 9, start_time_y), fill=0) drawred.line( (1, start_time_y + 1, 9, start_time_y + 1), fill=0) drawred.line((41, start_time_y, 382, start_time_y), fill=0) drawred.line( (41, start_time_y + 1, 382, start_time_y + 1), fill=0) # 4pm elif start_time_y < 530 and start_time_y > 511: drawred.line((1, start_time_y, 8, start_time_y), fill=0) drawred.line( (1, start_time_y + 1, 8, start_time_y + 1), fill=0) drawred.line((41, start_time_y, 382, start_time_y), fill=0) drawred.line( (41, start_time_y + 1, 382, start_time_y + 1), fill=0) # 5pm elif start_time_y < 594 and start_time_y > 575: drawred.line((1, start_time_y, 9, start_time_y), fill=0) drawred.line( (1, start_time_y + 1, 9, start_time_y + 1), fill=0) drawred.line((41, start_time_y, 382, start_time_y), fill=0) drawred.line( (41, start_time_y + 1, 382, start_time_y + 1), fill=0) # 6pm elif start_time_y > 624: drawred.line((1, start_time_y, 9, start_time_y), fill=0) drawred.line( (1, start_time_y + 1, 9, start_time_y + 1), fill=0) drawred.line((41, start_time_y, 382, start_time_y), fill=0) drawred.line( (41, start_time_y + 1, 382, start_time_y + 1), fill=0) else: drawred.line((1, start_time_y, 382, start_time_y), fill=0) drawred.line( (1, (start_time_y + 1), 382, (start_time_y + 1)), fill=0) ### End Time Lines ### # 9am if end_time_y < 81 and end_time_y > 64: drawred.line((1, end_time_y, 9, end_time_y), fill=0) drawred.line((1, end_time_y - 1, 9, end_time_y - 1), fill=0) drawred.line((41, end_time_y, 382, end_time_y), fill=0) drawred.line((41, end_time_y - 1, 382, end_time_y - 1), fill=0) # 10am elif end_time_y < 145 and end_time_y > 128: drawred.line((1, end_time_y, 10, end_time_y), fill=0) drawred.line((1, end_time_y - 1, 10, end_time_y - 1), fill=0) drawred.line((50, end_time_y, 382, end_time_y), fill=0) drawred.line((50, end_time_y - 1, 382, end_time_y - 1), fill=0) # 11am elif end_time_y < 209 and end_time_y > 192: drawred.line((1, end_time_y, 10, end_time_y), fill=0) drawred.line((1, end_time_y - 1, 10, end_time_y - 1), fill=0) drawred.line((50, end_time_y, 382, end_time_y), fill=0) drawred.line((50, end_time_y - 1, 382, end_time_y - 1), fill=0) # 12pm elif end_time_y < 275 and end_time_y > 256: drawred.line((1, end_time_y, 10, end_time_y), fill=0) drawred.line((1, end_time_y - 1, 10, end_time_y - 1), fill=0) drawred.line((50, end_time_y, 382, end_time_y), fill=0) drawred.line((50, end_time_y - 1, 382, end_time_y - 1), fill=0) # 1pm elif end_time_y < 338 and end_time_y > 319: drawred.line((1, end_time_y, 10, end_time_y), fill=0) drawred.line((1, end_time_y - 1, 10, end_time_y - 1), fill=0) drawred.line((41, end_time_y, 382, end_time_y), fill=0) drawred.line((41, end_time_y - 1, 382, end_time_y - 1), fill=0) # 2pm elif end_time_y < 402 and end_time_y > 383: drawred.line((1, end_time_y, 9, end_time_y), fill=0) drawred.line((1, end_time_y - 1, 9, end_time_y - 1), fill=0) drawred.line((41, end_time_y, 382, end_time_y), fill=0) drawred.line((41, end_time_y - 1, 382, end_time_y - 1), fill=0) # 3pm elif end_time_y < 466 and end_time_y > 447: drawred.line((1, end_time_y, 9, end_time_y), fill=0) drawred.line((1, end_time_y - 1, 9, end_time_y - 1), fill=0) drawred.line((41, end_time_y, 382, end_time_y), fill=0) drawred.line((41, end_time_y - 1, 382, end_time_y - 1), fill=0) # 4pm elif end_time_y < 530 and end_time_y > 511: drawred.line((1, end_time_y, 8, end_time_y), fill=0) drawred.line((1, end_time_y - 1, 8, end_time_y - 1), fill=0) drawred.line((41, end_time_y, 382, end_time_y), fill=0) drawred.line((41, end_time_y - 1, 382, end_time_y - 1), fill=0) # 5pm elif end_time_y < 594 and end_time_y > 575: drawred.line((1, end_time_y, 9, end_time_y), fill=0) drawred.line((1, end_time_y - 1, 9, end_time_y - 1), fill=0) drawred.line((41, end_time_y, 382, end_time_y), fill=0) drawred.line((41, end_time_y - 1, 382, end_time_y - 1), fill=0) # 6pm elif end_time_y > 624: drawred.line((1, end_time_y, 9, end_time_y), fill=0) drawred.line((1, end_time_y - 1, 9, end_time_y - 1), fill=0) drawred.line((41, end_time_y, 382, end_time_y), fill=0) drawred.line((41, end_time_y - 1, 382, end_time_y - 1), fill=0) else: drawred.line((1, end_time_y, 382, end_time_y), fill=0) drawred.line( (1, (end_time_y - 1), 382, (end_time_y - 1)), fill=0) # Left and right side borders for meetings drawred.line((0, start_time_y, 0, end_time_y), fill=0) drawred.line((1, start_time_y, 1, end_time_y), fill=0) drawred.line((2, start_time_y, 2, end_time_y), fill=0) drawred.line((383, start_time_y, 383, end_time_y), fill=0) drawred.line((382, start_time_y, 382, end_time_y), fill=0) drawred.line((381, start_time_y, 381, end_time_y), fill=0) if len(meetings[i]) <= 33: if h1 > 9 or h2 > 9: drawred.text((302, meeting_y), t1[:-3] + '-' + t2[:-3], font=font_time_small, fill=0) else: drawred.text((315, meeting_y), t1[:-3] + '-' + t2[:-3], font=font_time_small, fill=0) # Meeting Titles drawred.text((55, meeting_y), meetings[i], font=font_time_slot, fill=0) update_check = meetings epd.display(epd.getbuffer(HBlackimage), epd.getbuffer(HRedimage)) startup = False else: time.sleep(30) if startup: epd.display(epd.getbuffer(HBlackimage), epd.getbuffer(HRedimage)) startup = False except Exception as e: print('exception ' + str(e)) main()
api_key = "" location = "Stuttgart, DE" week_starts_on = "Monday" """That's all. The software will do the rest. You don't need to modify anything below this.""" import epd7in5b #epd-control from PIL import Image, ImageDraw, ImageFont, ImageOps #image operations import calendar, pyowm #calendar and openweathermap wrapper from ics import Calendar, Event #icalendar parser from datetime import datetime #time operations from time import sleep #more time operations from urllib.request import urlopen #allows url to be 'read' import arrow #icalendar parser compatible dates from calibration import calibration epd = epd7in5b.EPD() #required if (week_starts_on == "Monday"): calendar.setfirstweekday(calendar.MONDAY) if (week_starts_on == "Sunday"): calendar.setfirstweekday(calendar.Sunday) c = Calendar(urlopen(url).read().decode('UTF-8')) e = Event() open = Image.open EPD_WIDTH = 640 EPD_HEIGHT = 384 path = '/home/pi/E-Paper-Master/Calendar/' wpath = path + 'weather-icons/'
def __init__(self, width: int, height: int): _type = "E_Paper" Display.__init__(self, width, height, _type) self.__epd = epd7in5b.EPD() self.__epd.init()
def __init__(self, test=False): """initializes the screen and all functions needed""" # debugging and log file self.test = test logging.basicConfig( filename="logfile.log", level=logging.WARNING, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s') # read settings with open('settings.json') as f: settings = json.load(f) self.API_weather_key = settings['weather_api'] self.API_weather_city = settings['city_id'] # load fonts self.fonts = { 'normal': ImageFont.truetype('fonts/tahoma.ttf', 12), 'large': ImageFont.truetype('fonts/tahoma.ttf', 24), 'day': ImageFont.truetype('fonts/tahoma.ttf', 40), 'weather': ImageFont.truetype('fonts/meteocons.ttf', 32) } self.position = {'weather': (10, 100)} # load conversion of weather icons with open('fonts/weather_icons.json') as f: self.weather_icon_table = json.load(f) # set offsets self.cal_pos_v = 250 # initialize the screen if not test: try: import epd7in5b self.epd = epd7in5b.EPD() self.epd.init() self.epd.Clear(0xFF) self.epd_width = epd7in5b.EPD_WIDTH # 640 self.epd_height = epd7in5b.EPD_HEIGHT # 384 print('screen cleared, ready to use') print('============================') logging.warning('screen cleared, ready to use') except: print('failed to initialize screen') logging.warning('failed to initialize screen') else: self.epd_width = 640 self.epd_height = 384 print('using debug mode') print('================') logging.warning('using debug mode') # set up google calendar: self.calendar_list = settings['calendars'] creds = None if os.path.exists('token.pickle'): with open('token.pickle', 'rb') as token: creds = pickle.load(token) # If there are no (valid) credentials available, let the user log in. if not creds or not creds.valid: if creds and creds.expired and creds.refresh_token: creds.refresh(Request()) else: SCOPES = ['https://www.googleapis.com/auth/calendar.readonly'] flow = InstalledAppFlow.from_client_secrets_file( 'credentials.json', SCOPES) creds = flow.run_local_server() # Save the credentials for the next run with open('token.pickle', 'wb') as token: pickle.dump(creds, token) self.service = build('calendar', 'v3', credentials=creds) # start scheduler self.time_startup = time.time() self.s = sched.scheduler(time.time, time.sleep)
def new_day_redraw(): epd = epd7in5b.EPD() epd.init() #print("Clear...") epd.Clear(0xFF) # Drawing on the Vertical image HBlackimage = Image.new('1', (epd7in5b.EPD_HEIGHT, epd7in5b.EPD_WIDTH), 255) # 298*126 HRedimage = Image.new('1', (epd7in5b.EPD_HEIGHT, epd7in5b.EPD_WIDTH), 255) # 298*126 # Vertical drawblack = ImageDraw.Draw(HBlackimage) drawred = ImageDraw.Draw(HRedimage) font_title = ImageFont.truetype( '/usr/share/fonts/truetype/freefont/FreeSans.ttf', 24) font_message = ImageFont.truetype( '/usr/share/fonts/truetype/freefont/FreeSans.ttf', 22) font_date = ImageFont.truetype( '/usr/share/fonts/truetype/freefont/FreeSans.ttf', 18) font_meeting = ImageFont.truetype( '/usr/share/fonts/truetype/freefont/FreeSans.ttf', 17) font_time_slot = ImageFont.truetype( '/usr/share/fonts/truetype/freefont/FreeSans.ttf', 16) font_time_small = ImageFont.truetype( '/usr/share/fonts/truetype/freefont/FreeSans.ttf', 14) drawred.text((68, 4), 'Main Conference Room', font=font_title, fill=0) drawblack.line((70, 29, 314, 29), fill=0) # Bottom Border for Title drawred.line((3, 60, 380, 60), fill=0) drawred.line((3, 61, 380, 61), fill=0) drawblack.line((2, 62, 381, 62), fill=0) drawred.line((0, 63, 384, 63), fill=0) drawred.line((0, 64, 384, 64), fill=0) # Top Border for Title drawred.line((0, 0, 384, 0), fill=0) drawred.line((0, 1, 384, 1), fill=0) drawblack.line((2, 2, 381, 2), fill=0) drawred.line((3, 3, 380, 3), fill=0) drawred.line((3, 4, 380, 4), fill=0) # Right Border for Title drawred.line((379, 5, 379, 59), fill=0) drawred.line((380, 5, 380, 59), fill=0) drawblack.line((381, 2, 381, 62), fill=0) drawred.line((382, 2, 382, 62), fill=0) drawred.line((383, 2, 383, 64), fill=0) # Left Border for Title drawred.line((0, 2, 0, 64), fill=0) drawred.line((1, 2, 1, 63), fill=0) drawblack.line((2, 2, 2, 62), fill=0) drawred.line((3, 3, 3, 59), fill=0) drawred.line((4, 3, 4, 59), fill=0) drawblack.line((383, 65, 383, 640), fill=0) drawblack.line((382, 65, 382, 640), fill=0) drawblack.line((0, 65, 0, 640), fill=0) drawblack.line((1, 65, 1, 640), fill=0) ###Time Slot Lines & Text### normal_tick_x2 = 5 thirty_tick_x2 = 9 time_text_x = 10 # 9am Ticks & Text y_nine = 64 drawblack.line((0, (y_nine + 10), normal_tick_x2, (y_nine + 10))) drawblack.line((0, (y_nine + 21), normal_tick_x2, (y_nine + 21))) drawblack.line((0, (y_nine + 32), thirty_tick_x2, (y_nine + 32))) drawblack.line((0, (y_nine + 43), normal_tick_x2, (y_nine + 43))) drawblack.line((0, (y_nine + 54), normal_tick_x2, (y_nine + 54))) drawblack.text((time_text_x, (y_nine + 1)), '9am', font=font_time_slot, fill=0) # 10am Line y_ten = 128 drawblack.line((0, y_ten, 384, y_ten), fill=0) # 10am Ticks & Text drawblack.line((0, (y_ten + 10), normal_tick_x2, (y_ten + 10))) drawblack.line((0, (y_ten + 21), normal_tick_x2, (y_ten + 21))) drawblack.line((0, (y_ten + 32), thirty_tick_x2, (y_ten + 32))) drawblack.line((0, (y_ten + 43), normal_tick_x2, (y_ten + 43))) drawblack.line((0, (y_ten + 54), normal_tick_x2, (y_ten + 54))) drawblack.text((time_text_x, (y_ten + 1)), '10am', font=font_time_slot, fill=0) # 11am Line y_eleven = 192 drawblack.line((0, y_eleven, 384, y_eleven), fill=0) # 11am Ticks & Text drawblack.line((0, (y_eleven + 10), normal_tick_x2, (y_eleven + 10))) drawblack.line((0, (y_eleven + 21), normal_tick_x2, (y_eleven + 21))) drawblack.line((0, (y_eleven + 32), thirty_tick_x2, (y_eleven + 32))) drawblack.line((0, (y_eleven + 43), normal_tick_x2, (y_eleven + 43))) drawblack.line((0, (y_eleven + 54), normal_tick_x2, (y_eleven + 54))) drawblack.text((time_text_x, (y_eleven + 1)), '11am', font=font_time_slot, fill=0) # 12pm Line y_twelve = 256 drawblack.line((0, y_twelve, 384, y_twelve), fill=0) # 12pm Ticks & Text drawblack.line((0, (y_twelve + 10), normal_tick_x2, (y_twelve + 10))) drawblack.line((0, (y_twelve + 20), normal_tick_x2, (y_twelve + 20))) drawblack.line((0, (y_twelve + 31), thirty_tick_x2, (y_twelve + 31))) drawblack.line((0, (y_twelve + 42), normal_tick_x2, (y_twelve + 42))) drawblack.line((0, (y_twelve + 53), normal_tick_x2, (y_twelve + 53))) drawblack.text((time_text_x, (y_twelve + 1)), '12pm', font=font_time_slot, fill=0) # 1pm Line y_one = 319 drawblack.line((0, y_one, 384, y_one), fill=0) # 1pm Ticks & Text drawblack.line((0, (y_one + 10), normal_tick_x2, (y_one + 10))) drawblack.line((0, (y_one + 21), normal_tick_x2, (y_one + 21))) drawblack.line((0, (y_one + 32), thirty_tick_x2, (y_one + 32))) drawblack.line((0, (y_one + 43), normal_tick_x2, (y_one + 43))) drawblack.line((0, (y_one + 54), normal_tick_x2, (y_one + 54))) drawblack.text((time_text_x, (y_one + 1)), '1pm', font=font_time_slot, fill=0) # 2pm Line y_two = 383 drawblack.line((0, y_two, 384, y_two), fill=0) # 2pm Ticks & Text drawblack.line((0, (y_two + 10), normal_tick_x2, (y_two + 10))) drawblack.line((0, (y_two + 21), normal_tick_x2, (y_two + 21))) drawblack.line((0, (y_two + 32), thirty_tick_x2, (y_two + 32))) drawblack.line((0, (y_two + 43), normal_tick_x2, (y_two + 43))) drawblack.line((0, (y_two + 54), normal_tick_x2, (y_two + 54))) drawblack.text((time_text_x, (y_two + 1)), '2pm', font=font_time_slot, fill=0) # 3pm Line y_three = 447 drawblack.line((0, y_three, 384, y_three), fill=0) # 3pm Ticks & Textblack drawblack.line((0, (y_three + 10), normal_tick_x2, (y_three + 10))) drawblack.line((0, (y_three + 21), normal_tick_x2, (y_three + 21))) drawblack.line((0, (y_three + 32), thirty_tick_x2, (y_three + 32))) drawblack.line((0, (y_three + 43), normal_tick_x2, (y_three + 43))) drawblack.line((0, (y_three + 54), normal_tick_x2, (y_three + 54))) drawblack.text((time_text_x, (y_three + 1)), '3pm', font=font_time_slot, fill=0) # 4pm Line y_four = 511 drawblack.line((0, y_four, 384, y_four), fill=0) # 4pm Ticks & Text drawblack.line((0, (y_four + 10), normal_tick_x2, (y_four + 10))) drawblack.line((0, (y_four + 21), normal_tick_x2, (y_four + 21))) drawblack.line((0, (y_four + 32), thirty_tick_x2, (y_four + 32))) drawblack.line((0, (y_four + 43), normal_tick_x2, (y_four + 43))) drawblack.line((0, (y_four + 54), normal_tick_x2, (y_four + 54))) drawblack.text((time_text_x, (y_four + 1)), '4pm', font=font_time_slot, fill=0) # 5pm Line y_five = 575 drawblack.line((0, y_five, 384, y_five), fill=0) # 5pm Ticks & Text drawblack.line((0, (y_five + 10), normal_tick_x2, (y_five + 10))) drawblack.line((0, (y_five + 21), normal_tick_x2, (y_five + 21))) drawblack.line((0, (y_five + 32), thirty_tick_x2, (y_five + 32))) drawblack.line((0, (y_five + 43), normal_tick_x2, (y_five + 43))) drawblack.line((0, (y_five + 54), normal_tick_x2, (y_five + 54))) drawblack.text((time_text_x, (y_five + 1)), '5pm', font=font_time_slot, fill=0) #6pm Text drawblack.text((time_text_x, 623), '6pm', font=font_time_slot, fill=0) return (epd, drawblack, drawred, HBlackimage, HRedimage)
def displaySongs(command): epd = epd7in5b.EPD() epd.init() album = command.replace("displaysongs album: ", "").replace("\n", "") songlist = songs[album] image = Image.new('L', (EPD_WIDTH, EPD_HEIGHT), 255) # 255: clear the frame draw = ImageDraw.Draw(image) font = ImageFont.truetype( '/usr/share/fonts/truetype/freefont/FreeMonoBold.ttf', 14) widthPerSong = AVAILABLE_WIDTH / len(songlist) heightPerSong = AVAILABLE_HEIGHT / len(songlist) for song in songlist: index = songlist.index(song) songName = song["name"] songYear = song["year"] slashIndex = songName.index("/") + 1 dotIndex = songName.index(".mp3") songDisplayName = songName[slashIndex:dotIndex].replace("_", " ").replace( "1-", "") positionLeft = BEGIN_LEFT + index * widthPerSong positionRight = BEGIN_LEFT + (index + 1) * widthPerSong positionTop = BEGIN_TOP + RECTANGLE_Y_OFFSET + index * heightPerSong positionBottom = BEGIN_TOP + RECTANGLE_Y_OFFSET + \ RECTANGLE_HEIGHT + index * heightPerSong xPositionCentered = positionLeft + (widthPerSong / 2) songTextSize = draw.textsize(songDisplayName, font=font) yearTextSize = draw.textsize(songYear, font=font) textXPosition = xPositionCentered - (songTextSize[0] / 2) textYPosition = positionTop - RECTANGLE_Y_OFFSET - RECTANGLE_HEIGHT tickXPosition = xPositionCentered - (TICK_WIDTH / 2) tickYPosition = END_BOTTOM + TIMELINE_Y_OFFSET - (TICK_HEIGHT / 2) yearXPosition = xPositionCentered - (yearTextSize[0] / 2) yearYPosition = tickYPosition + TICK_HEIGHT + YEAR_Y_OFFSET # large rectangle draw.rectangle( (positionLeft, positionTop, positionRight, positionBottom), fill=0) # timeline rectangle draw.rectangle( (tickXPosition, tickYPosition, tickXPosition + TICK_WIDTH, tickYPosition + TICK_HEIGHT), fill=0) # song name draw.text((textXPosition, textYPosition), songDisplayName, font=font, fill=0) # year name draw.text((yearXPosition, yearYPosition), songYear, font=font, fill=0) timelineYPosition = END_BOTTOM + TIMELINE_Y_OFFSET - (TIMELINE_HEIGHT / 2) draw.rectangle((BEGIN_LEFT, timelineYPosition, END_RIGHT, timelineYPosition + TIMELINE_HEIGHT), fill=0) # For simplicity, the arguments are explicit numerical coordinates epd.display_frame(epd.get_frame_buffer(image))
def update_image(): image = Image.open(StringIO(request.data)) epd = epd7in5b.EPD() epd.init() epd.display_frame(epd.get_frame_buffer(image)) return "ok"