Dynamic imports + calibration function

This commit is contained in:
Ace 2020-01-18 16:06:49 +01:00 committed by GitHub
parent fa5b122ae9
commit 87eaf0d5da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -9,19 +9,14 @@ assembles them and sends it to the E-Paper
Copyright by aceisace Copyright by aceisace
""" """
from __future__ import print_function from __future__ import print_function
from configuration import *
import arrow import arrow
from time import sleep from time import sleep
import gc import gc
import inkycal_rss as rss
import inkycal_weather as weather
import inkycal_calendar as calendar
import inkycal_agenda as agenda
from configuration import * """Perepare for execution of main programm"""
import importlib calibration_countdown = 'initial'
driver = importlib.import_module('drivers.'+model) skip_calibration = False
"""Remove previously generated images"""
image_cleanup() image_cleanup()
"""Check time and calibrate display if time """ """Check time and calibrate display if time """
@ -35,36 +30,44 @@ while True:
'D MMM YYYY'), now.format('HH:mm'))) 'D MMM YYYY'), now.format('HH:mm')))
print('-----------Main programm started now----------') print('-----------Main programm started now----------')
"""------------------Calibration check----------------"""
if skip_calibration != True:
print('Calibration..', end = ' ')
if now.hour in calibration_hours:
if calibration_countdown == 'initial':
print('required. Performing calibration now.')
calibration_countdown = 0
calibrate_display(3)
else:
if calibration_countdown % (60 // int(update_interval)) == 0:
calibrate_display(3)
calibration_countdown = 0
else:
print('not required. Continuing...')
else:
print('Calibration skipped!. Please note that not calibrating e-paper',
'displays causes ghosting')
"""----------------Generating and assembling images------""" """----------------Generating and assembling images------"""
if top_section == 'Weather':
try: try:
weather.main() top_section_module = importlib.import_module(top_section)
weather_image = Image.open(image_path + 'weather.png') top_section_image = Image.open(image_path + top_section+'.png')
image.paste(weather_image, (0, 0)) image.paste(top_section_image, (0, 0))
except: except:
pass pass
if middle_section == 'Calendar':
try: try:
calendar.main() middle_section_module = importlib.import_module(middle_section)
calendar_image = Image.open(image_path + 'calendar.png') middle_section_image = Image.open(image_path + middle_section+'.png')
image.paste(calendar_image, (0, middle_section_offset)) image.paste(middle_section_image, (0, middle_section_offset))
except: except:
pass pass
if middle_section == 'Agenda':
try: try:
agenda.main() bottom_section_module = importlib.import_module(bottom_section)
agenda_image = Image.open(image_path + 'agenda.png') bottom_section_image = Image.open(image_path + bottom_section+'.png')
image.paste(agenda_image, (0, middle_section_offset)) image.paste(bottom_section_image, (0, bottom_section_offset))
except:
pass
if bottom_section == 'RSS':
try:
rss.main()
rss_image = Image.open(image_path + 'rss.png')
image.paste(rss_image, (0, bottom_section_offset))
except: except:
pass pass
@ -94,6 +97,11 @@ while True:
"""Collect some garbage to free up some resources""" """Collect some garbage to free up some resources"""
gc.collect() gc.collect()
"""Adjust calibration countdowns"""
if calibration_countdown == 'initial':
calibration_countdown = 0
calibration_countdown += 1
"""Calculate duration until next display refresh""" """Calculate duration until next display refresh"""
for _ in range(1): for _ in range(1):
update_timings = [(60 - int(update_interval)*updates) for updates in update_timings = [(60 - int(update_interval)*updates) for updates in