epaper/main.py

113 lines
3.6 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('RGB', (480, 800), 'white')
draw = ImageDraw.Draw(image)
import modules
config = modules.Config()
# Weather
# Toolbar
from modules.weather import WeatherToolbarModule
image.paste(WeatherToolbarModule().draw_module(config, 480, 50), (0, 0))
# Current Weather
from modules.weather import WeatherJumboCurrentModule
image.paste(WeatherJumboCurrentModule().draw_module(config, 480, 150), (0, 50))
# rule
image.paste(modules.RuleModule().draw_module(config, 450, 1), (30, 192))
# pluie
from modules.weather import WeatherRainModule
image.paste(WeatherRainModule().draw_module(config, 480-int(480/1.6), 94), (0, 205))
# moon phase
from modules.weather import WeatherMoonPhaseModule
moon = WeatherMoonPhaseModule().draw_module(config, 65, 65)
image.paste(moon, (0, 163), moon)
# weekly weather
from modules.weather import WeeklyWeatherModule
image.paste(WeeklyWeatherModule().draw_module(config, int(480/1.6), 275), (480-int(480/1.6), 305))
# alerts
from modules.weather import WeatherAlertsModule
mod = WeatherAlertsModule().draw_module(config, 480, 200)
image.paste(mod, (0, 580-mod.height-5), mod)
# 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), 205))
# températures
from modules.weather import WeatherTemperatureModule
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
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()