epaper/main.py

135 lines
4.4 KiB
Python

##
# @filename : main.cpp
# @brief : 7.5inch e-paper display demo
# @author : Yehui from Waveshare
#
# Copyright (C) Waveshare July 28 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.
##
from datetime import datetime, timedelta
import io
import locale
import os.path
import time
locale.setlocale(locale.LC_ALL, 'fr_FR.UTF-8')
from PIL import Image, ImageDraw, ImageFont
def main():
image = Image.new('1', (480, 800), 255)
#image = Image.new('L', (480, 800), 'white')
draw = ImageDraw.Draw(image)
import modules
config = modules.Config()
# Weather
# Current Weather
from modules.weather import WeatherJumboCurrentModule
image.paste(WeatherJumboCurrentModule().draw_module(config, 480, 150), (0, 0))
# rule
image.paste(modules.RuleModule().draw_module(config, 450, 1), (30, 142))
# pluie
from modules.weather import WeatherRainModule
image.paste(WeatherRainModule().draw_module(config, 480-int(480/1.6), 94), (0, 155))
# moon phase
from modules.weather import WeatherMoonPhaseModule
moon = WeatherMoonPhaseModule().draw_module(config, 65, 65)
image.paste(moon, (0, 113), moon)
# weekly weather
from modules.weather import WeeklyWeatherModule
image.paste(WeeklyWeatherModule().draw_module(config, int(480/1.6), 275), (480-int(480/1.6), 255))
# RATP weather
from modules.ratp import RATPWeatherModule
ratp = RATPWeatherModule().draw_module(config, int(480/1.6), 94)
image.paste(ratp, (480-int(480/1.6), 155))
# ical
from modules.ical import IcalModule
cal = IcalModule(config).draw_module(config, 480-int(480/1.6), 255)
image.paste(cal, (0, 250))
# Toolbar
from modules.weather import WeatherToolbarModule
image.paste(WeatherToolbarModule().draw_module(config, 480, 50), (0, 530))
# alerts
alerts = []
alerts += [a for a in RATPWeatherModule().gen_alerts()]
from modules.sncf import SNCFWeatherModule
alerts += SNCFWeatherModule().gen_alerts("normandie")
from modules.weather import WeatherAlerts
alerts += WeatherAlerts().gen_alerts()
from modules import AlertsModule
mod = AlertsModule(alerts).draw_module(config, 480, 330)
if mod.height > 260:
image.paste(mod, (0, 580-mod.height+67), mod)
elif mod.height < 100:
image.paste(mod, (0, 580-mod.height-40), mod)
else:
image.paste(mod, (0, 580-mod.height-5), mod)
# températures
from modules.weather import WeatherTemperatureModule
if mod.height > 260:
image.paste(WeatherTemperatureModule().draw_module(config, 480, 200 - mod.height+260), (0, 580 + mod.height-260))
else:
image.paste(WeatherTemperatureModule().draw_module(config, 480, 200), (0, 580))
# sunrise/set
from modules.weather import WeatherSunModule
image.paste(WeatherSunModule().draw_module(config, int(480/2), 20, start_align=5), (0, 780))
fnt = ImageFont.truetype(config.fnt_R_path, 11)
draw.text(
(475, 798),
"Dernière génération le " + datetime.now().strftime("%c"),
fill="black", anchor="rb", font=fnt
)
try:
import epd7in5
print("image generated")
epd = epd7in5.EPD()
epd.init()
print("initialized")
epd.display(epd.getbuffer(image))
print("time to sleep")
epd.sleep()
except:
image.save("screen.png")
if __name__ == '__main__':
main()