Allow usage without display and SPI when setting render->False
Generated images will be available in the images folder
This commit is contained in:
		| @@ -10,6 +10,7 @@ from PIL import Image | ||||
| from inkycal.custom import top_level | ||||
| import glob | ||||
|  | ||||
|  | ||||
| class Display: | ||||
|     """Display class for inkycal | ||||
|  | ||||
| @@ -81,14 +82,14 @@ class Display: | ||||
|  | ||||
|         epaper = self._epaper | ||||
|  | ||||
|     if self.supports_colour == False: | ||||
|         if not self.supports_colour: | ||||
|             print('Initialising..', end='') | ||||
|             epaper.init() | ||||
|             print('Updating display......', end='') | ||||
|             epaper.display(epaper.getbuffer(im_black)) | ||||
|             print('Done') | ||||
|  | ||||
|     elif self.supports_colour == True: | ||||
|         elif self.supports_colour: | ||||
|             if not im_colour: | ||||
|                 raise Exception('im_colour is required for coloured epaper displays') | ||||
|             print('Initialising..', end='') | ||||
| @@ -116,7 +117,7 @@ class Display: | ||||
|         critical, but not calibrating regularly results in grey-ish text. | ||||
|  | ||||
|         Please note that calibration takes a while to complete. 3 cycles may | ||||
|     take 10 mins on black-white E-Papers while it takes 20 minutes on coloured | ||||
|         take 10 minutes on black-white E-Papers while it takes 20 minutes on coloured | ||||
|         E-Paper displays. | ||||
|         """ | ||||
|  | ||||
| @@ -129,7 +130,7 @@ class Display: | ||||
|         black = Image.new('1', display_size, 'black') | ||||
|  | ||||
|         print('----------Started calibration of ePaper display----------') | ||||
|     if self.supports_colour == True: | ||||
|         if self.supports_colour: | ||||
|             for _ in range(cycles): | ||||
|                 print('Calibrating...', end=' ') | ||||
|                 print('black...', end=' ') | ||||
| @@ -140,7 +141,7 @@ class Display: | ||||
|                 epaper.display(epaper.getbuffer(white), epaper.getbuffer(white)) | ||||
|                 print(f'Cycle {_ + 1} of {cycles} complete') | ||||
|  | ||||
|     if self.supports_colour == False: | ||||
|         if not self.supports_colour: | ||||
|             for _ in range(cycles): | ||||
|                 print('Calibrating...', end=' ') | ||||
|                 print('black...', end=' ') | ||||
| @@ -152,12 +153,11 @@ class Display: | ||||
|             print('-----------Calibration complete----------') | ||||
|             epaper.sleep() | ||||
|  | ||||
|  | ||||
|     @classmethod | ||||
|     def get_display_size(cls, model_name): | ||||
|         """Returns the size of the display as a tuple -> (width, height) | ||||
|  | ||||
|     Looks inside drivers folder for the given model name, then returns it's | ||||
|         Looks inside "drivers" folder for the given model name, then returns it's | ||||
|         size. | ||||
|  | ||||
|         Args: | ||||
| @@ -214,6 +214,6 @@ class Display: | ||||
|         drivers.remove('epdconfig') | ||||
|         print(*drivers, sep='\n') | ||||
|  | ||||
|  | ||||
| if __name__ == '__main__': | ||||
|     print("Running Display class in standalone mode") | ||||
|  | ||||
|   | ||||
| @@ -1,4 +1,4 @@ | ||||
| #!/usr/bin/python3 | ||||
| #!python3 | ||||
| # -*- coding: utf-8 -*- | ||||
|  | ||||
| """ | ||||
| @@ -73,6 +73,7 @@ logging.getLogger("PIL").setLevel(logging.WARNING) | ||||
| filename = os.path.basename(__file__).split('.py')[0] | ||||
| logger = logging.getLogger(filename) | ||||
|  | ||||
|  | ||||
| # TODO: autostart -> supervisor? | ||||
|  | ||||
| class Inkycal: | ||||
| @@ -122,15 +123,13 @@ class Inkycal: | ||||
|                 print('No settings file found in /boot') | ||||
|                 return | ||||
|  | ||||
|  | ||||
|         # Option to use epaper image optimisation, reduces colours | ||||
|         self.optimize = True | ||||
|  | ||||
|         # Load drivers if image should be rendered | ||||
|         if self.render == True: | ||||
|  | ||||
|             # Init Display class with model in settings file | ||||
|       from inkycal.display import Display | ||||
|             # from inkycal.display import Display | ||||
|             self.Display = Display(settings["model"]) | ||||
|  | ||||
|             # check if colours can be rendered | ||||
| @@ -198,7 +197,6 @@ class Inkycal: | ||||
|         # Return seconds until next update | ||||
|         return remaining_time | ||||
|  | ||||
|  | ||||
|     def test(self): | ||||
|         """Tests if Inkycal can run without issues. | ||||
|  | ||||
| @@ -356,7 +354,6 @@ class Inkycal: | ||||
|  | ||||
|         return im1 | ||||
|  | ||||
|  | ||||
|     def _assemble(self): | ||||
|         """Assembles all sub-images to a single image""" | ||||
|  | ||||
| @@ -431,7 +428,6 @@ class Inkycal: | ||||
|                 # Shift the y-axis cursor at the beginning of next section | ||||
|                 im2_cursor += section_size[1] | ||||
|  | ||||
|  | ||||
|         # Add info-section if specified -- | ||||
|  | ||||
|         # Calculate the max. fontsize for info-section | ||||
| @@ -485,7 +481,6 @@ class Inkycal: | ||||
|         else: | ||||
|             self._calibration_state = False | ||||
|  | ||||
|  | ||||
|     @classmethod | ||||
|     def add_module(cls, filepath): | ||||
|         """registers a third party module for inkycal. | ||||
| @@ -538,7 +533,6 @@ class Inkycal: | ||||
|             raise TypeError("your module doesn't seem to be a correct inkycal module.." | ||||
|                             "Please check your module again.") | ||||
|  | ||||
|  | ||||
|         # Check if filename or classname exists in init of module folder | ||||
|         with open(module_folder + '/__init__.py', mode='r') as file: | ||||
|             module_init = file.read().splitlines() | ||||
| @@ -586,7 +580,6 @@ class Inkycal: | ||||
|         print(f"Your module '{filename}' with class '{classname}' has been added " | ||||
|               "successfully! Hooray!") | ||||
|  | ||||
|  | ||||
|     @classmethod | ||||
|     def remove_module(cls, filename, remove_file=True): | ||||
|         """unregisters a inkycal module. | ||||
| @@ -669,5 +662,6 @@ class Inkycal: | ||||
|  | ||||
|         print(f"Your module '{filename}' with class '{classname}' was removed.") | ||||
|  | ||||
|  | ||||
| if __name__ == '__main__': | ||||
|     print(f'running inkycal main in standalone/debug mode') | ||||
|   | ||||
		Reference in New Issue
	
	Block a user