Add files via upload

This commit is contained in:
Ace 2018-08-27 00:21:30 +02:00 committed by GitHub
parent 2a7a4d12c3
commit c167e5631e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
76 changed files with 736 additions and 0 deletions

226
Calendar/cal2-4.py Normal file
View file

@ -0,0 +1,226 @@
"""
Copyright by Ace-Laboratory
"""
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
##import requests #need to try changing from urllib to requests
from urllib.request import urlopen #allows url to be 'read'
import arrow #icalendar parser compatible dates
from calibration import calibration
epd = epd7in5b.EPD() #required
epd.init() #required
"""
Attention: Yahoo Calendar urls (for ics) may not work if there is an issue
with their servers. If you are expierencing issues, you might want to use google
calendar.
"""
#google#url = "https://calendar.google.com/calendar/ical/5r4fb74fncg569g17tqc941vco%40group.calendar.google.com/private-5e7bc80e93055e1fbc41ec358b2babab/basic.ics"
#yahoo calendar might not be so reliable in the long term.
url = "https://calendar.yahoo.com/saadnaseer63/9607e906db373c21566df3824b05e127/ycal.ics?id=1246"
calendar.setfirstweekday(calendar.MONDAY) #mon or sun
c = Calendar(urlopen(url).read().decode('UTF-8')) #was 'iso-8859-1'
##c = Calendar(requests.get(url)urlopen(url).read().decode('iso-8859-1'))
e = Event()
open = Image.open
EPD_WIDTH = 640
EPD_HEIGHT = 384
font = ImageFont.truetype('/usr/share/fonts/truetype/Assistant/Assistant-Bold.otf', 18)
path = '/home/pi/Calendar/'
wpath = path+'weather-icons/'
mpath = path+'months/'
dpath = path+'days/'
weekday = open(path+'/other/weekday.bmp')
eventicon = open(path+'other/event.bmp')
dateicon = open(path+'other/today.bmp')
tempicon = open(path+'other/temp-icon.bmp')
humicon = open(path+'other/hum-icon.bmp')
weekmon = open(path+'other/week-mon.bmp')
weeksun = open(path+'other/week-sun.bmp')
bar = open(path+'other/bar.bmp')
#qr = open(path+'other/qr.bmp') #dev
wiconplace = (570, 219)
tempplace = (605, 310)
humplace = (572, 308)
monthplace = (443, 0)
weekplace = (415,0)
barplace = (555, 0)
weekdaysmon = {'Mon': (416,3), 'Tue': (416,57), 'Wed': (416,111), 'Thu': (416,165), 'Fri': (416,219), 'Sat': (416,273), 'Sun':(416,327)}
weekdayssun = {'Sun': (416,3), 'Mon': (416,57), 'Tue': (416,111), 'Wed': (416,165), 'Thu': (416,219), 'Fri': (416,273), 'Sat':(416,327)}
positions = {'a1': (351, 3), 'a2': (351, 57), 'a3': (351, 111), 'a4': (351, 165), 'a5': (351, 219), 'a6': (351, 273), 'a7': (351, 327),
'b1': (284, 3), 'b2': (284, 57), 'b3': (284, 111), 'b4': (284, 165), 'b5': (284, 219), 'b6': (284, 273), 'b7': (284, 327),
'c1': (217, 3), 'c2': (217, 57), 'c3': (217, 111), 'c4': (217, 165), 'c5': (217, 219), 'c6': (217, 273), 'c7': (217, 327),
'd1': (150, 3), 'd2': (150, 57), 'd3': (150, 111), 'd4': (150, 165), 'd5': (150, 219), 'd6': (150, 273), 'd7': (150, 327),
'e1': (83, 3), 'e2': (83, 57), 'e3': (83, 111), 'e4': (83, 165), 'e5': (83, 219), 'e6': (83, 273), 'e7': (83, 327),
'f1': (16, 3), 'f2': (16, 57), 'f3': (16, 111), 'f4': (16, 165), 'f5': (16, 219), 'f6': (16, 273), 'f7': (16, 327)}
weathericons = {'01d': 'wi-day-sunny', '02d':'wi-day-cloudy', '03d': 'wi-cloudy',
'04d': 'wi-cloudy-windy', '09d': 'wi-showers', '10d':'wi-rain',
'11d':'wi-thunderstorm', '13d':'wi-snow', '50d': 'wi-fog',
'01n': 'wi-night-clear', '02n':'wi-night-cloudy',
'03n': 'wi-night-cloudy', '04n': 'wi-night-cloudy',
'09n': 'wi-night-showers', '10n':'wi-night-rain',
'11n':'wi-night-thunderstorm', '13n':'wi-night-snow',
'50n': 'wi-night-alt-cloudy-windy'}
def main():
while True:
time = datetime.now()
hour = int(time.strftime("%-H"))
for i in range(1):
if hour is 0:
calibration()
if hour is 12:
calibration()
if hour is 18: #change to 18
calibration()
image = Image.new('L', (EPD_WIDTH, EPD_HEIGHT), 255)
draw = (ImageDraw.Draw(image)).bitmap
#background image
draw(monthplace, Image.open(mpath+str(time.strftime("%B"))+'.bmp'))
if calendar.firstweekday() == 0:
draw(weekplace, weekmon)
if calendar.firstweekday() == 6:
draw(weekplace, weeksun)
draw(barplace, bar)
cal = calendar.monthcalendar(time.year, time.month)
for i in cal[0]:
draw(positions['a'+str(cal[0].index(i)+1)] ,open(dpath+str(i)+'.bmp'))
for i in cal[1]:
draw(positions['b'+str(cal[1].index(i)+1)] ,open(dpath+str(i)+'.bmp'))
for i in cal[2]:
draw(positions['c'+str(cal[2].index(i)+1)] ,open(dpath+str(i)+'.bmp'))
for i in cal[3]:
draw(positions['d'+str(cal[3].index(i)+1)] ,open(dpath+str(i)+'.bmp'))
for i in cal[4]:
draw(positions['e'+str(cal[4].index(i)+1)] ,open(dpath+str(i)+'.bmp'))
try:
for i in cal[5]:
draw(positions['f'+str(cal[5].index(i)+1)] ,Image.open(dpath+str(i)+'.bmp'))
except IndexError:
pass
# openweathermap api
owm = pyowm.OWM('57c07b8f2ae09e348d32317f1bfe3f52')
observation = owm.weather_at_place('Stuttgart, DE')
weather = observation.get_weather()
weathericon = weather.get_weather_icon_name()
Temperature = str(int(weather.get_temperature(unit='celsius')['temp']))
Humidity = str(weather.get_humidity())
#print('weather icon:', weathericon) -->debug
#print('Temperature:', Temperature + '°C') -->debug
#print('Humidity:', Humidity+' %') -->debug
#weather icon handler
draw(wiconplace, open(wpath+weathericons[weathericon]+'.bmp'))
# date writing function
space1=Image.new('1', (115,25), color=255)
measure1= ImageDraw.Draw(space1)
date = ImageDraw.Draw(space1)
date.text((2, 3), (time.strftime('%a %-d %b %y')), font=font, fill=0)
rotate1 = space1.rotate(270, expand=1)
image.paste(rotate1, (595,20))
# temperature writing function
space2 = Image.new('1', (50,35), color=255)
measure2= ImageDraw.Draw(space2)
temperature = ImageDraw.Draw(space2)
temperature.text((2, 8), (Temperature + " °C"), fill=0 ,font=font)
rotate2 = space2.rotate(270, expand=1)
image.paste(rotate2, (605,334))
# humidity writing function
space3 = Image.new('1', (50,35), color=255)
measure3= ImageDraw.Draw(space3)
humidity = ImageDraw.Draw(space3)
humidity.text((4, 8), (Humidity +'%'), fill=0 ,font=font)
rotate3 = space3.rotate(270, expand=1)
image.paste(rotate3, (570,334))
# weekday handler
if calendar.firstweekday() == 0:
draw(weekdaysmon[(time.strftime("%a"))], weekday)
if calendar.firstweekday() == 6:
draw(weekdayssun[(time.strftime("%a"))], weekday)
print('It is currently:',time.strftime('%a %-d %b %y')) #--debug
print('The current time is:', time.strftime('%H:%M')) #--debug
elist = []
for events in c.events:
if str(time.year) in str((events.begin).format('YYYY')):
if str(time.month) in str((events.begin).format('M')):
elist.append(int((events.begin).format('D')))
print('In this month, you have',len(elist),'Events') # -->debug
#cal = calendar.monthcalendar(time.year, time.month)
for x in elist:
if x in cal[0]:
draw(positions['a'+str(cal[0].index(x)+1)] ,eventicon)
if x in cal[1]:
draw(positions['b'+str(cal[1].index(x)+1)] ,eventicon)
if x in cal[2]:
draw(positions['c'+str(cal[2].index(x)+1)] ,eventicon)
if x in cal[3]:
draw(positions['d'+str(cal[3].index(x)+1)] ,eventicon)
if x in cal[4]:
draw(positions['e'+str(cal[4].index(x)+1)] ,eventicon)
try:
if x in cal[5]:
draw(positions['f'+str(cal[5].index(x)+1)] ,eventicon)
except IndexError:
pass
today = time.day
if today in cal[0]:
draw(positions['a'+str(cal[0].index(today)+1)] ,dateicon)
if today in cal[1]:
draw(positions['b'+str(cal[1].index(today)+1)] ,dateicon)
if today in cal[2]:
draw(positions['c'+str(cal[2].index(today)+1)] ,dateicon)
if today in cal[3]:
draw(positions['d'+str(cal[3].index(today)+1)] ,dateicon)
if today in cal[4]:
draw(positions['e'+str(cal[4].index(today)+1)] ,dateicon)
try:
if today in cal[5]:
draw(positions['f'+str(cal[5].index(today)+1)] ,dateicon)
except IndexError:
pass
draw(tempplace, tempicon)
draw(humplace, humicon)
epd.display_frame(epd.get_frame_buffer(image))
# delete the list so deleted events can be removed from the list
del elist[:]
for i in range(1):
nexthour = ((60 - int(time.strftime("%-M")))*60) - (int(time.strftime("%-S")))
sleep(nexthour)
if __name__ == '__main__':
main()

35
Calendar/calibration.py Normal file
View file

@ -0,0 +1,35 @@
import epd7in5b
from PIL import Image, ImageDraw, ImageFont
EPD_WIDTH = 640
EPD_HEIGHT = 384
def calibration():
for i in range(2):
epd = epd7in5b.EPD()
epd.init()
black = Image.new('L', (EPD_WIDTH, EPD_HEIGHT), 0)
print('calibrating black...')
ImageDraw.Draw(black)
epd.display_frame(epd.get_frame_buffer(black))
#print(epd.get_frame_buffer(black))
red = Image.new('L', (EPD_WIDTH, EPD_HEIGHT), 127)
ImageDraw.Draw(red)
print('calibrating red...')
epd.display_frame(epd.get_frame_buffer(red))
white = Image.new('L', (EPD_WIDTH, EPD_HEIGHT), 255)
ImageDraw.Draw(white)
print('calibrating white...')
epd.display_frame(epd.get_frame_buffer(white))
print('Cycle complete!')
def main():
epd = epd7in5b.EPD()
epd.init()
for i in range(1):
calibration()
if __name__ == '__main__':
main()

BIN
Calendar/days/0.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.5 KiB

BIN
Calendar/days/1.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

BIN
Calendar/days/10.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

BIN
Calendar/days/11.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

BIN
Calendar/days/12.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

BIN
Calendar/days/13.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

BIN
Calendar/days/14.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

BIN
Calendar/days/15.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

BIN
Calendar/days/16.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

BIN
Calendar/days/17.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

BIN
Calendar/days/18.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

BIN
Calendar/days/19.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

BIN
Calendar/days/2.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

BIN
Calendar/days/20.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

BIN
Calendar/days/21.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

BIN
Calendar/days/22.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

BIN
Calendar/days/23.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

BIN
Calendar/days/24.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

BIN
Calendar/days/25.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

BIN
Calendar/days/26.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

BIN
Calendar/days/27.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

BIN
Calendar/days/28.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

BIN
Calendar/days/29.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

BIN
Calendar/days/3.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

BIN
Calendar/days/30.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

BIN
Calendar/days/31.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

BIN
Calendar/days/4.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

BIN
Calendar/days/5.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

BIN
Calendar/days/6.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

BIN
Calendar/days/7.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

BIN
Calendar/days/8.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

BIN
Calendar/days/9.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

209
Calendar/epd7in5b.py Normal file
View file

@ -0,0 +1,209 @@
##
# @filename : epd7in5.py
# @brief : Implements for Dual-color e-paper library
# @author : Yehui from Waveshare
#
# Copyright (C) Waveshare July 10 2017
#
# 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
# copies of the Software, and to permit persons to whom the Software is
# furished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
import epdif
from PIL import Image
import RPi.GPIO as GPIO
# Display resolution
EPD_WIDTH = 640
EPD_HEIGHT = 384
# EPD7IN5 commands
PANEL_SETTING = 0x00
POWER_SETTING = 0x01
POWER_OFF = 0x02
POWER_OFF_SEQUENCE_SETTING = 0x03
POWER_ON = 0x04
POWER_ON_MEASURE = 0x05
BOOSTER_SOFT_START = 0x06
DEEP_SLEEP = 0x07
DATA_START_TRANSMISSION_1 = 0x10
DATA_STOP = 0x11
DISPLAY_REFRESH = 0x12
IMAGE_PROCESS = 0x13
LUT_FOR_VCOM = 0x20
LUT_BLUE = 0x21
LUT_WHITE = 0x22
LUT_GRAY_1 = 0x23
LUT_GRAY_2 = 0x24
LUT_RED_0 = 0x25
LUT_RED_1 = 0x26
LUT_RED_2 = 0x27
LUT_RED_3 = 0x28
LUT_XON = 0x29
PLL_CONTROL = 0x30 #was 0x30
TEMPERATURE_SENSOR_COMMAND = 0x40
TEMPERATURE_CALIBRATION = 0x41
TEMPERATURE_SENSOR_WRITE = 0x42
TEMPERATURE_SENSOR_READ = 0x43
VCOM_AND_DATA_INTERVAL_SETTING = 0x50
LOW_POWER_DETECTION = 0x51
TCON_SETTING = 0x60
TCON_RESOLUTION = 0x61
SPI_FLASH_CONTROL = 0x65
REVISION = 0x70
GET_STATUS = 0x71
AUTO_MEASUREMENT_VCOM = 0x80
READ_VCOM_VALUE = 0x81
VCM_DC_SETTING = 0x82 #was 0x82
class EPD:
def __init__(self):
self.reset_pin = epdif.RST_PIN
self.dc_pin = epdif.DC_PIN
self.busy_pin = epdif.BUSY_PIN
self.width = EPD_WIDTH
self.height = EPD_HEIGHT
def digital_write(self, pin, value):
epdif.epd_digital_write(pin, value)
def digital_read(self, pin):
return epdif.epd_digital_read(pin)
def delay_ms(self, delaytime):
epdif.epd_delay_ms(delaytime)
def send_command(self, command):
self.digital_write(self.dc_pin, GPIO.LOW)
# the parameter type is list but not int
# so use [command] instead of command
epdif.spi_transfer([command])
def send_data(self, data):
self.digital_write(self.dc_pin, GPIO.HIGH)
# the parameter type is list but not int
# so use [data] instead of data
epdif.spi_transfer([data])
def init(self):
if (epdif.epd_init() != 0):
return -1
self.reset()
self.send_command(POWER_SETTING)
self.send_data(0x37)
self.send_data(0x00)
self.send_command(PANEL_SETTING)
self.send_data(0xCF)
self.send_data(0x08)
self.send_command(BOOSTER_SOFT_START)
self.send_data(0xc7)
self.send_data(0xcc)
self.send_data(0x28)
self.send_command(POWER_ON)
self.wait_until_idle()
self.send_command(PLL_CONTROL)
self.send_data(0x3c)
self.send_command(TEMPERATURE_CALIBRATION)
self.send_data(0x00)
self.send_command(VCOM_AND_DATA_INTERVAL_SETTING)
self.send_data(0x77)
self.send_command(TCON_SETTING)
self.send_data(0x22)
self.send_command(TCON_RESOLUTION)
self.send_data(0x02) #source 640
self.send_data(0x80)
self.send_data(0x01) #gate 384
self.send_data(0x80)
self.send_command(VCM_DC_SETTING)
self.send_data(0x1E) #decide by LUT file
self.send_command(0xe5) #FLASH MODE
self.send_data(0x03)
def wait_until_idle(self):
while(self.digital_read(self.busy_pin) == 0): # 0: busy, 1: idle
self.delay_ms(100)
def reset(self):
self.digital_write(self.reset_pin, GPIO.LOW) # module reset
self.delay_ms(200)
self.digital_write(self.reset_pin, GPIO.HIGH)
self.delay_ms(200)
def get_frame_buffer(self, image):
buf = [0x00] * int(self.width * self.height / 4)
# Set buffer to value of Python Imaging Library image.
# Image must be in mode L.
image_grayscale = image.convert('L')
imwidth, imheight = image_grayscale.size
if imwidth != self.width or imheight != self.height:
raise ValueError('Image must be same dimensions as display \
({0}x{1}).' .format(self.width, self.height))
pixels = image_grayscale.load()
for y in range(self.height):
for x in range(self.width):
# Set the bits for the column of pixels at the current position.
if pixels[x, y] < 64: # black
buf[int((x + y * self.width) / 4)] &= ~(0xC0 >> (x % 4 * 2))
elif pixels[x, y] < 192: # convert gray to red
buf[int((x + y * self.width) / 4)] &= ~(0xC0 >> (x % 4 * 2))
buf[int((x + y * self.width) / 4)] |= 0x40 >> (x % 4 * 2)
else: # white
buf[int((x + y * self.width) / 4)] |= 0xC0 >> (x % 4 * 2)
return buf #due to python2 -> python3, int had to be added in 'get_frame
#_buffer
def display_frame(self, frame_buffer):
self.send_command(DATA_START_TRANSMISSION_1)
for i in range(0, int(self.width / 4 * self.height)):
#the above line had to be modified due to python2 -> python3
#the issue lies in division, which returns integers in python2
#but floats in python3
temp1 = frame_buffer[i]
j = 0
while (j < 4):
if ((temp1 & 0xC0) == 0xC0):
temp2 = 0x03
elif ((temp1 & 0xC0) == 0x00):
temp2 = 0x00
else:
temp2 = 0x04
temp2 = (temp2 << 4) & 0xFF
temp1 = (temp1 << 2) & 0xFF
j += 1
if((temp1 & 0xC0) == 0xC0):
temp2 |= 0x03
elif ((temp1 & 0xC0) == 0x00):
temp2 |= 0x00
else:
temp2 |= 0x04
temp1 = (temp1 << 2) & 0xFF
self.send_data(temp2)
j += 1
self.send_command(DISPLAY_REFRESH)
self.delay_ms(100)
self.wait_until_idle()
def sleep(self):
self.send_command(POWER_OFF)
self.wait_until_idle()
self.send_command(DEEP_SLEEP)
self.send_data(0xa5)
### END OF FILE ###

64
Calendar/epdif.py Normal file
View file

@ -0,0 +1,64 @@
##
# @filename : epdif.py
# @brief : EPD hardware interface implements (GPIO, SPI)
# @author : Yehui from Waveshare
#
# Copyright (C) Waveshare July 10 2017
#
# 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
# copies of the Software, and to permit persons to whom the Software is
# furished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
import spidev
import RPi.GPIO as GPIO
import time
# Pin definition
RST_PIN = 17
DC_PIN = 25
CS_PIN = 8
BUSY_PIN = 24
# SPI device, bus = 0, device = 0
SPI = spidev.SpiDev(0, 0)
#SPI.no_cs = True
def epd_digital_write(pin, value):
GPIO.output(pin, value)
def epd_digital_read(pin):
return GPIO.input(BUSY_PIN)
def epd_delay_ms(delaytime):
time.sleep(delaytime / 1000.0)
def spi_transfer(data):
SPI.writebytes(data)
def epd_init():
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(RST_PIN, GPIO.OUT)
GPIO.setup(DC_PIN, GPIO.OUT)
GPIO.setup(CS_PIN, GPIO.OUT)
GPIO.setup(BUSY_PIN, GPIO.IN)
SPI.max_speed_hz = 6250000 #was 2000000
SPI.mode = 0b00 #was 0b00
return 0;
### END OF FILE ###

117
Calendar/events.py Normal file
View file

@ -0,0 +1,117 @@
import epd7in5b
from PIL import Image, ImageDraw, ImageFont, ImageOps
import calendar, pyowm
from ics import Calendar, Event
from datetime import datetime
from time import sleep
from urllib.request import urlopen
import arrow
epd = epd7in5b.EPD()
epd.init()
url ="https://calendar.yahoo.com/jmuj6o2qum5wwa7aboeb3qxss5hssod4rlmbev5g/c4a110ace0d020e426cea69a2a873a19/ycal.ics?id=131"
#Enter your ical url above
c = Calendar(urlopen(url).read().decode('iso-8859-1'))
e = Event()
open = Image.open
EPD_WIDTH = 640
EPD_HEIGHT = 384
fpath = '/usr/share/fonts/truetype/Assistant/Assistant-Bold.otf'
fontsmall = ImageFont.truetype(fpath, 20)
fontbig = ImageFont.truetype(fpath, 34)
path = './dev-only/'
background = open(path+'background.bmp')
template = open(path+'event.bmp')
positions = {
'A1': (517,11), 'A2': (462,11), 'A3': (407,11), 'A4': (352,11), 'A5': (297,11),
'A6': (242,11), 'A7': (187,11), 'A8': (132,11), 'A9': (77,11), 'A10': (22,11),
'B1': (515,71), 'B2': (460, 71), 'B3': (460, 71), 'B4': (460, 71), 'B5': (460, 71),
'B6': (460, 71), 'B7': (460, 71), 'B8': (460, 71), 'B9': (460, 71), 'B10': (460, 71),
'C1':(542,313), 'C2':(487,313), 'C3':(432,313), 'C4':(377,313), 'C5':(322,313),
'C6':(267,313), 'C7':(212,313), 'C8':(157,313), 'C9':(102,313), 'C10':(47,313)
}
def main():
for i in range(1):
time = datetime.now()
for i in range(1):
image = Image.new('L', (EPD_WIDTH, EPD_HEIGHT), 255)
draw = (ImageDraw.Draw(image)).bitmap
print('Today is:',time.strftime('%a %-d %b %y'))
print('The time is ', time.strftime('%H:%M'))
edaylist = []
for events in c.events:
if str(time.year) in str((events.begin).format('YYYY')):
if str(time.month) in str((events.begin).format('M')):
edaylist.append((events.begin).format('D'))
print('In this month, you have',len(edaylist),'Events')
print(edaylist)
enamelist = []
for events in c.events:
if str(time.year) in str((events.begin).format('YYYY')):
if str(time.month) in str((events.begin).format('M')):
if str(time.month) in str((events.begin).format('M')):
enamelist.append(str(events.name))
for items in edaylist:
#date
txt = (events.begin).format('D')
w,h = fontbig.getsize(txt)
space = Image.new('1', (50,50), color=255)
date = ImageDraw.Draw(space)
date.text((int((50-w)/2),int((50-h)/2)), txt, fill=0,font=fontbig)
rotate = space.rotate(270, expand=1)
image.paste(rotate, positions['A'+len])#(517,11))
#print(enamelist)
#for items in enamelist:
#draw(positions['A'+events
etimelist = []
for events in c.events:
if str(time.year) in str((events.begin).format('YYYY')):
if str(time.month) in str((events.begin).format('M')):
etimelist.append(events.begin.format('HH:mm'))
print(etimelist)
# name
txt = enamelist[0]
w,h = fontsmall.getsize(txt) #works!
space = Image.new('1', (234,50), color=255)
name = ImageDraw.Draw(space)
name.text((int((234-w)/2),int((50-h)/2)), txt, fill=0, font = fontsmall)
rotate = space.rotate(270, expand=1)
image.paste(rotate, (515,71))
# time
txt = etimelist[0]
w,h = fontsmall.getsize(txt)
space = Image.new('1', (60,25), color=255) #use L and 127 to show
date = ImageDraw.Draw(space)
date.text((int((60-w)/2),int((25-h)/2)), txt, fill=0 ,font=fontsmall)
rotate = space.rotate(270, expand=1)
image.paste(rotate, (542,313))
draw((0,0), background)
draw((515,0), template)
del edaylist[:]
del enamelist[:]
del etimelist[:]
epd.display_frame(epd.get_frame_buffer(image))
if __name__ == '__main__':
main()

85
Calendar/license Normal file
View file

@ -0,0 +1,85 @@
PYOWM
The MIT License (MIT)
Copyright (c) 2013 Claudio Sparpaglione
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation 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 copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
ASSISTANT FONT
Copyright 2010 The Assistant Project Authors, with Reserved Font Name Source. Source is a trademark of Adobe Systems Incorporated in the United States and/or other countries.
This Font Software is licensed under the SIL Open Font License, Version 1.1.
This license is copied below, and is also available with a FAQ at: http://scripts.sil.org/OFL
—————————————————————————————-
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
—————————————————————————————-
PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide development of collaborative font projects, to support the font creation efforts of academic and linguistic communities, and to provide a free and open framework in which fonts may be shared and improved in partnership with others.
The OFL allows the licensed fonts to be used, studied, modified and redistributed freely as long as they are not sold by themselves. The fonts, including any derivative works, can be bundled, embedded, redistributed and/or sold with any software provided that any reserved names are not used by derivative works. The fonts and derivatives, however, cannot be released under any other type of license. The requirement for fonts to remain under this license does not apply to any document created using the fonts or their derivatives.
DEFINITIONS
“Font Software” refers to the set of files released by the Copyright Holder(s) under this license and clearly marked as such. This may include source files, build scripts and documentation.
“Reserved Font Name” refers to any names specified as such after the copyright statement(s).
“Original Version” refers to the collection of Font Software components as distributed by the Copyright Holder(s).
“Modified Version” refers to any derivative made by adding to, deleting, or substituting—in part or in whole—any of the components of the Original Version, by changing formats or by porting the Font Software to a new environment.
“Author” refers to any designer, engineer, programmer, technical writer or other person who contributed to the Font Software.
PERMISSION & CONDITIONS
Permission is hereby granted, free of charge, to any person obtaining a copy of the Font Software, to use, study, copy, merge, embed, modify, redistribute, and sell modified and unmodified copies of the Font Software, subject to the following conditions:
1) Neither the Font Software nor any of its individual components, in Original or Modified Versions, may be sold by itself.
2) Original or Modified Versions of the Font Software may be bundled, redistributed and/or sold with any software, provided that each copy contains the above copyright notice and this license. These can be included either as stand-alone text files, human-readable headers or in the appropriate machine-readable metadata fields within text or binary files as long as those fields can be easily viewed by the user.
3) No Modified Version of the Font Software may use the Reserved Font Name(s) unless explicit written permission is granted by the corresponding Copyright Holder. This restriction only applies to the primary font name as presented to the users.
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font Software shall not be used to promote, endorse or advertise any Modified Version, except to acknowledge the contribution(s) of the Copyright Holder(s) and the Author(s) or with their explicit written permission.
5) The Font Software, modified or unmodified, in part or in whole, must be distributed entirely under this license, and must not be distributed under any other license. The requirement for fonts to remain under this license does not apply to any document created using the Font Software.
TERMINATION
This license becomes null and void if any of the above conditions are not met.
DISCLAIMER
THE FONT SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER DEALINGS IN THE FONT SOFTWARE.
PILLOW:
The Python Imaging Library (PIL) is
Copyright © 1997-2011 by Secret Labs AB
Copyright © 1995-2011 by Fredrik Lundh
Pillow is the friendly PIL fork. It is
Copyright © 2010-2018 by Alex Clark and contributors
Like PIL, Pillow is licensed under the open source PIL Software License:
By obtaining, using, and/or copying this software and/or its associated documentation, you agree that you have read, understood, and will comply with the following terms and conditions:
Permission to use, copy, modify, and distribute this software and its associated documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appears in all copies, and that both that copyright notice and this permission notice appear in supporting documentation, and that the name of Secret Labs AB or the author not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission.
SECRET LABS AB AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL SECRET LABS AB OR THE AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

BIN
Calendar/months/April.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

BIN
Calendar/months/August.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

BIN
Calendar/months/July.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

BIN
Calendar/months/June.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

BIN
Calendar/months/March.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

BIN
Calendar/months/May.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

BIN
Calendar/months/October.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 241 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 241 KiB

BIN
Calendar/other/bar.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

BIN
Calendar/other/event.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

BIN
Calendar/other/hum-icon.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

BIN
Calendar/other/today.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

BIN
Calendar/other/week-mon.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

BIN
Calendar/other/week-sun.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

BIN
Calendar/other/weekday.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6 KiB