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