Skip to content

Commit

Permalink
QA: Apply cherry-picked Black suggestions.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gadgetoid committed Nov 20, 2023
1 parent fe70476 commit b8635c0
Show file tree
Hide file tree
Showing 9 changed files with 147 additions and 141 deletions.
4 changes: 3 additions & 1 deletion inky/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
from .phat import InkyPHAT, InkyPHAT_SSD1608 # noqa: F401
from .what import InkyWHAT # noqa: F401

__version__ = '1.5.0'
__version__ = "1.5.0"

try:
from pkg_resources import declare_namespace

declare_namespace(__name__)
except ImportError:
from pkgutil import extend_path

__path__ = extend_path(__path__, __name__)
6 changes: 3 additions & 3 deletions inky/auto.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ def auto(i2c_bus=None, ask_user=False, verbose=False):
if verbose:
print("Failed to detect an Inky board. Trying --type/--colour arguments instead...\n")
parser = argparse.ArgumentParser()
parser.add_argument('--simulate', '-s', action='store_true', default=False, help="Simulate Inky display")
parser.add_argument('--type', '-t', type=str, required=True, choices=DISPLAY_TYPES, help="Type of display")
parser.add_argument('--colour', '-c', type=str, required=False, choices=DISPLAY_COLORS, help="Display colour")
parser.add_argument("--simulate", "-s", action="store_true", default=False, help="Simulate Inky display")
parser.add_argument("--type", "-t", type=str, required=True, choices=DISPLAY_TYPES, help="Type of display")
parser.add_argument("--colour", "-c", type=str, required=False, choices=DISPLAY_COLORS, help="Display colour")
args, _ = parser.parse_known_args()
if args.simulate:
cls = None
Expand Down
56 changes: 28 additions & 28 deletions inky/eeprom.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,33 @@

DISPLAY_VARIANT = [
None,
'Red pHAT (High-Temp)',
'Yellow wHAT',
'Black wHAT',
'Black pHAT',
'Yellow pHAT',
'Red wHAT',
'Red wHAT (High-Temp)',
'Red wHAT',
"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)',
"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)'
"7-Colour (UC8159)",
"7-Colour 640x400 (UC8159)",
"7-Colour 640x400 (UC8159)",
"Black wHAT (SSD1683)",
"Red wHAT (SSD1683)",
"Yellow wHAT (SSD1683)",
"7-Colour 800x480 (AC073TC1A)",
]


class EPDType:
"""Class to represent EPD EEPROM structure."""

valid_colors = [None, 'black', 'red', 'yellow', None, '7colour']
valid_colors = [None, "black", "red", "yellow", None, "7colour"]

def __init__(self, width, height, color, pcb_variant, display_variant, write_time=None):
"""Initialise new EEPROM data structure."""
Expand Down Expand Up @@ -67,7 +67,7 @@ def __repr__(self):
def from_bytes(class_object, data):
"""Initialise new EEPROM data structure from a bytes-like object or list."""
data = bytearray(data)
data = struct.unpack('<HHBBB22p', data)
data = struct.unpack("<HHBBB22p", data)
return class_object(*data)

def update_eeprom_write_time(self):
Expand All @@ -76,7 +76,7 @@ def update_eeprom_write_time(self):

def encode(self):
"""Return a bytearray representing the EEPROM data structure."""
return struct.pack('<HHBBB22p',
return struct.pack("<HHBBB22p",
self.width,
self.height,
self.color,
Expand All @@ -96,7 +96,7 @@ def set_color(self, color):
try:
self.color = self.valid_colors.index(color)
except IndexError:
raise ValueError('Invalid colour: {}'.format(color))
raise ValueError("Invalid colour: {}".format(color))

def get_color(self):
"""Get the stored colour value."""
Expand All @@ -114,16 +114,16 @@ def get_variant(self):


# Normal Yellow wHAT
yellow_what_1_E = EPDType(400, 300, color='yellow', pcb_variant=12, display_variant=2)
yellow_what_1_E = EPDType(400, 300, color="yellow", pcb_variant=12, display_variant=2)

# Normal Black wHAT
black_what_1_E = EPDType(400, 300, color='black', pcb_variant=12, display_variant=3)
black_what_1_E = EPDType(400, 300, color="black", pcb_variant=12, display_variant=3)

# Normal Black pHAT
black_phat_1_E = EPDType(212, 104, color='black', pcb_variant=12, display_variant=4)
black_phat_1_E = EPDType(212, 104, color="black", pcb_variant=12, display_variant=4)

# Hightemp Red pHAT
red_small_1_E = EPDType(212, 104, color='red', pcb_variant=12, display_variant=1)
red_small_1_E = EPDType(212, 104, color="red", pcb_variant=12, display_variant=1)


def read_eeprom(i2c_bus=None):
Expand All @@ -133,7 +133,7 @@ def read_eeprom(i2c_bus=None):
try:
from smbus2 import SMBus
except ImportError:
raise ImportError('This library requires the smbus2 module\nInstall with: sudo pip install smbus2')
raise ImportError("This library requires the smbus2 module\nInstall with: sudo pip install smbus2")
i2c_bus = SMBus(1)
i2c_bus.write_i2c_block_data(EEP_ADDRESS, 0x00, [0x00])
return EPDType.from_bytes(i2c_bus.read_i2c_block_data(EEP_ADDRESS, 0, 29))
Expand All @@ -147,6 +147,6 @@ def main(args):
return 0


if __name__ == '__main__':
if __name__ == "__main__":
import sys
sys.exit(main(sys.argv))
62 changes: 31 additions & 31 deletions inky/inky.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
try:
import numpy
except ImportError:
raise ImportError('This library requires the numpy module\nInstall with: sudo apt install python-numpy')
raise ImportError("This library requires the numpy module\nInstall with: sudo apt install python-numpy")

__version__ = "1.5.0"

Expand Down Expand Up @@ -54,13 +54,13 @@ class Inky:
RED = 2
YELLOW = 2

def __init__(self, resolution=(400, 300), colour='black', cs_channel=CS0, dc_pin=DC_PIN, reset_pin=RESET_PIN, busy_pin=BUSY_PIN, h_flip=False, v_flip=False,
def __init__(self, resolution=(400, 300), colour="black", cs_channel=CS0, dc_pin=DC_PIN, reset_pin=RESET_PIN, busy_pin=BUSY_PIN, h_flip=False, v_flip=False,
spi_bus=None, i2c_bus=None, gpio=None):
"""Initialise an Inky Display.
:param resolution: Display resolution (width, height) in pixels, default: (400, 300).
:type resolution: tuple(int, int)
:param str colour: One of 'red', 'black' or 'yellow', default: 'black'.
:param str colour: One of "red", "black" or "yellow", default: "black".
:param int cs_channel: Chip-select channel for SPI communication, default: `0`.
:param int dc_pin: Data/command pin for SPI communication, default: `22`.
:param int reset_pin: Device reset pin, default: `27`.
Expand All @@ -78,24 +78,24 @@ def __init__(self, resolution=(400, 300), colour='black', cs_channel=CS0, dc_pin
self._i2c_bus = i2c_bus

if resolution not in _RESOLUTION.keys():
raise ValueError('Resolution {}x{} not supported!'.format(*resolution))
raise ValueError("Resolution {}x{} not supported!".format(*resolution))

self.resolution = resolution
self.width, self.height = resolution
self.cols, self.rows, self.rotation = _RESOLUTION[resolution]

if colour not in ('red', 'black', 'yellow'):
raise ValueError('Colour {} is not supported!'.format(colour))
if colour not in ("red", "black", "yellow"):
raise ValueError("Colour {} is not supported!".format(colour))

self.colour = colour
self.eeprom = eeprom.read_eeprom(i2c_bus=i2c_bus)
self.lut = colour

if self.eeprom is not None:
if self.eeprom.width != self.width or self.eeprom.height != self.height:
raise ValueError('Supplied width/height do not match Inky: {}x{}'.format(self.eeprom.width, self.eeprom.height))
if self.eeprom.display_variant in (1, 6) and self.eeprom.get_color() == 'red':
self.lut = 'red_ht'
raise ValueError("Supplied width/height do not match Inky: {}x{}".format(self.eeprom.width, self.eeprom.height))
if self.eeprom.display_variant in (1, 6) and self.eeprom.get_color() == "red":
self.lut = "red_ht"

self.buf = numpy.zeros((self.height, self.width), dtype=numpy.uint8)
self.border_colour = 0
Expand Down Expand Up @@ -160,7 +160,7 @@ def __init__(self, resolution=(400, 300), colour='black', cs_channel=CS0, dc_pin
"""
self._luts = {
'black': [
"black": [
0b01001000, 0b10100000, 0b00010000, 0b00010000, 0b00010011, 0b00000000, 0b00000000,
0b01001000, 0b10100000, 0b10000000, 0b00000000, 0b00000011, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
Expand All @@ -174,7 +174,7 @@ def __init__(self, resolution=(400, 300), colour='black', cs_channel=CS0, dc_pin
0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00,
],
'red': [
"red": [
0b01001000, 0b10100000, 0b00010000, 0b00010000, 0b00010011, 0b00000000, 0b00000000,
0b01001000, 0b10100000, 0b10000000, 0b00000000, 0b00000011, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
Expand All @@ -188,7 +188,7 @@ def __init__(self, resolution=(400, 300), colour='black', cs_channel=CS0, dc_pin
0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00
],
'red_ht': [
"red_ht": [
0b01001000, 0b10100000, 0b00010000, 0b00010000, 0b00010011, 0b00010000, 0b00010000,
0b01001000, 0b10100000, 0b10000000, 0b00000000, 0b00000011, 0b10000000, 0b10000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
Expand All @@ -202,7 +202,7 @@ def __init__(self, resolution=(400, 300), colour='black', cs_channel=CS0, dc_pin
0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00
],
'yellow': [
"yellow": [
0b11111010, 0b10010100, 0b10001100, 0b11000000, 0b11010000, 0b00000000, 0b00000000,
0b11111010, 0b10010100, 0b00101100, 0b10000000, 0b11100000, 0b00000000, 0b00000000,
0b11111010, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
Expand All @@ -226,7 +226,7 @@ def setup(self):
import RPi.GPIO as GPIO
self._gpio = GPIO
except ImportError:
raise ImportError('This library requires the RPi.GPIO module\nInstall with: sudo apt install python-rpi.gpio')
raise ImportError("This library requires the RPi.GPIO module\nInstall with: sudo apt install python-rpi.gpio")
self._gpio.setmode(self._gpio.BCM)
self._gpio.setwarnings(False)
self._gpio.setup(self.dc_pin, self._gpio.OUT, initial=self._gpio.LOW, pull_up_down=self._gpio.PUD_OFF)
Expand Down Expand Up @@ -264,38 +264,38 @@ def _update(self, buf_a, buf_b, busy_wait=True):
"""
self.setup()

packed_height = list(struct.pack('<H', self.rows))
packed_height = list(struct.pack("<H", self.rows))

if isinstance(packed_height[0], str):
packed_height = map(ord, packed_height)

self._send_command(0x74, 0x54) # Set Analog Block Control
self._send_command(0x7e, 0x3b) # Set Digital Block Control
self._send_command(0x7E, 0x3B) # Set Digital Block Control

self._send_command(0x01, packed_height + [0x00]) # Gate setting

self._send_command(0x03, 0x17) # Gate Driving Voltage
self._send_command(0x04, [0x41, 0xAC, 0x32]) # Source Driving Voltage

self._send_command(0x3a, 0x07) # Dummy line period
self._send_command(0x3b, 0x04) # Gate line width
self._send_command(0x3A, 0x07) # Dummy line period
self._send_command(0x3B, 0x04) # Gate line width
self._send_command(0x11, 0x03) # Data entry mode setting 0x03 = X/Y increment

self._send_command(0x2c, 0x3c) # VCOM Register, 0x3c = -1.5v?
self._send_command(0x2C, 0x3C) # VCOM Register, 0x3c = -1.5v?

self._send_command(0x3c, 0b00000000)
self._send_command(0x3C, 0b00000000)
if self.border_colour == self.BLACK:
self._send_command(0x3c, 0b00000000) # GS Transition Define A + VSS + LUT0
elif self.border_colour == self.RED and self.colour == 'red':
self._send_command(0x3c, 0b01110011) # Fix Level Define A + VSH2 + LUT3
elif self.border_colour == self.YELLOW and self.colour == 'yellow':
self._send_command(0x3c, 0b00110011) # GS Transition Define A + VSH2 + LUT3
self._send_command(0x3C, 0b00000000) # GS Transition Define A + VSS + LUT0
elif self.border_colour == self.RED and self.colour == "red":
self._send_command(0x3C, 0b01110011) # Fix Level Define A + VSH2 + LUT3
elif self.border_colour == self.YELLOW and self.colour == "yellow":
self._send_command(0x3C, 0b00110011) # GS Transition Define A + VSH2 + LUT3
elif self.border_colour == self.WHITE:
self._send_command(0x3c, 0b00110001) # GS Transition Define A + VSH2 + LUT1
self._send_command(0x3C, 0b00110001) # GS Transition Define A + VSH2 + LUT1

if self.colour == 'yellow':
if self.colour == "yellow":
self._send_command(0x04, [0x07, 0xAC, 0x32]) # Set voltage of VSH and VSL
if self.colour == 'red' and self.resolution == (400, 300):
if self.colour == "red" and self.resolution == (400, 300):
self._send_command(0x04, [0x30, 0xAC, 0x22])

self._send_command(0x32, self._luts[self.lut]) # Set LUTs
Expand All @@ -306,8 +306,8 @@ def _update(self, buf_a, buf_b, busy_wait=True):
# 0x24 == RAM B/W, 0x26 == RAM Red/Yellow/etc
for data in ((0x24, buf_a), (0x26, buf_b)):
cmd, buf = data
self._send_command(0x4e, 0x00) # Set RAM X Pointer Start
self._send_command(0x4f, [0x00, 0x00]) # Set RAM Y Pointer Start
self._send_command(0x4E, 0x00) # Set RAM X Pointer Start
self._send_command(0x4F, [0x00, 0x00]) # Set RAM Y Pointer Start
self._send_command(cmd, buf)

self._send_command(0x22, 0xC7) # Display Update Sequence
Expand Down Expand Up @@ -382,7 +382,7 @@ def _spi_write(self, dc, values):
except AttributeError:
for x in range(((len(values) - 1) // _SPI_CHUNK_SIZE) + 1):
offset = x * _SPI_CHUNK_SIZE
self._spi_bus.xfer(values[offset:offset + _SPI_CHUNK_SIZE])
self._spi_bus.xfer(values[offset : offset + _SPI_CHUNK_SIZE])

def _send_command(self, command, data=None):
"""Send command over SPI.
Expand Down
Loading

0 comments on commit b8635c0

Please sign in to comment.