Skip to content

Commit 16ccc6b

Browse files
committed
Better handling of LEDs on Pi 5.
1 parent e8c5b84 commit 16ccc6b

File tree

3 files changed

+11
-12
lines changed

3 files changed

+11
-12
lines changed

inventorhatmini/__init__.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
#!/usr/bin/env python3
22

33
import time
4+
import warnings
45

56
import gpiod
67
import gpiodevice
78
from gpiod.line import Bias, Direction, Value
9+
from gpiodevice import platform
810
from ioexpander import ADC, SuperIOE
911
from ioexpander.common import NORMAL_DIR
1012
from ioexpander.encoder import MMME_CPR, ROTARY_CPR, Encoder
@@ -111,13 +113,18 @@ def __init__(self, address=IOE_ADDRESS, motor_gear_ratio=50, init_motors=True, i
111113
self.__init_servos = init_servos
112114
self.reinit()
113115

114-
if init_leds:
116+
is_pi5 = platform.get_name().starts_with("Raspberry Pi 5")
117+
118+
if init_leds and not is_pi5:
115119
# Setup the PixelStrip object to use with Inventor's LEDs, wrapped in a Plasma class
116120
self.leds = Plasma(NUM_LEDS, self.PI_LED_DATA_PIN)
117121
else:
118122
# Setup a dummy Plasma class, so examples don't need to check LED presence
119123
self.leds = DummyPlasma()
120124

125+
if is_pi5:
126+
warnings.warn("LEDs are not yet supported on Pi 5.")
127+
121128
def _write_pin(self, pin, state):
122129
lines, offset = pin
123130
lines.set_value(offset, Value.ACTIVE if state else Value.INACTIVE)

inventorhatmini/plasma.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from colorsys import hsv_to_rgb
22

3+
from rpi_ws281x import PixelStrip
4+
35
from inventorhatmini.errors import LED_INIT_FAILED
46

57

@@ -28,12 +30,6 @@ class Plasma():
2830
222, 224, 227, 229, 231, 233, 235, 237, 239, 241, 244, 246, 248, 250, 252, 255]
2931

3032
def __init__(self, num_leds, pin):
31-
try:
32-
from rpi_ws281x import PixelStrip
33-
except ImportError:
34-
self = DummyPlasma()
35-
return
36-
3733
# Setup the PixelStrip object to use with Inventor's LEDs
3834
self.leds = PixelStrip(num_leds, pin, self.LED_FREQ_HZ, self.LED_DMA, self.LED_INVERT, self.LED_BRIGHTNESS, self.LED_CHANNEL, self.LED_GAMMA)
3935
try:

pyproject.toml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,7 @@ classifiers = [
3737
]
3838
dependencies = [
3939
"pimoroni-ioexpander>=1.0.0",
40-
"smbus2"
41-
]
42-
43-
[project.optional-dependencies]
44-
leds = [
40+
"smbus2",
4541
"rpi_ws281x"
4642
]
4743

0 commit comments

Comments
 (0)