diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index fff3aa9..1dad804 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -40,7 +40,7 @@ jobs: source actions-ci/install.sh - name: Pip install pylint, black, & Sphinx run: | - pip install --force-reinstall pylint==1.9.2 black==19.10b0 Sphinx sphinx-rtd-theme + pip install --force-reinstall pylint black==19.10b0 Sphinx sphinx-rtd-theme - name: Library version run: git describe --dirty --always --tags - name: PyLint diff --git a/adafruit_rgb_display/hx8353.py b/adafruit_rgb_display/hx8353.py index 3d6592a..cf2df6f 100644 --- a/adafruit_rgb_display/hx8353.py +++ b/adafruit_rgb_display/hx8353.py @@ -40,12 +40,13 @@ _INVON = const(0x21) _DISPOFF = const(0x28) _DISPON = const(0x29) -_CASET = const(0x2a) -_PASET = const(0x2b) -_RAMWR = const(0x2c) -_RAMRD = const(0x2e) +_CASET = const(0x2A) +_PASET = const(0x2B) +_RAMWR = const(0x2C) +_RAMRD = const(0x2E) _MADCTL = const(0x36) -_COLMOD = const(0x3a) +_COLMOD = const(0x3A) + class HX8353(DisplaySPI): """ @@ -62,6 +63,7 @@ class HX8353(DisplaySPI): >>> display.fill(0x7521) >>> display.pixel(64, 64, 0) """ + _COLUMN_SET = _CASET _PAGE_SET = _PASET _RAM_WRITE = _RAMWR @@ -73,7 +75,6 @@ class HX8353(DisplaySPI): _ENCODE_PIXEL = ">H" _ENCODE_POS = ">HH" - #pylint: disable-msg=useless-super-delegation, too-many-arguments - def __init__(self, spi, dc, cs, rst=None, width=128, height=128, - rotation=0): + # pylint: disable-msg=useless-super-delegation, too-many-arguments + def __init__(self, spi, dc, cs, rst=None, width=128, height=128, rotation=0): super().__init__(spi, dc, cs, rst, width, height, rotation) diff --git a/adafruit_rgb_display/hx8357.py b/adafruit_rgb_display/hx8357.py index a2cea8b..ead3677 100755 --- a/adafruit_rgb_display/hx8357.py +++ b/adafruit_rgb_display/hx8357.py @@ -40,23 +40,24 @@ _INVON = const(0x21) _DISPOFF = const(0x28) _DISPON = const(0x29) -_CASET = const(0x2a) -_PASET = const(0x2b) -_RAMWR = const(0x2c) -_RAMRD = const(0x2e) +_CASET = const(0x2A) +_PASET = const(0x2B) +_RAMWR = const(0x2C) +_RAMRD = const(0x2E) _TEON = const(0x35) _MADCTL = const(0x36) -_COLMOD = const(0x3a) +_COLMOD = const(0x3A) _TEARLINE = const(0x44) -_SETOSC = const(0xb0) -_SETPWR1 = const(0xb1) -_SETRGB = const(0xb3) -_SETCYC = const(0xb4) -_SETCOM = const(0xb6) -_SETC = const(0xb9) -_SETSTBA = const(0xc0) -_SETPANEL = const(0xcc) -_SETGAMMA = const(0xe0) +_SETOSC = const(0xB0) +_SETPWR1 = const(0xB1) +_SETRGB = const(0xB3) +_SETCYC = const(0xB4) +_SETCOM = const(0xB6) +_SETC = const(0xB9) +_SETSTBA = const(0xC0) +_SETPANEL = const(0xCC) +_SETGAMMA = const(0xE0) + class HX8357(DisplaySPI): """ @@ -73,36 +74,63 @@ class HX8357(DisplaySPI): >>> display.fill(0x7521) >>> display.pixel(64, 64, 0) """ + _COLUMN_SET = _CASET _PAGE_SET = _PASET _RAM_WRITE = _RAMWR _RAM_READ = _RAMRD _INIT = ( (_SWRESET, None), - (_SETC, b'\xFF\x83\x57'), - (_SETRGB, b'\x80\x00\x06\x06'), # 0x80 enables SDO pin (0x00 disables) - (_SETCOM, b'\x25'), # -1.52V - (_SETOSC, b'\x68'), # Normal mode 70Hz, Idle mode 55 Hz - (_SETPANEL, b'\x05'), # BGR, Gate direction swapped - (_SETPWR1, b'\x00\x15\x1C\x1C\x83\xAA'), # Not deep standby BT VSPR VSNR AP - (_SETSTBA, b'\x50\x50\x01\x3C\x1E\x08'), # OPON normal OPON idle STBA GEN - (_SETCYC, b'\x02\x40\x00\x2A\x2A\x0D\x78'), # NW 0x02 RTN DIV DUM DUM GDON GDOFF - (_SETGAMMA, b'\x02\x0A\x11\x1d\x23\x35\x41\x4b\x4b\x42\x3A\x27\x1B\x08\x09\x03\x02' \ - b'\x0A\x11\x1d\x23\x35\x41\x4b\x4b\x42\x3A\x27\x1B\x08\x09\x03\x00\x01'), - (_COLMOD, b'\x55'), # 16 bit - (_MADCTL, b'\xc0'), - (_TEON, b'\x00'), - (_TEARLINE, b'\x00\x02'), # TW off + (_SETC, b"\xFF\x83\x57"), + (_SETRGB, b"\x80\x00\x06\x06"), # 0x80 enables SDO pin (0x00 disables) + (_SETCOM, b"\x25"), # -1.52V + (_SETOSC, b"\x68"), # Normal mode 70Hz, Idle mode 55 Hz + (_SETPANEL, b"\x05"), # BGR, Gate direction swapped + (_SETPWR1, b"\x00\x15\x1C\x1C\x83\xAA"), # Not deep standby BT VSPR VSNR AP + (_SETSTBA, b"\x50\x50\x01\x3C\x1E\x08"), # OPON normal OPON idle STBA GEN + ( + _SETCYC, + b"\x02\x40\x00\x2A\x2A\x0D\x78", + ), # NW 0x02 RTN DIV DUM DUM GDON GDOFF + ( + _SETGAMMA, + b"\x02\x0A\x11\x1d\x23\x35\x41\x4b\x4b\x42\x3A\x27\x1B\x08\x09\x03\x02" + b"\x0A\x11\x1d\x23\x35\x41\x4b\x4b\x42\x3A\x27\x1B\x08\x09\x03\x00\x01", + ), + (_COLMOD, b"\x55"), # 16 bit + (_MADCTL, b"\xc0"), + (_TEON, b"\x00"), + (_TEARLINE, b"\x00\x02"), # TW off (_SLPOUT, None), - (_MADCTL, b'\xa0'), + (_MADCTL, b"\xa0"), (_DISPON, None), ) _ENCODE_PIXEL = ">H" _ENCODE_POS = ">HH" - #pylint: disable-msg=useless-super-delegation, too-many-arguments - def __init__(self, spi, dc, cs, rst=None, width=480, height=320, - baudrate=16000000, polarity=0, phase=0, rotation=0): - super().__init__(spi, dc, cs, rst, width, height, - baudrate=baudrate, polarity=polarity, phase=phase, - rotation=rotation) + # pylint: disable-msg=useless-super-delegation, too-many-arguments + def __init__( + self, + spi, + dc, + cs, + rst=None, + width=480, + height=320, + baudrate=16000000, + polarity=0, + phase=0, + rotation=0, + ): + super().__init__( + spi, + dc, + cs, + rst, + width, + height, + baudrate=baudrate, + polarity=polarity, + phase=phase, + rotation=rotation, + ) diff --git a/adafruit_rgb_display/ili9341.py b/adafruit_rgb_display/ili9341.py index 9b52adf..8af891d 100644 --- a/adafruit_rgb_display/ili9341.py +++ b/adafruit_rgb_display/ili9341.py @@ -55,32 +55,36 @@ class ILI9341(DisplaySPI): >>> display.pixel(120, 160, 0) """ - _COLUMN_SET = 0x2a - _PAGE_SET = 0x2b - _RAM_WRITE = 0x2c - _RAM_READ = 0x2e + _COLUMN_SET = 0x2A + _PAGE_SET = 0x2B + _RAM_WRITE = 0x2C + _RAM_READ = 0x2E _INIT = ( - (0xef, b'\x03\x80\x02'), - (0xcf, b'\x00\xc1\x30'), - (0xed, b'\x64\x03\x12\x81'), - (0xe8, b'\x85\x00\x78'), - (0xcb, b'\x39\x2c\x00\x34\x02'), - (0xf7, b'\x20'), - (0xea, b'\x00\x00'), - (0xc0, b'\x23'), # Power Control 1, VRH[5:0] - (0xc1, b'\x10'), # Power Control 2, SAP[2:0], BT[3:0] - (0xc5, b'\x3e\x28'), # VCM Control 1 - (0xc7, b'\x86'), # VCM Control 2 - (0x36, b'\x48'), # Memory Access Control - (0x3a, b'\x55'), # Pixel Format - (0xb1, b'\x00\x18'), # FRMCTR1 - (0xb6, b'\x08\x82\x27'), # Display Function Control - (0xf2, b'\x00'), # 3Gamma Function Disable - (0x26, b'\x01'), # Gamma Curve Selected - (0xe0, # Set Gamma - b'\x0f\x31\x2b\x0c\x0e\x08\x4e\xf1\x37\x07\x10\x03\x0e\x09\x00'), - (0xe1, # Set Gamma - b'\x00\x0e\x14\x03\x11\x07\x31\xc1\x48\x08\x0f\x0c\x31\x36\x0f'), + (0xEF, b"\x03\x80\x02"), + (0xCF, b"\x00\xc1\x30"), + (0xED, b"\x64\x03\x12\x81"), + (0xE8, b"\x85\x00\x78"), + (0xCB, b"\x39\x2c\x00\x34\x02"), + (0xF7, b"\x20"), + (0xEA, b"\x00\x00"), + (0xC0, b"\x23"), # Power Control 1, VRH[5:0] + (0xC1, b"\x10"), # Power Control 2, SAP[2:0], BT[3:0] + (0xC5, b"\x3e\x28"), # VCM Control 1 + (0xC7, b"\x86"), # VCM Control 2 + (0x36, b"\x48"), # Memory Access Control + (0x3A, b"\x55"), # Pixel Format + (0xB1, b"\x00\x18"), # FRMCTR1 + (0xB6, b"\x08\x82\x27"), # Display Function Control + (0xF2, b"\x00"), # 3Gamma Function Disable + (0x26, b"\x01"), # Gamma Curve Selected + ( + 0xE0, # Set Gamma + b"\x0f\x31\x2b\x0c\x0e\x08\x4e\xf1\x37\x07\x10\x03\x0e\x09\x00", + ), + ( + 0xE1, # Set Gamma + b"\x00\x0e\x14\x03\x11\x07\x31\xc1\x48\x08\x0f\x0c\x31\x36\x0f", + ), (0x11, None), (0x29, None), ) @@ -88,19 +92,40 @@ class ILI9341(DisplaySPI): _ENCODE_POS = ">HH" _DECODE_PIXEL = ">BBB" - #pylint: disable-msg=too-many-arguments - def __init__(self, spi, dc, cs, rst=None, width=240, height=320, - baudrate=16000000, polarity=0, phase=0, rotation=0): - super().__init__(spi, dc, cs, rst=rst, width=width, height=height, - baudrate=baudrate, polarity=polarity, phase=phase, - rotation=rotation) + # pylint: disable-msg=too-many-arguments + def __init__( + self, + spi, + dc, + cs, + rst=None, + width=240, + height=320, + baudrate=16000000, + polarity=0, + phase=0, + rotation=0, + ): + super().__init__( + spi, + dc, + cs, + rst=rst, + width=width, + height=height, + baudrate=baudrate, + polarity=polarity, + phase=phase, + rotation=rotation, + ) self._scroll = 0 - #pylint: enable-msg=too-many-arguments - def scroll(self, dy=None): #pylint: disable-msg=invalid-name + # pylint: enable-msg=too-many-arguments + + def scroll(self, dy=None): # pylint: disable-msg=invalid-name """Scroll the display by delta y""" if dy is None: return self._scroll self._scroll = (self._scroll + dy) % self.height - self.write(0x37, struct.pack('>H', self._scroll)) + self.write(0x37, struct.pack(">H", self._scroll)) return None diff --git a/adafruit_rgb_display/rgb.py b/adafruit_rgb_display/rgb.py index d64dfa9..b70de33 100644 --- a/adafruit_rgb_display/rgb.py +++ b/adafruit_rgb_display/rgb.py @@ -29,6 +29,7 @@ """ import time + try: import numpy except ImportError: @@ -48,11 +49,13 @@ _BUFFER_SIZE = 256 try: import platform + if "CPython" in platform.python_implementation(): - _BUFFER_SIZE = 320 * 240 # blit the whole thing + _BUFFER_SIZE = 320 * 240 # blit the whole thing except ImportError: pass + def color565(r, g=0, b=0): """Convert red, green and blue values (0-255) into a 16-bit 565 encoding. As a convenience this is also available in the parent adafruit_rgb_display @@ -61,34 +64,37 @@ def color565(r, g=0, b=0): r, g, b = r # see if the first var is a tuple/list except TypeError: pass - return (r & 0xf8) << 8 | (g & 0xfc) << 3 | b >> 3 + return (r & 0xF8) << 8 | (g & 0xFC) << 3 | b >> 3 + def image_to_data(image): """Generator function to convert a PIL image to 16-bit 565 RGB bytes.""" - #NumPy is much faster at doing this. NumPy code provided by: - #Keith (https://www.blogger.com/profile/02555547344016007163) - data = numpy.array(image.convert('RGB')).astype('uint16') - color = ((data[:, :, 0] & 0xF8) << 8) | ((data[:, :, 1] & 0xFC) << 3) | (data[:, :, 2] >> 3) + # NumPy is much faster at doing this. NumPy code provided by: + # Keith (https://www.blogger.com/profile/02555547344016007163) + data = numpy.array(image.convert("RGB")).astype("uint16") + color = ( + ((data[:, :, 0] & 0xF8) << 8) + | ((data[:, :, 1] & 0xFC) << 3) + | (data[:, :, 2] >> 3) + ) return numpy.dstack(((color >> 8) & 0xFF, color & 0xFF)).flatten().tolist() + class DummyPin: """Can be used in place of a ``DigitalInOut()`` when you don't want to skip it.""" + def deinit(self): """Dummy DigitalInOut deinit""" - pass def switch_to_output(self, *args, **kwargs): """Dummy switch_to_output method""" - pass def switch_to_input(self, *args, **kwargs): """Dummy switch_to_input method""" - pass @property def value(self): """Dummy value DigitalInOut property""" - pass @value.setter def value(self, val): @@ -97,7 +103,6 @@ def value(self, val): @property def direction(self): """Dummy direction DigitalInOut property""" - pass @direction.setter def direction(self, val): @@ -106,23 +111,24 @@ def direction(self, val): @property def pull(self): """Dummy pull DigitalInOut property""" - pass @pull.setter def pull(self, val): pass -class Display: #pylint: disable-msg=no-member + +class Display: # pylint: disable-msg=no-member """Base class for all RGB display devices :param width: number of pixels wide :param height: number of pixels high """ + _PAGE_SET = None _COLUMN_SET = None _RAM_WRITE = None _RAM_READ = None - _X_START = 0 # pylint: disable=invalid-name - _Y_START = 0 # pylint: disable=invalid-name + _X_START = 0 # pylint: disable=invalid-name + _Y_START = 0 # pylint: disable=invalid-name _INIT = () _ENCODE_PIXEL = ">H" _ENCODE_POS = ">HH" @@ -132,7 +138,7 @@ def __init__(self, width, height, rotation): self.width = width self.height = height if rotation not in (0, 90, 180, 270): - raise ValueError('Rotation must be 0/90/180/270') + raise ValueError("Rotation must be 0/90/180/270") self._rotation = rotation self.init() @@ -141,18 +147,22 @@ def init(self): for command, data in self._INIT: self.write(command, data) - #pylint: disable-msg=invalid-name,too-many-arguments + # pylint: disable-msg=invalid-name,too-many-arguments def _block(self, x0, y0, x1, y1, data=None): """Read or write a block of data.""" - self.write(self._COLUMN_SET, self._encode_pos(x0 + self._X_START, x1 + self._X_START)) - self.write(self._PAGE_SET, self._encode_pos(y0 + self._Y_START, y1 + self._Y_START)) + self.write( + self._COLUMN_SET, self._encode_pos(x0 + self._X_START, x1 + self._X_START) + ) + self.write( + self._PAGE_SET, self._encode_pos(y0 + self._Y_START, y1 + self._Y_START) + ) if data is None: size = struct.calcsize(self._DECODE_PIXEL) - return self.read(self._RAM_READ, - (x1 - x0 + 1) * (y1 - y0 + 1) * size) + return self.read(self._RAM_READ, (x1 - x0 + 1) * (y1 - y0 + 1) * size) self.write(self._RAM_WRITE, data) return None - #pylint: enable-msg=invalid-name,too-many-arguments + + # pylint: enable-msg=invalid-name,too-many-arguments def _encode_pos(self, x, y): """Encode a postion into bytes.""" @@ -181,16 +191,19 @@ def image(self, img, rotation=None, x=0, y=0): the supplied origin.""" if rotation is None: rotation = self.rotation - if not img.mode in ('RGB', 'RGBA'): - raise ValueError('Image must be in mode RGB or RGBA') + if not img.mode in ("RGB", "RGBA"): + raise ValueError("Image must be in mode RGB or RGBA") if rotation not in (0, 90, 180, 270): - raise ValueError('Rotation must be 0/90/180/270') + raise ValueError("Rotation must be 0/90/180/270") if rotation != 0: img = img.rotate(rotation, expand=True) imwidth, imheight = img.size if x + imwidth > self.width or y + imheight > self.height: - raise ValueError('Image must not exceed dimensions of display ({0}x{1}).' \ - .format(self.width, self.height)) + raise ValueError( + "Image must not exceed dimensions of display ({0}x{1}).".format( + self.width, self.height + ) + ) if numpy: pixels = list(image_to_data(img)) else: @@ -199,11 +212,11 @@ def image(self, img, rotation=None, x=0, y=0): for i in range(imwidth): for j in range(imheight): pix = color565(img.getpixel((i, j))) - pixels[2*(j * imwidth + i)] = pix >> 8 - pixels[2*(j * imwidth + i) + 1] = pix & 0xFF + pixels[2 * (j * imwidth + i)] = pix >> 8 + pixels[2 * (j * imwidth + i) + 1] = pix & 0xFF self._block(x, y, x + imwidth - 1, y + imheight - 1, pixels) - #pylint: disable-msg=too-many-arguments + # pylint: disable-msg=too-many-arguments def fill_rectangle(self, x, y, width, height, color): """Draw a rectangle at specified position with specified width and height, and fill it with the specified color.""" @@ -211,7 +224,7 @@ def fill_rectangle(self, x, y, width, height, color): y = min(self.height - 1, max(0, y)) width = min(self.width - x, max(1, width)) height = min(self.height - y, max(1, height)) - self._block(x, y, x + width - 1, y + height - 1, b'') + self._block(x, y, x + width - 1, y + height - 1, b"") chunks, rest = divmod(width * height, _BUFFER_SIZE) pixel = self._encode_pixel(color) if chunks: @@ -219,7 +232,8 @@ def fill_rectangle(self, x, y, width, height, color): for _ in range(chunks): self.write(None, data) self.write(None, pixel * rest) - #pylint: enable-msg=too-many-arguments + + # pylint: enable-msg=too-many-arguments def fill(self, color=0): """Fill the whole display with the specified color.""" @@ -241,27 +255,44 @@ def rotation(self): @rotation.setter def rotation(self, val): if val not in (0, 90, 180, 270): - raise ValueError('Rotation must be 0/90/180/270') + raise ValueError("Rotation must be 0/90/180/270") self._rotation = val + class DisplaySPI(Display): """Base class for SPI type devices""" - #pylint: disable-msg=too-many-arguments - def __init__(self, spi, dc, cs, rst=None, width=1, height=1, - baudrate=12000000, polarity=0, phase=0, *, - x_offset=0, y_offset=0, rotation=0): - self.spi_device = spi_device.SPIDevice(spi, cs, baudrate=baudrate, - polarity=polarity, phase=phase) + + # pylint: disable-msg=too-many-arguments + def __init__( + self, + spi, + dc, + cs, + rst=None, + width=1, + height=1, + baudrate=12000000, + polarity=0, + phase=0, + *, + x_offset=0, + y_offset=0, + rotation=0 + ): + self.spi_device = spi_device.SPIDevice( + spi, cs, baudrate=baudrate, polarity=polarity, phase=phase + ) self.dc_pin = dc self.rst = rst self.dc_pin.switch_to_output(value=0) if self.rst: self.rst.switch_to_output(value=0) self.reset() - self._X_START = x_offset # pylint: disable=invalid-name - self._Y_START = y_offset # pylint: disable=invalid-name + self._X_START = x_offset # pylint: disable=invalid-name + self._Y_START = y_offset # pylint: disable=invalid-name super().__init__(width, height, rotation) - #pylint: enable-msg=too-many-arguments + + # pylint: enable-msg=too-many-arguments def reset(self): """Reset the device""" diff --git a/adafruit_rgb_display/s6d02a1.py b/adafruit_rgb_display/s6d02a1.py index b23e04f..c61aa71 100644 --- a/adafruit_rgb_display/s6d02a1.py +++ b/adafruit_rgb_display/s6d02a1.py @@ -37,13 +37,14 @@ _SWRESET = const(0x01) _DISPON = const(0x29) _SLEEPOUT = const(0x11) -_CASET = const(0x2a) -_PASET = const(0x2b) -_RAMWR = const(0x2c) -_RAMRD = const(0x2e) -_COLMOD = const(0x3a) +_CASET = const(0x2A) +_PASET = const(0x2B) +_RAMWR = const(0x2C) +_RAMRD = const(0x2E) +_COLMOD = const(0x3A) _MADCTL = const(0x36) + class S6D02A1(DisplaySPI): """ A simple driver for the S6D02A1-based displays. @@ -59,6 +60,7 @@ class S6D02A1(DisplaySPI): >>> display.fill(0x7521) >>> display.pixel(64, 64, 0) """ + _COLUMN_SET = _CASET _PAGE_SET = _PASET _RAM_WRITE = _RAMWR @@ -66,13 +68,13 @@ class S6D02A1(DisplaySPI): _INIT = ( (_SWRESET, None), (_SLEEPOUT, None), - (_MADCTL, b'\x10'), # bottom-top - (_COLMOD, b'\x05'), # RGB565 pixel format + (_MADCTL, b"\x10"), # bottom-top + (_COLMOD, b"\x05"), # RGB565 pixel format (_DISPON, None), ) _ENCODE_PIXEL = ">H" _ENCODE_POS = ">HH" - #pylint: disable-msg=useless-super-delegation, too-many-arguments + # pylint: disable-msg=useless-super-delegation, too-many-arguments def __init__(self, spi, dc, cs, rst=None, width=128, height=160, rotation=0): super().__init__(spi, dc, cs, rst, width, height, rotation) diff --git a/adafruit_rgb_display/ssd1331.py b/adafruit_rgb_display/ssd1331.py index 8512672..cb29c25 100644 --- a/adafruit_rgb_display/ssd1331.py +++ b/adafruit_rgb_display/ssd1331.py @@ -64,7 +64,7 @@ _PRECHARGEC = const(0x8C) _PRECHARGELEVEL = const(0xBB) _VCOMH = const(0xBE) -_LOCK = const(0xfd) +_LOCK = const(0xFD) class SSD1331(DisplaySPI): @@ -87,46 +87,67 @@ class SSD1331(DisplaySPI): display.pixel(32, 32, 0) """ + _COLUMN_SET = _SETCOLUMN _PAGE_SET = _SETROW _RAM_WRITE = None _RAM_READ = None _INIT = ( - (_DISPLAYOFF, b''), - (_LOCK, b'\x0b'), - (_SETREMAP, b'\x72'), # RGB Color - (_STARTLINE, b'\x00'), - (_DISPLAYOFFSET, b'\x00'), - (_NORMALDISPLAY, b''), + (_DISPLAYOFF, b""), + (_LOCK, b"\x0b"), + (_SETREMAP, b"\x72"), # RGB Color + (_STARTLINE, b"\x00"), + (_DISPLAYOFFSET, b"\x00"), + (_NORMALDISPLAY, b""), # (_FILL, b'\x01'), - - (_PHASEPERIOD, b'\x31'), - (_SETMULTIPLEX, b'\x3f'), - (_SETMASTER, b'\x8e'), - (_POWERMODE, b'\x0b'), - (_PRECHARGE, b'\x31'), # ;//0x1F - 0x31 - (_CLOCKDIV, b'\xf0'), - (_VCOMH, b'\x3e'), # ;//0x3E - 0x3F - (_MASTERCURRENT, b'\x0c'), # ;//0x06 - 0x0F - (_PRECHARGEA, b'\x64'), - (_PRECHARGEB, b'\x78'), - (_PRECHARGEC, b'\x64'), - (_PRECHARGELEVEL, b'\x3a'), # 0x3A - 0x00 - (_CONTRASTA, b'\x91'), # //0xEF - 0x91 - (_CONTRASTB, b'\x50'), # ;//0x11 - 0x50 - (_CONTRASTC, b'\x7d'), # ;//0x48 - 0x7D - (_DISPLAYON, b''), + (_PHASEPERIOD, b"\x31"), + (_SETMULTIPLEX, b"\x3f"), + (_SETMASTER, b"\x8e"), + (_POWERMODE, b"\x0b"), + (_PRECHARGE, b"\x31"), # ;//0x1F - 0x31 + (_CLOCKDIV, b"\xf0"), + (_VCOMH, b"\x3e"), # ;//0x3E - 0x3F + (_MASTERCURRENT, b"\x0c"), # ;//0x06 - 0x0F + (_PRECHARGEA, b"\x64"), + (_PRECHARGEB, b"\x78"), + (_PRECHARGEC, b"\x64"), + (_PRECHARGELEVEL, b"\x3a"), # 0x3A - 0x00 + (_CONTRASTA, b"\x91"), # //0xEF - 0x91 + (_CONTRASTB, b"\x50"), # ;//0x11 - 0x50 + (_CONTRASTC, b"\x7d"), # ;//0x48 - 0x7D + (_DISPLAYON, b""), ) _ENCODE_PIXEL = ">H" _ENCODE_POS = ">BB" # pylint: disable-msg=useless-super-delegation, too-many-arguments # super required to allow override of default values - def __init__(self, spi, dc, cs, rst=None, width=96, height=64, - baudrate=16000000, polarity=0, phase=0, *, rotation=0): - super().__init__(spi, dc, cs, rst, width, height, - baudrate=baudrate, polarity=polarity, phase=phase, - rotation=rotation) + def __init__( + self, + spi, + dc, + cs, + rst=None, + width=96, + height=64, + baudrate=16000000, + polarity=0, + phase=0, + *, + rotation=0 + ): + super().__init__( + spi, + dc, + cs, + rst, + width, + height, + baudrate=baudrate, + polarity=polarity, + phase=phase, + rotation=rotation, + ) # pylint: disable=no-member def write(self, command=None, data=None): diff --git a/adafruit_rgb_display/ssd1351.py b/adafruit_rgb_display/ssd1351.py index 6aae3e8..059d73e 100644 --- a/adafruit_rgb_display/ssd1351.py +++ b/adafruit_rgb_display/ssd1351.py @@ -87,38 +87,62 @@ class SSD1351(DisplaySPI): _RAM_WRITE = _WRITERAM _RAM_READ = _READRAM _INIT = ( - (_COMMANDLOCK, b'\x12'), - (_COMMANDLOCK, b'\xb1'), - (_DISPLAYOFF, b''), - (_DISPLAYENHANCE, b'\xa4\x00\x00'), + (_COMMANDLOCK, b"\x12"), + (_COMMANDLOCK, b"\xb1"), + (_DISPLAYOFF, b""), + (_DISPLAYENHANCE, b"\xa4\x00\x00"), # 7:4 = Oscillator Frequency, # 3:0 = CLK Div Ratio (A[3:0]+1 = 1..16) - (_CLOCKDIV, b'\xf0'), - (_MUXRATIO, b'\x7f'), # 127 - (_SETREMAP, b'\x74'), - (_STARTLINE, b'\x00'), - (_DISPLAYOFFSET, b'\x00'), - (_SETGPIO, b'\x00'), - (_FUNCTIONSELECT, b'\x01'), - (_PRECHARGE, b'\x32'), - (_PRECHARGELEVEL, b'\x1f'), - (_VCOMH, b'\x05'), - (_NORMALDISPLAY, b''), - (_CONTRASTABC, b'\xc8\x80\xc8'), - (_CONTRASTMASTER, b'\x0a'), - (_SETVSL, b'\xa0\xb5\x55'), - (_PRECHARGE2, b'\x01'), - (_DISPLAYON, b''), + (_CLOCKDIV, b"\xf0"), + (_MUXRATIO, b"\x7f"), # 127 + (_SETREMAP, b"\x74"), + (_STARTLINE, b"\x00"), + (_DISPLAYOFFSET, b"\x00"), + (_SETGPIO, b"\x00"), + (_FUNCTIONSELECT, b"\x01"), + (_PRECHARGE, b"\x32"), + (_PRECHARGELEVEL, b"\x1f"), + (_VCOMH, b"\x05"), + (_NORMALDISPLAY, b""), + (_CONTRASTABC, b"\xc8\x80\xc8"), + (_CONTRASTMASTER, b"\x0a"), + (_SETVSL, b"\xa0\xb5\x55"), + (_PRECHARGE2, b"\x01"), + (_DISPLAYON, b""), ) _ENCODE_PIXEL = ">H" _ENCODE_POS = ">BB" - #pylint: disable-msg=useless-super-delegation, too-many-arguments - def __init__(self, spi, dc, cs, rst=None, width=128, height=128, - baudrate=16000000, polarity=0, phase=0, *, - x_offset=0, y_offset=0, rotation=0): - if baudrate > 16000000: # Limit to Display Max Baudrate + # pylint: disable-msg=useless-super-delegation, too-many-arguments + def __init__( + self, + spi, + dc, + cs, + rst=None, + width=128, + height=128, + baudrate=16000000, + polarity=0, + phase=0, + *, + x_offset=0, + y_offset=0, + rotation=0 + ): + if baudrate > 16000000: # Limit to Display Max Baudrate baudrate = 16000000 - super().__init__(spi, dc, cs, rst, width, height, - baudrate=baudrate, polarity=polarity, phase=phase, - x_offset=x_offset, y_offset=y_offset, rotation=rotation) + super().__init__( + spi, + dc, + cs, + rst, + width, + height, + baudrate=baudrate, + polarity=polarity, + phase=phase, + x_offset=x_offset, + y_offset=y_offset, + rotation=rotation, + ) diff --git a/adafruit_rgb_display/st7735.py b/adafruit_rgb_display/st7735.py index aae3a41..ca9bd17 100644 --- a/adafruit_rgb_display/st7735.py +++ b/adafruit_rgb_display/st7735.py @@ -100,6 +100,7 @@ class ST7735(DisplaySPI): >>> display.fill(0x7521) >>> display.pixel(64, 64, 0) """ + _COLUMN_SET = _CASET _PAGE_SET = _RASET _RAM_WRITE = _RAMWR @@ -107,135 +108,214 @@ class ST7735(DisplaySPI): _INIT = ( (_SWRESET, None), (_SLPOUT, None), - (_COLMOD, b'\x05'), # 16bit color + (_COLMOD, b"\x05"), # 16bit color # fastest refresh, 6 lines front porch, 3 line back porch - (_FRMCTR1, b'\x00\x06\x03'), - (_MADCTL, b'\x08'), # bottom to top refresh + (_FRMCTR1, b"\x00\x06\x03"), + (_MADCTL, b"\x08"), # bottom to top refresh # 1 clk cycle nonoverlap, 2 cycle gate rise, 3 sycle osc equalie, # fix on VTL - (_DISSET5, b'\x15\x02'), - (_INVCTR, b'0x00'), # line inversion - (_PWCTR1, b'\x02\x70'), # GVDD = 4.7V, 1.0uA - (_PWCTR2, b'\x05'), # VGH=14.7V, VGL=-7.35V - (_PWCTR3, b'\x01\x02'), # Opamp current small, Boost frequency - (_VMCTR1, b'\x3c\x38'), # VCOMH = 4V, VOML = -1.1V - (_PWCTR6, b'\x11\x15'), - (_GMCTRP1, b'\x09\x16\x09\x20\x21\x1b\x13\x19' - b'\x17\x15\x1e\x2b\x04\x05\x02\x0e'), # Gamma - (_GMCTRN1, b'\x08\x14\x08\x1e\x22\x1d\x18\x1e' - b'\x18\x1a\x24\x2b\x06\x06\x02\x0f'), - (_CASET, b'\x00\x02\x00\x81'), # XSTART = 2, XEND = 129 - (_RASET, b'\x00\x02\x00\x81'), # XSTART = 2, XEND = 129 + (_DISSET5, b"\x15\x02"), + (_INVCTR, b"0x00"), # line inversion + (_PWCTR1, b"\x02\x70"), # GVDD = 4.7V, 1.0uA + (_PWCTR2, b"\x05"), # VGH=14.7V, VGL=-7.35V + (_PWCTR3, b"\x01\x02"), # Opamp current small, Boost frequency + (_VMCTR1, b"\x3c\x38"), # VCOMH = 4V, VOML = -1.1V + (_PWCTR6, b"\x11\x15"), + ( + _GMCTRP1, + b"\x09\x16\x09\x20\x21\x1b\x13\x19" b"\x17\x15\x1e\x2b\x04\x05\x02\x0e", + ), # Gamma + ( + _GMCTRN1, + b"\x08\x14\x08\x1e\x22\x1d\x18\x1e" b"\x18\x1a\x24\x2b\x06\x06\x02\x0f", + ), + (_CASET, b"\x00\x02\x00\x81"), # XSTART = 2, XEND = 129 + (_RASET, b"\x00\x02\x00\x81"), # XSTART = 2, XEND = 129 (_NORON, None), (_DISPON, None), ) _ENCODE_PIXEL = ">H" _ENCODE_POS = ">HH" - #pylint: disable-msg=useless-super-delegation, too-many-arguments - def __init__(self, spi, dc, cs, rst=None, width=128, height=128, - baudrate=16000000, polarity=0, phase=0, *, - x_offset=0, y_offset=0, rotation=0): - super().__init__(spi, dc, cs, rst, width, height, - baudrate=baudrate, polarity=polarity, phase=phase, - x_offset=x_offset, y_offset=y_offset, rotation=rotation) + # pylint: disable-msg=useless-super-delegation, too-many-arguments + def __init__( + self, + spi, + dc, + cs, + rst=None, + width=128, + height=128, + baudrate=16000000, + polarity=0, + phase=0, + *, + x_offset=0, + y_offset=0, + rotation=0 + ): + super().__init__( + spi, + dc, + cs, + rst, + width, + height, + baudrate=baudrate, + polarity=polarity, + phase=phase, + x_offset=x_offset, + y_offset=y_offset, + rotation=rotation, + ) class ST7735R(ST7735): """A simple driver for the ST7735R-based displays.""" + _INIT = ( (_SWRESET, None), (_SLPOUT, None), - - (_MADCTL, b'\xc8'), - (_COLMOD, b'\x05'), # 16bit color - (_INVCTR, b'\x07'), - - (_FRMCTR1, b'\x01\x2c\x2d'), - (_FRMCTR2, b'\x01\x2c\x2d'), - (_FRMCTR3, b'\x01\x2c\x2d\x01\x2c\x2d'), - - (_PWCTR1, b'\x02\x02\x84'), - (_PWCTR2, b'\xc5'), - (_PWCTR3, b'\x0a\x00'), - (_PWCTR4, b'\x8a\x2a'), - (_PWCTR5, b'\x8a\xee'), - - (_VMCTR1, b'\x0e'), + (_MADCTL, b"\xc8"), + (_COLMOD, b"\x05"), # 16bit color + (_INVCTR, b"\x07"), + (_FRMCTR1, b"\x01\x2c\x2d"), + (_FRMCTR2, b"\x01\x2c\x2d"), + (_FRMCTR3, b"\x01\x2c\x2d\x01\x2c\x2d"), + (_PWCTR1, b"\x02\x02\x84"), + (_PWCTR2, b"\xc5"), + (_PWCTR3, b"\x0a\x00"), + (_PWCTR4, b"\x8a\x2a"), + (_PWCTR5, b"\x8a\xee"), + (_VMCTR1, b"\x0e"), (_INVOFF, None), - - (_GMCTRP1, b'\x02\x1c\x07\x12\x37\x32\x29\x2d' - b'\x29\x25\x2B\x39\x00\x01\x03\x10'), # Gamma - (_GMCTRN1, b'\x03\x1d\x07\x06\x2E\x2C\x29\x2D' - b'\x2E\x2E\x37\x3F\x00\x00\x02\x10'), + ( + _GMCTRP1, + b"\x02\x1c\x07\x12\x37\x32\x29\x2d" b"\x29\x25\x2B\x39\x00\x01\x03\x10", + ), # Gamma + ( + _GMCTRN1, + b"\x03\x1d\x07\x06\x2E\x2C\x29\x2D" b"\x2E\x2E\x37\x3F\x00\x00\x02\x10", + ), ) - #pylint: disable-msg=useless-super-delegation, too-many-arguments - def __init__(self, spi, dc, cs, rst=None, width=128, height=160, - baudrate=16000000, polarity=0, phase=0, *, - x_offset=0, y_offset=0, rotation=0, bgr=False): + # pylint: disable-msg=useless-super-delegation, too-many-arguments + def __init__( + self, + spi, + dc, + cs, + rst=None, + width=128, + height=160, + baudrate=16000000, + polarity=0, + phase=0, + *, + x_offset=0, + y_offset=0, + rotation=0, + bgr=False + ): self._bgr = bgr - super().__init__(spi, dc, cs, rst, width, height, - baudrate=baudrate, polarity=polarity, phase=phase, - x_offset=x_offset, y_offset=y_offset, rotation=rotation) + super().__init__( + spi, + dc, + cs, + rst, + width, + height, + baudrate=baudrate, + polarity=polarity, + phase=phase, + x_offset=x_offset, + y_offset=y_offset, + rotation=rotation, + ) def init(self): super().init() - cols = struct.pack('>HH', 0, self.width - 1) - rows = struct.pack('>HH', 0, self.height - 1) + cols = struct.pack(">HH", 0, self.width - 1) + rows = struct.pack(">HH", 0, self.height - 1) for command, data in ( - (_CASET, cols), - (_RASET, rows), - (_NORON, None), - (_DISPON, None), + (_CASET, cols), + (_RASET, rows), + (_NORON, None), + (_DISPON, None), ): self.write(command, data) if self._bgr: - self.write(_MADCTL, b'\xc0') + self.write(_MADCTL, b"\xc0") + class ST7735S(ST7735): """A simple driver for the ST7735S-based displays.""" + _INIT = ( # Frame Rate - (_FRMCTR1, b'\x01\x2c\x2d'), - (_FRMCTR2, b'\x01\x2c\x2d'), - (_FRMCTR3, b'\x01\x2c\x2d\x01\x2c\x2d'), - + (_FRMCTR1, b"\x01\x2c\x2d"), + (_FRMCTR2, b"\x01\x2c\x2d"), + (_FRMCTR3, b"\x01\x2c\x2d\x01\x2c\x2d"), # Column inversion - (_INVCTR, b'\x07'), - + (_INVCTR, b"\x07"), # Power Sequence - (_PWCTR1, b'\xa2\x02\x84'), - (_PWCTR2, b'\xc5'), - (_PWCTR3, b'\x0a\x00'), - (_PWCTR4, b'\x8a\x2a'), - (_PWCTR5, b'\x8a\xee'), - + (_PWCTR1, b"\xa2\x02\x84"), + (_PWCTR2, b"\xc5"), + (_PWCTR3, b"\x0a\x00"), + (_PWCTR4, b"\x8a\x2a"), + (_PWCTR5, b"\x8a\xee"), # VCOM - (_VMCTR1, b'\x0e'), - + (_VMCTR1, b"\x0e"), # Gamma - (_GMCTRP1, b'\x0f\x1a\x0f\x18\x2f\x28\x20\x22' - b'\x1f\x1b\x23\x37\x00\x07\x02\x10'), - - (_GMCTRN1, b'\x0f\x1b\x0f\x17\x33\x2c\x29\x2e' - b'\x30\x30\x39\x3f\x00\x07\x03\x10'), + ( + _GMCTRP1, + b"\x0f\x1a\x0f\x18\x2f\x28\x20\x22" b"\x1f\x1b\x23\x37\x00\x07\x02\x10", + ), + ( + _GMCTRN1, + b"\x0f\x1b\x0f\x17\x33\x2c\x29\x2e" b"\x30\x30\x39\x3f\x00\x07\x03\x10", + ), # 65k mode - (_COLMOD, b'\x05'), + (_COLMOD, b"\x05"), # set scan direction: up to down, right to left - (_MADCTL, b'\x60'), + (_MADCTL, b"\x60"), (_SLPOUT, None), (_DISPON, None), ) - #pylint: disable-msg=useless-super-delegation, too-many-arguments - def __init__(self, spi, dc, cs, bl, rst=None, width=128, height=160, - baudrate=16000000, polarity=0, phase=0, *, - x_offset=2, y_offset=1, rotation=0): + # pylint: disable-msg=useless-super-delegation, too-many-arguments + def __init__( + self, + spi, + dc, + cs, + bl, + rst=None, + width=128, + height=160, + baudrate=16000000, + polarity=0, + phase=0, + *, + x_offset=2, + y_offset=1, + rotation=0 + ): self._bl = bl # Turn on backlight self._bl.switch_to_output(value=1) - super().__init__(spi, dc, cs, rst, width, height, - baudrate=baudrate, polarity=polarity, phase=phase, - x_offset=x_offset, y_offset=y_offset, rotation=rotation) + super().__init__( + spi, + dc, + cs, + rst, + width, + height, + baudrate=baudrate, + polarity=polarity, + phase=phase, + x_offset=x_offset, + y_offset=y_offset, + rotation=rotation, + ) diff --git a/adafruit_rgb_display/st7789.py b/adafruit_rgb_display/st7789.py index 463f0be..22025c7 100644 --- a/adafruit_rgb_display/st7789.py +++ b/adafruit_rgb_display/st7789.py @@ -100,6 +100,7 @@ class ST7789(DisplaySPI): >>> display.fill(0x7521) >>> display.pixel(64, 64, 0) """ + _COLUMN_SET = _CASET _PAGE_SET = _RASET _RAM_WRITE = _RAMWR @@ -107,28 +108,53 @@ class ST7789(DisplaySPI): _INIT = ( (_SWRESET, None), (_SLPOUT, None), - (_COLMOD, b'\x55'), # 16bit color - (_MADCTL, b'\x08'), + (_COLMOD, b"\x55"), # 16bit color + (_MADCTL, b"\x08"), ) - #pylint: disable-msg=useless-super-delegation, too-many-arguments - def __init__(self, spi, dc, cs, rst=None, width=240, height=320, - baudrate=16000000, polarity=0, phase=0, *, - x_offset=0, y_offset=0, rotation=0): - super().__init__(spi, dc, cs, rst, width, height, - baudrate=baudrate, polarity=polarity, phase=phase, - x_offset=x_offset, y_offset=y_offset, rotation=rotation) + # pylint: disable-msg=useless-super-delegation, too-many-arguments + def __init__( + self, + spi, + dc, + cs, + rst=None, + width=240, + height=320, + baudrate=16000000, + polarity=0, + phase=0, + *, + x_offset=0, + y_offset=0, + rotation=0 + ): + super().__init__( + spi, + dc, + cs, + rst, + width, + height, + baudrate=baudrate, + polarity=polarity, + phase=phase, + x_offset=x_offset, + y_offset=y_offset, + rotation=rotation, + ) + def init(self): super().init() - cols = struct.pack('>HH', self._X_START, self.width + self._X_START) - rows = struct.pack('>HH', self._Y_START, self.height + self._Y_START) + cols = struct.pack(">HH", self._X_START, self.width + self._X_START) + rows = struct.pack(">HH", self._Y_START, self.height + self._Y_START) for command, data in ( - (_CASET, cols), - (_RASET, rows), - (_INVON, None), - (_NORON, None), - (_DISPON, None), - (_MADCTL, b'\xc0'), #Set rotation to 0 and use RGB + (_CASET, cols), + (_RASET, rows), + (_INVON, None), + (_NORON, None), + (_DISPON, None), + (_MADCTL, b"\xc0"), # Set rotation to 0 and use RGB ): self.write(command, data) diff --git a/docs/conf.py b/docs/conf.py index 90e9b64..438cd91 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -2,7 +2,8 @@ import os import sys -sys.path.insert(0, os.path.abspath('..')) + +sys.path.insert(0, os.path.abspath("..")) # -- General configuration ------------------------------------------------ @@ -10,9 +11,9 @@ # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. extensions = [ - 'sphinx.ext.autodoc', - 'sphinx.ext.intersphinx', - 'sphinx.ext.viewcode', + "sphinx.ext.autodoc", + "sphinx.ext.intersphinx", + "sphinx.ext.viewcode", ] # Uncomment the below if you use native CircuitPython modules such as @@ -20,29 +21,36 @@ # autodoc module docs will fail to generate with a warning. # autodoc_mock_imports = ["adafruit_bus_device", "micropython"] -intersphinx_mapping = {'python': ('https://docs.python.org/3.4', None),'BusDevice': ('https://circuitpython.readthedocs.io/projects/busdevice/en/latest/', None),'CircuitPython': ('https://circuitpython.readthedocs.io/en/latest/', None)} +intersphinx_mapping = { + "python": ("https://docs.python.org/3.4", None), + "BusDevice": ( + "https://circuitpython.readthedocs.io/projects/busdevice/en/latest/", + None, + ), + "CircuitPython": ("https://circuitpython.readthedocs.io/en/latest/", None), +} # Add any paths that contain templates here, relative to this directory. -templates_path = ['_templates'] +templates_path = ["_templates"] -source_suffix = '.rst' +source_suffix = ".rst" # The master toctree document. -master_doc = 'index' +master_doc = "index" # General information about the project. -project = u'Adafruit RGB_Display Library' -copyright = u'2017 Michale McWethy' -author = u'Michale McWethy' +project = u"Adafruit RGB_Display Library" +copyright = u"2017 Michale McWethy" +author = u"Michale McWethy" # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents. # # The short X.Y version. -version = u'1.0' +version = u"1.0" # The full version, including alpha/beta/rc tags. -release = u'1.0' +release = u"1.0" # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. @@ -54,7 +62,7 @@ # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. # This patterns also effect to html_static_path and html_extra_path -exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', '.env', 'CODE_OF_CONDUCT.md'] +exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", ".env", "CODE_OF_CONDUCT.md"] # The reST default role (used for this markup: `text`) to use for all # documents. @@ -66,7 +74,7 @@ add_function_parentheses = True # The name of the Pygments (syntax highlighting) style to use. -pygments_style = 'sphinx' +pygments_style = "sphinx" # If true, `todo` and `todoList` produce output, else they produce nothing. todo_include_todos = False @@ -80,59 +88,62 @@ # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. # -on_rtd = os.environ.get('READTHEDOCS', None) == 'True' +on_rtd = os.environ.get("READTHEDOCS", None) == "True" if not on_rtd: # only import and set the theme if we're building docs locally try: import sphinx_rtd_theme - html_theme = 'sphinx_rtd_theme' - html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), '.'] + + html_theme = "sphinx_rtd_theme" + html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), "."] except: - html_theme = 'default' - html_theme_path = ['.'] + html_theme = "default" + html_theme_path = ["."] else: - html_theme_path = ['.'] + html_theme_path = ["."] # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". -html_static_path = ['_static'] +html_static_path = ["_static"] # The name of an image file (relative to this directory) to use as a favicon of # the docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 # pixels large. # -html_favicon = '_static/favicon.ico' +html_favicon = "_static/favicon.ico" # Output file base name for HTML help builder. -htmlhelp_basename = 'AdafruitRgb_displayLibrarydoc' +htmlhelp_basename = "AdafruitRgb_displayLibrarydoc" # -- Options for LaTeX output --------------------------------------------- latex_elements = { - # The paper size ('letterpaper' or 'a4paper'). - # - # 'papersize': 'letterpaper', - - # The font size ('10pt', '11pt' or '12pt'). - # - # 'pointsize': '10pt', - - # Additional stuff for the LaTeX preamble. - # - # 'preamble': '', - - # Latex figure (float) alignment - # - # 'figure_align': 'htbp', + # The paper size ('letterpaper' or 'a4paper'). + # + # 'papersize': 'letterpaper', + # The font size ('10pt', '11pt' or '12pt'). + # + # 'pointsize': '10pt', + # Additional stuff for the LaTeX preamble. + # + # 'preamble': '', + # Latex figure (float) alignment + # + # 'figure_align': 'htbp', } # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, # author, documentclass [howto, manual, or own class]). latex_documents = [ - (master_doc, 'AdafruitRGB_DisplayLibrary.tex', u'AdafruitRGB_Display Library Documentation', - author, 'manual'), + ( + master_doc, + "AdafruitRGB_DisplayLibrary.tex", + u"AdafruitRGB_Display Library Documentation", + author, + "manual", + ), ] # -- Options for manual page output --------------------------------------- @@ -140,8 +151,13 @@ # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ - (master_doc, 'AdafruitRGB_Displaylibrary', u'Adafruit RGB_Display Library Documentation', - [author], 1) + ( + master_doc, + "AdafruitRGB_Displaylibrary", + u"Adafruit RGB_Display Library Documentation", + [author], + 1, + ) ] # -- Options for Texinfo output ------------------------------------------- @@ -150,7 +166,13 @@ # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ - (master_doc, 'AdafruitRGB_DisplayLibrary', u'Adafruit RGB_Display Library Documentation', - author, 'AdafruitRGB_DisplayLibrary', 'One line description of project.', - 'Miscellaneous'), + ( + master_doc, + "AdafruitRGB_DisplayLibrary", + u"Adafruit RGB_Display Library Documentation", + author, + "AdafruitRGB_DisplayLibrary", + "One line description of project.", + "Miscellaneous", + ), ] diff --git a/examples/rgb_display_fbcp.py b/examples/rgb_display_fbcp.py index 025b883..db5cf22 100644 --- a/examples/rgb_display_fbcp.py +++ b/examples/rgb_display_fbcp.py @@ -32,33 +32,33 @@ FB_BLANK_POWERDOWN = 4 - -class Bitfield: # pylint: disable=too-few-public-methods +class Bitfield: # pylint: disable=too-few-public-methods def __init__(self, offset, length, msb_right): self.offset = offset self.length = length self.msb_right = msb_right + # Kind of like a pygame Surface object, or not! # http://www.pygame.org/docs/ref/surface.html -class Framebuffer: # pylint: disable=too-many-instance-attributes - +class Framebuffer: # pylint: disable=too-many-instance-attributes def __init__(self, dev): self.dev = dev self.fbfd = os.open(dev, os.O_RDWR) - vinfo = struct.unpack("8I12I16I4I", - fcntl.ioctl(self.fbfd, - FBIOGET_VSCREENINFO, - " "*((8+12+16+4)*4))) - finfo = struct.unpack("16cL4I3HI", - fcntl.ioctl(self.fbfd, - FBIOGET_FSCREENINFO, " "*48)) + vinfo = struct.unpack( + "8I12I16I4I", + fcntl.ioctl(self.fbfd, FBIOGET_VSCREENINFO, " " * ((8 + 12 + 16 + 4) * 4)), + ) + finfo = struct.unpack( + "16cL4I3HI", fcntl.ioctl(self.fbfd, FBIOGET_FSCREENINFO, " " * 48) + ) bytes_per_pixel = (vinfo[6] + 7) // 8 screensize = vinfo[0] * vinfo[1] * bytes_per_pixel - fbp = mmap.mmap(self.fbfd, screensize, - flags=mmap.MAP_SHARED, prot=mmap.PROT_READ) + fbp = mmap.mmap( + self.fbfd, screensize, flags=mmap.MAP_SHARED, prot=mmap.PROT_READ + ) self.fbp = fbp self.xres = vinfo[0] @@ -73,7 +73,7 @@ def __init__(self, dev): self.blue = Bitfield(vinfo[14], vinfo[15], vinfo[16]) self.transp = Bitfield(vinfo[17], vinfo[18], vinfo[19]) self.nonstd = vinfo[20] - self.name = b''.join([x for x in finfo[0:15] if x != b'\x00']) + self.name = b"".join([x for x in finfo[0:15] if x != b"\x00"]) self.type = finfo[18] self.visual = finfo[20] self.line_length = finfo[24] @@ -94,42 +94,59 @@ def blank(self, blank): pass def __str__(self): - visual_list = ['MONO01', 'MONO10', 'TRUECOLOR', - 'PSEUDOCOLOR', 'DIRECTCOLOR', - 'STATIC PSEUDOCOLOR', 'FOURCC'] - type_list = ['PACKED_PIXELS', 'PLANES', 'INTERLEAVED_PLANES', - 'TEXT', 'VGA_PLANES', 'FOURCC'] - visual_name = 'unknown' + visual_list = [ + "MONO01", + "MONO10", + "TRUECOLOR", + "PSEUDOCOLOR", + "DIRECTCOLOR", + "STATIC PSEUDOCOLOR", + "FOURCC", + ] + type_list = [ + "PACKED_PIXELS", + "PLANES", + "INTERLEAVED_PLANES", + "TEXT", + "VGA_PLANES", + "FOURCC", + ] + visual_name = "unknown" if self.visual < len(visual_list): visual_name = visual_list[self.visual] - type_name = 'unknown' + type_name = "unknown" if self.type < len(type_list): type_name = type_list[self.type] - return \ - "mode \"%sx%s\"\n" % (self.xres, self.yres) + \ - " nonstd %s\n" % self.nonstd + \ - " rgba %s/%s,%s/%s,%s/%s,%s/%s\n" % (self.red.length, - self.red.offset, - self.green.length, - self.green.offset, - self.blue.length, - self.blue.offset, - self.transp.length, - self.transp.offset) + \ - "endmode\n" + \ - "\n" + \ - "Frame buffer device information:\n" + \ - " Device : %s\n" % self.dev + \ - " Name : %s\n" % self.name + \ - " Size : (%d, %d)\n" % (self.xres, self.yres) + \ - " Length : %s\n" % self.screensize + \ - " BPP : %d\n" % self.bits_per_pixel + \ - " Type : %s\n" % type_name + \ - " Visual : %s\n" % visual_name + \ - " LineLength : %s\n" % self.line_length - -device = '/dev/fb0' + return ( + 'mode "%sx%s"\n' % (self.xres, self.yres) + + " nonstd %s\n" % self.nonstd + + " rgba %s/%s,%s/%s,%s/%s,%s/%s\n" + % ( + self.red.length, + self.red.offset, + self.green.length, + self.green.offset, + self.blue.length, + self.blue.offset, + self.transp.length, + self.transp.offset, + ) + + "endmode\n" + + "\n" + + "Frame buffer device information:\n" + + " Device : %s\n" % self.dev + + " Name : %s\n" % self.name + + " Size : (%d, %d)\n" % (self.xres, self.yres) + + " Length : %s\n" % self.screensize + + " BPP : %d\n" % self.bits_per_pixel + + " Type : %s\n" % type_name + + " Visual : %s\n" % visual_name + + " LineLength : %s\n" % self.line_length + ) + + +device = "/dev/fb0" fb = Framebuffer(device) print(fb) @@ -145,13 +162,21 @@ def __str__(self): spi = board.SPI() # Create the ST7789 display: -disp = st7789.ST7789(spi, cs=cs_pin, dc=dc_pin, rst=reset_pin, - baudrate=BAUDRATE, - width=135, height=240, x_offset=53, y_offset=40) - -height = disp.width # we swap height/width to rotate it to landscape! +disp = st7789.ST7789( + spi, + cs=cs_pin, + dc=dc_pin, + rst=reset_pin, + baudrate=BAUDRATE, + width=135, + height=240, + x_offset=53, + y_offset=40, +) + +height = disp.width # we swap height/width to rotate it to landscape! width = disp.height -image = Image.new('RGB', (width, height)) +image = Image.new("RGB", (width, height)) rotation = 90 # Get drawing object to draw on image. @@ -165,11 +190,11 @@ def __str__(self): t = time.monotonic() fb.fbp.seek(0) b = fb.fbp.read(fb.screensize) - fbimage = Image.frombytes('RGBA', (fb.xres, fb.yres), b, 'raw') + fbimage = Image.frombytes("RGBA", (fb.xres, fb.yres), b, "raw") b, g, r, a = fbimage.split() fbimage = Image.merge("RGB", (r, g, b)) fbimage = fbimage.resize((width, height)) disp.image(fbimage, rotation) - print(1.0 / (time.monotonic()-t)) + print(1.0 / (time.monotonic() - t)) fb.close() diff --git a/examples/rgb_display_hx8357test.py b/examples/rgb_display_hx8357test.py index 64629a7..db56e2e 100644 --- a/examples/rgb_display_hx8357test.py +++ b/examples/rgb_display_hx8357test.py @@ -34,12 +34,12 @@ # Clear the display display.fill(0) # Draw a red pixel in the center. - display.pixel(display.width//2, display.height//2, color565(255, 0, 0)) + display.pixel(display.width // 2, display.height // 2, color565(255, 0, 0)) # Pause 2 seconds. time.sleep(2) # Clear the screen a random color - display.fill(color565(random.randint(0, 255), - random.randint(0, 255), - random.randint(0, 255))) + display.fill( + color565(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)) + ) # Pause 2 seconds. time.sleep(2) diff --git a/examples/rgb_display_ili9341test.py b/examples/rgb_display_ili9341test.py index 99ede04..06901c0 100644 --- a/examples/rgb_display_ili9341test.py +++ b/examples/rgb_display_ili9341test.py @@ -32,12 +32,12 @@ # Clear the display display.fill(0) # Draw a red pixel in the center. - display.pixel(display.width//2, display.height//2, color565(255, 0, 0)) + display.pixel(display.width // 2, display.height // 2, color565(255, 0, 0)) # Pause 2 seconds. time.sleep(2) # Clear the screen a random color - display.fill(color565(random.randint(0, 255), - random.randint(0, 255), - random.randint(0, 255))) + display.fill( + color565(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)) + ) # Pause 2 seconds. time.sleep(2) diff --git a/examples/rgb_display_minipitftstats.py b/examples/rgb_display_minipitftstats.py index ae6556c..0cdffad 100644 --- a/examples/rgb_display_minipitftstats.py +++ b/examples/rgb_display_minipitftstats.py @@ -20,14 +20,23 @@ spi = board.SPI() # Create the ST7789 display: -disp = st7789.ST7789(spi, cs=cs_pin, dc=dc_pin, rst=reset_pin, baudrate=BAUDRATE, - width=135, height=240, x_offset=53, y_offset=40) +disp = st7789.ST7789( + spi, + cs=cs_pin, + dc=dc_pin, + rst=reset_pin, + baudrate=BAUDRATE, + width=135, + height=240, + x_offset=53, + y_offset=40, +) # Create blank image for drawing. # Make sure to create image with mode 'RGB' for full color. -height = disp.width # we swap height/width to rotate it to landscape! +height = disp.width # we swap height/width to rotate it to landscape! width = disp.height -image = Image.new('RGB', (width, height)) +image = Image.new("RGB", (width, height)) rotation = 90 # Get drawing object to draw on image. @@ -40,7 +49,7 @@ # First define some constants to allow easy resizing of shapes. padding = -2 top = padding -bottom = height-padding +bottom = height - padding # Move left to right keeping track of the current x position for drawing shapes. x = 0 @@ -48,7 +57,7 @@ # Alternatively load a TTF font. Make sure the .ttf font file is in the # same directory as the python script! # Some other nice fonts to try: http://www.dafont.com/bitmap.php -font = ImageFont.truetype('/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf', 24) +font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", 24) # Turn on the backlight backlight = digitalio.DigitalInOut(board.D22) @@ -61,15 +70,15 @@ # Shell scripts for system monitoring from here: # https://unix.stackexchange.com/questions/119126/command-to-display-memory-usage-disk-usage-and-cpu-load - cmd = "hostname -I | cut -d\' \' -f1" - IP = "IP: "+subprocess.check_output(cmd, shell=True).decode("utf-8") + cmd = "hostname -I | cut -d' ' -f1" + IP = "IP: " + subprocess.check_output(cmd, shell=True).decode("utf-8") cmd = "top -bn1 | grep load | awk '{printf \"CPU Load: %.2f\", $(NF-2)}'" CPU = subprocess.check_output(cmd, shell=True).decode("utf-8") cmd = "free -m | awk 'NR==2{printf \"Mem: %s/%s MB %.2f%%\", $3,$2,$3*100/$2 }'" MemUsage = subprocess.check_output(cmd, shell=True).decode("utf-8") - cmd = "df -h | awk '$NF==\"/\"{printf \"Disk: %d/%d GB %s\", $3,$2,$5}'" + cmd = 'df -h | awk \'$NF=="/"{printf "Disk: %d/%d GB %s", $3,$2,$5}\'' Disk = subprocess.check_output(cmd, shell=True).decode("utf-8") - cmd = "cat /sys/class/thermal/thermal_zone0/temp | awk \'{printf \"CPU Temp: %.1f C\", $(NF-0) / 1000}\'" # pylint: disable=line-too-long + cmd = "cat /sys/class/thermal/thermal_zone0/temp | awk '{printf \"CPU Temp: %.1f C\", $(NF-0) / 1000}'" # pylint: disable=line-too-long Temp = subprocess.check_output(cmd, shell=True).decode("utf-8") # Write four lines of text. @@ -86,4 +95,4 @@ # Display image. disp.image(image, rotation) - time.sleep(.1) + time.sleep(0.1) diff --git a/examples/rgb_display_minipitfttest.py b/examples/rgb_display_minipitfttest.py index ba20eab..8eab71d 100644 --- a/examples/rgb_display_minipitfttest.py +++ b/examples/rgb_display_minipitfttest.py @@ -8,10 +8,19 @@ cs_pin = digitalio.DigitalInOut(board.CE0) dc_pin = digitalio.DigitalInOut(board.D25) reset_pin = None -BAUDRATE = 64000000 # The pi can be very fast! +BAUDRATE = 64000000 # The pi can be very fast! # Create the ST7789 display: -display = st7789.ST7789(board.SPI(), cs=cs_pin, dc=dc_pin, rst=reset_pin, baudrate=BAUDRATE, - width=135, height=240, x_offset=53, y_offset=40) +display = st7789.ST7789( + board.SPI(), + cs=cs_pin, + dc=dc_pin, + rst=reset_pin, + baudrate=BAUDRATE, + width=135, + height=240, + x_offset=53, + y_offset=40, +) backlight = digitalio.DigitalInOut(board.D22) backlight.switch_to_output() @@ -24,12 +33,12 @@ # Main loop: while True: if buttonA.value and buttonB.value: - backlight.value = False # turn off backlight + backlight.value = False # turn off backlight else: - backlight.value = True # turn on backlight + backlight.value = True # turn on backlight if buttonB.value and not buttonA.value: # just button A pressed - display.fill(color565(255, 0, 0)) # red + display.fill(color565(255, 0, 0)) # red if buttonA.value and not buttonB.value: # just button B pressed - display.fill(color565(0, 0, 255)) # blue - if not buttonA.value and not buttonB.value: # none pressed - display.fill(color565(0, 255, 0)) # green + display.fill(color565(0, 0, 255)) # blue + if not buttonA.value and not buttonB.value: # none pressed + display.fill(color565(0, 255, 0)) # green diff --git a/examples/rgb_display_pillow_animated_gif.py b/examples/rgb_display_pillow_animated_gif.py index 0766603..c6d13a0 100644 --- a/examples/rgb_display_pillow_animated_gif.py +++ b/examples/rgb_display_pillow_animated_gif.py @@ -17,11 +17,11 @@ import board from PIL import Image, ImageOps import adafruit_rgb_display.ili9341 as ili9341 -import adafruit_rgb_display.st7789 as st7789 # pylint: disable=unused-import -import adafruit_rgb_display.hx8357 as hx8357 # pylint: disable=unused-import -import adafruit_rgb_display.st7735 as st7735 # pylint: disable=unused-import -import adafruit_rgb_display.ssd1351 as ssd1351 # pylint: disable=unused-import -import adafruit_rgb_display.ssd1331 as ssd1331 # pylint: disable=unused-import +import adafruit_rgb_display.st7789 as st7789 # pylint: disable=unused-import +import adafruit_rgb_display.hx8357 as hx8357 # pylint: disable=unused-import +import adafruit_rgb_display.st7735 as st7735 # pylint: disable=unused-import +import adafruit_rgb_display.ssd1351 as ssd1351 # pylint: disable=unused-import +import adafruit_rgb_display.ssd1331 as ssd1331 # pylint: disable=unused-import # Change to match your display BUTTON_NEXT = board.D17 @@ -34,19 +34,24 @@ # Set this to None on the Mini PiTFT reset_pin = digitalio.DigitalInOut(board.D24) + def init_button(pin): button = digitalio.DigitalInOut(pin) button.switch_to_input() button.pull = digitalio.Pull.UP return button + # pylint: disable=too-few-public-methods class Frame: def __init__(self, duration=0): self.duration = duration self.image = None + + # pylint: enable=too-few-public-methods + class AnimatedGif: def __init__(self, display, width=None, height=None, folder=None): self._frame_count = 0 @@ -75,10 +80,10 @@ def advance(self): self._index = (self._index + 1) % len(self._gif_files) def back(self): - self._index = (self._index - 1 + len(self._gif_files)) % len(self._gif_files) + self._index = (self._index - 1 + len(self._gif_files)) % len(self._gif_files) def load_files(self, folder): - gif_files = [f for f in os.listdir(folder) if f.endswith('.gif')] + gif_files = [f for f in os.listdir(folder) if f.endswith(".gif")] for gif_file in gif_files: image = Image.open(gif_file) # Only add animated Gifs @@ -88,17 +93,17 @@ def load_files(self, folder): print("Found", self._gif_files) if not self._gif_files: print("No Gif files found in current folder") - exit() + exit() # pylint: disable=consider-using-sys-exit def preload(self): image = Image.open(self._gif_files[self._index]) print("Loading {}...".format(self._gif_files[self._index])) if "duration" in image.info: - self._duration = image.info['duration'] + self._duration = image.info["duration"] else: self._duration = 0 if "loop" in image.info: - self._loop = image.info['loop'] + self._loop = image.info["loop"] else: self._loop = 1 self._frame_count = image.n_frames @@ -109,12 +114,14 @@ def preload(self): # Make sure to create image with mode 'RGB' for full color. frame_object = Frame(duration=self._duration) if "duration" in image.info: - frame_object.duration = image.info['duration'] - frame_object.image = ImageOps.pad(image.convert("RGB"), - (self._width, self._height), - method=Image.NEAREST, - color=(0, 0, 0), - centering=(0.5, 0.5)) + frame_object.duration = image.info["duration"] + frame_object.image = ImageOps.pad( # pylint: disable=no-member + image.convert("RGB"), + (self._width, self._height), + method=Image.NEAREST, + color=(0, 0, 0), + centering=(0.5, 0.5), + ) self._frames.append(frame_object) def play(self): @@ -148,6 +155,7 @@ def run(self): if auto_advance: self.advance() + # Config for display baudrate (default max is 64mhz): BAUDRATE = 64000000 @@ -156,22 +164,28 @@ def run(self): # pylint: disable=line-too-long # Create the display: -#disp = st7789.ST7789(spi, rotation=90, # 2.0" ST7789 -#disp = st7789.ST7789(spi, height=240, y_offset=80, rotation=180, # 1.3", 1.54" ST7789 -#disp = st7789.ST7789(spi, rotation=90, width=135, height=240, x_offset=53, y_offset=40, # 1.14" ST7789 -#disp = hx8357.HX8357(spi, rotation=180, # 3.5" HX8357 -#disp = st7735.ST7735R(spi, rotation=90, # 1.8" ST7735R -#disp = st7735.ST7735R(spi, rotation=270, height=128, x_offset=2, y_offset=3, # 1.44" ST7735R -#disp = st7735.ST7735R(spi, rotation=90, bgr=True, # 0.96" MiniTFT ST7735R -#disp = ssd1351.SSD1351(spi, rotation=180, # 1.5" SSD1351 -#disp = ssd1351.SSD1351(spi, height=96, y_offset=32, rotation=180, # 1.27" SSD1351 -#disp = ssd1331.SSD1331(spi, rotation=180, # 0.96" SSD1331 -disp = ili9341.ILI9341(spi, rotation=90, # 2.2", 2.4", 2.8", 3.2" ILI9341 - cs=cs_pin, dc=dc_pin, rst=reset_pin, baudrate=BAUDRATE) +# disp = st7789.ST7789(spi, rotation=90, # 2.0" ST7789 +# disp = st7789.ST7789(spi, height=240, y_offset=80, rotation=180, # 1.3", 1.54" ST7789 +# disp = st7789.ST7789(spi, rotation=90, width=135, height=240, x_offset=53, y_offset=40, # 1.14" ST7789 +# disp = hx8357.HX8357(spi, rotation=180, # 3.5" HX8357 +# disp = st7735.ST7735R(spi, rotation=90, # 1.8" ST7735R +# disp = st7735.ST7735R(spi, rotation=270, height=128, x_offset=2, y_offset=3, # 1.44" ST7735R +# disp = st7735.ST7735R(spi, rotation=90, bgr=True, # 0.96" MiniTFT ST7735R +# disp = ssd1351.SSD1351(spi, rotation=180, # 1.5" SSD1351 +# disp = ssd1351.SSD1351(spi, height=96, y_offset=32, rotation=180, # 1.27" SSD1351 +# disp = ssd1331.SSD1331(spi, rotation=180, # 0.96" SSD1331 +disp = ili9341.ILI9341( + spi, + rotation=90, # 2.2", 2.4", 2.8", 3.2" ILI9341 + cs=cs_pin, + dc=dc_pin, + rst=reset_pin, + baudrate=BAUDRATE, +) # pylint: enable=line-too-long if disp.rotation % 180 == 90: - disp_height = disp.width # we swap height/width to rotate it to landscape! + disp_height = disp.width # we swap height/width to rotate it to landscape! disp_width = disp.height else: disp_width = disp.width diff --git a/examples/rgb_display_pillow_demo.py b/examples/rgb_display_pillow_demo.py index e74e9ac..c166c99 100644 --- a/examples/rgb_display_pillow_demo.py +++ b/examples/rgb_display_pillow_demo.py @@ -2,11 +2,11 @@ import board from PIL import Image, ImageDraw, ImageFont import adafruit_rgb_display.ili9341 as ili9341 -import adafruit_rgb_display.st7789 as st7789 # pylint: disable=unused-import -import adafruit_rgb_display.hx8357 as hx8357 # pylint: disable=unused-import -import adafruit_rgb_display.st7735 as st7735 # pylint: disable=unused-import -import adafruit_rgb_display.ssd1351 as ssd1351 # pylint: disable=unused-import -import adafruit_rgb_display.ssd1331 as ssd1331 # pylint: disable=unused-import +import adafruit_rgb_display.st7789 as st7789 # pylint: disable=unused-import +import adafruit_rgb_display.hx8357 as hx8357 # pylint: disable=unused-import +import adafruit_rgb_display.st7735 as st7735 # pylint: disable=unused-import +import adafruit_rgb_display.ssd1351 as ssd1351 # pylint: disable=unused-import +import adafruit_rgb_display.ssd1331 as ssd1331 # pylint: disable=unused-import # First define some constants to allow easy resizing of shapes. BORDER = 20 @@ -25,30 +25,36 @@ # pylint: disable=line-too-long # Create the display: -#disp = st7789.ST7789(spi, rotation=90, # 2.0" ST7789 -#disp = st7789.ST7789(spi, height=240, y_offset=80, rotation=180, # 1.3", 1.54" ST7789 -#disp = st7789.ST7789(spi, rotation=90, width=135, height=240, x_offset=53, y_offset=40, # 1.14" ST7789 -#disp = hx8357.HX8357(spi, rotation=180, # 3.5" HX8357 -#disp = st7735.ST7735R(spi, rotation=90, # 1.8" ST7735R -#disp = st7735.ST7735R(spi, rotation=270, height=128, x_offset=2, y_offset=3, # 1.44" ST7735R -#disp = st7735.ST7735R(spi, rotation=90, bgr=True, # 0.96" MiniTFT ST7735R -#disp = ssd1351.SSD1351(spi, rotation=180, # 1.5" SSD1351 -#disp = ssd1351.SSD1351(spi, height=96, y_offset=32, rotation=180, # 1.27" SSD1351 -#disp = ssd1331.SSD1331(spi, rotation=180, # 0.96" SSD1331 -disp = ili9341.ILI9341(spi, rotation=90, # 2.2", 2.4", 2.8", 3.2" ILI9341 - cs=cs_pin, dc=dc_pin, rst=reset_pin, baudrate=BAUDRATE) +# disp = st7789.ST7789(spi, rotation=90, # 2.0" ST7789 +# disp = st7789.ST7789(spi, height=240, y_offset=80, rotation=180, # 1.3", 1.54" ST7789 +# disp = st7789.ST7789(spi, rotation=90, width=135, height=240, x_offset=53, y_offset=40, # 1.14" ST7789 +# disp = hx8357.HX8357(spi, rotation=180, # 3.5" HX8357 +# disp = st7735.ST7735R(spi, rotation=90, # 1.8" ST7735R +# disp = st7735.ST7735R(spi, rotation=270, height=128, x_offset=2, y_offset=3, # 1.44" ST7735R +# disp = st7735.ST7735R(spi, rotation=90, bgr=True, # 0.96" MiniTFT ST7735R +# disp = ssd1351.SSD1351(spi, rotation=180, # 1.5" SSD1351 +# disp = ssd1351.SSD1351(spi, height=96, y_offset=32, rotation=180, # 1.27" SSD1351 +# disp = ssd1331.SSD1331(spi, rotation=180, # 0.96" SSD1331 +disp = ili9341.ILI9341( + spi, + rotation=90, # 2.2", 2.4", 2.8", 3.2" ILI9341 + cs=cs_pin, + dc=dc_pin, + rst=reset_pin, + baudrate=BAUDRATE, +) # pylint: enable=line-too-long # Create blank image for drawing. # Make sure to create image with mode 'RGB' for full color. if disp.rotation % 180 == 90: - height = disp.width # we swap height/width to rotate it to landscape! + height = disp.width # we swap height/width to rotate it to landscape! width = disp.height else: - width = disp.width # we swap height/width to rotate it to landscape! + width = disp.width # we swap height/width to rotate it to landscape! height = disp.height -image = Image.new('RGB', (width, height)) +image = Image.new("RGB", (width, height)) # Get drawing object to draw on image. draw = ImageDraw.Draw(image) @@ -58,17 +64,22 @@ disp.image(image) # Draw a smaller inner purple rectangle -draw.rectangle((BORDER, BORDER, width - BORDER - 1, height - BORDER - 1), - fill=(170, 0, 136)) +draw.rectangle( + (BORDER, BORDER, width - BORDER - 1, height - BORDER - 1), fill=(170, 0, 136) +) # Load a TTF Font -font = ImageFont.truetype('/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf', FONTSIZE) +font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", FONTSIZE) # Draw Some Text text = "Hello World!" (font_width, font_height) = font.getsize(text) -draw.text((width//2 - font_width//2, height//2 - font_height//2), - text, font=font, fill=(255, 255, 0)) +draw.text( + (width // 2 - font_width // 2, height // 2 - font_height // 2), + text, + font=font, + fill=(255, 255, 0), +) # Display image. disp.image(image) diff --git a/examples/rgb_display_pillow_image.py b/examples/rgb_display_pillow_image.py index 0e6e6e9..e3676c6 100644 --- a/examples/rgb_display_pillow_image.py +++ b/examples/rgb_display_pillow_image.py @@ -2,11 +2,11 @@ import board from PIL import Image, ImageDraw import adafruit_rgb_display.ili9341 as ili9341 -import adafruit_rgb_display.st7789 as st7789 # pylint: disable=unused-import -import adafruit_rgb_display.hx8357 as hx8357 # pylint: disable=unused-import -import adafruit_rgb_display.st7735 as st7735 # pylint: disable=unused-import -import adafruit_rgb_display.ssd1351 as ssd1351 # pylint: disable=unused-import -import adafruit_rgb_display.ssd1331 as ssd1331 # pylint: disable=unused-import +import adafruit_rgb_display.st7789 as st7789 # pylint: disable=unused-import +import adafruit_rgb_display.hx8357 as hx8357 # pylint: disable=unused-import +import adafruit_rgb_display.st7735 as st7735 # pylint: disable=unused-import +import adafruit_rgb_display.ssd1351 as ssd1351 # pylint: disable=unused-import +import adafruit_rgb_display.ssd1331 as ssd1331 # pylint: disable=unused-import # Configuration for CS and DC pins (these are PiTFT defaults): cs_pin = digitalio.DigitalInOut(board.CE0) @@ -21,29 +21,35 @@ # pylint: disable=line-too-long # Create the display: -#disp = st7789.ST7789(spi, rotation=90, # 2.0" ST7789 -#disp = st7789.ST7789(spi, height=240, y_offset=80, rotation=180, # 1.3", 1.54" ST7789 -#disp = st7789.ST7789(spi, rotation=90, width=135, height=240, x_offset=53, y_offset=40, # 1.14" ST7789 -#disp = hx8357.HX8357(spi, rotation=180, # 3.5" HX8357 -#disp = st7735.ST7735R(spi, rotation=90, # 1.8" ST7735R -#disp = st7735.ST7735R(spi, rotation=270, height=128, x_offset=2, y_offset=3, # 1.44" ST7735R -#disp = st7735.ST7735R(spi, rotation=90, bgr=True, # 0.96" MiniTFT ST7735R -#disp = ssd1351.SSD1351(spi, rotation=180, # 1.5" SSD1351 -#disp = ssd1351.SSD1351(spi, height=96, y_offset=32, rotation=180, # 1.27" SSD1351 -#disp = ssd1331.SSD1331(spi, rotation=180, # 0.96" SSD1331 -disp = ili9341.ILI9341(spi, rotation=90, # 2.2", 2.4", 2.8", 3.2" ILI9341 - cs=cs_pin, dc=dc_pin, rst=reset_pin, baudrate=BAUDRATE) +# disp = st7789.ST7789(spi, rotation=90, # 2.0" ST7789 +# disp = st7789.ST7789(spi, height=240, y_offset=80, rotation=180, # 1.3", 1.54" ST7789 +# disp = st7789.ST7789(spi, rotation=90, width=135, height=240, x_offset=53, y_offset=40, # 1.14" ST7789 +# disp = hx8357.HX8357(spi, rotation=180, # 3.5" HX8357 +# disp = st7735.ST7735R(spi, rotation=90, # 1.8" ST7735R +# disp = st7735.ST7735R(spi, rotation=270, height=128, x_offset=2, y_offset=3, # 1.44" ST7735R +# disp = st7735.ST7735R(spi, rotation=90, bgr=True, # 0.96" MiniTFT ST7735R +# disp = ssd1351.SSD1351(spi, rotation=180, # 1.5" SSD1351 +# disp = ssd1351.SSD1351(spi, height=96, y_offset=32, rotation=180, # 1.27" SSD1351 +# disp = ssd1331.SSD1331(spi, rotation=180, # 0.96" SSD1331 +disp = ili9341.ILI9341( + spi, + rotation=90, # 2.2", 2.4", 2.8", 3.2" ILI9341 + cs=cs_pin, + dc=dc_pin, + rst=reset_pin, + baudrate=BAUDRATE, +) # pylint: enable=line-too-long # Create blank image for drawing. # Make sure to create image with mode 'RGB' for full color. if disp.rotation % 180 == 90: - height = disp.width # we swap height/width to rotate it to landscape! + height = disp.width # we swap height/width to rotate it to landscape! width = disp.height else: - width = disp.width # we swap height/width to rotate it to landscape! + width = disp.width # we swap height/width to rotate it to landscape! height = disp.height -image = Image.new('RGB', (width, height)) +image = Image.new("RGB", (width, height)) # Get drawing object to draw on image. draw = ImageDraw.Draw(image) diff --git a/examples/rgb_display_pillow_stats.py b/examples/rgb_display_pillow_stats.py index 36a1f3d..0617de8 100644 --- a/examples/rgb_display_pillow_stats.py +++ b/examples/rgb_display_pillow_stats.py @@ -4,11 +4,11 @@ import board from PIL import Image, ImageDraw, ImageFont import adafruit_rgb_display.ili9341 as ili9341 -import adafruit_rgb_display.st7789 as st7789 # pylint: disable=unused-import -import adafruit_rgb_display.hx8357 as hx8357 # pylint: disable=unused-import -import adafruit_rgb_display.st7735 as st7735 # pylint: disable=unused-import -import adafruit_rgb_display.ssd1351 as ssd1351 # pylint: disable=unused-import -import adafruit_rgb_display.ssd1331 as ssd1331 # pylint: disable=unused-import +import adafruit_rgb_display.st7789 as st7789 # pylint: disable=unused-import +import adafruit_rgb_display.hx8357 as hx8357 # pylint: disable=unused-import +import adafruit_rgb_display.st7735 as st7735 # pylint: disable=unused-import +import adafruit_rgb_display.ssd1351 as ssd1351 # pylint: disable=unused-import +import adafruit_rgb_display.ssd1331 as ssd1331 # pylint: disable=unused-import # Configuration for CS and DC pins (these are PiTFT defaults): cs_pin = digitalio.DigitalInOut(board.CE0) @@ -23,30 +23,36 @@ # pylint: disable=line-too-long # Create the display: -#disp = st7789.ST7789(spi, rotation=90, # 2.0" ST7789 -#disp = st7789.ST7789(spi, height=240, y_offset=80, rotation=180, # 1.3", 1.54" ST7789 -#disp = st7789.ST7789(spi, rotation=90, width=135, height=240, x_offset=53, y_offset=40, # 1.14" ST7789 -#disp = hx8357.HX8357(spi, rotation=180, # 3.5" HX8357 -#disp = st7735.ST7735R(spi, rotation=90, # 1.8" ST7735R -#disp = st7735.ST7735R(spi, rotation=270, height=128, x_offset=2, y_offset=3, # 1.44" ST7735R -#disp = st7735.ST7735R(spi, rotation=90, bgr=True, # 0.96" MiniTFT ST7735R -#disp = ssd1351.SSD1351(spi, rotation=180, # 1.5" SSD1351 -#disp = ssd1351.SSD1351(spi, height=96, y_offset=32, rotation=180, # 1.27" SSD1351 -#disp = ssd1331.SSD1331(spi, rotation=180, # 0.96" SSD1331 -disp = ili9341.ILI9341(spi, rotation=90, # 2.2", 2.4", 2.8", 3.2" ILI9341 - cs=cs_pin, dc=dc_pin, rst=reset_pin, baudrate=BAUDRATE) +# disp = st7789.ST7789(spi, rotation=90, # 2.0" ST7789 +# disp = st7789.ST7789(spi, height=240, y_offset=80, rotation=180, # 1.3", 1.54" ST7789 +# disp = st7789.ST7789(spi, rotation=90, width=135, height=240, x_offset=53, y_offset=40, # 1.14" ST7789 +# disp = hx8357.HX8357(spi, rotation=180, # 3.5" HX8357 +# disp = st7735.ST7735R(spi, rotation=90, # 1.8" ST7735R +# disp = st7735.ST7735R(spi, rotation=270, height=128, x_offset=2, y_offset=3, # 1.44" ST7735R +# disp = st7735.ST7735R(spi, rotation=90, bgr=True, # 0.96" MiniTFT ST7735R +# disp = ssd1351.SSD1351(spi, rotation=180, # 1.5" SSD1351 +# disp = ssd1351.SSD1351(spi, height=96, y_offset=32, rotation=180, # 1.27" SSD1351 +# disp = ssd1331.SSD1331(spi, rotation=180, # 0.96" SSD1331 +disp = ili9341.ILI9341( + spi, + rotation=90, # 2.2", 2.4", 2.8", 3.2" ILI9341 + cs=cs_pin, + dc=dc_pin, + rst=reset_pin, + baudrate=BAUDRATE, +) # pylint: enable=line-too-long # Create blank image for drawing. # Make sure to create image with mode 'RGB' for full color. if disp.rotation % 180 == 90: - height = disp.width # we swap height/width to rotate it to landscape! + height = disp.width # we swap height/width to rotate it to landscape! width = disp.height else: - width = disp.width # we swap height/width to rotate it to landscape! + width = disp.width # we swap height/width to rotate it to landscape! height = disp.height -image = Image.new('RGB', (width, height)) +image = Image.new("RGB", (width, height)) # Get drawing object to draw on image. draw = ImageDraw.Draw(image) @@ -62,7 +68,7 @@ # Load a TTF font. Make sure the .ttf font file is in the # same directory as the python script! # Some other nice fonts to try: http://www.dafont.com/bitmap.php -font = ImageFont.truetype('/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf', 24) +font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", 24) while True: # Draw a black filled box to clear the image. @@ -70,15 +76,15 @@ # Shell scripts for system monitoring from here: # https://unix.stackexchange.com/questions/119126/command-to-display-memory-usage-disk-usage-and-cpu-load - cmd = "hostname -I | cut -d\' \' -f1" - IP = "IP: "+subprocess.check_output(cmd, shell=True).decode("utf-8") + cmd = "hostname -I | cut -d' ' -f1" + IP = "IP: " + subprocess.check_output(cmd, shell=True).decode("utf-8") cmd = "top -bn1 | grep load | awk '{printf \"CPU Load: %.2f\", $(NF-2)}'" CPU = subprocess.check_output(cmd, shell=True).decode("utf-8") cmd = "free -m | awk 'NR==2{printf \"Mem: %s/%s MB %.2f%%\", $3,$2,$3*100/$2 }'" MemUsage = subprocess.check_output(cmd, shell=True).decode("utf-8") - cmd = "df -h | awk '$NF==\"/\"{printf \"Disk: %d/%d GB %s\", $3,$2,$5}'" + cmd = 'df -h | awk \'$NF=="/"{printf "Disk: %d/%d GB %s", $3,$2,$5}\'' Disk = subprocess.check_output(cmd, shell=True).decode("utf-8") - cmd = "cat /sys/class/thermal/thermal_zone0/temp | awk \'{printf \"CPU Temp: %.1f C\", $(NF-0) / 1000}\'" # pylint: disable=line-too-long + cmd = "cat /sys/class/thermal/thermal_zone0/temp | awk '{printf \"CPU Temp: %.1f C\", $(NF-0) / 1000}'" # pylint: disable=line-too-long Temp = subprocess.check_output(cmd, shell=True).decode("utf-8") # Write four lines of text. @@ -95,4 +101,4 @@ # Display image. disp.image(image) - time.sleep(.1) + time.sleep(0.1) diff --git a/examples/rgb_display_simpletest.py b/examples/rgb_display_simpletest.py index 3e232ad..a8438c4 100644 --- a/examples/rgb_display_simpletest.py +++ b/examples/rgb_display_simpletest.py @@ -35,12 +35,12 @@ # Clear the display display.fill(0) # Draw a red pixel in the center. - display.pixel(display.width//2, display.height//2, color565(255, 0, 0)) + display.pixel(display.width // 2, display.height // 2, color565(255, 0, 0)) # Pause 2 seconds. time.sleep(2) # Clear the screen a random color - display.fill(color565(random.randint(0, 255), - random.randint(0, 255), - random.randint(0, 255))) + display.fill( + color565(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)) + ) # Pause 2 seconds. time.sleep(2) diff --git a/setup.py b/setup.py index eb841bc..0243fce 100644 --- a/setup.py +++ b/setup.py @@ -7,6 +7,7 @@ # Always prefer setuptools over distutils from setuptools import setup, find_packages + # To use a consistent encoding from codecs import open from os import path @@ -14,48 +15,39 @@ here = path.abspath(path.dirname(__file__)) # Get the long description from the README file -with open(path.join(here, 'README.rst'), encoding='utf-8') as f: +with open(path.join(here, "README.rst"), encoding="utf-8") as f: long_description = f.read() setup( - name='adafruit-circuitpython-rgb-display', - + name="adafruit-circuitpython-rgb-display", use_scm_version=True, - setup_requires=['setuptools_scm'], - - description='CircuitPython library for RGB displays.', + setup_requires=["setuptools_scm"], + description="CircuitPython library for RGB displays.", long_description=long_description, - long_description_content_type='text/x-rst', - + long_description_content_type="text/x-rst", # The project's main homepage. - url='https://github.com/adafruit/Adafruit_CircuitPython_RGB_Display', - + url="https://github.com/adafruit/Adafruit_CircuitPython_RGB_Display", # Author details - author='Radomir Dopieralski, Michael McWethy', - author_email='circuitpython@adafruit.com', - - install_requires=['Adafruit-Blinka', 'adafruit-circuitpython-busdevice'], - + author="Radomir Dopieralski, Michael McWethy", + author_email="circuitpython@adafruit.com", + install_requires=["Adafruit-Blinka", "adafruit-circuitpython-busdevice"], # Choose your license - license='MIT', - + license="MIT", # See https://pypi.python.org/pypi?%3Aaction=list_classifiers classifiers=[ - 'Development Status :: 3 - Alpha', - 'Intended Audience :: Developers', - 'Topic :: Software Development :: Libraries', - 'Topic :: System :: Hardware', - 'License :: OSI Approved :: MIT License', - 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.4', - 'Programming Language :: Python :: 3.5', + "Development Status :: 3 - Alpha", + "Intended Audience :: Developers", + "Topic :: Software Development :: Libraries", + "Topic :: System :: Hardware", + "License :: OSI Approved :: MIT License", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.4", + "Programming Language :: Python :: 3.5", ], - # What does your project relate to? - keywords='adafruit rgb display hx8353 ili9341 s6d02A1 ssd1331 ssd1351 st7735' - 'hardware micropython circuitpython', - + keywords="adafruit rgb display hx8353 ili9341 s6d02A1 ssd1331 ssd1351 st7735" + "hardware micropython circuitpython", # You can just specify the packages manually here if your project is # simple. Or you can use find_packages(). - packages=['adafruit_rgb_display'], + packages=["adafruit_rgb_display"], )