epaper/main.py

157 lines
5.3 KiB
Python
Raw Normal View History

2022-08-11 12:46:36 +00:00
##
# @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(only_on_coming_evt=False):
2022-08-11 12:46:36 +00:00
image = Image.new('1', (480, 800), 255)
2022-08-14 16:25:06 +00:00
#image = Image.new('L', (480, 800), 'white')
2022-08-11 12:46:36 +00:00
draw = ImageDraw.Draw(image)
import modules
config = modules.Config()
# Weather
# Current Weather
from modules.weather import WeatherJumboCurrentModule
2022-08-14 16:25:06 +00:00
image.paste(WeatherJumboCurrentModule().draw_module(config, 480, 150), (0, 0))
2022-08-11 12:46:36 +00:00
# rule
2022-08-14 16:25:06 +00:00
image.paste(modules.RuleModule().draw_module(config, 450, 1), (30, 142))
2022-08-11 12:46:36 +00:00
# pluie
from modules.weather import WeatherRainModule
2022-08-14 16:25:06 +00:00
image.paste(WeatherRainModule().draw_module(config, 480-int(480/1.6), 94), (0, 155))
2022-08-11 12:46:36 +00:00
2022-08-14 11:32:52 +00:00
# moon phase
from modules.weather import WeatherMoonPhaseModule
moon = WeatherMoonPhaseModule().draw_module(config, 65, 65)
2022-08-14 16:25:06 +00:00
image.paste(moon, (0, 113), moon)
2022-08-11 12:46:36 +00:00
2022-08-21 02:03:33 +00:00
# ical
from modules.ical import IcalModule
ical = IcalModule(config)
cal = ical.draw_module(config, 480-int(480/1.6), 255)
image.paste(cal, (0, 250))
occuped_space = 0
evt_coming = ical.non_local_event_coming(config) or ical.local_event_ending(config)
2022-08-21 02:03:33 +00:00
if evt_coming:
from modules.ratp import RATPNextStopModule
nstops = RATPNextStopModule().draw_module(config, ["RB/cite+universitaire", "M7/porte+d'italie"], int(480/1.6), 275)
image.paste(nstops, (480-int(480/1.6), 255))
occuped_space = nstops.height
elif only_on_coming_evt:
# stop here in this case
return
2022-08-21 02:03:33 +00:00
if occuped_space < 250:
# weekly weather
from modules.weather import WeeklyWeatherModule
image.paste(WeeklyWeatherModule().draw_module(config, int(480/1.6), 275), (480-int(480/1.6), 255 + occuped_space))
2022-08-11 12:46:36 +00:00
2022-08-14 13:19:51 +00:00
# RATP weather
from modules.ratp import RATPWeatherModule
ratp = RATPWeatherModule().draw_module(config, int(480/1.6), 94)
2022-08-14 16:25:06 +00:00
image.paste(ratp, (480-int(480/1.6), 155))
# Toolbar
from modules.weather import WeatherToolbarModule
image.paste(WeatherToolbarModule().draw_module(config, 480, 50), (0, 530))
2022-08-14 13:19:51 +00:00
2022-08-14 13:32:52 +00:00
# alerts
alerts = []
2022-08-14 16:25:06 +00:00
alerts += [a for a in RATPWeatherModule().gen_alerts()]
2022-08-19 11:59:43 +00:00
from modules.sncf import SNCFWeatherModule
alerts += SNCFWeatherModule().gen_alerts("normandie")
from modules.weather import WeatherAlerts
2022-08-14 13:32:52 +00:00
alerts += WeatherAlerts().gen_alerts()
from modules import AlertsModule
2022-08-14 16:25:06 +00:00
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)
2022-08-14 13:32:52 +00:00
2022-08-11 12:46:36 +00:00
# températures
from modules.weather import WeatherTemperatureModule
2022-08-14 16:25:06 +00:00
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))
2022-08-11 12:46:36 +00:00
2022-08-14 11:32:52 +00:00
# sunrise/set
from modules.weather import WeatherSunModule
image.paste(WeatherSunModule().draw_module(config, int(480/2), 20, start_align=5), (0, 780))
2022-08-11 12:46:36 +00:00
fnt = ImageFont.truetype(config.fnt_R_path, 11)
draw.text(
2022-08-14 11:32:52 +00:00
(475, 798),
2022-08-11 12:46:36 +00:00
"Dernière génération le " + datetime.now().strftime("%c"),
2022-08-14 11:32:52 +00:00
fill="black", anchor="rb", font=fnt
2022-08-11 12:46:36 +00:00
)
try:
import epd7in5
2022-12-10 17:46:13 +00:00
#print("image generated")
2022-08-11 12:46:36 +00:00
epd = epd7in5.EPD()
epd.init()
2022-12-10 17:46:13 +00:00
#print("initialized")
2022-08-11 12:46:36 +00:00
epd.display(epd.getbuffer(image))
2022-12-10 17:46:13 +00:00
#print("time to sleep")
2022-08-11 12:46:36 +00:00
epd.sleep()
except:
image.save("screen.png")
if __name__ == '__main__':
import argparse
parser = argparse.ArgumentParser(description='E-ink status generator.')
parser.add_argument('--only-on-coming-evt', '-O', action='store_const', const=True,
help='Refresh screen only if there is upcoming event')
args = parser.parse_args()
main(args.only_on_coming_evt)