#!/usr/bin/env python3 """Inky display-type EEPROM tools.""" import datetime import struct from typing import ClassVar EEP_ADDRESS = 0x50 EEP_WP = 12 DISPLAY_VARIANT = [ None, "Red pHAT (High-Temp)", "Yellow wHAT", "Black wHAT", "Black pHAT", "Yellow pHAT", "Red wHAT", "Red wHAT (High-Temp)", "Red wHAT", None, "Black pHAT (SSD1608)", "Red pHAT (SSD1608)", "Yellow pHAT (SSD1608)", None, "7-Colour (UC8159)", "7-Colour 640x400 (UC8159)", "7-Colour 640x400 (UC8159)", "Black wHAT (SSD1683)", "Red wHAT (SSD1683)", "Yellow wHAT (SSD1683)", "7-Colour 800x480 (AC073TC1A)", "Spectra 6 13.3 1600 x 1200 (EL133UF1)", "Spectra 6 7.3 800 x 480 (E673)", "Red/Yellow pHAT (JD79661)", "Red/Yellow wHAT (JD79668)", "Spectra 6 4.0 600 x 400 (E640)", "Spectra 6 7.3 800 x 480 (E673) AC", "Spectra 6 13.3 1600 x 1200 (EL133UF1) AC", "Red/Yellow wHAT (SSD2683)" ] class EPDType: """Class to represent EPD EEPROM structure.""" valid_colors: ClassVar = [None, "black", "red", "yellow", None, "7colour", "spectra6", "red/yellow"] def __init__(self, width, height, color, pcb_variant, display_variant, write_time=None): """Initialise new EEPROM data structure.""" self.width = width self.height = height self.color = color if isinstance(color, str): self.set_color(color) self.pcb_variant = pcb_variant self.display_variant = display_variant self.eeprom_write_time = str(datetime.datetime.now()) if write_time is None else write_time def __repr__(self): """Return string representation of EEPROM data structure.""" return f"""Display: {self.width}x{self.height} Color: {self.get_color()} PCB Variant: {self.pcb_variant / 10.0} Display Variant: {self.display_variant} Time: {self.eeprom_write_time}""" @classmethod def from_bytes(class_object, data): """Initialise new EEPROM data structure from a bytes-like object or list.""" data = bytearray(data) data = struct.unpack("