Skip to content

Commit fa0d634

Browse files
committed
more cleanup, remove helper module
1 parent a29d40b commit fa0d634

File tree

7 files changed

+106
-275
lines changed

7 files changed

+106
-275
lines changed

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,8 @@ Python 3.6 or newer is required.
4040
4. `cd ledcontrol/driver/rpi_ws281x/`
4141
5. `scons`
4242
6. `cd ../../..`
43-
7. `swig -python ./ledcontrol/driver/ledcontrol_rpi_ws281x_driver.i`
44-
8. `sudo python3 setup.py develop`
45-
9. `sudo ledcontrol --led_count 150` (add `--led_pixel_order GRBW` if using RGBW LEDs)
43+
7. `sudo python3 setup.py develop`
44+
8. `sudo ledcontrol --led_count 150` (add `--led_pixel_order GRBW` if using RGBW LEDs)
4645

4746
### Command Line Configuration Arguments
4847
Web server and LED hardware parameters must be specified as command line arguments when running ledcontrol.
@@ -248,7 +247,7 @@ void mainImage(out vec4 fragColor, in vec2 fragCoord) {
248247
## Development
249248
To build the C extension module:
250249
```
251-
swig -python ./ledcontrol/rpi_ws281x/lib/rpi_ws281x.i && sudo python3 setup.py develop
250+
swig -python ./ledcontrol/driver/ledcontrol_rpi_ws281x_driver.i && sudo python3 setup.py develop
252251
```
253252

254253
## License

ledcontrol/animationcontroller.py

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
import ledcontrol.animationpatterns as animpatterns
1313
import ledcontrol.colorpalettes as colorpalettes
14-
import ledcontrol.driver as rpi_ws281x
14+
import ledcontrol.driver as driver
1515
import ledcontrol.utils as utils
1616

1717
class RepeatedTimer:
@@ -157,17 +157,17 @@ def getiter(obj):
157157
'hsv': animpatterns.ColorMode.hsv,
158158
'rgb': animpatterns.ColorMode.rgb,
159159
'clamp': utils.clamp,
160-
'wave_pulse': rpi_ws281x.wave_pulse,
161-
'wave_triangle': rpi_ws281x.wave_triangle,
162-
'wave_sine': rpi_ws281x.wave_sine,
163-
'wave_cubic': rpi_ws281x.wave_cubic,
164-
'plasma_sines': rpi_ws281x.plasma_sines,
165-
'plasma_sines_octave': rpi_ws281x.plasma_sines_octave,
166-
'perlin_noise_3d': rpi_ws281x.perlin_noise_3d,
160+
'wave_pulse': driver.wave_pulse,
161+
'wave_triangle': driver.wave_triangle,
162+
'wave_sine': driver.wave_sine,
163+
'wave_cubic': driver.wave_cubic,
164+
'plasma_sines': driver.plasma_sines,
165+
'plasma_sines_octave': driver.plasma_sines_octave,
166+
'perlin_noise_3d': driver.perlin_noise_3d,
167167
'impulse_exp': utils.impulse_exp,
168168
'fract': utils.fract,
169-
'blackbody_to_rgb': rpi_ws281x.blackbody_to_rgb,
170-
'blackbody_correction_rgb': rpi_ws281x.blackbody_correction_rgb,
169+
'blackbody_to_rgb': driver.blackbody_to_rgb,
170+
'blackbody_correction_rgb': driver.blackbody_correction_rgb,
171171
}
172172
restricted_locals = {}
173173
arg_names = ['t', 'dt', 'x', 'y', 'prev_state']
@@ -192,7 +192,7 @@ def reset_prev_states(self):
192192

193193
def calculate_color_correction(self):
194194
'Calculate and store color temperature correction'
195-
rgb = rpi_ws281x.blackbody_to_rgb(self.params['master_color_temp'])
195+
rgb = driver.blackbody_to_rgb(self.params['master_color_temp'])
196196
c = [self.correction_original[0] * int(rgb[0] * 255) // 255,
197197
self.correction_original[1] * int(rgb[1] * 255) // 255,
198198
self.correction_original[2] * int(rgb[2] * 255) // 255]
@@ -345,24 +345,32 @@ def update_leds(self):
345345

346346
# Write colors to LEDs
347347
if mode == animpatterns.ColorMode.hsv:
348-
self.led_controller.leds.set_all_pixels_hsv_float(
348+
self.led_controller.set_all_pixels_hsv_float(
349349
[(c[0][0] % 1, c[0][1], c[0][2] * c[1]) for c in s_2],
350350
self.correction,
351351
self.params['master_saturation'],
352352
self.params['master_brightness'],
353-
self.params['master_gamma'],
354-
self.led_controller.has_white
353+
self.params['master_gamma']
355354
)
356355
elif mode == animpatterns.ColorMode.rgb:
357-
self.led_controller.leds.set_all_pixels_rgb_float(
356+
self.led_controller.set_all_pixels_rgb_float(
358357
[(c[0][0] * c[1], c[0][1] * c[1], c[0][2] * c[1]) for c in s_2],
359358
self.correction,
360359
self.params['master_saturation'],
361360
self.params['master_brightness'],
362-
self.params['master_gamma'],
363-
self.led_controller.has_white
361+
self.params['master_gamma']
364362
)
365363

366-
def end_animation_thread(self):
364+
def clear_leds(self):
365+
'Turn all LEDs off'
366+
self.led_controller.set_all_pixels_rgb_float(
367+
[(0, 0, 0) for i in range(self.led_count)],
368+
self.correction,
369+
self.params['master_saturation'],
370+
self.params['master_brightness'],
371+
self.params['master_gamma']
372+
)
373+
374+
def end_animation(self):
367375
'Stop rendering in the animation thread'
368376
self.timer.stop()

ledcontrol/animationpatterns.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from random import random
55
from enum import Enum
66

7-
import ledcontrol.driver as rpi_ws281x
7+
import ledcontrol.driver as driver
88
import ledcontrol.utils as utils
99

1010
ColorMode = Enum('ColorMode', ['hsv', 'rgb'])
@@ -253,25 +253,25 @@ def pattern(t, dt, x, y, prev_state):
253253
# return brightness, colorRGB
254254

255255
def sine_1d(t, dt, x, y, prev_state, in_color):
256-
return in_color, rpi_ws281x.wave_sine(t + x)
256+
return in_color, driver.wave_sine(t + x)
257257

258258
def cubic_1d(t, dt, x, y, prev_state, in_color):
259-
return in_color, rpi_ws281x.wave_cubic(t + x)
259+
return in_color, driver.wave_cubic(t + x)
260260

261261
def ramp_1d(t, dt, x, y, prev_state, in_color):
262262
return in_color, (t + x) % 1 # test ramp^2
263263

264264
def bounce_linear_1d(t, dt, x, y, prev_state, in_color):
265-
return in_color, rpi_ws281x.wave_sine(x + rpi_ws281x.wave_triangle(t))
265+
return in_color, driver.wave_sine(x + driver.wave_triangle(t))
266266

267267
def bounce_sine_1d(t, dt, x, y, prev_state, in_color):
268-
return in_color, rpi_ws281x.wave_sine(x + rpi_ws281x.wave_sine(t))
268+
return in_color, driver.wave_sine(x + driver.wave_sine(t))
269269

270270
def bounce_cubic_1d(t, dt, x, y, prev_state, in_color):
271-
return in_color, rpi_ws281x.wave_sine(x + rpi_ws281x.wave_cubic(t))
271+
return in_color, driver.wave_sine(x + driver.wave_cubic(t))
272272

273273
def perlin_noise_2d(t, dt, x, y, prev_state, in_color):
274-
return in_color, rpi_ws281x.perlin_noise_3d(x, y, t)
274+
return in_color, driver.perlin_noise_3d(x, y, t)
275275

276276
def twinkle_pulse_1d(t, dt, x, y, prev_state, in_color):
277277
v = prev_state[1] - dt

ledcontrol/app.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,8 @@ def auto_save_settings():
226226

227227
controller.begin_animation_thread()
228228
atexit.register(save_settings)
229-
atexit.register(leds.clear)
230-
atexit.register(controller.end_animation_thread)
229+
atexit.register(controller.clear_leds)
230+
atexit.register(controller.end_animation)
231231
auto_save_settings()
232232

233233
return app

ledcontrol/driver/__init__.py

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,8 @@
11
# led-control WS2812B LED Controller Server
2-
# Copyright 2019 jackw01. Released under the MIT License (see LICENSE for details).
2+
# Copyright 2020 jackw01. Released under the MIT License (see LICENSE for details).
33

4-
import _ledcontrol_rpi_ws281x_driver as rpi_ws281x
4+
# Import the extension module
5+
from _ledcontrol_rpi_ws281x_driver import *
56

6-
from .rpi_ws281x_helper import PixelStrip, Color
7-
#from .lib.rpi_ws281x import (
8-
# blackbody_to_rgb,
9-
# blackbody_correction_rgb,
10-
# wave_pulse,
11-
# wave_triangle,
12-
# wave_sine,
13-
# wave_cubic,
14-
# plasma_sines,
15-
# plasma_sines_octave,
16-
# perlin_noise_3d,
17-
#)
187

19-
print(dir(rpi_ws281x))
208

21-
# For some reason this stopped working the normal way
22-
blackbody_to_rgb = rpi_ws281x.blackbody_to_rgb
23-
blackbody_correction_rgb = rpi_ws281x.blackbody_correction_rgb
24-
wave_pulse = rpi_ws281x.wave_pulse
25-
wave_triangle = rpi_ws281x.wave_triangle
26-
wave_sine = rpi_ws281x.wave_sine
27-
wave_cubic = rpi_ws281x.wave_cubic
28-
plasma_sines = rpi_ws281x.plasma_sines
29-
plasma_sines_octave = rpi_ws281x.plasma_sines_octave
30-
perlin_noise_3d = rpi_ws281x.perlin_noise_3d
31-
32-
__version__ = '4.2.2'

ledcontrol/driver/rpi_ws281x_helper.py

Lines changed: 0 additions & 189 deletions
This file was deleted.

0 commit comments

Comments
 (0)