Updated type hints for return values, fix type hint imports, update requirements
This commit is contained in:
parent
76f906c1e2
commit
f0feb8aa80
5 changed files with 40 additions and 25 deletions
|
|
@ -30,7 +30,8 @@ from adafruit_register.i2c_bit import RWBit
|
||||||
import busio
|
import busio
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from typing import Optional
|
# Used only for typing
|
||||||
|
from typing import Optional, Tuple, Union # pylint: disable=unused-import
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
|
|
@ -106,16 +107,16 @@ class IS31FL3741:
|
||||||
self._page = None
|
self._page = None
|
||||||
self.reset()
|
self.reset()
|
||||||
|
|
||||||
def reset(self):
|
def reset(self) -> None:
|
||||||
"""Reset"""
|
"""Reset"""
|
||||||
self.page = 4
|
self.page = 4
|
||||||
self._reset_reg = 0xAE
|
self._reset_reg = 0xAE
|
||||||
|
|
||||||
def unlock(self):
|
def unlock(self) -> None:
|
||||||
"""Unlock"""
|
"""Unlock"""
|
||||||
self._lock_reg = 0xC5
|
self._lock_reg = 0xC5
|
||||||
|
|
||||||
def set_led_scaling(self, scale: int):
|
def set_led_scaling(self, scale: int) -> None:
|
||||||
"""Set LED scaling.
|
"""Set LED scaling.
|
||||||
|
|
||||||
param scale: The scale.
|
param scale: The scale.
|
||||||
|
|
@ -130,34 +131,34 @@ class IS31FL3741:
|
||||||
i2c.write(bytes(scalebuf))
|
i2c.write(bytes(scalebuf))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def global_current(self):
|
def global_current(self) -> int:
|
||||||
"""Global current"""
|
"""Global current"""
|
||||||
self.page = 4
|
self.page = 4
|
||||||
return self._gcurrent_reg
|
return self._gcurrent_reg
|
||||||
|
|
||||||
@global_current.setter
|
@global_current.setter
|
||||||
def global_current(self, current: int):
|
def global_current(self, current: int) -> None:
|
||||||
self.page = 4
|
self.page = 4
|
||||||
self._gcurrent_reg = current
|
self._gcurrent_reg = current
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def enable(self):
|
def enable(self) -> bool:
|
||||||
"""Enable"""
|
"""Enable"""
|
||||||
self.page = 4
|
self.page = 4
|
||||||
return self._shutdown_bit
|
return self._shutdown_bit
|
||||||
|
|
||||||
@enable.setter
|
@enable.setter
|
||||||
def enable(self, enable: bool):
|
def enable(self, enable: bool) -> None:
|
||||||
self.page = 4
|
self.page = 4
|
||||||
self._shutdown_bit = enable
|
self._shutdown_bit = enable
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def page(self):
|
def page(self) -> Union[int, None]:
|
||||||
"""Page"""
|
"""Page"""
|
||||||
return self._page
|
return self._page
|
||||||
|
|
||||||
@page.setter
|
@page.setter
|
||||||
def page(self, page_value: int):
|
def page(self, page_value: int) -> None:
|
||||||
if page_value == self._page:
|
if page_value == self._page:
|
||||||
return # already set
|
return # already set
|
||||||
if page_value > 4:
|
if page_value > 4:
|
||||||
|
|
@ -166,7 +167,7 @@ class IS31FL3741:
|
||||||
self.unlock()
|
self.unlock()
|
||||||
self._page_reg = page_value
|
self._page_reg = page_value
|
||||||
|
|
||||||
def __getitem__(self, led: int):
|
def __getitem__(self, led: int) -> int:
|
||||||
if not 0 <= led <= 350:
|
if not 0 <= led <= 350:
|
||||||
raise ValueError("LED must be 0 ~ 350")
|
raise ValueError("LED must be 0 ~ 350")
|
||||||
if self._pixel_buffer:
|
if self._pixel_buffer:
|
||||||
|
|
@ -184,7 +185,7 @@ class IS31FL3741:
|
||||||
)
|
)
|
||||||
return self._buf[1]
|
return self._buf[1]
|
||||||
|
|
||||||
def __setitem__(self, led: int, pwm: int):
|
def __setitem__(self, led: int, pwm: int) -> None:
|
||||||
if not 0 <= led <= 350:
|
if not 0 <= led <= 350:
|
||||||
raise ValueError("LED must be 0 ~ 350")
|
raise ValueError("LED must be 0 ~ 350")
|
||||||
if not 0 <= pwm <= 255:
|
if not 0 <= pwm <= 255:
|
||||||
|
|
@ -205,12 +206,12 @@ class IS31FL3741:
|
||||||
|
|
||||||
# This function must be replaced for each board
|
# This function must be replaced for each board
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def pixel_addrs(x: int, y: int):
|
def pixel_addrs(x: int, y: int) -> Tuple[int, ...]:
|
||||||
"""Calulate the offset into the device array for x,y pixel"""
|
"""Calulate the offset into the device array for x,y pixel"""
|
||||||
raise NotImplementedError("Supported in subclasses only")
|
raise NotImplementedError("Supported in subclasses only")
|
||||||
|
|
||||||
# pylint: disable-msg=too-many-arguments
|
# pylint: disable-msg=too-many-arguments
|
||||||
def pixel(self, x: int, y: int, color: Optional[int] = None):
|
def pixel(self, x: int, y: int, color: Optional[int] = None) -> Union[int, None]:
|
||||||
"""
|
"""
|
||||||
Color of for x-, y-pixel
|
Color of for x-, y-pixel
|
||||||
|
|
||||||
|
|
@ -232,7 +233,7 @@ class IS31FL3741:
|
||||||
|
|
||||||
# pylint: enable-msg=too-many-arguments
|
# pylint: enable-msg=too-many-arguments
|
||||||
|
|
||||||
def image(self, img: Image):
|
def image(self, img: Image) -> None:
|
||||||
"""Set buffer to value of Python Imaging Library image. The image should
|
"""Set buffer to value of Python Imaging Library image. The image should
|
||||||
be in 8-bit mode (L) and a size equal to the display size.
|
be in 8-bit mode (L) and a size equal to the display size.
|
||||||
|
|
||||||
|
|
@ -255,7 +256,7 @@ class IS31FL3741:
|
||||||
for y in range(self.height): # but these displays are small!
|
for y in range(self.height): # but these displays are small!
|
||||||
self.pixel(x, y, pixels[(x, y)])
|
self.pixel(x, y, pixels[(x, y)])
|
||||||
|
|
||||||
def show(self):
|
def show(self) -> None:
|
||||||
"""Issue in-RAM pixel data to device. No effect if pixels are
|
"""Issue in-RAM pixel data to device. No effect if pixels are
|
||||||
unbuffered.
|
unbuffered.
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -23,10 +23,16 @@ Implementation Notes
|
||||||
|
|
||||||
"""
|
"""
|
||||||
from struct import unpack_from
|
from struct import unpack_from
|
||||||
import busio
|
|
||||||
import adafruit_is31fl3741
|
import adafruit_is31fl3741
|
||||||
from . import IS31FL3741
|
from . import IS31FL3741
|
||||||
|
|
||||||
|
try:
|
||||||
|
# Used only for typing
|
||||||
|
from typing import Tuple # pylint: disable=unused-import
|
||||||
|
import busio
|
||||||
|
except ImportError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class Right_Ring:
|
class Right_Ring:
|
||||||
"""The right eye ring of the LED glasses"""
|
"""The right eye ring of the LED glasses"""
|
||||||
|
|
@ -87,7 +93,7 @@ class Right_Ring:
|
||||||
def __init__(self, is31_controller: IS31FL3741):
|
def __init__(self, is31_controller: IS31FL3741):
|
||||||
self._is31 = is31_controller
|
self._is31 = is31_controller
|
||||||
|
|
||||||
def __setitem__(self, led: int, color: int):
|
def __setitem__(self, led: int, color: int) -> None:
|
||||||
if not 0 <= led <= 23:
|
if not 0 <= led <= 23:
|
||||||
raise ValueError("led must be 0~23")
|
raise ValueError("led must be 0~23")
|
||||||
|
|
||||||
|
|
@ -96,7 +102,7 @@ class Right_Ring:
|
||||||
self._is31[rgb[1]] = (color >> 8) & 0xFF
|
self._is31[rgb[1]] = (color >> 8) & 0xFF
|
||||||
self._is31[rgb[2]] = color & 0xFF
|
self._is31[rgb[2]] = color & 0xFF
|
||||||
|
|
||||||
def __getitem__(self, led: int):
|
def __getitem__(self, led: int) -> int:
|
||||||
if not 0 <= led <= 23:
|
if not 0 <= led <= 23:
|
||||||
raise ValueError("led must be 0~23")
|
raise ValueError("led must be 0~23")
|
||||||
rgb = unpack_from(">HHH", self.ledmap_bytes, led * 6)
|
rgb = unpack_from(">HHH", self.ledmap_bytes, led * 6)
|
||||||
|
|
@ -161,10 +167,10 @@ class Left_Ring:
|
||||||
b"\x00\xF1\x00\xF0\x01\x5E"
|
b"\x00\xF1\x00\xF0\x01\x5E"
|
||||||
)
|
)
|
||||||
|
|
||||||
def __init__(self, is31_controller: IS31FL3741):
|
def __init__(self, is31_controller: IS31FL3741) -> None:
|
||||||
self._is31 = is31_controller
|
self._is31 = is31_controller
|
||||||
|
|
||||||
def __setitem__(self, led: int, color: int):
|
def __setitem__(self, led: int, color: int) -> None:
|
||||||
if not 0 <= led <= 23:
|
if not 0 <= led <= 23:
|
||||||
raise ValueError("led must be 0~23")
|
raise ValueError("led must be 0~23")
|
||||||
|
|
||||||
|
|
@ -173,7 +179,7 @@ class Left_Ring:
|
||||||
self._is31[rgb[1]] = (color >> 8) & 0xFF
|
self._is31[rgb[1]] = (color >> 8) & 0xFF
|
||||||
self._is31[rgb[2]] = color & 0xFF
|
self._is31[rgb[2]] = color & 0xFF
|
||||||
|
|
||||||
def __getitem__(self, led: int):
|
def __getitem__(self, led: int) -> int:
|
||||||
if not 0 <= led <= 23:
|
if not 0 <= led <= 23:
|
||||||
raise ValueError("led must be 0~23")
|
raise ValueError("led must be 0~23")
|
||||||
rgb = unpack_from(">HHH", self.ledmap_bytes, led * 6)
|
rgb = unpack_from(">HHH", self.ledmap_bytes, led * 6)
|
||||||
|
|
@ -387,7 +393,7 @@ class LED_Glasses(IS31FL3741):
|
||||||
self.grid = self
|
self.grid = self
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def pixel_addrs(x: int, y: int):
|
def pixel_addrs(x: int, y: int) -> Tuple[int, ...]:
|
||||||
return unpack_from(
|
return unpack_from(
|
||||||
">HHH", LED_Glasses.ledmap_bytes, ((y * LED_Glasses.width) + x) * 6
|
">HHH", LED_Glasses.ledmap_bytes, ((y * LED_Glasses.width) + x) * 6
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,8 @@ Implementation Notes
|
||||||
|
|
||||||
# imports
|
# imports
|
||||||
try:
|
try:
|
||||||
from typing import Tuple
|
# Used only for typing
|
||||||
|
from typing import Tuple # pylint: disable=unused-import
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
from . import IS31FL3741
|
from . import IS31FL3741
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,12 @@ Implementation Notes
|
||||||
# imports
|
# imports
|
||||||
from . import IS31FL3741
|
from . import IS31FL3741
|
||||||
|
|
||||||
|
try:
|
||||||
|
# Used only for typing
|
||||||
|
from typing import Tuple # pylint: disable=unused-import
|
||||||
|
except ImportError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class ISSI_EVB(IS31FL3741):
|
class ISSI_EVB(IS31FL3741):
|
||||||
"""Supports the ISSI IS31FL3741 eval board"""
|
"""Supports the ISSI IS31FL3741 eval board"""
|
||||||
|
|
@ -37,7 +43,7 @@ class ISSI_EVB(IS31FL3741):
|
||||||
height = 9
|
height = 9
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def pixel_addrs(x: int, y: int):
|
def pixel_addrs(x: int, y: int) -> Tuple[int, int, int]:
|
||||||
"""Calulate the RGB offsets into the device array for x,y pixel"""
|
"""Calulate the RGB offsets into the device array for x,y pixel"""
|
||||||
if x > 9:
|
if x > 9:
|
||||||
offset = (x + 80 + y * 3) * 3
|
offset = (x + 80 + y * 3) * 3
|
||||||
|
|
|
||||||
|
|
@ -5,3 +5,4 @@
|
||||||
Adafruit-Blinka
|
Adafruit-Blinka
|
||||||
adafruit-circuitpython-framebuf
|
adafruit-circuitpython-framebuf
|
||||||
adafruit-circuitpython-register
|
adafruit-circuitpython-register
|
||||||
|
Pillow
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue