diff options
author | Marvin Borner | 2019-12-28 15:17:20 +0100 |
---|---|---|
committer | Marvin Borner | 2019-12-28 15:17:20 +0100 |
commit | 7ab78f003c0b9374ec3067ce10dc6111bcc25e06 (patch) | |
tree | 1fecec9b092dd6983629397341d47fca087a8b13 | |
parent | 4443ead95e3175bbc29f1b9eabbe7df338af4767 (diff) |
AMAZINGNESS
-rw-r--r-- | epaper/epd2in13.py | 138 | ||||
-rw-r--r-- | epaper/main.py | 50 |
2 files changed, 104 insertions, 84 deletions
diff --git a/epaper/epd2in13.py b/epaper/epd2in13.py index 4ad2c24..9d1359a 100644 --- a/epaper/epd2in13.py +++ b/epaper/epd2in13.py @@ -1,35 +1,17 @@ -# //*****************************************************************************
-# * | File : epd2in13.py
+# *****************************************************************************
+# * | File : epd2in13_V2.py
# * | Author : Waveshare team
# * | Function : Electronic paper driver
# * | Info :
# *----------------
-# * | This version: V3.0
-# * | Date : 2018-11-01
-# * | Info : python2 demo
-# * 1.Remove:
-# digital_write(self, pin, value)
-# digital_read(self, pin)
-# delay_ms(self, delaytime)
-# set_lut(self, lut)
-# self.lut = self.lut_full_update
-# * 2.Change:
-# display_frame -> TurnOnDisplay
-# set_memory_area -> SetWindow
-# set_memory_pointer -> SetCursor
-# * 3.How to use
-# epd = epd2in13.EPD()
-# epd.init(epd.lut_full_update)
-# image = Image.new('1', (epd2in13.EPD_WIDTH, epd2in13.EPD_HEIGHT), 255)
-# ...
-# drawing ......
-# ...
-# epd.display(getbuffer(image))
-# ******************************************************************************//
+# * | This version: V4.0
+# * | Date : 2019-06-20
+# # | Info : python demo
+# -----------------------------------------------------------------------------
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documnetation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
-# to use, copy, modify, merge, publish, distribute, sublicense, and//or sell
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furished to do so, subject to the following conditions:
#
@@ -46,10 +28,9 @@ #
+import logging
import epdconfig
-from PIL import Image
-import RPi.GPIO as GPIO
-# import numpy as np
+import numpy as np
# Display resolution
EPD_WIDTH = 122
@@ -60,8 +41,10 @@ class EPD: self.reset_pin = epdconfig.RST_PIN
self.dc_pin = epdconfig.DC_PIN
self.busy_pin = epdconfig.BUSY_PIN
+ self.cs_pin = epdconfig.CS_PIN
self.width = EPD_WIDTH
self.height = EPD_HEIGHT
+
FULL_UPDATE = 0
PART_UPDATE = 1
lut_full_update= [
@@ -102,22 +85,26 @@ class EPD: # Hardware reset
def reset(self):
- epdconfig.digital_write(self.reset_pin, GPIO.HIGH)
+ epdconfig.digital_write(self.reset_pin, 1)
epdconfig.delay_ms(200)
- epdconfig.digital_write(self.reset_pin, GPIO.LOW) # module reset
- epdconfig.delay_ms(200)
- epdconfig.digital_write(self.reset_pin, GPIO.HIGH)
+ epdconfig.digital_write(self.reset_pin, 0)
+ epdconfig.delay_ms(10)
+ epdconfig.digital_write(self.reset_pin, 1)
epdconfig.delay_ms(200)
def send_command(self, command):
- epdconfig.digital_write(self.dc_pin, GPIO.LOW)
+ epdconfig.digital_write(self.dc_pin, 0)
+ epdconfig.digital_write(self.cs_pin, 0)
epdconfig.spi_writebyte([command])
+ epdconfig.digital_write(self.cs_pin, 1)
def send_data(self, data):
- epdconfig.digital_write(self.dc_pin, GPIO.HIGH)
+ epdconfig.digital_write(self.dc_pin, 1)
+ epdconfig.digital_write(self.cs_pin, 0)
epdconfig.spi_writebyte([data])
+ epdconfig.digital_write(self.cs_pin, 1)
- def wait_until_idle(self):
+ def ReadBusy(self):
while(epdconfig.digital_read(self.busy_pin) == 1): # 0: idle, 1: busy
epdconfig.delay_ms(100)
@@ -125,17 +112,23 @@ class EPD: self.send_command(0x22)
self.send_data(0xC7)
self.send_command(0x20)
- self.wait_until_idle()
-
+ self.ReadBusy()
+
+ def TurnOnDisplayPart(self):
+ self.send_command(0x22)
+ self.send_data(0x0c)
+ self.send_command(0x20)
+ self.ReadBusy()
+
def init(self, update):
if (epdconfig.module_init() != 0):
return -1
# EPD hardware init start
self.reset()
if(update == self.FULL_UPDATE):
- self.wait_until_idle()
+ self.ReadBusy()
self.send_command(0x12) # soft reset
- self.wait_until_idle()
+ self.ReadBusy()
self.send_command(0x74) #set analog block control
self.send_data(0x54)
@@ -150,11 +143,11 @@ class EPD: self.send_command(0x11) #data entry mode
self.send_data(0x01)
- self.send_command(0x44) #set Ram-X address start//end position
+ self.send_command(0x44) #set Ram-X address start/end position
self.send_data(0x00)
self.send_data(0x0F) #0x0C-->(15+1)*8=128
- self.send_command(0x45) #set Ram-Y address start//end position
+ self.send_command(0x45) #set Ram-Y address start/end position
self.send_data(0xF9) #0xF9-->(249+1)=250
self.send_data(0x00)
self.send_data(0x00)
@@ -188,12 +181,12 @@ class EPD: self.send_command(0x4F) # set RAM y address count to 0X127
self.send_data(0xF9)
self.send_data(0x00)
- self.wait_until_idle()
+ self.ReadBusy()
else:
self.send_command(0x2C) #VCOM Voltage
self.send_data(0x26)
- self.wait_until_idle()
+ self.ReadBusy()
self.send_command(0x32)
for count in range(70):
@@ -211,7 +204,7 @@ class EPD: self.send_command(0x22)
self.send_data(0xC0)
self.send_command(0x20)
- self.wait_until_idle()
+ self.ReadBusy()
self.send_command(0x3C) #BorderWavefrom
self.send_data(0x01)
@@ -219,9 +212,9 @@ class EPD: def getbuffer(self, image):
if self.width%8 == 0:
- linewidth = self.width//8
+ linewidth = int(self.width/8)
else:
- linewidth = self.width//8 + 1
+ linewidth = int(self.width/8) + 1
buf = [0xFF] * (linewidth * self.height)
image_monocolor = image.convert('1')
@@ -229,29 +222,29 @@ class EPD: pixels = image_monocolor.load()
if(imwidth == self.width and imheight == self.height):
- print("Vertical")
+ logging.debug("Vertical")
for y in range(imheight):
for x in range(imwidth):
if pixels[x, y] == 0:
x = imwidth - x
- buf[x // 8 + y * linewidth] &= ~(0x80 >> (x % 8))
+ buf[int(x / 8) + y * linewidth] &= ~(0x80 >> (x % 8))
elif(imwidth == self.height and imheight == self.width):
- print("Horizontal")
+ logging.debug("Horizontal")
for y in range(imheight):
for x in range(imwidth):
newx = y
newy = self.height - x - 1
if pixels[x, y] == 0:
newy = imwidth - newy - 1
- buf[newx // 8 + newy*linewidth] &= ~(0x80 >> (y % 8))
+ buf[int(newx / 8) + newy*linewidth] &= ~(0x80 >> (y % 8))
return buf
def display(self, image):
if self.width%8 == 0:
- linewidth = self.width//8
+ linewidth = int(self.width/8)
else:
- linewidth = self.width//8 + 1
+ linewidth = int(self.width/8) + 1
self.send_command(0x24)
for j in range(0, self.height):
@@ -261,26 +254,46 @@ class EPD: def displayPartial(self, image):
if self.width%8 == 0:
- linewidth = self.width//8
+ linewidth = int(self.width/8)
+ else:
+ linewidth = int(self.width/8) + 1
+
+ self.send_command(0x24)
+ for j in range(0, self.height):
+ for i in range(0, linewidth):
+ self.send_data(image[i + j * linewidth])
+
+
+ # self.send_command(0x26)
+ # for j in range(0, self.height):
+ # for i in range(0, linewidth):
+ # self.send_data(~image[i + j * linewidth])
+ self.TurnOnDisplayPart()
+
+ def displayPartBaseImage(self, image):
+ if self.width%8 == 0:
+ linewidth = int(self.width/8)
else:
- linewidth = self.width//8 + 1
+ linewidth = int(self.width/8) + 1
self.send_command(0x24)
for j in range(0, self.height):
for i in range(0, linewidth):
self.send_data(image[i + j * linewidth])
+
+
self.send_command(0x26)
for j in range(0, self.height):
for i in range(0, linewidth):
- self.send_data(~image[i + j * linewidth])
+ self.send_data(image[i + j * linewidth])
self.TurnOnDisplay()
def Clear(self, color):
if self.width%8 == 0:
- linewidth = self.width//8
+ linewidth = int(self.width/8)
else:
- linewidth = self.width//8 + 1
- # print(linewidth)
+ linewidth = int(self.width/8) + 1
+ # logging.debug(linewidth)
self.send_command(0x24)
for j in range(0, self.height):
@@ -289,13 +302,12 @@ class EPD: self.TurnOnDisplay()
def sleep(self):
- self.send_command(0x22) #POWER OFF
- self.send_data(0xC3)
- self.send_command(0x20)
-
self.send_command(0x10) #enter deep sleep
self.send_data(0x01)
- epdconfig.delay_ms(100)
+ epdconfig.delay_ms(100)
+
+ epdconfig.module_exit()
### END OF FILE ###
+
diff --git a/epaper/main.py b/epaper/main.py index b25c821..6e97544 100644 --- a/epaper/main.py +++ b/epaper/main.py @@ -3,29 +3,37 @@ import epd2in13 import time +import requests +from datetime import date +from datetime import datetime from PIL import Image,ImageDraw,ImageFont -import traceback font_size = 14 -try: - epd = epd2in13.EPD() - epd.init(epd.FULL_UPDATE) - epd.Clear(0xFF) - - # Drawing on the image - image = Image.new('1', (epd2in13.EPD_HEIGHT, epd2in13.EPD_WIDTH), 255) # 255: clear the frame - - draw = ImageDraw.Draw(image) - font = ImageFont.truetype('/usr/share/fonts/truetype/wqy/wqy-microhei.ttc', font_size) - draw.text((0, 0), 'Guten Tag!', font=font, fill=0) - draw.text((0, font_size + 2), 'Marvin ist toll!', font=font, fill=0) - epd.display(epd.getbuffer(image)) - # time.sleep(10) - # epd.Clear(0xFF) - epd.sleep() - -except: - print('traceback.format_exc():\n%s',traceback.format_exc()) - exit() +epd = epd2in13.EPD() +epd.init(epd.FULL_UPDATE) +epd.Clear(0xFF) +image = Image.new('1', (epd2in13.EPD_HEIGHT, epd2in13.EPD_WIDTH), 255) # 255: clear the frame +draw = ImageDraw.Draw(image) +font = ImageFont.truetype('/usr/share/fonts/truetype/wqy/wqy-microhei.ttc', font_size) + +resp = requests.get('http://data.c3voc.de/36C3/everything.schedule.json') +days = resp.json()['schedule']['conference']['days'] +conferences = [] +for day in days: + for room in day['rooms']: + for conference in day['rooms'][room]: + conf_date = time.mktime(datetime.strptime(conference['date'], '%Y-%m-%dT%H:%M:%S%z').timetuple()) + if conf_date - time.time() > 2 * 60 * 60: + conferences.append(conference) + +sorted_list = sorted(conferences, key = lambda i: i['date']) + +for i in range(1, 6): + draw.text((0, font_size * i + 2), conferences[i - 1]['title'], font=font, fill=0) +epd.display(epd.getbuffer(image)) + +# time.sleep(10) +# epd.Clear(0xFF) +epd.sleep() |