Skip to content

Commit 0d4e2f3

Browse files
committed
Switch from plasma to apa102 library for LED
1 parent 7bbc5f6 commit 0d4e2f3

4 files changed

Lines changed: 19 additions & 17 deletions

File tree

examples/led.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
while True:
1111
h = time.time() / 25.0
1212
r, g, b = [int(c * 255) for c in colorsys.hsv_to_rgb(h, 1.0, 1.0)]
13-
fanshim.set_light(r, g, b)
13+
fanshim.set_light(r, g, b, brightness=0.05)
1414
time.sleep(1.0 / 60)
1515

1616
except KeyboardInterrupt:

library/fanshim/__init__.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import RPi.GPIO as GPIO
22
import time
3-
try:
4-
from plasma import legacy as plasma
5-
except ImportError:
6-
import plasma
3+
import apa102
74
import atexit
85
from threading import Thread
96

@@ -27,16 +24,14 @@ def __init__(self, pin_fancontrol=18, pin_button=17, button_poll_delay=0.05):
2724
self._button_hold_time = 2.0
2825
self._t_poll = None
2926

30-
atexit.register(self._cleanup)
31-
3227
GPIO.setwarnings(False)
3328
GPIO.setmode(GPIO.BCM)
3429
GPIO.setup(self._pin_fancontrol, GPIO.OUT)
3530
GPIO.setup(self._pin_button, GPIO.IN, pull_up_down=GPIO.PUD_UP)
3631

37-
plasma.set_clear_on_exit(True)
38-
plasma.set_light_count(1)
39-
plasma.set_light(0, 0, 0, 0)
32+
self._led = apa102.APA102(1, 15, 14, None, brightness=0.05)
33+
34+
atexit.register(self._cleanup)
4035

4136
def start_polling(self):
4237
"""Start button polling."""
@@ -109,20 +104,24 @@ def set_fan(self, fan_state):
109104
GPIO.output(self._pin_fancontrol, True if fan_state else False)
110105
return True if fan_state else False
111106

112-
def set_light(self, r, g, b):
107+
def set_light(self, r, g, b, brightness=None):
113108
"""Set LED.
114109
115110
:param r: Red (0-255)
116111
:param g: Green (0-255)
117112
:param b: Blue (0-255)
118113
119114
"""
120-
plasma.set_light(0, r, g, b)
121-
plasma.show()
115+
self._led.set_pixel(0, r, g, b)
116+
if brightness is not None:
117+
self._led.set_brightness(0, brightness)
118+
self._led.show()
122119

123120
def _cleanup(self):
124121
self.stop_polling()
125122

123+
self.set_light(0, 0, 0)
124+
126125
def _run(self):
127126
self._running = True
128127
last = 1

library/setup.cfg

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ classifiers =
2626
Topic :: Software Development :: Libraries
2727
Topic :: System :: Hardware
2828

29+
[options]
30+
python_requires = >= 2.7
31+
packages = fanshim
32+
install_requires =
33+
apa102 >= 0.0.3
34+
2935
[flake8]
3036
exclude =
3137
.tox,

library/setup.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,4 @@
2424

2525
from setuptools import setup
2626

27-
setup(
28-
packages=['fanshim'],
29-
install_requires=['plasmalights']
30-
)
27+
setup()

0 commit comments

Comments
 (0)