Merge pull request #358 from aceinnolab/hotfix/#357

Hotfix/#357
This commit is contained in:
Ace 2024-07-05 16:53:00 +02:00 committed by GitHub
commit 276298c32b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 23 additions and 28 deletions

View File

@ -36,8 +36,8 @@ class EPD:
def getbuffer(self, image): def getbuffer(self, image):
"""ad-hoc""" """ad-hoc"""
image = image.rotate(90, expand=True).transpose(Image.FLIP_LEFT_RIGHT) image = image.rotate(90, expand=True).transpose(Image.FLIP_LEFT_RIGHT)
image.convert('RGB').save(os.path.join(settings.IMAGE_FOLDER, 'canvas.bmp'), 'BMP') image.convert("RGB").save(os.path.join(settings.IMAGE_FOLDER, "canvas.bmp"), "BMP")
command = f'sudo {settings.PARALLEL_DRIVER_PATH}/epd -{settings.VCOM} 0 {settings.IMAGE_FOLDER + "canvas.bmp"}' command = f'sudo {settings.PARALLEL_DRIVER_PATH}/epd -{settings.VCOM} 0 {os.path.join(settings.IMAGE_FOLDER, "canvas.bmp")}'
print(command) print(command)
return command return command

View File

@ -34,8 +34,8 @@ class EPD:
def getbuffer(self, image): def getbuffer(self, image):
"""ad-hoc""" """ad-hoc"""
image = image.rotate(90, expand=True) image = image.rotate(90, expand=True)
image.convert('RGB').save(os.path.join(settings.IMAGE_FOLDER, 'canvas.bmp'), 'BMP') image.convert("RGB").save(os.path.join(settings.IMAGE_FOLDER, "canvas.bmp"), 'BMP')
command = f'sudo {settings.PARALLEL_DRIVER_PATH}/epd -{settings.VCOM} 0 {settings.IMAGE_FOLDER + "canvas.bmp"}' command = f'sudo {settings.PARALLEL_DRIVER_PATH}/epd -{settings.VCOM} 0 {os.path.join(settings.IMAGE_FOLDER, "canvas.bmp")}'
print(command) print(command)
return command return command

View File

@ -2,6 +2,7 @@
9.7" driver class 9.7" driver class
Copyright by aceinnolab Copyright by aceinnolab
""" """
import os
from subprocess import run from subprocess import run
from inkycal.settings import Settings from inkycal.settings import Settings
@ -10,11 +11,8 @@ from inkycal.settings import Settings
EPD_WIDTH = 1200 EPD_WIDTH = 1200
EPD_HEIGHT = 825 EPD_HEIGHT = 825
settings = Settings() settings = Settings()
command = f'sudo {settings.PARALLEL_DRIVER_PATH}/epd -{settings.VCOM} 0 {settings.IMAGE_FOLDER + "canvas.bmp"}'
class EPD: class EPD:
@ -36,8 +34,8 @@ class EPD:
def getbuffer(self, image): def getbuffer(self, image):
"""ad-hoc""" """ad-hoc"""
image = image.rotate(90, expand=True) image = image.rotate(90, expand=True)
image.convert('RGB').save(settings.IMAGE_FOLDER + 'canvas.bmp', 'BMP') image.convert("RGB").save(os.path.join(settings.IMAGE_FOLDER, "canvas.bmp"), "BMP")
command = f'sudo {settings.PARALLEL_DRIVER_PATH}/epd -{settings.VCOM} 0 {settings.IMAGE_FOLDER + "canvas.bmp"}' command = f'sudo {settings.PARALLEL_DRIVER_PATH}/epd -{settings.VCOM} 0 {os.path.join(settings.IMAGE_FOLDER, "canvas.bmp")}'
print(command) print(command)
return command return command

View File

@ -137,11 +137,8 @@ class Inkycal:
except: except:
logger.exception(f"Exception: {traceback.format_exc()}.") logger.exception(f"Exception: {traceback.format_exc()}.")
# Path to store images
self.image_folder = settings.IMAGE_FOLDER
# Remove old hashes # Remove old hashes
self._remove_hashes(self.image_folder) self._remove_hashes(settings.IMAGE_FOLDER)
# set up cache # set up cache
if not os.path.exists(os.path.join(settings.CACHE_PATH, CACHE_NAME)): if not os.path.exists(os.path.join(settings.CACHE_PATH, CACHE_NAME)):
@ -352,11 +349,11 @@ class Inkycal:
self._calibration_check() self._calibration_check()
if self._calibration_state: if self._calibration_state:
# After calibration, we have to forcefully rewrite the screen # After calibration, we have to forcefully rewrite the screen
self._remove_hashes(self.image_folder) self._remove_hashes(settings.IMAGE_FOLDER)
if self.supports_colour: if self.supports_colour:
im_black = Image.open(f"{self.image_folder}canvas.png") im_black = Image.open(os.path.join(settings.IMAGE_FOLDER, "canvas.png"))
im_colour = Image.open(f"{self.image_folder}canvas_colour.png") im_colour = Image.open(os.path.join(settings.IMAGE_FOLDER, "canvas_colour.png"))
# Flip the image by 180° if required # Flip the image by 180° if required
if self.settings['orientation'] == 180: if self.settings['orientation'] == 180:
@ -365,8 +362,8 @@ class Inkycal:
# Render the image on the display # Render the image on the display
if not self.settings.get('image_hash', False) or self._needs_image_update([ if not self.settings.get('image_hash', False) or self._needs_image_update([
(f"{self.image_folder}/canvas.png.hash", im_black), (f"{settings.IMAGE_FOLDER}/canvas.png.hash", im_black),
(f"{self.image_folder}/canvas_colour.png.hash", im_colour) (f"{settings.IMAGE_FOLDER}/canvas_colour.png.hash", im_colour)
]): ]):
display.render(im_black, im_colour) display.render(im_black, im_colour)
@ -379,7 +376,7 @@ class Inkycal:
im_black = upside_down(im_black) im_black = upside_down(im_black)
if not self.settings.get('image_hash', False) or self._needs_image_update([ if not self.settings.get('image_hash', False) or self._needs_image_update([
(f"{self.image_folder}/canvas.png.hash", im_black), ]): (f"{settings.IMAGE_FOLDER}/canvas.png.hash", im_black), ]):
display.render(im_black) display.render(im_black)
logger.info(f'\nNo errors since {self.counter} display updates') logger.info(f'\nNo errors since {self.counter} display updates')
@ -415,8 +412,8 @@ class Inkycal:
returns the merged image returns the merged image
""" """
im1_path = os.path.join(settings.image_folder, "canvas.png") im1_path = os.path.join(settings.IMAGE_FOLDER, "canvas.png")
im2_path = os.path.join(settings.image_folder, "canvas_colour.png") im2_path = os.path.join(settings.IMAGE_FOLDER, "canvas_colour.png")
# If there is an image for black and colour, merge them # If there is an image for black and colour, merge them
if os.path.exists(im1_path) and os.path.exists(im2_path): if os.path.exists(im1_path) and os.path.exists(im2_path):
@ -454,8 +451,8 @@ class Inkycal:
for number in range(1, self._module_number): for number in range(1, self._module_number):
# get the path of the current module's generated images # get the path of the current module's generated images
im1_path = f"{self.image_folder}module{number}_black.png" im1_path = os.path.join(settings.IMAGE_FOLDER, f"module{number}_black.png")
im2_path = f"{self.image_folder}module{number}_colour.png" im2_path = os.path.join(settings.IMAGE_FOLDER, f"module{number}_colour.png")
# Check if there is an image for the black band # Check if there is an image for the black band
if os.path.exists(im1_path): if os.path.exists(im1_path):
@ -525,8 +522,8 @@ class Inkycal:
im_black = self._optimize_im(im_black) im_black = self._optimize_im(im_black)
im_colour = self._optimize_im(im_colour) im_colour = self._optimize_im(im_colour)
im_black.save(self.image_folder + 'canvas.png', 'PNG') im_black.save(os.path.join(settings.IMAGE_FOLDER, "canvas.png"), "PNG")
im_colour.save(self.image_folder + 'canvas_colour.png', 'PNG') im_colour.save(os.path.join(settings.IMAGE_FOLDER, "canvas_colour.png"), 'PNG')
# Additionally, combine the two images with color # Additionally, combine the two images with color
def clear_white(img): def clear_white(img):
@ -614,8 +611,8 @@ class Inkycal:
black, colour = module.generate_image() black, colour = module.generate_image()
if self.show_border: if self.show_border:
draw_border_2(im=black, xy=(1, 1), size=(black.width - 2, black.height - 2), radius=5) draw_border_2(im=black, xy=(1, 1), size=(black.width - 2, black.height - 2), radius=5)
black.save(f"{self.image_folder}module{number}_black.png", "PNG") black.save(os.path.join(settings.IMAGE_FOLDER, f"module{number}_black.png"), "PNG")
colour.save(f"{self.image_folder}module{number}_colour.png", "PNG") colour.save(os.path.join(settings.IMAGE_FOLDER, f"module{number}_colour.png"), "PNG")
return True return True
except Exception: except Exception:
logger.exception(f"Error in module {number}!") logger.exception(f"Error in module {number}!")

View File

@ -15,6 +15,6 @@ class Settings:
INKYCAL_LOG_PATH = os.path.join(LOG_PATH, "inkycal.log") INKYCAL_LOG_PATH = os.path.join(LOG_PATH, "inkycal.log")
FONT_PATH = os.path.join(basedir, "../fonts") FONT_PATH = os.path.join(basedir, "../fonts")
IMAGE_FOLDER = os.path.join(basedir, "../image_folder") IMAGE_FOLDER = os.path.join(basedir, "../image_folder")
PARALLEL_DRIVER_PATH = os.path.join(basedir, "inkycal", "display", "drivers", "parallel_drivers") PARALLEL_DRIVER_PATH = os.path.join(basedir, "display", "drivers", "parallel_drivers")
TEMPORARY_FOLDER = os.path.join(basedir, "tmp") TEMPORARY_FOLDER = os.path.join(basedir, "tmp")
VCOM = "2.0" VCOM = "2.0"